2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010 Free Software Foundation, Inc.
5 * GRUB 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, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/machine/int.h>
20 #include <grub/machine/apm.h>
22 #include <grub/command.h>
23 #include <grub/i18n.h>
25 GRUB_MOD_LICENSE ("GPLv3+");
28 grub_apm_get_info (struct grub_apm_info
*info
)
30 struct grub_bios_int_registers regs
;
35 regs
.flags
= GRUB_CPU_INT_FLAGS_DEFAULT
;
36 grub_bios_interrupt (0x15, ®s
);
38 if (regs
.flags
& GRUB_CPU_INT_FLAGS_CARRY
)
40 info
->version
= regs
.eax
& 0xffff;
41 info
->flags
= regs
.ecx
& 0xffff;
43 /* disconnect APM first */
46 regs
.flags
= GRUB_CPU_INT_FLAGS_DEFAULT
;
47 grub_bios_interrupt (0x15, ®s
);
52 regs
.flags
= GRUB_CPU_INT_FLAGS_DEFAULT
;
53 grub_bios_interrupt (0x15, ®s
);
55 if (regs
.flags
& GRUB_CPU_INT_FLAGS_CARRY
)
58 info
->cseg
= regs
.eax
& 0xffff;
59 info
->offset
= regs
.ebx
;
60 info
->cseg_16
= regs
.ecx
& 0xffff;
61 info
->dseg
= regs
.edx
& 0xffff;
62 info
->cseg_len
= regs
.esi
>> 16;
63 info
->cseg_16_len
= regs
.esi
& 0xffff;
64 info
->dseg_len
= regs
.edi
;
70 grub_cmd_lsapm (grub_command_t cmd
__attribute__ ((unused
)),
71 int argc
__attribute__ ((unused
)), char **args
__attribute__ ((unused
)))
73 struct grub_apm_info info
;
74 if (!grub_apm_get_info (&info
))
75 return grub_error (GRUB_ERR_IO
, N_("no APM found"));
77 grub_printf_ (N_("Version %u.%u\n"
78 "32-bit CS = 0x%x, len = 0x%x, offset = 0x%x\n"
79 "16-bit CS = 0x%x, len = 0x%x\n"
80 "DS = 0x%x, len = 0x%x\n"),
81 info
.version
>> 8, info
.version
& 0xff,
82 info
.cseg
, info
.cseg_len
, info
.offset
,
83 info
.cseg_16
, info
.cseg_16_len
,
84 info
.dseg
, info
.dseg_len
);
85 grub_xputs (info
.flags
& GRUB_APM_FLAGS_16BITPROTECTED_SUPPORTED
86 ? _("16-bit protected interface supported\n")
87 : _("16-bit protected interface unsupported\n"));
88 grub_xputs (info
.flags
& GRUB_APM_FLAGS_32BITPROTECTED_SUPPORTED
89 ? _("32-bit protected interface supported\n")
90 : _("32-bit protected interface unsupported\n"));
91 grub_xputs (info
.flags
& GRUB_APM_FLAGS_CPUIDLE_SLOWS_DOWN
92 ? _("CPU Idle slows down processor\n")
93 : _("CPU Idle doesn't slow down processor\n"));
94 grub_xputs (info
.flags
& GRUB_APM_FLAGS_DISABLED
95 ? _("APM disabled\n") : _("APM enabled\n"));
96 grub_xputs (info
.flags
& GRUB_APM_FLAGS_DISENGAGED
97 ? _("APM disengaged\n") : _("APM engaged\n"));
102 static grub_command_t cmd
;
106 cmd
= grub_register_command ("lsapm", grub_cmd_lsapm
, 0,
107 N_("Show APM information."));
112 grub_unregister_command (cmd
);