|
|
1.1 ! root 1: /* ! 2: Copyright (C) 2000, Entity Cyber, Inc. ! 3: ! 4: Authors: Gary Byers ([email protected]) ! 5: Marty Connor ([email protected]) ! 6: ! 7: This software may be used and distributed according to the terms ! 8: of the GNU Public License (GPL), incorporated herein by reference. ! 9: ! 10: Description: ! 11: ! 12: This is just a little bit of code and data that can get prepended ! 13: to a ROM image in order to allow bootloaders to load the result ! 14: as if it were a Linux kernel image. ! 15: ! 16: A real Linux kernel image consists of a one-sector boot loader ! 17: (to load the image from a floppy disk), followed a few sectors ! 18: of setup code, followed by the kernel code itself. There's ! 19: a table in the first sector (starting at offset 497) that indicates ! 20: how many sectors of setup code follow the first sector and which ! 21: contains some other parameters that aren't interesting in this ! 22: case. ! 23: ! 24: When a bootloader loads the sectors that comprise a kernel image, ! 25: it doesn't execute the code in the first sector (since that code ! 26: would try to load the image from a floppy disk.) The code in the ! 27: first sector below doesn't expect to get executed (and prints an ! 28: error message if it ever -is- executed.) ! 29: ! 30: We don't require much in the way of setup code. Historically, the ! 31: Linux kernel required at least 4 sectors of setup code. ! 32: Therefore, at least 4 sectors must be present even though we don't ! 33: use them. ! 34: ! 35: */ ! 36: ! 37: FILE_LICENCE ( GPL_ANY ) ! 38: ! 39: #define SETUPSECS 4 /* Minimal nr of setup-sectors */ ! 40: #define PREFIXSIZE ((SETUPSECS+1)*512) ! 41: #define PREFIXPGH (PREFIXSIZE / 16 ) ! 42: #define BOOTSEG 0x07C0 /* original address of boot-sector */ ! 43: #define INITSEG 0x9000 /* we move boot here - out of the way */ ! 44: #define SETUPSEG 0x9020 /* setup starts here */ ! 45: #define SYSSEG 0x1000 /* system loaded at 0x10000 (65536). */ ! 46: ! 47: .text ! 48: .code16 ! 49: .arch i386 ! 50: .org 0 ! 51: .section ".prefix", "ax", @progbits ! 52: .globl _lkrn_start ! 53: _lkrn_start: ! 54: /* ! 55: This is a minimal boot sector. If anyone tries to execute it (e.g., if ! 56: a .lilo file is dd'ed to a floppy), print an error message. ! 57: */ ! 58: ! 59: bootsector: ! 60: jmp $BOOTSEG, $1f /* reload cs:ip to match relocation addr */ ! 61: 1: ! 62: movw $0x2000, %di /* 0x2000 is arbitrary value >= length ! 63: of bootsect + room for stack */ ! 64: ! 65: movw $BOOTSEG, %ax ! 66: movw %ax,%ds ! 67: movw %ax,%es ! 68: ! 69: cli ! 70: movw %ax, %ss /* put stack at BOOTSEG:0x2000. */ ! 71: movw %di,%sp ! 72: sti ! 73: ! 74: movw $why_end-why, %cx ! 75: movw $why, %si ! 76: ! 77: movw $0x0007, %bx /* page 0, attribute 7 (normal) */ ! 78: movb $0x0e, %ah /* write char, tty mode */ ! 79: prloop: ! 80: lodsb ! 81: int $0x10 ! 82: loop prloop ! 83: freeze: jmp freeze ! 84: ! 85: why: .ascii "This image cannot be loaded from a floppy disk.\r\n" ! 86: why_end: ! 87: ! 88: ! 89: /* ! 90: The following header is documented in the Linux source code at ! 91: Documentation/x86/boot.txt ! 92: */ ! 93: .org 497 ! 94: setup_sects: ! 95: .byte SETUPSECS ! 96: root_flags: ! 97: .word 0 ! 98: syssize: ! 99: .long -PREFIXPGH ! 100: ! 101: .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */ ! 102: .ascii "ADDL" ! 103: .long syssize ! 104: .long 16 ! 105: .long 0 ! 106: .previous ! 107: ! 108: ram_size: ! 109: .word 0 ! 110: vid_mode: ! 111: .word 0 ! 112: root_dev: ! 113: .word 0 ! 114: boot_flag: ! 115: .word 0xAA55 ! 116: jump: ! 117: /* Manually specify a two-byte jmp instruction here rather ! 118: * than leaving it up to the assembler. */ ! 119: .byte 0xeb ! 120: .byte setup_code - header ! 121: header: ! 122: .byte 'H', 'd', 'r', 'S' ! 123: version: ! 124: .word 0x0207 /* 2.07 */ ! 125: realmode_swtch: ! 126: .long 0 ! 127: start_sys: ! 128: .word 0 ! 129: kernel_version: ! 130: .word 0 ! 131: type_of_loader: ! 132: .byte 0 ! 133: loadflags: ! 134: .byte 0 ! 135: setup_move_size: ! 136: .word 0 ! 137: code32_start: ! 138: .long 0 ! 139: ramdisk_image: ! 140: .long 0 ! 141: ramdisk_size: ! 142: .long 0 ! 143: bootsect_kludge: ! 144: .long 0 ! 145: heap_end_ptr: ! 146: .word 0 ! 147: pad1: ! 148: .word 0 ! 149: cmd_line_ptr: ! 150: .long 0 ! 151: initrd_addr_max: ! 152: /* We don't use an initrd but some bootloaders (e.g. SYSLINUX) have ! 153: * been known to require this field. Set the value to 2 GB. This ! 154: * value is also used by the Linux kernel. */ ! 155: .long 0x7fffffff ! 156: kernel_alignment: ! 157: .long 0 ! 158: relocatable_kernel: ! 159: .byte 0 ! 160: pad2: ! 161: .byte 0, 0, 0 ! 162: cmdline_size: ! 163: .long 0 ! 164: hardware_subarch: ! 165: .long 0 ! 166: hardware_subarch_data: ! 167: .byte 0, 0, 0, 0, 0, 0, 0, 0 ! 168: ! 169: /* ! 170: We don't need to do too much setup. ! 171: ! 172: This code gets loaded at SETUPSEG:0. It wants to start ! 173: executing the image that's loaded at SYSSEG:0 and ! 174: whose entry point is SYSSEG:0. ! 175: */ ! 176: setup_code: ! 177: /* We expect to be contiguous in memory once loaded. The Linux image ! 178: * boot process requires that setup code is loaded separately from ! 179: * "non-real code". Since we don't need any information that's left ! 180: * in the prefix, it doesn't matter: we just have to ensure that ! 181: * %cs:0000 is where the start of the image *would* be. ! 182: */ ! 183: ljmp $(SYSSEG-(PREFIXSIZE/16)), $run_ipxe ! 184: ! 185: ! 186: .org PREFIXSIZE ! 187: /* ! 188: We're now at the beginning of the kernel proper. ! 189: */ ! 190: run_ipxe: ! 191: /* Set up stack just below 0x7c00 */ ! 192: xorw %ax, %ax ! 193: movw %ax, %ss ! 194: movw $0x7c00, %sp ! 195: ! 196: /* Retrieve command-line pointer */ ! 197: movl %es:cmd_line_ptr, %edx ! 198: ! 199: /* Install iPXE */ ! 200: call install ! 201: ! 202: /* Set up real-mode stack */ ! 203: movw %bx, %ss ! 204: movw $_estack16, %sp ! 205: ! 206: /* Jump to .text16 segment */ ! 207: pushw %ax ! 208: pushw $1f ! 209: lret ! 210: .section ".text16", "awx", @progbits ! 211: 1: ! 212: /* Set up %ds for access to .data16 */ ! 213: movw %bx, %ds ! 214: ! 215: /* Store command-line pointer */ ! 216: movl %edx, cmdline_phys ! 217: ! 218: /* Run iPXE */ ! 219: pushl $main ! 220: pushw %cs ! 221: call prot_call ! 222: popl %ecx /* discard */ ! 223: ! 224: /* Uninstall iPXE */ ! 225: call uninstall ! 226: ! 227: /* Boot next device */ ! 228: int $0x18
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.