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