lsapm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include <grub/machine/int.h>
  19. #include <grub/machine/apm.h>
  20. #include <grub/dl.h>
  21. #include <grub/command.h>
  22. #include <grub/i18n.h>
  23. GRUB_MOD_LICENSE ("GPLv3+");
  24. int
  25. grub_apm_get_info (struct grub_apm_info *info)
  26. {
  27. struct grub_bios_int_registers regs;
  28. /* detect APM */
  29. regs.eax = 0x5300;
  30. regs.ebx = 0;
  31. regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
  32. grub_bios_interrupt (0x15, &regs);
  33. if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
  34. return 0;
  35. info->version = regs.eax & 0xffff;
  36. info->flags = regs.ecx & 0xffff;
  37. /* disconnect APM first */
  38. regs.eax = 0x5304;
  39. regs.ebx = 0;
  40. regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
  41. grub_bios_interrupt (0x15, &regs);
  42. /* connect APM */
  43. regs.eax = 0x5303;
  44. regs.ebx = 0;
  45. regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
  46. grub_bios_interrupt (0x15, &regs);
  47. if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
  48. return 0;
  49. info->cseg = regs.eax & 0xffff;
  50. info->offset = regs.ebx;
  51. info->cseg_16 = regs.ecx & 0xffff;
  52. info->dseg = regs.edx & 0xffff;
  53. info->cseg_len = regs.esi >> 16;
  54. info->cseg_16_len = regs.esi & 0xffff;
  55. info->dseg_len = regs.edi;
  56. return 1;
  57. }
  58. static grub_err_t
  59. grub_cmd_lsapm (grub_command_t cmd __attribute__ ((unused)),
  60. int argc __attribute__ ((unused)), char **args __attribute__ ((unused)))
  61. {
  62. struct grub_apm_info info;
  63. if (!grub_apm_get_info (&info))
  64. return grub_error (GRUB_ERR_IO, N_("no APM found"));
  65. grub_printf_ (N_("Version %u.%u\n"
  66. "32-bit CS = 0x%x, len = 0x%x, offset = 0x%x\n"
  67. "16-bit CS = 0x%x, len = 0x%x\n"
  68. "DS = 0x%x, len = 0x%x\n"),
  69. info.version >> 8, info.version & 0xff,
  70. info.cseg, info.cseg_len, info.offset,
  71. info.cseg_16, info.cseg_16_len,
  72. info.dseg, info.dseg_len);
  73. grub_xputs (info.flags & GRUB_APM_FLAGS_16BITPROTECTED_SUPPORTED
  74. ? _("16-bit protected interface supported\n")
  75. : _("16-bit protected interface unsupported\n"));
  76. grub_xputs (info.flags & GRUB_APM_FLAGS_32BITPROTECTED_SUPPORTED
  77. ? _("32-bit protected interface supported\n")
  78. : _("32-bit protected interface unsupported\n"));
  79. grub_xputs (info.flags & GRUB_APM_FLAGS_CPUIDLE_SLOWS_DOWN
  80. ? _("CPU Idle slows down processor\n")
  81. : _("CPU Idle doesn't slow down processor\n"));
  82. grub_xputs (info.flags & GRUB_APM_FLAGS_DISABLED
  83. ? _("APM disabled\n") : _("APM enabled\n"));
  84. grub_xputs (info.flags & GRUB_APM_FLAGS_DISENGAGED
  85. ? _("APM disengaged\n") : _("APM engaged\n"));
  86. return GRUB_ERR_NONE;
  87. }
  88. static grub_command_t cmd;
  89. GRUB_MOD_INIT(lsapm)
  90. {
  91. cmd = grub_register_command ("lsapm", grub_cmd_lsapm, 0,
  92. N_("Show APM information."));
  93. }
  94. GRUB_MOD_FINI(lsapm)
  95. {
  96. grub_unregister_command (cmd);
  97. }