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/linkage.h>
27 #include <asm/segment.h>
36 movl $(__BOOT_DS),%eax
43 /* Calculate the delta between where we were compiled to run
44 * at and where we were actually loaded at. This can only be done
45 * with a short local call on x86. Nothing else will tell us what
46 * address we are running at. The reserved chunk of the real-mode
47 * data at 0x34-0x3f are used as the stack for this calculation.
48 * Only 4 bytes are needed.
55 /* Compute the delta between where we were compiled to run at
56 * and where the code will actually run at.
58 /* Start with the delta to where the kernel will run at. If we are
59 * a relocatable kernel this is the delta to our load address otherwise
60 * this is the delta to CONFIG_PHYSICAL start.
62 #ifdef CONFIG_RELOCATABLE
65 movl $(CONFIG_PHYSICAL_START - startup_32), %ebx
68 /* Replace the compressed data size with the uncompressed size */
69 subl input_len(%ebp), %ebx
70 movl output_len(%ebp), %eax
72 /* Add 8 bytes for every 32K input block */
75 /* Add 32K + 18 bytes of extra slack */
76 addl $(32768 + 18), %ebx
77 /* Align on a 4K boundary */
81 /* Copy the compressed kernel to the end of our buffer
82 * where decompression in place becomes safe.
87 movl $(_end - startup_32), %ecx
94 /* Compute the kernel start address.
96 #ifdef CONFIG_RELOCATABLE
97 leal startup_32(%ebp), %ebp
99 movl $CONFIG_PHYSICAL_START, %ebp
103 * Jump to the relocated address.
105 leal relocated(%ebx), %eax
114 leal _edata(%ebx),%edi
115 leal _end(%ebx), %ecx
122 * Setup the stack for the decompressor
124 leal stack_end(%ebx), %esp
127 * Do the decompression, and jump to the new kernel..
129 movl output_len(%ebx), %eax
131 pushl %ebp # output address
132 movl input_len(%ebx), %eax
133 pushl %eax # input_len
134 leal input_data(%ebx), %eax
135 pushl %eax # input_data
136 leal _end(%ebx), %eax
137 pushl %eax # end of the image as third argument
138 pushl %esi # real mode pointer as second arg
139 call decompress_kernel
143 #if CONFIG_RELOCATABLE
144 /* Find the address of the relocations.
149 /* Calculate the delta between where vmlinux was compiled to run
150 * and where it was actually loaded.
153 subl $CONFIG_PHYSICAL_START, %ebx
156 * Process relocations.
163 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
169 * Jump to the decompressed kernel.