|
|
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: bios.S,v $ ! 32: * Revision 1.1 1993/03/21 18:08:23 cgd ! 33: * after 0.2.2 "stable" patches applied ! 34: * ! 35: * Revision 2.2 92/04/04 11:34:26 rpd ! 36: * Fix Intel Copyright as per B. Davies authorization. ! 37: * [92/04/03 rvb] ! 38: * From 2.5 version ! 39: * [92/03/30 mg32] ! 40: * ! 41: * Revision 2.2 91/04/02 14:35:21 mbj ! 42: * Add Intel copyright ! 43: * [90/02/09 rvb] ! 44: * ! 45: */ ! 46: ! 47: ! 48: /* ! 49: Copyright 1988, 1989, 1990, 1991, 1992 ! 50: by Intel Corporation, Santa Clara, California. ! 51: ! 52: All Rights Reserved ! 53: ! 54: Permission to use, copy, modify, and distribute this software and ! 55: its documentation for any purpose and without fee is hereby ! 56: granted, provided that the above copyright notice appears in all ! 57: copies and that both the copyright notice and this permission notice ! 58: appear in supporting documentation, and that the name of Intel ! 59: not be used in advertising or publicity pertaining to distribution ! 60: of the software without specific, written prior permission. ! 61: ! 62: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE ! 63: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, ! 64: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR ! 65: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ! 66: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, ! 67: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION ! 68: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 69: */ ! 70: ! 71: .file "bios.s" ! 72: ! 73: #include "asm.h" ! 74: .text ! 75: ! 76: /* ! 77: # biosread(dev, cyl, head, sec) ! 78: # Read one sector from disk into the internal buffer "intbuf" which ! 79: # is the first 512 bytes of the boot loader. ! 80: # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory ! 81: # Call with %ah = 0x2 ! 82: # %al = number of sectors ! 83: # %ch = cylinder ! 84: # %cl = sector ! 85: # %dh = head ! 86: # %dl = drive (0x80 for hard disk, 0x0 for floppy disk) ! 87: # %es:%bx = segment:offset of buffer ! 88: # Return: ! 89: # %al = 0x0 on success; err code on failure ! 90: */ ! 91: ! 92: ENTRY(biosread) ! 93: push %ebp ! 94: mov %esp, %ebp ! 95: ! 96: push %ebx ! 97: push %ecx ! 98: push %edx ! 99: push %es ! 100: ! 101: movb 0x10(%ebp), %dh ! 102: movw 0x0c(%ebp), %cx ! 103: xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl ! 104: rorb $2, %cl ! 105: movb 0x14(%ebp), %al ! 106: orb %al, %cl ! 107: incb %cl # sector; sec starts from 1, not 0 ! 108: movb 0x8(%ebp), %dl # device ! 109: xor %ebx, %ebx # offset -- 0 ! 110: # prot_to_real will set %es to BOOTSEG ! 111: ! 112: call EXT(prot_to_real) # enter real mode ! 113: movb $0x2, %ah # subfunction ! 114: movb $0x1, %al # number of sectors -- one ! 115: ! 116: sti ! 117: int $0x13 ! 118: cli ! 119: ! 120: mov %eax, %ebx # save return value ! 121: ! 122: data16 ! 123: call EXT(real_to_prot) # back to protected mode ! 124: ! 125: xor %eax, %eax ! 126: movb %bh, %al # return value in %ax ! 127: ! 128: pop %es ! 129: pop %edx ! 130: pop %ecx ! 131: pop %ebx ! 132: pop %ebp ! 133: ! 134: ret ! 135: ! 136: ! 137: /* ! 138: # putc(ch) ! 139: # BIOS call "INT 10H Function 0Eh" to write character to console ! 140: # Call with %ah = 0x0e ! 141: # %al = character ! 142: # %bh = page ! 143: # %bl = foreground color ( graphics modes) ! 144: */ ! 145: ! 146: ! 147: ENTRY(putc) ! 148: push %ebp ! 149: mov %esp, %ebp ! 150: push %ebx ! 151: push %ecx ! 152: ! 153: movb 0x8(%ebp), %cl ! 154: ! 155: call EXT(prot_to_real) ! 156: ! 157: data16 ! 158: mov $0x1, %ebx # %bh=0, %bl=1 (blue) ! 159: movb $0xe, %ah ! 160: movb %cl, %al ! 161: sti ! 162: int $0x10 # display a byte ! 163: cli ! 164: ! 165: data16 ! 166: call EXT(real_to_prot) ! 167: ! 168: pop %ecx ! 169: pop %ebx ! 170: pop %ebp ! 171: ret ! 172: ! 173: ! 174: /* ! 175: # getc() ! 176: # BIOS call "INT 16H Function 00H" to read character from keyboard ! 177: # Call with %ah = 0x0 ! 178: # Return: %ah = keyboard scan code ! 179: # %al = ASCII character ! 180: */ ! 181: ! 182: ENTRY(getc) ! 183: push %ebp ! 184: mov %esp, %ebp ! 185: push %ebx # save %ebx ! 186: ! 187: call EXT(prot_to_real) ! 188: ! 189: movb $0x0, %ah ! 190: sti ! 191: int $0x16 ! 192: cli ! 193: ! 194: movb %al, %bl # real_to_prot uses %eax ! 195: ! 196: data16 ! 197: call EXT(real_to_prot) ! 198: ! 199: xor %eax, %eax ! 200: movb %bl, %al ! 201: ! 202: pop %ebx ! 203: pop %ebp ! 204: ret ! 205: /* ! 206: # ischar() ! 207: # if there is a character pending, return it; otherwise return 0 ! 208: # BIOS call "INT 16H Function 01H" to check whether a character is pending ! 209: # Call with %ah = 0x1 ! 210: # Return: ! 211: # If key waiting to be input: ! 212: # %ah = keyboard scan code ! 213: # %al = ASCII character ! 214: # Zero flag = clear ! 215: # else ! 216: # Zero flag = set ! 217: */ ! 218: ENTRY(ischar) ! 219: push %ebp ! 220: mov %esp, %ebp ! 221: push %ebx ! 222: ! 223: call EXT(prot_to_real) # enter real mode ! 224: ! 225: xor %ebx, %ebx ! 226: movb $0x1, %ah ! 227: sti ! 228: int $0x16 ! 229: cli ! 230: data16 ! 231: jz nochar ! 232: movb %al, %bl ! 233: ! 234: nochar: ! 235: data16 ! 236: call EXT(real_to_prot) ! 237: ! 238: xor %eax, %eax ! 239: movb %bl, %al ! 240: ! 241: pop %ebx ! 242: pop %ebp ! 243: ret ! 244: ! 245: /* ! 246: # ! 247: # get_diskinfo(): return a word that represents the ! 248: # max number of sectors and heads and drives for this device ! 249: # ! 250: */ ! 251: ! 252: ENTRY(get_diskinfo) ! 253: push %ebp ! 254: mov %esp, %ebp ! 255: push %es ! 256: push %ebx ! 257: push %ecx ! 258: push %edx ! 259: ! 260: movb 0x8(%ebp), %dl # diskinfo(drive #) ! 261: call EXT(prot_to_real) # enter real mode ! 262: ! 263: movb $0x8, %ah # ask for disk info ! 264: ! 265: sti ! 266: int $0x13 ! 267: cli ! 268: ! 269: data16 ! 270: call EXT(real_to_prot) # back to protected mode ! 271: ! 272: xor %eax, %eax ! 273: ! 274: /*form a longword representing all this gunk*/ ! 275: movb %dh, %ah # # heads ! 276: andb $0x3f, %cl # mask of cylinder gunk ! 277: movb %cl, %al # # sectors ! 278: ! 279: pop %edx ! 280: pop %ecx ! 281: pop %ebx ! 282: pop %es ! 283: pop %ebp ! 284: ret ! 285: ! 286: /* ! 287: # ! 288: # memsize(i) : return the memory size in KB. i == 0 for conventional memory, ! 289: # i == 1 for extended memory ! 290: # BIOS call "INT 12H" to get conventional memory size ! 291: # BIOS call "INT 15H, AH=88H" to get extended memory size ! 292: # Both have the return value in AX. ! 293: # ! 294: */ ! 295: ! 296: ENTRY(memsize) ! 297: push %ebp ! 298: mov %esp, %ebp ! 299: push %ebx ! 300: ! 301: mov 8(%ebp), %ebx ! 302: ! 303: call EXT(prot_to_real) # enter real mode ! 304: ! 305: cmpb $0x1, %bl ! 306: data16 ! 307: je xext ! 308: ! 309: sti ! 310: int $0x12 ! 311: cli ! 312: data16 ! 313: jmp xdone ! 314: ! 315: xext: movb $0x88, %ah ! 316: sti ! 317: int $0x15 ! 318: cli ! 319: ! 320: xdone: ! 321: mov %eax, %ebx ! 322: ! 323: data16 ! 324: call EXT(real_to_prot) ! 325: ! 326: mov %ebx, %eax ! 327: pop %ebx ! 328: pop %ebp ! 329: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.