Home | History | Annotate | Line # | Download | only in lib
biosmemx.S revision 1.9
      1 /*	$NetBSD: biosmemx.S,v 1.9 2008/10/14 14:18:11 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997, 1999
      5  *	Matthias Drochner.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  */
     28 
     29 #include <machine/asm.h>
     30 
     31 	.text
     32 
     33 /* int getextmem2(int buffer[2])
     34    return: 0=OK, -1=error
     35    buffer[0]: extmem kBytes below 16M (max 15M/1024)
     36    buffer[1]: extmem above 16M, in 64k units
     37 */
     38 ENTRY(getextmem2)
     39 	pushl	%ebp
     40 	movl	%esp,%ebp
     41 	pushl	%ebx
     42 	pushl	%ecx
     43 	pushl	%edx
     44 	push	%esi
     45 	push	%edi
     46 
     47 	call	_C_LABEL(prot_to_real)
     48 	.code16
     49 
     50 	xorl	%ebx, %ebx
     51 	movl	$0xe801, %eax
     52 	int	$0x15
     53 	pushf
     54 
     55 	movw	%si, %ax
     56 	orw	%si, %bx
     57 	jz	1f		/* if zero use configured values */
     58 	movw	%cx, %ax	/* k below 16M (max 0x3c00 = 15MB) */
     59 	movw	%dx, %bx	/* 64k above 16M */
     60 1:
     61 	popf
     62 	setc	%bl
     63 
     64 	calll	_C_LABEL(real_to_prot)
     65 	.code32
     66 
     67 	movl	8(%ebp), %edi
     68 	xorl	%eax, %eax
     69 	movw	%cx, %ax
     70 	stosl
     71 	movw	%dx, %ax
     72 	stosl
     73 	movb	%bl, %al
     74 	cbw
     75 
     76 	pop	%edi
     77 	pop	%esi
     78 	popl	%edx
     79 	popl	%ecx
     80 	popl	%ebx
     81 	popl	%ebp
     82 	ret
     83 
     84 /* int getmementry(int *iterator, buffer[5])
     85    return: 0=ok, else error
     86    buffer[0]: start of memory chunk
     87    buffer[2]: length (bytes)
     88    buffer[4]: type
     89 */
     90 ENTRY(getmementry)
     91 	pushl	%ebp
     92 	movl	%esp,%ebp
     93 	pushl	%ebx
     94 	pushl	%ecx
     95 	pushl	%edx
     96 	push	%esi
     97 	push	%edi
     98 
     99 	movl	8(%ebp), %eax
    100 	movl	0(%eax), %ebx		/* index */
    101 	movl	$20, %ecx		/* Buffer size */
    102 	movl	$0x534d4150, %edx	/* "SMAP" */
    103 	movl	12(%ebp), %edi		/* buffer address */
    104 
    105 	call	_C_LABEL(prot_to_real)
    106 	.code16
    107 
    108 	push	%di
    109 	shrl	$4, %edi
    110 	mov	%ds, %ax
    111 	add	%di, %ax
    112 	mov	%ax, %es
    113 	pop	%di
    114 	and	$0xf, %di		/* buffer addres now in ES:DI */
    115 
    116 	movl	$0xe820, %eax		/* Some BIOS check EAX value */
    117 	int	$0x15
    118 
    119 	setc	%cl
    120 
    121 	calll	_C_LABEL(real_to_prot)
    122 	.code32
    123 
    124 	movl	8(%ebp), %eax
    125 	movl	%ebx, 0(%eax)		/* updated index */
    126 	xorl	%eax, %eax
    127 	movb	%cl, %al
    128 
    129 	pop	%edi
    130 	pop	%esi
    131 	popl	%edx
    132 	popl	%ecx
    133 	popl	%ebx
    134 	popl	%ebp
    135 	ret
    136 
    137 /* int biosA20(void)
    138    return: 0=ok, else error
    139 */
    140 ENTRY(biosA20)
    141 	pushl	%ebp
    142 	movl	%esp,%ebp
    143 	pushl	%ebx
    144 	pushl	%ecx
    145 	pushl	%edx
    146 	push	%esi
    147 	push	%edi
    148 
    149 	call	_C_LABEL(prot_to_real)
    150 	.code16
    151 
    152 	movl	$0x2401, %eax
    153 	int	$0x15
    154 	setc	%cl
    155 
    156 	calll	_C_LABEL(real_to_prot)
    157 	.code32
    158 
    159 	movzbl	%cl, %eax
    160 
    161 	pop	%edi
    162 	pop	%esi
    163 	popl	%edx
    164 	popl	%ecx
    165 	popl	%ebx
    166 	popl	%ebp
    167 	ret
    168