bios_disk.S revision 1.7 1 /* $NetBSD: bios_disk.S,v 1.7 1999/03/30 22:35:21 fvdl 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 #define addr32 .byte 0x67
59 #define data32 .byte 0x66
60
61 /*
62 # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
63 # Call with %ah = 0x2
64 # %al = number of sectors
65 # %ch = cylinder
66 # %cl = sector
67 # %dh = head
68 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
69 # %es:%bx = segment:offset of buffer
70 # Return:
71 # %al = 0x0 on success; err code on failure
72 */
73 ENTRY(biosread)
74 pushl %ebp
75 movl %esp, %ebp
76 pushl %ebx
77 push %ecx
78 push %edx
79 push %esi
80 push %edi
81
82 movb 16(%ebp), %dh
83 movw 12(%ebp), %cx
84 xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl
85 rorb $2, %cl
86 movb 20(%ebp), %al
87 orb %al, %cl
88 incb %cl # sector; sec starts from 1, not 0
89 movb 8(%ebp), %dl # device
90 movl 28(%ebp), %ebx # offset
91 # prot_to_real will set %es to BOOTSEG
92
93 call _C_LABEL(prot_to_real) # enter real mode
94
95 movb $0x2, %ah # subfunction
96 addr32
97 movb 24(%ebp), %al # number of sectors
98 int $0x13
99 setc %bl
100
101 data32
102 call _C_LABEL(real_to_prot) # back to protected mode
103
104 xorl %eax, %eax
105 movb %bl, %al # return value in %ax
106
107 pop %edi
108 pop %esi
109 pop %edx
110 pop %ecx
111 popl %ebx
112 popl %ebp
113 ret
114
115 /*
116 #
117 # get_diskinfo(): return a word that represents the
118 # max number of sectors, heads and cylinders for this device
119 #
120 */
121
122 ENTRY(get_diskinfo)
123 pushl %ebp
124 movl %esp, %ebp
125 push %es
126 pushl %ebx
127 push %ecx
128 push %edx
129 push %esi
130 push %edi
131
132 movb 8(%ebp), %dl # diskinfo(drive #)
133
134 call _C_LABEL(prot_to_real) # enter real mode
135
136 movb $0x08, %ah # ask for disk info
137 int $0x13
138 jnc ok
139
140 /*
141 * Urk. Call failed. It is not supported for floppies by old BIOS's.
142 * Guess it's a 15-sector floppy. Initialize all the registers for
143 * documentation, although we only need head and sector counts.
144 */
145 # subb %ah, %ah # %ax = 0
146 # movb %ah, %bh # %bh = 0
147 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
148 movb $79, %ch # max track
149 movb $15, %cl # max sector
150 movb $1, %dh # max head
151 # movb $1, %dl # # floppy drives installed
152 # es:di = parameter table
153 # carry = 0
154
155 ok:
156 data32
157 call _C_LABEL(real_to_prot) # back to protected mode
158
159 /* form a longword representing all this gunk */
160 shll $8, %ecx
161 movb %dh, %cl
162
163 movl %ecx, %eax
164
165 pop %edi
166 pop %esi
167 pop %edx
168 pop %ecx
169 popl %ebx
170 pop %es
171 popl %ebp
172 ret
173
174 /*
175 # int13_extension: check for availibility of int13 extensions.
176 */
177
178 ENTRY(int13_extension)
179 pushl %ebp
180 movl %esp, %ebp
181 pushl %ebx
182 pushl %ecx
183 pushl %edx
184 pushl %esi
185 pushl %edi
186
187 movb 8(%ebp), %dl # drive #
188 movw $0x55aa, %bx
189
190 call _C_LABEL(prot_to_real) # enter real mode
191
192 movb $0x41, %ah # ask for disk info
193 int $0x13
194 setnc %dl
195
196 data32
197 CALL _C_LABEL(real_to_prot) # switch back
198
199 xorl %eax, %eax
200 movb %dl, %al # return value in %ax
201
202 cmpw $0xaa55, %bx
203 sete %dl
204 andb %dl, %al
205
206 andb %cl, %al
207
208 popl %edi
209 popl %esi
210 popl %edx
211 popl %ecx
212 popl %ebx
213 popl %ebp
214 ret
215
216 /*
217 # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
218 # Call with %ah = 0x42
219 # %ds:%si = parameter block
220 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
221 # Return:
222 # %al = 0x0 on success; err code on failure
223 */
224 ENTRY(biosextread)
225 pushl %ebp
226 movl %esp, %ebp
227 pushl %ebx
228 push %ecx
229 push %edx
230 push %esi
231 push %edi
232
233 movb 8(%ebp), %dl # device
234 movl 12(%ebp), %esi # parameter block
235
236 call _C_LABEL(prot_to_real) # enter real mode
237
238 movb $0x42, %ah # subfunction
239 int $0x13
240 setc %bl
241
242 data32
243 call _C_LABEL(real_to_prot) # back to protected mode
244
245 xorl %eax, %eax
246 movb %bl, %al # return value in %ax
247
248 pop %edi
249 pop %esi
250 pop %edx
251 pop %ecx
252 popl %ebx
253 popl %ebp
254 ret
255
256 ENTRY(int13_getextinfo)
257 pushl %ebp
258 movl %esp, %ebp
259 pushl %ebx
260 push %ecx
261 push %edx
262 push %esi
263 push %edi
264
265 movb 8(%ebp), %dl # device
266 movl 12(%ebp), %esi # parameter block
267 movl $0x01a, (%esi) # length (v 1.x)
268
269 call _C_LABEL(prot_to_real) # enter real mode
270
271 movb $0x48, %ah # subfunction
272 int $0x13
273 setc %bl
274
275 data32
276 call _C_LABEL(real_to_prot) # back to protected mode
277
278 xorl %eax, %eax
279 movb %bl, %al # return value in %ax
280
281 pop %edi
282 pop %esi
283 pop %edx
284 pop %ecx
285 popl %ebx
286 popl %ebp
287 ret
288