paging: Some 1GiB pages adjustments
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index a0440b27..15df9f0e 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -427,7 +427,7 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
//
// start = 0x200000
// end = 0x40000000
- //
+ //
// pages_required = (end - start) / (4096 * 512 * 512)
//
// So we map 2MiB to 1GiB with 2MiB pages and then map the rest
@@ -460,14 +460,14 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null, struct elf_range
if (base >= top)
continue;
- uint64_t aligned_base = ALIGN_DOWN(base, 0x200000);
- uint64_t aligned_top = ALIGN_UP(top, 0x200000);
+ uint64_t aligned_base = ALIGN_DOWN(base, 0x40000000);
+ uint64_t aligned_top = ALIGN_UP(top, 0x40000000);
uint64_t aligned_length = aligned_top - aligned_base;
- for (uint64_t j = 0; j < aligned_length; j += 0x200000) {
+ for (uint64_t j = 0; j < aligned_length; j += 0x40000000) {
uint64_t page = aligned_base + j;
- map_page(pagemap, page, page, 0x03, Size2MiB);
- map_page(pagemap, direct_map_offset + page, page, 0x03, Size2MiB);
+ map_page(pagemap, page, page, 0x03, Size1GiB);
+ map_page(pagemap, direct_map_offset + page, page, 0x03, Size1GiB);
}
}
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 13d8853e..ebd8334e 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -243,7 +243,13 @@ failed_to_load_header_section:
panic(true, "stivale2: Requested HHDM slide alignment is not a multiple of 2MiB");
}
- direct_map_offset += (rand64() & ~(slt->alignment - 1)) & 0xffffffffff;
+ // XXX: Assert that slt->alignment is not larger than 1GiB and ignore the value altogether.
+ // This is required for 1GiB pages.
+ if (((uint64_t)0x40000000 % slt->alignment) != 0) {
+ panic(true, "stivale2: 1 GiB is not a multiple of HHDM slide alignment");
+ }
+
+ direct_map_offset += (rand64() & ~((uint64_t)0x40000000 - 1)) & 0xfffffffffff;
}
}
