mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
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:
parent
1f30a5e4d9
commit
1d58663298
2 changed files with 27 additions and 10 deletions
|
@ -19,30 +19,42 @@
|
||||||
|
|
||||||
namespace Kernel::Memory {
|
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()
|
LockRefPtr<PageDirectory> PageDirectory::find_current()
|
||||||
{
|
{
|
||||||
TODO_AARCH64();
|
return s_ttbr0_map->map.with([&](auto& map) {
|
||||||
return nullptr;
|
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()
|
UNMAP_AFTER_INIT NonnullLockRefPtr<PageDirectory> PageDirectory::must_create_kernel_page_directory()
|
||||||
|
|
|
@ -409,6 +409,11 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread)
|
||||||
|
|
||||||
Processor::set_current_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());
|
to_thread->set_cpu(Processor::current().id());
|
||||||
|
|
||||||
auto in_critical = to_thread->saved_critical();
|
auto in_critical = to_thread->saved_critical();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue