X86指令以实模式关闭计算机电源?

Gov*_*mar 10 x86 assembly dos

在实模式下是否有任何x86指令序列可以关闭(而不是重启)机器?我还有一台带有MS-DOS的旧电脑,我很好奇.

这个问题具体是关于实模式,而不是保护模式或64位长模式.

Bla*_*ear 8

从OSDev上的这篇文章中,您可以使用ACPI或APM接口.ACPI似乎过于复杂,正如您在本文中看到的那样,而APM更简单.我将在此处报告基本步骤:

1)安装检查,以查看是否支持APM:

mov ah,53h            ;this is an APM command
mov al,00h            ;installation check command
xor bx,bx             ;device id (0 = APM BIOS)
int 15h               ;call the BIOS function through interrupt 15h
jc APM_error          ;if the carry flag is set there was an error
                      ;the function was successful
                      ;AX = APM version number
                          ;AH = Major revision number (in BCD format)
                          ;AL = Minor revision number (also BCD format)
                      ;BX = ASCII characters "P" (in BH) and "M" (in BL)
                      ;CX = APM flags (see the official documentation for more details)
Run Code Online (Sandbox Code Playgroud)

2)断开任何现有接口:

;disconnect from any APM interface
mov ah,53h               ;this is an APM command
mov al,04h               ;interface disconnect command
xor bx,bx                ;device id (0 = APM BIOS)
int 15h                  ;call the BIOS function through interrupt 15h
jc .disconnect_error            ;if the carry flag is set see what the fuss is about. 
jmp .no_error

.disconnect_error:       ;the error code is in ah.
cmp ah,03h               ;if the error code is anything but 03h there was an error.
jne APM_error            ;the error code 03h means that no interface was connected in the first place.

.no_error:
                         ;the function was successful
                         ;Nothing is returned.
Run Code Online (Sandbox Code Playgroud)

3)连接到实模式接口(01h):

;connect to an APM interface
mov ah,53h               ;this is an APM command
mov al,[interface_number];see above description
xor bx,bx                ;device id (0 = APM BIOS)
int 15h                  ;call the BIOS function through interrupt 15h
jc APM_error             ;if the carry flag is set there was an error
                         ;the function was successful
                         ;The return values are different for each interface.
                         ;The Real Mode Interface returns nothing.
                         ;See the official documentation for the 
                         ;return values for the protected mode interfaces.
Run Code Online (Sandbox Code Playgroud)

4)为所有设备启用电源管理:

;Enable power management for all devices
mov ah,53h              ;this is an APM command
mov al,08h              ;Change the state of power management...
mov bx,0001h            ;...on all devices to...
mov cx,0001h            ;...power management on.
int 15h                 ;call the BIOS function through interrupt 15h
jc APM_error            ;if the carry flag is set there was an error
Run Code Online (Sandbox Code Playgroud)

5)最后,将电源状态设置为关闭(03h):

;Set the power state for all devices
mov ah,53h              ;this is an APM command
mov al,07h              ;Set the power state...
mov bx,0001h            ;...on all devices to...
mov cx,[power_state]    ;see above
int 15h                 ;call the BIOS function through interrupt 15h
jc APM_error            ;if the carry flag is set there was an error
Run Code Online (Sandbox Code Playgroud)