4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * Based on bootsect.S and setup.S
7 * modified by more people than can be counted
9 * Rewritten as a common file by H. Peter Anvin (Apr 2007)
11 * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
12 * addresses must be multiplied by 16 to obtain their respective linear
13 * addresses. To avoid confusion, linear addresses are written using leading
14 * hex while segment addresses are written as segment:offset.
18 #include <asm/segment.h>
19 #include <linux/utsrelease.h>
22 #include <asm/page_types.h>
23 #include <asm/setup.h>
27 BOOTSEG = 0x07C0 /* original address of boot-sector */
28 SYSSEG = 0x1000 /* historical load address >> 4 */
31 #define SVGA_MODE ASK_VGA
43 .section ".bstext", "ax"
45 .global bootsect_start
48 # Normalize the start address
49 ljmp $BOOTSEG, $start2
60 movw $bugger_off_msg, %si
72 # Allow the user to press a key, then reboot
77 # int 0x19 should never return. In case it does anyway,
78 # invoke the BIOS reset code...
81 .section ".bsdata", "a"
83 .ascii "Direct booting from floppy is no longer supported.\r\n"
84 .ascii "Please use a boot loader program instead.\r\n"
86 .ascii "Remove disk and press any key to reboot . . .\r\n"
90 # Kernel attributes; used by setup. This is part 1 of the
91 # header, from the old boot sector.
93 .section ".header", "a"
96 setup_sects: .byte 0 /* Filled in by build.c */
97 root_flags: .word ROOT_RDONLY
98 syssize: .long 0 /* Filled in by build.c */
99 ram_size: .word 0 /* Obsolete */
100 vid_mode: .word SVGA_MODE
101 root_dev: .word 0 /* Filled in by build.c */
102 boot_flag: .word 0xAA55
104 # offset 512, entry point
108 # Explicitly enter this as bytes, or the assembler
109 # tries to generate a 3-byte jump here, which causes
110 # everything else to push off to the wrong offset.
111 .byte 0xeb # short (2-byte) jump
112 .byte start_of_setup-1f
115 # Part 2 of the header, from the old setup.S
117 .ascii "HdrS" # header signature
118 .word 0x0209 # header version number (>= 0x0105)
119 # or else old loadlin-1.5 will fail)
120 .globl realmode_swtch
121 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
122 start_sys_seg: .word SYSSEG # obsolete and meaningless, but just
123 # in case something decided to "use" it
124 .word kernel_version-512 # pointing to kernel version string
125 # above section of header is compatible
126 # with loadlin-1.5 (header v1.5). Don't
129 type_of_loader: .byte 0 # 0 means ancient bootloader, newer
130 # bootloaders know to change this.
131 # See Documentation/i386/boot.txt for
134 # flags, unused bits must be zero (RFU) bit within loadflags
136 LOADED_HIGH = 1 # If set, the kernel is loaded high
137 CAN_USE_HEAP = 0x80 # If set, the loader also has set
138 # heap_end_ptr to tell how much
139 # space behind setup.S can be used for
141 # Only the loader knows what is free
144 setup_move_size: .word 0x8000 # size to move, when setup is not
145 # loaded at 0x90000. We will move setup
146 # to 0x90000 then just before jumping
147 # into the kernel. However, only the
148 # loader knows how much data behind
149 # us also needs to be loaded.
151 code32_start: # here loaders can put a different
152 # start address for 32-bit code.
153 .long 0x100000 # 0x100000 = default for big kernel
155 ramdisk_image: .long 0 # address of loaded ramdisk image
156 # Here the loader puts the 32-bit
157 # address where it loaded the image.
158 # This only will be read by the kernel.
160 ramdisk_size: .long 0 # its size in bytes
165 heap_end_ptr: .word _end+STACK_SIZE-512
166 # (Header version 0x0201 or later)
167 # space from here (exclusive) down to
168 # end of setup code can be used by setup
169 # for local heap purposes.
172 cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
173 # If nonzero, a 32-bit pointer
174 # to the kernel command line.
175 # The command line should be
176 # located between the start of
177 # setup and the end of low
178 # memory (0xa0000), or it may
179 # get overwritten before it
180 # gets read. If this field is
181 # used, there is no longer
182 # anything magical about the
183 # 0x90000 segment; the setup
184 # can be located anywhere in
185 # low memory 0x10000 or higher.
187 ramdisk_max: .long 0x7fffffff
188 # (Header version 0x0203 or later)
189 # The highest safe address for
190 # the contents of an initrd
191 # The current kernel allows up to 4 GB,
192 # but leave it at 2 GB to avoid
193 # possible bootloader bugs.
195 kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
196 #required for protected mode
198 #ifdef CONFIG_RELOCATABLE
199 relocatable_kernel: .byte 1
201 relocatable_kernel: .byte 0
206 cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
207 #added with boot protocol
210 hardware_subarch: .long 0 # subarchitecture, added with 2.07
211 # default to 0 for normal x86 PC
213 hardware_subarch_data: .quad 0
215 payload_offset: .long input_data
216 payload_length: .long input_data_end-input_data
218 setup_data: .quad 0 # 64-bit physical pointer to
219 # single linked list of
222 # End of setup header #####################################################
224 .section ".inittext", "ax"
226 #ifdef SAFE_RESET_DISK_CONTROLLER
227 # Reset the disk controller.
228 movw $0x0000, %ax # Reset disk controller
229 movb $0x80, %dl # All disks
238 # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
239 # which happened to work by accident for the old code. Recalculate the stack
240 # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
241 # stack behind its own code, so we can't blindly put it directly past the heap.
244 cmpw %ax, %dx # %ds == %ss?
246 je 2f # -> assume %sp is reasonably set
248 # Invalid %ss, make up a new stack
250 testb $CAN_USE_HEAP, loadflags
252 movw heap_end_ptr, %dx
253 1: addw $STACK_SIZE, %dx
255 xorw %dx, %dx # Prevent wraparound
257 2: # Now %dx should point to the end of our stack space
258 andw $~3, %dx # dword align (might as well...)
260 movw $0xfffc, %dx # Make sure we're not zero
262 movzwl %dx, %esp # Clear upper half of %esp
263 sti # Now we should have a working stack
265 # We will have entered with %cs = %ds+0x20, normalize %cs so
266 # it is on par with the other segments.
272 # Check signature at end of setup
273 cmpl $0x5a5aaa55, setup_sig
277 movw $__bss_start, %di
284 # Jump to C code (should not return)
287 # Setup corrupt somehow...
289 movl $setup_corrupt, %eax
301 .section ".initdata", "a"
304 .string "No setup signature found...\n"