|
|
1.1 ! root 1: /* ! 2: * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992 ! 3: * ! 4: * Mach Operating System ! 5: * Copyright (c) 1992, 1991 Carnegie Mellon University ! 6: * All Rights Reserved. ! 7: * ! 8: * Permission to use, copy, modify and distribute this software and its ! 9: * documentation is hereby granted, provided that both the copyright ! 10: * notice and this permission notice appear in all copies of the ! 11: * software, derivative works or modified versions, and any portions ! 12: * thereof, and that both notices appear in supporting documentation. ! 13: * ! 14: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 15: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 16: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 17: * ! 18: * Carnegie Mellon requests users of this software to return to ! 19: * ! 20: * Software Distribution Coordinator or [email protected] ! 21: * School of Computer Science ! 22: * Carnegie Mellon University ! 23: * Pittsburgh PA 15213-3890 ! 24: * ! 25: * any improvements or extensions that they make and grant Carnegie Mellon ! 26: * the rights to redistribute these changes. ! 27: */ ! 28: ! 29: /* ! 30: * HISTORY ! 31: * $Log: start.S,v $ ! 32: * Revision 1.1 1993/03/21 18:08:42 cgd ! 33: * after 0.2.2 "stable" patches applied ! 34: * ! 35: * Revision 2.2 92/04/04 11:36:29 rpd ! 36: * Fix Intel Copyright as per B. Davies authorization. ! 37: * [92/04/03 rvb] ! 38: * Need to zero dh on hd path; at least for an adaptec card. ! 39: * [92/01/14 rvb] ! 40: * ! 41: * From 2.5 boot: ! 42: * Flush digit printing. ! 43: * Fuse floppy and hd boot by using Int 21 to tell ! 44: * boot type (slightly dubious since Int 21 is DOS ! 45: * not BIOS) ! 46: * [92/03/30 mg32] ! 47: * ! 48: * Revision 2.2 91/04/02 14:42:04 mbj ! 49: * Fix the BIG boot bug. We had missed a necessary data ! 50: * before a xor that was clearing a register used later ! 51: * as an index register. ! 52: * [91/03/01 rvb] ! 53: * Remember floppy type for swapgeneric ! 54: * Add Intel copyright ! 55: * [90/02/09 rvb] ! 56: * ! 57: */ ! 58: ! 59: ! 60: /* ! 61: Copyright 1988, 1989, 1990, 1991, 1992 ! 62: by Intel Corporation, Santa Clara, California. ! 63: ! 64: All Rights Reserved ! 65: ! 66: Permission to use, copy, modify, and distribute this software and ! 67: its documentation for any purpose and without fee is hereby ! 68: granted, provided that the above copyright notice appears in all ! 69: copies and that both the copyright notice and this permission notice ! 70: appear in supporting documentation, and that the name of Intel ! 71: not be used in advertising or publicity pertaining to distribution ! 72: of the software without specific, written prior permission. ! 73: ! 74: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE ! 75: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, ! 76: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR ! 77: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ! 78: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, ! 79: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION ! 80: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 81: */ ! 82: #include "asm.h" ! 83: ! 84: .file "start.s" ! 85: ! 86: BOOTSEG = 0x9000 # boot will be loaded at 640k-64k ! 87: BOOTSTACK = 0xe000 # boot stack ! 88: SIGNATURE = 0xaa55 ! 89: LOADSZ = 14 # size of unix boot ! 90: PARTSTART = 0x1be # starting address of partition table ! 91: NUMPART = 4 # number of partitions in partition table ! 92: PARTSZ = 16 # each partition table entry is 16 bytes ! 93: BSDPART = 0xA5 # value of boot_ind, means bootable partition ! 94: BOOTABLE = 0x80 # value of boot_ind, means bootable partition ! 95: ! 96: .text ! 97: ! 98: ENTRY(boot1) ! 99: ! 100: # boot1 is loaded at 0x0:0x7c00 ! 101: # ljmp to the next instruction to set up %cs ! 102: data32 ! 103: ljmp $0x7c0, $start ! 104: ! 105: start: ! 106: # set up %ds ! 107: mov %cs, %ax ! 108: mov %ax, %ds ! 109: ! 110: ! 111: # set up %ss and %esp ! 112: data32 ! 113: mov $BOOTSEG, %eax ! 114: mov %ax, %ss ! 115: data32 ! 116: mov $BOOTSTACK, %esp ! 117: ! 118: /*** set up %es, (where we will load boot2 to) ***/ ! 119: mov %ax, %es ! 120: ! 121: #ifdef DEBUG ! 122: data32 ! 123: mov $one, %esi ! 124: data32 ! 125: call message ! 126: #endif ! 127: # get the boot drive id ! 128: movb $0x33, %ah ! 129: movb $0x05, %al ! 130: int $0x21 ! 131: ! 132: cmpb $0x80, %dl ! 133: data32 ! 134: jge hd ! 135: ! 136: fd: ! 137: # reset the disk system ! 138: #ifdef DEBUG ! 139: data32 ! 140: mov $two, %esi ! 141: data32 ! 142: call message ! 143: #endif ! 144: movb $0x0, %ah ! 145: int $0x13 ! 146: data32 ! 147: mov $0x0001, %ecx # cyl 0, sector 1 ! 148: data32 ! 149: #ifdef DEBUG ! 150: data32 ! 151: mov $three, %esi ! 152: data32 ! 153: call message ! 154: #endif ! 155: jmp load ! 156: ! 157: hd: /**** load sector 0 into the BOOTSEG ****/ ! 158: #ifdef DEBUG ! 159: data32 ! 160: mov $four, %esi ! 161: data32 ! 162: call message ! 163: #endif ! 164: data32 ! 165: mov $0x0201, %eax ! 166: xor %ebx, %ebx # %bx = 0 ! 167: data32 ! 168: mov $0x0001, %ecx ! 169: #ifdef DEBUG ! 170: data32 ! 171: mov $five, %esi ! 172: data32 ! 173: call message ! 174: #endif ! 175: data32 ! 176: andl $0xff, %edx ! 177: /*mov $0x0080, %edx*/ ! 178: int $0x13 ! 179: data32 ! 180: jb read_error ! 181: ! 182: /***# find the bootable partition *****/ ! 183: data32 ! 184: mov $PARTSTART, %ebx ! 185: data32 ! 186: mov $NUMPART, %ecx ! 187: again: ! 188: addr16 ! 189: movb %es:4(%ebx), %al ! 190: cmpb $BSDPART, %al ! 191: data32 ! 192: je found ! 193: data32 ! 194: add $PARTSZ, %ebx ! 195: data32 ! 196: loop again ! 197: data32 ! 198: mov $enoboot, %esi ! 199: data32 ! 200: jmp err_stop ! 201: ! 202: ! 203: /* ! 204: # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory ! 205: # Call with %ah = 0x2 ! 206: # %al = number of sectors ! 207: # %ch = cylinder ! 208: # %cl = sector ! 209: # %dh = head ! 210: # %dl = drive (0x80 for hard disk, 0x0 for floppy disk) ! 211: # %es:%bx = segment:offset of buffer ! 212: # Return: ! 213: # %al = 0x0 on success; err code on failure ! 214: */ ! 215: ! 216: found: ! 217: addr16 ! 218: movb %es:1(%ebx), %dh /* head */ ! 219: addr16 ! 220: xor %ecx, %ecx ! 221: addr16 ! 222: movw %es:2(%ebx), %ecx /*sect,cyl (+ 2 bytes junk in top word )*/ ! 223: ! 224: load: ! 225: movb $0x2, %ah /* function 2 */ ! 226: movb $LOADSZ, %al /* number of blocks */ ! 227: xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */ ! 228: int $0x13 ! 229: data32 ! 230: jb read_error ! 231: ! 232: # ljmp to the second stage boot loader (boot2). ! 233: # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used ! 234: # as an internal buffer "intbuf". ! 235: ! 236: #ifdef DEBUG ! 237: data32 ! 238: mov $six, %esi ! 239: data32 ! 240: call message ! 241: #endif ! 242: data32 ! 243: ljmp $BOOTSEG, $EXT(boot2) ! 244: ! 245: # ! 246: # read_error ! 247: # ! 248: ! 249: read_error: ! 250: ! 251: data32 ! 252: mov $eread, %esi ! 253: err_stop: ! 254: data32 ! 255: call message ! 256: data32 ! 257: jmp stop ! 258: ! 259: # ! 260: # message: write the error message in %ds:%esi to console ! 261: # ! 262: ! 263: message: ! 264: # Use BIOS "int 10H Function 0Eh" to write character in teletype mode ! 265: # %ah = 0xe %al = character ! 266: # %bh = page %bl = foreground color (graphics modes) ! 267: ! 268: data32 ! 269: push %eax ! 270: data32 ! 271: push %ebx ! 272: data32 ! 273: mov $0x0001, %ebx ! 274: cld ! 275: ! 276: nextb: ! 277: lodsb # load a byte into %al ! 278: cmpb $0x0, %al ! 279: data32 ! 280: je done ! 281: movb $0xe, %ah ! 282: int $0x10 # display a byte ! 283: data32 ! 284: jmp nextb ! 285: done: ! 286: data32 ! 287: pop %ebx ! 288: data32 ! 289: pop %eax ! 290: data32 ! 291: ret ! 292: ! 293: stop: hlt ! 294: data32 ! 295: jmp stop # halt doesnt actually halt forever ! 296: ! 297: /* error messages */ ! 298: ! 299: #ifdef DEBUG ! 300: one: String "1\r\n\0" ! 301: two: String "2\r\n\0" ! 302: three: String "3\r\n\0" ! 303: four: String "4\r\n\0" ! 304: five: String "5\r\n\0" ! 305: six: String "6\r\n\0" ! 306: seven: String "7\r\n\0" ! 307: #endif DEBUG ! 308: eread: String "Read error\r\n\0" ! 309: enoboot: String "No bootable partition\r\n\0" ! 310: endofcode: ! 311: /* throw in a partition in case we are block0 as well */ ! 312: /* flag,head,sec,cyl,typ,ehead,esect,ecyl,start,len */ ! 313: . = EXT(boot1) + PARTSTART ! 314: .byte 0x0,0,0,0,0,0,0,0 ! 315: .long 0,0 ! 316: .byte 0x0,0,0,0,0,0,0,0 ! 317: .long 0,0 ! 318: .byte 0x0,0,0,0,0,0,0,0 ! 319: .long 0,0 ! 320: .byte BOOTABLE,0,1,0,BSDPART,255,255,255 ! 321: .long 0,50000 ! 322: /* the last 2 bytes in the sector 0 contain the signature */ ! 323: . = EXT(boot1) + 0x1fe ! 324: .value SIGNATURE ! 325: ENTRY(disklabel) ! 326: . = EXT(boot1) + 0x400
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.