aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86_64/boot/compressed
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/x86_64/boot/compressed
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/x86_64/boot/compressed')
-rw-r--r--arch/x86_64/boot/compressed/Makefile32
-rw-r--r--arch/x86_64/boot/compressed/head.S142
-rw-r--r--arch/x86_64/boot/compressed/misc.c354
-rw-r--r--arch/x86_64/boot/compressed/miscsetup.h39
-rw-r--r--arch/x86_64/boot/compressed/vmlinux.scr9
5 files changed, 576 insertions, 0 deletions
diff --git a/arch/x86_64/boot/compressed/Makefile b/arch/x86_64/boot/compressed/Makefile
new file mode 100644
index 000000000000..f89d96f11a9f
--- /dev/null
+++ b/arch/x86_64/boot/compressed/Makefile
@@ -0,0 +1,32 @@
1#
2# linux/arch/x86_64/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6# Note all the files here are compiled/linked as 32bit executables.
7#
8
9targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
10EXTRA_AFLAGS := -traditional -m32
11
12# cannot use EXTRA_CFLAGS because base CFLAGS contains -mkernel which conflicts with
13# -m32
14CFLAGS := -m32 -D__KERNEL__ -Iinclude -O2 -fno-strict-aliasing
15LDFLAGS := -m elf_i386
16
17LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32 -m elf_i386
18
19$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
20 $(call if_changed,ld)
21 @:
22
23$(obj)/vmlinux.bin: vmlinux FORCE
24 $(call if_changed,objcopy)
25
26$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
27 $(call if_changed,gzip)
28
29LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
30
31$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
32 $(call if_changed,ld)
diff --git a/arch/x86_64/boot/compressed/head.S b/arch/x86_64/boot/compressed/head.S
new file mode 100644
index 000000000000..27264dbd575c
--- /dev/null
+++ b/arch/x86_64/boot/compressed/head.S
@@ -0,0 +1,142 @@
1/*
2 * linux/boot/head.S
3 *
4 * Copyright (C) 1991, 1992, 1993 Linus Torvalds
5 *
6 * $Id: head.S,v 1.3 2001/04/20 00:59:28 ak Exp $
7 */
8
9/*
10 * head.S contains the 32-bit startup code.
11 *
12 * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
13 * the page directory will exist. The startup code will be overwritten by
14 * the page directory. [According to comments etc elsewhere on a compressed
15 * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
16 *
17 * Page 0 is deliberately kept safe, since System Management Mode code in
18 * laptops may need to access the BIOS data stored there. This is also
19 * useful for future device drivers that either access the BIOS via VM86
20 * mode.
21 */
22
23/*
24 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
25 */
26.code32
27.text
28
29#include <linux/linkage.h>
30#include <asm/segment.h>
31
32 .code32
33 .globl startup_32
34
35startup_32:
36 cld
37 cli
38 movl $(__KERNEL_DS),%eax
39 movl %eax,%ds
40 movl %eax,%es
41 movl %eax,%fs
42 movl %eax,%gs
43
44 lss stack_start,%esp
45 xorl %eax,%eax
461: incl %eax # check that A20 really IS enabled
47 movl %eax,0x000000 # loop forever if it isn't
48 cmpl %eax,0x100000
49 je 1b
50
51/*
52 * Initialize eflags. Some BIOS's leave bits like NT set. This would
53 * confuse the debugger if this code is traced.
54 * XXX - best to initialize before switching to protected mode.
55 */
56 pushl $0
57 popfl
58/*
59 * Clear BSS
60 */
61 xorl %eax,%eax
62 movl $_edata,%edi
63 movl $_end,%ecx
64 subl %edi,%ecx
65 cld
66 rep
67 stosb
68/*
69 * Do the decompression, and jump to the new kernel..
70 */
71 subl $16,%esp # place for structure on the stack
72 movl %esp,%eax
73 pushl %esi # real mode pointer as second arg
74 pushl %eax # address of structure as first arg
75 call decompress_kernel
76 orl %eax,%eax
77 jnz 3f
78 addl $8,%esp
79 xorl %ebx,%ebx
80 ljmp $(__KERNEL_CS), $0x100000
81
82/*
83 * We come here, if we were loaded high.
84 * We need to move the move-in-place routine down to 0x1000
85 * and then start it with the buffer addresses in registers,
86 * which we got from the stack.
87 */
883:
89 movl %esi,%ebx
90 movl $move_routine_start,%esi
91 movl $0x1000,%edi
92 movl $move_routine_end,%ecx
93 subl %esi,%ecx
94 addl $3,%ecx
95 shrl $2,%ecx
96 cld
97 rep
98 movsl
99
100 popl %esi # discard the address
101 addl $4,%esp # real mode pointer
102 popl %esi # low_buffer_start
103 popl %ecx # lcount
104 popl %edx # high_buffer_start
105 popl %eax # hcount
106 movl $0x100000,%edi
107 cli # make sure we don't get interrupted
108 ljmp $(__KERNEL_CS), $0x1000 # and jump to the move routine
109
110/*
111 * Routine (template) for moving the decompressed kernel in place,
112 * if we were high loaded. This _must_ PIC-code !
113 */
114move_routine_start:
115 movl %ecx,%ebp
116 shrl $2,%ecx
117 rep
118 movsl
119 movl %ebp,%ecx
120 andl $3,%ecx
121 rep
122 movsb
123 movl %edx,%esi
124 movl %eax,%ecx # NOTE: rep movsb won't move if %ecx == 0
125 addl $3,%ecx
126 shrl $2,%ecx
127 rep
128 movsl
129 movl %ebx,%esi # Restore setup pointer
130 xorl %ebx,%ebx
131 ljmp $(__KERNEL_CS), $0x100000
132move_routine_end:
133
134
135/* Stack for uncompression */
136 .align 32
137user_stack:
138 .fill 4096,4,0
139stack_start:
140 .long user_stack+4096
141 .word __KERNEL_DS
142
diff --git a/arch/x86_64/boot/compressed/misc.c b/arch/x86_64/boot/compressed/misc.c
new file mode 100644
index 000000000000..c8b9216f9e63
--- /dev/null
+++ b/arch/x86_64/boot/compressed/misc.c
@@ -0,0 +1,354 @@
1/*
2 * misc.c
3 *
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
6 *
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
8 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
9 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
10 */
11
12#include "miscsetup.h"
13#include <asm/io.h>
14
15/*
16 * gzip declarations
17 */
18
19#define OF(args) args
20#define STATIC static
21
22#undef memset
23#undef memcpy
24#define memzero(s, n) memset ((s), 0, (n))
25
26typedef unsigned char uch;
27typedef unsigned short ush;
28typedef unsigned long ulg;
29
30#define WSIZE 0x8000 /* Window size must be at least 32k, */
31 /* and a power of two */
32
33static uch *inbuf; /* input buffer */
34static uch window[WSIZE]; /* Sliding window buffer */
35
36static unsigned insize = 0; /* valid bytes in inbuf */
37static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
38static unsigned outcnt = 0; /* bytes in output buffer */
39
40/* gzip flag byte */
41#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
42#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
43#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
44#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
45#define COMMENT 0x10 /* bit 4 set: file comment present */
46#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
47#define RESERVED 0xC0 /* bit 6,7: reserved */
48
49#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
50
51/* Diagnostic functions */
52#ifdef DEBUG
53# define Assert(cond,msg) {if(!(cond)) error(msg);}
54# define Trace(x) fprintf x
55# define Tracev(x) {if (verbose) fprintf x ;}
56# define Tracevv(x) {if (verbose>1) fprintf x ;}
57# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
58# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
59#else
60# define Assert(cond,msg)
61# define Trace(x)
62# define Tracev(x)
63# define Tracevv(x)
64# define Tracec(c,x)
65# define Tracecv(c,x)
66#endif
67
68static int fill_inbuf(void);
69static void flush_window(void);
70static void error(char *m);
71static void gzip_mark(void **);
72static void gzip_release(void **);
73
74/*
75 * This is set up by the setup-routine at boot-time
76 */
77static unsigned char *real_mode; /* Pointer to real-mode data */
78
79#define EXT_MEM_K (*(unsigned short *)(real_mode + 0x2))
80#ifndef STANDARD_MEMORY_BIOS_CALL
81#define ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0))
82#endif
83#define SCREEN_INFO (*(struct screen_info *)(real_mode+0))
84
85extern char input_data[];
86extern int input_len;
87
88static long bytes_out = 0;
89static uch *output_data;
90static unsigned long output_ptr = 0;
91
92static void *malloc(int size);
93static void free(void *where);
94
95static void putstr(const char *);
96
97extern int end;
98static long free_mem_ptr = (long)&end;
99static long free_mem_end_ptr;
100
101#define INPLACE_MOVE_ROUTINE 0x1000
102#define LOW_BUFFER_START 0x2000
103#define LOW_BUFFER_MAX 0x90000
104#define HEAP_SIZE 0x3000
105static unsigned int low_buffer_end, low_buffer_size;
106static int high_loaded =0;
107static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
108
109static char *vidmem = (char *)0xb8000;
110static int vidport;
111static int lines, cols;
112
113#include "../../../../lib/inflate.c"
114
115static void *malloc(int size)
116{
117 void *p;
118
119 if (size <0) error("Malloc error");
120 if (free_mem_ptr <= 0) error("Memory error");
121
122 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
123
124 p = (void *)free_mem_ptr;
125 free_mem_ptr += size;
126
127 if (free_mem_ptr >= free_mem_end_ptr)
128 error("Out of memory");
129
130 return p;
131}
132
133static void free(void *where)
134{ /* Don't care */
135}
136
137static void gzip_mark(void **ptr)
138{
139 *ptr = (void *) free_mem_ptr;
140}
141
142static void gzip_release(void **ptr)
143{
144 free_mem_ptr = (long) *ptr;
145}
146
147static void scroll(void)
148{
149 int i;
150
151 memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
152 for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
153 vidmem[i] = ' ';
154}
155
156static void putstr(const char *s)
157{
158 int x,y,pos;
159 char c;
160
161 x = SCREEN_INFO.orig_x;
162 y = SCREEN_INFO.orig_y;
163
164 while ( ( c = *s++ ) != '\0' ) {
165 if ( c == '\n' ) {
166 x = 0;
167 if ( ++y >= lines ) {
168 scroll();
169 y--;
170 }
171 } else {
172 vidmem [ ( x + cols * y ) * 2 ] = c;
173 if ( ++x >= cols ) {
174 x = 0;
175 if ( ++y >= lines ) {
176 scroll();
177 y--;
178 }
179 }
180 }
181 }
182
183 SCREEN_INFO.orig_x = x;
184 SCREEN_INFO.orig_y = y;
185
186 pos = (x + cols * y) * 2; /* Update cursor position */
187 outb_p(14, vidport);
188 outb_p(0xff & (pos >> 9), vidport+1);
189 outb_p(15, vidport);
190 outb_p(0xff & (pos >> 1), vidport+1);
191}
192
193void* memset(void* s, int c, unsigned n)
194{
195 int i;
196 char *ss = (char*)s;
197
198 for (i=0;i<n;i++) ss[i] = c;
199 return s;
200}
201
202void* memcpy(void* dest, const void* src, unsigned n)
203{
204 int i;
205 char *d = (char *)dest, *s = (char *)src;
206
207 for (i=0;i<n;i++) d[i] = s[i];
208 return dest;
209}
210
211/* ===========================================================================
212 * Fill the input buffer. This is called only when the buffer is empty
213 * and at least one byte is really needed.
214 */
215static int fill_inbuf(void)
216{
217 if (insize != 0) {
218 error("ran out of input data");
219 }
220
221 inbuf = input_data;
222 insize = input_len;
223 inptr = 1;
224 return inbuf[0];
225}
226
227/* ===========================================================================
228 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
229 * (Used for the decompressed data only.)
230 */
231static void flush_window_low(void)
232{
233 ulg c = crc; /* temporary variable */
234 unsigned n;
235 uch *in, *out, ch;
236
237 in = window;
238 out = &output_data[output_ptr];
239 for (n = 0; n < outcnt; n++) {
240 ch = *out++ = *in++;
241 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
242 }
243 crc = c;
244 bytes_out += (ulg)outcnt;
245 output_ptr += (ulg)outcnt;
246 outcnt = 0;
247}
248
249static void flush_window_high(void)
250{
251 ulg c = crc; /* temporary variable */
252 unsigned n;
253 uch *in, ch;
254 in = window;
255 for (n = 0; n < outcnt; n++) {
256 ch = *output_data++ = *in++;
257 if ((ulg)output_data == low_buffer_end) output_data=high_buffer_start;
258 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
259 }
260 crc = c;
261 bytes_out += (ulg)outcnt;
262 outcnt = 0;
263}
264
265static void flush_window(void)
266{
267 if (high_loaded) flush_window_high();
268 else flush_window_low();
269}
270
271static void error(char *x)
272{
273 putstr("\n\n");
274 putstr(x);
275 putstr("\n\n -- System halted");
276
277 while(1);
278}
279
280void setup_normal_output_buffer(void)
281{
282#ifdef STANDARD_MEMORY_BIOS_CALL
283 if (EXT_MEM_K < 1024) error("Less than 2MB of memory");
284#else
285 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < 1024) error("Less than 2MB of memory");
286#endif
287 output_data = (char *)0x100000; /* Points to 1M */
288 free_mem_end_ptr = (long)real_mode;
289}
290
291struct moveparams {
292 uch *low_buffer_start; int lcount;
293 uch *high_buffer_start; int hcount;
294};
295
296void setup_output_buffer_if_we_run_high(struct moveparams *mv)
297{
298 high_buffer_start = (uch *)(((ulg)&end) + HEAP_SIZE);
299#ifdef STANDARD_MEMORY_BIOS_CALL
300 if (EXT_MEM_K < (3*1024)) error("Less than 4MB of memory");
301#else
302 if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < (3*1024)) error("Less than 4MB of memory");
303#endif
304 mv->low_buffer_start = output_data = (char *)LOW_BUFFER_START;
305 low_buffer_end = ((unsigned int)real_mode > LOW_BUFFER_MAX
306 ? LOW_BUFFER_MAX : (unsigned int)real_mode) & ~0xfff;
307 low_buffer_size = low_buffer_end - LOW_BUFFER_START;
308 high_loaded = 1;
309 free_mem_end_ptr = (long)high_buffer_start;
310 if ( (0x100000 + low_buffer_size) > ((ulg)high_buffer_start)) {
311 high_buffer_start = (uch *)(0x100000 + low_buffer_size);
312 mv->hcount = 0; /* say: we need not to move high_buffer */
313 }
314 else mv->hcount = -1;
315 mv->high_buffer_start = high_buffer_start;
316}
317
318void close_output_buffer_if_we_run_high(struct moveparams *mv)
319{
320 if (bytes_out > low_buffer_size) {
321 mv->lcount = low_buffer_size;
322 if (mv->hcount)
323 mv->hcount = bytes_out - low_buffer_size;
324 } else {
325 mv->lcount = bytes_out;
326 mv->hcount = 0;
327 }
328}
329
330int decompress_kernel(struct moveparams *mv, void *rmode)
331{
332 real_mode = rmode;
333
334 if (SCREEN_INFO.orig_video_mode == 7) {
335 vidmem = (char *) 0xb0000;
336 vidport = 0x3b4;
337 } else {
338 vidmem = (char *) 0xb8000;
339 vidport = 0x3d4;
340 }
341
342 lines = SCREEN_INFO.orig_video_lines;
343 cols = SCREEN_INFO.orig_video_cols;
344
345 if (free_mem_ptr < 0x100000) setup_normal_output_buffer();
346 else setup_output_buffer_if_we_run_high(mv);
347
348 makecrc();
349 putstr(".\nDecompressing Linux...");
350 gunzip();
351 putstr("done.\nBooting the kernel.\n");
352 if (high_loaded) close_output_buffer_if_we_run_high(mv);
353 return high_loaded;
354}
diff --git a/arch/x86_64/boot/compressed/miscsetup.h b/arch/x86_64/boot/compressed/miscsetup.h
new file mode 100644
index 000000000000..bb1620531703
--- /dev/null
+++ b/arch/x86_64/boot/compressed/miscsetup.h
@@ -0,0 +1,39 @@
1#define NULL 0
2//typedef unsigned int size_t;
3
4
5struct screen_info {
6 unsigned char orig_x; /* 0x00 */
7 unsigned char orig_y; /* 0x01 */
8 unsigned short dontuse1; /* 0x02 -- EXT_MEM_K sits here */
9 unsigned short orig_video_page; /* 0x04 */
10 unsigned char orig_video_mode; /* 0x06 */
11 unsigned char orig_video_cols; /* 0x07 */
12 unsigned short unused2; /* 0x08 */
13 unsigned short orig_video_ega_bx; /* 0x0a */
14 unsigned short unused3; /* 0x0c */
15 unsigned char orig_video_lines; /* 0x0e */
16 unsigned char orig_video_isVGA; /* 0x0f */
17 unsigned short orig_video_points; /* 0x10 */
18
19 /* VESA graphic mode -- linear frame buffer */
20 unsigned short lfb_width; /* 0x12 */
21 unsigned short lfb_height; /* 0x14 */
22 unsigned short lfb_depth; /* 0x16 */
23 unsigned long lfb_base; /* 0x18 */
24 unsigned long lfb_size; /* 0x1c */
25 unsigned short dontuse2, dontuse3; /* 0x20 -- CL_MAGIC and CL_OFFSET here */
26 unsigned short lfb_linelength; /* 0x24 */
27 unsigned char red_size; /* 0x26 */
28 unsigned char red_pos; /* 0x27 */
29 unsigned char green_size; /* 0x28 */
30 unsigned char green_pos; /* 0x29 */
31 unsigned char blue_size; /* 0x2a */
32 unsigned char blue_pos; /* 0x2b */
33 unsigned char rsvd_size; /* 0x2c */
34 unsigned char rsvd_pos; /* 0x2d */
35 unsigned short vesapm_seg; /* 0x2e */
36 unsigned short vesapm_off; /* 0x30 */
37 unsigned short pages; /* 0x32 */
38 /* 0x34 -- 0x3f reserved for future expansion */
39};
diff --git a/arch/x86_64/boot/compressed/vmlinux.scr b/arch/x86_64/boot/compressed/vmlinux.scr
new file mode 100644
index 000000000000..1ed9d791f863
--- /dev/null
+++ b/arch/x86_64/boot/compressed/vmlinux.scr
@@ -0,0 +1,9 @@
1SECTIONS
2{
3 .data : {
4 input_len = .;
5 LONG(input_data_end - input_data) input_data = .;
6 *(.data)
7 input_data_end = .;
8 }
9}