]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/x86/boot/compressed/head_32.S
Merge branch 'x86-hash-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / arch / x86 / boot / compressed / head_32.S
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         .text
25
26 #include <linux/init.h>
27 #include <linux/linkage.h>
28 #include <asm/segment.h>
29 #include <asm/page_types.h>
30 #include <asm/boot.h>
31 #include <asm/asm-offsets.h>
32
33         __HEAD
34 ENTRY(startup_32)
35 #ifdef CONFIG_EFI_STUB
36         jmp     preferred_addr
37
38         /*
39          * We don't need the return address, so set up the stack so
40          * efi_main() can find its arguments.
41          */
42 ENTRY(efi_pe_entry)
43         add     $0x4, %esp
44
45         call    1f
46 1:      popl    %esi
47         subl    $1b, %esi
48
49         popl    %ecx
50         movl    %ecx, efi32_config(%esi)        /* Handle */
51         popl    %ecx
52         movl    %ecx, efi32_config+8(%esi)      /* EFI System table pointer */
53
54         /* Relocate efi_config->call() */
55         leal    efi32_config(%esi), %eax
56         add     %esi, 88(%eax)
57         pushl   %eax
58
59         call    make_boot_params
60         cmpl    $0, %eax
61         je      fail
62         popl    %ecx
63         pushl   %eax
64         pushl   %ecx
65         jmp     2f              /* Skip efi_config initialization */
66
67 ENTRY(efi32_stub_entry)
68         add     $0x4, %esp
69         popl    %ecx
70         popl    %edx
71
72         call    1f
73 1:      popl    %esi
74         subl    $1b, %esi
75
76         movl    %ecx, efi32_config(%esi)        /* Handle */
77         movl    %edx, efi32_config+8(%esi)      /* EFI System table pointer */
78
79         /* Relocate efi_config->call() */
80         leal    efi32_config(%esi), %eax
81         add     %esi, 88(%eax)
82         pushl   %eax
83 2:
84         call    efi_main
85         cmpl    $0, %eax
86         movl    %eax, %esi
87         jne     2f
88 fail:
89         /* EFI init failed, so hang. */
90         hlt
91         jmp     fail
92 2:
93         call    3f
94 3:
95         popl    %eax
96         subl    $3b, %eax
97         subl    BP_pref_address(%esi), %eax
98         add     BP_code32_start(%esi), %eax
99         leal    preferred_addr(%eax), %eax
100         jmp     *%eax
101
102 preferred_addr:
103 #endif
104         cld
105         /*
106          * Test KEEP_SEGMENTS flag to see if the bootloader is asking
107          * us to not reload segments
108          */
109         testb   $(1<<6), BP_loadflags(%esi)
110         jnz     1f
111
112         cli
113         movl    $__BOOT_DS, %eax
114         movl    %eax, %ds
115         movl    %eax, %es
116         movl    %eax, %fs
117         movl    %eax, %gs
118         movl    %eax, %ss
119 1:
120
121 /*
122  * Calculate the delta between where we were compiled to run
123  * at and where we were actually loaded at.  This can only be done
124  * with a short local call on x86.  Nothing  else will tell us what
125  * address we are running at.  The reserved chunk of the real-mode
126  * data at 0x1e4 (defined as a scratch field) are used as the stack
127  * for this calculation. Only 4 bytes are needed.
128  */
129         leal    (BP_scratch+4)(%esi), %esp
130         call    1f
131 1:      popl    %ebp
132         subl    $1b, %ebp
133
134 /*
135  * %ebp contains the address we are loaded at by the boot loader and %ebx
136  * contains the address where we should move the kernel image temporarily
137  * for safe in-place decompression.
138  */
139
140 #ifdef CONFIG_RELOCATABLE
141         movl    %ebp, %ebx
142         movl    BP_kernel_alignment(%esi), %eax
143         decl    %eax
144         addl    %eax, %ebx
145         notl    %eax
146         andl    %eax, %ebx
147         cmpl    $LOAD_PHYSICAL_ADDR, %ebx
148         jge     1f
149 #endif
150         movl    $LOAD_PHYSICAL_ADDR, %ebx
151 1:
152
153         /* Target address to relocate to for decompression */
154         addl    $z_extract_offset, %ebx
155
156         /* Set up the stack */
157         leal    boot_stack_end(%ebx), %esp
158
159         /* Zero EFLAGS */
160         pushl   $0
161         popfl
162
163 /*
164  * Copy the compressed kernel to the end of our buffer
165  * where decompression in place becomes safe.
166  */
167         pushl   %esi
168         leal    (_bss-4)(%ebp), %esi
169         leal    (_bss-4)(%ebx), %edi
170         movl    $(_bss - startup_32), %ecx
171         shrl    $2, %ecx
172         std
173         rep     movsl
174         cld
175         popl    %esi
176
177 /*
178  * Jump to the relocated address.
179  */
180         leal    relocated(%ebx), %eax
181         jmp     *%eax
182 ENDPROC(startup_32)
183
184         .text
185 relocated:
186
187 /*
188  * Clear BSS (stack is currently empty)
189  */
190         xorl    %eax, %eax
191         leal    _bss(%ebx), %edi
192         leal    _ebss(%ebx), %ecx
193         subl    %edi, %ecx
194         shrl    $2, %ecx
195         rep     stosl
196
197 /*
198  * Adjust our own GOT
199  */
200         leal    _got(%ebx), %edx
201         leal    _egot(%ebx), %ecx
202 1:
203         cmpl    %ecx, %edx
204         jae     2f
205         addl    %ebx, (%edx)
206         addl    $4, %edx
207         jmp     1b
208 2:
209
210 /*
211  * Do the decompression, and jump to the new kernel..
212  */
213                                 /* push arguments for decompress_kernel: */
214         pushl   $z_output_len   /* decompressed length */
215         leal    z_extract_offset_negative(%ebx), %ebp
216         pushl   %ebp            /* output address */
217         pushl   $z_input_len    /* input_len */
218         leal    input_data(%ebx), %eax
219         pushl   %eax            /* input_data */
220         leal    boot_heap(%ebx), %eax
221         pushl   %eax            /* heap area */
222         pushl   %esi            /* real mode pointer */
223         call    decompress_kernel /* returns kernel location in %eax */
224         addl    $24, %esp
225
226 /*
227  * Jump to the decompressed kernel.
228  */
229         xorl    %ebx, %ebx
230         jmp     *%eax
231
232 #ifdef CONFIG_EFI_STUB
233         .data
234 efi32_config:
235         .fill 11,8,0
236         .long efi_call_phys
237         .long 0
238         .byte 0
239 #endif
240
241 /*
242  * Stack and heap for uncompression
243  */
244         .bss
245         .balign 4
246 boot_heap:
247         .fill BOOT_HEAP_SIZE, 1, 0
248 boot_stack:
249         .fill BOOT_STACK_SIZE, 1, 0
250 boot_stack_end: