diff --git a/kernel/arch/i686/PageTable.cpp b/kernel/arch/i686/PageTable.cpp index 4246e64f..d07285b9 100644 --- a/kernel/arch/i686/PageTable.cpp +++ b/kernel/arch/i686/PageTable.cpp @@ -231,26 +231,40 @@ namespace Kernel void PageTable::map_fast_page(paddr_t paddr) { - ASSERT(paddr && paddr % PAGE_SIZE == 0); - - 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())); + map_fast_page(0, paddr); } 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_lock.current_processor_has_lock()); - ASSERT((*s_fast_page_pt & Flags::Present)); - s_fast_page_pt[0] = 0; + ASSERT(!(s_fast_page_pt[index] & Flags::Present)); + s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present; - asm volatile("invlpg (%0)" :: "r"(fast_page())); + void* address = reinterpret_cast(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::create_userspace() diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index b02a93a3..3a526909 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -369,26 +369,40 @@ namespace Kernel void PageTable::map_fast_page(paddr_t paddr) { - ASSERT(paddr && paddr % PAGE_SIZE == 0); - - 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())); + map_fast_page(0, paddr); } 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_lock.current_processor_has_lock()); - ASSERT((*s_fast_page_pt & Flags::Present)); - s_fast_page_pt[0] = 0; + ASSERT(!(s_fast_page_pt[index] & Flags::Present)); + s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present; - asm volatile("invlpg (%0)" :: "r"(fast_page())); + void* address = reinterpret_cast(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::create_userspace() diff --git a/kernel/include/kernel/Memory/PageTable.h b/kernel/include/kernel/Memory/PageTable.h index 68629266..bf7f0825 100644 --- a/kernel/include/kernel/Memory/PageTable.h +++ b/kernel/include/kernel/Memory/PageTable.h @@ -149,6 +149,9 @@ namespace Kernel static void map_fast_page(paddr_t); static void unmap_fast_page(); + static void* map_fast_page(size_t index, paddr_t); + static void unmap_fast_page(size_t index); + private: paddr_t m_highest_paging_struct { 0 }; mutable RecursiveSpinLock m_lock;