lsmmap.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2008 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/dl.h>
  19. #include <grub/misc.h>
  20. #include <grub/command.h>
  21. #include <grub/i18n.h>
  22. #include <grub/memory.h>
  23. #include <grub/mm.h>
  24. GRUB_MOD_LICENSE ("GPLv3+");
  25. #ifndef GRUB_MACHINE_EMU
  26. static const char *names[] =
  27. {
  28. [GRUB_MEMORY_AVAILABLE] = N_("available RAM"),
  29. [GRUB_MEMORY_RESERVED] = N_("reserved RAM"),
  30. /* TRANSLATORS: this refers to memory where ACPI tables are stored
  31. and which can be used by OS once it loads ACPI tables. */
  32. [GRUB_MEMORY_ACPI] = N_("ACPI reclaimable RAM"),
  33. /* TRANSLATORS: this refers to memory which ACPI-compliant OS
  34. is required to save accross hibernations. */
  35. [GRUB_MEMORY_NVS] = N_("ACPI non-volatile storage RAM"),
  36. [GRUB_MEMORY_BADRAM] = N_("faulty RAM (BadRAM)"),
  37. [GRUB_MEMORY_PERSISTENT] = N_("persistent RAM"),
  38. [GRUB_MEMORY_PERSISTENT_LEGACY] = N_("persistent RAM (legacy)"),
  39. [GRUB_MEMORY_COREBOOT_TABLES] = N_("RAM holding coreboot tables"),
  40. [GRUB_MEMORY_CODE] = N_("RAM holding firmware code")
  41. };
  42. /* Helper for grub_cmd_lsmmap. */
  43. static int
  44. lsmmap_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
  45. void *data __attribute__ ((unused)))
  46. {
  47. if (type < (int) ARRAY_SIZE (names) && type >= 0 && names[type])
  48. grub_printf_ (N_("base_addr = 0x%llx, length = 0x%llx, %s\n"),
  49. (long long) addr, (long long) size, _(names[type]));
  50. else
  51. grub_printf_ (N_("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n"),
  52. (long long) addr, (long long) size, type);
  53. return 0;
  54. }
  55. #endif
  56. static grub_err_t
  57. grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)),
  58. int argc __attribute__ ((unused)),
  59. char **args __attribute__ ((unused)))
  60. {
  61. #ifndef GRUB_MACHINE_EMU
  62. grub_machine_mmap_iterate (lsmmap_hook, NULL);
  63. #endif
  64. return 0;
  65. }
  66. static grub_command_t cmd;
  67. GRUB_MOD_INIT(lsmmap)
  68. {
  69. cmd = grub_register_command ("lsmmap", grub_cmd_lsmmap,
  70. 0, N_("List memory map provided by firmware."));
  71. }
  72. GRUB_MOD_FINI(lsmmap)
  73. {
  74. grub_unregister_command (cmd);
  75. }