:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / hal / halx86 / pwroff.c
1 /* $Id$
2  *
3  * FILE       : reactos/hal/x86/apm.c
4  * DESCRIPTION: Turn CPU off...
5  * PROJECT    : ReactOS Operating System
6  * AUTHOR     : D. Lindauer (July 11 1997)
7  * NOTE       : This program is public domain
8  * REVISIONS  :
9  *      1999-12-26
10  */
11
12 #define APM_FUNCTION_AVAILABLE  0x5300
13 #define APM_FUNCTION_CONNREAL   0x5301
14 #define APM_FUNCTION_POWEROFF   0x5307
15 #define APM_FUNCTION_ENABLECPU  0x530d
16 #define APM_FUNCTION_ENABLEAPM  0x530e
17
18 #define APM_DEVICE_BIOS         0
19 #define APM_DEVICE_ALL          1
20
21 #define APM_MODE_DISABLE        0
22 #define APM_MODE_ENABLE         1
23
24
25
26 nopm    db      'No power management functionality',10,13,'$'
27 errmsg  db      'Power management error',10,13,'$'
28 wrongver db     'Need APM version 1.1 or better',10,13,'$'
29 ;
30 ; Entry point
31 ;
32 go:
33         mov     dx,offset nopm
34         jc      error
35         cmp     ax,101h                 ; See if version 1.1 or greater
36         mov     dx,offset wrongver
37         jc      error
38         
39         mov     [ver],ax
40         mov     ax,5301h                ; Do a real mode connection
41         mov     bx,0                    ; device = BIOS
42         int     15h
43         jnc     noconerr
44         
45         cmp     ah,2                    ; Pass if already connected
46         mov     dx,offset errmsg        ; else error
47         jnz     error
48 noconerr:
49         mov     ax,530eh                ; Enable latest version of APM
50         mov     bx,0                    ; device = BIOS
51         mov     cx,[ver]                ; version
52         int     15h
53         mov     dx,offset errmsg
54         jc      error
55         
56         mov     ax,530dh                ; Now engage and enable CPU management
57         mov     bx,1                    ; device = all
58         mov     cx,1                    ; enable
59         int     15h
60         mov     dx,offset errmsg
61         jc      error
62         
63         mov     ax,530fh
64         mov     bx,1                    ; device = ALL
65         mov     cx,1                    ; enable
66         int     15h
67         mov     dx,offset errmsg
68         jc      error
69
70         mov     dx,offset errmsg
71 error:
72         call    print
73         mov     ax,4c01h
74         int     21h
75         int 3
76         end start
77
78
79 BOOLEAN
80 ApmCall (
81         DWORD   Function,
82         DWORD   Device,
83         DWORD   Mode
84         )
85 {
86         /* AX <== Function */
87         /* BX <== Device */
88         /* CX <== Mode */
89         __asm__("int 21\n"); /* 0x15 */
90 }
91
92
93 BOOLEAN
94 HalPowerOff (VOID)
95 {
96         ApmCall (
97                 APM_FUNCTION_AVAILABLE,
98                 APM_DEVICE_BIOS,
99                 0
100                 );
101         ApmCall (
102                 APM_FUNCTION_ENABLEAPM,
103                 );
104         /* Shutdown CPU */
105         ApmCall (
106                 APM_FUNCTION_POWEROFF,
107                 APM_DEVICE_ALL,
108                 3
109                 );
110         return TRUE;
111 }
112
113
114 /* EOF */