Home | History | Annotate | Line # | Download | only in lib
bios_disk.S revision 1.21.26.1
      1  1.21.26.1       tls /*	$NetBSD: bios_disk.S,v 1.21.26.1 2014/08/10 06:53:59 tls Exp $	*/
      2        1.1     perry 
      3        1.1     perry /*
      4        1.1     perry  * Ported to boot 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
      5        1.1     perry  *
      6        1.1     perry  * Mach Operating System
      7        1.1     perry  * Copyright (c) 1992, 1991 Carnegie Mellon University
      8        1.1     perry  * All Rights Reserved.
      9       1.14  junyoung  *
     10        1.1     perry  * Permission to use, copy, modify and distribute this software and its
     11        1.1     perry  * documentation is hereby granted, provided that both the copyright
     12        1.1     perry  * notice and this permission notice appear in all copies of the
     13        1.1     perry  * software, derivative works or modified versions, and any portions
     14        1.1     perry  * thereof, and that both notices appear in supporting documentation.
     15       1.14  junyoung  *
     16        1.1     perry  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     17        1.1     perry  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     18        1.1     perry  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     19       1.14  junyoung  *
     20        1.1     perry  * Carnegie Mellon requests users of this software to return to
     21       1.14  junyoung  *
     22        1.1     perry  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     23        1.1     perry  *  School of Computer Science
     24        1.1     perry  *  Carnegie Mellon University
     25        1.1     perry  *  Pittsburgh PA 15213-3890
     26       1.14  junyoung  *
     27        1.1     perry  * any improvements or extensions that they make and grant Carnegie Mellon
     28        1.1     perry  * the rights to redistribute these changes.
     29        1.1     perry  */
     30        1.1     perry 
     31        1.1     perry /*
     32       1.14  junyoung   Copyright 1988, 1989, 1990, 1991, 1992
     33        1.1     perry    by Intel Corporation, Santa Clara, California.
     34        1.1     perry 
     35        1.1     perry                 All Rights Reserved
     36        1.1     perry 
     37        1.1     perry Permission to use, copy, modify, and distribute this software and
     38        1.1     perry its documentation for any purpose and without fee is hereby
     39        1.1     perry granted, provided that the above copyright notice appears in all
     40        1.1     perry copies and that both the copyright notice and this permission notice
     41        1.1     perry appear in supporting documentation, and that the name of Intel
     42        1.1     perry not be used in advertising or publicity pertaining to distribution
     43        1.1     perry of the software without specific, written prior permission.
     44        1.1     perry 
     45        1.1     perry INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
     46        1.1     perry INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
     47        1.1     perry IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
     48        1.1     perry CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
     49        1.1     perry LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
     50        1.1     perry NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     51        1.1     perry WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     52        1.1     perry */
     53        1.1     perry 
     54        1.1     perry /* extracted from netbsd:sys/arch/i386/boot/bios.S */
     55        1.1     perry 
     56        1.1     perry #include <machine/asm.h>
     57        1.1     perry 
     58        1.1     perry /*
     59       1.15  junyoung  * BIOS call "INT 0x13 Function 0x0" to reset the disk subsystem
     60       1.15  junyoung  *	Call with	%ah = 0x0
     61       1.15  junyoung  *			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
     62       1.15  junyoung  *	Return:
     63       1.15  junyoung  *			%al = 0x0 on success; err code on failure
     64       1.15  junyoung  */
     65       1.17  junyoung ENTRY(biosdisk_reset)
     66       1.21     joerg 	pusha
     67        1.9    dyoung 
     68       1.21     joerg 	movb	%al, %dl	# device
     69        1.9    dyoung 
     70        1.9    dyoung 	call	_C_LABEL(prot_to_real)	# enter real mode
     71       1.10       dsl 	.code16
     72        1.9    dyoung 
     73        1.9    dyoung 	movb	$0x0, %ah	# subfunction
     74        1.9    dyoung 	int	$0x13
     75        1.9    dyoung 	setc	%bl
     76        1.9    dyoung 	movb	%ah, %bh	# save error code
     77        1.9    dyoung 
     78       1.10       dsl 	calll	_C_LABEL(real_to_prot) # back to protected mode
     79       1.10       dsl 	.code32
     80        1.9    dyoung 
     81       1.20  jakllsch 	movzwl	%bx, %eax	# return value in %eax
     82       1.21     joerg 	movl	%eax, 28(%esp)
     83        1.9    dyoung 
     84       1.21     joerg 	popa
     85        1.9    dyoung 	ret
     86        1.9    dyoung 
     87        1.9    dyoung /*
     88       1.15  junyoung  * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
     89       1.15  junyoung  *	Call with	%ah = 0x2
     90       1.15  junyoung  *			%al = number of sectors
     91       1.15  junyoung  *			%ch = cylinder
     92       1.15  junyoung  *			%cl = sector
     93       1.15  junyoung  *			%dh = head
     94       1.15  junyoung  *			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
     95       1.15  junyoung  *			%es:%bx = segment:offset of buffer
     96       1.15  junyoung  *	Return:
     97       1.15  junyoung  *			%al = 0x0 on success; err code on failure
     98       1.15  junyoung  *
     99       1.17  junyoung  * biosdisk_read(dev, cyl, head, sect, count, buff_addr);
    100       1.15  junyoung  *
    101       1.17  junyoung  *  Note: On failure, you must reset the disk with biosdisk_reset() before
    102       1.15  junyoung  *        sending another command.
    103       1.15  junyoung  */
    104       1.17  junyoung ENTRY(biosdisk_read)
    105       1.21     joerg 	pusha
    106        1.1     perry 
    107       1.21     joerg 	movb	44(%esp), %dh
    108       1.21     joerg 	movw	40(%esp), %cx
    109        1.1     perry 	xchgb	%ch, %cl	# cylinder; the highest 2 bits of cyl is in %cl
    110        1.1     perry 	rorb	$2, %cl
    111       1.21     joerg 	movb	48(%esp), %al
    112        1.1     perry 	orb	%al, %cl
    113        1.1     perry 	incb	%cl		# sector; sec starts from 1, not 0
    114       1.21     joerg 	movb	36(%esp), %dl	# device
    115       1.21     joerg 	movl	56(%esp), %ebx	# buffer address (may be >64k)
    116       1.21     joerg 	movb	52(%esp), %al	# number of sectors
    117        1.1     perry 
    118        1.1     perry 	call	_C_LABEL(prot_to_real)	# enter real mode
    119       1.10       dsl 	.code16
    120       1.10       dsl 
    121       1.12       dsl 	push	%bx
    122       1.12       dsl 	shrl	$4, %ebx	# max segment
    123       1.10       dsl 	mov	%ds, %si
    124       1.12       dsl 	add	%si, %bx
    125       1.12       dsl 	mov	%bx, %es	# %es:%bx now valid buffer address
    126       1.12       dsl 	pop	%bx
    127       1.12       dsl 	and	$0xf, %bx	# and min offset - to avoid overrun
    128        1.1     perry 
    129        1.1     perry 	movb	$0x2, %ah	# subfunction
    130        1.1     perry 	int	$0x13
    131       1.12       dsl 	setc	%al		# error code is in %ah
    132       1.14  junyoung 
    133       1.10       dsl 	calll	_C_LABEL(real_to_prot) # back to protected mode
    134       1.10       dsl 	.code32
    135        1.1     perry 
    136  1.21.26.1       tls 	andl    $0x0000FFFF, %eax  # Some bioses set high bits in %eax
    137  1.21.26.1       tls 	                           #  on success, interfering with our
    138  1.21.26.1       tls 	                           #  return value.  Clear those out.
    139       1.21     joerg 	movl	%eax, 28(%esp)
    140        1.1     perry 
    141       1.21     joerg 	popa
    142        1.1     perry 	ret
    143        1.1     perry 
    144        1.1     perry /*
    145       1.17  junyoung  * biosdisk_getinfo(int dev):  return a word that represents the
    146       1.15  junyoung  *	max number of sectors, heads and cylinders for this device
    147       1.15  junyoung  */
    148       1.17  junyoung ENTRY(biosdisk_getinfo)
    149        1.1     perry 	push	%es
    150       1.21     joerg 	pusha
    151        1.1     perry 
    152       1.21     joerg 	movb	%al, %dl		# diskinfo(drive #)
    153        1.1     perry 
    154        1.1     perry 	call	_C_LABEL(prot_to_real)	# enter real mode
    155       1.10       dsl 	.code16
    156        1.1     perry 
    157       1.16  junyoung 	push	%dx			# save drive #
    158        1.1     perry 	movb	$0x08, %ah		# ask for disk info
    159        1.1     perry 	int	$0x13
    160       1.16  junyoung 	pop	%bx			# restore drive #
    161        1.1     perry 	jnc	ok
    162        1.1     perry 
    163       1.16  junyoung 	testb	$0x80, %bl		# is it a hard disk?
    164       1.16  junyoung 	jnz	ok
    165       1.16  junyoung 
    166        1.1     perry 	/*
    167        1.1     perry 	 * Urk.  Call failed.  It is not supported for floppies by old BIOS's.
    168        1.1     perry 	 * Guess it's a 15-sector floppy.  Initialize all the registers for
    169        1.1     perry 	 * documentation, although we only need head and sector counts.
    170        1.1     perry 	 */
    171       1.16  junyoung 	xorw	%ax, %ax		# set status to success
    172        1.1     perry #	movb	%ah, %bh		# %bh = 0
    173        1.1     perry #	movb	$2, %bl			# %bl bits 0-3 = drive type, 2 = 1.2M
    174        1.6  drochner 	movb	$79, %ch		# max track
    175        1.1     perry 	movb	$15, %cl		# max sector
    176        1.1     perry 	movb	$1, %dh			# max head
    177        1.1     perry #	movb	$1, %dl			# # floppy drives installed
    178        1.1     perry 	# es:di = parameter table
    179        1.1     perry 	# carry = 0
    180        1.1     perry 
    181        1.1     perry ok:
    182       1.10       dsl 	calll	_C_LABEL(real_to_prot)	# back to protected mode
    183       1.10       dsl 	.code32
    184        1.7      fvdl 
    185        1.6  drochner 	/* form a longword representing all this gunk */
    186       1.16  junyoung 	shrl	$8, %eax		# clear unnecessary bits
    187       1.16  junyoung 	shll	$24, %eax
    188       1.16  junyoung 	shll	$16, %ecx		# do the same for %ecx
    189       1.16  junyoung 	shrl	$8, %ecx
    190       1.16  junyoung 	movb	%dh, %cl		# max head
    191       1.16  junyoung 	orl	%ecx, %eax		# return value in %eax
    192       1.21     joerg 	movl	%eax, 28(%esp)
    193        1.1     perry 
    194       1.21     joerg 	popa
    195        1.1     perry 	pop	%es
    196        1.2        ws 	ret
    197        1.2        ws 
    198        1.2        ws /*
    199       1.17  junyoung  * int biosdisk_int13ext(int dev):
    200       1.17  junyoung  *	check for availibility of int13 extensions.
    201       1.15  junyoung  */
    202       1.17  junyoung ENTRY(biosdisk_int13ext)
    203       1.21     joerg 	pusha
    204        1.2        ws 
    205       1.21     joerg 	movb	%al, %dl		# drive #
    206        1.2        ws 	movw	$0x55aa, %bx
    207        1.2        ws 
    208        1.2        ws 	call	_C_LABEL(prot_to_real)	# enter real mode
    209       1.10       dsl 	.code16
    210        1.2        ws 
    211        1.2        ws 	movb	$0x41, %ah		# ask for disk info
    212        1.2        ws 	int	$0x13
    213        1.3        ws 	setnc	%dl
    214        1.2        ws 
    215       1.10       dsl 	calll	_C_LABEL(real_to_prot)	# switch back
    216       1.10       dsl 	.code32
    217        1.2        ws 
    218       1.20  jakllsch 	movzbl	%dl, %eax		# return value in %eax
    219        1.2        ws 
    220        1.2        ws 	cmpw	$0xaa55, %bx
    221        1.2        ws 	sete	%dl
    222        1.4        ws 	andb	%dl, %al
    223        1.2        ws 
    224        1.4        ws 	andb	%cl, %al
    225       1.21     joerg 	movl	%eax, 28(%esp)
    226        1.2        ws 
    227       1.21     joerg 	popa
    228        1.2        ws 	ret
    229        1.2        ws 
    230        1.2        ws /*
    231       1.15  junyoung  * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
    232       1.15  junyoung  *	Call with	%ah = 0x42
    233       1.15  junyoung  *			%ds:%si = parameter block (data buffer address
    234       1.15  junyoung  *				must be a real mode physical address).
    235       1.15  junyoung  *			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
    236       1.15  junyoung  *	Return:
    237       1.15  junyoung  *			%al = 0x0 on success; err code on failure
    238       1.15  junyoung  */
    239       1.17  junyoung ENTRY(biosdisk_extread)
    240       1.21     joerg 	pusha
    241        1.2        ws 
    242       1.21     joerg 	movl	%edx, %esi	# parameter block
    243       1.21     joerg 	movb	%al, %dl	# device
    244        1.2        ws 
    245        1.2        ws 	call	_C_LABEL(prot_to_real)	# enter real mode
    246       1.10       dsl 	.code16
    247       1.10       dsl 
    248       1.19       dsl 	push	%ds
    249       1.10       dsl 	movl	%esi, %eax
    250       1.10       dsl 	shrl	$4, %eax
    251       1.10       dsl 	movw	%ds, %bx
    252       1.10       dsl 	addw	%bx, %ax
    253       1.10       dsl 	movw	%ax, %ds
    254       1.10       dsl 	andw	$0xf, %si
    255        1.2        ws 
    256        1.2        ws 	movb	$0x42, %ah	# subfunction
    257        1.5      fvdl 	int	$0x13
    258        1.5      fvdl 	setc	%bl
    259        1.8     perry 	movb	%ah, %bh	# save error code
    260       1.19       dsl 	pop	%ds
    261        1.5      fvdl 
    262       1.10       dsl 	calll	_C_LABEL(real_to_prot) # back to protected mode
    263       1.10       dsl 	.code32
    264        1.5      fvdl 
    265       1.20  jakllsch 	movzwl	%bx, %eax	# return value in %eax
    266       1.21     joerg 	movl	%eax, 28(%esp)
    267        1.5      fvdl 
    268       1.21     joerg 	popa
    269        1.5      fvdl 	ret
    270        1.5      fvdl 
    271       1.17  junyoung ENTRY(biosdisk_getextinfo)
    272       1.21     joerg 	pusha
    273        1.5      fvdl 
    274       1.21     joerg 	movl	%edx, %esi	# parameter block
    275       1.21     joerg 	movb	%al, %dl	# device
    276        1.5      fvdl 
    277        1.5      fvdl 	call	_C_LABEL(prot_to_real)	# enter real mode
    278       1.10       dsl 	.code16
    279       1.10       dsl 
    280       1.19       dsl 	push	%ds
    281       1.10       dsl 	movl	%esi, %eax
    282       1.10       dsl 	shrl	$4, %eax
    283       1.10       dsl 	andw	$0xf, %si
    284       1.10       dsl 	movw	%ds, %bx
    285       1.10       dsl 	addw	%bx, %ax
    286       1.10       dsl 	movw	%ax, %ds
    287        1.5      fvdl 
    288        1.5      fvdl 	movb	$0x48, %ah	# subfunction
    289        1.2        ws 	int	$0x13
    290        1.2        ws 	setc	%bl
    291       1.19       dsl 	pop	%ds
    292        1.2        ws 
    293       1.10       dsl 	calll	_C_LABEL(real_to_prot) # back to protected mode
    294       1.10       dsl 	.code32
    295        1.2        ws 
    296       1.20  jakllsch 	movzbl	%bl, %eax	# return value in %eax
    297       1.21     joerg 	movl	%eax, 28(%esp)
    298        1.2        ws 
    299       1.21     joerg 	popa
    300        1.1     perry 	ret
    301