From d3b6201b405fb7a041b5e12001c2dee4de072ef5 Mon Sep 17 00:00:00 2001 From: James Mintram Date: Sat, 2 Apr 2022 23:48:04 +0100 Subject: Kernel: Make PageDirectory.cpp compile on aarch64 --- Kernel/Arch/PageDirectory.h | 156 ++++++++++++++++++++++++++++++++++ Kernel/Arch/PageFault.h | 65 ++++++++++++++ Kernel/Arch/aarch64/Processor.h | 3 + Kernel/Arch/x86/PageDirectory.h | 156 ---------------------------------- Kernel/Arch/x86/PageFault.h | 67 --------------- Kernel/Arch/x86/Processor.h | 2 +- Kernel/Arch/x86/common/Interrupts.cpp | 2 +- Kernel/Memory/MemoryManager.cpp | 2 +- Kernel/Memory/PageDirectory.cpp | 2 + 9 files changed, 229 insertions(+), 226 deletions(-) create mode 100644 Kernel/Arch/PageDirectory.h create mode 100644 Kernel/Arch/PageFault.h delete mode 100644 Kernel/Arch/x86/PageDirectory.h delete mode 100644 Kernel/Arch/x86/PageFault.h (limited to 'Kernel') diff --git a/Kernel/Arch/PageDirectory.h b/Kernel/Arch/PageDirectory.h new file mode 100644 index 0000000000..1fddb0ad4f --- /dev/null +++ b/Kernel/Arch/PageDirectory.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +#include + +namespace Kernel { + +class PageDirectoryEntry { +public: + PhysicalPtr page_table_base() const { return PhysicalAddress::physical_page_base(m_raw); } + void set_page_table_base(u32 value) + { + m_raw &= 0x8000000000000fffULL; + m_raw |= PhysicalAddress::physical_page_base(value); + } + + bool is_null() const { return m_raw == 0; } + void clear() { m_raw = 0; } + + u64 raw() const { return m_raw; } + void copy_from(Badge, PageDirectoryEntry const& other) { m_raw = other.m_raw; } + + enum Flags { + Present = 1 << 0, + ReadWrite = 1 << 1, + UserSupervisor = 1 << 2, + WriteThrough = 1 << 3, + CacheDisabled = 1 << 4, + Huge = 1 << 7, + Global = 1 << 8, + NoExecute = 0x8000000000000000ULL, + }; + + bool is_present() const { return (raw() & Present) == Present; } + void set_present(bool b) { set_bit(Present, b); } + + bool is_user_allowed() const { return (raw() & UserSupervisor) == UserSupervisor; } + void set_user_allowed(bool b) { set_bit(UserSupervisor, b); } + + bool is_huge() const { return (raw() & Huge) == Huge; } + void set_huge(bool b) { set_bit(Huge, b); } + + bool is_writable() const { return (raw() & ReadWrite) == ReadWrite; } + void set_writable(bool b) { set_bit(ReadWrite, b); } + + bool is_write_through() const { return (raw() & WriteThrough) == WriteThrough; } + void set_write_through(bool b) { set_bit(WriteThrough, b); } + + bool is_cache_disabled() const { return (raw() & CacheDisabled) == CacheDisabled; } + void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } + + bool is_global() const { return (raw() & Global) == Global; } + void set_global(bool b) { set_bit(Global, b); } + + bool is_execute_disabled() const { return (raw() & NoExecute) == NoExecute; } + void set_execute_disabled(bool b) { set_bit(NoExecute, b); } + +private: + void set_bit(u64 bit, bool value) + { + if (value) + m_raw |= bit; + else + m_raw &= ~bit; + } + + u64 m_raw; +}; + +class PageTableEntry { +public: + PhysicalPtr physical_page_base() const { return PhysicalAddress::physical_page_base(m_raw); } + void set_physical_page_base(PhysicalPtr value) + { + // FIXME: IS THIS PLATFORM SPECIFIC? + m_raw &= 0x8000000000000fffULL; + m_raw |= PhysicalAddress::physical_page_base(value); + } + + u64 raw() const { return m_raw; } + + enum Flags { + Present = 1 << 0, + ReadWrite = 1 << 1, + UserSupervisor = 1 << 2, + WriteThrough = 1 << 3, + CacheDisabled = 1 << 4, + PAT = 1 << 7, + Global = 1 << 8, + NoExecute = 0x8000000000000000ULL, + }; + + bool is_present() const { return (raw() & Present) == Present; } + void set_present(bool b) { set_bit(Present, b); } + + bool is_user_allowed() const { return (raw() & UserSupervisor) == UserSupervisor; } + void set_user_allowed(bool b) { set_bit(UserSupervisor, b); } + + bool is_writable() const { return (raw() & ReadWrite) == ReadWrite; } + void set_writable(bool b) { set_bit(ReadWrite, b); } + + bool is_write_through() const { return (raw() & WriteThrough) == WriteThrough; } + void set_write_through(bool b) { set_bit(WriteThrough, b); } + + bool is_cache_disabled() const { return (raw() & CacheDisabled) == CacheDisabled; } + void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } + + bool is_global() const { return (raw() & Global) == Global; } + void set_global(bool b) { set_bit(Global, b); } + + bool is_execute_disabled() const { return (raw() & NoExecute) == NoExecute; } + void set_execute_disabled(bool b) { set_bit(NoExecute, b); } + + bool is_pat() const { return (raw() & PAT) == PAT; } + void set_pat(bool b) { set_bit(PAT, b); } + + bool is_null() const { return m_raw == 0; } + void clear() { m_raw = 0; } + +private: + void set_bit(u64 bit, bool value) + { + if (value) + m_raw |= bit; + else + m_raw &= ~bit; + } + + u64 m_raw; +}; + +static_assert(AssertSize()); +static_assert(AssertSize()); + +class PageDirectoryPointerTable { +public: + PageDirectoryEntry* directory(size_t index) + { + VERIFY(index <= (NumericLimits::max() << 30)); + return (PageDirectoryEntry*)(PhysicalAddress::physical_page_base(raw[index])); + } + + u64 raw[512]; +}; + +} diff --git a/Kernel/Arch/PageFault.h b/Kernel/Arch/PageFault.h new file mode 100644 index 0000000000..1d939d8ea2 --- /dev/null +++ b/Kernel/Arch/PageFault.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Kernel { + +struct PageFaultFlags { + enum Flags { + NotPresent = 0x00, + ProtectionViolation = 0x01, + Read = 0x00, + Write = 0x02, + UserMode = 0x04, + SupervisorMode = 0x00, + ReservedBitViolation = 0x08, + InstructionFetch = 0x10, + }; +}; + +class PageFault { +public: + PageFault(u16 code, VirtualAddress vaddr) + : m_code(code) + , m_vaddr(vaddr) + { + } + + enum class Type { + PageNotPresent = PageFaultFlags::NotPresent, + ProtectionViolation = PageFaultFlags::ProtectionViolation, + }; + + enum class Access { + Read = PageFaultFlags::Read, + Write = PageFaultFlags::Write, + }; + + VirtualAddress vaddr() const { return m_vaddr; } + u16 code() const { return m_code; } + + Type type() const { return (Type)(m_code & 1); } + Access access() const { return (Access)(m_code & 2); } + + bool is_not_present() const { return (m_code & 1) == PageFaultFlags::NotPresent; } + bool is_protection_violation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; } + bool is_read() const { return (m_code & 2) == PageFaultFlags::Read; } + bool is_write() const { return (m_code & 2) == PageFaultFlags::Write; } + bool is_user() const { return (m_code & 4) == PageFaultFlags::UserMode; } + bool is_supervisor() const { return (m_code & 4) == PageFaultFlags::SupervisorMode; } + bool is_instruction_fetch() const { return (m_code & 16) == PageFaultFlags::InstructionFetch; } + +private: + u16 m_code; + VirtualAddress m_vaddr; +}; + +} diff --git a/Kernel/Arch/aarch64/Processor.h b/Kernel/Arch/aarch64/Processor.h index 512c13da45..76d1e30788 100644 --- a/Kernel/Arch/aarch64/Processor.h +++ b/Kernel/Arch/aarch64/Processor.h @@ -33,6 +33,9 @@ public: ALWAYS_INLINE static void pause() { } ALWAYS_INLINE static void wait_check() { } + ALWAYS_INLINE u8 physical_address_bit_width() const { return 0; } + ALWAYS_INLINE u8 virtual_address_bit_width() const { return 0; } + ALWAYS_INLINE static bool is_initialized() { return false; diff --git a/Kernel/Arch/x86/PageDirectory.h b/Kernel/Arch/x86/PageDirectory.h deleted file mode 100644 index 7c8e7e2cf9..0000000000 --- a/Kernel/Arch/x86/PageDirectory.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include - -#include -VALIDATE_IS_X86() - -namespace Kernel { - -class PageDirectoryEntry { -public: - PhysicalPtr page_table_base() const { return PhysicalAddress::physical_page_base(m_raw); } - void set_page_table_base(u32 value) - { - m_raw &= 0x8000000000000fffULL; - m_raw |= PhysicalAddress::physical_page_base(value); - } - - bool is_null() const { return m_raw == 0; } - void clear() { m_raw = 0; } - - u64 raw() const { return m_raw; } - void copy_from(Badge, PageDirectoryEntry const& other) { m_raw = other.m_raw; } - - enum Flags { - Present = 1 << 0, - ReadWrite = 1 << 1, - UserSupervisor = 1 << 2, - WriteThrough = 1 << 3, - CacheDisabled = 1 << 4, - Huge = 1 << 7, - Global = 1 << 8, - NoExecute = 0x8000000000000000ULL, - }; - - bool is_present() const { return (raw() & Present) == Present; } - void set_present(bool b) { set_bit(Present, b); } - - bool is_user_allowed() const { return (raw() & UserSupervisor) == UserSupervisor; } - void set_user_allowed(bool b) { set_bit(UserSupervisor, b); } - - bool is_huge() const { return (raw() & Huge) == Huge; } - void set_huge(bool b) { set_bit(Huge, b); } - - bool is_writable() const { return (raw() & ReadWrite) == ReadWrite; } - void set_writable(bool b) { set_bit(ReadWrite, b); } - - bool is_write_through() const { return (raw() & WriteThrough) == WriteThrough; } - void set_write_through(bool b) { set_bit(WriteThrough, b); } - - bool is_cache_disabled() const { return (raw() & CacheDisabled) == CacheDisabled; } - void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } - - bool is_global() const { return (raw() & Global) == Global; } - void set_global(bool b) { set_bit(Global, b); } - - bool is_execute_disabled() const { return (raw() & NoExecute) == NoExecute; } - void set_execute_disabled(bool b) { set_bit(NoExecute, b); } - -private: - void set_bit(u64 bit, bool value) - { - if (value) - m_raw |= bit; - else - m_raw &= ~bit; - } - - u64 m_raw; -}; - -class PageTableEntry { -public: - PhysicalPtr physical_page_base() const { return PhysicalAddress::physical_page_base(m_raw); } - void set_physical_page_base(PhysicalPtr value) - { - m_raw &= 0x8000000000000fffULL; - m_raw |= PhysicalAddress::physical_page_base(value); - } - - u64 raw() const { return m_raw; } - - enum Flags { - Present = 1 << 0, - ReadWrite = 1 << 1, - UserSupervisor = 1 << 2, - WriteThrough = 1 << 3, - CacheDisabled = 1 << 4, - PAT = 1 << 7, - Global = 1 << 8, - NoExecute = 0x8000000000000000ULL, - }; - - bool is_present() const { return (raw() & Present) == Present; } - void set_present(bool b) { set_bit(Present, b); } - - bool is_user_allowed() const { return (raw() & UserSupervisor) == UserSupervisor; } - void set_user_allowed(bool b) { set_bit(UserSupervisor, b); } - - bool is_writable() const { return (raw() & ReadWrite) == ReadWrite; } - void set_writable(bool b) { set_bit(ReadWrite, b); } - - bool is_write_through() const { return (raw() & WriteThrough) == WriteThrough; } - void set_write_through(bool b) { set_bit(WriteThrough, b); } - - bool is_cache_disabled() const { return (raw() & CacheDisabled) == CacheDisabled; } - void set_cache_disabled(bool b) { set_bit(CacheDisabled, b); } - - bool is_global() const { return (raw() & Global) == Global; } - void set_global(bool b) { set_bit(Global, b); } - - bool is_execute_disabled() const { return (raw() & NoExecute) == NoExecute; } - void set_execute_disabled(bool b) { set_bit(NoExecute, b); } - - bool is_pat() const { return (raw() & PAT) == PAT; } - void set_pat(bool b) { set_bit(PAT, b); } - - bool is_null() const { return m_raw == 0; } - void clear() { m_raw = 0; } - -private: - void set_bit(u64 bit, bool value) - { - if (value) - m_raw |= bit; - else - m_raw &= ~bit; - } - - u64 m_raw; -}; - -static_assert(AssertSize()); -static_assert(AssertSize()); - -class PageDirectoryPointerTable { -public: - PageDirectoryEntry* directory(size_t index) - { - VERIFY(index <= (NumericLimits::max() << 30)); - return (PageDirectoryEntry*)(PhysicalAddress::physical_page_base(raw[index])); - } - - u64 raw[512]; -}; - -} diff --git a/Kernel/Arch/x86/PageFault.h b/Kernel/Arch/x86/PageFault.h deleted file mode 100644 index a51c3e3874..0000000000 --- a/Kernel/Arch/x86/PageFault.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -#include -VALIDATE_IS_X86() - -namespace Kernel { - -struct PageFaultFlags { - enum Flags { - NotPresent = 0x00, - ProtectionViolation = 0x01, - Read = 0x00, - Write = 0x02, - UserMode = 0x04, - SupervisorMode = 0x00, - ReservedBitViolation = 0x08, - InstructionFetch = 0x10, - }; -}; - -class PageFault { -public: - PageFault(u16 code, VirtualAddress vaddr) - : m_code(code) - , m_vaddr(vaddr) - { - } - - enum class Type { - PageNotPresent = PageFaultFlags::NotPresent, - ProtectionViolation = PageFaultFlags::ProtectionViolation, - }; - - enum class Access { - Read = PageFaultFlags::Read, - Write = PageFaultFlags::Write, - }; - - VirtualAddress vaddr() const { return m_vaddr; } - u16 code() const { return m_code; } - - Type type() const { return (Type)(m_code & 1); } - Access access() const { return (Access)(m_code & 2); } - - bool is_not_present() const { return (m_code & 1) == PageFaultFlags::NotPresent; } - bool is_protection_violation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; } - bool is_read() const { return (m_code & 2) == PageFaultFlags::Read; } - bool is_write() const { return (m_code & 2) == PageFaultFlags::Write; } - bool is_user() const { return (m_code & 4) == PageFaultFlags::UserMode; } - bool is_supervisor() const { return (m_code & 4) == PageFaultFlags::SupervisorMode; } - bool is_instruction_fetch() const { return (m_code & 16) == PageFaultFlags::InstructionFetch; } - -private: - u16 m_code; - VirtualAddress m_vaddr; -}; - -} diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86/Processor.h index cd93b2bf37..05493f82e0 100644 --- a/Kernel/Arch/x86/Processor.h +++ b/Kernel/Arch/x86/Processor.h @@ -12,11 +12,11 @@ #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/Kernel/Arch/x86/common/Interrupts.cpp b/Kernel/Arch/x86/common/Interrupts.cpp index e87601130d..a29c6ecdb4 100644 --- a/Kernel/Arch/x86/common/Interrupts.cpp +++ b/Kernel/Arch/x86/common/Interrupts.cpp @@ -23,10 +23,10 @@ #include +#include #include #include #include -#include #include #include diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index f5cdfbe825..b00fcbda91 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Memory/PageDirectory.cpp b/Kernel/Memory/PageDirectory.cpp index dc0a652860..b6030ee9bb 100644 --- a/Kernel/Memory/PageDirectory.cpp +++ b/Kernel/Memory/PageDirectory.cpp @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include #include -- cgit v1.2.3