1
2
3
4
5
6
7
8
9
10
11
12#include <linux/config.h>
13#include <asm/uaccess.h>
14
15
16#define CACHE_ENABLE 0
17#define CACHE_DISABLE 1
18int cache_control(unsigned int command);
19
20
21
22
23
24#define OF(args) args
25#define STATIC static
26
27#undef memset
28#undef memcpy
29#define memzero(s, n) memset ((s), 0, (n))
30
31typedef unsigned char uch;
32typedef unsigned short ush;
33typedef unsigned long ulg;
34
35#define WSIZE 0x8000
36
37
38static uch *inbuf;
39static uch window[WSIZE];
40
41static unsigned insize = 0;
42static unsigned inptr = 0;
43static unsigned outcnt = 0;
44
45
46#define ASCII_FLAG 0x01
47#define CONTINUATION 0x02
48#define EXTRA_FIELD 0x04
49#define ORIG_NAME 0x08
50#define COMMENT 0x10
51#define ENCRYPTED 0x20
52#define RESERVED 0xC0
53
54#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
55
56
57#ifdef DEBUG
58# define Assert(cond,msg) {if(!(cond)) error(msg);}
59# define Trace(x) fprintf x
60# define Tracev(x) {if (verbose) fprintf x ;}
61# define Tracevv(x) {if (verbose>1) fprintf x ;}
62# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
63# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
64#else
65# define Assert(cond,msg)
66# define Trace(x)
67# define Tracev(x)
68# define Tracevv(x)
69# define Tracec(c,x)
70# define Tracecv(c,x)
71#endif
72
73static int fill_inbuf(void);
74static void flush_window(void);
75static void error(char *m);
76static void gzip_mark(void **);
77static void gzip_release(void **);
78
79extern char input_data[];
80extern int input_len;
81
82static long bytes_out = 0;
83static uch *output_data;
84static unsigned long output_ptr = 0;
85
86static void *malloc(int size);
87static void free(void *where);
88static void error(char *m);
89static void gzip_mark(void **);
90static void gzip_release(void **);
91
92static void puts(const char *);
93
94extern int _text;
95extern int _end;
96static unsigned long free_mem_ptr;
97static unsigned long free_mem_end_ptr;
98
99#define HEAP_SIZE 0x10000
100
101#include "../../../../lib/inflate.c"
102
103static void *malloc(int size)
104{
105 void *p;
106
107 if (size < 0)
108 error("Malloc error\n");
109 if (free_mem_ptr == 0)
110 error("Memory error\n");
111
112 free_mem_ptr = (free_mem_ptr + 3) & ~3;
113
114 p = (void *) free_mem_ptr;
115 free_mem_ptr += size;
116
117 if (free_mem_ptr >= free_mem_end_ptr)
118 error("\nOut of memory\n");
119
120 return p;
121}
122
123static void free(void *where)
124{
125}
126
127static void gzip_mark(void **ptr)
128{
129 *ptr = (void *) free_mem_ptr;
130}
131
132static void gzip_release(void **ptr)
133{
134 free_mem_ptr = (long) *ptr;
135}
136
137void puts(const char *s)
138{
139}
140
141void *memset(void *s, int c, size_t n)
142{
143 int i;
144 char *ss = (char *) s;
145
146 for (i = 0; i < n; i++)
147 ss[i] = c;
148 return s;
149}
150
151void *memcpy(void *__dest, __const void *__src, size_t __n)
152{
153 int i;
154 char *d = (char *) __dest, *s = (char *) __src;
155
156 for (i = 0; i < __n; i++)
157 d[i] = s[i];
158 return __dest;
159}
160
161
162
163
164
165static int fill_inbuf(void)
166{
167 if (insize != 0) {
168 error("ran out of input data\n");
169 }
170
171 inbuf = input_data;
172 insize = input_len;
173 inptr = 1;
174 return inbuf[0];
175}
176
177
178
179
180
181static void flush_window(void)
182{
183 ulg c = crc;
184 unsigned n;
185 uch *in, *out, ch;
186
187 in = window;
188 out = &output_data[output_ptr];
189 for (n = 0; n < outcnt; n++) {
190 ch = *out++ = *in++;
191 c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8);
192 }
193 crc = c;
194 bytes_out += (ulg) outcnt;
195 output_ptr += (ulg) outcnt;
196 outcnt = 0;
197 puts(".");
198}
199
200static void error(char *x)
201{
202 puts("\n\n");
203 puts(x);
204 puts("\n\n -- System halted");
205
206 while (1) ;
207}
208
209#define STACK_SIZE (4096)
210long __attribute__ ((aligned(8))) user_stack[STACK_SIZE];
211long *stack_start = &user_stack[STACK_SIZE];
212
213void decompress_kernel(void)
214{
215 output_data = (uch *) (CONFIG_MEMORY_START + 0x2000);
216 free_mem_ptr = (unsigned long) &_end;
217 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
218
219 makecrc();
220 puts("Uncompressing Linux... ");
221 cache_control(CACHE_ENABLE);
222 gunzip();
223 puts("\n");
224
225#if 0
226
227
228
229
230
231 {
232 volatile unsigned int *parambase =
233 (int *) (CONFIG_MEMORY_START + 0x1000);
234
235 parambase[0] = 0x1;
236 parambase[1] = 0x0;
237 parambase[2] = 0x0200;
238 parambase[3] = 0x0;
239 parambase[4] = 0x0;
240 parambase[5] = 0x0;
241 parambase[6] = 0;
242
243 strcpy((char *) ((int) parambase + 0x100),
244 "console=ttySC0,38400");
245 }
246#endif
247
248 puts("Ok, booting the kernel.\n");
249
250 cache_control(CACHE_DISABLE);
251}
252