Kernel: Add page table api to map multiple fast pages

This is not currently used, but can be handy in the future
This commit is contained in:
2026-05-03 00:55:06 +03:00
parent b8dc199738
commit 8091127150
3 changed files with 55 additions and 24 deletions

View File

@@ -231,26 +231,40 @@ namespace Kernel
void PageTable::map_fast_page(paddr_t paddr) void PageTable::map_fast_page(paddr_t paddr)
{ {
ASSERT(paddr && paddr % PAGE_SIZE == 0); map_fast_page(0, paddr);
ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT(!(*s_fast_page_pt & Flags::Present));
s_fast_page_pt[0] = paddr | Flags::ReadWrite | Flags::Present;
asm volatile("invlpg (%0)" :: "r"(fast_page()));
} }
void PageTable::unmap_fast_page() void PageTable::unmap_fast_page()
{ {
unmap_fast_page(0);
}
void* PageTable::map_fast_page(size_t index, paddr_t paddr)
{
ASSERT(paddr && paddr % PAGE_SIZE == 0);
ASSERT(index < 512);
ASSERT(s_fast_page_pt); ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock()); ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT((*s_fast_page_pt & Flags::Present)); ASSERT(!(s_fast_page_pt[index] & Flags::Present));
s_fast_page_pt[0] = 0; s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
asm volatile("invlpg (%0)" :: "r"(fast_page())); void* address = reinterpret_cast<void*>(fast_page() + index * PAGE_SIZE);
asm volatile("invlpg (%0)" :: "r"(address));
return address;
}
void PageTable::unmap_fast_page(size_t index)
{
ASSERT(index < 512);
ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT((s_fast_page_pt[index] & Flags::Present));
s_fast_page_pt[index] = 0;
asm volatile("invlpg (%0)" :: "r"(fast_page() + index * PAGE_SIZE));
} }
BAN::ErrorOr<PageTable*> PageTable::create_userspace() BAN::ErrorOr<PageTable*> PageTable::create_userspace()

View File

@@ -369,26 +369,40 @@ namespace Kernel
void PageTable::map_fast_page(paddr_t paddr) void PageTable::map_fast_page(paddr_t paddr)
{ {
ASSERT(paddr && paddr % PAGE_SIZE == 0); map_fast_page(0, paddr);
ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT(!(*s_fast_page_pt & Flags::Present));
s_fast_page_pt[0] = paddr | Flags::ReadWrite | Flags::Present;
asm volatile("invlpg (%0)" :: "r"(fast_page()));
} }
void PageTable::unmap_fast_page() void PageTable::unmap_fast_page()
{ {
unmap_fast_page(0);
}
void* PageTable::map_fast_page(size_t index, paddr_t paddr)
{
ASSERT(paddr && paddr % PAGE_SIZE == 0);
ASSERT(index < 512);
ASSERT(s_fast_page_pt); ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock()); ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT((*s_fast_page_pt & Flags::Present)); ASSERT(!(s_fast_page_pt[index] & Flags::Present));
s_fast_page_pt[0] = 0; s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
asm volatile("invlpg (%0)" :: "r"(fast_page())); void* address = reinterpret_cast<void*>(fast_page() + index * PAGE_SIZE);
asm volatile("invlpg (%0)" :: "r"(address));
return address;
}
void PageTable::unmap_fast_page(size_t index)
{
ASSERT(index < 512);
ASSERT(s_fast_page_pt);
ASSERT(s_fast_page_lock.current_processor_has_lock());
ASSERT((s_fast_page_pt[index] & Flags::Present));
s_fast_page_pt[index] = 0;
asm volatile("invlpg (%0)" :: "r"(fast_page() + index * PAGE_SIZE));
} }
BAN::ErrorOr<PageTable*> PageTable::create_userspace() BAN::ErrorOr<PageTable*> PageTable::create_userspace()

View File

@@ -149,6 +149,9 @@ namespace Kernel
static void map_fast_page(paddr_t); static void map_fast_page(paddr_t);
static void unmap_fast_page(); static void unmap_fast_page();
static void* map_fast_page(size_t index, paddr_t);
static void unmap_fast_page(size_t index);
private: private:
paddr_t m_highest_paging_struct { 0 }; paddr_t m_highest_paging_struct { 0 };
mutable RecursiveSpinLock m_lock; mutable RecursiveSpinLock m_lock;