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" */
35 #define SVGA_MODE ASK_VGA
47 .section ".bstext", "ax"
49 .global bootsect_start
52 # Normalize the start address
53 ljmp $BOOTSEG, $start2
64 movw $bugger_off_msg, %si
76 # Allow the user to press a key, then reboot
81 # int 0x19 should never return. In case it does anyway,
82 # invoke the BIOS reset code...
85 .section ".bsdata", "a"
87 .ascii "Direct booting from floppy is no longer supported.\r\n"
88 .ascii "Please use a boot loader program instead.\r\n"
90 .ascii "Remove disk and press any key to reboot . . .\r\n"
94 # Kernel attributes; used by setup. This is part 1 of the
95 # header, from the old boot sector.
97 .section ".header", "a"
100 setup_sects: .byte SETUPSECTS
101 root_flags: .word ROOT_RDONLY
102 syssize: .long SYSSIZE
103 ram_size: .word RAMDISK
104 vid_mode: .word SVGA_MODE
105 root_dev: .word ROOT_DEV
106 boot_flag: .word 0xAA55
108 # offset 512, entry point
112 # Explicitly enter this as bytes, or the assembler
113 # tries to generate a 3-byte jump here, which causes
114 # everything else to push off to the wrong offset.
115 .byte 0xeb # short (2-byte) jump
116 .byte start_of_setup-1f
119 # Part 2 of the header, from the old setup.S
121 .ascii "HdrS" # header signature
122 .word 0x0209 # header version number (>= 0x0105)
123 # or else old loadlin-1.5 will fail)
124 .globl realmode_swtch
125 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
126 start_sys_seg: .word SYSSEG
127 .word kernel_version-512 # pointing to kernel version string
128 # above section of header is compatible
129 # with loadlin-1.5 (header v1.5). Don't
132 type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
133 # Bootlin, SYSLX, bootsect...)
134 # See Documentation/i386/boot.txt for
137 # flags, unused bits must be zero (RFU) bit within loadflags
139 LOADED_HIGH = 1 # If set, the kernel is loaded high
140 CAN_USE_HEAP = 0x80 # If set, the loader also has set
141 # heap_end_ptr to tell how much
142 # space behind setup.S can be used for
144 # Only the loader knows what is free
145 #ifndef __BIG_KERNEL__
151 setup_move_size: .word 0x8000 # size to move, when setup is not
152 # loaded at 0x90000. We will move setup
153 # to 0x90000 then just before jumping
154 # into the kernel. However, only the
155 # loader knows how much data behind
156 # us also needs to be loaded.
158 code32_start: # here loaders can put a different
159 # start address for 32-bit code.
160 #ifndef __BIG_KERNEL__
161 .long 0x1000 # 0x1000 = default for zImage
163 .long 0x100000 # 0x100000 = default for big kernel
166 ramdisk_image: .long 0 # address of loaded ramdisk image
167 # Here the loader puts the 32-bit
168 # address where it loaded the image.
169 # This only will be read by the kernel.
171 ramdisk_size: .long 0 # its size in bytes
176 heap_end_ptr: .word _end+STACK_SIZE-512
177 # (Header version 0x0201 or later)
178 # space from here (exclusive) down to
179 # end of setup code can be used by setup
180 # for local heap purposes.
183 cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
184 # If nonzero, a 32-bit pointer
185 # to the kernel command line.
186 # The command line should be
187 # located between the start of
188 # setup and the end of low
189 # memory (0xa0000), or it may
190 # get overwritten before it
191 # gets read. If this field is
192 # used, there is no longer
193 # anything magical about the
194 # 0x90000 segment; the setup
195 # can be located anywhere in
196 # low memory 0x10000 or higher.
198 ramdisk_max: .long 0x7fffffff
199 # (Header version 0x0203 or later)
200 # The highest safe address for
201 # the contents of an initrd
202 # The current kernel allows up to 4 GB,
203 # but leave it at 2 GB to avoid
204 # possible bootloader bugs.
206 kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
207 #required for protected mode
209 #ifdef CONFIG_RELOCATABLE
210 relocatable_kernel: .byte 1
212 relocatable_kernel: .byte 0
217 cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
218 #added with boot protocol
221 hardware_subarch: .long 0 # subarchitecture, added with 2.07
222 # default to 0 for normal x86 PC
224 hardware_subarch_data: .quad 0
226 payload_offset: .long input_data
227 payload_length: .long input_data_end-input_data
229 setup_data: .quad 0 # 64-bit physical pointer to
230 # single linked list of
233 # End of setup header #####################################################
235 .section ".inittext", "ax"
237 #ifdef SAFE_RESET_DISK_CONTROLLER
238 # Reset the disk controller.
239 movw $0x0000, %ax # Reset disk controller
240 movb $0x80, %dl # All disks
249 # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
250 # which happened to work by accident for the old code. Recalculate the stack
251 # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
252 # stack behind its own code, so we can't blindly put it directly past the heap.
255 cmpw %ax, %dx # %ds == %ss?
257 je 2f # -> assume %sp is reasonably set
259 # Invalid %ss, make up a new stack
261 testb $CAN_USE_HEAP, loadflags
263 movw heap_end_ptr, %dx
264 1: addw $STACK_SIZE, %dx
266 xorw %dx, %dx # Prevent wraparound
268 2: # Now %dx should point to the end of our stack space
269 andw $~3, %dx # dword align (might as well...)
271 movw $0xfffc, %dx # Make sure we're not zero
273 movzwl %dx, %esp # Clear upper half of %esp
274 sti # Now we should have a working stack
276 # We will have entered with %cs = %ds+0x20, normalize %cs so
277 # it is on par with the other segments.
283 # Check signature at end of setup
284 cmpl $0x5a5aaa55, setup_sig
288 movw $__bss_start, %di
295 # Jump to C code (should not return)
298 # Setup corrupt somehow...
300 movl $setup_corrupt, %eax
312 .section ".initdata", "a"
315 .string "No setup signature found...\n"