This source file includes following definitions.
- malloc
- free
- gzip_mark
- gzip_release
- scroll
- puts
- memset
- memcpy
- fill_inbuf
- flush_window
- error
- gzip_mark
- gzip_release
- main
- decompress_kernel
1
2
3
4
5
6
7
8
9
10
11 #include <string.h>
12
13 #include <asm/segment.h>
14 #include <asm/io.h>
15
16
17
18
19
20 #define OF(args) args
21 #define STATIC static
22
23 #define memzero(s, n) memset ((s), 0, (n))
24
25 typedef unsigned char uch;
26 typedef unsigned short ush;
27 typedef unsigned long ulg;
28
29 #define WSIZE 0x8000
30
31
32 static uch *inbuf;
33 static uch window[WSIZE];
34
35 static unsigned insize = 0;
36 static unsigned inptr = 0;
37 static unsigned outcnt = 0;
38
39
40 #define ASCII_FLAG 0x01
41 #define CONTINUATION 0x02
42 #define EXTRA_FIELD 0x04
43 #define ORIG_NAME 0x08
44 #define COMMENT 0x10
45 #define ENCRYPTED 0x20
46 #define RESERVED 0xC0
47
48 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
49
50
51 #ifdef DEBUG
52 # define Assert(cond,msg) {if(!(cond)) error(msg);}
53 # define Trace(x) fprintf x
54 # define Tracev(x) {if (verbose) fprintf x ;}
55 # define Tracevv(x) {if (verbose>1) fprintf x ;}
56 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
57 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
58 #else
59 # define Assert(cond,msg)
60 # define Trace(x)
61 # define Tracev(x)
62 # define Tracevv(x)
63 # define Tracec(c,x)
64 # define Tracecv(c,x)
65 #endif
66
67 static int fill_inbuf(void);
68 static void flush_window(void);
69 static void error(char *m);
70 static void gzip_mark(void **);
71 static void gzip_release(void **);
72
73
74
75
76
77 struct screen_info {
78 unsigned char orig_x;
79 unsigned char orig_y;
80 unsigned char unused1[2];
81 unsigned short orig_video_page;
82 unsigned char orig_video_mode;
83 unsigned char orig_video_cols;
84 unsigned short unused2;
85 unsigned short orig_video_ega_bx;
86 unsigned short unused3;
87 unsigned char orig_video_lines;
88 unsigned char orig_video_isVGA;
89 };
90
91
92
93
94 #define EXT_MEM_K (*(unsigned short *)0x90002)
95 #define DRIVE_INFO (*(struct drive_info *)0x90080)
96 #define SCREEN_INFO (*(struct screen_info *)0x90000)
97 #define RAMDISK_SIZE (*(unsigned short *)0x901F8)
98 #define ORIG_ROOT_DEV (*(unsigned short *)0x901FC)
99 #define AUX_DEVICE_INFO (*(unsigned char *)0x901FF)
100
101 extern char input_data[];
102 extern int input_len;
103
104 static long bytes_out = 0;
105 static uch *output_data;
106 static unsigned long output_ptr = 0;
107
108 static void *malloc(int size);
109 static void free(void *where);
110 static void error(char *m);
111 static void gzip_mark(void **);
112 static void gzip_release(void **);
113
114 #ifndef STANDALONE_DEBUG
115 static void puts(const char *);
116
117 extern int end;
118 static long free_mem_ptr = (long)&end;
119
120 static char *vidmem = (char *)0xb8000;
121 static int vidport;
122 static int lines, cols;
123
124 #include "../../../../lib/inflate.c"
125
126 static void *malloc(int size)
127 {
128 void *p;
129
130 if (size <0) error("Malloc error\n");
131 if (free_mem_ptr <= 0) error("Memory error\n");
132
133 free_mem_ptr = (free_mem_ptr + 3) & ~3;
134
135 p = (void *)free_mem_ptr;
136 free_mem_ptr += size;
137
138 if (free_mem_ptr >= 0x90000)
139 error("\nOut of memory\n");
140
141 return p;
142 }
143
144 static void free(void *where)
145 {
146 }
147
148 static void gzip_mark(void **ptr)
149 {
150 *ptr = (void *) free_mem_ptr;
151 }
152
153 static void gzip_release(void **ptr)
154 {
155 free_mem_ptr = (long) *ptr;
156 }
157
158 static void scroll()
159 {
160 int i;
161
162 memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
163 for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
164 vidmem[i] = ' ';
165 }
166
167 static void puts(const char *s)
168 {
169 int x,y,pos;
170 char c;
171
172 x = SCREEN_INFO.orig_x;
173 y = SCREEN_INFO.orig_y;
174
175 while ( ( c = *s++ ) != '\0' ) {
176 if ( c == '\n' ) {
177 x = 0;
178 if ( ++y >= lines ) {
179 scroll();
180 y--;
181 }
182 } else {
183 vidmem [ ( x + cols * y ) * 2 ] = c;
184 if ( ++x >= cols ) {
185 x = 0;
186 if ( ++y >= lines ) {
187 scroll();
188 y--;
189 }
190 }
191 }
192 }
193
194 SCREEN_INFO.orig_x = x;
195 SCREEN_INFO.orig_y = y;
196
197 pos = (x + cols * y) * 2;
198 outb_p(14, vidport);
199 outb_p(0xff & (pos >> 9), vidport+1);
200 outb_p(15, vidport);
201 outb_p(0xff & (pos >> 1), vidport+1);
202 }
203
204 __ptr_t memset(__ptr_t s, int c, size_t n)
205 {
206 int i;
207 char *ss = (char*)s;
208
209 for (i=0;i<n;i++) ss[i] = c;
210 }
211
212 __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
213 size_t __n)
214 {
215 int i;
216 char *d = (char *)__dest, *s = (char *)__src;
217
218 for (i=0;i<__n;i++) d[i] = s[i];
219 }
220 #endif
221
222
223
224
225
226 static int fill_inbuf()
227 {
228 if (insize != 0) {
229 error("ran out of input data\n");
230 }
231
232 inbuf = input_data;
233 insize = input_len;
234 inptr = 1;
235 return inbuf[0];
236 }
237
238
239
240
241
242 static void flush_window()
243 {
244 ulg c = crc;
245 unsigned n;
246 uch *in, *out, ch;
247
248 in = window;
249 out = &output_data[output_ptr];
250 for (n = 0; n < outcnt; n++) {
251 ch = *out++ = *in++;
252 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
253 }
254 crc = c;
255 bytes_out += (ulg)outcnt;
256 output_ptr += (ulg)outcnt;
257 outcnt = 0;
258 }
259
260 static void error(char *x)
261 {
262 puts("\n\n");
263 puts(x);
264 puts("\n\n -- System halted");
265
266 while(1);
267 }
268
269 #define STACK_SIZE (4096)
270
271 long user_stack [STACK_SIZE];
272
273 struct {
274 long * a;
275 short b;
276 } stack_start = { & user_stack [STACK_SIZE] , KERNEL_DS };
277
278 #ifdef STANDALONE_DEBUG
279
280 static void gzip_mark(void **ptr)
281 {
282 }
283
284 static void gzip_release(void **ptr)
285 {
286 }
287
288 char output_buffer[1024 * 800];
289
290 int
291 main(argc, argv)
292 int argc;
293 char **argv;
294 {
295 output_data = output_buffer;
296
297 makecrc();
298 puts("Uncompressing Linux...");
299 gunzip();
300 puts("done.\n");
301 return 0;
302 }
303
304 #else
305
306 void decompress_kernel()
307 {
308 if (SCREEN_INFO.orig_video_mode == 7) {
309 vidmem = (char *) 0xb0000;
310 vidport = 0x3b4;
311 } else {
312 vidmem = (char *) 0xb8000;
313 vidport = 0x3d4;
314 }
315
316 lines = SCREEN_INFO.orig_video_lines;
317 cols = SCREEN_INFO.orig_video_cols;
318
319 if (EXT_MEM_K < 1024) error("Less than 2MB of memory.\n");
320
321 output_data = (char *)0x100000;
322 makecrc();
323 puts("Uncompressing Linux...");
324 gunzip();
325 puts("done.\nNow booting the kernel\n");
326 }
327 #endif
328
329
330
331