mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-02 16:25:34 +03:00
Kernel: Make MemoryManager compile on aarch64
This commit is contained in:
parent
6299a69253
commit
d79c772c87
Notes:
sideshowbarker
2024-07-17 14:35:27 +09:00
Author: https://github.com/jamesmintram Commit: https://github.com/SerenityOS/serenity/commit/d79c772c87 Pull-request: https://github.com/SerenityOS/serenity/pull/13447
@ -4,6 +4,8 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Forward.h>
|
||||
|
||||
#include <Kernel/Arch/CPU.h>
|
||||
#include <Kernel/Arch/RegisterState.h>
|
||||
|
||||
|
33
Kernel/Arch/aarch64/PageDirectory.cpp
Normal file
33
Kernel/Arch/aarch64/PageDirectory.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, James Mintram <me@jamesrm.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Memory/PageDirectory.h>
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
void PageDirectory::register_page_directory(PageDirectory*)
|
||||
{
|
||||
}
|
||||
|
||||
void PageDirectory::deregister_page_directory(PageDirectory*)
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<PageDirectory> PageDirectory::find_current()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void activate_kernel_page_directory(PageDirectory const&)
|
||||
{
|
||||
}
|
||||
|
||||
void activate_page_directory(PageDirectory const&, Thread*)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -13,8 +13,14 @@
|
||||
|
||||
#include <Kernel/Arch/ProcessorSpecificDataID.h>
|
||||
|
||||
class VirtualAddress;
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
namespace Memory {
|
||||
class PageDirectory;
|
||||
};
|
||||
|
||||
class Thread;
|
||||
|
||||
// FIXME This needs to go behind some sort of platform abstraction
|
||||
@ -41,6 +47,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE static void flush_tlb_local(VirtualAddress&, size_t&)
|
||||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE static void flush_tlb(Memory::PageDirectory const*, VirtualAddress const&, size_t)
|
||||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE static u32 current_id()
|
||||
{
|
||||
return 0;
|
||||
|
@ -9,6 +9,8 @@
|
||||
namespace Kernel {
|
||||
|
||||
struct RegisterState {
|
||||
FlatPtr userspace_sp() const { return 0; }
|
||||
FlatPtr ip() const { return 0; }
|
||||
};
|
||||
|
||||
struct DebugRegisterState {
|
||||
|
50
Kernel/Arch/x86/common/PageDirectory.cpp
Normal file
50
Kernel/Arch/x86/common/PageDirectory.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, James Mintram <me@jamesrm.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Singleton.h>
|
||||
|
||||
#include <Kernel/Memory/PageDirectory.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
static Singleton<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>> s_cr3_map;
|
||||
|
||||
static IntrusiveRedBlackTree<&PageDirectory::m_tree_node>& cr3_map()
|
||||
{
|
||||
VERIFY_INTERRUPTS_DISABLED();
|
||||
return *s_cr3_map;
|
||||
}
|
||||
|
||||
void PageDirectory::register_page_directory(PageDirectory* directory)
|
||||
{
|
||||
cr3_map().insert(directory->cr3(), *directory);
|
||||
}
|
||||
|
||||
void PageDirectory::deregister_page_directory(PageDirectory* directory)
|
||||
{
|
||||
cr3_map().remove(directory->cr3());
|
||||
}
|
||||
|
||||
RefPtr<PageDirectory> PageDirectory::find_current()
|
||||
{
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
return cr3_map().find(read_cr3());
|
||||
}
|
||||
|
||||
void activate_kernel_page_directory(PageDirectory const& pgd)
|
||||
{
|
||||
write_cr3(pgd.cr3());
|
||||
}
|
||||
|
||||
void activate_page_directory(PageDirectory const& pgd, Thread* current_thread)
|
||||
{
|
||||
current_thread->regs().cr3 = pgd.cr3();
|
||||
write_cr3(pgd.cr3());
|
||||
}
|
||||
|
||||
}
|
@ -326,6 +326,7 @@ if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/CPU.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/CPUID.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/Interrupts.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/PageDirectory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/Processor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/ProcessorInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/SafeMem.cpp
|
||||
@ -396,6 +397,7 @@ else()
|
||||
Arch/aarch64/Mailbox.cpp
|
||||
Arch/aarch64/MainIdRegister.cpp
|
||||
Arch/aarch64/MMIO.cpp
|
||||
Arch/aarch64/PageDirectory.cpp
|
||||
Arch/aarch64/Timer.cpp
|
||||
Arch/aarch64/UART.cpp
|
||||
Arch/aarch64/Utils.cpp
|
||||
|
@ -8,7 +8,9 @@
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Arch/CPU.h>
|
||||
#include <Kernel/Arch/PageDirectory.h>
|
||||
#include <Kernel/Arch/PageFault.h>
|
||||
#include <Kernel/Arch/RegisterState.h>
|
||||
#include <Kernel/BootInfo.h>
|
||||
#include <Kernel/CMOS.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
@ -78,7 +80,7 @@ UNMAP_AFTER_INIT MemoryManager::MemoryManager()
|
||||
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
parse_memory_map();
|
||||
write_cr3(kernel_page_directory().cr3());
|
||||
activate_kernel_page_directory(kernel_page_directory());
|
||||
protect_kernel_image();
|
||||
|
||||
// We're temporarily "committing" to two pages that we need to allocate below
|
||||
@ -105,7 +107,7 @@ UNMAP_AFTER_INIT void MemoryManager::protect_kernel_image()
|
||||
auto& pte = *ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||
pte.set_writable(false);
|
||||
}
|
||||
if (Processor::current().has_feature(CPUFeature::NX)) {
|
||||
if (Processor::current().has_nx()) {
|
||||
// Disable execution of the kernel data, bss and heap segments.
|
||||
for (auto const* i = start_of_kernel_data; i < end_of_kernel_image; i += PAGE_SIZE) {
|
||||
auto& pte = *ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||
@ -467,7 +469,7 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages()
|
||||
pte.set_physical_page_base(physical_page_array_current_page);
|
||||
pte.set_user_allowed(false);
|
||||
pte.set_writable(true);
|
||||
if (Processor::current().has_feature(CPUFeature::NX))
|
||||
if (Processor::current().has_nx())
|
||||
pte.set_execute_disabled(false);
|
||||
pte.set_global(true);
|
||||
pte.set_present(true);
|
||||
@ -710,7 +712,7 @@ Region* MemoryManager::find_region_from_vaddr(VirtualAddress vaddr)
|
||||
{
|
||||
if (auto* region = kernel_region_from_vaddr(vaddr))
|
||||
return region;
|
||||
auto page_directory = PageDirectory::find_by_cr3(read_cr3());
|
||||
auto page_directory = PageDirectory::find_current();
|
||||
if (!page_directory)
|
||||
return nullptr;
|
||||
VERIFY(page_directory->address_space());
|
||||
@ -1024,7 +1026,7 @@ void MemoryManager::enter_address_space(AddressSpace& space)
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
|
||||
current_thread->regs().cr3 = space.page_directory().cr3();
|
||||
write_cr3(space.page_directory().cr3());
|
||||
activate_page_directory(space.page_directory(), current_thread);
|
||||
}
|
||||
|
||||
void MemoryManager::flush_tlb_local(VirtualAddress vaddr, size_t page_count)
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
namespace Kernel {
|
||||
class PageDirectoryEntry;
|
||||
class PageTableEntry;
|
||||
}
|
||||
|
||||
struct KmallocGlobalData;
|
||||
|
@ -20,20 +20,6 @@ extern u8 end_of_kernel_image[];
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
static Singleton<IntrusiveRedBlackTree<&PageDirectory::m_tree_node>> s_cr3_map;
|
||||
|
||||
static IntrusiveRedBlackTree<&PageDirectory::m_tree_node>& cr3_map()
|
||||
{
|
||||
VERIFY_INTERRUPTS_DISABLED();
|
||||
return *s_cr3_map;
|
||||
}
|
||||
|
||||
RefPtr<PageDirectory> PageDirectory::find_by_cr3(FlatPtr cr3)
|
||||
{
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
return cr3_map().find(cr3);
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<PageDirectory> PageDirectory::must_create_kernel_page_directory()
|
||||
{
|
||||
auto directory = adopt_ref_if_nonnull(new (nothrow) PageDirectory).release_nonnull();
|
||||
@ -125,7 +111,7 @@ ErrorOr<NonnullRefPtr<PageDirectory>> PageDirectory::try_create_for_userspace(Vi
|
||||
MM.unquickmap_page();
|
||||
}
|
||||
|
||||
cr3_map().insert(directory->cr3(), directory);
|
||||
register_page_directory(directory);
|
||||
return directory;
|
||||
}
|
||||
|
||||
@ -150,7 +136,7 @@ PageDirectory::~PageDirectory()
|
||||
{
|
||||
if (is_cr3_initialized()) {
|
||||
SpinlockLocker lock(s_mm_lock);
|
||||
cr3_map().remove(cr3());
|
||||
deregister_page_directory(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class PageDirectory : public RefCounted<PageDirectory> {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<PageDirectory>> try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator = nullptr);
|
||||
static NonnullRefPtr<PageDirectory> must_create_kernel_page_directory();
|
||||
static RefPtr<PageDirectory> find_by_cr3(FlatPtr);
|
||||
static RefPtr<PageDirectory> find_current();
|
||||
|
||||
~PageDirectory();
|
||||
|
||||
@ -62,6 +62,8 @@ public:
|
||||
|
||||
private:
|
||||
PageDirectory();
|
||||
static void register_page_directory(PageDirectory* directory);
|
||||
static void deregister_page_directory(PageDirectory* directory);
|
||||
|
||||
AddressSpace* m_space { nullptr };
|
||||
VirtualRangeAllocator m_range_allocator;
|
||||
@ -77,4 +79,7 @@ private:
|
||||
RecursiveSpinlock m_lock;
|
||||
};
|
||||
|
||||
void activate_kernel_page_directory(PageDirectory const& pgd);
|
||||
void activate_page_directory(PageDirectory const& pgd, Thread* current_thread);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user