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