VirtualBox

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

Last change on this file since 100658 was 100658, checked in by vboxsync, 16 months ago

BIOS: Reworked BIOS build to have a common core and add 286/386 specific modules (see bugref:6549).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1; $Id:
2;; @file
3; Protected-mode APM implementation.
4;
5
6;
7; Copyright (C) 2006-2023 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
40;
41; This module is for protected mode only and therefore
42; 286+ only
43;
44SET_DEFAULT_CPU_286
45
46
47; APM function dispatch table
48apm_disp:
49 dw offset apmf_disconnect ; 04h
50 dw offset apmf_idle ; 05h
51 dw offset apmf_busy ; 06h
52 dw offset apmf_set_state ; 07h
53 dw offset apmf_enable ; 08h
54 dw offset apmf_restore ; 09h
55 dw offset apmf_get_status ; 0Ah
56 dw offset apmf_get_event ; 0Bh
57 dw offset apmf_pwr_state ; 0Ch
58 dw offset apmf_dev_pm ; 0Dh
59 dw offset apmf_version ; 0Eh
60 dw offset apmf_engage ; 0Fh
61 dw offset apmf_get_caps ; 10h
62apm_disp_end:
63
64;
65; APM worker routine. Function code in AL; it is assumed that AL >= 4.
66; Caller must preserve BP.
67;
68apm_worker proc near
69
70 sti ; TODO ?? necessary ??
71
72 push ax ; check if function is supported...
73 xor ah, ah
74 sub al, 4
75 mov bp, ax
76 shl bp, 1
77 cmp al, (apm_disp_end - apm_disp) / 2
78 pop ax
79 mov ah, 53h ; put back APM function
80 jae apmw_bad_func ; validate function range
81
82 jmp apm_disp[bp] ; and dispatch
83
84apmf_disconnect: ; function 04h
85 jmp apmw_success
86
87apmf_idle: ; function 05h
88if 1
89 ; Port I/O based HLT equivalent using a custom BIOS I/O port.
90 ; Works in situations where HLT can't be used, such as Windows 3.1
91 ; in Standard mode or DR-DOS 5.0/6.0 EMM386.SYS.
92 push si
93 push cx
94 push dx
95
96 mov dx, 40Fh
97 mov si, offset hlt_string
98 mov cx,8
99 rep outsb
100
101 pop dx
102 pop cx
103 pop si
104
105 jmp apmw_success
106
107hlt_string db 'Prochalt'
108
109else
110 ;
111 ; Windows 3.1 POWER.DRV in Standard mode calls into APM
112 ; with CPL=3. If that happens, the HLT instruction will fault
113 ; and Windows will crash. To prevent that, we check the CPL
114 ; and do nothing (better than crashing).
115 ;
116 push cs
117 pop ax
118 test ax, 3 ; CPL > 0?
119 jnz apmw_success
120 sti
121 hlt
122 jmp apmw_success
123endif
124
125apmf_busy: ; function 06h
126; jmp apmw_success
127
128apmf_set_state: ; function 07h
129; jmp apmw_success
130
131apmf_enable: ; function 08h
132 jmp apmw_success
133
134apmf_restore: ; function 09h
135; jmp apmw_success
136
137apmf_get_status: ; function 0Ah
138 jmp apmw_bad_func
139
140apmf_get_event: ; function 0Bh
141 mov ah, 80h
142 jmp apmw_failure
143
144apmf_pwr_state: ; function 0Ch
145
146apmf_dev_pm: ; function 0Dh
147 jmp apmw_bad_func
148
149apmf_version: ; function 0Eh
150 mov ax, 0102h
151 jmp apmw_success
152
153apmf_engage: ; function 0Fh
154 ; TODO do something?
155 jmp apmw_success
156
157apmf_get_caps: ; function 10h
158 mov bl, 0 ; no batteries
159 mov cx, 0 ; no special caps
160 jmp apmw_success
161
162apmw_success:
163 clc ; successful return
164 ret
165
166apmw_bad_func:
167 mov ah, 09h ; unrecognized device ID - generic
168
169apmw_failure:
170 stc ; error for unsupported functions
171 ret
172
173apm_worker endp
174
175
176;; 16-bit protected mode APM entry point
177
178;; According to the APM spec, only CS (16-bit code selector) is defined.
179;; The data selector can be derived from it.
180
181apm_pm16_entry:
182
183 mov ah, 2 ; mark as originating in 16-bit PM
184
185 ; fall through
186
187apm_pm16_entry_from_32:
188
189 push ds ; save registers
190 push bp
191
192 push cs
193 pop bp
194 add bp, 8 ; calculate data selector
195 mov ds, bp ; load data segment
196
197 call apm_worker ; call APM handler
198
199 pop bp
200 pop ds ; restore registers
201
202 retf ; return to caller - 16-bit return
203 ; even to 32-bit thunk!
204
205_TEXT ends
206
207
208if VBOX_BIOS_CPU ge 80386
209
210.386
211
212BIOS32 segment public 'CODE' use32
213
214public apm_pm32_entry
215
216;; 32-bit protected mode APM entry point and thunk
217
218;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
219;; selector and the data selector can be derived from it.
220
221;; WARNING: To simplify matters, we use 16-bit far return to go from 32-bit
222;; code to 16-bit and back. As a consequence, the 32-bit APM code must lie
223;; below 64K boundary in the 32-bit APM code segment.
224
225apm_pm32_entry:
226
227 push ebp ; ebp is not used by APM
228
229 mov bp, cs ; return address for 16-bit code
230 push bp
231 mov ebp, apm_pm32_back
232 push bp ; Note: 16:16 address!
233
234 push cs
235 pop ebp
236 add ebp, 8 ; calculate 16-bit code selector
237 push bp ; push 16-bit code selector
238
239 mov ebp, apm_pm16_entry_from_32
240 push bp ; push 16-bit offset
241
242 mov ah, 3 ; mark as originating in 32-bit PM
243
244 db 66h ; force a 16-bit return
245 retf ; off to 16-bit code...
246
247apm_pm32_back: ; return here from 16-bit code
248
249 pop ebp ; restore scratch register
250 retf
251
252BIOS32 ends
253
254endif ; 32-bit code
255
256 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