bios_disk.S revision 1.5 1 /* $NetBSD: bios_disk.S,v 1.5 1999/03/08 00:09:25 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(): takes a pointer to a biosdisk_ll struct, and fills it in.
118 #
119 */
120
121 ENTRY(get_diskinfo)
122 pushl %ebp
123 movl %esp, %ebp
124 push %es
125 pushl %ebx
126 push %ecx
127 push %edx
128 push %esi
129 push %edi
130
131 movl 8(%ebp), %esi # diskinfo(drive #)
132 movb (%esi), %dl
133 pushl %esi
134
135 call _C_LABEL(prot_to_real) # enter real mode
136
137 movb $0x08, %ah # ask for disk info
138 int $0x13
139 jnc ok
140
141 /*
142 * Urk. Call failed. It is not supported for floppies by old BIOS's.
143 * Guess it's a 15-sector floppy. Initialize all the registers for
144 * documentation, although we only need head and sector counts.
145 */
146 # subb %ah, %ah # %ax = 0
147 # movb %ah, %bh # %bh = 0
148 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
149 # movb $79, %ch # max track
150 movb $15, %cl # max sector
151 movb $1, %dh # max head
152 # movb $1, %dl # # floppy drives installed
153 # es:di = parameter table
154 # carry = 0
155
156 ok:
157 data32
158 call _C_LABEL(real_to_prot) # back to protected mode
159
160 popl %esi
161
162 movzbl %dh, %eax
163 movl %eax, 8(%esi) # heads
164 movb %cl, %al
165 andb $0x3f, %al
166 movzbl %al, %ebx
167 movl %ebx, 4(%esi) # sectors per track
168 xorl %eax, %eax
169 movb %ch, %al
170 andl $0x0c0, %ecx
171 shll $2, %ecx
172 orl %ecx, %eax
173 movl %eax, 12(%esi) # cylinders
174
175 pop %edi
176 pop %esi
177 pop %edx
178 pop %ecx
179 popl %ebx
180 pop %es
181 popl %ebp
182 ret
183
184 /*
185 # int13_extension: check for availibility of int13 extensions.
186 */
187
188 ENTRY(int13_extension)
189 pushl %ebp
190 movl %esp, %ebp
191 pushl %ebx
192 pushl %ecx
193 pushl %edx
194 pushl %esi
195 pushl %edi
196
197 movb 8(%ebp), %dl # drive #
198 movw $0x55aa, %bx
199
200 call _C_LABEL(prot_to_real) # enter real mode
201
202 movb $0x41, %ah # ask for disk info
203 int $0x13
204 setnc %dl
205
206 data32
207 CALL _C_LABEL(real_to_prot) # switch back
208
209 xorl %eax, %eax
210 movb %dl, %al # return value in %ax
211
212 cmpw $0xaa55, %bx
213 sete %dl
214 andb %dl, %al
215
216 andb %cl, %al
217
218 popl %edi
219 popl %esi
220 popl %edx
221 popl %ecx
222 popl %ebx
223 popl %ebp
224 ret
225
226 /*
227 # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
228 # Call with %ah = 0x42
229 # %ds:%si = parameter block
230 # %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
231 # Return:
232 # %al = 0x0 on success; err code on failure
233 */
234 ENTRY(biosextread)
235 pushl %ebp
236 movl %esp, %ebp
237 pushl %ebx
238 push %ecx
239 push %edx
240 push %esi
241 push %edi
242
243 movb 8(%ebp), %dl # device
244 movl 12(%ebp), %esi # parameter block
245
246 call _C_LABEL(prot_to_real) # enter real mode
247
248 movb $0x42, %ah # subfunction
249 int $0x13
250 setc %bl
251
252 data32
253 call _C_LABEL(real_to_prot) # back to protected mode
254
255 xorl %eax, %eax
256 movb %bl, %al # return value in %ax
257
258 pop %edi
259 pop %esi
260 pop %edx
261 pop %ecx
262 popl %ebx
263 popl %ebp
264 ret
265
266 ENTRY(int13_getextinfo)
267 pushl %ebp
268 movl %esp, %ebp
269 pushl %ebx
270 push %ecx
271 push %edx
272 push %esi
273 push %edi
274
275 movb 8(%ebp), %dl # device
276 movl 12(%ebp), %esi # parameter block
277 movl $0x01a, (%esi) # length (v 1.x)
278
279 call _C_LABEL(prot_to_real) # enter real mode
280
281 movb $0x48, %ah # subfunction
282 int $0x13
283 setc %bl
284
285 data32
286 call _C_LABEL(real_to_prot) # back to protected mode
287
288 xorl %eax, %eax
289 movb %bl, %al # return value in %ax
290
291 pop %edi
292 pop %esi
293 pop %edx
294 pop %ecx
295 popl %ebx
296 popl %ebp
297 ret
298