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

时间:2014-01-30 17:51:56

标签: assembly x86 dos

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

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

1 个答案:

答案 0 :(得分:8)

从OSDev上的this文章中,您可以使用ACPI或APM界面。 ACPI似乎过于复杂,正如您在this article中看到的那样,而APM更简单。我会报告here出现的基本步骤:

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)

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.

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.

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

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