Home | History | Annotate | Line # | Download | only in lib
biosmemx.S revision 1.12
      1  1.12    andvar /*	$NetBSD: biosmemx.S,v 1.12 2024/08/17 08:38:31 andvar 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.12    andvar  * 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.12    andvar  * buffer[5]: ACPI 3.0 Extended Attributes bitfield (unused)
     94  1.12    andvar  * Some buggy BIOSes may write to 24 bytes even if only 20 were requested.
     95  1.12    andvar  * Therefore, the buffer is defined for 6 elements to avoid stack buffer
     96  1.12    andvar  * overruns.  See PR install/49470.
     97  1.12    andvar  *
     98  1.12    andvar  * More details can be found in the
     99  1.12    andvar  * Advanced Configuration and Power Interface (ACPI) Specification, Release 6.5,
    100  1.12    andvar  * 2022-08-29, UEFI Forum, Inc.,
    101  1.12    andvar  * Sec. 15.1 `INT 15H E820H - Query System Address Map', pp. 756-757
    102  1.12    andvar  * https://uefi.org/sites/default/files/resources/ACPI_Spec_6_5_Aug29.pdf#page=824
    103  1.12    andvar  * https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.html#int-15h-e820h-query-system-address-map
    104  1.12    andvar  * as well as OSDev.org wiki page
    105  1.12    andvar  * https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15,_EAX_=_0xE820.
    106  1.10      maxv  */
    107   1.1  drochner ENTRY(getmementry)
    108   1.1  drochner 	pushl	%ebp
    109   1.1  drochner 	movl	%esp,%ebp
    110   1.1  drochner 	pushl	%ebx
    111   1.1  drochner 	pushl	%ecx
    112   1.1  drochner 	pushl	%edx
    113   1.1  drochner 	push	%esi
    114   1.1  drochner 	push	%edi
    115   1.1  drochner 
    116  1.10      maxv 	movl	8(%ebp),%eax
    117  1.10      maxv 	movl	0(%eax),%ebx		/* index */
    118  1.10      maxv 	movl	$20,%ecx		/* Buffer size */
    119  1.10      maxv 	movl	$0x534d4150,%edx	/* "SMAP" */
    120  1.10      maxv 	movl	12(%ebp),%edi		/* buffer address */
    121   1.1  drochner 
    122   1.1  drochner 	call	_C_LABEL(prot_to_real)
    123   1.3       dsl 	.code16
    124   1.4       dsl 
    125   1.4       dsl 	push	%di
    126  1.10      maxv 	shrl	$4,%edi
    127  1.10      maxv 	mov	%ds,%ax
    128  1.10      maxv 	add	%di,%ax
    129  1.10      maxv 	mov	%ax,%es
    130   1.4       dsl 	pop	%di
    131  1.11    andvar 	and	$0xf,%di		/* buffer address now in ES:DI */
    132   1.1  drochner 
    133  1.10      maxv 	movl	$0xe820,%eax		/* Some BIOS check EAX value */
    134   1.1  drochner 	int	$0x15
    135   1.1  drochner 
    136   1.2  drochner 	setc	%cl
    137   1.1  drochner 
    138   1.3       dsl 	calll	_C_LABEL(real_to_prot)
    139   1.3       dsl 	.code32
    140   1.1  drochner 
    141  1.10      maxv 	movl	8(%ebp),%eax
    142  1.10      maxv 	movl	%ebx,0(%eax)		/* updated index */
    143  1.10      maxv 	xorl	%eax,%eax
    144  1.10      maxv 	movb	%cl,%al
    145   1.1  drochner 
    146   1.1  drochner 	pop	%edi
    147   1.1  drochner 	pop	%esi
    148   1.1  drochner 	popl	%edx
    149   1.1  drochner 	popl	%ecx
    150   1.1  drochner 	popl	%ebx
    151   1.1  drochner 	popl	%ebp
    152   1.1  drochner 	ret
    153   1.9        ad 
    154  1.10      maxv /*
    155  1.10      maxv  * int biosA20(void)
    156  1.10      maxv  *
    157  1.10      maxv  * return: 0=ok, else error
    158  1.10      maxv  */
    159   1.9        ad ENTRY(biosA20)
    160   1.9        ad 	pushl	%ebp
    161   1.9        ad 	movl	%esp,%ebp
    162   1.9        ad 	pushl	%ebx
    163   1.9        ad 	pushl	%ecx
    164   1.9        ad 	pushl	%edx
    165   1.9        ad 	push	%esi
    166   1.9        ad 	push	%edi
    167   1.9        ad 
    168   1.9        ad 	call	_C_LABEL(prot_to_real)
    169   1.9        ad 	.code16
    170   1.9        ad 
    171  1.10      maxv 	movl	$0x2401,%eax
    172   1.9        ad 	int	$0x15
    173   1.9        ad 	setc	%cl
    174   1.9        ad 
    175   1.9        ad 	calll	_C_LABEL(real_to_prot)
    176   1.9        ad 	.code32
    177   1.9        ad 
    178  1.10      maxv 	movzbl	%cl,%eax
    179   1.9        ad 
    180   1.9        ad 	pop	%edi
    181   1.9        ad 	pop	%esi
    182   1.9        ad 	popl	%edx
    183   1.9        ad 	popl	%ecx
    184   1.9        ad 	popl	%ebx
    185   1.9        ad 	popl	%ebp
    186   1.9        ad 	ret
    187