diff options
25 files changed, 199 insertions, 101 deletions
diff --git a/AK/Singleton.h b/AK/Singleton.h index a736d3471f..353102a83b 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -10,7 +10,7 @@ #include <AK/Atomic.h> #include <AK/Noncopyable.h> #ifdef KERNEL -# include <Kernel/Arch/x86/Processor.h> +# include <Kernel/Arch/Processor.h> # include <Kernel/Arch/x86/ScopedCritical.h> #endif diff --git a/AK/Weakable.h b/AK/Weakable.h index 47acb06288..f093af8a2a 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -12,7 +12,7 @@ #include "RefPtr.h" #include "StdLibExtras.h" #ifdef KERNEL -# include <Kernel/Arch/x86/Processor.h> +# include <Kernel/Arch/Processor.h> # include <Kernel/Arch/x86/ScopedCritical.h> #endif diff --git a/Kernel/Arch/Processor.h b/Kernel/Arch/Processor.h new file mode 100644 index 0000000000..804cb1da08 --- /dev/null +++ b/Kernel/Arch/Processor.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2018-2021, James Mintram <me@jamesrm.com> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Function.h> +#include <Kernel/Arch/x86/ASM_wrapper.h> + +namespace Kernel { + +namespace Memory { +class PageDirectory; +} + +struct ProcessorMessageEntry; +struct DeferredCallEntry; + +enum class ProcessorSpecificDataID { + MemoryManager, + __Count, +}; +struct ProcessorMessage { + using CallbackFunction = Function<void()>; + + enum Type { + FlushTlb, + Callback, + }; + Type type; + Atomic<u32> refs; + union { + ProcessorMessage* next; // only valid while in the pool + alignas(CallbackFunction) u8 callback_storage[sizeof(CallbackFunction)]; + struct { + Memory::PageDirectory const* page_directory; + u8* ptr; + size_t page_count; + } flush_tlb; + }; + + volatile bool async; + + ProcessorMessageEntry* per_proc_entries; + + CallbackFunction& callback_value() + { + return *bit_cast<CallbackFunction*>(&callback_storage); + } + + void invoke_callback() + { + VERIFY(type == Type::Callback); + callback_value()(); + } +}; + +struct ProcessorMessageEntry { + ProcessorMessageEntry* next; + ProcessorMessage* msg; +}; + +struct DeferredCallEntry { + using HandlerFunction = Function<void()>; + + DeferredCallEntry* next; + alignas(HandlerFunction) u8 handler_storage[sizeof(HandlerFunction)]; + bool was_allocated; + + HandlerFunction& handler_value() + { + return *bit_cast<HandlerFunction*>(&handler_storage); + } + + void invoke_handler() + { + handler_value()(); + } +}; + +} + +#if ARCH(X86_64) || ARCH(I386) +# include <Kernel/Arch/x86/Processor.h> +#elif ARCH(AARCH64) +# include <Kernel/Arch/aarch64/Processor.h> +#else +# error "Unknown architecture" +#endif + +namespace Kernel { +template<typename T> +class ProcessorSpecific { +public: + static void initialize() + { + Processor::current().set_specific(T::processor_specific_data_id(), new T); + } + static T& get() + { + return *Processor::current().get_specific<T>(); + } +}; +} diff --git a/Kernel/Arch/aarch64/Processor.h b/Kernel/Arch/aarch64/Processor.h new file mode 100644 index 0000000000..89143a35f8 --- /dev/null +++ b/Kernel/Arch/aarch64/Processor.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018-2021, James Mintram <me@jamesrm.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Array.h> +#include <AK/Concepts.h> +#include <AK/Function.h> +#include <AK/Types.h> + +namespace Kernel { + +class Thread; + +//FIXME This needs to go behind some sort of platform abstraction +// it is used between Thread and Processor. +struct [[gnu::aligned(16)]] FPUState +{ + u8 buffer[512]; +}; + +class Processor { +public: + void set_specific(ProcessorSpecificDataID /*specific_id*/, void* /*ptr*/) { } + template<typename T> + T* get_specific() { return 0; } + + ALWAYS_INLINE static void pause() { } + ALWAYS_INLINE static void wait_check() { } + + ALWAYS_INLINE static bool is_initialized() + { + return false; + } + + ALWAYS_INLINE static u32 current_id() + { + return 0; + } + + ALWAYS_INLINE static Thread* current_thread() + { + return 0; + } + + ALWAYS_INLINE static FlatPtr current_in_irq() + { + return 0; + } + + ALWAYS_INLINE static void enter_critical() { } + ALWAYS_INLINE static void leave_critical() { } + ALWAYS_INLINE static u32 in_critical() + { + return 0; + } + + ALWAYS_INLINE static Processor& current() { return *((Processor*)0); } + + static void deferred_call_queue(Function<void()> /* callback */) { } +}; + +} diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86/Processor.h index a1b6bf97e2..719aa4ebcb 100644 --- a/Kernel/Arch/x86/Processor.h +++ b/Kernel/Arch/x86/Processor.h @@ -21,13 +21,9 @@ namespace Kernel { class ProcessorInfo; +struct ProcessorMessage; struct ProcessorMessageEntry; -enum class ProcessorSpecificDataID { - MemoryManager, - __Count, -}; - #if ARCH(X86_64) # define MSR_FS_BASE 0xc0000100 # define MSR_GS_BASE 0xc0000101 @@ -44,64 +40,6 @@ struct [[gnu::aligned(16)]] FPUState u8 buffer[512]; }; -struct ProcessorMessage { - using CallbackFunction = Function<void()>; - - enum Type { - FlushTlb, - Callback, - }; - Type type; - Atomic<u32> refs; - union { - ProcessorMessage* next; // only valid while in the pool - alignas(CallbackFunction) u8 callback_storage[sizeof(CallbackFunction)]; - struct { - Memory::PageDirectory const* page_directory; - u8* ptr; - size_t page_count; - } flush_tlb; - }; - - volatile bool async; - - ProcessorMessageEntry* per_proc_entries; - - CallbackFunction& callback_value() - { - return *bit_cast<CallbackFunction*>(&callback_storage); - } - - void invoke_callback() - { - VERIFY(type == Type::Callback); - callback_value()(); - } -}; - -struct ProcessorMessageEntry { - ProcessorMessageEntry* next; - ProcessorMessage* msg; -}; - -struct DeferredCallEntry { - using HandlerFunction = Function<void()>; - - DeferredCallEntry* next; - alignas(HandlerFunction) u8 handler_storage[sizeof(HandlerFunction)]; - bool was_allocated; - - HandlerFunction& handler_value() - { - return *bit_cast<HandlerFunction*>(&handler_storage); - } - - void invoke_handler() - { - handler_value()(); - } -}; - class Processor; // Note: We only support 64 processors at most at the moment, // so allocate 64 slots of inline capacity in the container. @@ -441,17 +379,4 @@ public: static StringView platform_string(); }; -template<typename T> -class ProcessorSpecific { -public: - static void initialize() - { - Processor::current().set_specific(T::processor_specific_data_id(), new T); - } - static T& get() - { - return *Processor::current().get_specific<T>(); - } -}; - } diff --git a/Kernel/Arch/x86/ScopedCritical.h b/Kernel/Arch/x86/ScopedCritical.h index 3c75490144..5abf896b3f 100644 --- a/Kernel/Arch/x86/ScopedCritical.h +++ b/Kernel/Arch/x86/ScopedCritical.h @@ -8,7 +8,7 @@ #include <AK/Types.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> namespace Kernel { diff --git a/Kernel/Arch/x86/common/ASM_wrapper.cpp b/Kernel/Arch/x86/common/ASM_wrapper.cpp index 49f33dd3e8..e19f9dc5d3 100644 --- a/Kernel/Arch/x86/common/ASM_wrapper.cpp +++ b/Kernel/Arch/x86/common/ASM_wrapper.cpp @@ -6,8 +6,8 @@ #include <AK/Types.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/ASM_wrapper.h> -#include <Kernel/Arch/x86/Processor.h> #include <Kernel/Sections.h> namespace Kernel { diff --git a/Kernel/Arch/x86/common/Interrupts.cpp b/Kernel/Arch/x86/common/Interrupts.cpp index 5a4ae7c71f..2dc3d6f200 100644 --- a/Kernel/Arch/x86/common/Interrupts.cpp +++ b/Kernel/Arch/x86/common/Interrupts.cpp @@ -21,8 +21,8 @@ #include <LibC/mallocdefs.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/ISRStubs.h> -#include <Kernel/Arch/x86/Processor.h> #include <Kernel/Arch/x86/RegisterState.h> #include <Kernel/Arch/x86/TrapFrame.h> #include <Kernel/KSyms.h> diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 4d819a6f80..34d36f3f5a 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -15,18 +15,18 @@ #include <Kernel/StdLib.h> #include <Kernel/Thread.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/CPUID.h> +#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Arch/x86/Interrupts.h> #include <Kernel/Arch/x86/MSR.h> -#include <Kernel/Arch/x86/Processor.h> #include <Kernel/Arch/x86/ProcessorInfo.h> #include <Kernel/Arch/x86/SafeMem.h> #include <Kernel/Arch/x86/ScopedCritical.h> #include <Kernel/Arch/x86/TrapFrame.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> -#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h> #include <Kernel/Memory/PageDirectory.h> +#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h> namespace Kernel { diff --git a/Kernel/Arch/x86/common/ProcessorInfo.cpp b/Kernel/Arch/x86/common/ProcessorInfo.cpp index 3cb24ba64e..9fbea93ad7 100644 --- a/Kernel/Arch/x86/common/ProcessorInfo.cpp +++ b/Kernel/Arch/x86/common/ProcessorInfo.cpp @@ -6,8 +6,8 @@ #include <AK/StringBuilder.h> #include <AK/Types.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/CPUID.h> -#include <Kernel/Arch/x86/Processor.h> #include <Kernel/Arch/x86/ProcessorInfo.h> namespace Kernel { diff --git a/Kernel/Arch/x86/common/SafeMem.cpp b/Kernel/Arch/x86/common/SafeMem.cpp index d7100c31d7..01e405a01d 100644 --- a/Kernel/Arch/x86/common/SafeMem.cpp +++ b/Kernel/Arch/x86/common/SafeMem.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/RegisterState.h> #include <Kernel/Arch/x86/SafeMem.h> diff --git a/Kernel/Arch/x86/common/TrapFrame.cpp b/Kernel/Arch/x86/common/TrapFrame.cpp index b591c2513f..9e3054c678 100644 --- a/Kernel/Arch/x86/common/TrapFrame.cpp +++ b/Kernel/Arch/x86/common/TrapFrame.cpp @@ -4,9 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <Kernel/Arch/x86/TrapFrame.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/InterruptDisabler.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/x86/TrapFrame.h> namespace Kernel { diff --git a/Kernel/Arch/x86/i386/Processor.cpp b/Kernel/Arch/x86/i386/Processor.cpp index 7fcb0aa3ea..71186f360b 100644 --- a/Kernel/Arch/x86/i386/Processor.cpp +++ b/Kernel/Arch/x86/i386/Processor.cpp @@ -5,7 +5,7 @@ */ #include <AK/StdLibExtras.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/TrapFrame.h> #include <Kernel/Process.h> #include <Kernel/Random.h> diff --git a/Kernel/Arch/x86/x86_64/Processor.cpp b/Kernel/Arch/x86/x86_64/Processor.cpp index 3c77a0e796..38b998581a 100644 --- a/Kernel/Arch/x86/x86_64/Processor.cpp +++ b/Kernel/Arch/x86/x86_64/Processor.cpp @@ -5,7 +5,7 @@ */ #include <AK/StdLibExtras.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/TrapFrame.h> #include <Kernel/Panic.h> #include <Kernel/Process.h> diff --git a/Kernel/AtomicEdgeAction.h b/Kernel/AtomicEdgeAction.h index 6626b8e00a..c80adcaa1d 100644 --- a/Kernel/AtomicEdgeAction.h +++ b/Kernel/AtomicEdgeAction.h @@ -7,7 +7,7 @@ #pragma once #include <AK/Atomic.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> namespace Kernel { diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp index 83d438e772..6900478c01 100644 --- a/Kernel/Bus/PCI/Access.cpp +++ b/Kernel/Bus/PCI/Access.cpp @@ -8,13 +8,13 @@ #include <AK/HashTable.h> #include <Kernel/API/KResult.h> #include <Kernel/Arch/x86/IO.h> +#include <Kernel/Arch/x86/InterruptDisabler.h> #include <Kernel/Bus/PCI/Access.h> #include <Kernel/Debug.h> #include <Kernel/Firmware/ACPI/Definitions.h> #include <Kernel/Memory/MemoryManager.h> #include <Kernel/Memory/Region.h> #include <Kernel/Sections.h> -#include <Kernel/Arch/x86/InterruptDisabler.h> namespace Kernel::PCI { diff --git a/Kernel/Bus/USB/USBHub.cpp b/Kernel/Bus/USB/USBHub.cpp index 335e582f9b..a486b710b3 100644 --- a/Kernel/Bus/USB/USBHub.cpp +++ b/Kernel/Bus/USB/USBHub.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <Kernel/Arch/x86/IO.h> #include <Kernel/Bus/USB/SysFSUSB.h> #include <Kernel/Bus/USB/USBClasses.h> #include <Kernel/Bus/USB/USBController.h> #include <Kernel/Bus/USB/USBHub.h> #include <Kernel/Bus/USB/USBRequest.h> #include <Kernel/StdLib.h> -#include <Kernel/Arch/x86/IO.h> namespace Kernel::USB { diff --git a/Kernel/FileSystem/InodeMetadata.h b/Kernel/FileSystem/InodeMetadata.h index 407d941a83..ba61a76234 100644 --- a/Kernel/FileSystem/InodeMetadata.h +++ b/Kernel/FileSystem/InodeMetadata.h @@ -9,8 +9,8 @@ #include <AK/Span.h> #include <Kernel/API/KResult.h> #include <Kernel/FileSystem/InodeIdentifier.h> -#include <Kernel/UnixTypes.h> #include <Kernel/Forward.h> +#include <Kernel/UnixTypes.h> namespace Kernel { diff --git a/Kernel/Library/ThreadSafeNonnullRefPtr.h b/Kernel/Library/ThreadSafeNonnullRefPtr.h index 523fdbec42..9cd44d4a04 100644 --- a/Kernel/Library/ThreadSafeNonnullRefPtr.h +++ b/Kernel/Library/ThreadSafeNonnullRefPtr.h @@ -12,7 +12,7 @@ #include <AK/Traits.h> #include <AK/Types.h> #ifdef KERNEL -# include <Kernel/Arch/x86/Processor.h> +# include <Kernel/Arch/Processor.h> # include <Kernel/Arch/x86/ScopedCritical.h> #endif diff --git a/Kernel/Library/ThreadSafeRefPtr.h b/Kernel/Library/ThreadSafeRefPtr.h index 03b7d2e11e..2adf13ed33 100644 --- a/Kernel/Library/ThreadSafeRefPtr.h +++ b/Kernel/Library/ThreadSafeRefPtr.h @@ -15,7 +15,7 @@ #include <AK/Types.h> #ifdef KERNEL # include <Kernel/API/KResult.h> -# include <Kernel/Arch/x86/Processor.h> +# include <Kernel/Arch/Processor.h> # include <Kernel/Arch/x86/ScopedCritical.h> #endif diff --git a/Kernel/Locking/Spinlock.h b/Kernel/Locking/Spinlock.h index 81b6d5ae66..7e8f83708a 100644 --- a/Kernel/Locking/Spinlock.h +++ b/Kernel/Locking/Spinlock.h @@ -8,7 +8,7 @@ #include <AK/Atomic.h> #include <AK/Types.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Locking/LockRank.h> namespace Kernel { diff --git a/Kernel/Panic.cpp b/Kernel/Panic.cpp index 5f25385f0e..b4fe667425 100644 --- a/Kernel/Panic.cpp +++ b/Kernel/Panic.cpp @@ -5,8 +5,8 @@ */ #include <AK/Format.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/x86/IO.h> -#include <Kernel/Arch/x86/Processor.h> #include <Kernel/CommandLine.h> #include <Kernel/KSyms.h> #include <Kernel/Panic.h> diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp index 2933e9d595..1889245991 100644 --- a/Kernel/Random.cpp +++ b/Kernel/Random.cpp @@ -6,7 +6,7 @@ */ #include <AK/Singleton.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Devices/RandomDevice.h> #include <Kernel/Random.h> #include <Kernel/Sections.h> diff --git a/Kernel/UBSanitizer.cpp b/Kernel/UBSanitizer.cpp index 0bb39b306d..571b495d8c 100644 --- a/Kernel/UBSanitizer.cpp +++ b/Kernel/UBSanitizer.cpp @@ -6,7 +6,7 @@ #include <AK/Format.h> #include <AK/UBSanitizer.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/KSyms.h> using namespace Kernel; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 1ea58ec7d2..0de7d195e2 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -5,7 +5,7 @@ */ #include <AK/Types.h> -#include <Kernel/Arch/x86/Processor.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/BootInfo.h> #include <Kernel/Bus/PCI/Access.h> #include <Kernel/Bus/PCI/Initializer.h> |