apm_shutdown2.S 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* https://github.com/cirosantilli/x86-bare-metal-examples#apm */
  2. #include "common.h"
  3. BEGIN
  4. movb $0x53,%ah #this is an APM command
  5. movb $0x0,%al #installation check command
  6. xorw %bx,%bx #device id (0 = APM BIOS)
  7. int $0x15 #call the BIOS function through interrupt 15h
  8. jc APM_error #if the carry flag is set there was an error
  9. #the function was successful
  10. #AX = APM version number
  11. #AH = Major revision number (in BCD format)
  12. #AL = Minor revision number (also BCD format)
  13. #BX = ASCII characters "P" (in BH) and "M" (in BL)
  14. #CX = APM flags (see the official documentation for more details)
  15. #disconnect from any APM interface
  16. movb $0x53,%ah #this is an APM command
  17. movb $0x4,%al #interface disconnect command
  18. xorw %bx,%bx #device id (0 = APM BIOS)
  19. int $0x15 #call the BIOS function through interrupt 15h
  20. jc .disconnect_error #if the carry flag is set see what the fuss is about.
  21. jmp .no_error
  22. .disconnect_error: #the error code is in ah.
  23. cmpb $0x3,%ah #if the error code is anything but 03h there was an error.
  24. jne APM_error #the error code 03h means that no interface was connected in the first place.
  25. .no_error:
  26. #the function was successful
  27. #Nothing is returned.
  28. #connect to an APM interface
  29. movb $0x53,%ah #this is an APM command
  30. movb $0x01,%al #see above description
  31. xorw %bx,%bx #device id (0 = APM BIOS)
  32. int $0x15 #call the BIOS function through interrupt 15h
  33. jc APM_error #if the carry flag is set there was an error
  34. #the function was successful
  35. #The return values are different for each interface.
  36. #The Real Mode Interface returns nothing.
  37. #See the official documentation for the
  38. #return values for the protected mode interfaces.
  39. #Enable power management for all devices
  40. movb $0x53,%ah #this is an APM command
  41. movb $0x8,%al #Change the state of power management...
  42. movw $0x001,%bx #...on all devices to...
  43. movw $0x001,%cx #...power management on.
  44. int $0x15 #call the BIOS function through interrupt 15h
  45. jc APM_error #if the carry flag is set there was an error
  46. #Set the power state for all devices
  47. movb $0x53,%ah #this is an APM command
  48. movb $0x07,%al #Set the power state...
  49. movw $0x0001,%bx #...on all devices to...
  50. movw $0x0003,%cx #see above
  51. int $0x15 #call the BIOS function through interrupt 15h
  52. jc APM_error #if the carry flag is set there was an error
  53. APM_error:
  54. hlt