efi: Misc bug fixes
diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c
index f95f0352..39fdfc88 100644
--- a/stage23/mm/pmm.s2.c
+++ b/stage23/mm/pmm.s2.c
@@ -321,8 +321,8 @@ void init_memmap(void) {
allocations_disallowed = false;
- // Let's leave 64MiB to the firmware
- ext_mem_alloc_type(65536, MEMMAP_EFI_RECLAIMABLE);
+ // Let's leave 16MiB to the firmware
+ ext_mem_alloc_type(0x1000000, MEMMAP_EFI_RECLAIMABLE);
memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct e820_entry_t));
untouched_memmap_entries = memmap_entries;
@@ -453,6 +453,8 @@ void pmm_reclaim_uefi_mem(void) {
void pmm_release_uefi_mem(void) {
EFI_STATUS status;
+ sanitise_entries(memmap, &memmap_entries, true);
+
for (size_t i = 0; i < memmap_entries; i++) {
if (memmap[i].type != MEMMAP_USABLE
&& memmap[i].type != MEMMAP_BOOTLOADER_RECLAIMABLE) {
diff --git a/stage23/protos/chainload.c b/stage23/protos/chainload.c
index 58bba9b3..f03f2027 100644
--- a/stage23/protos/chainload.c
+++ b/stage23/protos/chainload.c
@@ -9,6 +9,7 @@
#include <lib/fb.h>
#include <lib/uri.h>
#include <lib/print.h>
+#include <lib/libc.h>
#include <sys/idt.h>
#include <drivers/vga_textmode.h>
#include <mm/pmm.h>
@@ -119,8 +120,14 @@ void chainload(char *config) {
if (!uri_open(image, image_path))
panic("chainload: Failed to open image with path `%s`. Is the path correct?", image_path);
- void *ptr = freadall(image, MEMMAP_RESERVED);
+ void *_ptr = freadall(image, MEMMAP_RESERVED);
size_t image_size = image->size;
+ void *ptr;
+ status = uefi_call_wrapper(gBS->AllocatePool, 3,
+ EfiLoaderData, image_size, &ptr);
+ if (status)
+ panic("chainload: Allocation failure");
+ memcpy(ptr, _ptr, image_size);
term_deinit();
diff --git a/test/stivale2.c b/test/stivale2.c
index 55d16755..eef221d9 100644
--- a/test/stivale2.c
+++ b/test/stivale2.c
@@ -86,10 +86,15 @@ void stivale2_main(struct stivale2_struct *info) {
struct stivale2_struct_tag_memmap *m = (struct stivale2_struct_tag_memmap *)tag;
e9_puts("Memmap tag:");
e9_printf("\tEntries: %d", m->entries);
+ size_t total_mem = 0;
for (size_t i = 0; i < m->entries; i++) {
struct stivale2_mmap_entry me = m->memmap[i];
e9_printf("\t\t[%x+%x] %x", me.base, me.length, me.type);
+ if (m->memmap[i].type == 1) {
+ total_mem += m->memmap[i].length;
+ }
}
+ e9_printf("\tTotal usable memory: %d", total_mem);
break;
}
case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID: {
