Home | History | Annotate | Line # | Download | only in lib
bios_disk.S revision 1.6
      1 /*	$NetBSD: bios_disk.S,v 1.6 1999/03/30 17:55:48 drochner Exp $	*/
      2 
      3 /*
      4  * Ported to boot 386BSD by Julian Elischer (julian (at) 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 (at) 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 
     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.
     44 
     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.
     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 */
     73 ENTRY(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, heads and cylinders for this device
    119 #
    120 */
    121 
    122 ENTRY(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 
    155 ok:
    156 	/* form a longword representing all this gunk */
    157 	shll	$8, %ecx
    158 	movb	%dh, %cl
    159 
    160 	data32
    161 	call	_C_LABEL(real_to_prot)	# back to protected mode
    162 
    163 	data32
    164 	movl	%ecx, %eax
    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 
    175 /*
    176 # int13_extension: check for availibility of int13 extensions.
    177 */
    178 
    179 ENTRY(int13_extension)
    180 	pushl	%ebp
    181 	movl	%esp, %ebp
    182 	pushl	%ebx
    183 	pushl	%ecx
    184 	pushl	%edx
    185 	pushl	%esi
    186 	pushl	%edi
    187 
    188 	movb	8(%ebp), %dl		# drive #
    189 	movw	$0x55aa, %bx
    190 
    191 	call	_C_LABEL(prot_to_real)	# enter real mode
    192 
    193 	movb	$0x41, %ah		# ask for disk info
    194 	int	$0x13
    195 	setnc	%dl
    196 
    197 	data32
    198 	CALL	_C_LABEL(real_to_prot)	# switch back
    199 
    200 	xorl	%eax, %eax
    201 	movb	%dl, %al	# return value in %ax
    202 
    203 	cmpw	$0xaa55, %bx
    204 	sete	%dl
    205 	andb	%dl, %al
    206 
    207 	andb	%cl, %al
    208 
    209 	popl	%edi
    210 	popl	%esi
    211 	popl	%edx
    212 	popl	%ecx
    213 	popl	%ebx
    214 	popl	%ebp
    215 	ret
    216 
    217 /*
    218 # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
    219 #	Call with	%ah = 0x42
    220 #			%ds:%si = parameter block
    221 #			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
    222 #	Return:
    223 #			%al = 0x0 on success; err code on failure
    224 */
    225 ENTRY(biosextread)
    226 	pushl	%ebp
    227 	movl	%esp, %ebp
    228 	pushl	%ebx
    229 	push	%ecx
    230 	push	%edx
    231 	push	%esi
    232 	push	%edi
    233 
    234 	movb	8(%ebp), %dl	# device
    235 	movl	12(%ebp), %esi	# parameter block
    236 
    237 	call	_C_LABEL(prot_to_real)	# enter real mode
    238 
    239 	movb	$0x42, %ah	# subfunction
    240 	int	$0x13
    241 	setc	%bl
    242 
    243 	data32
    244 	call	_C_LABEL(real_to_prot) # back to protected mode
    245 
    246 	xorl	%eax, %eax
    247 	movb	%bl, %al	# return value in %ax
    248 
    249 	pop	%edi
    250 	pop	%esi
    251 	pop	%edx
    252 	pop	%ecx
    253 	popl	%ebx
    254 	popl	%ebp
    255 	ret
    256 
    257 ENTRY(int13_getextinfo)
    258 	pushl	%ebp
    259 	movl	%esp, %ebp
    260 	pushl	%ebx
    261 	push	%ecx
    262 	push	%edx
    263 	push	%esi
    264 	push	%edi
    265 
    266 	movb	8(%ebp), %dl	# device
    267 	movl	12(%ebp), %esi	# parameter block
    268 	movl	$0x01a, (%esi)	# length (v 1.x)
    269 
    270 	call	_C_LABEL(prot_to_real)	# enter real mode
    271 
    272 	movb	$0x48, %ah	# subfunction
    273 	int	$0x13
    274 	setc	%bl
    275 
    276 	data32
    277 	call	_C_LABEL(real_to_prot) # back to protected mode
    278 
    279 	xorl	%eax, %eax
    280 	movb	%bl, %al	# return value in %ax
    281 
    282 	pop	%edi
    283 	pop	%esi
    284 	pop	%edx
    285 	pop	%ecx
    286 	popl	%ebx
    287 	popl	%ebp
    288 	ret
    289