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>
32 #include <asm/bootparam.h>
36 #ifdef CONFIG_EFI_STUB
40 * We don't need the return address, so set up the stack so
41 * efi_main() can find its arguments.
51 movl %ecx, efi32_config(%esi) /* Handle */
53 movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
55 /* Relocate efi_config->call() */
56 leal efi32_config(%esi), %eax
63 movl %esi, BP_code32_start(%eax)
67 jmp 2f /* Skip efi_config initialization */
69 ENTRY(efi32_stub_entry)
78 movl %ecx, efi32_config(%esi) /* Handle */
79 movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
81 /* Relocate efi_config->call() */
82 leal efi32_config(%esi), %eax
91 /* EFI init failed, so hang. */
95 movl BP_code32_start(%esi), %eax
96 leal preferred_addr(%eax), %eax
103 * Test KEEP_SEGMENTS flag to see if the bootloader is asking
104 * us to not reload segments
106 testb $KEEP_SEGMENTS, BP_loadflags(%esi)
110 movl $__BOOT_DS, %eax
119 * Calculate the delta between where we were compiled to run
120 * at and where we were actually loaded at. This can only be done
121 * with a short local call on x86. Nothing else will tell us what
122 * address we are running at. The reserved chunk of the real-mode
123 * data at 0x1e4 (defined as a scratch field) are used as the stack
124 * for this calculation. Only 4 bytes are needed.
126 leal (BP_scratch+4)(%esi), %esp
132 * %ebp contains the address we are loaded at by the boot loader and %ebx
133 * contains the address where we should move the kernel image temporarily
134 * for safe in-place decompression.
137 #ifdef CONFIG_RELOCATABLE
139 movl BP_kernel_alignment(%esi), %eax
144 cmpl $LOAD_PHYSICAL_ADDR, %ebx
147 movl $LOAD_PHYSICAL_ADDR, %ebx
150 /* Target address to relocate to for decompression */
151 addl $z_extract_offset, %ebx
153 /* Set up the stack */
154 leal boot_stack_end(%ebx), %esp
161 * Copy the compressed kernel to the end of our buffer
162 * where decompression in place becomes safe.
165 leal (_bss-4)(%ebp), %esi
166 leal (_bss-4)(%ebx), %edi
167 movl $(_bss - startup_32), %ecx
175 * Jump to the relocated address.
177 leal relocated(%ebx), %eax
185 * Clear BSS (stack is currently empty)
188 leal _bss(%ebx), %edi
189 leal _ebss(%ebx), %ecx
197 leal _got(%ebx), %edx
198 leal _egot(%ebx), %ecx
208 * Do the decompression, and jump to the new kernel..
210 /* push arguments for decompress_kernel: */
211 pushl $z_run_size /* size of kernel with .bss and .brk */
212 pushl $z_output_len /* decompressed length, end of relocs */
213 leal z_extract_offset_negative(%ebx), %ebp
214 pushl %ebp /* output address */
215 pushl $z_input_len /* input_len */
216 leal input_data(%ebx), %eax
217 pushl %eax /* input_data */
218 leal boot_heap(%ebx), %eax
219 pushl %eax /* heap area */
220 pushl %esi /* real mode pointer */
221 call decompress_kernel /* returns kernel location in %eax */
225 * Jump to the decompressed kernel.
230 #ifdef CONFIG_EFI_STUB
240 * Stack and heap for uncompression
245 .fill BOOT_HEAP_SIZE, 1, 0
247 .fill BOOT_STACK_SIZE, 1, 0