VirtualBox

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

Last change on this file since 42791 was 42791, checked in by vboxsync, 12 years ago

BIOS: Fixed 16-bit PM APM interface.

  • 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-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;; 16-bit protected mode APM entry point
127
128;; According to the APM spec, only CS (16-bit code selector) is defined.
129;; The data selector can be derived from it.
130
131apm_pm16_entry:
132
133 mov ah, 2 ; mark as originating in 16-bit PM
134
135 ; fall through
136
137apm_pm16_entry_from_32:
138
139 push ds ; save registers
140 push bp
141
142 push cs
143 pop bp
144 add bp, 8 ; calculate data selector
145 mov ds, bp ; load data segment
146
147 call apm_worker ; call APM handler
148
149 pop bp
150 pop ds ; restore registers
151
152 retf ; return to caller - 16-bit return
153 ; even to 32-bit thunk!
154
155_TEXT ends
156
157
158.386
159
160BIOS32 segment public 'CODE' use32
161
162public apm_pm32_entry
163
164;; 32-bit protected mode APM entry point and thunk
165
166;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
167;; selector and the data selector can be derived from it.
168
169;; WARNING: To simplify matters, we use 16-bit far return to go from 32-bit
170;; code to 16-bit and back. As a consequence, the 32-bit APM code must lie
171;; below 64K boundary in the 32-bit APM code segment.
172
173apm_pm32_entry:
174
175 push ebp ; ebp is not used by APM
176
177 mov bp, cs ; return address for 16-bit code
178 push bp
179 mov ebp, apm_pm32_back
180 push bp ; Note: 16:16 address!
181
182 push cs
183 pop ebp
184 add ebp, 8 ; calculate 16-bit code selector
185 push bp ; push 16-bit code selector
186
187 mov ebp, apm_pm16_entry_from_32
188 push bp ; push 16-bit offset
189
190 mov ah, 3 ; mark as originating in 32-bit PM
191
192 db 66h ; force a 16-bit return
193 retf ; off to 16-bit code...
194
195apm_pm32_back: ; return here from 16-bit code
196
197 pop ebp ; restore scratch register
198 retf
199
200BIOS32 ends
201
202 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