diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-31 09:42:54 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-31 09:42:54 +0100 |
| commit | fc55f0d69d24fb4908cbd811681f2c3fac53614d (patch) | |
| tree | ba09a2cdbb225df7ba1a9ec5a12bcbb90b673ead /Private/KernelKit/SMPManager.hpp | |
| parent | 7bed9287589293bd9d712d152539591dee0b28c0 (diff) | |
kernel: add GKit, improve AMD64 HAL.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/KernelKit/SMPManager.hpp')
| -rw-r--r-- | Private/KernelKit/SMPManager.hpp | 202 |
1 files changed, 98 insertions, 104 deletions
diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index 889f72c1..a7106a9b 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -10,112 +10,106 @@ #ifndef _INC_SMP_MANAGER_HPP #define _INC_SMP_MANAGER_HPP -#include <CompilerKit/CompilerKit.hpp> #include <ArchKit/Arch.hpp> +#include <CompilerKit/CompilerKit.hpp> #include <NewKit/Ref.hpp> #define kMaxHarts 8 -namespace HCore -{ - using ThreadID = UInt32; - - enum ThreadKind - { - kSystemReserved, // System reserved thread, well user can't use it - kStandard, // user thread, cannot be used by kernel - kFallback, // fallback thread, cannot be used by user if not clear or used by kernel. - kBoot, // The core we booted from, the mama. - }; - - /// - /// \name ProcessorCore - /// CPU core (PowerPC, Intel, or NewCPU) - /// - - class ProcessorCore final - { - public: - explicit ProcessorCore(); - ~ProcessorCore(); - - public: - HCORE_COPY_DEFAULT(ProcessorCore) - - public: - operator bool(); - - public: - void Wake(const bool wakeup = false) noexcept; - void Busy(const bool busy = false) noexcept; - - public: - bool Switch(HAL::StackFrame* stack); - bool IsWakeup() noexcept; - - public: - HAL::StackFrame* StackFrame() noexcept; - const ThreadKind& Kind() noexcept; - bool IsBusy() noexcept; - const ThreadID& ID() noexcept; - - private: - HAL::StackFrame* m_Stack; - ThreadKind m_Kind; - ThreadID m_ID; - bool m_Wakeup; - bool m_Busy; - Int64 m_PID; - - private: - friend class SMPManager; - - }; - - /// - /// \name ProcessorCore - /// - /// Multi processor manager to manage other cores and dispatch tasks. - /// - - class SMPManager final - { - private: - explicit SMPManager(); - - public: - ~SMPManager(); - - public: - HCORE_COPY_DEFAULT(SMPManager); - - public: - bool Switch(HAL::StackFrame* the); - HAL::StackFramePtr GetStackFrame() noexcept; - - public: - Ref<ProcessorCore> operator[](const SizeT& idx); - bool operator!() noexcept; - operator bool() noexcept; - - public: - /// @brief Shared instance of the SMP Manager. - /// @return the reference to the smp manager. - static Ref<SMPManager> Shared(); - - private: - Array<ProcessorCore, kMaxHarts> m_ThreadList; - ThreadID m_CurrentThread; - - }; - - // @brief wakes up thread. - // wakes up thread from hang. - void rt_wakeup_thread(HAL::StackFrame* stack); - - // @brief makes thread sleep. - // hooks and hangs thread to prevent code from executing. - void rt_hang_thread(HAL::StackFrame* stack); -} // namespace HCore - -#endif // !_INC_SMP_MANAGER_HPP +namespace HCore { +using ThreadID = UInt32; + +enum ThreadKind { + kSystemReserved, // System reserved thread, well user can't use it + kStandard, // user thread, cannot be used by kernel + kFallback, // fallback thread, cannot be used by user if not clear or used by + // kernel. + kBoot, // The core we booted from, the mama. +}; + +/// +/// \name HardwareThread +/// @brief CPU Hardware Thread (PowerPC, Intel, or NewCPU) +/// + +class HardwareThread final { + public: + explicit HardwareThread(); + ~HardwareThread(); + + public: + HCORE_COPY_DEFAULT(HardwareThread) + + public: + operator bool(); + + public: + void Wake(const bool wakeup = false) noexcept; + void Busy(const bool busy = false) noexcept; + + public: + bool Switch(HAL::StackFrame* stack); + bool IsWakeup() noexcept; + + public: + HAL::StackFrame* StackFrame() noexcept; + const ThreadKind& Kind() noexcept; + bool IsBusy() noexcept; + const ThreadID& ID() noexcept; + + private: + HAL::StackFrame* m_Stack; + ThreadKind m_Kind; + ThreadID m_ID; + bool m_Wakeup; + bool m_Busy; + Int64 m_PID; + + private: + friend class SMPManager; +}; + +/// +/// \name SMPManager +/// @brief Multi processor manager to manage other cores and dispatch tasks. +/// + +class SMPManager final { + private: + explicit SMPManager(); + + public: + ~SMPManager(); + + public: + HCORE_COPY_DEFAULT(SMPManager); + + public: + bool Switch(HAL::StackFrame* the); + HAL::StackFramePtr GetStackFrame() noexcept; + + public: + Ref<HardwareThread> operator[](const SizeT& idx); + bool operator!() noexcept; + operator bool() noexcept; + + public: + /// @brief Shared instance of the SMP Manager. + /// @return the reference to the smp manager. + static Ref<SMPManager> Shared(); + + private: + Array<HardwareThread, kMaxHarts> m_ThreadList; + ThreadID m_CurrentThread; +}; + +// @brief wakes up thread. +// wakes up thread from hang. +void rt_wakeup_thread(HAL::StackFrame* stack); + +// @brief makes thread sleep. +// hooks and hangs thread to prevent code from executing. +void rt_hang_thread(HAL::StackFrame* stack); +} // namespace HCore + +#endif // !_INC_SMP_MANAGER_HPP |
