From fc55f0d69d24fb4908cbd811681f2c3fac53614d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 31 Jan 2024 09:42:54 +0100 Subject: kernel: add GKit, improve AMD64 HAL. Signed-off-by: Amlal El Mahrouss --- Private/EFIKit/EFILib.hxx | 11 +- Private/HALKit/AMD64/HalHardwareAPIC.cpp | 42 +++++ Private/HALKit/AMD64/HalHardwareInit.cpp | 20 +++ Private/HALKit/AMD64/HalPlatformAMD64.cpp | 47 ++++++ Private/HALKit/AMD64/HalProcessPrimitives.cxx | 25 +++ Private/HALKit/AMD64/HalProcessor.cpp | 58 +++++++ Private/HALKit/AMD64/HalRoutines.s | 8 +- Private/HALKit/AMD64/HardwareAPIC.cpp | 42 ----- Private/HALKit/AMD64/HardwareInit.cpp | 20 --- Private/HALKit/AMD64/PlatformAMD64.cpp | 47 ------ Private/HALKit/AMD64/ProcessPrimitives.cxx | 25 --- Private/HALKit/AMD64/Processor.cpp | 58 ------- Private/HALKit/AMD64/Processor.hpp | 24 ++- Private/HALKit/PowerPC/HalHardware.cpp | 48 ++++++ Private/HALKit/PowerPC/Processor.cpp | 48 ------ Private/HALKit/PowerPC/StartSequence.s | 6 +- Private/KernelKit/PEF.hpp | 6 +- Private/KernelKit/SMPManager.hpp | 202 ++++++++++++------------ Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 2 +- Private/Source/RuntimeMain.cxx | 3 +- Private/Source/SMPManager.cxx | 30 ++-- 21 files changed, 389 insertions(+), 383 deletions(-) create mode 100644 Private/HALKit/AMD64/HalHardwareAPIC.cpp create mode 100644 Private/HALKit/AMD64/HalHardwareInit.cpp create mode 100644 Private/HALKit/AMD64/HalPlatformAMD64.cpp create mode 100644 Private/HALKit/AMD64/HalProcessPrimitives.cxx create mode 100644 Private/HALKit/AMD64/HalProcessor.cpp delete mode 100644 Private/HALKit/AMD64/HardwareAPIC.cpp delete mode 100644 Private/HALKit/AMD64/HardwareInit.cpp delete mode 100644 Private/HALKit/AMD64/PlatformAMD64.cpp delete mode 100644 Private/HALKit/AMD64/ProcessPrimitives.cxx delete mode 100644 Private/HALKit/AMD64/Processor.cpp create mode 100644 Private/HALKit/PowerPC/HalHardware.cpp delete mode 100644 Private/HALKit/PowerPC/Processor.cpp (limited to 'Private') diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx index 3f441a76..147b4fe2 100644 --- a/Private/EFIKit/EFILib.hxx +++ b/Private/EFIKit/EFILib.hxx @@ -12,17 +12,14 @@ #include -#include "NewKit/Defines.hpp" - inline EfiSystemTable* ST = nullptr; inline EfiBootServices* BS = nullptr; namespace EFI { /** @brief Stop Execution of program. -@param SystemTable EFI System Table. */ -inline Void Stop(EfiSystemTable* SystemTable) noexcept { +inline Void Stop() noexcept { while (true) { rt_cli(); rt_halt(); @@ -35,11 +32,15 @@ Bascially frees everything we have in the EFI side. */ inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept { + if (!SystemTable) return; + SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey); } } // namespace EFI inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept { + if (!SystemTable) return; + ST = SystemTable; BS = ST->BootServices; } @@ -54,7 +55,7 @@ inline void KeRuntimeStop(const EfiCharType* File, ST->ConOut->OutputString(ST->ConOut, Reason); ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); - EFI::Stop(ST); + EFI::Stop(); } #ifdef __BOOTLOADER__ diff --git a/Private/HALKit/AMD64/HalHardwareAPIC.cpp b/Private/HALKit/AMD64/HalHardwareAPIC.cpp new file mode 100644 index 00000000..6d77a8b5 --- /dev/null +++ b/Private/HALKit/AMD64/HalHardwareAPIC.cpp @@ -0,0 +1,42 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +// bugs = 0 + +namespace HCore { +// @brief wakes up thread. +// wakes up thread from hang. +void rt_wakeup_thread(HAL::StackFrame* stack) { + __asm__ volatile("cli"); + + stack->Rbp = stack->R15; + stack->Rsi = stack->Rbp; + + __asm__ volatile("sti"); +} + +static void __rt_hang_proc(void) { + while (1) + ; +} + +// @brief makes thread sleep. +// hooks and hangs thread to prevent code from executing. +void rt_hang_thread(HAL::StackFrame* stack) { + __asm__ volatile("cli"); + + stack->R15 = stack->Rbp; + stack->Rbp = (HAL::Reg)&__rt_hang_proc; + stack->Rsp = stack->Rbp; + + __asm__ volatile("sti"); +} +} // namespace HCore diff --git a/Private/HALKit/AMD64/HalHardwareInit.cpp b/Private/HALKit/AMD64/HalHardwareInit.cpp new file mode 100644 index 00000000..1856cc2d --- /dev/null +++ b/Private/HALKit/AMD64/HalHardwareInit.cpp @@ -0,0 +1,20 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +// bugs = 0 + +namespace HCore { +bool ke_init_hal() { + // TODO: Hardware Specific stuff. + + return true; +} +} // namespace HCore diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp new file mode 100644 index 00000000..f72be01f --- /dev/null +++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp @@ -0,0 +1,47 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +namespace HCore::HAL { +namespace Detail { +struct RegisterAMD64 final { + UIntPtr base; + UShort limit; +}; +} // namespace Detail + +void GDTLoader::Load(Register64 &gdt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); + + reg->base = gdt.Base; + reg->limit = gdt.Limit; + + rt_cli(); + rt_load_gdt(reg); + rt_sti(); +} + +void IDTLoader::Load(Register64 &idt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); + + reg->base = idt.Base; + reg->limit = idt.Limit; + + rt_cli(); + rt_load_idt(reg); + rt_sti(); +} + +void GDTLoader::Load(Ref &gdt) { GDTLoader::Load(gdt.Leak()); } + +void IDTLoader::Load(Ref &idt) { IDTLoader::Load(idt.Leak()); } +} // namespace HCore::HAL diff --git a/Private/HALKit/AMD64/HalProcessPrimitives.cxx b/Private/HALKit/AMD64/HalProcessPrimitives.cxx new file mode 100644 index 00000000..8d0554f3 --- /dev/null +++ b/Private/HALKit/AMD64/HalProcessPrimitives.cxx @@ -0,0 +1,25 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +#include "NewKit/Defines.hpp" + +using namespace HCore; + +Void Process::AssignStart(UIntPtr &imageStart) noexcept { + if (imageStart == 0) this->Crash(); + +#ifdef __x86_64__ + this->StackFrame->Rbp = imageStart; +#elif defined(__powerpc) + // link return register towards the __start symbol. + this->StackFrame->R3 = imageStart; +#endif +} diff --git a/Private/HALKit/AMD64/HalProcessor.cpp b/Private/HALKit/AMD64/HalProcessor.cpp new file mode 100644 index 00000000..3d509f79 --- /dev/null +++ b/Private/HALKit/AMD64/HalProcessor.cpp @@ -0,0 +1,58 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +/** + * @file Processor.cpp + * @brief This file is about processor specific functions (in/out...) + */ + +namespace HCore::HAL { +void out8(UInt16 port, UInt8 value) { + asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +void out16(UInt16 port, UInt16 value) { + asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +void out32(UInt16 port, UInt32 value) { + asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +UInt8 in8(UInt16 port) { + UInt8 value = 0UL; + asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +UInt16 in16(UInt16 port) { + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +UInt32 in32(UInt16 port) { + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +void rt_halt() { asm volatile("hlt"); } + +void rt_cli() { asm volatile("cli"); } + +void rt_sti() { asm volatile("sti"); } + +void rt_cld() { asm volatile("cld"); } +} // namespace HCore::HAL diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s index 78b9e503..7965c8a8 100644 --- a/Private/HALKit/AMD64/HalRoutines.s +++ b/Private/HALKit/AMD64/HalRoutines.s @@ -1,14 +1,14 @@ -.globl load_idt -.globl load_gdt +.globl rt_load_idt +.globl rt_load_gdt .globl rt_wait_for_io .globl rt_get_current_context .section .text -load_gdt: +rt_load_gdt: lgdt (%rdi) ret -load_idt: +rt_load_idt: lidt (%rdi) sti ret diff --git a/Private/HALKit/AMD64/HardwareAPIC.cpp b/Private/HALKit/AMD64/HardwareAPIC.cpp deleted file mode 100644 index 6d77a8b5..00000000 --- a/Private/HALKit/AMD64/HardwareAPIC.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -// bugs = 0 - -namespace HCore { -// @brief wakes up thread. -// wakes up thread from hang. -void rt_wakeup_thread(HAL::StackFrame* stack) { - __asm__ volatile("cli"); - - stack->Rbp = stack->R15; - stack->Rsi = stack->Rbp; - - __asm__ volatile("sti"); -} - -static void __rt_hang_proc(void) { - while (1) - ; -} - -// @brief makes thread sleep. -// hooks and hangs thread to prevent code from executing. -void rt_hang_thread(HAL::StackFrame* stack) { - __asm__ volatile("cli"); - - stack->R15 = stack->Rbp; - stack->Rbp = (HAL::Reg)&__rt_hang_proc; - stack->Rsp = stack->Rbp; - - __asm__ volatile("sti"); -} -} // namespace HCore diff --git a/Private/HALKit/AMD64/HardwareInit.cpp b/Private/HALKit/AMD64/HardwareInit.cpp deleted file mode 100644 index 1856cc2d..00000000 --- a/Private/HALKit/AMD64/HardwareInit.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -// bugs = 0 - -namespace HCore { -bool ke_init_hal() { - // TODO: Hardware Specific stuff. - - return true; -} -} // namespace HCore diff --git a/Private/HALKit/AMD64/PlatformAMD64.cpp b/Private/HALKit/AMD64/PlatformAMD64.cpp deleted file mode 100644 index 1c0d560d..00000000 --- a/Private/HALKit/AMD64/PlatformAMD64.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -namespace HCore::HAL { -namespace Detail { -struct RegisterAMD64 final { - UIntPtr base; - UShort limit; -}; -} // namespace Detail - -void GDTLoader::Load(Register64 &gdt) { - Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); - MUST_PASS(reg); - - reg->base = gdt.Base; - reg->limit = gdt.Limit; - - rt_cli(); - load_gdt(reg); - rt_sti(); -} - -void IDTLoader::Load(Register64 &idt) { - Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); - MUST_PASS(reg); - - reg->base = idt.Base; - reg->limit = idt.Limit; - - rt_cli(); - load_idt(reg); - rt_sti(); -} - -void GDTLoader::Load(Ref &gdt) { GDTLoader::Load(gdt.Leak()); } - -void IDTLoader::Load(Ref &idt) { IDTLoader::Load(idt.Leak()); } -} // namespace HCore::HAL diff --git a/Private/HALKit/AMD64/ProcessPrimitives.cxx b/Private/HALKit/AMD64/ProcessPrimitives.cxx deleted file mode 100644 index 8d0554f3..00000000 --- a/Private/HALKit/AMD64/ProcessPrimitives.cxx +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -#include "NewKit/Defines.hpp" - -using namespace HCore; - -Void Process::AssignStart(UIntPtr &imageStart) noexcept { - if (imageStart == 0) this->Crash(); - -#ifdef __x86_64__ - this->StackFrame->Rbp = imageStart; -#elif defined(__powerpc) - // link return register towards the __start symbol. - this->StackFrame->R3 = imageStart; -#endif -} diff --git a/Private/HALKit/AMD64/Processor.cpp b/Private/HALKit/AMD64/Processor.cpp deleted file mode 100644 index 3d509f79..00000000 --- a/Private/HALKit/AMD64/Processor.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include - -/** - * @file Processor.cpp - * @brief This file is about processor specific functions (in/out...) - */ - -namespace HCore::HAL { -void out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -void out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -void out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -UInt8 in8(UInt16 port) { - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -UInt16 in16(UInt16 port) { - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -UInt32 in32(UInt16 port) { - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -void rt_halt() { asm volatile("hlt"); } - -void rt_cli() { asm volatile("cli"); } - -void rt_sti() { asm volatile("sti"); } - -void rt_cld() { asm volatile("cld"); } -} // namespace HCore::HAL diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index dc258bcc..bab1d518 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -86,15 +86,24 @@ using InterruptDescriptorArray = Array; class SegmentDescriptor final { public: - UIntPtr Base; - UIntPtr BaseMiddle; - UIntPtr BaseHigh; + UInt16 Base; + UInt8 BaseMiddle; + UInt8 BaseHigh; UShort Limit; UChar Gran; - UChar AB; + UChar AccessByte; +}; - operator bool() { return Base > Limit; } +/*** + * @brief Segment Boolean operations + */ +class SegmentDescriptorComparator final { + public: + bool IsValid(SegmentDescriptor &seg) { return seg.Base > seg.Limit; } + bool Equals(SegmentDescriptor &seg, SegmentDescriptor &segRight) { + return seg.Base == segRight.Base && seg.Limit == segRight.Limit; + } }; using SegmentArray = Array; @@ -116,8 +125,9 @@ void system_get_cores(voidPtr rsdPtr); extern "C" void idt_handle_system_call(HCore::UIntPtr rsp); extern "C" void idt_handle_generic(HCore::UIntPtr rsp); -extern "C" void load_idt(HCore::voidPtr ptr); -extern "C" void load_gdt(HCore::voidPtr ptr); extern "C" void idt_handle_gpf(HCore::UIntPtr rsp); extern "C" void idt_handle_math(HCore::UIntPtr rsp); extern "C" void idt_handle_pf(HCore::UIntPtr rsp); + +extern "C" void rt_load_idt(HCore::voidPtr ptr); +extern "C" void rt_load_gdt(HCore::voidPtr ptr); diff --git a/Private/HALKit/PowerPC/HalHardware.cpp b/Private/HALKit/PowerPC/HalHardware.cpp new file mode 100644 index 00000000..04676eff --- /dev/null +++ b/Private/HALKit/PowerPC/HalHardware.cpp @@ -0,0 +1,48 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include + +extern "C" void flush_tlb() {} +extern "C" void rt_wait_for_io() {} +extern "C" HCore::HAL::StackFrame* rt_get_current_context() {} + +namespace HCore { +namespace HAL { +UIntPtr hal_create_page(bool rw, bool user) { return 0; } + +UIntPtr hal_alloc_page(UIntPtr offset, bool rw, bool user) { return 0; } +} // namespace HAL + +// @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) {} + +// @brief main HAL entrypoint +void ke_init_hal() {} + +void system_io_print(const char* bytes) { + if (!bytes) return; + + SizeT index = 0; + SizeT len = string_length(bytes, 256); + + while (index < len) { + // TODO + ++index; + } +} + +TerminalDevice kcout(HCore::system_io_print, nullptr); +} // namespace HCore diff --git a/Private/HALKit/PowerPC/Processor.cpp b/Private/HALKit/PowerPC/Processor.cpp deleted file mode 100644 index 04676eff..00000000 --- a/Private/HALKit/PowerPC/Processor.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include - -extern "C" void flush_tlb() {} -extern "C" void rt_wait_for_io() {} -extern "C" HCore::HAL::StackFrame* rt_get_current_context() {} - -namespace HCore { -namespace HAL { -UIntPtr hal_create_page(bool rw, bool user) { return 0; } - -UIntPtr hal_alloc_page(UIntPtr offset, bool rw, bool user) { return 0; } -} // namespace HAL - -// @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) {} - -// @brief main HAL entrypoint -void ke_init_hal() {} - -void system_io_print(const char* bytes) { - if (!bytes) return; - - SizeT index = 0; - SizeT len = string_length(bytes, 256); - - while (index < len) { - // TODO - ++index; - } -} - -TerminalDevice kcout(HCore::system_io_print, nullptr); -} // namespace HCore diff --git a/Private/HALKit/PowerPC/StartSequence.s b/Private/HALKit/PowerPC/StartSequence.s index 0b9807d0..112ac73f 100644 --- a/Private/HALKit/PowerPC/StartSequence.s +++ b/Private/HALKit/PowerPC/StartSequence.s @@ -1,6 +1,6 @@ -.globl __AssemblerStart +.globl Main .align 4 .text -__AssemblerStart: - b __AssemblerStart +Main: + b Main diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index d6c7ec87..161049c1 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -7,8 +7,8 @@ * ======================================================== */ -#ifndef __PEF_HPP__ -#define __PEF_HPP__ +#ifndef __PEF__ +#define __PEF__ #include #include @@ -86,4 +86,4 @@ enum { #define kPefStart "__start" -#endif /* ifndef __PEF_HPP__ */ +#endif /* ifndef __PEF__ */ 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 #include +#include #include #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 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 Shared(); - - private: - Array 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 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 Shared(); + + private: + Array 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 diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index 862226c2..5a34572b 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -26,7 +26,7 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, // TODO: Jump Code EFI::ExitBootServices(SystemTable, mapKey, ImageHandle); - EFI::Stop(SystemTable); + EFI::Stop(); return kEfiOk; } diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx index 94a483c5..15c68adc 100644 --- a/Private/Source/RuntimeMain.cxx +++ b/Private/Source/RuntimeMain.cxx @@ -19,6 +19,7 @@ extern "C" void (*__SYSTEM_FINI)(); extern "C" void (**__SYSTEM_INIT)(); extern "C" void RuntimeMain() { + /// Init C++ globals for (HCore::SizeT index_init = 0UL; __SYSTEM_INIT[index_init] != __SYSTEM_FINI; ++index_init) { __SYSTEM_INIT[index_init](); @@ -30,7 +31,7 @@ extern "C" void RuntimeMain() { HCore::ke_init_ke_heap(); HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); - HCore::PEFLoader img("/System/Seeker.cm"); + HCore::PEFLoader img("/System/Shell.exe"); if (!HCore::Utils::execute_from_image(img)) { HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx index 9dd38d33..6e935fb1 100644 --- a/Private/Source/SMPManager.cxx +++ b/Private/Source/SMPManager.cxx @@ -13,45 +13,45 @@ /// BUGS: 0 -//! This file handles multi processing in HCore. -//! Multi processing is needed for File I/O, networking and scheduling. +///! @brief This file handles multi processing in HCore. +///! @brief Multi processing is needed for multi-tasking operations. namespace HCore { -// A ProcessorCore class takes care of it's owned hardware thread. +// A HardwareThread class takes care of it's owned hardware thread. // It has a stack for it's core. // @brief constructor -ProcessorCore::ProcessorCore() = default; +HardwareThread::HardwareThread() = default; // @brief destructor -ProcessorCore::~ProcessorCore() = default; +HardwareThread::~HardwareThread() = default; //! @brief returns the id -const ThreadID& ProcessorCore::ID() noexcept { return m_ID; } +const ThreadID& HardwareThread::ID() noexcept { return m_ID; } //! @brief returns the kind -const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; } +const ThreadKind& HardwareThread::Kind() noexcept { return m_Kind; } //! @brief is the core busy? -bool ProcessorCore::IsBusy() noexcept { return m_Busy; } +bool HardwareThread::IsBusy() noexcept { return m_Busy; } /// @brief Get processor stack frame. -HAL::StackFrame* ProcessorCore::StackFrame() noexcept { +HAL::StackFrame* HardwareThread::StackFrame() noexcept { MUST_PASS(m_Stack); return m_Stack; } -void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; } +void HardwareThread::Busy(const bool busy) noexcept { m_Busy = busy; } -ProcessorCore::operator bool() { return m_Stack; } +HardwareThread::operator bool() { return m_Stack; } /// @brief Wakeup the processor. -void ProcessorCore::Wake(const bool wakeup) noexcept { +void HardwareThread::Wake(const bool wakeup) noexcept { m_Wakeup = wakeup; if (!m_Wakeup) @@ -60,14 +60,14 @@ void ProcessorCore::Wake(const bool wakeup) noexcept { rt_wakeup_thread(m_Stack); } -bool ProcessorCore::Switch(HAL::StackFrame* stack) { +bool HardwareThread::Switch(HAL::StackFrame* stack) { if (stack == nullptr) return false; return rt_do_context_switch(m_Stack, stack) == 0; } ///! @brief Tells if processor is waked up. -bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; } +bool HardwareThread::IsWakeup() noexcept { return m_Wakeup; } //! @brief Constructor and destructor @@ -125,7 +125,7 @@ bool SMPManager::Switch(HAL::StackFrame* stack) { * @param idx the index * @return the reference to the hardware thread. */ -Ref SMPManager::operator[](const SizeT& idx) { +Ref SMPManager::operator[](const SizeT& idx) { return m_ThreadList[idx].Leak(); } -- cgit v1.2.3