Adding upstream version 6.02~pre8+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / poweroff.c
blob8b656ad42f776754ca5be1a10a42ddd3ff430e91
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2013 Sebastian Herbszt - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
14 * poweroff.c
16 * APM poweroff module
19 #include <stdio.h>
20 #include <string.h>
21 #include <com32.h>
23 int main()
25 com32sys_t inregs, outregs;
27 memset(&inregs, 0, sizeof inregs);
29 inregs.eax.l = 0x5300; /* APM Installation Check (00h) */
30 inregs.ebx.l = 0; /* APM BIOS (0000h) */
31 __intcall(0x15, &inregs, &outregs);
33 if (outregs.eflags.l & EFLAGS_CF) {
34 printf("APM not present.\n");
35 return 1;
38 if ((outregs.ebx.l & 0xffff) != 0x504d) { /* signature 'PM' */
39 printf("APM not present.\n");
40 return 1;
43 if ((outregs.eax.l & 0xffff) < 0x101) { /* Need version 1.1+ */
44 printf("APM 1.1+ not supported.\n");
45 return 1;
48 if ((outregs.ecx.l & 0x8) == 0x8) { /* bit 3 APM BIOS Power Management disabled */
49 printf("Power management disabled.\n");
50 return 1;
53 inregs.eax.l = 0x5301; /* APM Real Mode Interface Connect (01h) */
54 inregs.ebx.l = 0; /* APM BIOS (0000h) */
55 __intcall(0x15, &inregs, &outregs);
57 if (outregs.eflags.l & EFLAGS_CF) {
58 printf("APM RM interface connect failed.\n");
59 return 1;
62 inregs.eax.l = 0x530e; /* APM Driver Version (0Eh) */
63 inregs.ebx.l = 0; /* APM BIOS (0000h) */
64 inregs.ecx.l = 0x101; /* APM Driver version 1.1 */
65 __intcall(0x15, &inregs, &outregs);
67 if (outregs.eflags.l & EFLAGS_CF) {
68 printf("APM 1.1+ not supported.\n");
69 return 1;
72 if ((outregs.ecx.l & 0xffff) < 0x101) { /* APM Connection version */
73 printf("APM 1.1+ not supported.\n");
74 return 1;
77 inregs.eax.l = 0x5307; /* Set Power State (07h) */
78 inregs.ebx.l = 1; /* All devices power managed by the APM BIOS */
79 inregs.ecx.l = 3; /* Power state off */
80 __intcall(0x15, &inregs, &outregs);
82 if (outregs.eflags.l & EFLAGS_CF) {
83 printf("Power off failed.\n");
84 return 1;
87 return 0;