VirtualBox

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

Last change on this file since 66146 was 62509, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1;;
2;; Copyright (C) 2006-2016 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
18include commondefs.inc
19
20;; 16-bit protected mode APM entry point
21
22_TEXT segment public 'CODE'
23
24extern _apm_function:near ; implemented in C code
25
26
27public apm_pm16_entry
28
29SET_DEFAULT_CPU_286
30
31
32; APM function dispatch table
33apm_disp:
34 dw offset apmf_disconnect ; 04h
35 dw offset apmf_idle ; 05h
36 dw offset apmf_busy ; 06h
37 dw offset apmf_set_state ; 07h
38 dw offset apmf_enable ; 08h
39 dw offset apmf_restore ; 09h
40 dw offset apmf_get_status ; 0Ah
41 dw offset apmf_get_event ; 0Bh
42 dw offset apmf_pwr_state ; 0Ch
43 dw offset apmf_dev_pm ; 0Dh
44 dw offset apmf_version ; 0Eh
45 dw offset apmf_engage ; 0Fh
46 dw offset apmf_get_caps ; 10h
47apm_disp_end:
48
49;
50; APM worker routine. Function code in AL; it is assumed that AL >= 4.
51; Caller must preserve BP.
52;
53apm_worker proc near
54
55 sti ; TODO ?? necessary ??
56
57 push ax ; check if function is supported...
58 xor ah, ah
59 sub al, 4
60 mov bp, ax
61 shl bp, 1
62 cmp al, (apm_disp_end - apm_disp) / 2
63 pop ax
64 mov ah, 53h ; put back APM function
65 jae apmw_bad_func ; validate function range
66
67 jmp apm_disp[bp] ; and dispatch
68
69apmf_disconnect: ; function 04h
70 jmp apmw_success
71
72apmf_idle: ; function 05h
73 sti
74 hlt
75 jmp apmw_success
76
77apmf_busy: ; function 06h
78; jmp apmw_success
79
80apmf_set_state: ; function 07h
81; jmp apmw_success
82
83apmf_enable: ; function 08h
84 jmp apmw_success
85
86apmf_restore: ; function 09h
87; jmp apmw_success
88
89apmf_get_status: ; function 0Ah
90 jmp apmw_bad_func
91
92apmf_get_event: ; function 0Bh
93 mov ah, 80h
94 jmp apmw_failure
95
96apmf_pwr_state: ; function 0Ch
97
98apmf_dev_pm: ; function 0Dh
99 jmp apmw_bad_func
100
101apmf_version: ; function 0Eh
102 mov ax, 0102h
103 jmp apmw_success
104
105apmf_engage: ; function 0Fh
106 ; TODO do something?
107 jmp apmw_success
108
109apmf_get_caps: ; function 10h
110 mov bl, 0 ; no batteries
111 mov cx, 0 ; no special caps
112 jmp apmw_success
113
114apmw_success:
115 clc ; successful return
116 ret
117
118apmw_bad_func:
119 mov ah, 09h ; unrecognized device ID - generic
120
121apmw_failure:
122 stc ; error for unsupported functions
123 ret
124
125apm_worker endp
126
127
128;; 16-bit protected mode APM entry point
129
130;; According to the APM spec, only CS (16-bit code selector) is defined.
131;; The data selector can be derived from it.
132
133apm_pm16_entry:
134
135 mov ah, 2 ; mark as originating in 16-bit PM
136
137 ; fall through
138
139apm_pm16_entry_from_32:
140
141 push ds ; save registers
142 push bp
143
144 push cs
145 pop bp
146 add bp, 8 ; calculate data selector
147 mov ds, bp ; load data segment
148
149 call apm_worker ; call APM handler
150
151 pop bp
152 pop ds ; restore registers
153
154 retf ; return to caller - 16-bit return
155 ; even to 32-bit thunk!
156
157_TEXT ends
158
159
160.386
161
162BIOS32 segment public 'CODE' use32
163
164public apm_pm32_entry
165
166;; 32-bit protected mode APM entry point and thunk
167
168;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
169;; selector and the data selector can be derived from it.
170
171;; WARNING: To simplify matters, we use 16-bit far return to go from 32-bit
172;; code to 16-bit and back. As a consequence, the 32-bit APM code must lie
173;; below 64K boundary in the 32-bit APM code segment.
174
175apm_pm32_entry:
176
177 push ebp ; ebp is not used by APM
178
179 mov bp, cs ; return address for 16-bit code
180 push bp
181 mov ebp, apm_pm32_back
182 push bp ; Note: 16:16 address!
183
184 push cs
185 pop ebp
186 add ebp, 8 ; calculate 16-bit code selector
187 push bp ; push 16-bit code selector
188
189 mov ebp, apm_pm16_entry_from_32
190 push bp ; push 16-bit offset
191
192 mov ah, 3 ; mark as originating in 32-bit PM
193
194 db 66h ; force a 16-bit return
195 retf ; off to 16-bit code...
196
197apm_pm32_back: ; return here from 16-bit code
198
199 pop ebp ; restore scratch register
200 retf
201
202BIOS32 ends
203
204 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