lsmmap.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. GRUB_MOD_LICENSE ("GPLv3+");
  24. static const char *names[] =
  25. {
  26. [GRUB_MEMORY_AVAILABLE] = "available",
  27. [GRUB_MEMORY_RESERVED] = "reserved",
  28. [GRUB_MEMORY_ACPI] = "ACPI reclamaible",
  29. [GRUB_MEMORY_NVS] = "NVS",
  30. [GRUB_MEMORY_BADRAM] = "BadRAM",
  31. [GRUB_MEMORY_CODE] = "firmware code",
  32. [GRUB_MEMORY_HOLE] = "hole"
  33. };
  34. static grub_err_t
  35. grub_cmd_lsmmap (grub_command_t cmd __attribute__ ((unused)),
  36. int argc __attribute__ ((unused)),
  37. char **args __attribute__ ((unused)))
  38. {
  39. auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_memory_type_t);
  40. int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size,
  41. grub_memory_type_t type)
  42. {
  43. if (type < ARRAY_SIZE (names) && names[type])
  44. grub_printf ("base_addr = 0x%llx, length = 0x%llx, %s\n",
  45. (long long) addr, (long long) size, names[type]);
  46. else
  47. grub_printf ("base_addr = 0x%llx, length = 0x%llx, type = 0x%x\n",
  48. (long long) addr, (long long) size, type);
  49. return 0;
  50. }
  51. #ifndef GRUB_MACHINE_EMU
  52. grub_machine_mmap_iterate (hook);
  53. #endif
  54. return 0;
  55. }
  56. static grub_command_t cmd;
  57. GRUB_MOD_INIT(lsmmap)
  58. {
  59. cmd = grub_register_command ("lsmmap", grub_cmd_lsmmap,
  60. 0, N_("List memory map provided by firmware."));
  61. }
  62. GRUB_MOD_FINI(lsmmap)
  63. {
  64. grub_unregister_command (cmd);
  65. }