Home | History | Annotate | Line # | Download | only in lib
biosmemx.S revision 1.10.20.1
      1  1.10.20.1    martin /*	$NetBSD: biosmemx.S,v 1.10.20.1 2024/09/03 15:29:05 martin Exp $	*/
      2        1.1  drochner 
      3        1.1  drochner /*
      4        1.2  drochner  * Copyright (c) 1997, 1999
      5        1.1  drochner  *	Matthias Drochner.  All rights reserved.
      6        1.1  drochner  *
      7        1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8        1.1  drochner  * modification, are permitted provided that the following conditions
      9        1.1  drochner  * are met:
     10        1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11        1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     12        1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15        1.1  drochner  *
     16        1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17        1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18        1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19        1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20        1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21        1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22        1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23        1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24        1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25        1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26        1.1  drochner  *
     27        1.1  drochner  */
     28        1.1  drochner 
     29        1.1  drochner #include <machine/asm.h>
     30        1.1  drochner 
     31        1.1  drochner 	.text
     32        1.1  drochner 
     33       1.10      maxv /*
     34       1.10      maxv  * int getextmem2(int buffer[2])
     35       1.10      maxv  *
     36       1.10      maxv  * return: 0=OK, -1=error
     37       1.10      maxv  * buffer[0]: extmem kBytes below 16M (max 15M/1024)
     38       1.10      maxv  * buffer[1]: extmem above 16M, in 64k units
     39       1.10      maxv  */
     40        1.1  drochner ENTRY(getextmem2)
     41        1.1  drochner 	pushl	%ebp
     42        1.1  drochner 	movl	%esp,%ebp
     43        1.1  drochner 	pushl	%ebx
     44        1.1  drochner 	pushl	%ecx
     45        1.1  drochner 	pushl	%edx
     46        1.1  drochner 	push	%esi
     47        1.1  drochner 	push	%edi
     48        1.1  drochner 
     49        1.1  drochner 	call	_C_LABEL(prot_to_real)
     50        1.3       dsl 	.code16
     51        1.1  drochner 
     52       1.10      maxv 	xorl	%ebx,%ebx
     53       1.10      maxv 	movl	$0xe801,%eax
     54        1.1  drochner 	int	$0x15
     55        1.6       dsl 	pushf
     56        1.1  drochner 
     57       1.10      maxv 	movw	%si,%ax
     58       1.10      maxv 	orw	%si,%bx
     59        1.6       dsl 	jz	1f		/* if zero use configured values */
     60       1.10      maxv 	movw	%cx,%ax		/* k below 16M (max 0x3c00 = 15MB) */
     61       1.10      maxv 	movw	%dx,%bx		/* 64k above 16M */
     62        1.6       dsl 1:
     63        1.6       dsl 	popf
     64        1.6       dsl 	setc	%bl
     65        1.1  drochner 
     66        1.3       dsl 	calll	_C_LABEL(real_to_prot)
     67        1.3       dsl 	.code32
     68        1.1  drochner 
     69       1.10      maxv 	movl	8(%ebp),%edi
     70       1.10      maxv 	xorl	%eax,%eax
     71       1.10      maxv 	movw	%cx,%ax
     72        1.6       dsl 	stosl
     73       1.10      maxv 	movw	%dx,%ax
     74        1.6       dsl 	stosl
     75       1.10      maxv 	movb	%bl,%al
     76        1.6       dsl 	cbw
     77        1.1  drochner 
     78        1.1  drochner 	pop	%edi
     79        1.1  drochner 	pop	%esi
     80        1.1  drochner 	popl	%edx
     81        1.1  drochner 	popl	%ecx
     82        1.1  drochner 	popl	%ebx
     83        1.1  drochner 	popl	%ebp
     84        1.1  drochner 	ret
     85        1.1  drochner 
     86       1.10      maxv /*
     87  1.10.20.1    martin  * int getmementry(int *iterator, int buffer[6])
     88       1.10      maxv  *
     89       1.10      maxv  * return: 0=ok, else error
     90       1.10      maxv  * buffer[0]: start of memory chunk
     91       1.10      maxv  * buffer[2]: length (bytes)
     92       1.10      maxv  * buffer[4]: type
     93  1.10.20.1    martin  * buffer[5]: ACPI 3.0 Extended Attributes bitfield (unused)
     94  1.10.20.1    martin  *
     95  1.10.20.1    martin  * Some buggy BIOSes may write to 24 bytes even if only 20 were requested.
     96  1.10.20.1    martin  * Therefore, the buffer is defined for 6 elements to avoid stack buffer
     97  1.10.20.1    martin  * overruns.  See PR install/49470.
     98  1.10.20.1    martin  *
     99  1.10.20.1    martin  * More details can be found in the:
    100  1.10.20.1    martin  *
    101  1.10.20.1    martin  *	Advanced Configuration and Power Interface (ACPI)
    102  1.10.20.1    martin  *	Specification, Release 6.5, 2022-08-29, UEFI Forum, Inc.,
    103  1.10.20.1    martin  *	Sec. 15.1 `INT 15H E820H - Query System Address Map',
    104  1.10.20.1    martin  *	pp. 756-757
    105  1.10.20.1    martin  *	https://uefi.org/sites/default/files/resources/ACPI_Spec_6_5_Aug29.pdf#page=824
    106  1.10.20.1    martin  *	https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.html#int-15h-e820h-query-system-address-map
    107  1.10.20.1    martin  *
    108  1.10.20.1    martin  * as well as this OSDev.org wiki page:
    109  1.10.20.1    martin  *
    110  1.10.20.1    martin  *	https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15,_EAX_=_0xE820
    111       1.10      maxv  */
    112        1.1  drochner ENTRY(getmementry)
    113        1.1  drochner 	pushl	%ebp
    114        1.1  drochner 	movl	%esp,%ebp
    115        1.1  drochner 	pushl	%ebx
    116        1.1  drochner 	pushl	%ecx
    117        1.1  drochner 	pushl	%edx
    118        1.1  drochner 	push	%esi
    119        1.1  drochner 	push	%edi
    120        1.1  drochner 
    121       1.10      maxv 	movl	8(%ebp),%eax
    122       1.10      maxv 	movl	0(%eax),%ebx		/* index */
    123       1.10      maxv 	movl	$20,%ecx		/* Buffer size */
    124       1.10      maxv 	movl	$0x534d4150,%edx	/* "SMAP" */
    125       1.10      maxv 	movl	12(%ebp),%edi		/* buffer address */
    126        1.1  drochner 
    127        1.1  drochner 	call	_C_LABEL(prot_to_real)
    128        1.3       dsl 	.code16
    129        1.4       dsl 
    130        1.4       dsl 	push	%di
    131       1.10      maxv 	shrl	$4,%edi
    132       1.10      maxv 	mov	%ds,%ax
    133       1.10      maxv 	add	%di,%ax
    134       1.10      maxv 	mov	%ax,%es
    135        1.4       dsl 	pop	%di
    136       1.10      maxv 	and	$0xf,%di		/* buffer addres now in ES:DI */
    137        1.1  drochner 
    138       1.10      maxv 	movl	$0xe820,%eax		/* Some BIOS check EAX value */
    139        1.1  drochner 	int	$0x15
    140        1.1  drochner 
    141        1.2  drochner 	setc	%cl
    142        1.1  drochner 
    143        1.3       dsl 	calll	_C_LABEL(real_to_prot)
    144        1.3       dsl 	.code32
    145        1.1  drochner 
    146       1.10      maxv 	movl	8(%ebp),%eax
    147       1.10      maxv 	movl	%ebx,0(%eax)		/* updated index */
    148       1.10      maxv 	xorl	%eax,%eax
    149       1.10      maxv 	movb	%cl,%al
    150        1.1  drochner 
    151        1.1  drochner 	pop	%edi
    152        1.1  drochner 	pop	%esi
    153        1.1  drochner 	popl	%edx
    154        1.1  drochner 	popl	%ecx
    155        1.1  drochner 	popl	%ebx
    156        1.1  drochner 	popl	%ebp
    157        1.1  drochner 	ret
    158        1.9        ad 
    159       1.10      maxv /*
    160       1.10      maxv  * int biosA20(void)
    161       1.10      maxv  *
    162       1.10      maxv  * return: 0=ok, else error
    163       1.10      maxv  */
    164        1.9        ad ENTRY(biosA20)
    165        1.9        ad 	pushl	%ebp
    166        1.9        ad 	movl	%esp,%ebp
    167        1.9        ad 	pushl	%ebx
    168        1.9        ad 	pushl	%ecx
    169        1.9        ad 	pushl	%edx
    170        1.9        ad 	push	%esi
    171        1.9        ad 	push	%edi
    172        1.9        ad 
    173        1.9        ad 	call	_C_LABEL(prot_to_real)
    174        1.9        ad 	.code16
    175        1.9        ad 
    176       1.10      maxv 	movl	$0x2401,%eax
    177        1.9        ad 	int	$0x15
    178        1.9        ad 	setc	%cl
    179        1.9        ad 
    180        1.9        ad 	calll	_C_LABEL(real_to_prot)
    181        1.9        ad 	.code32
    182        1.9        ad 
    183       1.10      maxv 	movzbl	%cl,%eax
    184        1.9        ad 
    185        1.9        ad 	pop	%edi
    186        1.9        ad 	pop	%esi
    187        1.9        ad 	popl	%edx
    188        1.9        ad 	popl	%ecx
    189        1.9        ad 	popl	%ebx
    190        1.9        ad 	popl	%ebp
    191        1.9        ad 	ret
    192