1 /* $NetBSD: bios_disk.S,v 1.18 2005/12/11 12:17:48 christos 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
72 movb 8(%ebp), %dl # device
74 call _C_LABEL(prot_to_real) # enter real mode
77 movb $0x0, %ah # subfunction
80 movb %ah, %bh # save error code
82 calll _C_LABEL(real_to_prot) # back to protected mode
86 movw %bx, %ax # return value in %ax
95 * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
97 * %al = number of sectors
101 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
102 * %es:%bx = segment:offset of buffer
104 * %al = 0x0 on success; err code on failure
106 * biosdisk_read(dev, cyl, head, sect, count, buff_addr);
108 * Note: On failure, you must reset the disk with biosdisk_reset() before
109 * sending another command.
122 xchgb %ch, %cl # cylinder; the highest 2 bits of cyl is in %cl
126 incb %cl # sector; sec starts from 1, not 0
127 movb 8(%ebp), %dl # device
128 movl 28(%ebp), %ebx # buffer address (may be >64k)
129 movb 24(%ebp), %al # number of sectors
131 call _C_LABEL(prot_to_real) # enter real mode
135 shrl $4, %ebx # max segment
138 mov %bx, %es # %es:%bx now valid buffer address
140 and $0xf, %bx # and min offset - to avoid overrun
142 movb $0x2, %ah # subfunction
144 setc %al # error code is in %ah
146 calll _C_LABEL(real_to_prot) # back to protected mode
160 * biosdisk_getinfo(int dev): return a word that represents the
161 * max number of sectors, heads and cylinders for this device
163 ENTRY(biosdisk_getinfo)
173 movb 8(%ebp), %dl # diskinfo(drive #)
175 call _C_LABEL(prot_to_real) # enter real mode
178 push %dx # save drive #
179 movb $0x08, %ah # ask for disk info
181 pop %bx # restore drive #
184 testb $0x80, %bl # is it a hard disk?
188 * Urk. Call failed. It is not supported for floppies by old BIOS's.
189 * Guess it's a 15-sector floppy. Initialize all the registers for
190 * documentation, although we only need head and sector counts.
192 xorw %ax, %ax # set status to success
193 # movb %ah, %bh # %bh = 0
194 # movb $2, %bl # %bl bits 0-3 = drive type, 2 = 1.2M
195 movb $79, %ch # max track
196 movb $15, %cl # max sector
197 movb $1, %dh # max head
198 # movb $1, %dl # # floppy drives installed
199 # es:di = parameter table
203 calll _C_LABEL(real_to_prot) # back to protected mode
206 /* form a longword representing all this gunk */
207 shrl $8, %eax # clear unnecessary bits
209 shll $16, %ecx # do the same for %ecx
211 movb %dh, %cl # max head
212 orl %ecx, %eax # return value in %eax
224 * int biosdisk_int13ext(int dev):
225 * check for availibility of int13 extensions.
227 ENTRY(biosdisk_int13ext)
236 movb 8(%ebp), %dl # drive #
239 call _C_LABEL(prot_to_real) # enter real mode
242 movb $0x41, %ah # ask for disk info
246 calll _C_LABEL(real_to_prot) # switch back
250 movb %dl, %al # return value in %ax
267 * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
268 * Call with %ah = 0x42
269 * %ds:%si = parameter block (data buffer address
270 * must be a real mode physical address).
271 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
273 * %al = 0x0 on success; err code on failure
275 ENTRY(biosdisk_extread)
284 movb 8(%ebp), %dl # device
285 movl 12(%ebp), %esi # parameter block
287 call _C_LABEL(prot_to_real) # enter real mode
298 movb $0x42, %ah # subfunction
301 movb %ah, %bh # save error code
304 calll _C_LABEL(real_to_prot) # back to protected mode
308 movw %bx, %ax # return value in %ax
318 ENTRY(biosdisk_getextinfo)
327 movb 8(%ebp), %dl # device
328 movl 12(%ebp), %esi # parameter block
330 call _C_LABEL(prot_to_real) # enter real mode
341 movb $0x48, %ah # subfunction
346 calll _C_LABEL(real_to_prot) # back to protected mode
350 movb %bl, %al # return value in %ax