Home | History | Annotate | Line # | Download | only in lib
bios_disk.S revision 1.5
      1  1.5   fvdl /*	$NetBSD: bios_disk.S,v 1.5 1999/03/08 00:09:25 fvdl 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.1  perry  *
     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.1  perry  *
     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.1  perry  *
     20  1.1  perry  * Carnegie Mellon requests users of this software to return to
     21  1.1  perry  *
     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.1  perry  *
     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.1  perry   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 #define	addr32	.byte 0x67
     59  1.1  perry #define	data32	.byte 0x66
     60  1.1  perry 
     61  1.1  perry /*
     62  1.1  perry # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
     63  1.1  perry #	Call with	%ah = 0x2
     64  1.1  perry #			%al = number of sectors
     65  1.1  perry #			%ch = cylinder
     66  1.1  perry #			%cl = sector
     67  1.1  perry #			%dh = head
     68  1.1  perry #			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
     69  1.1  perry #			%es:%bx = segment:offset of buffer
     70  1.1  perry #	Return:
     71  1.1  perry #			%al = 0x0 on success; err code on failure
     72  1.1  perry */
     73  1.1  perry ENTRY(biosread)
     74  1.1  perry 	pushl	%ebp
     75  1.1  perry 	movl	%esp, %ebp
     76  1.1  perry 	pushl	%ebx
     77  1.1  perry 	push	%ecx
     78  1.1  perry 	push	%edx
     79  1.1  perry 	push	%esi
     80  1.1  perry 	push	%edi
     81  1.1  perry 
     82  1.1  perry 	movb	16(%ebp), %dh
     83  1.1  perry 	movw	12(%ebp), %cx
     84  1.1  perry 	xchgb	%ch, %cl	# cylinder; the highest 2 bits of cyl is in %cl
     85  1.1  perry 	rorb	$2, %cl
     86  1.1  perry 	movb	20(%ebp), %al
     87  1.1  perry 	orb	%al, %cl
     88  1.1  perry 	incb	%cl		# sector; sec starts from 1, not 0
     89  1.1  perry 	movb	8(%ebp), %dl	# device
     90  1.1  perry 	movl	28(%ebp), %ebx	# offset
     91  1.1  perry 				# prot_to_real will set %es to BOOTSEG
     92  1.1  perry 
     93  1.1  perry 	call	_C_LABEL(prot_to_real)	# enter real mode
     94  1.1  perry 
     95  1.1  perry 	movb	$0x2, %ah	# subfunction
     96  1.1  perry 	addr32
     97  1.1  perry 	movb	24(%ebp), %al	# number of sectors
     98  1.1  perry 	int	$0x13
     99  1.1  perry 	setc	%bl
    100  1.1  perry 
    101  1.1  perry 	data32
    102  1.1  perry 	call	_C_LABEL(real_to_prot) # back to protected mode
    103  1.1  perry 
    104  1.1  perry 	xorl	%eax, %eax
    105  1.1  perry 	movb	%bl, %al	# return value in %ax
    106  1.1  perry 
    107  1.1  perry 	pop	%edi
    108  1.1  perry 	pop	%esi
    109  1.1  perry 	pop	%edx
    110  1.1  perry 	pop	%ecx
    111  1.1  perry 	popl	%ebx
    112  1.1  perry 	popl	%ebp
    113  1.1  perry 	ret
    114  1.1  perry 
    115  1.1  perry /*
    116  1.1  perry #
    117  1.5   fvdl # get_diskinfo():  takes a pointer to a biosdisk_ll struct, and fills it in.
    118  1.1  perry #
    119  1.1  perry */
    120  1.1  perry 
    121  1.1  perry ENTRY(get_diskinfo)
    122  1.1  perry 	pushl	%ebp
    123  1.1  perry 	movl	%esp, %ebp
    124  1.1  perry 	push	%es
    125  1.1  perry 	pushl	%ebx
    126  1.1  perry 	push	%ecx
    127  1.1  perry 	push	%edx
    128  1.1  perry 	push	%esi
    129  1.1  perry 	push	%edi
    130  1.1  perry 
    131  1.5   fvdl 	movl	8(%ebp), %esi		# diskinfo(drive #)
    132  1.5   fvdl 	movb	(%esi), %dl
    133  1.5   fvdl 	pushl	%esi
    134  1.1  perry 
    135  1.1  perry 	call	_C_LABEL(prot_to_real)	# enter real mode
    136  1.1  perry 
    137  1.1  perry 	movb	$0x08, %ah		# ask for disk info
    138  1.1  perry 	int	$0x13
    139  1.1  perry 	jnc	ok
    140  1.1  perry 
    141  1.1  perry 	/*
    142  1.1  perry 	 * Urk.  Call failed.  It is not supported for floppies by old BIOS's.
    143  1.1  perry 	 * Guess it's a 15-sector floppy.  Initialize all the registers for
    144  1.1  perry 	 * documentation, although we only need head and sector counts.
    145  1.1  perry 	 */
    146  1.1  perry #	subb	%ah, %ah		# %ax = 0
    147  1.1  perry #	movb	%ah, %bh		# %bh = 0
    148  1.1  perry #	movb	$2, %bl			# %bl bits 0-3 = drive type, 2 = 1.2M
    149  1.1  perry #	movb	$79, %ch		# max track
    150  1.1  perry 	movb	$15, %cl		# max sector
    151  1.1  perry 	movb	$1, %dh			# max head
    152  1.1  perry #	movb	$1, %dl			# # floppy drives installed
    153  1.1  perry 	# es:di = parameter table
    154  1.1  perry 	# carry = 0
    155  1.1  perry 
    156  1.1  perry ok:
    157  1.1  perry 	data32
    158  1.1  perry 	call	_C_LABEL(real_to_prot)	# back to protected mode
    159  1.1  perry 
    160  1.5   fvdl 	popl	%esi
    161  1.5   fvdl 
    162  1.5   fvdl 	movzbl	%dh, %eax
    163  1.5   fvdl 	movl	%eax, 8(%esi)		# heads
    164  1.5   fvdl 	movb	%cl, %al
    165  1.5   fvdl 	andb	$0x3f, %al
    166  1.5   fvdl 	movzbl	%al, %ebx
    167  1.5   fvdl 	movl	%ebx, 4(%esi)		# sectors per track
    168  1.1  perry 	xorl	%eax, %eax
    169  1.5   fvdl 	movb	%ch, %al
    170  1.5   fvdl 	andl	$0x0c0, %ecx
    171  1.5   fvdl 	shll	$2, %ecx
    172  1.5   fvdl 	orl	%ecx, %eax
    173  1.5   fvdl 	movl	%eax, 12(%esi)		# cylinders
    174  1.1  perry 
    175  1.1  perry 	pop	%edi
    176  1.1  perry 	pop	%esi
    177  1.1  perry 	pop	%edx
    178  1.1  perry 	pop	%ecx
    179  1.1  perry 	popl	%ebx
    180  1.1  perry 	pop	%es
    181  1.2     ws 	popl	%ebp
    182  1.2     ws 	ret
    183  1.2     ws 
    184  1.2     ws /*
    185  1.2     ws # int13_extension: check for availibility of int13 extensions.
    186  1.2     ws */
    187  1.2     ws 
    188  1.2     ws ENTRY(int13_extension)
    189  1.2     ws 	pushl	%ebp
    190  1.2     ws 	movl	%esp, %ebp
    191  1.2     ws 	pushl	%ebx
    192  1.2     ws 	pushl	%ecx
    193  1.2     ws 	pushl	%edx
    194  1.2     ws 	pushl	%esi
    195  1.2     ws 	pushl	%edi
    196  1.2     ws 
    197  1.2     ws 	movb	8(%ebp), %dl		# drive #
    198  1.2     ws 	movw	$0x55aa, %bx
    199  1.2     ws 
    200  1.2     ws 	call	_C_LABEL(prot_to_real)	# enter real mode
    201  1.2     ws 
    202  1.2     ws 	movb	$0x41, %ah		# ask for disk info
    203  1.2     ws 	int	$0x13
    204  1.3     ws 	setnc	%dl
    205  1.2     ws 
    206  1.2     ws 	data32
    207  1.2     ws 	CALL	_C_LABEL(real_to_prot)	# switch back
    208  1.2     ws 
    209  1.2     ws 	xorl	%eax, %eax
    210  1.2     ws 	movb	%dl, %al	# return value in %ax
    211  1.2     ws 
    212  1.2     ws 	cmpw	$0xaa55, %bx
    213  1.2     ws 	sete	%dl
    214  1.4     ws 	andb	%dl, %al
    215  1.2     ws 
    216  1.4     ws 	andb	%cl, %al
    217  1.2     ws 
    218  1.2     ws 	popl	%edi
    219  1.2     ws 	popl	%esi
    220  1.2     ws 	popl	%edx
    221  1.2     ws 	popl	%ecx
    222  1.2     ws 	popl	%ebx
    223  1.2     ws 	popl	%ebp
    224  1.2     ws 	ret
    225  1.2     ws 
    226  1.2     ws /*
    227  1.2     ws # BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory
    228  1.2     ws #	Call with	%ah = 0x42
    229  1.5   fvdl #			%ds:%si = parameter block
    230  1.2     ws #			%dl = drive (0x80 for hard disk, 0x0 for floppy disk)
    231  1.2     ws #	Return:
    232  1.2     ws #			%al = 0x0 on success; err code on failure
    233  1.2     ws */
    234  1.2     ws ENTRY(biosextread)
    235  1.2     ws 	pushl	%ebp
    236  1.2     ws 	movl	%esp, %ebp
    237  1.2     ws 	pushl	%ebx
    238  1.2     ws 	push	%ecx
    239  1.2     ws 	push	%edx
    240  1.2     ws 	push	%esi
    241  1.2     ws 	push	%edi
    242  1.2     ws 
    243  1.2     ws 	movb	8(%ebp), %dl	# device
    244  1.2     ws 	movl	12(%ebp), %esi	# parameter block
    245  1.2     ws 
    246  1.2     ws 	call	_C_LABEL(prot_to_real)	# enter real mode
    247  1.2     ws 
    248  1.2     ws 	movb	$0x42, %ah	# subfunction
    249  1.5   fvdl 	int	$0x13
    250  1.5   fvdl 	setc	%bl
    251  1.5   fvdl 
    252  1.5   fvdl 	data32
    253  1.5   fvdl 	call	_C_LABEL(real_to_prot) # back to protected mode
    254  1.5   fvdl 
    255  1.5   fvdl 	xorl	%eax, %eax
    256  1.5   fvdl 	movb	%bl, %al	# return value in %ax
    257  1.5   fvdl 
    258  1.5   fvdl 	pop	%edi
    259  1.5   fvdl 	pop	%esi
    260  1.5   fvdl 	pop	%edx
    261  1.5   fvdl 	pop	%ecx
    262  1.5   fvdl 	popl	%ebx
    263  1.5   fvdl 	popl	%ebp
    264  1.5   fvdl 	ret
    265  1.5   fvdl 
    266  1.5   fvdl ENTRY(int13_getextinfo)
    267  1.5   fvdl 	pushl	%ebp
    268  1.5   fvdl 	movl	%esp, %ebp
    269  1.5   fvdl 	pushl	%ebx
    270  1.5   fvdl 	push	%ecx
    271  1.5   fvdl 	push	%edx
    272  1.5   fvdl 	push	%esi
    273  1.5   fvdl 	push	%edi
    274  1.5   fvdl 
    275  1.5   fvdl 	movb	8(%ebp), %dl	# device
    276  1.5   fvdl 	movl	12(%ebp), %esi	# parameter block
    277  1.5   fvdl 	movl	$0x01a, (%esi)	# length (v 1.x)
    278  1.5   fvdl 
    279  1.5   fvdl 	call	_C_LABEL(prot_to_real)	# enter real mode
    280  1.5   fvdl 
    281  1.5   fvdl 	movb	$0x48, %ah	# subfunction
    282  1.2     ws 	int	$0x13
    283  1.2     ws 	setc	%bl
    284  1.2     ws 
    285  1.2     ws 	data32
    286  1.2     ws 	call	_C_LABEL(real_to_prot) # back to protected mode
    287  1.2     ws 
    288  1.2     ws 	xorl	%eax, %eax
    289  1.2     ws 	movb	%bl, %al	# return value in %ax
    290  1.2     ws 
    291  1.2     ws 	pop	%edi
    292  1.2     ws 	pop	%esi
    293  1.2     ws 	pop	%edx
    294  1.2     ws 	pop	%ecx
    295  1.2     ws 	popl	%ebx
    296  1.1  perry 	popl	%ebp
    297  1.1  perry 	ret
    298