bios_disk.S revision 1.11 1 /* $NetBSD: bios_disk.S,v 1.11 2003/02/05 21:41:51 dsl Exp $ */
2
3 /*
4 * Ported to boot 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
5 *
6 * Mach Operating System
7 * Copyright (c) 1992, 1991 Carnegie Mellon University
8 * All Rights Reserved.
9 *
10 * Permission to use, copy, modify and distribute this software and its
11 * documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie Mellon
28 * the rights to redistribute these changes.
29 */
30
31 /*
32 Copyright 1988, 1989, 1990, 1991, 1992
33 by Intel Corporation, Santa Clara, California.
34
35 All Rights Reserved
36
37 Permission to use, copy, modify, and distribute this software and
38 its documentation for any purpose and without fee is hereby
39 granted, provided that the above copyright notice appears in all
40 copies and that both the copyright notice and this permission notice
41 appear in supporting documentation, and that the name of Intel
42 not be used in advertising or publicity pertaining to distribution
43 of the software without specific, written prior permission.
44
45 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 */
53
54 /* extracted from netbsd:sys/arch/i386/boot/bios.S */
55
56 #include <machine/asm.h>
57
58 /*
59 # BIOS call "INT 0x13 Function 0x0" to reset the disk subsystem
60 # Call with %ah = 0x0
61 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
62 # Return:
63 # %al = 0x0 on success; err code on failure
64 */
65 ENTRY(biosdiskreset)
66 pushl %ebp
67 movl %esp, %ebp
68 pushl %ebx
69 push %edx
70 push %edi
71
72 movb 8(%ebp), %dl # device
73
74 call _C_LABEL(prot_to_real) # enter real mode
75 .code16
76
77 movb $0x0, %ah # subfunction
78 int $0x13
79 setc %bl
80 movb %ah, %bh # save error code
81
82 calll _C_LABEL(real_to_prot) # back to protected mode
83 .code32
84
85 xorl %eax, %eax
86 movw %bx, %ax # return value in %ax
87
88 pop %edi
89 pop %edx
90 popl %ebx
91 popl %ebp
92 ret
93
94 /*
95 # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
96 # Call with %ah = 0x2
97 # %al = number of sectors
98 # %ch = cylinder
99 # %cl = sector
100 # %dh = head
101 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
102 # %es:%bx = segment:offset of buffer
103 # Return:
104 # %al = 0x0 on success; err code on failure
105 #
106 # biosread( dev, cyl, head, sect, count, buff_addr );
107 #
108 # Note: On failure, you must reset the disk with biosdiskreset() before
109 # sending another command.
110 */
111 ENTRY(biosread)
112 pushl %ebp
113 movl %esp, %ebp
114 pushl %ebx
115 push %ecx
116 push %edx
117 push %esi
118 push %edi
119
120 movb 16(%ebp), %dh
121 movw 12(%ebp), %cx
122 xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl
123 rorb $2, %cl
124 movb 20(%ebp), %al
125 orb %al, %cl
126 incb %cl # sector; sec starts from 1, not 0
127 movb 8(%ebp), %dl # device
128
129 call _C_LABEL(prot_to_real) # enter real mode
130 .code16
131
132 movl 28(%bp), %ebx # buffer address (may be >64k)
133 movl %ebx, %eax
134 shrl $4, %eax # max segment
135 andl $0xf, %ebx # and min offset - to avoid overrun
136 mov %ds, %si
137 add %si, %ax
138 mov %ax, %es # %es:%bx now valid buffer address
139
140 movb $0x2, %ah # subfunction
141 movb 24(%bp), %al # number of sectors
142 int $0x13
143 setc %bl
144 movb %ah, %bh # save error code
145
146 calll _C_LABEL(real_to_prot) # back to protected mode
147 .code32
148
149 xorl %eax, %eax
150 movw %bx, %ax # return value in %ax
151
152 pop %edi
153 pop %esi
154 pop %edx
155 pop %ecx
156 popl %ebx
157 popl %ebp
158 ret
159
160 /*
161 #
162 # get_diskinfo(): return a word that represents the
163 # max number of sectors, heads and cylinders for this device
164 #
165 */
166
167 ENTRY(get_diskinfo)
168 pushl %ebp
169 movl %esp, %ebp
170 push %es
171 pushl %ebx
172 push %ecx
173 push %edx
174 push %esi
175 push %edi
176
177 movb 8(%ebp), %dl # diskinfo(drive #)
178
179 call _C_LABEL(prot_to_real) # enter real mode
180 .code16
181
182 movb $0x08, %ah # ask for disk info
183 int $0x13
184 jnc ok
185
186 /*
187 * Urk. Call failed. It is not supported for floppies by old BIOS's.
188 * Guess it's a 15-sector floppy. Initialize all the registers for
189 * documentation, although we only need head and sector counts.
190 */
191 # subb %ah, %ah # %ax = 0
192 # movb %ah, %bh # %bh = 0
193 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
194 movb $79, %ch # max track
195 movb $15, %cl # max sector
196 movb $1, %dh # max head
197 # movb $1, %dl # # floppy drives installed
198 # es:di = parameter table
199 # carry = 0
200
201 ok:
202 calll _C_LABEL(real_to_prot) # back to protected mode
203 .code32
204
205 /* form a longword representing all this gunk */
206 shll $8, %ecx
207 movb %dh, %cl
208
209 movl %ecx, %eax
210
211 pop %edi
212 pop %esi
213 pop %edx
214 pop %ecx
215 popl %ebx
216 pop %es
217 popl %ebp
218 ret
219
220 /*
221 # int13_extension: check for availibility of int13 extensions.
222 */
223
224 ENTRY(int13_extension)
225 pushl %ebp
226 movl %esp, %ebp
227 pushl %ebx
228 pushl %ecx
229 pushl %edx
230 pushl %esi
231 pushl %edi
232
233 movb 8(%ebp), %dl # drive #
234 movw $0x55aa, %bx
235
236 call _C_LABEL(prot_to_real) # enter real mode
237 .code16
238
239 movb $0x41, %ah # ask for disk info
240 int $0x13
241 setnc %dl
242
243 calll _C_LABEL(real_to_prot) # switch back
244 .code32
245
246 xorl %eax, %eax
247 movb %dl, %al # return value in %ax
248
249 cmpw $0xaa55, %bx
250 sete %dl
251 andb %dl, %al
252
253 andb %cl, %al
254
255 popl %edi
256 popl %esi
257 popl %edx
258 popl %ecx
259 popl %ebx
260 popl %ebp
261 ret
262
263 /*
264 # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
265 # Call with %ah = 0x42
266 # %ds:%si = parameter block (data buffer address
267 # must be a real mode physical address).
268 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
269 # Return:
270 # %al = 0x0 on success; err code on failure
271 */
272 ENTRY(biosextread)
273 pushl %ebp
274 movl %esp, %ebp
275 pushl %ebx
276 push %ecx
277 push %edx
278 push %esi
279 push %edi
280
281 movb 8(%ebp), %dl # device
282 movl 12(%ebp), %esi # parameter block
283
284 call _C_LABEL(prot_to_real) # enter real mode
285 .code16
286
287 movl %esi, %eax
288 shrl $4, %eax
289 movw %ds, %bx
290 addw %bx, %ax
291 movw %ax, %ds
292 andw $0xf, %si
293
294 movb $0x42, %ah # subfunction
295 int $0x13
296 setc %bl
297 movb %ah, %bh # save error code
298
299 calll _C_LABEL(real_to_prot) # back to protected mode
300 .code32
301
302 xorl %eax, %eax
303 movw %bx, %ax # return value in %ax
304
305 pop %edi
306 pop %esi
307 pop %edx
308 pop %ecx
309 popl %ebx
310 popl %ebp
311 ret
312
313 ENTRY(int13_getextinfo)
314 pushl %ebp
315 movl %esp, %ebp
316 pushl %ebx
317 push %ecx
318 push %edx
319 push %esi
320 push %edi
321
322 movb 8(%ebp), %dl # device
323 movl 12(%ebp), %esi # parameter block
324 movl $0x01a, (%esi) # length (v 1.x)
325
326 call _C_LABEL(prot_to_real) # enter real mode
327 .code16
328
329 movl %esi, %eax
330 shrl $4, %eax
331 andw $0xf, %si
332 movw %ds, %bx
333 addw %bx, %ax
334 movw %ax, %ds
335
336 movb $0x48, %ah # subfunction
337 int $0x13
338 setc %bl
339
340 calll _C_LABEL(real_to_prot) # back to protected mode
341 .code32
342
343 xorl %eax, %eax
344 movb %bl, %al # return value in %ax
345
346 pop %edi
347 pop %esi
348 pop %edx
349 pop %ecx
350 popl %ebx
351 popl %ebp
352 ret
353