summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-31 09:42:54 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-31 09:42:54 +0100
commitfc55f0d69d24fb4908cbd811681f2c3fac53614d (patch)
treeba09a2cdbb225df7ba1a9ec5a12bcbb90b673ead /Private
parent7bed9287589293bd9d712d152539591dee0b28c0 (diff)
kernel: add GKit, improve AMD64 HAL.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/EFIKit/EFILib.hxx11
-rw-r--r--Private/HALKit/AMD64/HalHardwareAPIC.cpp (renamed from Private/HALKit/AMD64/HardwareAPIC.cpp)0
-rw-r--r--Private/HALKit/AMD64/HalHardwareInit.cpp (renamed from Private/HALKit/AMD64/HardwareInit.cpp)0
-rw-r--r--Private/HALKit/AMD64/HalPlatformAMD64.cpp (renamed from Private/HALKit/AMD64/PlatformAMD64.cpp)4
-rw-r--r--Private/HALKit/AMD64/HalProcessPrimitives.cxx (renamed from Private/HALKit/AMD64/ProcessPrimitives.cxx)0
-rw-r--r--Private/HALKit/AMD64/HalProcessor.cpp (renamed from Private/HALKit/AMD64/Processor.cpp)0
-rw-r--r--Private/HALKit/AMD64/HalRoutines.s8
-rw-r--r--Private/HALKit/AMD64/Processor.hpp24
-rw-r--r--Private/HALKit/PowerPC/HalHardware.cpp (renamed from Private/HALKit/PowerPC/Processor.cpp)0
-rw-r--r--Private/HALKit/PowerPC/StartSequence.s6
-rw-r--r--Private/KernelKit/PEF.hpp6
-rw-r--r--Private/KernelKit/SMPManager.hpp202
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx2
-rw-r--r--Private/Source/RuntimeMain.cxx3
-rw-r--r--Private/Source/SMPManager.cxx30
15 files changed, 151 insertions, 145 deletions
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 <EFIKit/EFI.hxx>
-#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/HardwareAPIC.cpp b/Private/HALKit/AMD64/HalHardwareAPIC.cpp
index 6d77a8b5..6d77a8b5 100644
--- a/Private/HALKit/AMD64/HardwareAPIC.cpp
+++ b/Private/HALKit/AMD64/HalHardwareAPIC.cpp
diff --git a/Private/HALKit/AMD64/HardwareInit.cpp b/Private/HALKit/AMD64/HalHardwareInit.cpp
index 1856cc2d..1856cc2d 100644
--- a/Private/HALKit/AMD64/HardwareInit.cpp
+++ b/Private/HALKit/AMD64/HalHardwareInit.cpp
diff --git a/Private/HALKit/AMD64/PlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
index 1c0d560d..f72be01f 100644
--- a/Private/HALKit/AMD64/PlatformAMD64.cpp
+++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
@@ -25,7 +25,7 @@ void GDTLoader::Load(Register64 &gdt) {
reg->limit = gdt.Limit;
rt_cli();
- load_gdt(reg);
+ rt_load_gdt(reg);
rt_sti();
}
@@ -37,7 +37,7 @@ void IDTLoader::Load(Register64 &idt) {
reg->limit = idt.Limit;
rt_cli();
- load_idt(reg);
+ rt_load_idt(reg);
rt_sti();
}
diff --git a/Private/HALKit/AMD64/ProcessPrimitives.cxx b/Private/HALKit/AMD64/HalProcessPrimitives.cxx
index 8d0554f3..8d0554f3 100644
--- a/Private/HALKit/AMD64/ProcessPrimitives.cxx
+++ b/Private/HALKit/AMD64/HalProcessPrimitives.cxx
diff --git a/Private/HALKit/AMD64/Processor.cpp b/Private/HALKit/AMD64/HalProcessor.cpp
index 3d509f79..3d509f79 100644
--- a/Private/HALKit/AMD64/Processor.cpp
+++ b/Private/HALKit/AMD64/HalProcessor.cpp
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/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<InterruptDescriptor, 256>;
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<SegmentDescriptor, 6>;
@@ -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/Processor.cpp b/Private/HALKit/PowerPC/HalHardware.cpp
index 04676eff..04676eff 100644
--- a/Private/HALKit/PowerPC/Processor.cpp
+++ b/Private/HALKit/PowerPC/HalHardware.cpp
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 <CompilerKit/CompilerKit.hpp>
#include <KernelKit/Loader.hpp>
@@ -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 <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
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<ProcessorCore> SMPManager::operator[](const SizeT& idx) {
+Ref<HardwareThread> SMPManager::operator[](const SizeT& idx) {
return m_ThreadList[idx].Leak();
}