4 * Copyright (C) 1991, 1992, 1993 Linus Torvalds
8 * head.S contains the 32-bit startup code.
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]
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
22 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
26 #include <linux/init.h>
27 #include <linux/linkage.h>
28 #include <asm/segment.h>
29 #include <asm/page_types.h>
31 #include <asm/asm-offsets.h>
35 #ifdef CONFIG_EFI_STUB
39 * We don't need the return address, so set up the stack so
40 * efi_main() can find its arguments.
50 movl %ecx, efi32_config(%esi) /* Handle */
52 movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
54 /* Relocate efi_config->call() */
55 leal efi32_config(%esi), %eax
65 jmp 2f /* Skip efi_config initialization */
67 ENTRY(efi32_stub_entry)
76 movl %ecx, efi32_config(%esi) /* Handle */
77 movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
79 /* Relocate efi_config->call() */
80 leal efi32_config(%esi), %eax
89 /* EFI init failed, so hang. */
97 subl BP_pref_address(%esi), %eax
98 add BP_code32_start(%esi), %eax
99 leal preferred_addr(%eax), %eax
106 * Test KEEP_SEGMENTS flag to see if the bootloader is asking
107 * us to not reload segments
109 testb $(1<<6), BP_loadflags(%esi)
113 movl $__BOOT_DS, %eax
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.
129 leal (BP_scratch+4)(%esi), %esp
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.
140 #ifdef CONFIG_RELOCATABLE
142 movl BP_kernel_alignment(%esi), %eax
147 cmpl $LOAD_PHYSICAL_ADDR, %ebx
150 movl $LOAD_PHYSICAL_ADDR, %ebx
153 /* Target address to relocate to for decompression */
154 addl $z_extract_offset, %ebx
156 /* Set up the stack */
157 leal boot_stack_end(%ebx), %esp
164 * Copy the compressed kernel to the end of our buffer
165 * where decompression in place becomes safe.
168 leal (_bss-4)(%ebp), %esi
169 leal (_bss-4)(%ebx), %edi
170 movl $(_bss - startup_32), %ecx
178 * Jump to the relocated address.
180 leal relocated(%ebx), %eax
188 * Clear BSS (stack is currently empty)
191 leal _bss(%ebx), %edi
192 leal _ebss(%ebx), %ecx
200 leal _got(%ebx), %edx
201 leal _egot(%ebx), %ecx
211 * Do the decompression, and jump to the new kernel..
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 */
227 * Jump to the decompressed kernel.
232 #ifdef CONFIG_EFI_STUB
242 * Stack and heap for uncompression
247 .fill BOOT_HEAP_SIZE, 1, 0
249 .fill BOOT_STACK_SIZE, 1, 0