From c0002a79e77908016731c2a1f6ddba7ca29a1df7 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Thu, 21 Apr 2016 13:04:28 +1200 Subject: [PATCH] EFI: Implement heap --- src/system/boot/platform/efi/heap.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/system/boot/platform/efi/heap.cpp b/src/system/boot/platform/efi/heap.cpp index 282dab2d3d..ade11ed003 100644 --- a/src/system/boot/platform/efi/heap.cpp +++ b/src/system/boot/platform/efi/heap.cpp @@ -7,16 +7,34 @@ #include #include +#include "efi_platform.h" + + +#define STAGE_PAGES 0x2000 /* 32 MB */ + + +static EFI_PHYSICAL_ADDRESS staging; + extern "C" void platform_release_heap(struct stage2_args *args, void *base) { - return; + if ((void*)staging != base) + panic("Attempt to release heap with wrong base address!"); + + kBootServices->FreePages(staging, STAGE_PAGES); } extern "C" status_t platform_init_heap(struct stage2_args *args, void **_base, void **_top) { - return B_ERROR; + if (kBootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, + STAGE_PAGES, &staging) != EFI_SUCCESS) + return B_NO_MEMORY; + + *_base = (void*)staging; + *_top = (void*)((int8*)staging + STAGE_PAGES * PAGE_SIZE); + + return B_OK; }