| 1 |
/* |
| 2 |
* GRUB -- GRand Unified Bootloader |
| 3 |
* Copyright (C) 2010 Free Software Foundation, Inc. |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <grub/machine/int.h> |
| 20 |
#include <grub/machine/apm.h> |
| 21 |
#include <grub/dl.h> |
| 22 |
#include <grub/command.h> |
| 23 |
#include <grub/i18n.h> |
| 24 |
|
| 25 |
GRUB_MOD_LICENSE ("GPLv3+"); |
| 26 |
|
| 27 |
int |
| 28 |
grub_apm_get_info (struct grub_apm_info *info) |
| 29 |
{ |
| 30 |
struct grub_bios_int_registers regs; |
| 31 |
|
| 32 |
/* detect APM */ |
| 33 |
regs.eax = 0x5300; |
| 34 |
regs.ebx = 0; |
| 35 |
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; |
| 36 |
grub_bios_interrupt (0x15, ®s); |
| 37 |
|
| 38 |
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) |
| 39 |
return 0; |
| 40 |
info->version = regs.eax & 0xffff; |
| 41 |
info->flags = regs.ecx & 0xffff; |
| 42 |
|
| 43 |
/* disconnect APM first */ |
| 44 |
regs.eax = 0x5304; |
| 45 |
regs.ebx = 0; |
| 46 |
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; |
| 47 |
grub_bios_interrupt (0x15, ®s); |
| 48 |
|
| 49 |
/* connect APM */ |
| 50 |
regs.eax = 0x5303; |
| 51 |
regs.ebx = 0; |
| 52 |
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; |
| 53 |
grub_bios_interrupt (0x15, ®s); |
| 54 |
|
| 55 |
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY) |
| 56 |
return 0; |
| 57 |
|
| 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; |
| 65 |
|
| 66 |
return 1; |
| 67 |
} |
| 68 |
|
| 69 |
static grub_err_t |
| 70 |
grub_cmd_lsapm (grub_command_t cmd __attribute__ ((unused)), |
| 71 |
int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) |
| 72 |
{ |
| 73 |
struct grub_apm_info info; |
| 74 |
if (!grub_apm_get_info (&info)) |
| 75 |
return grub_error (GRUB_ERR_IO, N_("no APM found")); |
| 76 |
|
| 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")); |
| 98 |
|
| 99 |
return GRUB_ERR_NONE; |
| 100 |
} |
| 101 |
|
| 102 |
static grub_command_t cmd; |
| 103 |
|
| 104 |
GRUB_MOD_INIT(lsapm) |
| 105 |
{ |
| 106 |
cmd = grub_register_command ("lsapm", grub_cmd_lsapm, 0, |
| 107 |
N_("Show APM information.")); |
| 108 |
} |
| 109 |
|
| 110 |
GRUB_MOD_FINI(lsapm) |
| 111 |
{ |
| 112 |
grub_unregister_command (cmd); |
| 113 |
} |
| 114 |
|
| 115 |
|