xref: /netbsd-src/sys/arch/i386/stand/lib/bios_disk.S (revision c41a4eebefede43f6950f838a387dc18c6a431bf)
1/*	$NetBSD: bios_disk.S,v 1.1.1.1 1997/03/14 02:40:32 perry Exp $	*/
2
3/*
4 * Ported to boot 386BSD by Julian Elischer (julian@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@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
37Permission to use, copy, modify, and distribute this software and
38its documentation for any purpose and without fee is hereby
39granted, provided that the above copyright notice appears in all
40copies and that both the copyright notice and this permission notice
41appear in supporting documentation, and that the name of Intel
42not be used in advertising or publicity pertaining to distribution
43of the software without specific, written prior permission.
44
45INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51WITH 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*/
73ENTRY(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():  return a word that represents the
118#	max number of sectors and  heads and drives for this device
119#
120*/
121
122ENTRY(get_diskinfo)
123	pushl	%ebp
124	movl	%esp, %ebp
125	push	%es
126	pushl	%ebx
127	push	%ecx
128	push	%edx
129	push	%esi
130	push	%edi
131
132	movb	8(%ebp), %dl		# diskinfo(drive #)
133
134	call	_C_LABEL(prot_to_real)	# enter real mode
135
136	movb	$0x08, %ah		# ask for disk info
137	int	$0x13
138	jnc	ok
139
140	/*
141	 * Urk.  Call failed.  It is not supported for floppies by old BIOS's.
142	 * Guess it's a 15-sector floppy.  Initialize all the registers for
143	 * documentation, although we only need head and sector counts.
144	 */
145#	subb	%ah, %ah		# %ax = 0
146#	movb	%ah, %bh		# %bh = 0
147#	movb	$2, %bl			# %bl bits 0-3 = drive type, 2 = 1.2M
148#	movb	$79, %ch		# max track
149	movb	$15, %cl		# max sector
150	movb	$1, %dh			# max head
151#	movb	$1, %dl			# # floppy drives installed
152	# es:di = parameter table
153	# carry = 0
154
155ok:
156	data32
157	call	_C_LABEL(real_to_prot)	# back to protected mode
158
159	xorl	%eax, %eax
160
161	/*form a longword representing all this gunk*/
162	movb	%dh, %ah		# max head
163	andb	$0x3f, %cl		# mask of cylinder gunk
164	movb	%cl, %al		# max sector (and # sectors)
165
166	pop	%edi
167	pop	%esi
168	pop	%edx
169	pop	%ecx
170	popl	%ebx
171	pop	%es
172	popl	%ebp
173	ret
174