paging: Some 1GiB pages adjustments

This commit is contained in:
mintsuki 2022-01-28 11:06:22 +01:00
parent 31736bea08
commit 091baf40a9
2 changed files with 13 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}