VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/apm_pm.asm@ 42770

Last change on this file since 42770 was 42770, checked in by vboxsync, 13 years ago

BIOS: Added a very minimal APM implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1;;
2;; Copyright (C) 2006-2012 Oracle Corporation
3;;
4;; This file is part of VirtualBox Open Source Edition (OSE), as
5;; available from http://www.virtualbox.org. This file is free software;
6;; you can redistribute it and/or modify it under the terms of the GNU
7;; General Public License (GPL) as published by the Free Software
8;; Foundation, in version 2 as it comes in the "COPYING" file of the
9;; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10;; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11;;
12;; --------------------------------------------------------------------
13;;
14;; Protected-mode APM implementation.
15;;
16
17
18;; 16-bit protected mode APM entry point
19
20_TEXT segment public 'CODE'
21
22extern _apm_function:near ; implemented in C code
23
24
25public apm_pm16_entry
26
27.286
28
29
30; APM function dispatch table
31apm_disp:
32 dw offset apmf_disconnect ; 04h
33 dw offset apmf_idle ; 05h
34 dw offset apmf_busy ; 06h
35 dw offset apmf_set_state ; 07h
36 dw offset apmf_enable ; 08h
37 dw offset apmf_restore ; 09h
38 dw offset apmf_get_status ; 0Ah
39 dw offset apmf_get_event ; 0Bh
40 dw offset apmf_pwr_state ; 0Ch
41 dw offset apmf_dev_pm ; 0Dh
42 dw offset apmf_version ; 0Eh
43 dw offset apmf_engage ; 0Fh
44 dw offset apmf_get_caps ; 10h
45apm_disp_end:
46
47;
48; APM worker routine. Function code in AL; it is assumed that AL >= 4.
49; Caller must preserve BP.
50;
51apm_worker proc near
52
53 sti ; TODO ?? necessary ??
54
55 push ax ; check if function is supported...
56 xor ah, ah
57 sub al, 4
58 mov bp, ax
59 shl bp, 1
60 cmp al, (apm_disp_end - apm_disp) / 2
61 pop ax
62 mov ah, 53h ; put back APM function
63 jae apmw_bad_func ; validate function range
64
65 jmp apm_disp[bp] ; and dispatch
66
67apmf_disconnect: ; function 04h
68 jmp apmw_success
69
70apmf_idle: ; function 05h
71 sti
72 hlt
73 jmp apmw_success
74
75apmf_busy: ; function 06h
76; jmp apmw_success
77
78apmf_set_state: ; function 07h
79; jmp apmw_success
80
81apmf_enable: ; function 08h
82 jmp apmw_success
83
84apmf_restore: ; function 09h
85; jmp apmw_success
86
87apmf_get_status: ; function 0Ah
88 jmp apmw_bad_func
89
90apmf_get_event: ; function 0Bh
91 mov ah, 80h
92 jmp apmw_failure
93
94apmf_pwr_state: ; function 0Ch
95
96apmf_dev_pm: ; function 0Dh
97 jmp apmw_bad_func
98
99apmf_version: ; function 0Eh
100 mov ax, 0102h
101 jmp apmw_success
102
103apmf_engage: ; function 0Fh
104 ; TODO do something?
105 jmp apmw_success
106
107apmf_get_caps: ; function 10h
108 mov bl, 0 ; no batteries
109 mov cx, 0 ; no special caps
110 jmp apmw_success
111
112apmw_success:
113 clc ; successful return
114 ret
115
116apmw_bad_func:
117 mov ah, 09h ; unrecognized device ID - generic
118
119apmw_failure:
120 stc ; error for unsupported functions
121 ret
122
123apm_worker endp
124
125
126
127apm_pm16_entry:
128 stc
129 retf ; return to 16-bit caller
130
131apm_pm16_entry_from_32:
132
133 push ds ; save registers
134 push bp
135
136 push cs
137 pop bp
138 add bp, 8 ; calculate data selector
139 mov ds, bp ; load data segment
140
141 call apm_worker ; call APM handler
142
143 pop bp
144 pop ds ; restore registers
145
146.386
147 retfd ; return to 32-bit code
148
149_TEXT ends
150
151
152.386
153
154BIOS32 segment public 'CODE' use32
155
156public apm_pm32_entry
157
158;; 32-bit protected mode APM entry point and thunk
159
160;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
161;; selector and the data selector can be derived from it.
162
163apm_pm32_entry:
164
165; cli
166; hlt
167
168 push ebp ; ebp is not used by APM
169
170 push cs ; return address for 16-bit code
171 push apm_pm32_back
172
173 push cs
174 pop ebp
175 add ebp, 8 ; calculate 16-bit code selector
176 push ebp ; push 16-bit code selector
177
178 xor ebp, ebp ; manually pad 16-bit offset
179 push bp ; to a 32-bit value
180 push apm_pm16_entry_from_32
181
182 mov ah, 3 ; mark as originating in 32-bit PM
183 retf ; off to 16-bit code...
184
185apm_pm32_back: ; return here from 16-bit code
186
187 pop ebp ; restore scratch register
188 retf
189
190BIOS32 ends
191
192 end
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