summaryrefslogtreecommitdiff
path: root/core/memmap.c
diff options
context:
space:
mode:
authorIan M. <ian@aptel.org>2026-09-11 05:40:51 +0000
committerIan M. <ian@aptel.org>2026-09-11 05:40:51 +0000
commit9bf419b4e0516ac23c3e49af0a10cb79ac1fd063 (patch)
tree2cf48d860bae74a613864134d391e041033c3c81 /core/memmap.c
parentd1ae146b1fcecdd6ae688cedf523a5be0d7980c5 (diff)
core: Get platform memory map and exit boot services
Signed-off-by: Ian M. <ian@aptel.org>
Diffstat (limited to 'core/memmap.c')
-rw-r--r--core/memmap.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/core/memmap.c b/core/memmap.c
new file mode 100644
index 0000000..f02e538
--- /dev/null
+++ b/core/memmap.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <sboot/memmap.h>
+
+EFI_STATUS
+SBootGetMemmap(OUT PLATFORM_MEMMAP *Map)
+{
+ EFI_STATUS Status;
+
+ if (Map == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Map->Map = NULL;
+ Map->MapSize = 0;
+ Map->MapKey = 0;
+ Map->DescriptorSize = 0;
+ Map->DescriptorVersion = 0;
+
+ Status = uefi_call_wrapper(
+ gBS->GetMemoryMap,
+ 5,
+ &Map->MapSize,
+ Map->Map,
+ &Map->MapKey,
+ &Map->DescriptorSize,
+ &Map->DescriptorVersion
+ );
+
+ Map->Map = AllocatePool(Map->MapSize);
+ if (Map->Map == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ /*
+ * We have to call this twice as the act of allocating memory
+ * alters the memory map.
+ */
+ for (UINTN Idx = 0; Idx < 2; ++Idx) {
+ Status = uefi_call_wrapper(
+ gBS->GetMemoryMap,
+ 5,
+ &Map->MapSize,
+ Map->Map,
+ &Map->MapKey,
+ &Map->DescriptorSize,
+ &Map->DescriptorVersion
+ );
+
+ if (!EFI_ERROR(Status)) {
+ break;
+ }
+ }
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: failed to get memory map\n");
+ }
+
+ return EFI_SUCCESS;
+}