Kernel: Add per platform Processor.h headers

The platform independent Processor.h file includes the shared processor
code and includes the specific platform header file.

All references to the Arch/x86/Processor.h file have been replaced with
a reference to Arch/Processor.h.
This commit is contained in:
James Mintram 2021-10-14 00:07:37 +01:00 committed by Linus Groh
parent 23676bee1f
commit 545ce5b595
Notes: sideshowbarker 2024-07-18 02:45:18 +09:00
25 changed files with 199 additions and 101 deletions

View file

@ -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

View file

@ -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

107
Kernel/Arch/Processor.h Normal file
View file

@ -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>();
}
};
}

View file

@ -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 */) { }
};
}

View file

@ -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>();
}
};
}

View file

@ -8,7 +8,7 @@
#include <AK/Types.h>
#include <Kernel/Arch/x86/Processor.h>
#include <Kernel/Arch/Processor.h>
namespace Kernel {

View file

@ -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 {

View file

@ -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>

View file

@ -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 {

View file

@ -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 {

View file

@ -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>

View file

@ -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 {

View file

@ -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>

View file

@ -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>

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/Atomic.h>
#include <Kernel/Arch/x86/Processor.h>
#include <Kernel/Arch/Processor.h>
namespace Kernel {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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 {

View file

@ -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>

View file

@ -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>

View file

@ -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;

View file

@ -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>