biosmemx.S revision 1.10 1 /* $NetBSD: biosmemx.S,v 1.10 2016/12/04 08:21:08 maxv 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 /*
34 * int getextmem2(int buffer[2])
35 *
36 * return: 0=OK, -1=error
37 * buffer[0]: extmem kBytes below 16M (max 15M/1024)
38 * buffer[1]: extmem above 16M, in 64k units
39 */
40 ENTRY(getextmem2)
41 pushl %ebp
42 movl %esp,%ebp
43 pushl %ebx
44 pushl %ecx
45 pushl %edx
46 push %esi
47 push %edi
48
49 call _C_LABEL(prot_to_real)
50 .code16
51
52 xorl %ebx,%ebx
53 movl $0xe801,%eax
54 int $0x15
55 pushf
56
57 movw %si,%ax
58 orw %si,%bx
59 jz 1f /* if zero use configured values */
60 movw %cx,%ax /* k below 16M (max 0x3c00 = 15MB) */
61 movw %dx,%bx /* 64k above 16M */
62 1:
63 popf
64 setc %bl
65
66 calll _C_LABEL(real_to_prot)
67 .code32
68
69 movl 8(%ebp),%edi
70 xorl %eax,%eax
71 movw %cx,%ax
72 stosl
73 movw %dx,%ax
74 stosl
75 movb %bl,%al
76 cbw
77
78 pop %edi
79 pop %esi
80 popl %edx
81 popl %ecx
82 popl %ebx
83 popl %ebp
84 ret
85
86 /*
87 * int getmementry(int *iterator, int buffer[5])
88 *
89 * return: 0=ok, else error
90 * buffer[0]: start of memory chunk
91 * buffer[2]: length (bytes)
92 * buffer[4]: type
93 */
94 ENTRY(getmementry)
95 pushl %ebp
96 movl %esp,%ebp
97 pushl %ebx
98 pushl %ecx
99 pushl %edx
100 push %esi
101 push %edi
102
103 movl 8(%ebp),%eax
104 movl 0(%eax),%ebx /* index */
105 movl $20,%ecx /* Buffer size */
106 movl $0x534d4150,%edx /* "SMAP" */
107 movl 12(%ebp),%edi /* buffer address */
108
109 call _C_LABEL(prot_to_real)
110 .code16
111
112 push %di
113 shrl $4,%edi
114 mov %ds,%ax
115 add %di,%ax
116 mov %ax,%es
117 pop %di
118 and $0xf,%di /* buffer addres now in ES:DI */
119
120 movl $0xe820,%eax /* Some BIOS check EAX value */
121 int $0x15
122
123 setc %cl
124
125 calll _C_LABEL(real_to_prot)
126 .code32
127
128 movl 8(%ebp),%eax
129 movl %ebx,0(%eax) /* updated index */
130 xorl %eax,%eax
131 movb %cl,%al
132
133 pop %edi
134 pop %esi
135 popl %edx
136 popl %ecx
137 popl %ebx
138 popl %ebp
139 ret
140
141 /*
142 * int biosA20(void)
143 *
144 * return: 0=ok, else error
145 */
146 ENTRY(biosA20)
147 pushl %ebp
148 movl %esp,%ebp
149 pushl %ebx
150 pushl %ecx
151 pushl %edx
152 push %esi
153 push %edi
154
155 call _C_LABEL(prot_to_real)
156 .code16
157
158 movl $0x2401,%eax
159 int $0x15
160 setc %cl
161
162 calll _C_LABEL(real_to_prot)
163 .code32
164
165 movzbl %cl,%eax
166
167 pop %edi
168 pop %esi
169 popl %edx
170 popl %ecx
171 popl %ebx
172 popl %ebp
173 ret
174