[69300] | 1 | ; $Id:
|
---|
| 2 | ;; @file
|
---|
| 3 | ; Protected-mode APM implementation.
|
---|
| 4 | ;
|
---|
[42770] | 5 |
|
---|
[69300] | 6 | ;
|
---|
[98103] | 7 | ; Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[69300] | 8 | ;
|
---|
[96407] | 9 | ; This file is part of VirtualBox base platform packages, as
|
---|
| 10 | ; available from https://www.virtualbox.org.
|
---|
[69300] | 11 | ;
|
---|
[96407] | 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 | ;
|
---|
[42770] | 27 |
|
---|
[69300] | 28 |
|
---|
[60422] | 29 | include commondefs.inc
|
---|
| 30 |
|
---|
[42770] | 31 | ;; 16-bit protected mode APM entry point
|
---|
| 32 |
|
---|
| 33 | _TEXT segment public 'CODE'
|
---|
| 34 |
|
---|
| 35 | extern _apm_function:near ; implemented in C code
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | public apm_pm16_entry
|
---|
| 39 |
|
---|
[100456] | 40 | ;
|
---|
| 41 | ; This module is for protected mode only and therefore
|
---|
| 42 | ; 286+ only
|
---|
| 43 | ;
|
---|
[60422] | 44 | SET_DEFAULT_CPU_286
|
---|
[42770] | 45 |
|
---|
| 46 |
|
---|
| 47 | ; APM function dispatch table
|
---|
| 48 | apm_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
|
---|
| 62 | apm_disp_end:
|
---|
| 63 |
|
---|
| 64 | ;
|
---|
| 65 | ; APM worker routine. Function code in AL; it is assumed that AL >= 4.
|
---|
| 66 | ; Caller must preserve BP.
|
---|
| 67 | ;
|
---|
| 68 | apm_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 |
|
---|
| 84 | apmf_disconnect: ; function 04h
|
---|
| 85 | jmp apmw_success
|
---|
| 86 |
|
---|
| 87 | apmf_idle: ; function 05h
|
---|
[100456] | 88 | if 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
|
---|
[100458] | 99 | .286 ; build fix; @todo remove
|
---|
[100456] | 100 | rep outsb
|
---|
| 101 |
|
---|
| 102 | pop dx
|
---|
| 103 | pop cx
|
---|
| 104 | pop si
|
---|
| 105 |
|
---|
| 106 | jmp apmw_success
|
---|
| 107 |
|
---|
| 108 | hlt_string db 'Prochalt'
|
---|
| 109 |
|
---|
| 110 | else
|
---|
[76968] | 111 | ;
|
---|
| 112 | ; Windows 3.1 POWER.DRV in Standard mode calls into APM
|
---|
| 113 | ; with CPL=3. If that happens, the HLT instruction will fault
|
---|
| 114 | ; and Windows will crash. To prevent that, we check the CPL
|
---|
| 115 | ; and do nothing (better than crashing).
|
---|
| 116 | ;
|
---|
| 117 | push cs
|
---|
| 118 | pop ax
|
---|
| 119 | test ax, 3 ; CPL > 0?
|
---|
| 120 | jnz apmw_success
|
---|
[42770] | 121 | sti
|
---|
| 122 | hlt
|
---|
| 123 | jmp apmw_success
|
---|
[100456] | 124 | endif
|
---|
[42770] | 125 |
|
---|
| 126 | apmf_busy: ; function 06h
|
---|
| 127 | ; jmp apmw_success
|
---|
| 128 |
|
---|
| 129 | apmf_set_state: ; function 07h
|
---|
| 130 | ; jmp apmw_success
|
---|
| 131 |
|
---|
| 132 | apmf_enable: ; function 08h
|
---|
| 133 | jmp apmw_success
|
---|
| 134 |
|
---|
| 135 | apmf_restore: ; function 09h
|
---|
| 136 | ; jmp apmw_success
|
---|
| 137 |
|
---|
| 138 | apmf_get_status: ; function 0Ah
|
---|
| 139 | jmp apmw_bad_func
|
---|
| 140 |
|
---|
| 141 | apmf_get_event: ; function 0Bh
|
---|
| 142 | mov ah, 80h
|
---|
| 143 | jmp apmw_failure
|
---|
| 144 |
|
---|
| 145 | apmf_pwr_state: ; function 0Ch
|
---|
| 146 |
|
---|
| 147 | apmf_dev_pm: ; function 0Dh
|
---|
| 148 | jmp apmw_bad_func
|
---|
| 149 |
|
---|
| 150 | apmf_version: ; function 0Eh
|
---|
| 151 | mov ax, 0102h
|
---|
| 152 | jmp apmw_success
|
---|
| 153 |
|
---|
| 154 | apmf_engage: ; function 0Fh
|
---|
| 155 | ; TODO do something?
|
---|
| 156 | jmp apmw_success
|
---|
| 157 |
|
---|
| 158 | apmf_get_caps: ; function 10h
|
---|
| 159 | mov bl, 0 ; no batteries
|
---|
| 160 | mov cx, 0 ; no special caps
|
---|
| 161 | jmp apmw_success
|
---|
| 162 |
|
---|
| 163 | apmw_success:
|
---|
| 164 | clc ; successful return
|
---|
| 165 | ret
|
---|
| 166 |
|
---|
| 167 | apmw_bad_func:
|
---|
| 168 | mov ah, 09h ; unrecognized device ID - generic
|
---|
| 169 |
|
---|
| 170 | apmw_failure:
|
---|
| 171 | stc ; error for unsupported functions
|
---|
| 172 | ret
|
---|
| 173 |
|
---|
| 174 | apm_worker endp
|
---|
| 175 |
|
---|
| 176 |
|
---|
[42791] | 177 | ;; 16-bit protected mode APM entry point
|
---|
[42770] | 178 |
|
---|
[42791] | 179 | ;; According to the APM spec, only CS (16-bit code selector) is defined.
|
---|
| 180 | ;; The data selector can be derived from it.
|
---|
| 181 |
|
---|
[42770] | 182 | apm_pm16_entry:
|
---|
| 183 |
|
---|
[42791] | 184 | mov ah, 2 ; mark as originating in 16-bit PM
|
---|
[69300] | 185 |
|
---|
[42791] | 186 | ; fall through
|
---|
| 187 |
|
---|
[42770] | 188 | apm_pm16_entry_from_32:
|
---|
| 189 |
|
---|
| 190 | push ds ; save registers
|
---|
| 191 | push bp
|
---|
| 192 |
|
---|
| 193 | push cs
|
---|
| 194 | pop bp
|
---|
| 195 | add bp, 8 ; calculate data selector
|
---|
| 196 | mov ds, bp ; load data segment
|
---|
| 197 |
|
---|
| 198 | call apm_worker ; call APM handler
|
---|
| 199 |
|
---|
| 200 | pop bp
|
---|
| 201 | pop ds ; restore registers
|
---|
| 202 |
|
---|
[42791] | 203 | retf ; return to caller - 16-bit return
|
---|
| 204 | ; even to 32-bit thunk!
|
---|
[42770] | 205 |
|
---|
| 206 | _TEXT ends
|
---|
| 207 |
|
---|
| 208 |
|
---|
[74580] | 209 | if VBOX_BIOS_CPU ge 80386
|
---|
| 210 |
|
---|
[42770] | 211 | .386
|
---|
| 212 |
|
---|
| 213 | BIOS32 segment public 'CODE' use32
|
---|
| 214 |
|
---|
| 215 | public apm_pm32_entry
|
---|
| 216 |
|
---|
| 217 | ;; 32-bit protected mode APM entry point and thunk
|
---|
| 218 |
|
---|
| 219 | ;; According to the APM spec, only CS (32-bit) is defined. 16-bit code
|
---|
| 220 | ;; selector and the data selector can be derived from it.
|
---|
| 221 |
|
---|
[42791] | 222 | ;; WARNING: To simplify matters, we use 16-bit far return to go from 32-bit
|
---|
| 223 | ;; code to 16-bit and back. As a consequence, the 32-bit APM code must lie
|
---|
| 224 | ;; below 64K boundary in the 32-bit APM code segment.
|
---|
| 225 |
|
---|
[42770] | 226 | apm_pm32_entry:
|
---|
| 227 |
|
---|
| 228 | push ebp ; ebp is not used by APM
|
---|
| 229 |
|
---|
[42791] | 230 | mov bp, cs ; return address for 16-bit code
|
---|
| 231 | push bp
|
---|
| 232 | mov ebp, apm_pm32_back
|
---|
| 233 | push bp ; Note: 16:16 address!
|
---|
[42770] | 234 |
|
---|
| 235 | push cs
|
---|
| 236 | pop ebp
|
---|
| 237 | add ebp, 8 ; calculate 16-bit code selector
|
---|
[42791] | 238 | push bp ; push 16-bit code selector
|
---|
[42770] | 239 |
|
---|
[42791] | 240 | mov ebp, apm_pm16_entry_from_32
|
---|
| 241 | push bp ; push 16-bit offset
|
---|
[42770] | 242 |
|
---|
| 243 | mov ah, 3 ; mark as originating in 32-bit PM
|
---|
[42791] | 244 |
|
---|
| 245 | db 66h ; force a 16-bit return
|
---|
[42770] | 246 | retf ; off to 16-bit code...
|
---|
| 247 |
|
---|
| 248 | apm_pm32_back: ; return here from 16-bit code
|
---|
| 249 |
|
---|
| 250 | pop ebp ; restore scratch register
|
---|
| 251 | retf
|
---|
| 252 |
|
---|
| 253 | BIOS32 ends
|
---|
| 254 |
|
---|
[74580] | 255 | endif ; 32-bit code
|
---|
| 256 |
|
---|
[42770] | 257 | end
|
---|