]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/bios.s
boot-83.2.tar.gz
[apple/boot.git] / i386 / libsaio / bios.s
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Copyright 1993 NeXT Computer, Inc.
26 * All rights reserved.
27 *
28 * Harness for calling real-mode BIOS functions.
29 */
30
31 #include "legacy/asm.h"
32
33 #define data32 .byte 0x66
34 #define addr32 .byte 0x67
35
36 #define O_INT 0
37 #define O_EAX 4
38 #define O_EBX 8
39 #define O_ECX 12
40 #define O_EDX 16
41 #define O_EDI 20
42 #define O_ESI 24
43 #define O_EBP 28
44 #define O_CS 32
45 #define O_DS 34
46 #define O_ES 36
47 #define O_FLG 38
48
49 .data
50 .lcomm save_eax, 4,2
51 .lcomm save_edx, 4,2
52 .lcomm save_es, 2,1
53 .lcomm save_flag, 2,1
54 .lcomm new_eax, 4,2
55 .lcomm new_edx, 4,2
56 .lcomm new_es, 2,1
57
58 .text
59
60 /*============================================================================
61 * Call real-mode BIOS INT functions.
62 *
63 */
64 ENTRY(bios)
65 enter $0,$0
66 pushal
67
68 movl 8(%ebp), %edx // address of save area
69 movb O_INT(%edx), %al // save int number
70 movb %al, do_int+1
71
72 movl O_EBX(%edx), %ebx
73 movl O_ECX(%edx), %ecx
74 movl O_EDI(%edx), %edi
75 movl O_ESI(%edx), %esi
76 movl O_EBP(%edx), %ebp
77 movl %edx, save_edx
78 movl O_EAX(%edx), %eax
79 movl %eax, new_eax
80 movl O_EDX(%edx), %eax
81 movl %eax, new_edx
82 movw O_ES(%edx), %ax
83 movl %ax, new_es
84
85 call EXT(_prot_to_real)
86
87 data32
88 addr32
89 mov new_eax, %eax
90 data32
91 addr32
92 mov new_edx, %edx
93 data32
94 addr32
95 mov new_es, %es
96
97 do_int:
98 int $0x00
99 pushf
100 data32
101 addr32
102 movl %eax, save_eax
103 popl %eax // actually pop %ax
104 addr32
105 movl %eax, save_flag // actually movw
106 mov %es, %ax
107 addr32
108 movl %eax, save_es // actually movw
109 data32
110 call EXT(_real_to_prot)
111
112 movl %edx, new_edx // save new edx before clobbering
113 movl save_edx, %edx
114 movl new_edx, %eax // now move it into buffer
115 movl %eax, O_EDX(%edx)
116 movl save_eax, %eax
117 movl %eax, O_EAX(%edx)
118 movw save_es, %ax
119 movw %ax, O_ES(%edx)
120 movw save_flag, %ax
121 movw %ax, O_FLG(%edx)
122 movl %ebx, O_EBX(%edx)
123 movl %ecx, O_ECX(%edx)
124 movl %edi, O_EDI(%edx)
125 movl %esi, O_ESI(%edx)
126 movl %ebp, O_EBP(%edx)
127
128 popal
129 leave
130
131 ret
132
133 /*============================================================================
134 * Determines the total system memory size using various BIOS Int 15 calls.
135 *
136 */
137 ENTRY(get_memsize)
138 enter $0, $0 # create frame pointer (32 bit operand/stack)
139 pushal # save all registers
140
141 movl 8(%ebp), %ebx # push input structure pointer to stack
142 pushl %ebx
143
144 call EXT(_prot_to_real) # switch to real mode
145
146 ##################################################################
147 # In real mode.
148 # Do not forget the opcode overrides, since the assembler
149 # does not know we have made a transition to 16-bit operation.
150 ##################################################################
151
152 data32
153 movl $0xE801, %eax # Get memory size
154 clc
155 int $0x15
156 data32
157 jnc getmsz_e801
158
159 data32
160 movl $0xDA88, %eax # Get memory size
161 clc
162 int $0x15
163 data32
164 jnc getmsz_da88
165
166 movb $0x8A, %ah # Get memory size
167 clc
168 int $0x15
169 data32
170 jnc getmsz_8a
171
172 movb $0x88, %ah # Get memory size
173 clc
174 int $0x15
175 data32
176 jnc getmsz_88
177
178 xorl %edx, %edx # Error, cannot get memory size
179 xorl %eax, %eax
180
181 getmsz_done:
182 data32
183 addr32
184 pushl %eax # Push EAX to 32-bit stack
185
186 data32
187 call EXT(_real_to_prot) # Back to protected mode. EAX is modified.
188
189 ##################################################################
190 # Back to protected mode.
191 ##################################################################
192
193 popl %eax # Pop EAX from stack
194 popl %ebx # Pop pointer to register structure
195
196 # Copy the result to the input structure pointed to by a pointer
197 # which is on top of the stack. Write register EAX and EDX to the
198 # structure.
199
200 movl %eax, O_EAX(%ebx)
201 movl %edx, O_EDX(%ebx)
202
203 popal # restore all registers
204 leave # undo enter operator
205 ret
206
207 getmsz_88:
208 orl %eax, %eax
209 data32
210 jz getmsz_64m
211 xorl %edx, %edx
212
213 getmsz_8a:
214 data32
215 movl $1024, %ebx # Add in 1M
216 addl %ebx, %eax
217 adcl $0, %edx
218 data32
219 jmp getmsz_done
220
221 getmsz_64m:
222 data32
223 movl $1, %edx
224 xorl %eax, %eax
225 data32
226 jmp getmsz_done
227
228 getmsz_da88:
229 xor %dh, %dh
230 movb %cl, %dl
231 movl %ebx, %eax
232 data32
233 jmp getmsz_8a
234
235 getmsz_e801:
236 xorl %edx, %edx
237 orl %ebx, %ebx
238 data32
239 jz getmsz_88
240
241 data32
242 movl $64, %eax
243 mul %ebx
244
245 data32
246 movl $16384, %ebx
247 addl %ebx, %eax
248 adcl $0, %edx
249
250 data32
251 jmp getmsz_done