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