196ae6ea0SThomas Gleixner/* 296ae6ea0SThomas Gleixner * header.S 396ae6ea0SThomas Gleixner * 496ae6ea0SThomas Gleixner * Copyright (C) 1991, 1992 Linus Torvalds 596ae6ea0SThomas Gleixner * 696ae6ea0SThomas Gleixner * Based on bootsect.S and setup.S 796ae6ea0SThomas Gleixner * modified by more people than can be counted 896ae6ea0SThomas Gleixner * 996ae6ea0SThomas Gleixner * Rewritten as a common file by H. Peter Anvin (Apr 2007) 1096ae6ea0SThomas Gleixner * 1196ae6ea0SThomas Gleixner * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment 1296ae6ea0SThomas Gleixner * addresses must be multiplied by 16 to obtain their respective linear 1396ae6ea0SThomas Gleixner * addresses. To avoid confusion, linear addresses are written using leading 1496ae6ea0SThomas Gleixner * hex while segment addresses are written as segment:offset. 1596ae6ea0SThomas Gleixner * 1696ae6ea0SThomas Gleixner */ 1796ae6ea0SThomas Gleixner 1896ae6ea0SThomas Gleixner#include <asm/segment.h> 19273b281fSSam Ravnborg#include <generated/utsrelease.h> 2096ae6ea0SThomas Gleixner#include <asm/boot.h> 2196ae6ea0SThomas Gleixner#include <asm/e820.h> 220341c14dSJeremy Fitzhardinge#include <asm/page_types.h> 2396ae6ea0SThomas Gleixner#include <asm/setup.h> 2409c205afSH. Peter Anvin#include <asm/bootparam.h> 2596ae6ea0SThomas Gleixner#include "boot.h" 2677d1a499SH. Peter Anvin#include "voffset.h" 2777d1a499SH. Peter Anvin#include "zoffset.h" 2896ae6ea0SThomas Gleixner 2996ae6ea0SThomas GleixnerBOOTSEG = 0x07C0 /* original address of boot-sector */ 305e47c478SH. Peter AnvinSYSSEG = 0x1000 /* historical load address >> 4 */ 3196ae6ea0SThomas Gleixner 3296ae6ea0SThomas Gleixner#ifndef SVGA_MODE 3396ae6ea0SThomas Gleixner#define SVGA_MODE ASK_VGA 3496ae6ea0SThomas Gleixner#endif 3596ae6ea0SThomas Gleixner 3696ae6ea0SThomas Gleixner#ifndef ROOT_RDONLY 3796ae6ea0SThomas Gleixner#define ROOT_RDONLY 1 3896ae6ea0SThomas Gleixner#endif 3996ae6ea0SThomas Gleixner 4096ae6ea0SThomas Gleixner .code16 4196ae6ea0SThomas Gleixner .section ".bstext", "ax" 4296ae6ea0SThomas Gleixner 4396ae6ea0SThomas Gleixner .global bootsect_start 4496ae6ea0SThomas Gleixnerbootsect_start: 45291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 46291f3632SMatt Fleming # "MZ", MS-DOS header 47291f3632SMatt Fleming .byte 0x4d 48291f3632SMatt Fleming .byte 0x5a 49291f3632SMatt Fleming#endif 5096ae6ea0SThomas Gleixner 5196ae6ea0SThomas Gleixner # Normalize the start address 5296ae6ea0SThomas Gleixner ljmp $BOOTSEG, $start2 5396ae6ea0SThomas Gleixner 5496ae6ea0SThomas Gleixnerstart2: 5596ae6ea0SThomas Gleixner movw %cs, %ax 5696ae6ea0SThomas Gleixner movw %ax, %ds 5796ae6ea0SThomas Gleixner movw %ax, %es 5896ae6ea0SThomas Gleixner movw %ax, %ss 5996ae6ea0SThomas Gleixner xorw %sp, %sp 6096ae6ea0SThomas Gleixner sti 6196ae6ea0SThomas Gleixner cld 6296ae6ea0SThomas Gleixner 6396ae6ea0SThomas Gleixner movw $bugger_off_msg, %si 6496ae6ea0SThomas Gleixner 6596ae6ea0SThomas Gleixnermsg_loop: 6696ae6ea0SThomas Gleixner lodsb 6796ae6ea0SThomas Gleixner andb %al, %al 6896ae6ea0SThomas Gleixner jz bs_die 6996ae6ea0SThomas Gleixner movb $0xe, %ah 7096ae6ea0SThomas Gleixner movw $7, %bx 7196ae6ea0SThomas Gleixner int $0x10 7296ae6ea0SThomas Gleixner jmp msg_loop 7396ae6ea0SThomas Gleixner 7496ae6ea0SThomas Gleixnerbs_die: 7596ae6ea0SThomas Gleixner # Allow the user to press a key, then reboot 7696ae6ea0SThomas Gleixner xorw %ax, %ax 7796ae6ea0SThomas Gleixner int $0x16 7896ae6ea0SThomas Gleixner int $0x19 7996ae6ea0SThomas Gleixner 8096ae6ea0SThomas Gleixner # int 0x19 should never return. In case it does anyway, 8196ae6ea0SThomas Gleixner # invoke the BIOS reset code... 8296ae6ea0SThomas Gleixner ljmp $0xf000,$0xfff0 8396ae6ea0SThomas Gleixner 84291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 85291f3632SMatt Fleming .org 0x3c 86291f3632SMatt Fleming # 87291f3632SMatt Fleming # Offset to the PE header. 88291f3632SMatt Fleming # 89291f3632SMatt Fleming .long pe_header 90291f3632SMatt Fleming#endif /* CONFIG_EFI_STUB */ 91291f3632SMatt Fleming 9296ae6ea0SThomas Gleixner .section ".bsdata", "a" 9396ae6ea0SThomas Gleixnerbugger_off_msg: 94743628e8SJordan Justen .ascii "Direct floppy boot is not supported. " 95743628e8SJordan Justen .ascii "Use a boot loader program instead.\r\n" 9696ae6ea0SThomas Gleixner .ascii "\n" 9796ae6ea0SThomas Gleixner .ascii "Remove disk and press any key to reboot ...\r\n" 9896ae6ea0SThomas Gleixner .byte 0 9996ae6ea0SThomas Gleixner 100291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 101291f3632SMatt Flemingpe_header: 102291f3632SMatt Fleming .ascii "PE" 103291f3632SMatt Fleming .word 0 104291f3632SMatt Fleming 105291f3632SMatt Flemingcoff_header: 106291f3632SMatt Fleming#ifdef CONFIG_X86_32 107291f3632SMatt Fleming .word 0x14c # i386 108291f3632SMatt Fleming#else 109291f3632SMatt Fleming .word 0x8664 # x86-64 110291f3632SMatt Fleming#endif 111743628e8SJordan Justen .word 3 # nr_sections 112291f3632SMatt Fleming .long 0 # TimeDateStamp 113291f3632SMatt Fleming .long 0 # PointerToSymbolTable 114291f3632SMatt Fleming .long 1 # NumberOfSymbols 115291f3632SMatt Fleming .word section_table - optional_header # SizeOfOptionalHeader 116291f3632SMatt Fleming#ifdef CONFIG_X86_32 117291f3632SMatt Fleming .word 0x306 # Characteristics. 118291f3632SMatt Fleming # IMAGE_FILE_32BIT_MACHINE | 119291f3632SMatt Fleming # IMAGE_FILE_DEBUG_STRIPPED | 120291f3632SMatt Fleming # IMAGE_FILE_EXECUTABLE_IMAGE | 121291f3632SMatt Fleming # IMAGE_FILE_LINE_NUMS_STRIPPED 122291f3632SMatt Fleming#else 123291f3632SMatt Fleming .word 0x206 # Characteristics 124291f3632SMatt Fleming # IMAGE_FILE_DEBUG_STRIPPED | 125291f3632SMatt Fleming # IMAGE_FILE_EXECUTABLE_IMAGE | 126291f3632SMatt Fleming # IMAGE_FILE_LINE_NUMS_STRIPPED 127291f3632SMatt Fleming#endif 128291f3632SMatt Fleming 129291f3632SMatt Flemingoptional_header: 130291f3632SMatt Fleming#ifdef CONFIG_X86_32 131291f3632SMatt Fleming .word 0x10b # PE32 format 132291f3632SMatt Fleming#else 133291f3632SMatt Fleming .word 0x20b # PE32+ format 134291f3632SMatt Fleming#endif 135291f3632SMatt Fleming .byte 0x02 # MajorLinkerVersion 136291f3632SMatt Fleming .byte 0x14 # MinorLinkerVersion 137291f3632SMatt Fleming 138291f3632SMatt Fleming # Filled in by build.c 139291f3632SMatt Fleming .long 0 # SizeOfCode 140291f3632SMatt Fleming 141291f3632SMatt Fleming .long 0 # SizeOfInitializedData 142291f3632SMatt Fleming .long 0 # SizeOfUninitializedData 143291f3632SMatt Fleming 144291f3632SMatt Fleming # Filled in by build.c 145291f3632SMatt Fleming .long 0x0000 # AddressOfEntryPoint 146291f3632SMatt Fleming 147e31be363SMatt Fleming .long 0x0200 # BaseOfCode 148291f3632SMatt Fleming#ifdef CONFIG_X86_32 149291f3632SMatt Fleming .long 0 # data 150291f3632SMatt Fleming#endif 151291f3632SMatt Fleming 152291f3632SMatt Flemingextra_header_fields: 153291f3632SMatt Fleming#ifdef CONFIG_X86_32 154291f3632SMatt Fleming .long 0 # ImageBase 155291f3632SMatt Fleming#else 156291f3632SMatt Fleming .quad 0 # ImageBase 157291f3632SMatt Fleming#endif 158743628e8SJordan Justen .long 0x20 # SectionAlignment 159743628e8SJordan Justen .long 0x20 # FileAlignment 160291f3632SMatt Fleming .word 0 # MajorOperatingSystemVersion 161291f3632SMatt Fleming .word 0 # MinorOperatingSystemVersion 162291f3632SMatt Fleming .word 0 # MajorImageVersion 163291f3632SMatt Fleming .word 0 # MinorImageVersion 164291f3632SMatt Fleming .word 0 # MajorSubsystemVersion 165291f3632SMatt Fleming .word 0 # MinorSubsystemVersion 166291f3632SMatt Fleming .long 0 # Win32VersionValue 167291f3632SMatt Fleming 168291f3632SMatt Fleming # 169291f3632SMatt Fleming # The size of the bzImage is written in tools/build.c 170291f3632SMatt Fleming # 171291f3632SMatt Fleming .long 0 # SizeOfImage 172291f3632SMatt Fleming 173291f3632SMatt Fleming .long 0x200 # SizeOfHeaders 174291f3632SMatt Fleming .long 0 # CheckSum 175291f3632SMatt Fleming .word 0xa # Subsystem (EFI application) 176291f3632SMatt Fleming .word 0 # DllCharacteristics 177291f3632SMatt Fleming#ifdef CONFIG_X86_32 178291f3632SMatt Fleming .long 0 # SizeOfStackReserve 179291f3632SMatt Fleming .long 0 # SizeOfStackCommit 180291f3632SMatt Fleming .long 0 # SizeOfHeapReserve 181291f3632SMatt Fleming .long 0 # SizeOfHeapCommit 182291f3632SMatt Fleming#else 183291f3632SMatt Fleming .quad 0 # SizeOfStackReserve 184291f3632SMatt Fleming .quad 0 # SizeOfStackCommit 185291f3632SMatt Fleming .quad 0 # SizeOfHeapReserve 186291f3632SMatt Fleming .quad 0 # SizeOfHeapCommit 187291f3632SMatt Fleming#endif 188291f3632SMatt Fleming .long 0 # LoaderFlags 189e47bb0bdSMatt Fleming .long 0x6 # NumberOfRvaAndSizes 190291f3632SMatt Fleming 191291f3632SMatt Fleming .quad 0 # ExportTable 192291f3632SMatt Fleming .quad 0 # ImportTable 193291f3632SMatt Fleming .quad 0 # ResourceTable 194291f3632SMatt Fleming .quad 0 # ExceptionTable 195291f3632SMatt Fleming .quad 0 # CertificationTable 196291f3632SMatt Fleming .quad 0 # BaseRelocationTable 197291f3632SMatt Fleming 198291f3632SMatt Fleming # Section table 199291f3632SMatt Flemingsection_table: 200743628e8SJordan Justen # 201743628e8SJordan Justen # The offset & size fields are filled in by build.c. 202743628e8SJordan Justen # 203743628e8SJordan Justen .ascii ".setup" 204291f3632SMatt Fleming .byte 0 205291f3632SMatt Fleming .byte 0 206291f3632SMatt Fleming .long 0 207291f3632SMatt Fleming .long 0x0 # startup_{32,64} 208291f3632SMatt Fleming .long 0 # Size of initialized data 209291f3632SMatt Fleming # on disk 210291f3632SMatt Fleming .long 0x0 # startup_{32,64} 211291f3632SMatt Fleming .long 0 # PointerToRelocations 212291f3632SMatt Fleming .long 0 # PointerToLineNumbers 213291f3632SMatt Fleming .word 0 # NumberOfRelocations 214291f3632SMatt Fleming .word 0 # NumberOfLineNumbers 215291f3632SMatt Fleming .long 0x60500020 # Characteristics (section flags) 216291f3632SMatt Fleming 217291f3632SMatt Fleming # 218291f3632SMatt Fleming # The EFI application loader requires a relocation section 219743628e8SJordan Justen # because EFI applications must be relocatable. The .reloc 220743628e8SJordan Justen # offset & size fields are filled in by build.c. 221291f3632SMatt Fleming # 222291f3632SMatt Fleming .ascii ".reloc" 223291f3632SMatt Fleming .byte 0 224291f3632SMatt Fleming .byte 0 2252e064b1eSJordan Justen .long 0 2262e064b1eSJordan Justen .long 0 2272e064b1eSJordan Justen .long 0 # SizeOfRawData 2282e064b1eSJordan Justen .long 0 # PointerToRawData 229291f3632SMatt Fleming .long 0 # PointerToRelocations 230291f3632SMatt Fleming .long 0 # PointerToLineNumbers 231291f3632SMatt Fleming .word 0 # NumberOfRelocations 232291f3632SMatt Fleming .word 0 # NumberOfLineNumbers 233291f3632SMatt Fleming .long 0x42100040 # Characteristics (section flags) 234743628e8SJordan Justen 235743628e8SJordan Justen # 236743628e8SJordan Justen # The offset & size fields are filled in by build.c. 237743628e8SJordan Justen # 238743628e8SJordan Justen .ascii ".text" 239743628e8SJordan Justen .byte 0 240743628e8SJordan Justen .byte 0 241743628e8SJordan Justen .byte 0 242743628e8SJordan Justen .long 0 243743628e8SJordan Justen .long 0x0 # startup_{32,64} 244743628e8SJordan Justen .long 0 # Size of initialized data 245743628e8SJordan Justen # on disk 246743628e8SJordan Justen .long 0x0 # startup_{32,64} 247743628e8SJordan Justen .long 0 # PointerToRelocations 248743628e8SJordan Justen .long 0 # PointerToLineNumbers 249743628e8SJordan Justen .word 0 # NumberOfRelocations 250743628e8SJordan Justen .word 0 # NumberOfLineNumbers 251743628e8SJordan Justen .long 0x60500020 # Characteristics (section flags) 252743628e8SJordan Justen 253291f3632SMatt Fleming#endif /* CONFIG_EFI_STUB */ 25496ae6ea0SThomas Gleixner 25596ae6ea0SThomas Gleixner # Kernel attributes; used by setup. This is part 1 of the 25696ae6ea0SThomas Gleixner # header, from the old boot sector. 25796ae6ea0SThomas Gleixner 25896ae6ea0SThomas Gleixner .section ".header", "a" 25909c205afSH. Peter Anvin .globl sentinel 26009c205afSH. Peter Anvinsentinel: .byte 0xff, 0xff /* Used to detect broken loaders */ 26109c205afSH. Peter Anvin 26296ae6ea0SThomas Gleixner .globl hdr 26396ae6ea0SThomas Gleixnerhdr: 2645e47c478SH. Peter Anvinsetup_sects: .byte 0 /* Filled in by build.c */ 26596ae6ea0SThomas Gleixnerroot_flags: .word ROOT_RDONLY 2665e47c478SH. Peter Anvinsyssize: .long 0 /* Filled in by build.c */ 2675e47c478SH. Peter Anvinram_size: .word 0 /* Obsolete */ 26896ae6ea0SThomas Gleixnervid_mode: .word SVGA_MODE 2695e47c478SH. Peter Anvinroot_dev: .word 0 /* Filled in by build.c */ 27096ae6ea0SThomas Gleixnerboot_flag: .word 0xAA55 27196ae6ea0SThomas Gleixner 27296ae6ea0SThomas Gleixner # offset 512, entry point 27396ae6ea0SThomas Gleixner 27496ae6ea0SThomas Gleixner .globl _start 27596ae6ea0SThomas Gleixner_start: 27696ae6ea0SThomas Gleixner # Explicitly enter this as bytes, or the assembler 27796ae6ea0SThomas Gleixner # tries to generate a 3-byte jump here, which causes 27896ae6ea0SThomas Gleixner # everything else to push off to the wrong offset. 27996ae6ea0SThomas Gleixner .byte 0xeb # short (2-byte) jump 28096ae6ea0SThomas Gleixner .byte start_of_setup-1f 28196ae6ea0SThomas Gleixner1: 28296ae6ea0SThomas Gleixner 28396ae6ea0SThomas Gleixner # Part 2 of the header, from the old setup.S 28496ae6ea0SThomas Gleixner 28596ae6ea0SThomas Gleixner .ascii "HdrS" # header signature 28609c205afSH. Peter Anvin .word 0x020c # header version number (>= 0x0105) 28796ae6ea0SThomas Gleixner # or else old loadlin-1.5 will fail) 28896ae6ea0SThomas Gleixner .globl realmode_swtch 28996ae6ea0SThomas Gleixnerrealmode_swtch: .word 0, 0 # default_switch, SETUPSEG 2905e47c478SH. Peter Anvinstart_sys_seg: .word SYSSEG # obsolete and meaningless, but just 2915e47c478SH. Peter Anvin # in case something decided to "use" it 29296ae6ea0SThomas Gleixner .word kernel_version-512 # pointing to kernel version string 29396ae6ea0SThomas Gleixner # above section of header is compatible 29496ae6ea0SThomas Gleixner # with loadlin-1.5 (header v1.5). Don't 29596ae6ea0SThomas Gleixner # change it. 29696ae6ea0SThomas Gleixner 2975e47c478SH. Peter Anvintype_of_loader: .byte 0 # 0 means ancient bootloader, newer 2985e47c478SH. Peter Anvin # bootloaders know to change this. 299395cf969SPaul Bolle # See Documentation/x86/boot.txt for 30096ae6ea0SThomas Gleixner # assigned ids 30196ae6ea0SThomas Gleixner 30296ae6ea0SThomas Gleixner# flags, unused bits must be zero (RFU) bit within loadflags 30396ae6ea0SThomas Gleixnerloadflags: 30409c205afSH. Peter Anvin .byte LOADED_HIGH # The kernel is to be loaded high 30596ae6ea0SThomas Gleixner 30696ae6ea0SThomas Gleixnersetup_move_size: .word 0x8000 # size to move, when setup is not 30796ae6ea0SThomas Gleixner # loaded at 0x90000. We will move setup 30896ae6ea0SThomas Gleixner # to 0x90000 then just before jumping 30996ae6ea0SThomas Gleixner # into the kernel. However, only the 31096ae6ea0SThomas Gleixner # loader knows how much data behind 31196ae6ea0SThomas Gleixner # us also needs to be loaded. 31296ae6ea0SThomas Gleixner 31396ae6ea0SThomas Gleixnercode32_start: # here loaders can put a different 31496ae6ea0SThomas Gleixner # start address for 32-bit code. 31596ae6ea0SThomas Gleixner .long 0x100000 # 0x100000 = default for big kernel 31696ae6ea0SThomas Gleixner 31796ae6ea0SThomas Gleixnerramdisk_image: .long 0 # address of loaded ramdisk image 31896ae6ea0SThomas Gleixner # Here the loader puts the 32-bit 31996ae6ea0SThomas Gleixner # address where it loaded the image. 32096ae6ea0SThomas Gleixner # This only will be read by the kernel. 32196ae6ea0SThomas Gleixner 32296ae6ea0SThomas Gleixnerramdisk_size: .long 0 # its size in bytes 32396ae6ea0SThomas Gleixner 32496ae6ea0SThomas Gleixnerbootsect_kludge: 32596ae6ea0SThomas Gleixner .long 0 # obsolete 32696ae6ea0SThomas Gleixner 3276b6815c6SH. Peter Anvinheap_end_ptr: .word _end+STACK_SIZE-512 3286b6815c6SH. Peter Anvin # (Header version 0x0201 or later) 32996ae6ea0SThomas Gleixner # space from here (exclusive) down to 33096ae6ea0SThomas Gleixner # end of setup code can be used by setup 33196ae6ea0SThomas Gleixner # for local heap purposes. 33296ae6ea0SThomas Gleixner 3335031296cSH. Peter Anvinext_loader_ver: 3345031296cSH. Peter Anvin .byte 0 # Extended boot loader version 3355031296cSH. Peter Anvinext_loader_type: 3365031296cSH. Peter Anvin .byte 0 # Extended boot loader type 3375031296cSH. Peter Anvin 33896ae6ea0SThomas Gleixnercmd_line_ptr: .long 0 # (Header version 0x0202 or later) 33996ae6ea0SThomas Gleixner # If nonzero, a 32-bit pointer 34096ae6ea0SThomas Gleixner # to the kernel command line. 34196ae6ea0SThomas Gleixner # The command line should be 34296ae6ea0SThomas Gleixner # located between the start of 34396ae6ea0SThomas Gleixner # setup and the end of low 34496ae6ea0SThomas Gleixner # memory (0xa0000), or it may 34596ae6ea0SThomas Gleixner # get overwritten before it 34696ae6ea0SThomas Gleixner # gets read. If this field is 34796ae6ea0SThomas Gleixner # used, there is no longer 34896ae6ea0SThomas Gleixner # anything magical about the 34996ae6ea0SThomas Gleixner # 0x90000 segment; the setup 35096ae6ea0SThomas Gleixner # can be located anywhere in 35196ae6ea0SThomas Gleixner # low memory 0x10000 or higher. 35296ae6ea0SThomas Gleixner 353cf8fa920SH. Peter Anvinramdisk_max: .long 0x7fffffff 35496ae6ea0SThomas Gleixner # (Header version 0x0203 or later) 35596ae6ea0SThomas Gleixner # The highest safe address for 35696ae6ea0SThomas Gleixner # the contents of an initrd 357cf8fa920SH. Peter Anvin # The current kernel allows up to 4 GB, 358cf8fa920SH. Peter Anvin # but leave it at 2 GB to avoid 359cf8fa920SH. Peter Anvin # possible bootloader bugs. 36096ae6ea0SThomas Gleixner 36196ae6ea0SThomas Gleixnerkernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment 36296ae6ea0SThomas Gleixner #required for protected mode 36396ae6ea0SThomas Gleixner #kernel 36496ae6ea0SThomas Gleixner#ifdef CONFIG_RELOCATABLE 36596ae6ea0SThomas Gleixnerrelocatable_kernel: .byte 1 36696ae6ea0SThomas Gleixner#else 36796ae6ea0SThomas Gleixnerrelocatable_kernel: .byte 0 36896ae6ea0SThomas Gleixner#endif 36937ba7ab5SH. Peter Anvinmin_alignment: .byte MIN_KERNEL_ALIGN_LG2 # minimum alignment 37009c205afSH. Peter Anvin 37109c205afSH. Peter Anvinxloadflags: 37209c205afSH. Peter Anvin#ifdef CONFIG_X86_64 37309c205afSH. Peter Anvin# define XLF0 XLF_KERNEL_64 /* 64-bit kernel */ 37409c205afSH. Peter Anvin#else 37509c205afSH. Peter Anvin# define XLF0 0 37609c205afSH. Peter Anvin#endif 377ee92d815SYinghai Lu 378ee92d815SYinghai Lu#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) 379ee92d815SYinghai Lu /* kernel/boot_param/ramdisk could be loaded above 4g */ 380ee92d815SYinghai Lu# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G 381ee92d815SYinghai Lu#else 382ee92d815SYinghai Lu# define XLF1 0 383ee92d815SYinghai Lu#endif 384ee92d815SYinghai Lu 38509c205afSH. Peter Anvin#ifdef CONFIG_EFI_STUB 38609c205afSH. Peter Anvin# ifdef CONFIG_X86_64 38709c205afSH. Peter Anvin# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */ 38809c205afSH. Peter Anvin# else 38909c205afSH. Peter Anvin# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */ 39009c205afSH. Peter Anvin# endif 39109c205afSH. Peter Anvin#else 39209c205afSH. Peter Anvin# define XLF23 0 39309c205afSH. Peter Anvin#endif 394ee92d815SYinghai Lu .word XLF0 | XLF1 | XLF23 39596ae6ea0SThomas Gleixner 39696ae6ea0SThomas Gleixnercmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line, 39796ae6ea0SThomas Gleixner #added with boot protocol 39896ae6ea0SThomas Gleixner #version 2.06 39996ae6ea0SThomas Gleixner 400a24e7851SRusty Russellhardware_subarch: .long 0 # subarchitecture, added with 2.07 401a24e7851SRusty Russell # default to 0 for normal x86 PC 402a24e7851SRusty Russell 403a24e7851SRusty Russellhardware_subarch_data: .quad 0 404a24e7851SRusty Russell 40577d1a499SH. Peter Anvinpayload_offset: .long ZO_input_data 40677d1a499SH. Peter Anvinpayload_length: .long ZO_z_input_len 407099e1377SIan Campbell 4088b664aa6SHuang, Yingsetup_data: .quad 0 # 64-bit physical pointer to 4098b664aa6SHuang, Ying # single linked list of 4108b664aa6SHuang, Ying # struct setup_data 4118b664aa6SHuang, Ying 41237ba7ab5SH. Peter Anvinpref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr 41337ba7ab5SH. Peter Anvin 414c6ac4c18SH. Peter Anvin#define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset) 41537ba7ab5SH. Peter Anvin#define VO_INIT_SIZE (VO__end - VO__text) 41637ba7ab5SH. Peter Anvin#if ZO_INIT_SIZE > VO_INIT_SIZE 41737ba7ab5SH. Peter Anvin#define INIT_SIZE ZO_INIT_SIZE 41837ba7ab5SH. Peter Anvin#else 41937ba7ab5SH. Peter Anvin#define INIT_SIZE VO_INIT_SIZE 42037ba7ab5SH. Peter Anvin#endif 42137ba7ab5SH. Peter Anvininit_size: .long INIT_SIZE # kernel initialization size 42209c205afSH. Peter Anvinhandover_offset: 42309c205afSH. Peter Anvin#ifdef CONFIG_EFI_STUB 42409c205afSH. Peter Anvin .long 0x30 # offset to the handover 4259ca8f72aSMatt Fleming # protocol entry point 42609c205afSH. Peter Anvin#else 42709c205afSH. Peter Anvin .long 0 42809c205afSH. Peter Anvin#endif 42937ba7ab5SH. Peter Anvin 43096ae6ea0SThomas Gleixner# End of setup header ##################################################### 43196ae6ea0SThomas Gleixner 4327a734e7dSH. Peter Anvin .section ".entrytext", "ax" 43396ae6ea0SThomas Gleixnerstart_of_setup: 43496ae6ea0SThomas Gleixner# Force %es = %ds 43596ae6ea0SThomas Gleixner movw %ds, %ax 43696ae6ea0SThomas Gleixner movw %ax, %es 43796ae6ea0SThomas Gleixner cld 43896ae6ea0SThomas Gleixner 43916252da6SJens Rottmann# Apparently some ancient versions of LILO invoked the kernel with %ss != %ds, 44016252da6SJens Rottmann# which happened to work by accident for the old code. Recalculate the stack 44116252da6SJens Rottmann# pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the 44216252da6SJens Rottmann# stack behind its own code, so we can't blindly put it directly past the heap. 4436b6815c6SH. Peter Anvin 4446b6815c6SH. Peter Anvin movw %ss, %dx 4456b6815c6SH. Peter Anvin cmpw %ax, %dx # %ds == %ss? 4466b6815c6SH. Peter Anvin movw %sp, %dx 44716252da6SJens Rottmann je 2f # -> assume %sp is reasonably set 4486b6815c6SH. Peter Anvin 44916252da6SJens Rottmann # Invalid %ss, make up a new stack 45016252da6SJens Rottmann movw $_end, %dx 45116252da6SJens Rottmann testb $CAN_USE_HEAP, loadflags 45216252da6SJens Rottmann jz 1f 45316252da6SJens Rottmann movw heap_end_ptr, %dx 45416252da6SJens Rottmann1: addw $STACK_SIZE, %dx 45516252da6SJens Rottmann jnc 2f 45616252da6SJens Rottmann xorw %dx, %dx # Prevent wraparound 45716252da6SJens Rottmann 45816252da6SJens Rottmann2: # Now %dx should point to the end of our stack space 4596b6815c6SH. Peter Anvin andw $~3, %dx # dword align (might as well...) 4606b6815c6SH. Peter Anvin jnz 3f 4616b6815c6SH. Peter Anvin movw $0xfffc, %dx # Make sure we're not zero 46216252da6SJens Rottmann3: movw %ax, %ss 4636b6815c6SH. Peter Anvin movzwl %dx, %esp # Clear upper half of %esp 4646b6815c6SH. Peter Anvin sti # Now we should have a working stack 4656b6815c6SH. Peter Anvin 4666b6815c6SH. Peter Anvin# We will have entered with %cs = %ds+0x20, normalize %cs so 4676b6815c6SH. Peter Anvin# it is on par with the other segments. 4686b6815c6SH. Peter Anvin pushw %ds 4696b6815c6SH. Peter Anvin pushw $6f 4706b6815c6SH. Peter Anvin lretw 4716b6815c6SH. Peter Anvin6: 47296ae6ea0SThomas Gleixner 47396ae6ea0SThomas Gleixner# Check signature at end of setup 47496ae6ea0SThomas Gleixner cmpl $0x5a5aaa55, setup_sig 47596ae6ea0SThomas Gleixner jne setup_bad 47696ae6ea0SThomas Gleixner 47796ae6ea0SThomas Gleixner# Zero the bss 47896ae6ea0SThomas Gleixner movw $__bss_start, %di 47996ae6ea0SThomas Gleixner movw $_end+3, %cx 48096ae6ea0SThomas Gleixner xorl %eax, %eax 48196ae6ea0SThomas Gleixner subw %di, %cx 48296ae6ea0SThomas Gleixner shrw $2, %cx 48396ae6ea0SThomas Gleixner rep; stosl 48496ae6ea0SThomas Gleixner 48596ae6ea0SThomas Gleixner# Jump to C code (should not return) 48696ae6ea0SThomas Gleixner calll main 48796ae6ea0SThomas Gleixner 48896ae6ea0SThomas Gleixner# Setup corrupt somehow... 48996ae6ea0SThomas Gleixnersetup_bad: 49096ae6ea0SThomas Gleixner movl $setup_corrupt, %eax 49196ae6ea0SThomas Gleixner calll puts 49296ae6ea0SThomas Gleixner # Fall through... 49396ae6ea0SThomas Gleixner 49496ae6ea0SThomas Gleixner .globl die 49596ae6ea0SThomas Gleixner .type die, @function 49696ae6ea0SThomas Gleixnerdie: 49796ae6ea0SThomas Gleixner hlt 49896ae6ea0SThomas Gleixner jmp die 49996ae6ea0SThomas Gleixner 50096ae6ea0SThomas Gleixner .size die, .-die 50196ae6ea0SThomas Gleixner 50296ae6ea0SThomas Gleixner .section ".initdata", "a" 50396ae6ea0SThomas Gleixnersetup_corrupt: 50496ae6ea0SThomas Gleixner .byte 7 50596ae6ea0SThomas Gleixner .string "No setup signature found...\n" 506