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>
36 * The relocation base must be in %ebx
38 * It is safe to call this macro more than once, because in some of the
39 * code paths multiple invocations are inevitable, e.g. via the efi*
42 * Relocation is only performed the first time.
45 cmpb $1, got_fixed(%ebx)
49 leal _egot(%ebx), %ecx
57 movb $1, got_fixed(%ebx)
62 #ifdef CONFIG_EFI_STUB
66 * We don't need the return address, so set up the stack so
67 * efi_main() can find its arguments.
77 movl %ecx, efi32_config(%esi) /* Handle */
79 movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
81 /* Relocate efi_config->call() */
82 leal efi32_config(%esi), %eax
92 movl %esi, BP_code32_start(%eax)
96 jmp 2f /* Skip efi_config initialization */
98 ENTRY(efi32_stub_entry)
107 movl %ecx, efi32_config(%esi) /* Handle */
108 movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
110 /* Relocate efi_config->call() */
111 leal efi32_config(%esi), %eax
124 /* EFI init failed, so hang. */
128 movl BP_code32_start(%esi), %eax
129 leal preferred_addr(%eax), %eax
136 * Test KEEP_SEGMENTS flag to see if the bootloader is asking
137 * us to not reload segments
139 testb $(1<<6), BP_loadflags(%esi)
143 movl $__BOOT_DS, %eax
152 * Calculate the delta between where we were compiled to run
153 * at and where we were actually loaded at. This can only be done
154 * with a short local call on x86. Nothing else will tell us what
155 * address we are running at. The reserved chunk of the real-mode
156 * data at 0x1e4 (defined as a scratch field) are used as the stack
157 * for this calculation. Only 4 bytes are needed.
159 leal (BP_scratch+4)(%esi), %esp
165 * %ebp contains the address we are loaded at by the boot loader and %ebx
166 * contains the address where we should move the kernel image temporarily
167 * for safe in-place decompression.
170 #ifdef CONFIG_RELOCATABLE
172 movl BP_kernel_alignment(%esi), %eax
177 cmpl $LOAD_PHYSICAL_ADDR, %ebx
180 movl $LOAD_PHYSICAL_ADDR, %ebx
183 /* Target address to relocate to for decompression */
184 addl $z_extract_offset, %ebx
186 /* Set up the stack */
187 leal boot_stack_end(%ebx), %esp
194 * Copy the compressed kernel to the end of our buffer
195 * where decompression in place becomes safe.
198 leal (_bss-4)(%ebp), %esi
199 leal (_bss-4)(%ebx), %edi
200 movl $(_bss - startup_32), %ecx
208 * Jump to the relocated address.
210 leal relocated(%ebx), %eax
218 * Clear BSS (stack is currently empty)
221 leal _bss(%ebx), %edi
222 leal _ebss(%ebx), %ecx
229 * Do the decompression, and jump to the new kernel..
231 /* push arguments for decompress_kernel: */
232 pushl $z_output_len /* decompressed length */
233 leal z_extract_offset_negative(%ebx), %ebp
234 pushl %ebp /* output address */
235 pushl $z_input_len /* input_len */
236 leal input_data(%ebx), %eax
237 pushl %eax /* input_data */
238 leal boot_heap(%ebx), %eax
239 pushl %eax /* heap area */
240 pushl %esi /* real mode pointer */
241 call decompress_kernel /* returns kernel location in %eax */
245 * Jump to the decompressed kernel.
251 /* Have we relocated the GOT? */
255 #ifdef CONFIG_EFI_STUB
264 * Stack and heap for uncompression
269 .fill BOOT_HEAP_SIZE, 1, 0
271 .fill BOOT_STACK_SIZE, 1, 0