[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
|
---|
| 99 | rep outsb
|
---|
| 100 |
|
---|
| 101 | pop dx
|
---|
| 102 | pop cx
|
---|
| 103 | pop si
|
---|
| 104 |
|
---|
| 105 | jmp apmw_success
|
---|
| 106 |
|
---|
| 107 | hlt_string db 'Prochalt'
|
---|
| 108 |
|
---|
| 109 | else
|
---|
[76968] | 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
|
---|
[42770] | 120 | sti
|
---|
| 121 | hlt
|
---|
| 122 | jmp apmw_success
|
---|
[100456] | 123 | endif
|
---|
[42770] | 124 |
|
---|
| 125 | apmf_busy: ; function 06h
|
---|
| 126 | ; jmp apmw_success
|
---|
| 127 |
|
---|
| 128 | apmf_set_state: ; function 07h
|
---|
| 129 | ; jmp apmw_success
|
---|
| 130 |
|
---|
| 131 | apmf_enable: ; function 08h
|
---|
| 132 | jmp apmw_success
|
---|
| 133 |
|
---|
| 134 | apmf_restore: ; function 09h
|
---|
| 135 | ; jmp apmw_success
|
---|
| 136 |
|
---|
| 137 | apmf_get_status: ; function 0Ah
|
---|
| 138 | jmp apmw_bad_func
|
---|
| 139 |
|
---|
| 140 | apmf_get_event: ; function 0Bh
|
---|
| 141 | mov ah, 80h
|
---|
| 142 | jmp apmw_failure
|
---|
| 143 |
|
---|
| 144 | apmf_pwr_state: ; function 0Ch
|
---|
| 145 |
|
---|
| 146 | apmf_dev_pm: ; function 0Dh
|
---|
| 147 | jmp apmw_bad_func
|
---|
| 148 |
|
---|
| 149 | apmf_version: ; function 0Eh
|
---|
| 150 | mov ax, 0102h
|
---|
| 151 | jmp apmw_success
|
---|
| 152 |
|
---|
| 153 | apmf_engage: ; function 0Fh
|
---|
| 154 | ; TODO do something?
|
---|
| 155 | jmp apmw_success
|
---|
| 156 |
|
---|
| 157 | apmf_get_caps: ; function 10h
|
---|
| 158 | mov bl, 0 ; no batteries
|
---|
| 159 | mov cx, 0 ; no special caps
|
---|
| 160 | jmp apmw_success
|
---|
| 161 |
|
---|
| 162 | apmw_success:
|
---|
| 163 | clc ; successful return
|
---|
| 164 | ret
|
---|
| 165 |
|
---|
| 166 | apmw_bad_func:
|
---|
| 167 | mov ah, 09h ; unrecognized device ID - generic
|
---|
| 168 |
|
---|
| 169 | apmw_failure:
|
---|
| 170 | stc ; error for unsupported functions
|
---|
| 171 | ret
|
---|
| 172 |
|
---|
| 173 | apm_worker endp
|
---|
| 174 |
|
---|
| 175 |
|
---|
[42791] | 176 | ;; 16-bit protected mode APM entry point
|
---|
[42770] | 177 |
|
---|
[42791] | 178 | ;; According to the APM spec, only CS (16-bit code selector) is defined.
|
---|
| 179 | ;; The data selector can be derived from it.
|
---|
| 180 |
|
---|
[42770] | 181 | apm_pm16_entry:
|
---|
| 182 |
|
---|
[42791] | 183 | mov ah, 2 ; mark as originating in 16-bit PM
|
---|
[69300] | 184 |
|
---|
[42791] | 185 | ; fall through
|
---|
| 186 |
|
---|
[42770] | 187 | apm_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 |
|
---|
[42791] | 202 | retf ; return to caller - 16-bit return
|
---|
| 203 | ; even to 32-bit thunk!
|
---|
[42770] | 204 |
|
---|
| 205 | _TEXT ends
|
---|
| 206 |
|
---|
| 207 |
|
---|
[74580] | 208 | if VBOX_BIOS_CPU ge 80386
|
---|
| 209 |
|
---|
[42770] | 210 | .386
|
---|
| 211 |
|
---|
| 212 | BIOS32 segment public 'CODE' use32
|
---|
| 213 |
|
---|
| 214 | public 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 |
|
---|
[42791] | 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 |
|
---|
[42770] | 225 | apm_pm32_entry:
|
---|
| 226 |
|
---|
| 227 | push ebp ; ebp is not used by APM
|
---|
| 228 |
|
---|
[42791] | 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!
|
---|
[42770] | 233 |
|
---|
| 234 | push cs
|
---|
| 235 | pop ebp
|
---|
| 236 | add ebp, 8 ; calculate 16-bit code selector
|
---|
[42791] | 237 | push bp ; push 16-bit code selector
|
---|
[42770] | 238 |
|
---|
[42791] | 239 | mov ebp, apm_pm16_entry_from_32
|
---|
| 240 | push bp ; push 16-bit offset
|
---|
[42770] | 241 |
|
---|
| 242 | mov ah, 3 ; mark as originating in 32-bit PM
|
---|
[42791] | 243 |
|
---|
| 244 | db 66h ; force a 16-bit return
|
---|
[42770] | 245 | retf ; off to 16-bit code...
|
---|
| 246 |
|
---|
| 247 | apm_pm32_back: ; return here from 16-bit code
|
---|
| 248 |
|
---|
| 249 | pop ebp ; restore scratch register
|
---|
| 250 | retf
|
---|
| 251 |
|
---|
| 252 | BIOS32 ends
|
---|
| 253 |
|
---|
[74580] | 254 | endif ; 32-bit code
|
---|
| 255 |
|
---|
[42770] | 256 | end
|
---|