|
|
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: *
44: * Goal is to read in sucessive 7.5Kbytes of bootstrap to
45: * execute.
46: *
47: * No attempt is made to handle disk errors.
1.1.1.4 ! root 48: *
! 49: * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
! 50: * -------------------- ----- ----------------------
! 51: * CURRENT PATCH LEVEL: 1 00073
! 52: * -------------------- ----- ----------------------
! 53: *
! 54: * 22 Jan 93 Frank Maclachlan Fixed NOP's to read correct register
! 55: *
1.1 root 56: */
57: /*#include "/sys/i386/isa/isa.h"
58: #include "/sys/i386/isa/fdreg.h"*/
1.1.1.3 root 59: #define NOP inb $0x84,%al
1.1 root 60: #define BIOSRELOC 0x7c00
1.1.1.3 root 61: #define start RELOC+0x400
1.1 root 62:
1.1.1.3 root 63: /* mumbo-jumbo to pacify DOS, in the hope of getting diskcopy to work */
64: jmp 1f
65: .asciz "386BSD "
66: .byte 1 # sectors per allocation
67: .word 15 # additional sectors for bootstrap
68: .word 0 # number of DOS fat sectors
69: .word 0 # number of DOS rootdir entries
70: .byte 0xf0 # media descriptor
71: .word 0 # number of sectors per a DOS fat entry
72: .word 18 # number of sectors per track
73: .word 2 # number of heads
74: .long 0 # number of hidden sectors
75: .long 2880-18 # logical sectors per volume
76: .byte 0 # physical drive
77: .byte 0x29 # ?
78: .long 137 # binary id
79: .ascii "Release 0.1" # volume label
80: .space 5
81: 1:
1.1 root 82: /* step 0 force descriptors to bottom of address space */
1.1.1.3 root 83:
84: cli
85: .byte 0xb8,0x30,0x00 /* mov $0x30,%ax */
86: mov %ax, %ss
87: .byte 0xbc,0x00,0x01 /* mov $0x100,%sp */
1.1 root 88:
89: xorl %eax,%eax
90: movl %ax,%ds
91: movl %ax,%es
92:
1.1.1.3 root 93: /* obtain BIOS parameters for hard disk XXX */
94: movb $0x9f,%ah /* write to 0x9ff00 XXX */
95: movb $0xf0,%al
96: mov %ax,%es
97: xor %edi,%edi
98:
99: .byte 0xf, 0xb4, 0x36 ; .word 0x41*4 /* lfs 0x41*4, %si */
100: xorb %ch,%ch
101: movb $0x10,%cl
102: fs
103: rep
104: movsb
105:
106: .byte 0xf, 0xb4, 0x36 ; .word 0x46*4 /* lfs 0x46*4, %si */
107: xorb %ch,%ch
108: movb $0x10,%cl
109: fs
110: rep
111: movsb
112:
113: xorl %eax,%eax
114: movl %ax,%es
115:
1.1 root 116: /* step 1 load new descriptor table */
117:
1.1.1.3 root 118: .byte 0x2E,0x0F,1,0x16 /* word aword cs lgdt GDTptr */
119: .word BIOSRELOC+0xa4 #GDTptr
1.1 root 120:
121: /* step 2 turn on protected mode */
122:
123: smsw %ax
124: orb $1,%al
125: lmsw %ax
126: jmp 1f
127: nop
128:
129: /* step 3 reload segment descriptors */
130:
131: 1:
132: xorl %eax,%eax
133: movb $0x10,%al
134: movl %ax,%ds
135: movl %ax,%es
136: movl %ax,%ss
137: word
1.1.1.3 root 138: ljmp $0x8,$ BIOSRELOC+0xb3 /* would be nice if .-RELOC+0x7c00 worked */
1.1 root 139:
140: /* Global Descriptor Table contains three descriptors:
141: * 0x00: Null: not used
142: * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
143: * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
144: * (overlays code)
145: */
146: GDT:
147: NullDesc: .word 0,0,0,0 # null descriptor - not used
148: CodeDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
149: .byte 0,0,0 # base at 0: (bits 23:0)
150: .byte 0x9f # present/priv level 0/code/conforming/readable
151: .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
152: .byte 0 # base at 0: (bits 31:24)
153: DataDesc: .word 0xFFFF # limit at maximum: (bits 15:0)
154: .byte 0,0,0 # base at 0: (bits 23:0)
155: .byte 0x93 # present/priv level 0/data/expand-up/writeable
156: .byte 0xcf # page granular/default 32-bit/limit(bits 19:16)
157: .byte 0 # base at 0: (bits 31:24)
158:
159: /* Global Descriptor Table pointer
160: * contains 6-byte pointer information for LGDT
161: */
162: GDTptr: .word 0x17 # limit to three 8 byte selectors(null,code,data)
1.1.1.3 root 163: .long BIOSRELOC+0x8c # GDT -- arrgh, gas again!
1.1 root 164: readcmd: .byte 0xe6,0,0,0,0,2,18,0x1b,0xff
165:
166: /* step 4 relocate to final bootstrap address. */
167: reloc:
168: movl $ BIOSRELOC,%esi
169: movl $ RELOC,%edi
170: movl $512,%ecx
171: rep
172: movsb
1.1.1.3 root 173: movl $0xa0000, %esp
1.1 root 174: pushl $dodisk
175: ret
176:
177: /* step 5 load remaining 15 sectors off disk */
178: dodisk:
1.1.1.3 root 179: movl $ RELOC+0x200, %edi
180: xorl %ebx, %ebx
181: incb %bl # shl $1,%bl
1.1 root 182: incb %bl
183: movb $0x20,%al # do a eoi
184: outb %al,$0x20
185:
186: NOP
1.1.1.4 ! root 187: movb $0xbf,%al # enable floppy interrupt, mask out rest
1.1 root 188: outb %al,$0x21
189: NOP
190: 8:
191: movb %bl,readcmd+4
192: movl %edi,%ecx
193:
194: /* Set read/write bytes */
195: xorl %edx,%edx
1.1.1.4 ! root 196: movb $0x0c,%dl # outb(0xC,junk); outb(0xB,0x46);
! 197: outb %al,%dx # reset DMA controller first/last flip-flop
1.1 root 198: NOP
199: decb %dx
1.1.1.4 ! root 200: movb $0x46,%al # single mode, write mem, chan 2
! 201: outb %al,%dx # output DMA controller mode byte
1.1 root 202:
203: /* Send start address */
204: movb $0x04,%dl # outb(0x4, addr);
205: movb %cl,%al
206: outb %al,%dx
207: NOP
208: movb %ch,%al # outb(0x4, addr>>8);
209: outb %al,%dx
210: NOP
211: rorl $8,%ecx # outb(0x81, addr>>16);
212: movb %ch,%al
213: outb %al,$0x81
214: NOP
215:
216: /* Send count */
217: movb $0x05,%dl # outb(0x5, 0);
218: xorl %eax,%eax
219: outb %al,%dx
220: NOP
221: movb $2,%al # outb(0x5,2);
222: outb %al,%dx
223: NOP
224:
225: /* set channel 2 */
1.1.1.3 root 226: movb $2,%al # outb(0x0A,2);
1.1 root 227: outb %al,$0x0A
228: NOP
229:
230: /* issue read command to fdc */
231: movw $0x3f4,%dx
232: movl $readcmd,%esi
233: xorl %ecx,%ecx
234: movb $9,%cl
235:
1.1.1.3 root 236: 2: NOP
237: inb %dx,%al
1.1 root 238: testb $0x80,%al
239: jz 2b
240:
241: incb %dx
1.1.1.3 root 242: NOP
1.1 root 243: movl (%esi),%al
244: outb %al,%dx
245: NOP
246: incl %esi
247: decb %dx
248: loop 2b
249:
250: /* watch the icu looking for an interrupt signalling completion */
251: xorl %edx,%edx
252: movb $0x20,%dl
1.1.1.3 root 253: 2:
254: NOP
255: movb $0xc,%al
1.1 root 256: outb %al,%dx
257: NOP
258: inb %dx,%al
259: andb $0x7f,%al
260: cmpb $6,%al
261: jne 2b
1.1.1.3 root 262: NOP
1.1 root 263: movb $0x20,%al # do a eoi
264: outb %al,%dx
265: NOP
266:
267: movl $0x3f4,%edx
268: xorl %ecx,%ecx
269: movb $7,%cl
1.1.1.3 root 270: 2:
1.1 root 271: NOP
1.1.1.3 root 272: inb %dx,%al
1.1 root 273: andb $0xC0,%al
274: cmpb $0xc0,%al
275: jne 2b
276: incb %dx
277: inb %dx,%al
278: decb %dx
279: loop 2b
280:
281: /* extract the status bytes after the read. must we do this? */
282: addw $0x200,%edi # next addr to load to
283: incb %bl
1.1.1.2 root 284: cmpb $15,%bl
1.1 root 285: jle 8b
286:
287: /* for clever bootstrap, dig out boot unit and cylinder */
288: pushl $0
289: pushl $0
290:
291: /* fd controller is major device 2 */
292: pushl $2 /* dev */
293:
294: /* sorry, no flags at this point! */
295:
1.1.1.3 root 296: movl $ start, %eax
297: call %eax /* main (dev, unit, off) */
1.1 root 298:
299: ebootblkcode:
300:
301: /* remaining space usable for a disk label */
302:
1.1.1.3 root 303: .org 0x1fe
1.1 root 304: .word 0xaa55 /* signature -- used by BIOS ROM */
305:
306: 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.