VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/apmbios.S@ 21205

Last change on this file since 21205 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1// APM BIOS support for the Bochs BIOS
2// Copyright (C) 2004 Fabrice Bellard
3//
4// Debugging extensions, 16-bit interface and extended power options
5// Copyright (C) 2005 Struan Bartlett
6//
7// This library is free software; you can redistribute it and/or
8// modify it under the terms of the GNU Lesser General Public
9// License as published by the Free Software Foundation; either
10// version 2 of the License, or (at your option) any later version.
11//
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// Lesser General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public
18// License along with this library; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21#if defined(APM_REAL)
22#define APMSYM(s) apmreal_ ## s
23#elif defined(APM_PROT16)
24#define APMSYM(s) apm16_ ## s
25#elif defined(APM_PROT32)
26#define APMSYM(s) apm32_ ## s
27#else
28#error unsupported APM mode
29#endif
30
31APMSYM(out_str):
32 push eax
33 push ebx
34 mov ebx, eax
35APMSYM(out_str1):
36 SEG CS
37 mov al, byte ptr [bx]
38 cmp al, #0
39 je APMSYM(out_str2)
40 outb dx, al
41 inc ebx
42 jmp APMSYM(out_str1)
43APMSYM(out_str2):
44 pop ebx
45 pop eax
46 ret
47
48APMSYM(07_poweroff_str):
49 .ascii "Shutdown"
50 db 0
51APMSYM(07_suspend_str):
52 .ascii "Suspend"
53 db 0
54APMSYM(07_standby_str):
55 .ascii "Standby"
56 db 0
57
58#if DEBUG_APM
59APMSYM(put_str):
60 push edx
61 mov dx, #INFO_PORT
62 call APMSYM(out_str)
63 pop edx
64 ret
65
66; print the hex number in eax
67APMSYM(put_num):
68 push eax
69 push ebx
70 push ecx
71 push edx
72 mov ecx, eax
73 mov bx, #8
74 mov dx, #INFO_PORT
75APMSYM(put_num1):
76 mov eax, ecx
77 shr eax, #28
78 add al, #0x30
79 cmp al, #0x39
80 jbe APMSYM(put_num2)
81 add al, #0x27
82APMSYM(put_num2):
83 outb dx, al
84 shl ecx, #4
85 dec bx
86 jne APMSYM(put_num1)
87 pop edx
88 pop ecx
89 pop ebx
90 pop eax
91 ret
92
93APMSYM(put_reg):
94 outb dx, al
95 shr eax, #8
96 outb dx, al
97 shr eax, #8
98 outb dx, al
99 shr eax, #8
100 outb dx, al
101
102 mov eax,ebx
103 call APMSYM(put_num)
104
105 mov al, #0x3b
106 outb dx,al
107 mov al, #0x20
108 outb dx,al
109 ret
110
111APMSYM(put_regs):
112 push eax
113 push edx
114 push ebx
115 mov dx, #INFO_PORT
116
117 mov ebx, eax
118 mov eax, #0x3d584145 // 'EAX='
119 call APMSYM(put_reg)
120 pop ebx
121 push ebx
122 mov eax, #0x3d584245 // 'EBX='
123 call APMSYM(put_reg)
124 mov ebx, ecx
125 mov eax, #0x3d584345 // 'ECX='
126 call APMSYM(put_reg)
127 mov ebx, edx
128 mov eax, #0x3d584445 // 'EDX='
129 call APMSYM(put_reg)
130 mov ebx, esi
131 mov eax, #0x3d495345 // 'ESI='
132 call APMSYM(put_reg)
133 mov ebx, edi
134 mov eax, #0x3d494445 // 'EDI='
135 call APMSYM(put_reg)
136
137 mov al, #0x0a
138 outb dx, al
139 pop ebx
140 pop edx
141 pop eax
142 ret
143#endif
144
145#if defined(APM_PROT32)
146_apm32_entry:
147#endif
148#if defined(APM_PROT16)
149_apm16_entry:
150#endif
151 pushf
152
153#if defined(APM_REAL)
154_apmreal_entry:
155#endif
156
157#if DEBUG_APM
158 call APMSYM(put_regs)
159#endif
160
161;-----------------
162; APM CPU Idle
163APMSYM(05):
164 cmp al, #0x05
165 jne APMSYM(06)
166 sti
167 hlt
168 jmp APMSYM(ok)
169
170;-----------------
171; APM CPU Busy
172APMSYM(06):
173 cmp al, #0x06
174#if defined(APM_REAL)
175 jne APMSYM(00)
176#else
177 jne APMSYM(04)
178#endif
179 jmp APMSYM(ok)
180
181#if defined(APM_REAL)
182;-----------------
183; APM installation check
184APMSYM(00):
185 cmp al, #0x00
186 jne APMSYM(01)
187
188 mov ah, #1 // APM major version
189 mov al, #2 // APM minor version
190
191 mov bh, #0x50 // 'P'
192 mov bl, #0x4d // 'M'
193
194 // bit 0 : 16 bit interface supported
195 // bit 1 : 32 bit interface supported
196 mov cx, #0x3
197 jmp APMSYM(ok)
198
199;-----------------
200; APM real mode interface connect
201APMSYM(01):
202 cmp al, #0x01
203 jne APMSYM(02)
204 jmp APMSYM(ok)
205
206;-----------------
207; APM 16 bit protected mode interface connect
208APMSYM(02):
209 cmp al, #0x02
210 jne APMSYM(03)
211
212 mov bx, #_apm16_entry
213
214 mov ax, #0xf000 // 16 bit code segment base
215 mov si, #0xfff0 // 16 bit code segment size
216 mov cx, #0xf000 // data segment address
217 mov di, #0xfff0 // data segment length
218 jmp APMSYM(ok)
219
220;-----------------
221; APM 32 bit protected mode interface connect
222APMSYM(03):
223 cmp al, #0x03
224 jne APMSYM(04)
225 mov ax, #0xf000 // 32 bit code segment base
226 mov ebx, #_apm32_entry
227 mov cx, #0xf000 // 16 bit code segment base
228 // 32 bit code segment size (low 16 bits)
229 // 16 bit code segment size (high 16 bits)
230 mov esi, #0xfff0fff0
231 mov dx, #0xf000 // data segment address
232 mov di, #0xfff0 // data segment length
233 jmp APMSYM(ok)
234#endif
235
236;-----------------
237; APM interface disconnect
238APMSYM(04):
239 cmp al, #0x04
240 jne APMSYM(07)
241 jmp APMSYM(ok)
242
243;-----------------
244; APM Set Power State
245APMSYM(07):
246 cmp al, #0x07
247 jne APMSYM(0a)
248
249 cmp bx, #1
250 jne APMSYM(ok)
251
252 cmp cx, #3
253 je APMSYM(07_poweroff)
254
255 cmp cx, #2
256 je APMSYM(07_suspend)
257
258 cmp cx, #1
259 je APMSYM(07_standby)
260
261 jne APMSYM(ok)
262
263APMSYM(07_poweroff):
264 // send power off event to emulator
265 cli
266 mov dx, #0x8900
267 mov ax, #APMSYM(07_poweroff_str)
268 call APMSYM(out_str)
269
270APMSYM(07_1):
271 hlt
272 jmp APMSYM(07_1)
273
274APMSYM(07_suspend):
275 push edx
276 mov dx, #0x8900
277 mov ax, #APMSYM(07_suspend_str)
278 call APMSYM(out_str)
279 pop edx
280 jmp APMSYM(ok)
281
282APMSYM(07_standby):
283 push edx
284 mov dx, #0x8900
285 mov ax, #APMSYM(07_standby_str)
286 call APMSYM(out_str)
287 pop edx
288 jmp APMSYM(ok)
289
290;-----------------
291; Get Power Status
292APMSYM(0a):
293 cmp al, #0x0a
294 jne APMSYM(0b)
295 mov bh, #0x01 // on line
296 // mov bh, #0x02 // battery
297 mov bl, #0xff // unknown battery status
298 // mov bl, #0x03 // charging
299 mov ch, #0x80 // no system battery
300 // mov ch, #0x8 // charging
301 mov cl, #0xff // unknown remaining time
302 // mov cl, #50
303 mov dx, #0xffff // unknown remaining time
304 mov si, #0 // zero battery
305 // mov si, #1 // one battery
306 jmp APMSYM(ok)
307
308;-----------------
309; Get PM Event
310APMSYM(0b):
311 cmp al, #0x0b
312 jne APMSYM(0e)
313 mov ah, #0x80 // no event pending
314 jmp APMSYM(error)
315
316;-----------------
317; APM Driver Version
318APMSYM(0e):
319 cmp al, #0x0e
320 jne APMSYM(unimplemented)
321
322 mov ah, #1
323 mov al, #2
324
325 jmp APMSYM(ok)
326
327;-----------------
328APMSYM(ok):
329 popf
330 clc
331#if defined(APM_REAL)
332 jmp iret_modify_cf
333#else
334 retf
335#endif
336APMSYM(unimplemented):
337APMSYM(error):
338 popf
339 stc
340#if defined(APM_REAL)
341 jmp iret_modify_cf
342#else
343 retf
344#endif
345
346#undef APM_PROT32
347#undef APM_PROT16
348#undef APM_REAL
349#undef APMSYM
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette