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> 2496ae6ea0SThomas Gleixner#include "boot.h" 2577d1a499SH. Peter Anvin#include "voffset.h" 2677d1a499SH. Peter Anvin#include "zoffset.h" 2796ae6ea0SThomas Gleixner 2896ae6ea0SThomas GleixnerBOOTSEG = 0x07C0 /* original address of boot-sector */ 295e47c478SH. Peter AnvinSYSSEG = 0x1000 /* historical load address >> 4 */ 3096ae6ea0SThomas Gleixner 3196ae6ea0SThomas Gleixner#ifndef SVGA_MODE 3296ae6ea0SThomas Gleixner#define SVGA_MODE ASK_VGA 3396ae6ea0SThomas Gleixner#endif 3496ae6ea0SThomas Gleixner 3596ae6ea0SThomas Gleixner#ifndef RAMDISK 3696ae6ea0SThomas Gleixner#define RAMDISK 0 3796ae6ea0SThomas Gleixner#endif 3896ae6ea0SThomas Gleixner 3996ae6ea0SThomas Gleixner#ifndef ROOT_RDONLY 4096ae6ea0SThomas Gleixner#define ROOT_RDONLY 1 4196ae6ea0SThomas Gleixner#endif 4296ae6ea0SThomas Gleixner 4396ae6ea0SThomas Gleixner .code16 4496ae6ea0SThomas Gleixner .section ".bstext", "ax" 4596ae6ea0SThomas Gleixner 4696ae6ea0SThomas Gleixner .global bootsect_start 4796ae6ea0SThomas Gleixnerbootsect_start: 48291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 49291f3632SMatt Fleming # "MZ", MS-DOS header 50291f3632SMatt Fleming .byte 0x4d 51291f3632SMatt Fleming .byte 0x5a 52291f3632SMatt Fleming#endif 5396ae6ea0SThomas Gleixner 5496ae6ea0SThomas Gleixner # Normalize the start address 5596ae6ea0SThomas Gleixner ljmp $BOOTSEG, $start2 5696ae6ea0SThomas Gleixner 5796ae6ea0SThomas Gleixnerstart2: 5896ae6ea0SThomas Gleixner movw %cs, %ax 5996ae6ea0SThomas Gleixner movw %ax, %ds 6096ae6ea0SThomas Gleixner movw %ax, %es 6196ae6ea0SThomas Gleixner movw %ax, %ss 6296ae6ea0SThomas Gleixner xorw %sp, %sp 6396ae6ea0SThomas Gleixner sti 6496ae6ea0SThomas Gleixner cld 6596ae6ea0SThomas Gleixner 6696ae6ea0SThomas Gleixner movw $bugger_off_msg, %si 6796ae6ea0SThomas Gleixner 6896ae6ea0SThomas Gleixnermsg_loop: 6996ae6ea0SThomas Gleixner lodsb 7096ae6ea0SThomas Gleixner andb %al, %al 7196ae6ea0SThomas Gleixner jz bs_die 7296ae6ea0SThomas Gleixner movb $0xe, %ah 7396ae6ea0SThomas Gleixner movw $7, %bx 7496ae6ea0SThomas Gleixner int $0x10 7596ae6ea0SThomas Gleixner jmp msg_loop 7696ae6ea0SThomas Gleixner 7796ae6ea0SThomas Gleixnerbs_die: 7896ae6ea0SThomas Gleixner # Allow the user to press a key, then reboot 7996ae6ea0SThomas Gleixner xorw %ax, %ax 8096ae6ea0SThomas Gleixner int $0x16 8196ae6ea0SThomas Gleixner int $0x19 8296ae6ea0SThomas Gleixner 8396ae6ea0SThomas Gleixner # int 0x19 should never return. In case it does anyway, 8496ae6ea0SThomas Gleixner # invoke the BIOS reset code... 8596ae6ea0SThomas Gleixner ljmp $0xf000,$0xfff0 8696ae6ea0SThomas Gleixner 87291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 88291f3632SMatt Fleming .org 0x3c 89291f3632SMatt Fleming # 90291f3632SMatt Fleming # Offset to the PE header. 91291f3632SMatt Fleming # 92291f3632SMatt Fleming .long pe_header 93291f3632SMatt Fleming#endif /* CONFIG_EFI_STUB */ 94291f3632SMatt Fleming 9596ae6ea0SThomas Gleixner .section ".bsdata", "a" 9696ae6ea0SThomas Gleixnerbugger_off_msg: 9796ae6ea0SThomas Gleixner .ascii "Direct booting from floppy is no longer supported.\r\n" 9896ae6ea0SThomas Gleixner .ascii "Please use a boot loader program instead.\r\n" 9996ae6ea0SThomas Gleixner .ascii "\n" 10096ae6ea0SThomas Gleixner .ascii "Remove disk and press any key to reboot . . .\r\n" 10196ae6ea0SThomas Gleixner .byte 0 10296ae6ea0SThomas Gleixner 103291f3632SMatt Fleming#ifdef CONFIG_EFI_STUB 104291f3632SMatt Flemingpe_header: 105291f3632SMatt Fleming .ascii "PE" 106291f3632SMatt Fleming .word 0 107291f3632SMatt Fleming 108291f3632SMatt Flemingcoff_header: 109291f3632SMatt Fleming#ifdef CONFIG_X86_32 110291f3632SMatt Fleming .word 0x14c # i386 111291f3632SMatt Fleming#else 112291f3632SMatt Fleming .word 0x8664 # x86-64 113291f3632SMatt Fleming#endif 114291f3632SMatt Fleming .word 2 # nr_sections 115291f3632SMatt Fleming .long 0 # TimeDateStamp 116291f3632SMatt Fleming .long 0 # PointerToSymbolTable 117291f3632SMatt Fleming .long 1 # NumberOfSymbols 118291f3632SMatt Fleming .word section_table - optional_header # SizeOfOptionalHeader 119291f3632SMatt Fleming#ifdef CONFIG_X86_32 120291f3632SMatt Fleming .word 0x306 # Characteristics. 121291f3632SMatt Fleming # IMAGE_FILE_32BIT_MACHINE | 122291f3632SMatt Fleming # IMAGE_FILE_DEBUG_STRIPPED | 123291f3632SMatt Fleming # IMAGE_FILE_EXECUTABLE_IMAGE | 124291f3632SMatt Fleming # IMAGE_FILE_LINE_NUMS_STRIPPED 125291f3632SMatt Fleming#else 126291f3632SMatt Fleming .word 0x206 # Characteristics 127291f3632SMatt Fleming # IMAGE_FILE_DEBUG_STRIPPED | 128291f3632SMatt Fleming # IMAGE_FILE_EXECUTABLE_IMAGE | 129291f3632SMatt Fleming # IMAGE_FILE_LINE_NUMS_STRIPPED 130291f3632SMatt Fleming#endif 131291f3632SMatt Fleming 132291f3632SMatt Flemingoptional_header: 133291f3632SMatt Fleming#ifdef CONFIG_X86_32 134291f3632SMatt Fleming .word 0x10b # PE32 format 135291f3632SMatt Fleming#else 136291f3632SMatt Fleming .word 0x20b # PE32+ format 137291f3632SMatt Fleming#endif 138291f3632SMatt Fleming .byte 0x02 # MajorLinkerVersion 139291f3632SMatt Fleming .byte 0x14 # MinorLinkerVersion 140291f3632SMatt Fleming 141291f3632SMatt Fleming # Filled in by build.c 142291f3632SMatt Fleming .long 0 # SizeOfCode 143291f3632SMatt Fleming 144291f3632SMatt Fleming .long 0 # SizeOfInitializedData 145291f3632SMatt Fleming .long 0 # SizeOfUninitializedData 146291f3632SMatt Fleming 147291f3632SMatt Fleming # Filled in by build.c 148291f3632SMatt Fleming .long 0x0000 # AddressOfEntryPoint 149291f3632SMatt Fleming 150e31be363SMatt Fleming .long 0x0200 # BaseOfCode 151291f3632SMatt Fleming#ifdef CONFIG_X86_32 152291f3632SMatt Fleming .long 0 # data 153291f3632SMatt Fleming#endif 154291f3632SMatt Fleming 155291f3632SMatt Flemingextra_header_fields: 156291f3632SMatt Fleming#ifdef CONFIG_X86_32 157291f3632SMatt Fleming .long 0 # ImageBase 158291f3632SMatt Fleming#else 159291f3632SMatt Fleming .quad 0 # ImageBase 160291f3632SMatt Fleming#endif 161291f3632SMatt Fleming .long 0x1000 # SectionAlignment 162291f3632SMatt Fleming .long 0x200 # FileAlignment 163291f3632SMatt Fleming .word 0 # MajorOperatingSystemVersion 164291f3632SMatt Fleming .word 0 # MinorOperatingSystemVersion 165291f3632SMatt Fleming .word 0 # MajorImageVersion 166291f3632SMatt Fleming .word 0 # MinorImageVersion 167291f3632SMatt Fleming .word 0 # MajorSubsystemVersion 168291f3632SMatt Fleming .word 0 # MinorSubsystemVersion 169291f3632SMatt Fleming .long 0 # Win32VersionValue 170291f3632SMatt Fleming 171291f3632SMatt Fleming # 172291f3632SMatt Fleming # The size of the bzImage is written in tools/build.c 173291f3632SMatt Fleming # 174291f3632SMatt Fleming .long 0 # SizeOfImage 175291f3632SMatt Fleming 176291f3632SMatt Fleming .long 0x200 # SizeOfHeaders 177291f3632SMatt Fleming .long 0 # CheckSum 178291f3632SMatt Fleming .word 0xa # Subsystem (EFI application) 179291f3632SMatt Fleming .word 0 # DllCharacteristics 180291f3632SMatt Fleming#ifdef CONFIG_X86_32 181291f3632SMatt Fleming .long 0 # SizeOfStackReserve 182291f3632SMatt Fleming .long 0 # SizeOfStackCommit 183291f3632SMatt Fleming .long 0 # SizeOfHeapReserve 184291f3632SMatt Fleming .long 0 # SizeOfHeapCommit 185291f3632SMatt Fleming#else 186291f3632SMatt Fleming .quad 0 # SizeOfStackReserve 187291f3632SMatt Fleming .quad 0 # SizeOfStackCommit 188291f3632SMatt Fleming .quad 0 # SizeOfHeapReserve 189291f3632SMatt Fleming .quad 0 # SizeOfHeapCommit 190291f3632SMatt Fleming#endif 191291f3632SMatt Fleming .long 0 # LoaderFlags 192*e47bb0bdSMatt Fleming .long 0x6 # NumberOfRvaAndSizes 193291f3632SMatt Fleming 194291f3632SMatt Fleming .quad 0 # ExportTable 195291f3632SMatt Fleming .quad 0 # ImportTable 196291f3632SMatt Fleming .quad 0 # ResourceTable 197291f3632SMatt Fleming .quad 0 # ExceptionTable 198291f3632SMatt Fleming .quad 0 # CertificationTable 199291f3632SMatt Fleming .quad 0 # BaseRelocationTable 200291f3632SMatt Fleming 201291f3632SMatt Fleming # Section table 202291f3632SMatt Flemingsection_table: 203291f3632SMatt Fleming .ascii ".text" 204291f3632SMatt Fleming .byte 0 205291f3632SMatt Fleming .byte 0 206291f3632SMatt Fleming .byte 0 207291f3632SMatt Fleming .long 0 208291f3632SMatt Fleming .long 0x0 # startup_{32,64} 209291f3632SMatt Fleming .long 0 # Size of initialized data 210291f3632SMatt Fleming # on disk 211291f3632SMatt Fleming .long 0x0 # startup_{32,64} 212291f3632SMatt Fleming .long 0 # PointerToRelocations 213291f3632SMatt Fleming .long 0 # PointerToLineNumbers 214291f3632SMatt Fleming .word 0 # NumberOfRelocations 215291f3632SMatt Fleming .word 0 # NumberOfLineNumbers 216291f3632SMatt Fleming .long 0x60500020 # Characteristics (section flags) 217291f3632SMatt Fleming 218291f3632SMatt Fleming # 219291f3632SMatt Fleming # The EFI application loader requires a relocation section 2202e064b1eSJordan Justen # because EFI applications must be relocatable. But since 2212e064b1eSJordan Justen # we don't need the loader to fixup any relocs for us, we 2222e064b1eSJordan Justen # just create an empty (zero-length) .reloc section header. 223291f3632SMatt Fleming # 224291f3632SMatt Fleming .ascii ".reloc" 225291f3632SMatt Fleming .byte 0 226291f3632SMatt Fleming .byte 0 2272e064b1eSJordan Justen .long 0 2282e064b1eSJordan Justen .long 0 2292e064b1eSJordan Justen .long 0 # SizeOfRawData 2302e064b1eSJordan Justen .long 0 # PointerToRawData 231291f3632SMatt Fleming .long 0 # PointerToRelocations 232291f3632SMatt Fleming .long 0 # PointerToLineNumbers 233291f3632SMatt Fleming .word 0 # NumberOfRelocations 234291f3632SMatt Fleming .word 0 # NumberOfLineNumbers 235291f3632SMatt Fleming .long 0x42100040 # Characteristics (section flags) 236291f3632SMatt Fleming#endif /* CONFIG_EFI_STUB */ 23796ae6ea0SThomas Gleixner 23896ae6ea0SThomas Gleixner # Kernel attributes; used by setup. This is part 1 of the 23996ae6ea0SThomas Gleixner # header, from the old boot sector. 24096ae6ea0SThomas Gleixner 24196ae6ea0SThomas Gleixner .section ".header", "a" 24296ae6ea0SThomas Gleixner .globl hdr 24396ae6ea0SThomas Gleixnerhdr: 2445e47c478SH. Peter Anvinsetup_sects: .byte 0 /* Filled in by build.c */ 24596ae6ea0SThomas Gleixnerroot_flags: .word ROOT_RDONLY 2465e47c478SH. Peter Anvinsyssize: .long 0 /* Filled in by build.c */ 2475e47c478SH. Peter Anvinram_size: .word 0 /* Obsolete */ 24896ae6ea0SThomas Gleixnervid_mode: .word SVGA_MODE 2495e47c478SH. Peter Anvinroot_dev: .word 0 /* Filled in by build.c */ 25096ae6ea0SThomas Gleixnerboot_flag: .word 0xAA55 25196ae6ea0SThomas Gleixner 25296ae6ea0SThomas Gleixner # offset 512, entry point 25396ae6ea0SThomas Gleixner 25496ae6ea0SThomas Gleixner .globl _start 25596ae6ea0SThomas Gleixner_start: 25696ae6ea0SThomas Gleixner # Explicitly enter this as bytes, or the assembler 25796ae6ea0SThomas Gleixner # tries to generate a 3-byte jump here, which causes 25896ae6ea0SThomas Gleixner # everything else to push off to the wrong offset. 25996ae6ea0SThomas Gleixner .byte 0xeb # short (2-byte) jump 26096ae6ea0SThomas Gleixner .byte start_of_setup-1f 26196ae6ea0SThomas Gleixner1: 26296ae6ea0SThomas Gleixner 26396ae6ea0SThomas Gleixner # Part 2 of the header, from the old setup.S 26496ae6ea0SThomas Gleixner 26596ae6ea0SThomas Gleixner .ascii "HdrS" # header signature 26637ba7ab5SH. Peter Anvin .word 0x020a # header version number (>= 0x0105) 26796ae6ea0SThomas Gleixner # or else old loadlin-1.5 will fail) 26896ae6ea0SThomas Gleixner .globl realmode_swtch 26996ae6ea0SThomas Gleixnerrealmode_swtch: .word 0, 0 # default_switch, SETUPSEG 2705e47c478SH. Peter Anvinstart_sys_seg: .word SYSSEG # obsolete and meaningless, but just 2715e47c478SH. Peter Anvin # in case something decided to "use" it 27296ae6ea0SThomas Gleixner .word kernel_version-512 # pointing to kernel version string 27396ae6ea0SThomas Gleixner # above section of header is compatible 27496ae6ea0SThomas Gleixner # with loadlin-1.5 (header v1.5). Don't 27596ae6ea0SThomas Gleixner # change it. 27696ae6ea0SThomas Gleixner 2775e47c478SH. Peter Anvintype_of_loader: .byte 0 # 0 means ancient bootloader, newer 2785e47c478SH. Peter Anvin # bootloaders know to change this. 279395cf969SPaul Bolle # See Documentation/x86/boot.txt for 28096ae6ea0SThomas Gleixner # assigned ids 28196ae6ea0SThomas Gleixner 28296ae6ea0SThomas Gleixner# flags, unused bits must be zero (RFU) bit within loadflags 28396ae6ea0SThomas Gleixnerloadflags: 28496ae6ea0SThomas GleixnerLOADED_HIGH = 1 # If set, the kernel is loaded high 28596ae6ea0SThomas GleixnerCAN_USE_HEAP = 0x80 # If set, the loader also has set 28696ae6ea0SThomas Gleixner # heap_end_ptr to tell how much 28796ae6ea0SThomas Gleixner # space behind setup.S can be used for 28896ae6ea0SThomas Gleixner # heap purposes. 28996ae6ea0SThomas Gleixner # Only the loader knows what is free 29096ae6ea0SThomas Gleixner .byte LOADED_HIGH 29196ae6ea0SThomas Gleixner 29296ae6ea0SThomas Gleixnersetup_move_size: .word 0x8000 # size to move, when setup is not 29396ae6ea0SThomas Gleixner # loaded at 0x90000. We will move setup 29496ae6ea0SThomas Gleixner # to 0x90000 then just before jumping 29596ae6ea0SThomas Gleixner # into the kernel. However, only the 29696ae6ea0SThomas Gleixner # loader knows how much data behind 29796ae6ea0SThomas Gleixner # us also needs to be loaded. 29896ae6ea0SThomas Gleixner 29996ae6ea0SThomas Gleixnercode32_start: # here loaders can put a different 30096ae6ea0SThomas Gleixner # start address for 32-bit code. 30196ae6ea0SThomas Gleixner .long 0x100000 # 0x100000 = default for big kernel 30296ae6ea0SThomas Gleixner 30396ae6ea0SThomas Gleixnerramdisk_image: .long 0 # address of loaded ramdisk image 30496ae6ea0SThomas Gleixner # Here the loader puts the 32-bit 30596ae6ea0SThomas Gleixner # address where it loaded the image. 30696ae6ea0SThomas Gleixner # This only will be read by the kernel. 30796ae6ea0SThomas Gleixner 30896ae6ea0SThomas Gleixnerramdisk_size: .long 0 # its size in bytes 30996ae6ea0SThomas Gleixner 31096ae6ea0SThomas Gleixnerbootsect_kludge: 31196ae6ea0SThomas Gleixner .long 0 # obsolete 31296ae6ea0SThomas Gleixner 3136b6815c6SH. Peter Anvinheap_end_ptr: .word _end+STACK_SIZE-512 3146b6815c6SH. Peter Anvin # (Header version 0x0201 or later) 31596ae6ea0SThomas Gleixner # space from here (exclusive) down to 31696ae6ea0SThomas Gleixner # end of setup code can be used by setup 31796ae6ea0SThomas Gleixner # for local heap purposes. 31896ae6ea0SThomas Gleixner 3195031296cSH. Peter Anvinext_loader_ver: 3205031296cSH. Peter Anvin .byte 0 # Extended boot loader version 3215031296cSH. Peter Anvinext_loader_type: 3225031296cSH. Peter Anvin .byte 0 # Extended boot loader type 3235031296cSH. Peter Anvin 32496ae6ea0SThomas Gleixnercmd_line_ptr: .long 0 # (Header version 0x0202 or later) 32596ae6ea0SThomas Gleixner # If nonzero, a 32-bit pointer 32696ae6ea0SThomas Gleixner # to the kernel command line. 32796ae6ea0SThomas Gleixner # The command line should be 32896ae6ea0SThomas Gleixner # located between the start of 32996ae6ea0SThomas Gleixner # setup and the end of low 33096ae6ea0SThomas Gleixner # memory (0xa0000), or it may 33196ae6ea0SThomas Gleixner # get overwritten before it 33296ae6ea0SThomas Gleixner # gets read. If this field is 33396ae6ea0SThomas Gleixner # used, there is no longer 33496ae6ea0SThomas Gleixner # anything magical about the 33596ae6ea0SThomas Gleixner # 0x90000 segment; the setup 33696ae6ea0SThomas Gleixner # can be located anywhere in 33796ae6ea0SThomas Gleixner # low memory 0x10000 or higher. 33896ae6ea0SThomas Gleixner 339cf8fa920SH. Peter Anvinramdisk_max: .long 0x7fffffff 34096ae6ea0SThomas Gleixner # (Header version 0x0203 or later) 34196ae6ea0SThomas Gleixner # The highest safe address for 34296ae6ea0SThomas Gleixner # the contents of an initrd 343cf8fa920SH. Peter Anvin # The current kernel allows up to 4 GB, 344cf8fa920SH. Peter Anvin # but leave it at 2 GB to avoid 345cf8fa920SH. Peter Anvin # possible bootloader bugs. 34696ae6ea0SThomas Gleixner 34796ae6ea0SThomas Gleixnerkernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment 34896ae6ea0SThomas Gleixner #required for protected mode 34996ae6ea0SThomas Gleixner #kernel 35096ae6ea0SThomas Gleixner#ifdef CONFIG_RELOCATABLE 35196ae6ea0SThomas Gleixnerrelocatable_kernel: .byte 1 35296ae6ea0SThomas Gleixner#else 35396ae6ea0SThomas Gleixnerrelocatable_kernel: .byte 0 35496ae6ea0SThomas Gleixner#endif 35537ba7ab5SH. Peter Anvinmin_alignment: .byte MIN_KERNEL_ALIGN_LG2 # minimum alignment 35696ae6ea0SThomas Gleixnerpad3: .word 0 35796ae6ea0SThomas Gleixner 35896ae6ea0SThomas Gleixnercmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line, 35996ae6ea0SThomas Gleixner #added with boot protocol 36096ae6ea0SThomas Gleixner #version 2.06 36196ae6ea0SThomas Gleixner 362a24e7851SRusty Russellhardware_subarch: .long 0 # subarchitecture, added with 2.07 363a24e7851SRusty Russell # default to 0 for normal x86 PC 364a24e7851SRusty Russell 365a24e7851SRusty Russellhardware_subarch_data: .quad 0 366a24e7851SRusty Russell 36777d1a499SH. Peter Anvinpayload_offset: .long ZO_input_data 36877d1a499SH. Peter Anvinpayload_length: .long ZO_z_input_len 369099e1377SIan Campbell 3708b664aa6SHuang, Yingsetup_data: .quad 0 # 64-bit physical pointer to 3718b664aa6SHuang, Ying # single linked list of 3728b664aa6SHuang, Ying # struct setup_data 3738b664aa6SHuang, Ying 37437ba7ab5SH. Peter Anvinpref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr 37537ba7ab5SH. Peter Anvin 376c6ac4c18SH. Peter Anvin#define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset) 37737ba7ab5SH. Peter Anvin#define VO_INIT_SIZE (VO__end - VO__text) 37837ba7ab5SH. Peter Anvin#if ZO_INIT_SIZE > VO_INIT_SIZE 37937ba7ab5SH. Peter Anvin#define INIT_SIZE ZO_INIT_SIZE 38037ba7ab5SH. Peter Anvin#else 38137ba7ab5SH. Peter Anvin#define INIT_SIZE VO_INIT_SIZE 38237ba7ab5SH. Peter Anvin#endif 38337ba7ab5SH. Peter Anvininit_size: .long INIT_SIZE # kernel initialization size 38437ba7ab5SH. Peter Anvin 38596ae6ea0SThomas Gleixner# End of setup header ##################################################### 38696ae6ea0SThomas Gleixner 3877a734e7dSH. Peter Anvin .section ".entrytext", "ax" 38896ae6ea0SThomas Gleixnerstart_of_setup: 38996ae6ea0SThomas Gleixner#ifdef SAFE_RESET_DISK_CONTROLLER 39096ae6ea0SThomas Gleixner# Reset the disk controller. 39196ae6ea0SThomas Gleixner movw $0x0000, %ax # Reset disk controller 39296ae6ea0SThomas Gleixner movb $0x80, %dl # All disks 39396ae6ea0SThomas Gleixner int $0x13 39496ae6ea0SThomas Gleixner#endif 39596ae6ea0SThomas Gleixner 39696ae6ea0SThomas Gleixner# Force %es = %ds 39796ae6ea0SThomas Gleixner movw %ds, %ax 39896ae6ea0SThomas Gleixner movw %ax, %es 39996ae6ea0SThomas Gleixner cld 40096ae6ea0SThomas Gleixner 40116252da6SJens Rottmann# Apparently some ancient versions of LILO invoked the kernel with %ss != %ds, 40216252da6SJens Rottmann# which happened to work by accident for the old code. Recalculate the stack 40316252da6SJens Rottmann# pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the 40416252da6SJens Rottmann# stack behind its own code, so we can't blindly put it directly past the heap. 4056b6815c6SH. Peter Anvin 4066b6815c6SH. Peter Anvin movw %ss, %dx 4076b6815c6SH. Peter Anvin cmpw %ax, %dx # %ds == %ss? 4086b6815c6SH. Peter Anvin movw %sp, %dx 40916252da6SJens Rottmann je 2f # -> assume %sp is reasonably set 4106b6815c6SH. Peter Anvin 41116252da6SJens Rottmann # Invalid %ss, make up a new stack 41216252da6SJens Rottmann movw $_end, %dx 41316252da6SJens Rottmann testb $CAN_USE_HEAP, loadflags 41416252da6SJens Rottmann jz 1f 41516252da6SJens Rottmann movw heap_end_ptr, %dx 41616252da6SJens Rottmann1: addw $STACK_SIZE, %dx 41716252da6SJens Rottmann jnc 2f 41816252da6SJens Rottmann xorw %dx, %dx # Prevent wraparound 41916252da6SJens Rottmann 42016252da6SJens Rottmann2: # Now %dx should point to the end of our stack space 4216b6815c6SH. Peter Anvin andw $~3, %dx # dword align (might as well...) 4226b6815c6SH. Peter Anvin jnz 3f 4236b6815c6SH. Peter Anvin movw $0xfffc, %dx # Make sure we're not zero 42416252da6SJens Rottmann3: movw %ax, %ss 4256b6815c6SH. Peter Anvin movzwl %dx, %esp # Clear upper half of %esp 4266b6815c6SH. Peter Anvin sti # Now we should have a working stack 4276b6815c6SH. Peter Anvin 4286b6815c6SH. Peter Anvin# We will have entered with %cs = %ds+0x20, normalize %cs so 4296b6815c6SH. Peter Anvin# it is on par with the other segments. 4306b6815c6SH. Peter Anvin pushw %ds 4316b6815c6SH. Peter Anvin pushw $6f 4326b6815c6SH. Peter Anvin lretw 4336b6815c6SH. Peter Anvin6: 43496ae6ea0SThomas Gleixner 43596ae6ea0SThomas Gleixner# Check signature at end of setup 43696ae6ea0SThomas Gleixner cmpl $0x5a5aaa55, setup_sig 43796ae6ea0SThomas Gleixner jne setup_bad 43896ae6ea0SThomas Gleixner 43996ae6ea0SThomas Gleixner# Zero the bss 44096ae6ea0SThomas Gleixner movw $__bss_start, %di 44196ae6ea0SThomas Gleixner movw $_end+3, %cx 44296ae6ea0SThomas Gleixner xorl %eax, %eax 44396ae6ea0SThomas Gleixner subw %di, %cx 44496ae6ea0SThomas Gleixner shrw $2, %cx 44596ae6ea0SThomas Gleixner rep; stosl 44696ae6ea0SThomas Gleixner 44796ae6ea0SThomas Gleixner# Jump to C code (should not return) 44896ae6ea0SThomas Gleixner calll main 44996ae6ea0SThomas Gleixner 45096ae6ea0SThomas Gleixner# Setup corrupt somehow... 45196ae6ea0SThomas Gleixnersetup_bad: 45296ae6ea0SThomas Gleixner movl $setup_corrupt, %eax 45396ae6ea0SThomas Gleixner calll puts 45496ae6ea0SThomas Gleixner # Fall through... 45596ae6ea0SThomas Gleixner 45696ae6ea0SThomas Gleixner .globl die 45796ae6ea0SThomas Gleixner .type die, @function 45896ae6ea0SThomas Gleixnerdie: 45996ae6ea0SThomas Gleixner hlt 46096ae6ea0SThomas Gleixner jmp die 46196ae6ea0SThomas Gleixner 46296ae6ea0SThomas Gleixner .size die, .-die 46396ae6ea0SThomas Gleixner 46496ae6ea0SThomas Gleixner .section ".initdata", "a" 46596ae6ea0SThomas Gleixnersetup_corrupt: 46696ae6ea0SThomas Gleixner .byte 7 46796ae6ea0SThomas Gleixner .string "No setup signature found...\n" 468291f3632SMatt Fleming 469291f3632SMatt Fleming .data 470291f3632SMatt Flemingdummy: .long 0 471