From 41a331a8d34879afedb0c8850fa48a63b1e73bcb Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 1 Sep 2010 10:12:41 +0200 Subject: [PATCH] * grub-core/commands/efi/lsefimmap.c: New file. * grub-core/Makefile.core.def (lsefimmap): New module. * include/grub/efi/api.h (PRIxGRUB_EFI_UINTN_T): New definition. Also-By: Robert Millan Also-By: Vladimir Serbinenko --- ChangeLog.gingold3 | 7 ++ grub-core/Makefile.core.def | 8 ++ grub-core/commands/efi/lsefimmap.c | 143 +++++++++++++++++++++++++++++ include/grub/efi/api.h | 2 + 4 files changed, 160 insertions(+) create mode 100644 ChangeLog.gingold3 create mode 100644 grub-core/commands/efi/lsefimmap.c diff --git a/ChangeLog.gingold3 b/ChangeLog.gingold3 new file mode 100644 index 000000000..f8e69c3cd --- /dev/null +++ b/ChangeLog.gingold3 @@ -0,0 +1,7 @@ +2008-01-28 Tristan Gingold +2010-01-18 Robert Millan +2010-08-31 Vladimir Serbinenko + + * grub-core/commands/efi/lsefimmap.c: New file. + * grub-core/Makefile.core.def (lsefimmap): New module. + * include/grub/efi/api.h (PRIxGRUB_EFI_UINTN_T): New definition. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f9cf382f2..576490fbf 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -441,6 +441,14 @@ module = { enable = x86_efi; }; +module = { + name = lsefimmap; + + common = commands/efi/lsefimmap.c; + + enable = x86_efi; +}; + module = { name = blocklist; common = commands/blocklist.c; diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c new file mode 100644 index 000000000..010fc0d77 --- /dev/null +++ b/grub-core/commands/efi/lsefimmap.c @@ -0,0 +1,143 @@ +/* memmap.c - Display memory map. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ +#include +#include +#include +#include +#include +#include + +#define ADD_MEMORY_DESCRIPTOR(desc, size) \ + ((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size))) + +static grub_err_t +grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) +{ + grub_efi_uintn_t map_size; + grub_efi_memory_descriptor_t *memory_map; + grub_efi_memory_descriptor_t *memory_map_end; + grub_efi_memory_descriptor_t *desc; + grub_efi_uintn_t desc_size; + + map_size = 0; + if (grub_efi_get_memory_map (&map_size, NULL, NULL, &desc_size, 0) < 0) + return 0; + + memory_map = grub_malloc (map_size); + if (memory_map == NULL) + return grub_errno; + if (grub_efi_get_memory_map (&map_size, memory_map, NULL, &desc_size, 0) <= 0) + goto fail; + + grub_printf + ("Type Physical start - end #Pages " + " Size Attributes\n"); + memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size); + for (desc = memory_map; + desc < memory_map_end; + desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size)) + { + grub_efi_uint64_t size; + grub_efi_uint64_t attr; + static const char types_str[][9] = + { + "reserved", + "ldr-code", + "ldr-data", + "BS-code ", + "BS-data ", + "RT-code ", + "RT-data ", + "conv-mem", + "unusable", + "ACPI-rec", + "ACPI-nvs", + "MMIO ", + "IO-ports", + "PAL-code" + }; + if (desc->type < ARRAY_SIZE (types_str)) + grub_printf ("%s ", types_str[desc->type]); + else + grub_printf ("Unk %02x ", desc->type); + + grub_printf (" %016" PRIxGRUB_UINT64_T "-%016" PRIxGRUB_UINT64_T + " %08" PRIxGRUB_EFI_UINTN_T, + desc->physical_start, + desc->physical_start + (desc->num_pages << 12) - 1, + desc->num_pages); + + size = desc->num_pages; + size <<= (12 - 10); + if (size < 1024) + grub_printf (" %4" PRIuGRUB_UINT64_T "KB", size); + else + { + size /= 1024; + if (size < 1024) + grub_printf (" %4" PRIuGRUB_UINT64_T "MB", size); + else + { + size /= 1024; + grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size); + } + } + + attr = desc->attribute; + if (attr & GRUB_EFI_MEMORY_RUNTIME) + grub_printf (" RT"); + if (attr & GRUB_EFI_MEMORY_UC) + grub_printf (" UC"); + if (attr & GRUB_EFI_MEMORY_WC) + grub_printf (" WC"); + if (attr & GRUB_EFI_MEMORY_WT) + grub_printf (" WT"); + if (attr & GRUB_EFI_MEMORY_WB) + grub_printf (" WB"); + if (attr & GRUB_EFI_MEMORY_UCE) + grub_printf (" UCE"); + if (attr & GRUB_EFI_MEMORY_WP) + grub_printf (" WP"); + if (attr & GRUB_EFI_MEMORY_RP) + grub_printf (" RP"); + if (attr & GRUB_EFI_MEMORY_XP) + grub_printf (" XP"); + + grub_printf ("\n"); + } + + fail: + grub_free (memory_map); + return 0; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(lsefimmap) +{ + cmd = grub_register_command ("lsefimmap", grub_cmd_lsefimmap, + "", "Display EFI memory map."); +} + +GRUB_MOD_FINI(lsefimmap) +{ + grub_unregister_command (cmd); +} diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 5eededdc2..cb6b1113b 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -287,6 +287,8 @@ typedef grub_uint64_t grub_efi_uint64_t; typedef grub_uint8_t grub_efi_char8_t; typedef grub_uint16_t grub_efi_char16_t; +#define PRIxGRUB_EFI_UINTN_T "lx" + typedef grub_efi_intn_t grub_efi_status_t; #define GRUB_EFI_ERROR_CODE(value) \