1 /* $NetBSD: bios_disk.S,v 1.22 2014/07/19 14:50:21 erh Exp $ */
4 * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
6 * Mach Operating System
7 * Copyright (c) 1992, 1991 Carnegie Mellon University
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.
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.
20 * Carnegie Mellon requests users of this software to return to
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
27 * any improvements or extensions that they make and grant Carnegie Mellon
28 * the rights to redistribute these changes.
32 Copyright 1988, 1989, 1990, 1991, 1992
33 by Intel Corporation, Santa Clara, California.
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.
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.
54 /* extracted from netbsd:sys/arch/i386/boot/bios.S */
56 #include <machine/asm.h>
59 * BIOS call "INT 0x13 Function 0x0" to reset the disk subsystem
61 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
63 * %al = 0x0 on success; err code on failure
68 movb %al, %dl # device
70 call _C_LABEL(prot_to_real) # enter real mode
73 movb $0x0, %ah # subfunction
76 movb %ah, %bh # save error code
78 calll _C_LABEL(real_to_prot) # back to protected mode
81 movzwl %bx, %eax # return value in %eax
88 * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
90 * %al = number of sectors
94 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
95 * %es:%bx = segment:offset of buffer
97 * %al = 0x0 on success; err code on failure
99 * biosdisk_read(dev, cyl, head, sect, count, buff_addr);
101 * Note: On failure, you must reset the disk with biosdisk_reset() before
102 * sending another command.
109 xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl
113 incb %cl # sector; sec starts from 1, not 0
114 movb 36(%esp), %dl # device
115 movl 56(%esp), %ebx # buffer address (may be >64k)
116 movb 52(%esp), %al # number of sectors
118 call _C_LABEL(prot_to_real) # enter real mode
122 shrl $4, %ebx # max segment
125 mov %bx, %es # %es:%bx now valid buffer address
127 and $0xf, %bx # and min offset - to avoid overrun
129 movb $0x2, %ah # subfunction
131 setc %al # error code is in %ah
133 calll _C_LABEL(real_to_prot) # back to protected mode
136 andl $0x0000FFFF, %eax # Some bioses set high bits in %eax
137 # on success, interfering with our
138 # return value. Clear those out.
145 * biosdisk_getinfo(int dev): return a word that represents the
146 * max number of sectors, heads and cylinders for this device
148 ENTRY(biosdisk_getinfo)
152 movb %al, %dl # diskinfo(drive #)
154 call _C_LABEL(prot_to_real) # enter real mode
157 push %dx # save drive #
158 movb $0x08, %ah # ask for disk info
160 pop %bx # restore drive #
163 testb $0x80, %bl # is it a hard disk?
167 * Urk. Call failed. It is not supported for floppies by old BIOS's.
168 * Guess it's a 15-sector floppy. Initialize all the registers for
169 * documentation, although we only need head and sector counts.
171 xorw %ax, %ax # set status to success
172 # movb %ah, %bh # %bh = 0
173 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
174 movb $79, %ch # max track
175 movb $15, %cl # max sector
176 movb $1, %dh # max head
177 # movb $1, %dl # # floppy drives installed
178 # es:di = parameter table
182 calll _C_LABEL(real_to_prot) # back to protected mode
185 /* form a longword representing all this gunk */
186 shrl $8, %eax # clear unnecessary bits
188 shll $16, %ecx # do the same for %ecx
190 movb %dh, %cl # max head
191 orl %ecx, %eax # return value in %eax
199 * int biosdisk_int13ext(int dev):
200 * check for availibility of int13 extensions.
202 ENTRY(biosdisk_int13ext)
205 movb %al, %dl # drive #
208 call _C_LABEL(prot_to_real) # enter real mode
211 movb $0x41, %ah # ask for disk info
215 calll _C_LABEL(real_to_prot) # switch back
218 movzbl %dl, %eax # return value in %eax
231 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
232 * Call with %ah = 0x42
233 * %ds:%si = parameter block (data buffer address
234 * must be a real mode physical address).
235 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
237 * %al = 0x0 on success; err code on failure
239 ENTRY(biosdisk_extread)
242 movl %edx, %esi # parameter block
243 movb %al, %dl # device
245 call _C_LABEL(prot_to_real) # enter real mode
256 movb $0x42, %ah # subfunction
259 movb %ah, %bh # save error code
262 calll _C_LABEL(real_to_prot) # back to protected mode
265 movzwl %bx, %eax # return value in %eax
271 ENTRY(biosdisk_getextinfo)
274 movl %edx, %esi # parameter block
275 movb %al, %dl # device
277 call _C_LABEL(prot_to_real) # enter real mode
288 movb $0x48, %ah # subfunction
293 calll _C_LABEL(real_to_prot) # back to protected mode
296 movzbl %bl, %eax # return value in %eax