Shutting down computer with nasm

青春壹個敷衍的年華 提交于 2019-12-20 07:26:43

问题


Is it possible to shut down or kill the power (is there a difference?) to a computer from nasm. I know you can use this to reboot:

mov al, 0xFE
out 0x64, al

Is there an equivalent for shutting down? I am making my own 16 bit OS.


回答1:


The code you have is not guaranteed to work. It relies on two facts:

  • the OS maps the physical IO memory into the process memory space.
  • the machine has BIOS.

Neither of the two might be true.

The only reliable way to reboot or shutdown the machine programatically is to call the corresponding OS API.

An alternative to calling the OS API (which you need, since you are writing the OS :-)) is using ACPI. Not all machines support ACPI an of these that do, there's at four different ACPI revisions.

http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface?wasRedirected=true
http://www.acpi.info




回答2:


    mov ax, 0x1000
    mov ax, ss
    mov sp, 0xf000
    mov ax, 0x5307
    mov bx, 0x0001
    mov cx, 0x0003
    int 0x15



回答3:


you can try this code:-

shutdown_sucess:
  mov ax, 5301h             ; Connect to the APM
  xor bx, bx
  int 15h
  je near continue_connection       ; Pass if connected
  cmp ah, 2
  je near continue_connection       ; Pass if already connected
  ret               ; Bail if fail

continue_connection:
  mov ax, 530Eh             ; Check APM Version
  xor bx, bx
  mov cx, 0102h             ; v1.2 Required
  int 15h
  ret       


来源:https://stackoverflow.com/questions/3463883/shutting-down-computer-with-nasm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!