-
Notifications
You must be signed in to change notification settings - Fork 406
/
apm_shutdown2.S
64 lines (54 loc) · 2.85 KB
/
apm_shutdown2.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* https://github.com/cirosantilli/x86-bare-metal-examples#apm */
#include "common.h"
BEGIN
movb $0x53,%ah #this is an APM command
movb $0x0,%al #installation check command
xorw %bx,%bx #device id (0 = APM BIOS)
int $0x15 #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)
#disconnect from any APM interface
movb $0x53,%ah #this is an APM command
movb $0x4,%al #interface disconnect command
xorw %bx,%bx #device id (0 = APM BIOS)
int $0x15 #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.
cmpb $0x3,%ah #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.
#connect to an APM interface
movb $0x53,%ah #this is an APM command
movb $0x01,%al #see above description
xorw %bx,%bx #device id (0 = APM BIOS)
int $0x15 #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.
#Enable power management for all devices
movb $0x53,%ah #this is an APM command
movb $0x8,%al #Change the state of power management...
movw $0x001,%bx #...on all devices to...
movw $0x001,%cx #...power management on.
int $0x15 #call the BIOS function through interrupt 15h
jc APM_error #if the carry flag is set there was an error
#Set the power state for all devices
movb $0x53,%ah #this is an APM command
movb $0x07,%al #Set the power state...
movw $0x0001,%bx #...on all devices to...
movw $0x0003,%cx #see above
int $0x15 #call the BIOS function through interrupt 15h
jc APM_error #if the carry flag is set there was an error
APM_error:
hlt