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>
23 #include <asm/setup.h>
27 SETUPSECTS = 4 /* default nr of setup-sectors */
28 BOOTSEG = 0x07C0 /* original address of boot-sector */
29 SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */
30 SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */
32 ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */
33 SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */
36 #define SVGA_MODE ASK_VGA
48 .section ".bstext", "ax"
50 .global bootsect_start
53 # Normalize the start address
54 ljmp $BOOTSEG, $start2
65 movw $bugger_off_msg, %si
77 # Allow the user to press a key, then reboot
82 # int 0x19 should never return. In case it does anyway,
83 # invoke the BIOS reset code...
86 .section ".bsdata", "a"
88 .ascii "Direct booting from floppy is no longer supported.\r\n"
89 .ascii "Please use a boot loader program instead.\r\n"
91 .ascii "Remove disk and press any key to reboot . . .\r\n"
95 # Kernel attributes; used by setup. This is part 1 of the
96 # header, from the old boot sector.
98 .section ".header", "a"
101 setup_sects: .byte SETUPSECTS
102 root_flags: .word ROOT_RDONLY
103 syssize: .long SYSSIZE
104 ram_size: .word RAMDISK
105 vid_mode: .word SVGA_MODE
106 root_dev: .word ROOT_DEV
107 boot_flag: .word 0xAA55
109 # offset 512, entry point
113 # Explicitly enter this as bytes, or the assembler
114 # tries to generate a 3-byte jump here, which causes
115 # everything else to push off to the wrong offset.
116 .byte 0xeb # short (2-byte) jump
117 .byte start_of_setup-1f
120 # Part 2 of the header, from the old setup.S
122 .ascii "HdrS" # header signature
123 .word 0x0208 # header version number (>= 0x0105)
124 # or else old loadlin-1.5 will fail)
125 .globl realmode_swtch
126 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
127 start_sys_seg: .word SYSSEG
128 .word kernel_version-512 # pointing to kernel version string
129 # above section of header is compatible
130 # with loadlin-1.5 (header v1.5). Don't
133 type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
134 # Bootlin, SYSLX, bootsect...)
135 # See Documentation/i386/boot.txt for
138 # flags, unused bits must be zero (RFU) bit within loadflags
140 LOADED_HIGH = 1 # If set, the kernel is loaded high
141 CAN_USE_HEAP = 0x80 # If set, the loader also has set
142 # heap_end_ptr to tell how much
143 # space behind setup.S can be used for
145 # Only the loader knows what is free
146 #ifndef __BIG_KERNEL__
152 setup_move_size: .word 0x8000 # size to move, when setup is not
153 # loaded at 0x90000. We will move setup
154 # to 0x90000 then just before jumping
155 # into the kernel. However, only the
156 # loader knows how much data behind
157 # us also needs to be loaded.
159 code32_start: # here loaders can put a different
160 # start address for 32-bit code.
161 #ifndef __BIG_KERNEL__
162 .long 0x1000 # 0x1000 = default for zImage
164 .long 0x100000 # 0x100000 = default for big kernel
167 ramdisk_image: .long 0 # address of loaded ramdisk image
168 # Here the loader puts the 32-bit
169 # address where it loaded the image.
170 # This only will be read by the kernel.
172 ramdisk_size: .long 0 # its size in bytes
177 heap_end_ptr: .word _end+STACK_SIZE-512
178 # (Header version 0x0201 or later)
179 # space from here (exclusive) down to
180 # end of setup code can be used by setup
181 # for local heap purposes.
184 cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
185 # If nonzero, a 32-bit pointer
186 # to the kernel command line.
187 # The command line should be
188 # located between the start of
189 # setup and the end of low
190 # memory (0xa0000), or it may
191 # get overwritten before it
192 # gets read. If this field is
193 # used, there is no longer
194 # anything magical about the
195 # 0x90000 segment; the setup
196 # can be located anywhere in
197 # low memory 0x10000 or higher.
199 ramdisk_max: .long 0x7fffffff
200 # (Header version 0x0203 or later)
201 # The highest safe address for
202 # the contents of an initrd
203 # The current kernel allows up to 4 GB,
204 # but leave it at 2 GB to avoid
205 # possible bootloader bugs.
207 kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
208 #required for protected mode
210 #ifdef CONFIG_RELOCATABLE
211 relocatable_kernel: .byte 1
213 relocatable_kernel: .byte 0
218 cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
219 #added with boot protocol
222 hardware_subarch: .long 0 # subarchitecture, added with 2.07
223 # default to 0 for normal x86 PC
225 hardware_subarch_data: .quad 0
227 payload_offset: .long input_data
228 payload_length: .long input_data_end-input_data
230 # End of setup header #####################################################
232 .section ".inittext", "ax"
234 #ifdef SAFE_RESET_DISK_CONTROLLER
235 # Reset the disk controller.
236 movw $0x0000, %ax # Reset disk controller
237 movb $0x80, %dl # All disks
246 # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
247 # which happened to work by accident for the old code. Recalculate the stack
248 # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
249 # stack behind its own code, so we can't blindly put it directly past the heap.
252 cmpw %ax, %dx # %ds == %ss?
254 je 2f # -> assume %sp is reasonably set
256 # Invalid %ss, make up a new stack
258 testb $CAN_USE_HEAP, loadflags
260 movw heap_end_ptr, %dx
261 1: addw $STACK_SIZE, %dx
263 xorw %dx, %dx # Prevent wraparound
265 2: # Now %dx should point to the end of our stack space
266 andw $~3, %dx # dword align (might as well...)
268 movw $0xfffc, %dx # Make sure we're not zero
270 movzwl %dx, %esp # Clear upper half of %esp
271 sti # Now we should have a working stack
273 # We will have entered with %cs = %ds+0x20, normalize %cs so
274 # it is on par with the other segments.
280 # Check signature at end of setup
281 cmpl $0x5a5aaa55, setup_sig
285 movw $__bss_start, %di
292 # Jump to C code (should not return)
295 # Setup corrupt somehow...
297 movl $setup_corrupt, %eax
309 .section ".initdata", "a"
312 .string "No setup signature found...\n"