Run Nindent on com32/libutil/ansiline.c
[profile/ivi/syslinux.git] / modules / poweroff.asm
1 ; ****************************************************************************
2 ;
3 ;  poweroff.asm
4 ;
5 ;   Copyright 2009 Sebastian Herbszt
6 ;
7 ;  APM poweroff module.
8 ;
9 ;  This program is free software; you can redistribute it and/or modify
10 ;  it under the terms of the GNU General Public License as published by
11 ;  the Free Software Foundation, Inc., 53 Temple Place Ste 330,
12 ;  Boston MA 02111-1307, USA; either version 2 of the License, or
13 ;  (at your option) any later version; incorporated herein by reference.
14 ;
15 ; ****************************************************************************
16
17                 absolute 0
18 pspInt20:       resw 1
19 pspNextP:       resw 1
20                 resb 124
21 pspCmdLen:      resb 1
22 pspCmdArg:      resb 127
23
24                 section .text
25                 org     0x100
26
27 _start:
28                 mov ax,5300h    ; APM Installation Check (00h)
29                 xor bx,bx       ; APM BIOS (0000h)
30                 int 15h
31                 jnc check_sig
32
33                 mov bx, msg_notpresent
34                 jmp error
35
36 check_sig:
37                 cmp bx,504Dh    ; signature 'PM'
38                 je check_ver
39
40                 mov bx, msg_notpresent
41                 jmp error
42
43 check_ver:
44                 cmp ax,0101h    ; Need version 1.1+
45                 jae check_state
46
47                 mov bx, msg_notsup
48                 jmp error
49
50 check_state:
51                 test cx,8       ; bit 3 APM BIOS Power Management disabled
52                 jz connect
53
54                 mov bx, msg_pmdisabled
55                 jmp error
56
57 connect:
58                 mov ax,5301h    ; APM Real Mode Interface Connect (01h)
59                 xor bx,bx       ; APM BIOS (0000h)
60                 int 15h
61                 jnc connect_ok
62
63                 mov bx, msg_connect
64                 jmp error
65
66 connect_ok:
67                 mov ax,530Eh    ; APM Driver Version (0Eh)
68                 xor bx,bx       ; APM BIOS (0000h)
69                 mov cx,0101h    ; APM Driver version 1.1
70                 int 15h
71                 jnc apm0101_check
72
73                 mov bx, msg_notsup
74                 jmp error
75
76 apm0101_check:
77                 cmp cx,0101h    ; APM Connection version
78                 jae apm0101_ok
79
80                 mov bx, msg_notsup
81                 jmp error
82
83 apm0101_ok:
84                 mov ax,5307h    ; Set Power State (07h)
85                 mov bx,0001h    ; All devices power managed by the APM BIOS
86                 mov cx,0003h    ; Power state off
87                 int 15h
88                 jnc off
89
90                 mov bx, msg_failed
91
92 error:
93                 mov ax,2
94                 int 22h
95 off:
96                 ret
97
98 msg_notpresent: db 'APM not present.',0dh,0ah,0
99 msg_notsup:     db 'APM 1.1+ not supported.',0dh,0ah,0
100 msg_pmdisabled: db 'Power management disabled.',0dh,0ah,0
101 msg_connect:    db 'APM RM interface connect failed.',0dh,0ah,0
102 msg_failed:     db 'Power off failed.',0dh,0ah,0