1 /* $NetBSD: bios_disk.S,v 1.21 2011/06/16 13:27:59 joerg 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
142 * biosdisk_getinfo(int dev): return a word that represents the
143 * max number of sectors, heads and cylinders for this device
145 ENTRY(biosdisk_getinfo)
149 movb %al, %dl # diskinfo(drive #)
151 call _C_LABEL(prot_to_real) # enter real mode
154 push %dx # save drive #
155 movb $0x08, %ah # ask for disk info
157 pop %bx # restore drive #
160 testb $0x80, %bl # is it a hard disk?
164 * Urk. Call failed. It is not supported for floppies by old BIOS's.
165 * Guess it's a 15-sector floppy. Initialize all the registers for
166 * documentation, although we only need head and sector counts.
168 xorw %ax, %ax # set status to success
169 # movb %ah, %bh # %bh = 0
170 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
171 movb $79, %ch # max track
172 movb $15, %cl # max sector
173 movb $1, %dh # max head
174 # movb $1, %dl # # floppy drives installed
175 # es:di = parameter table
179 calll _C_LABEL(real_to_prot) # back to protected mode
182 /* form a longword representing all this gunk */
183 shrl $8, %eax # clear unnecessary bits
185 shll $16, %ecx # do the same for %ecx
187 movb %dh, %cl # max head
188 orl %ecx, %eax # return value in %eax
196 * int biosdisk_int13ext(int dev):
197 * check for availibility of int13 extensions.
199 ENTRY(biosdisk_int13ext)
202 movb %al, %dl # drive #
205 call _C_LABEL(prot_to_real) # enter real mode
208 movb $0x41, %ah # ask for disk info
212 calll _C_LABEL(real_to_prot) # switch back
215 movzbl %dl, %eax # return value in %eax
228 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
229 * Call with %ah = 0x42
230 * %ds:%si = parameter block (data buffer address
231 * must be a real mode physical address).
232 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
234 * %al = 0x0 on success; err code on failure
236 ENTRY(biosdisk_extread)
239 movl %edx, %esi # parameter block
240 movb %al, %dl # device
242 call _C_LABEL(prot_to_real) # enter real mode
253 movb $0x42, %ah # subfunction
256 movb %ah, %bh # save error code
259 calll _C_LABEL(real_to_prot) # back to protected mode
262 movzwl %bx, %eax # return value in %eax
268 ENTRY(biosdisk_getextinfo)
271 movl %edx, %esi # parameter block
272 movb %al, %dl # device
274 call _C_LABEL(prot_to_real) # enter real mode
285 movb $0x48, %ah # subfunction
290 calll _C_LABEL(real_to_prot) # back to protected mode
293 movzbl %bl, %eax # return value in %eax