stivale: Fix pagemap not mapping every memmap entry bug
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 40301f0b..00835233 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 8dbce093..f8687d24 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/protos/stivale.c b/stage2/protos/stivale.c
index 980a02d1..2b8697b0 100644
--- a/stage2/protos/stivale.c
+++ b/stage2/protos/stivale.c
@@ -182,13 +182,12 @@ void stivale_load(char *cmdline) {
stivale_struct.framebuffer_addr = (uint64_t)(size_t)fb32;
}
+ bool want_5lv = level5pg && (stivale_hdr.flags & (1 << 1));
+ pagemap_t pagemap = stivale_build_pagemap(want_5lv);
+
size_t memmap_entries;
struct e820_entry_t *memmap = get_memmap(&memmap_entries);
- bool want_5lv = level5pg && (stivale_hdr.flags & (1 << 1));
- pagemap_t pagemap = stivale_build_pagemap(want_5lv, memmap, memmap_entries);
-
- memmap = get_memmap(&memmap_entries);
stivale_struct.memory_map_entries = (uint64_t)memmap_entries;
stivale_struct.memory_map_addr = (uint64_t)(size_t)memmap;
@@ -196,8 +195,7 @@ void stivale_load(char *cmdline) {
entry_point, &stivale_struct, stivale_hdr.stack);
}
-pagemap_t stivale_build_pagemap(bool level5pg, struct e820_entry_t *memmap,
- size_t memmap_entries) {
+pagemap_t stivale_build_pagemap(bool level5pg) {
pagemap_t pagemap = new_pagemap(level5pg ? 5 : 4);
uint64_t higher_half_base = level5pg ? 0xff00000000000000 : 0xffff800000000000;
@@ -212,8 +210,13 @@ pagemap_t stivale_build_pagemap(bool level5pg, struct e820_entry_t *memmap,
map_page(pagemap, higher_half_base + i, i, 0x03);
}
+ size_t memmap_entries;
+ struct e820_entry_t *memmap = get_memmap(&memmap_entries);
+
// Map any other region of memory from the memmap
for (size_t i = 0; i < memmap_entries; i++) {
+ memmap = get_memmap(&memmap_entries);
+
uint64_t base = memmap[i].base;
uint64_t length = memmap[i].length;
uint64_t top = base + length;
diff --git a/stage2/protos/stivale.h b/stage2/protos/stivale.h
index d46ad6da..21822011 100644
--- a/stage2/protos/stivale.h
+++ b/stage2/protos/stivale.h
@@ -8,8 +8,7 @@
void stivale_load(char *cmdline);
-pagemap_t stivale_build_pagemap(bool level5pg, struct e820_entry_t *memmap,
- size_t memmap_entries);
+pagemap_t stivale_build_pagemap(bool level5pg);
__attribute__((noreturn)) void stivale_spinup(
int bits, bool level5pg, pagemap_t pagemap,
uint64_t entry_point, void *stivale_struct, uint64_t stack);
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index 61b2073c..04781fd9 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -275,22 +275,19 @@ void stivale2_load(char *cmdline) {
}
}
- size_t memmap_entries;
- struct e820_entry_t *memmap = get_memmap(&memmap_entries);
-
// Check if 5-level paging tag is requesting support
bool level5pg_requested = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_5LV_PAGING_ID) ? true : false;
pagemap_t pagemap = {0};
if (bits == 64)
- pagemap = stivale_build_pagemap(level5pg && level5pg_requested,
- memmap, memmap_entries);
+ pagemap = stivale_build_pagemap(level5pg && level5pg_requested);
//////////////////////////////////////////////
// Create memmap struct tag
//////////////////////////////////////////////
{
- memmap = get_memmap(&memmap_entries);
+ size_t memmap_entries;
+ struct e820_entry_t *memmap = get_memmap(&memmap_entries);
struct stivale2_struct_tag_memmap *tag =
conv_mem_alloc(sizeof(struct stivale2_struct_tag_memmap) +
