Kernel/aarch64: Implement switching page directories

The code in PageDirectory.cpp now keeps track of the registered page
directories, and actually sets the TTBR0_EL1 to the page table base of
the currently executing thread. When context switching, we now also
change the TTBR0_EL1 to the page table base of the thread that we
context switch into.
This commit is contained in:
Timon Kruiper 2023-01-24 19:31:25 +01:00 committed by Andreas Kling
parent 1f30a5e4d9
commit 1d58663298
Notes: sideshowbarker 2024-07-17 01:09:41 +09:00
2 changed files with 27 additions and 10 deletions

View file

@ -19,30 +19,42 @@
namespace Kernel::Memory {
void PageDirectory::register_page_directory(PageDirectory*)
struct TTBR0Map {
SpinlockProtected<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>, LockRank::None> map {};
};
static Singleton<TTBR0Map> s_ttbr0_map;
void PageDirectory::register_page_directory(PageDirectory* directory)
{
dbgln("FIXME: PageDirectory: Actually implement registering a page directory!");
s_ttbr0_map->map.with([&](auto& map) {
map.insert(directory->ttbr0(), *directory);
});
}
void PageDirectory::deregister_page_directory(PageDirectory*)
void PageDirectory::deregister_page_directory(PageDirectory* directory)
{
TODO_AARCH64();
s_ttbr0_map->map.with([&](auto& map) {
map.remove(directory->ttbr0());
});
}
LockRefPtr<PageDirectory> PageDirectory::find_current()
{
TODO_AARCH64();
return nullptr;
return s_ttbr0_map->map.with([&](auto& map) {
return map.find(Aarch64::Asm::get_ttbr0_el1());
});
}
void activate_kernel_page_directory(PageDirectory const&)
void activate_kernel_page_directory(PageDirectory const& page_directory)
{
dbgln("FIXME: PageDirectory: Actually implement activating a kernel page directory!");
Aarch64::Asm::set_ttbr0_el1(page_directory.ttbr0());
}
void activate_page_directory(PageDirectory const&, Thread*)
void activate_page_directory(PageDirectory const& page_directory, Thread* current_thread)
{
TODO_AARCH64();
current_thread->regs().ttbr0_el1 = page_directory.ttbr0();
Aarch64::Asm::set_ttbr0_el1(page_directory.ttbr0());
}
UNMAP_AFTER_INIT NonnullLockRefPtr<PageDirectory> PageDirectory::must_create_kernel_page_directory()

View file

@ -409,6 +409,11 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
Processor::set_current_thread(*to_thread);
auto& from_regs = from_thread->regs();
auto& to_regs = to_thread->regs();
if (from_regs.ttbr0_el1 != to_regs.ttbr0_el1)
Aarch64::Asm::set_ttbr0_el1(to_regs.ttbr0_el1);
to_thread->set_cpu(Processor::current().id());
auto in_critical = to_thread->saved_critical();