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 |
|
---|
18 | include commondefs.inc
|
---|
19 |
|
---|
20 | ;; 16-bit protected mode APM entry point
|
---|
21 |
|
---|
22 | _TEXT segment public 'CODE'
|
---|
23 |
|
---|
24 | extern _apm_function:near ; implemented in C code
|
---|
25 |
|
---|
26 |
|
---|
27 | public apm_pm16_entry
|
---|
28 |
|
---|
29 | SET_DEFAULT_CPU_286
|
---|
30 |
|
---|
31 |
|
---|
32 | ; APM function dispatch table
|
---|
33 | apm_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
|
---|
47 | apm_disp_end:
|
---|
48 |
|
---|
49 | ;
|
---|
50 | ; APM worker routine. Function code in AL; it is assumed that AL >= 4.
|
---|
51 | ; Caller must preserve BP.
|
---|
52 | ;
|
---|
53 | apm_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 |
|
---|
69 | apmf_disconnect: ; function 04h
|
---|
70 | jmp apmw_success
|
---|
71 |
|
---|
72 | apmf_idle: ; function 05h
|
---|
73 | sti
|
---|
74 | hlt
|
---|
75 | jmp apmw_success
|
---|
76 |
|
---|
77 | apmf_busy: ; function 06h
|
---|
78 | ; jmp apmw_success
|
---|
79 |
|
---|
80 | apmf_set_state: ; function 07h
|
---|
81 | ; jmp apmw_success
|
---|
82 |
|
---|
83 | apmf_enable: ; function 08h
|
---|
84 | jmp apmw_success
|
---|
85 |
|
---|
86 | apmf_restore: ; function 09h
|
---|
87 | ; jmp apmw_success
|
---|
88 |
|
---|
89 | apmf_get_status: ; function 0Ah
|
---|
90 | jmp apmw_bad_func
|
---|
91 |
|
---|
92 | apmf_get_event: ; function 0Bh
|
---|
93 | mov ah, 80h
|
---|
94 | jmp apmw_failure
|
---|
95 |
|
---|
96 | apmf_pwr_state: ; function 0Ch
|
---|
97 |
|
---|
98 | apmf_dev_pm: ; function 0Dh
|
---|
99 | jmp apmw_bad_func
|
---|
100 |
|
---|
101 | apmf_version: ; function 0Eh
|
---|
102 | mov ax, 0102h
|
---|
103 | jmp apmw_success
|
---|
104 |
|
---|
105 | apmf_engage: ; function 0Fh
|
---|
106 | ; TODO do something?
|
---|
107 | jmp apmw_success
|
---|
108 |
|
---|
109 | apmf_get_caps: ; function 10h
|
---|
110 | mov bl, 0 ; no batteries
|
---|
111 | mov cx, 0 ; no special caps
|
---|
112 | jmp apmw_success
|
---|
113 |
|
---|
114 | apmw_success:
|
---|
115 | clc ; successful return
|
---|
116 | ret
|
---|
117 |
|
---|
118 | apmw_bad_func:
|
---|
119 | mov ah, 09h ; unrecognized device ID - generic
|
---|
120 |
|
---|
121 | apmw_failure:
|
---|
122 | stc ; error for unsupported functions
|
---|
123 | ret
|
---|
124 |
|
---|
125 | apm_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 |
|
---|
133 | apm_pm16_entry:
|
---|
134 |
|
---|
135 | mov ah, 2 ; mark as originating in 16-bit PM
|
---|
136 |
|
---|
137 | ; fall through
|
---|
138 |
|
---|
139 | apm_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 |
|
---|
162 | BIOS32 segment public 'CODE' use32
|
---|
163 |
|
---|
164 | public 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 |
|
---|
175 | apm_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 |
|
---|
197 | apm_pm32_back: ; return here from 16-bit code
|
---|
198 |
|
---|
199 | pop ebp ; restore scratch register
|
---|
200 | retf
|
---|
201 |
|
---|
202 | BIOS32 ends
|
---|
203 |
|
---|
204 | end
|
---|