diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2007-10-11 05:17:15 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2007-10-11 05:17:15 -0400 |
commit | 9e9b4573e4411ac5fcfb6ba04ad360d3de6414ba (patch) | |
tree | 8e62dbe670e98552cf6ff7b9b5b59597e3143bf3 /arch/x86 | |
parent | aadfb679c8eb9b83125833f03b5221889595b67c (diff) |
x86_64: move boot
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/boot/compressed/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/boot/compressed/Makefile_64 | 30 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_64.S | 311 | ||||
-rw-r--r-- | arch/x86/boot/compressed/misc_64.c | 371 | ||||
-rw-r--r-- | arch/x86/boot/compressed/vmlinux_64.lds | 44 | ||||
-rw-r--r-- | arch/x86/boot/compressed/vmlinux_64.scr | 10 |
6 files changed, 767 insertions, 1 deletions
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 76ab5caddf9a..52c1db854520 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | ifeq ($(CONFIG_X86_32),y) | 1 | ifeq ($(CONFIG_X86_32),y) |
2 | include ${srctree}/arch/x86/boot/compressed/Makefile_32 | 2 | include ${srctree}/arch/x86/boot/compressed/Makefile_32 |
3 | else | 3 | else |
4 | include ${srctree}/arch/x86_64/boot/compressed/Makefile_64 | 4 | include ${srctree}/arch/x86/boot/compressed/Makefile_64 |
5 | endif | 5 | endif |
diff --git a/arch/x86/boot/compressed/Makefile_64 b/arch/x86/boot/compressed/Makefile_64 new file mode 100644 index 000000000000..dc6b3380cc45 --- /dev/null +++ b/arch/x86/boot/compressed/Makefile_64 | |||
@@ -0,0 +1,30 @@ | |||
1 | # | ||
2 | # linux/arch/x86/boot/compressed/Makefile | ||
3 | # | ||
4 | # create a compressed vmlinux image from the original vmlinux | ||
5 | # | ||
6 | |||
7 | targets := vmlinux vmlinux.bin vmlinux.bin.gz head_64.o misc_64.o piggy.o | ||
8 | |||
9 | CFLAGS := -m64 -D__KERNEL__ $(LINUXINCLUDE) -O2 \ | ||
10 | -fno-strict-aliasing -fPIC -mcmodel=small \ | ||
11 | $(call cc-option, -ffreestanding) \ | ||
12 | $(call cc-option, -fno-stack-protector) | ||
13 | AFLAGS := $(CFLAGS) -D__ASSEMBLY__ | ||
14 | LDFLAGS := -m elf_x86_64 | ||
15 | |||
16 | LDFLAGS_vmlinux := -T | ||
17 | $(obj)/vmlinux: $(src)/vmlinux_64.lds $(obj)/head_64.o $(obj)/misc_64.o $(obj)/piggy.o FORCE | ||
18 | $(call if_changed,ld) | ||
19 | @: | ||
20 | |||
21 | $(obj)/vmlinux.bin: vmlinux FORCE | ||
22 | $(call if_changed,objcopy) | ||
23 | |||
24 | $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE | ||
25 | $(call if_changed,gzip) | ||
26 | |||
27 | LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T | ||
28 | |||
29 | $(obj)/piggy.o: $(obj)/vmlinux_64.scr $(obj)/vmlinux.bin.gz FORCE | ||
30 | $(call if_changed,ld) | ||
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S new file mode 100644 index 000000000000..cff3d1dc5dd4 --- /dev/null +++ b/arch/x86/boot/compressed/head_64.S | |||
@@ -0,0 +1,311 @@ | |||
1 | /* | ||
2 | * linux/boot/head.S | ||
3 | * | ||
4 | * Copyright (C) 1991, 1992, 1993 Linus Torvalds | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * head.S contains the 32-bit startup code. | ||
9 | * | ||
10 | * NOTE!!! Startup happens at absolute address 0x00001000, which is also where | ||
11 | * the page directory will exist. The startup code will be overwritten by | ||
12 | * the page directory. [According to comments etc elsewhere on a compressed | ||
13 | * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC] | ||
14 | * | ||
15 | * Page 0 is deliberately kept safe, since System Management Mode code in | ||
16 | * laptops may need to access the BIOS data stored there. This is also | ||
17 | * useful for future device drivers that either access the BIOS via VM86 | ||
18 | * mode. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996 | ||
23 | */ | ||
24 | .code32 | ||
25 | .text | ||
26 | |||
27 | #include <linux/linkage.h> | ||
28 | #include <asm/segment.h> | ||
29 | #include <asm/pgtable.h> | ||
30 | #include <asm/page.h> | ||
31 | #include <asm/msr.h> | ||
32 | |||
33 | .section ".text.head" | ||
34 | .code32 | ||
35 | .globl startup_32 | ||
36 | |||
37 | startup_32: | ||
38 | cld | ||
39 | cli | ||
40 | movl $(__KERNEL_DS), %eax | ||
41 | movl %eax, %ds | ||
42 | movl %eax, %es | ||
43 | movl %eax, %ss | ||
44 | |||
45 | /* Calculate the delta between where we were compiled to run | ||
46 | * at and where we were actually loaded at. This can only be done | ||
47 | * with a short local call on x86. Nothing else will tell us what | ||
48 | * address we are running at. The reserved chunk of the real-mode | ||
49 | * data at 0x1e4 (defined as a scratch field) are used as the stack | ||
50 | * for this calculation. Only 4 bytes are needed. | ||
51 | */ | ||
52 | leal (0x1e4+4)(%esi), %esp | ||
53 | call 1f | ||
54 | 1: popl %ebp | ||
55 | subl $1b, %ebp | ||
56 | |||
57 | /* setup a stack and make sure cpu supports long mode. */ | ||
58 | movl $user_stack_end, %eax | ||
59 | addl %ebp, %eax | ||
60 | movl %eax, %esp | ||
61 | |||
62 | call verify_cpu | ||
63 | testl %eax, %eax | ||
64 | jnz no_longmode | ||
65 | |||
66 | /* Compute the delta between where we were compiled to run at | ||
67 | * and where the code will actually run at. | ||
68 | */ | ||
69 | /* %ebp contains the address we are loaded at by the boot loader and %ebx | ||
70 | * contains the address where we should move the kernel image temporarily | ||
71 | * for safe in-place decompression. | ||
72 | */ | ||
73 | |||
74 | #ifdef CONFIG_RELOCATABLE | ||
75 | movl %ebp, %ebx | ||
76 | addl $(LARGE_PAGE_SIZE -1), %ebx | ||
77 | andl $LARGE_PAGE_MASK, %ebx | ||
78 | #else | ||
79 | movl $CONFIG_PHYSICAL_START, %ebx | ||
80 | #endif | ||
81 | |||
82 | /* Replace the compressed data size with the uncompressed size */ | ||
83 | subl input_len(%ebp), %ebx | ||
84 | movl output_len(%ebp), %eax | ||
85 | addl %eax, %ebx | ||
86 | /* Add 8 bytes for every 32K input block */ | ||
87 | shrl $12, %eax | ||
88 | addl %eax, %ebx | ||
89 | /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */ | ||
90 | addl $(32768 + 18 + 4095), %ebx | ||
91 | andl $~4095, %ebx | ||
92 | |||
93 | /* | ||
94 | * Prepare for entering 64 bit mode | ||
95 | */ | ||
96 | |||
97 | /* Load new GDT with the 64bit segments using 32bit descriptor */ | ||
98 | leal gdt(%ebp), %eax | ||
99 | movl %eax, gdt+2(%ebp) | ||
100 | lgdt gdt(%ebp) | ||
101 | |||
102 | /* Enable PAE mode */ | ||
103 | xorl %eax, %eax | ||
104 | orl $(1 << 5), %eax | ||
105 | movl %eax, %cr4 | ||
106 | |||
107 | /* | ||
108 | * Build early 4G boot pagetable | ||
109 | */ | ||
110 | /* Initialize Page tables to 0*/ | ||
111 | leal pgtable(%ebx), %edi | ||
112 | xorl %eax, %eax | ||
113 | movl $((4096*6)/4), %ecx | ||
114 | rep stosl | ||
115 | |||
116 | /* Build Level 4 */ | ||
117 | leal pgtable + 0(%ebx), %edi | ||
118 | leal 0x1007 (%edi), %eax | ||
119 | movl %eax, 0(%edi) | ||
120 | |||
121 | /* Build Level 3 */ | ||
122 | leal pgtable + 0x1000(%ebx), %edi | ||
123 | leal 0x1007(%edi), %eax | ||
124 | movl $4, %ecx | ||
125 | 1: movl %eax, 0x00(%edi) | ||
126 | addl $0x00001000, %eax | ||
127 | addl $8, %edi | ||
128 | decl %ecx | ||
129 | jnz 1b | ||
130 | |||
131 | /* Build Level 2 */ | ||
132 | leal pgtable + 0x2000(%ebx), %edi | ||
133 | movl $0x00000183, %eax | ||
134 | movl $2048, %ecx | ||
135 | 1: movl %eax, 0(%edi) | ||
136 | addl $0x00200000, %eax | ||
137 | addl $8, %edi | ||
138 | decl %ecx | ||
139 | jnz 1b | ||
140 | |||
141 | /* Enable the boot page tables */ | ||
142 | leal pgtable(%ebx), %eax | ||
143 | movl %eax, %cr3 | ||
144 | |||
145 | /* Enable Long mode in EFER (Extended Feature Enable Register) */ | ||
146 | movl $MSR_EFER, %ecx | ||
147 | rdmsr | ||
148 | btsl $_EFER_LME, %eax | ||
149 | wrmsr | ||
150 | |||
151 | /* Setup for the jump to 64bit mode | ||
152 | * | ||
153 | * When the jump is performend we will be in long mode but | ||
154 | * in 32bit compatibility mode with EFER.LME = 1, CS.L = 0, CS.D = 1 | ||
155 | * (and in turn EFER.LMA = 1). To jump into 64bit mode we use | ||
156 | * the new gdt/idt that has __KERNEL_CS with CS.L = 1. | ||
157 | * We place all of the values on our mini stack so lret can | ||
158 | * used to perform that far jump. | ||
159 | */ | ||
160 | pushl $__KERNEL_CS | ||
161 | leal startup_64(%ebp), %eax | ||
162 | pushl %eax | ||
163 | |||
164 | /* Enter paged protected Mode, activating Long Mode */ | ||
165 | movl $0x80000001, %eax /* Enable Paging and Protected mode */ | ||
166 | movl %eax, %cr0 | ||
167 | |||
168 | /* Jump from 32bit compatibility mode into 64bit mode. */ | ||
169 | lret | ||
170 | |||
171 | no_longmode: | ||
172 | /* This isn't an x86-64 CPU so hang */ | ||
173 | 1: | ||
174 | hlt | ||
175 | jmp 1b | ||
176 | |||
177 | #include "../../../x86_64/kernel/verify_cpu_64.S" | ||
178 | |||
179 | /* Be careful here startup_64 needs to be at a predictable | ||
180 | * address so I can export it in an ELF header. Bootloaders | ||
181 | * should look at the ELF header to find this address, as | ||
182 | * it may change in the future. | ||
183 | */ | ||
184 | .code64 | ||
185 | .org 0x200 | ||
186 | ENTRY(startup_64) | ||
187 | /* We come here either from startup_32 or directly from a | ||
188 | * 64bit bootloader. If we come here from a bootloader we depend on | ||
189 | * an identity mapped page table being provied that maps our | ||
190 | * entire text+data+bss and hopefully all of memory. | ||
191 | */ | ||
192 | |||
193 | /* Setup data segments. */ | ||
194 | xorl %eax, %eax | ||
195 | movl %eax, %ds | ||
196 | movl %eax, %es | ||
197 | movl %eax, %ss | ||
198 | movl %eax, %fs | ||
199 | movl %eax, %gs | ||
200 | lldt %ax | ||
201 | movl $0x20, %eax | ||
202 | ltr %ax | ||
203 | |||
204 | /* Compute the decompressed kernel start address. It is where | ||
205 | * we were loaded at aligned to a 2M boundary. %rbp contains the | ||
206 | * decompressed kernel start address. | ||
207 | * | ||
208 | * If it is a relocatable kernel then decompress and run the kernel | ||
209 | * from load address aligned to 2MB addr, otherwise decompress and | ||
210 | * run the kernel from CONFIG_PHYSICAL_START | ||
211 | */ | ||
212 | |||
213 | /* Start with the delta to where the kernel will run at. */ | ||
214 | #ifdef CONFIG_RELOCATABLE | ||
215 | leaq startup_32(%rip) /* - $startup_32 */, %rbp | ||
216 | addq $(LARGE_PAGE_SIZE - 1), %rbp | ||
217 | andq $LARGE_PAGE_MASK, %rbp | ||
218 | movq %rbp, %rbx | ||
219 | #else | ||
220 | movq $CONFIG_PHYSICAL_START, %rbp | ||
221 | movq %rbp, %rbx | ||
222 | #endif | ||
223 | |||
224 | /* Replace the compressed data size with the uncompressed size */ | ||
225 | movl input_len(%rip), %eax | ||
226 | subq %rax, %rbx | ||
227 | movl output_len(%rip), %eax | ||
228 | addq %rax, %rbx | ||
229 | /* Add 8 bytes for every 32K input block */ | ||
230 | shrq $12, %rax | ||
231 | addq %rax, %rbx | ||
232 | /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */ | ||
233 | addq $(32768 + 18 + 4095), %rbx | ||
234 | andq $~4095, %rbx | ||
235 | |||
236 | /* Copy the compressed kernel to the end of our buffer | ||
237 | * where decompression in place becomes safe. | ||
238 | */ | ||
239 | leaq _end(%rip), %r8 | ||
240 | leaq _end(%rbx), %r9 | ||
241 | movq $_end /* - $startup_32 */, %rcx | ||
242 | 1: subq $8, %r8 | ||
243 | subq $8, %r9 | ||
244 | movq 0(%r8), %rax | ||
245 | movq %rax, 0(%r9) | ||
246 | subq $8, %rcx | ||
247 | jnz 1b | ||
248 | |||
249 | /* | ||
250 | * Jump to the relocated address. | ||
251 | */ | ||
252 | leaq relocated(%rbx), %rax | ||
253 | jmp *%rax | ||
254 | |||
255 | .section ".text" | ||
256 | relocated: | ||
257 | |||
258 | /* | ||
259 | * Clear BSS | ||
260 | */ | ||
261 | xorq %rax, %rax | ||
262 | leaq _edata(%rbx), %rdi | ||
263 | leaq _end(%rbx), %rcx | ||
264 | subq %rdi, %rcx | ||
265 | cld | ||
266 | rep | ||
267 | stosb | ||
268 | |||
269 | /* Setup the stack */ | ||
270 | leaq user_stack_end(%rip), %rsp | ||
271 | |||
272 | /* zero EFLAGS after setting rsp */ | ||
273 | pushq $0 | ||
274 | popfq | ||
275 | |||
276 | /* | ||
277 | * Do the decompression, and jump to the new kernel.. | ||
278 | */ | ||
279 | pushq %rsi # Save the real mode argument | ||
280 | movq %rsi, %rdi # real mode address | ||
281 | leaq _heap(%rip), %rsi # _heap | ||
282 | leaq input_data(%rip), %rdx # input_data | ||
283 | movl input_len(%rip), %eax | ||
284 | movq %rax, %rcx # input_len | ||
285 | movq %rbp, %r8 # output | ||
286 | call decompress_kernel | ||
287 | popq %rsi | ||
288 | |||
289 | |||
290 | /* | ||
291 | * Jump to the decompressed kernel. | ||
292 | */ | ||
293 | jmp *%rbp | ||
294 | |||
295 | .data | ||
296 | gdt: | ||
297 | .word gdt_end - gdt | ||
298 | .long gdt | ||
299 | .word 0 | ||
300 | .quad 0x0000000000000000 /* NULL descriptor */ | ||
301 | .quad 0x00af9a000000ffff /* __KERNEL_CS */ | ||
302 | .quad 0x00cf92000000ffff /* __KERNEL_DS */ | ||
303 | .quad 0x0080890000000000 /* TS descriptor */ | ||
304 | .quad 0x0000000000000000 /* TS continued */ | ||
305 | gdt_end: | ||
306 | .bss | ||
307 | /* Stack for uncompression */ | ||
308 | .balign 4 | ||
309 | user_stack: | ||
310 | .fill 4096,4,0 | ||
311 | user_stack_end: | ||
diff --git a/arch/x86/boot/compressed/misc_64.c b/arch/x86/boot/compressed/misc_64.c new file mode 100644 index 000000000000..f932b0e89096 --- /dev/null +++ b/arch/x86/boot/compressed/misc_64.c | |||
@@ -0,0 +1,371 @@ | |||
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 | #define _LINUX_STRING_H_ 1 | ||
13 | #define __LINUX_BITMAP_H 1 | ||
14 | |||
15 | #include <linux/linkage.h> | ||
16 | #include <linux/screen_info.h> | ||
17 | #include <asm/io.h> | ||
18 | #include <asm/page.h> | ||
19 | |||
20 | /* WARNING!! | ||
21 | * This code is compiled with -fPIC and it is relocated dynamically | ||
22 | * at run time, but no relocation processing is performed. | ||
23 | * This means that it is not safe to place pointers in static structures. | ||
24 | */ | ||
25 | |||
26 | /* | ||
27 | * Getting to provable safe in place decompression is hard. | ||
28 | * Worst case behaviours need to be analized. | ||
29 | * Background information: | ||
30 | * | ||
31 | * The file layout is: | ||
32 | * magic[2] | ||
33 | * method[1] | ||
34 | * flags[1] | ||
35 | * timestamp[4] | ||
36 | * extraflags[1] | ||
37 | * os[1] | ||
38 | * compressed data blocks[N] | ||
39 | * crc[4] orig_len[4] | ||
40 | * | ||
41 | * resulting in 18 bytes of non compressed data overhead. | ||
42 | * | ||
43 | * Files divided into blocks | ||
44 | * 1 bit (last block flag) | ||
45 | * 2 bits (block type) | ||
46 | * | ||
47 | * 1 block occurs every 32K -1 bytes or when there 50% compression has been achieved. | ||
48 | * The smallest block type encoding is always used. | ||
49 | * | ||
50 | * stored: | ||
51 | * 32 bits length in bytes. | ||
52 | * | ||
53 | * fixed: | ||
54 | * magic fixed tree. | ||
55 | * symbols. | ||
56 | * | ||
57 | * dynamic: | ||
58 | * dynamic tree encoding. | ||
59 | * symbols. | ||
60 | * | ||
61 | * | ||
62 | * The buffer for decompression in place is the length of the | ||
63 | * uncompressed data, plus a small amount extra to keep the algorithm safe. | ||
64 | * The compressed data is placed at the end of the buffer. The output | ||
65 | * pointer is placed at the start of the buffer and the input pointer | ||
66 | * is placed where the compressed data starts. Problems will occur | ||
67 | * when the output pointer overruns the input pointer. | ||
68 | * | ||
69 | * The output pointer can only overrun the input pointer if the input | ||
70 | * pointer is moving faster than the output pointer. A condition only | ||
71 | * triggered by data whose compressed form is larger than the uncompressed | ||
72 | * form. | ||
73 | * | ||
74 | * The worst case at the block level is a growth of the compressed data | ||
75 | * of 5 bytes per 32767 bytes. | ||
76 | * | ||
77 | * The worst case internal to a compressed block is very hard to figure. | ||
78 | * The worst case can at least be boundined by having one bit that represents | ||
79 | * 32764 bytes and then all of the rest of the bytes representing the very | ||
80 | * very last byte. | ||
81 | * | ||
82 | * All of which is enough to compute an amount of extra data that is required | ||
83 | * to be safe. To avoid problems at the block level allocating 5 extra bytes | ||
84 | * per 32767 bytes of data is sufficient. To avoind problems internal to a block | ||
85 | * adding an extra 32767 bytes (the worst case uncompressed block size) is | ||
86 | * sufficient, to ensure that in the worst case the decompressed data for | ||
87 | * block will stop the byte before the compressed data for a block begins. | ||
88 | * To avoid problems with the compressed data's meta information an extra 18 | ||
89 | * bytes are needed. Leading to the formula: | ||
90 | * | ||
91 | * extra_bytes = (uncompressed_size >> 12) + 32768 + 18 + decompressor_size. | ||
92 | * | ||
93 | * Adding 8 bytes per 32K is a bit excessive but much easier to calculate. | ||
94 | * Adding 32768 instead of 32767 just makes for round numbers. | ||
95 | * Adding the decompressor_size is necessary as it musht live after all | ||
96 | * of the data as well. Last I measured the decompressor is about 14K. | ||
97 | * 10K of actuall data and 4K of bss. | ||
98 | * | ||
99 | */ | ||
100 | |||
101 | /* | ||
102 | * gzip declarations | ||
103 | */ | ||
104 | |||
105 | #define OF(args) args | ||
106 | #define STATIC static | ||
107 | |||
108 | #undef memset | ||
109 | #undef memcpy | ||
110 | #define memzero(s, n) memset ((s), 0, (n)) | ||
111 | |||
112 | typedef unsigned char uch; | ||
113 | typedef unsigned short ush; | ||
114 | typedef unsigned long ulg; | ||
115 | |||
116 | #define WSIZE 0x80000000 /* Window size must be at least 32k, | ||
117 | * and a power of two | ||
118 | * We don't actually have a window just | ||
119 | * a huge output buffer so I report | ||
120 | * a 2G windows size, as that should | ||
121 | * always be larger than our output buffer. | ||
122 | */ | ||
123 | |||
124 | static uch *inbuf; /* input buffer */ | ||
125 | static uch *window; /* Sliding window buffer, (and final output buffer) */ | ||
126 | |||
127 | static unsigned insize; /* valid bytes in inbuf */ | ||
128 | static unsigned inptr; /* index of next byte to be processed in inbuf */ | ||
129 | static unsigned outcnt; /* bytes in output buffer */ | ||
130 | |||
131 | /* gzip flag byte */ | ||
132 | #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */ | ||
133 | #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ | ||
134 | #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ | ||
135 | #define ORIG_NAME 0x08 /* bit 3 set: original file name present */ | ||
136 | #define COMMENT 0x10 /* bit 4 set: file comment present */ | ||
137 | #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ | ||
138 | #define RESERVED 0xC0 /* bit 6,7: reserved */ | ||
139 | |||
140 | #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) | ||
141 | |||
142 | /* Diagnostic functions */ | ||
143 | #ifdef DEBUG | ||
144 | # define Assert(cond,msg) {if(!(cond)) error(msg);} | ||
145 | # define Trace(x) fprintf x | ||
146 | # define Tracev(x) {if (verbose) fprintf x ;} | ||
147 | # define Tracevv(x) {if (verbose>1) fprintf x ;} | ||
148 | # define Tracec(c,x) {if (verbose && (c)) fprintf x ;} | ||
149 | # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} | ||
150 | #else | ||
151 | # define Assert(cond,msg) | ||
152 | # define Trace(x) | ||
153 | # define Tracev(x) | ||
154 | # define Tracevv(x) | ||
155 | # define Tracec(c,x) | ||
156 | # define Tracecv(c,x) | ||
157 | #endif | ||
158 | |||
159 | static int fill_inbuf(void); | ||
160 | static void flush_window(void); | ||
161 | static void error(char *m); | ||
162 | static void gzip_mark(void **); | ||
163 | static void gzip_release(void **); | ||
164 | |||
165 | /* | ||
166 | * This is set up by the setup-routine at boot-time | ||
167 | */ | ||
168 | static unsigned char *real_mode; /* Pointer to real-mode data */ | ||
169 | |||
170 | #define RM_EXT_MEM_K (*(unsigned short *)(real_mode + 0x2)) | ||
171 | #ifndef STANDARD_MEMORY_BIOS_CALL | ||
172 | #define RM_ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0)) | ||
173 | #endif | ||
174 | #define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0)) | ||
175 | |||
176 | extern unsigned char input_data[]; | ||
177 | extern int input_len; | ||
178 | |||
179 | static long bytes_out = 0; | ||
180 | |||
181 | static void *malloc(int size); | ||
182 | static void free(void *where); | ||
183 | |||
184 | static void *memset(void *s, int c, unsigned n); | ||
185 | static void *memcpy(void *dest, const void *src, unsigned n); | ||
186 | |||
187 | static void putstr(const char *); | ||
188 | |||
189 | static long free_mem_ptr; | ||
190 | static long free_mem_end_ptr; | ||
191 | |||
192 | #define HEAP_SIZE 0x7000 | ||
193 | |||
194 | static char *vidmem = (char *)0xb8000; | ||
195 | static int vidport; | ||
196 | static int lines, cols; | ||
197 | |||
198 | #include "../../../../lib/inflate.c" | ||
199 | |||
200 | static void *malloc(int size) | ||
201 | { | ||
202 | void *p; | ||
203 | |||
204 | if (size <0) error("Malloc error"); | ||
205 | if (free_mem_ptr <= 0) error("Memory error"); | ||
206 | |||
207 | free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ | ||
208 | |||
209 | p = (void *)free_mem_ptr; | ||
210 | free_mem_ptr += size; | ||
211 | |||
212 | if (free_mem_ptr >= free_mem_end_ptr) | ||
213 | error("Out of memory"); | ||
214 | |||
215 | return p; | ||
216 | } | ||
217 | |||
218 | static void free(void *where) | ||
219 | { /* Don't care */ | ||
220 | } | ||
221 | |||
222 | static void gzip_mark(void **ptr) | ||
223 | { | ||
224 | *ptr = (void *) free_mem_ptr; | ||
225 | } | ||
226 | |||
227 | static void gzip_release(void **ptr) | ||
228 | { | ||
229 | free_mem_ptr = (long) *ptr; | ||
230 | } | ||
231 | |||
232 | static void scroll(void) | ||
233 | { | ||
234 | int i; | ||
235 | |||
236 | memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 ); | ||
237 | for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 ) | ||
238 | vidmem[i] = ' '; | ||
239 | } | ||
240 | |||
241 | static void putstr(const char *s) | ||
242 | { | ||
243 | int x,y,pos; | ||
244 | char c; | ||
245 | |||
246 | x = RM_SCREEN_INFO.orig_x; | ||
247 | y = RM_SCREEN_INFO.orig_y; | ||
248 | |||
249 | while ( ( c = *s++ ) != '\0' ) { | ||
250 | if ( c == '\n' ) { | ||
251 | x = 0; | ||
252 | if ( ++y >= lines ) { | ||
253 | scroll(); | ||
254 | y--; | ||
255 | } | ||
256 | } else { | ||
257 | vidmem [ ( x + cols * y ) * 2 ] = c; | ||
258 | if ( ++x >= cols ) { | ||
259 | x = 0; | ||
260 | if ( ++y >= lines ) { | ||
261 | scroll(); | ||
262 | y--; | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | } | ||
267 | |||
268 | RM_SCREEN_INFO.orig_x = x; | ||
269 | RM_SCREEN_INFO.orig_y = y; | ||
270 | |||
271 | pos = (x + cols * y) * 2; /* Update cursor position */ | ||
272 | outb_p(14, vidport); | ||
273 | outb_p(0xff & (pos >> 9), vidport+1); | ||
274 | outb_p(15, vidport); | ||
275 | outb_p(0xff & (pos >> 1), vidport+1); | ||
276 | } | ||
277 | |||
278 | static void* memset(void* s, int c, unsigned n) | ||
279 | { | ||
280 | int i; | ||
281 | char *ss = (char*)s; | ||
282 | |||
283 | for (i=0;i<n;i++) ss[i] = c; | ||
284 | return s; | ||
285 | } | ||
286 | |||
287 | static void* memcpy(void* dest, const void* src, unsigned n) | ||
288 | { | ||
289 | int i; | ||
290 | char *d = (char *)dest, *s = (char *)src; | ||
291 | |||
292 | for (i=0;i<n;i++) d[i] = s[i]; | ||
293 | return dest; | ||
294 | } | ||
295 | |||
296 | /* =========================================================================== | ||
297 | * Fill the input buffer. This is called only when the buffer is empty | ||
298 | * and at least one byte is really needed. | ||
299 | */ | ||
300 | static int fill_inbuf(void) | ||
301 | { | ||
302 | error("ran out of input data"); | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | /* =========================================================================== | ||
307 | * Write the output window window[0..outcnt-1] and update crc and bytes_out. | ||
308 | * (Used for the decompressed data only.) | ||
309 | */ | ||
310 | static void flush_window(void) | ||
311 | { | ||
312 | /* With my window equal to my output buffer | ||
313 | * I only need to compute the crc here. | ||
314 | */ | ||
315 | ulg c = crc; /* temporary variable */ | ||
316 | unsigned n; | ||
317 | uch *in, ch; | ||
318 | |||
319 | in = window; | ||
320 | for (n = 0; n < outcnt; n++) { | ||
321 | ch = *in++; | ||
322 | c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8); | ||
323 | } | ||
324 | crc = c; | ||
325 | bytes_out += (ulg)outcnt; | ||
326 | outcnt = 0; | ||
327 | } | ||
328 | |||
329 | static void error(char *x) | ||
330 | { | ||
331 | putstr("\n\n"); | ||
332 | putstr(x); | ||
333 | putstr("\n\n -- System halted"); | ||
334 | |||
335 | while(1); /* Halt */ | ||
336 | } | ||
337 | |||
338 | asmlinkage void decompress_kernel(void *rmode, unsigned long heap, | ||
339 | uch *input_data, unsigned long input_len, uch *output) | ||
340 | { | ||
341 | real_mode = rmode; | ||
342 | |||
343 | if (RM_SCREEN_INFO.orig_video_mode == 7) { | ||
344 | vidmem = (char *) 0xb0000; | ||
345 | vidport = 0x3b4; | ||
346 | } else { | ||
347 | vidmem = (char *) 0xb8000; | ||
348 | vidport = 0x3d4; | ||
349 | } | ||
350 | |||
351 | lines = RM_SCREEN_INFO.orig_video_lines; | ||
352 | cols = RM_SCREEN_INFO.orig_video_cols; | ||
353 | |||
354 | window = output; /* Output buffer (Normally at 1M) */ | ||
355 | free_mem_ptr = heap; /* Heap */ | ||
356 | free_mem_end_ptr = heap + HEAP_SIZE; | ||
357 | inbuf = input_data; /* Input buffer */ | ||
358 | insize = input_len; | ||
359 | inptr = 0; | ||
360 | |||
361 | if ((ulg)output & (__KERNEL_ALIGN - 1)) | ||
362 | error("Destination address not 2M aligned"); | ||
363 | if ((ulg)output >= 0xffffffffffUL) | ||
364 | error("Destination address too large"); | ||
365 | |||
366 | makecrc(); | ||
367 | putstr(".\nDecompressing Linux..."); | ||
368 | gunzip(); | ||
369 | putstr("done.\nBooting the kernel.\n"); | ||
370 | return; | ||
371 | } | ||
diff --git a/arch/x86/boot/compressed/vmlinux_64.lds b/arch/x86/boot/compressed/vmlinux_64.lds new file mode 100644 index 000000000000..94c13e557fb4 --- /dev/null +++ b/arch/x86/boot/compressed/vmlinux_64.lds | |||
@@ -0,0 +1,44 @@ | |||
1 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") | ||
2 | OUTPUT_ARCH(i386:x86-64) | ||
3 | ENTRY(startup_64) | ||
4 | SECTIONS | ||
5 | { | ||
6 | /* Be careful parts of head.S assume startup_32 is at | ||
7 | * address 0. | ||
8 | */ | ||
9 | . = 0; | ||
10 | .text : { | ||
11 | _head = . ; | ||
12 | *(.text.head) | ||
13 | _ehead = . ; | ||
14 | *(.text.compressed) | ||
15 | _text = .; /* Text */ | ||
16 | *(.text) | ||
17 | *(.text.*) | ||
18 | _etext = . ; | ||
19 | } | ||
20 | .rodata : { | ||
21 | _rodata = . ; | ||
22 | *(.rodata) /* read-only data */ | ||
23 | *(.rodata.*) | ||
24 | _erodata = . ; | ||
25 | } | ||
26 | .data : { | ||
27 | _data = . ; | ||
28 | *(.data) | ||
29 | *(.data.*) | ||
30 | _edata = . ; | ||
31 | } | ||
32 | .bss : { | ||
33 | _bss = . ; | ||
34 | *(.bss) | ||
35 | *(.bss.*) | ||
36 | *(COMMON) | ||
37 | . = ALIGN(8); | ||
38 | _end = . ; | ||
39 | . = ALIGN(4096); | ||
40 | pgtable = . ; | ||
41 | . = . + 4096 * 6; | ||
42 | _heap = .; | ||
43 | } | ||
44 | } | ||
diff --git a/arch/x86/boot/compressed/vmlinux_64.scr b/arch/x86/boot/compressed/vmlinux_64.scr new file mode 100644 index 000000000000..bd1429ce193e --- /dev/null +++ b/arch/x86/boot/compressed/vmlinux_64.scr | |||
@@ -0,0 +1,10 @@ | |||
1 | SECTIONS | ||
2 | { | ||
3 | .text.compressed : { | ||
4 | input_len = .; | ||
5 | LONG(input_data_end - input_data) input_data = .; | ||
6 | *(.data) | ||
7 | output_len = . - 4; | ||
8 | input_data_end = .; | ||
9 | } | ||
10 | } | ||