VirtualBox

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

Last change on this file since 97097 was 96407, checked in by vboxsync, 3 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1; $Id:
2;; @file
3; Protected-mode APM implementation.
4;
5
6;
7; Copyright (C) 2006-2022 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; SPDX-License-Identifier: GPL-3.0-only
26;
27
28
29include commondefs.inc
30
31;; 16-bit protected mode APM entry point
32
33_TEXT segment public 'CODE'
34
35extern _apm_function:near ; implemented in C code
36
37
38public apm_pm16_entry
39
40SET_DEFAULT_CPU_286
41
42
43; APM function dispatch table
44apm_disp:
45 dw offset apmf_disconnect ; 04h
46 dw offset apmf_idle ; 05h
47 dw offset apmf_busy ; 06h
48 dw offset apmf_set_state ; 07h
49 dw offset apmf_enable ; 08h
50 dw offset apmf_restore ; 09h
51 dw offset apmf_get_status ; 0Ah
52 dw offset apmf_get_event ; 0Bh
53 dw offset apmf_pwr_state ; 0Ch
54 dw offset apmf_dev_pm ; 0Dh
55 dw offset apmf_version ; 0Eh
56 dw offset apmf_engage ; 0Fh
57 dw offset apmf_get_caps ; 10h
58apm_disp_end:
59
60;
61; APM worker routine. Function code in AL; it is assumed that AL >= 4.
62; Caller must preserve BP.
63;
64apm_worker proc near
65
66 sti ; TODO ?? necessary ??
67
68 push ax ; check if function is supported...
69 xor ah, ah
70 sub al, 4
71 mov bp, ax
72 shl bp, 1
73 cmp al, (apm_disp_end - apm_disp) / 2
74 pop ax
75 mov ah, 53h ; put back APM function
76 jae apmw_bad_func ; validate function range
77
78 jmp apm_disp[bp] ; and dispatch
79
80apmf_disconnect: ; function 04h
81 jmp apmw_success
82
83apmf_idle: ; function 05h
84 ;
85 ; Windows 3.1 POWER.DRV in Standard mode calls into APM
86 ; with CPL=3. If that happens, the HLT instruction will fault
87 ; and Windows will crash. To prevent that, we check the CPL
88 ; and do nothing (better than crashing).
89 ;
90 push cs
91 pop ax
92 test ax, 3 ; CPL > 0?
93 jnz apmw_success
94 sti
95 hlt
96 jmp apmw_success
97
98apmf_busy: ; function 06h
99; jmp apmw_success
100
101apmf_set_state: ; function 07h
102; jmp apmw_success
103
104apmf_enable: ; function 08h
105 jmp apmw_success
106
107apmf_restore: ; function 09h
108; jmp apmw_success
109
110apmf_get_status: ; function 0Ah
111 jmp apmw_bad_func
112
113apmf_get_event: ; function 0Bh
114 mov ah, 80h
115 jmp apmw_failure
116
117apmf_pwr_state: ; function 0Ch
118
119apmf_dev_pm: ; function 0Dh
120 jmp apmw_bad_func
121
122apmf_version: ; function 0Eh
123 mov ax, 0102h
124 jmp apmw_success
125
126apmf_engage: ; function 0Fh
127 ; TODO do something?
128 jmp apmw_success
129
130apmf_get_caps: ; function 10h
131 mov bl, 0 ; no batteries
132 mov cx, 0 ; no special caps
133 jmp apmw_success
134
135apmw_success:
136 clc ; successful return
137 ret
138
139apmw_bad_func:
140 mov ah, 09h ; unrecognized device ID - generic
141
142apmw_failure:
143 stc ; error for unsupported functions
144 ret
145
146apm_worker endp
147
148
149;; 16-bit protected mode APM entry point
150
151;; According to the APM spec, only CS (16-bit code selector) is defined.
152;; The data selector can be derived from it.
153
154apm_pm16_entry:
155
156 mov ah, 2 ; mark as originating in 16-bit PM
157
158 ; fall through
159
160apm_pm16_entry_from_32:
161
162 push ds ; save registers
163 push bp
164
165 push cs
166 pop bp
167 add bp, 8 ; calculate data selector
168 mov ds, bp ; load data segment
169
170 call apm_worker ; call APM handler
171
172 pop bp
173 pop ds ; restore registers
174
175 retf ; return to caller - 16-bit return
176 ; even to 32-bit thunk!
177
178_TEXT ends
179
180
181if VBOX_BIOS_CPU ge 80386
182
183.386
184
185BIOS32 segment public 'CODE' use32
186
187public apm_pm32_entry
188
189;; 32-bit protected mode APM entry point and thunk
190
191;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
192;; selector and the data selector can be derived from it.
193
194;; WARNING: To simplify matters, we use 16-bit far return to go from 32-bit
195;; code to 16-bit and back. As a consequence, the 32-bit APM code must lie
196;; below 64K boundary in the 32-bit APM code segment.
197
198apm_pm32_entry:
199
200 push ebp ; ebp is not used by APM
201
202 mov bp, cs ; return address for 16-bit code
203 push bp
204 mov ebp, apm_pm32_back
205 push bp ; Note: 16:16 address!
206
207 push cs
208 pop ebp
209 add ebp, 8 ; calculate 16-bit code selector
210 push bp ; push 16-bit code selector
211
212 mov ebp, apm_pm16_entry_from_32
213 push bp ; push 16-bit offset
214
215 mov ah, 3 ; mark as originating in 32-bit PM
216
217 db 66h ; force a 16-bit return
218 retf ; off to 16-bit code...
219
220apm_pm32_back: ; return here from 16-bit code
221
222 pop ebp ; restore scratch register
223 retf
224
225BIOS32 ends
226
227endif ; 32-bit code
228
229 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