2014-01-30 45 views
9

實模式中是否有x86指令序列會關閉(不重新啓動)機器?我還有一臺裝有MS-DOS的舊電腦,我對此很好奇。X86指令在實模式下關閉計算機?

這個問題具體是關於實模式,而不是保護模式或64位長模式。

+2

我認爲這個問題可以幫助你:http://stackoverflow.com/questions/3145569/how-to-power-down-the-computer-from-a-freestanding-environment –

回答

7

this有關OSDev的文章,您可以使用ACPI或APM接口。 ACPI似乎過於複雜,您可以在this article中看到,而APM更簡單。

1)安裝檢查,看看是否支持APM:因爲它們出現here我會報告的基本步驟

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 
+0

在QEMU 2.0.0上測試Ubuntu 14.04:https://github.com/cirosantilli/x86-bare-metal-examples/blob/ 7cff2a3fc93a636f8e253892af212a30c5a58697/apm_shutdown2.S –

+0

那麼當最後的int15h返回成功時你怎麼做? – Joshua