|
|
1.1 ! root 1: /*- ! 2: * Copyright (c) 1990 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This code is derived from software contributed to Berkeley by ! 6: * William Jolitz. ! 7: * ! 8: * Redistribution and use in source and binary forms, with or without ! 9: * modification, are permitted provided that the following conditions ! 10: * are met: ! 11: * 1. Redistributions of source code must retain the above copyright ! 12: * notice, this list of conditions and the following disclaimer. ! 13: * 2. Redistributions in binary form must reproduce the above copyright ! 14: * notice, this list of conditions and the following disclaimer in the ! 15: * documentation and/or other materials provided with the distribution. ! 16: * 3. All advertising materials mentioning features or use of this software ! 17: * must display the following acknowledgement: ! 18: * This product includes software developed by the University of ! 19: * California, Berkeley and its contributors. ! 20: * 4. Neither the name of the University nor the names of its contributors ! 21: * may be used to endorse or promote products derived from this software ! 22: * without specific prior written permission. ! 23: * ! 24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 34: * SUCH DAMAGE. ! 35: * ! 36: * @(#)fdbootblk.c 7.2 (Berkeley) 5/4/91 ! 37: */ ! 38: ! 39: /* ! 40: * fdbootblk.s: ! 41: * Written 10/6/90 by William F. Jolitz ! 42: * Initial block boot for AT/386 with typical stupid NEC controller ! 43: * Works only with 3.5 inch diskettes that have 16 or greater sectors/side ! 44: * ! 45: * Goal is to read in sucessive 7.5Kbytes of bootstrap to ! 46: * execute. ! 47: * ! 48: * No attempt is made to handle disk errors. ! 49: */ ! 50: /*#include "/sys/i386/isa/isa.h" ! 51: #include "/sys/i386/isa/fdreg.h"*/ ! 52: #define NOP jmp 1f ; nop ; 1: ! 53: #define BIOSRELOC 0x7c00 ! 54: #define start 0x70400 ! 55: ! 56: /* step 0 force descriptors to bottom of address space */ ! 57: ! 58: .byte 0xfa,0xb8,0x30,0x00,0x8e,0xd0,0xbc,0x00,0x01 #ll fb ! 59: ! 60: xorl %eax,%eax ! 61: movl %ax,%ds ! 62: movl %ax,%es ! 63: ! 64: /* step 1 load new descriptor table */ ! 65: ! 66: .byte 0x2E,0x0F,1,0x16 ! 67: .word BIOSRELOC+0x4a #GDTptr ! 68: # word aword cs lgdt GDTptr ! 69: ! 70: /* step 2 turn on protected mode */ ! 71: ! 72: smsw %ax ! 73: orb $1,%al ! 74: lmsw %ax ! 75: jmp 1f ! 76: nop ! 77: ! 78: /* step 3 reload segment descriptors */ ! 79: ! 80: 1: ! 81: xorl %eax,%eax ! 82: movb $0x10,%al ! 83: movl %ax,%ds ! 84: movl %ax,%es ! 85: movl %ax,%ss ! 86: word ! 87: ljmp $0x8,$ BIOSRELOC+0x59 /* would be nice if .-RELOC+0x7c00 worked */ ! 88: ! 89: /* Global Descriptor Table contains three descriptors: ! 90: * 0x00: Null: not used ! 91: * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes ! 92: * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes ! 93: * (overlays code) ! 94: */ ! 95: GDT: ! 96: NullDesc: .word 0,0,0,0 # null descriptor - not used ! 97: CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0) ! 98: .byte 0,0,0 # base at 0: (bits 23:0) ! 99: .byte 0x9f # present/priv level 0/code/conforming/readable ! 100: .byte 0xcf # page granular/default 32-bit/limit(bits 19:16) ! 101: .byte 0 # base at 0: (bits 31:24) ! 102: DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0) ! 103: .byte 0,0,0 # base at 0: (bits 23:0) ! 104: .byte 0x93 # present/priv level 0/data/expand-up/writeable ! 105: .byte 0xcf # page granular/default 32-bit/limit(bits 19:16) ! 106: .byte 0 # base at 0: (bits 31:24) ! 107: ! 108: /* Global Descriptor Table pointer ! 109: * contains 6-byte pointer information for LGDT ! 110: */ ! 111: GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data) ! 112: .long BIOSRELOC+0x32 # GDT -- arrgh, gas again! ! 113: readcmd: .byte 0xe6,0,0,0,0,2,18,0x1b,0xff ! 114: ! 115: /* step 4 relocate to final bootstrap address. */ ! 116: reloc: ! 117: movl $ BIOSRELOC,%esi ! 118: movl $ RELOC,%edi ! 119: movl $512,%ecx ! 120: rep ! 121: movsb ! 122: pushl $dodisk ! 123: ret ! 124: ! 125: /* step 5 load remaining 15 sectors off disk */ ! 126: dodisk: ! 127: movl $0x70200,%edi ! 128: xorl %ebx,%ebx ! 129: incb %bl ! 130: incb %bl ! 131: movb $0x20,%al # do a eoi ! 132: outb %al,$0x20 ! 133: ! 134: NOP ! 135: movb $0x07,%al ! 136: outb %al,$0x21 ! 137: NOP ! 138: 8: ! 139: movb %bl,readcmd+4 ! 140: movl %edi,%ecx ! 141: ! 142: /* Set read/write bytes */ ! 143: xorl %edx,%edx ! 144: movb $0x0c,%dl # outb(0xC,0x46); outb(0xB,0x46); ! 145: movb $0x46,%al ! 146: outb %al,%dx ! 147: NOP ! 148: decb %dx ! 149: outb %al,%dx ! 150: ! 151: /* Send start address */ ! 152: movb $0x04,%dl # outb(0x4, addr); ! 153: movb %cl,%al ! 154: outb %al,%dx ! 155: NOP ! 156: movb %ch,%al # outb(0x4, addr>>8); ! 157: outb %al,%dx ! 158: NOP ! 159: rorl $8,%ecx # outb(0x81, addr>>16); ! 160: movb %ch,%al ! 161: outb %al,$0x81 ! 162: NOP ! 163: ! 164: /* Send count */ ! 165: movb $0x05,%dl # outb(0x5, 0); ! 166: xorl %eax,%eax ! 167: outb %al,%dx ! 168: NOP ! 169: movb $2,%al # outb(0x5,2); ! 170: outb %al,%dx ! 171: NOP ! 172: ! 173: /* set channel 2 */ ! 174: # movb $2,%al # outb(0x0A,2); ! 175: outb %al,$0x0A ! 176: NOP ! 177: ! 178: /* issue read command to fdc */ ! 179: movw $0x3f4,%dx ! 180: movl $readcmd,%esi ! 181: xorl %ecx,%ecx ! 182: movb $9,%cl ! 183: ! 184: 2: inb %dx,%al ! 185: NOP ! 186: testb $0x80,%al ! 187: jz 2b ! 188: ! 189: incb %dx ! 190: movl (%esi),%al ! 191: outb %al,%dx ! 192: NOP ! 193: incl %esi ! 194: decb %dx ! 195: loop 2b ! 196: ! 197: /* watch the icu looking for an interrupt signalling completion */ ! 198: xorl %edx,%edx ! 199: movb $0x20,%dl ! 200: 2: movb $0xc,%al ! 201: outb %al,%dx ! 202: NOP ! 203: inb %dx,%al ! 204: NOP ! 205: andb $0x7f,%al ! 206: cmpb $6,%al ! 207: jne 2b ! 208: movb $0x20,%al # do a eoi ! 209: outb %al,%dx ! 210: NOP ! 211: ! 212: movl $0x3f4,%edx ! 213: xorl %ecx,%ecx ! 214: movb $7,%cl ! 215: 2: inb %dx,%al ! 216: NOP ! 217: andb $0xC0,%al ! 218: cmpb $0xc0,%al ! 219: jne 2b ! 220: incb %dx ! 221: inb %dx,%al ! 222: decb %dx ! 223: loop 2b ! 224: ! 225: /* extract the status bytes after the read. must we do this? */ ! 226: addw $0x200,%edi # next addr to load to ! 227: incb %bl ! 228: cmpb $16,%bl ! 229: jle 8b ! 230: ! 231: /* for clever bootstrap, dig out boot unit and cylinder */ ! 232: pushl $0 ! 233: pushl $0 ! 234: ! 235: /* fd controller is major device 2 */ ! 236: pushl $2 /* dev */ ! 237: ! 238: /* sorry, no flags at this point! */ ! 239: ! 240: pushl $ start ! 241: ret /* main (dev, unit, off) */ ! 242: ! 243: ebootblkcode: ! 244: ! 245: /* remaining space usable for a disk label */ ! 246: ! 247: .space 510-310 /* would be nice if .space 512-2-. worked */ ! 248: .word 0xaa55 /* signature -- used by BIOS ROM */ ! 249: ! 250: ebootblk: /* MUST BE EXACTLY 0x200 BIG FOR SURE */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.