From 46a885ad913aa24543efb154886919ad30182229 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 6 Dec 2024 15:53:20 +0100 Subject: META: Friday bump. Signed-off-by: Amlal --- dev/HintKit/CompilerHint.h | 25 ++++++++ dev/SCIKit/CompilerHint.h | 6 +- dev/ZBAKit/src/BootString.cc | 2 +- dev/ZBAKit/src/BootTextWriter.cc | 2 +- dev/ZKAKit/CompressKit/GZip.h | 4 +- dev/ZKAKit/CompressKit/RLE.h | 4 +- dev/ZKAKit/HALKit/AMD64/HalAP.cc | 51 ++++++++++++++++ .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 2 +- dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc | 46 -------------- dev/ZKAKit/HALKit/ARM64/AP.h | 36 +++++++++++ dev/ZKAKit/HALKit/ARM64/HalAP.cc | 40 ++++++++++++ dev/ZKAKit/HALKit/ARM64/HalSchedulerCore.cc | 34 +++++++++++ dev/ZKAKit/HALKit/POWER/AP.h | 39 ++++++++++++ dev/ZKAKit/HALKit/POWER/HalAP.cc | 40 ++++++++++++ dev/ZKAKit/HALKit/POWER/HalHart.cc | 25 -------- dev/ZKAKit/HALKit/POWER/Hart.h | 36 ----------- dev/ZKAKit/HALKit/RISCV/AP.h | 36 +++++++++++ dev/ZKAKit/HALKit/RISCV/HalAP.cc | 40 ++++++++++++ dev/ZKAKit/HALKit/RISCV/Hart.h | 24 -------- dev/ZKAKit/HintKit/CompilerHint.h | 25 -------- dev/ZKAKit/KernelKit/HardwareThreadScheduler.h | 20 +++--- dev/ZKAKit/KernelKit/UserProcessScheduler.h | 2 +- dev/ZKAKit/NetworkKit/LTE.h | 2 +- dev/ZKAKit/NewKit/Defines.h | 41 ++++++++----- dev/ZKAKit/POSIXKit/signal.h | 20 ++++++ dev/ZKAKit/POSIXKit/unix_layer.h | 11 ++++ dev/ZKAKit/PosixKit/Signals.h | 16 ----- dev/ZKAKit/src/FS/HPFS.cc | 2 +- dev/ZKAKit/src/HardwareThreadScheduler.cc | 71 +++++++++++++++++----- dev/ZKAKit/src/ThreadLocalStorage.cc | 4 +- dev/ZKAKit/src/UserProcessScheduler.cc | 9 ++- 31 files changed, 484 insertions(+), 231 deletions(-) create mode 100644 dev/HintKit/CompilerHint.h create mode 100644 dev/ZKAKit/HALKit/AMD64/HalAP.cc delete mode 100644 dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc create mode 100644 dev/ZKAKit/HALKit/ARM64/AP.h create mode 100644 dev/ZKAKit/HALKit/ARM64/HalAP.cc create mode 100644 dev/ZKAKit/HALKit/ARM64/HalSchedulerCore.cc create mode 100644 dev/ZKAKit/HALKit/POWER/AP.h create mode 100644 dev/ZKAKit/HALKit/POWER/HalAP.cc delete mode 100644 dev/ZKAKit/HALKit/POWER/HalHart.cc delete mode 100644 dev/ZKAKit/HALKit/POWER/Hart.h create mode 100644 dev/ZKAKit/HALKit/RISCV/AP.h create mode 100644 dev/ZKAKit/HALKit/RISCV/HalAP.cc delete mode 100644 dev/ZKAKit/HALKit/RISCV/Hart.h delete mode 100644 dev/ZKAKit/HintKit/CompilerHint.h create mode 100644 dev/ZKAKit/POSIXKit/signal.h create mode 100644 dev/ZKAKit/POSIXKit/unix_layer.h delete mode 100644 dev/ZKAKit/PosixKit/Signals.h (limited to 'dev') diff --git a/dev/HintKit/CompilerHint.h b/dev/HintKit/CompilerHint.h new file mode 100644 index 00000000..c3205307 --- /dev/null +++ b/dev/HintKit/CompilerHint.h @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef HINTKIT_HINT_H +#define HINTKIT_HINT_H + +#ifdef __TK__ +#pragma compiler(hint_manifest) +#endif + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut + +#endif // ifndef HINTKIT_HINT_H diff --git a/dev/SCIKit/CompilerHint.h b/dev/SCIKit/CompilerHint.h index 8afa1750..319e924c 100644 --- a/dev/SCIKit/CompilerHint.h +++ b/dev/SCIKit/CompilerHint.h @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef __SCI_HINT_H__ -#define __SCI_HINT_H__ +#ifndef SCI_HINT_H +#define SCI_HINT_H #ifdef __TK__ #pragma compiler(hint_manifest) @@ -22,4 +22,4 @@ #define _InOut #define _StrictInOut -#endif // ifndef __SCI_HINT_H__ +#endif // ifndef SCI_HINT_H diff --git a/dev/ZBAKit/src/BootString.cc b/dev/ZBAKit/src/BootString.cc index e60235f9..ce9a5898 100644 --- a/dev/ZBAKit/src/BootString.cc +++ b/dev/ZBAKit/src/BootString.cc @@ -2,7 +2,7 @@ Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - File: String.cc + File: BootString.cc Purpose: ZBA string library Revision History: diff --git a/dev/ZBAKit/src/BootTextWriter.cc b/dev/ZBAKit/src/BootTextWriter.cc index 13ed41cc..df33f5fe 100644 --- a/dev/ZBAKit/src/BootTextWriter.cc +++ b/dev/ZBAKit/src/BootTextWriter.cc @@ -2,7 +2,7 @@ Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - File: String.cc + File: BootTextWriter.cc Purpose: ZBA string library Revision History: diff --git a/dev/ZKAKit/CompressKit/GZip.h b/dev/ZKAKit/CompressKit/GZip.h index 834bd1af..f99742f6 100644 --- a/dev/ZKAKit/CompressKit/GZip.h +++ b/dev/ZKAKit/CompressKit/GZip.h @@ -11,8 +11,8 @@ namespace Kernel::GZip { - class IGZipObject; - class IGZipProxy; + class IGZIPObject; + class IGZIPProxy; } // namespace Kernel::GZip #endif // !COMPRESSKIT_GZIP_H diff --git a/dev/ZKAKit/CompressKit/RLE.h b/dev/ZKAKit/CompressKit/RLE.h index 33a29e8d..95eebabd 100644 --- a/dev/ZKAKit/CompressKit/RLE.h +++ b/dev/ZKAKit/CompressKit/RLE.h @@ -11,8 +11,8 @@ namespace Kernel { - class IRleObject; - class IRleProxy; + class IRLEObject; + class IRLEProxy; } // namespace Kernel #endif // !ifndef COMPRESSKIT_RLE_H diff --git a/dev/ZKAKit/HALKit/AMD64/HalAP.cc b/dev/ZKAKit/HALKit/AMD64/HalAP.cc new file mode 100644 index 00000000..3405ea32 --- /dev/null +++ b/dev/ZKAKit/HALKit/AMD64/HalAP.cc @@ -0,0 +1,51 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +namespace Kernel +{ + /***********************************************************************************/ + /// @brief Unimplemented function (crashes by default) + /// @param + /***********************************************************************************/ + + EXTERN_C Void __zka_pure_call(void) + { + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + } + + /***********************************************************************************/ + /// @brief Validate user stack. + /// @param stack_ptr the frame pointer. + /***********************************************************************************/ + + Bool hal_check_stack(HAL::StackFramePtr stack_ptr) + { + if (!stack_ptr) + return No; + + return stack_ptr->SP != 0 && stack_ptr->BP != 0; + } + + /// @brief Wakes up thread. + /// Wakes up thread from the hang state. + Void mp_wakeup_thread(HAL::StackFrame* stack) + { + Kernel::UserProcessHelper::StartScheduling(); + } + + /// @brief makes the thread sleep on a loop. + /// hooks and hangs thread to prevent code from executing. + Void mp_hang_thread(HAL::StackFrame* stack) + { + while (Yes) + { + /* Nothing to do, code is spinning */ + } + } +} // namespace Kernel diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index b75f37ce..b5c35372 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -7,7 +7,7 @@ #include #include #include -#include +#include /// @brief Handle GPF fault. /// @param rsp diff --git a/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc deleted file mode 100644 index 4ab8671f..00000000 --- a/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -namespace Kernel -{ - /***********************************************************************************/ - /// @brief Unimplemented function (crashes by default) - /// @param - /***********************************************************************************/ - - EXTERN_C Void __zka_pure_call(void) - { - UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); - } - - Bool hal_check_stack(HAL::StackFramePtr stack_ptr) - { - if (!stack_ptr) - return No; - - return Yes; - } - - /// @brief Wakes up thread. - /// Wakes up thread from the hang state. - Void mp_wakeup_thread(HAL::StackFrame* stack) - { - Kernel::UserProcessHelper::StartScheduling(); - } - - /// @brief makes the thread sleep on a loop. - /// hooks and hangs thread to prevent code from executing. - Void mp_hang_thread(HAL::StackFrame* stack) - { - while (Yes) - { - /* Nothing to do, code is spinning */ - } - } -} // namespace Kernel diff --git a/dev/ZKAKit/HALKit/ARM64/AP.h b/dev/ZKAKit/HALKit/ARM64/AP.h new file mode 100644 index 00000000..ac2e7d21 --- /dev/null +++ b/dev/ZKAKit/HALKit/ARM64/AP.h @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + + File: AP.h + Purpose: RISC-V hardware threads. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel +{ + typedef Int64 hal_ap_kind; + + typedef struct HAL_HARDWARE_THREAD + { + Kernel::UIntPtr fStartAddress; + Kernel::UInt8 fPrivleged : 1; + Kernel::UInt32 fPageMemoryFlags; + hal_ap_kind fIdentNumber; + } HAL_HARDWARE_THREAD; + + /// @brief Set PC to specific hart. + /// @param hart the hart + /// @param epc the pc. + /// @return + EXTERN_C Kernel::Void hal_set_pc_to_hart(HAL_HARDWARE_THREAD* hart, Kernel::VoidPtr epc); + +} // namespace Kernel \ No newline at end of file diff --git a/dev/ZKAKit/HALKit/ARM64/HalAP.cc b/dev/ZKAKit/HALKit/ARM64/HalAP.cc new file mode 100644 index 00000000..dd4ecea4 --- /dev/null +++ b/dev/ZKAKit/HALKit/ARM64/HalAP.cc @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; + +namespace Kernel::Details +{ + STATIC void mp_hang_fn(void) + { + while (YES) + ; + } +} // namespace Kernel::Details + +/// @brief wakes up thread. +/// wakes up thread from hang. +void mp_wakeup_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(stack->BP)); +} + +/// @brief makes thread sleep. +/// hooks and hangs thread to prevent code from executing. +void mp_hang_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(Kernel::Details::mp_hang_fn)); +} diff --git a/dev/ZKAKit/HALKit/ARM64/HalSchedulerCore.cc b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCore.cc new file mode 100644 index 00000000..a0088958 --- /dev/null +++ b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCore.cc @@ -0,0 +1,34 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +namespace Kernel +{ + /***********************************************************************************/ + /// @brief Unimplemented function (crashes by default) + /// @param void + /***********************************************************************************/ + + EXTERN_C Void __zka_pure_call(void) + { + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + } + + /***********************************************************************************/ + /// @brief Validate user stack. + /// @param stack_ptr the frame pointer. + /***********************************************************************************/ + + Bool hal_check_stack(HAL::StackFramePtr stack_ptr) + { + if (!stack_ptr) + return No; + + return stack_ptr->SP != 0 && stack_ptr->BP != 0; + } +} // namespace Kernel \ No newline at end of file diff --git a/dev/ZKAKit/HALKit/POWER/AP.h b/dev/ZKAKit/HALKit/POWER/AP.h new file mode 100644 index 00000000..10cf97ba --- /dev/null +++ b/dev/ZKAKit/HALKit/POWER/AP.h @@ -0,0 +1,39 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + + File: AP.h + Purpose: POWER hardware threads. + + Revision History: + + 14/04/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel +{ + struct HAL_HARDWARE_THREAD; + + /// @brief hardware thread indentification type. + typedef Kernel::Int32 hal_ap_kind; + + /// @brief Hardware thread information structure. + typedef struct HAL_HARDWARE_THREAD + { + Kernel::UIntPtr fStartAddress; + Kernel::UInt8 fPrivleged : 1; + Kernel::UInt32 fPageMemoryFlags; + hal_ap_kind fIdentNumber; + } HAL_HARDWARE_THREAD; + + /// @brief Set PC to specific hart. + /// @param hart the hart + /// @param epc the pc. + /// @return + EXTERN_C Kernel::Void hal_set_pc_to_hart(HAL_HARDWARE_THREAD* hart, Kernel::VoidPtr epc); +} // namespace Kernel \ No newline at end of file diff --git a/dev/ZKAKit/HALKit/POWER/HalAP.cc b/dev/ZKAKit/HALKit/POWER/HalAP.cc new file mode 100644 index 00000000..df261d94 --- /dev/null +++ b/dev/ZKAKit/HALKit/POWER/HalAP.cc @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; + +namespace Kernel::Details +{ + STATIC void mp_hang_fn(void) + { + while (YES) + ; + } +} // namespace Kernel::Details + +/// @brief wakes up thread. +/// wakes up thread from hang. +void mp_wakeup_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(stack->BP)); +} + +/// @brief makes thread sleep. +/// hooks and hangs thread to prevent code from executing. +void mp_hang_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(Kernel::Details::mp_hang_fn)); +} diff --git a/dev/ZKAKit/HALKit/POWER/HalHart.cc b/dev/ZKAKit/HALKit/POWER/HalHart.cc deleted file mode 100644 index ed42014a..00000000 --- a/dev/ZKAKit/HALKit/POWER/HalHart.cc +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include -#include - -using namespace Kernel; - -/// @brief wakes up thread. -/// wakes up thread from hang. -void mp_wakeup_thread(HAL::StackFramePtr stack) -{ - ZKA_UNUSED(stack); -} - -/// @brief makes thread sleep. -/// hooks and hangs thread to prevent code from executing. -void mp_hang_thread(HAL::StackFramePtr stack) -{ - ZKA_UNUSED(stack); -} diff --git a/dev/ZKAKit/HALKit/POWER/Hart.h b/dev/ZKAKit/HALKit/POWER/Hart.h deleted file mode 100644 index f3a14737..00000000 --- a/dev/ZKAKit/HALKit/POWER/Hart.h +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - - File: Hart.h - Purpose: POWER hardware threads. - - Revision History: - - 14/04/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -#include - -struct HAL_HARDWARE_THREAD; - -/// @brief hardware thread indentification type. -typedef Kernel::Int32 PPCHartType; - -/// @brief Hardware thread information structure. -typedef struct HAL_HARDWARE_THREAD -{ - Kernel::UIntPtr fStartAddress; - Kernel::UInt8 fPrivleged : 1; - Kernel::UInt32 fPagkMMFlags; - PPCHartType fIdentNumber; -} HAL_HARDWARE_THREAD; - -/// @brief Set PC to specific hart. -/// @param hart the hart -/// @param epc the pc. -/// @return -EXTERN_C Kernel::Void hal_set_pc_to_hart(HAL_HARDWARE_THREAD* hart, Kernel::VoidPtr epc); diff --git a/dev/ZKAKit/HALKit/RISCV/AP.h b/dev/ZKAKit/HALKit/RISCV/AP.h new file mode 100644 index 00000000..ac2e7d21 --- /dev/null +++ b/dev/ZKAKit/HALKit/RISCV/AP.h @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + + File: AP.h + Purpose: RISC-V hardware threads. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel +{ + typedef Int64 hal_ap_kind; + + typedef struct HAL_HARDWARE_THREAD + { + Kernel::UIntPtr fStartAddress; + Kernel::UInt8 fPrivleged : 1; + Kernel::UInt32 fPageMemoryFlags; + hal_ap_kind fIdentNumber; + } HAL_HARDWARE_THREAD; + + /// @brief Set PC to specific hart. + /// @param hart the hart + /// @param epc the pc. + /// @return + EXTERN_C Kernel::Void hal_set_pc_to_hart(HAL_HARDWARE_THREAD* hart, Kernel::VoidPtr epc); + +} // namespace Kernel \ No newline at end of file diff --git a/dev/ZKAKit/HALKit/RISCV/HalAP.cc b/dev/ZKAKit/HALKit/RISCV/HalAP.cc new file mode 100644 index 00000000..05cd2f8a --- /dev/null +++ b/dev/ZKAKit/HALKit/RISCV/HalAP.cc @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; + +namespace Kernel::Details +{ + STATIC void mp_hang_fn(void) + { + while (YES) + ; + } +} // namespace Kernel::Details + +/// @brief wakes up thread. +/// wakes up thread from hang. +void mp_wakeup_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(stack->BP)); +} + +/// @brief makes thread sleep. +/// hooks and hangs thread to prevent code from executing. +void mp_hang_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(Kernel::Details::mp_hang_fn)); +} diff --git a/dev/ZKAKit/HALKit/RISCV/Hart.h b/dev/ZKAKit/HALKit/RISCV/Hart.h deleted file mode 100644 index 6249cf7b..00000000 --- a/dev/ZKAKit/HALKit/RISCV/Hart.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - - File: Hart.h - Purpose: RISC-V hardware threads. - - Revision History: - - 30/01/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -#include - -typedef Kernel::Int32 Rv64HartType; - -/// @brief Set PC to specific hart. -/// @param hart the hart -/// @param epc the pc. -/// @return -EXTERN_C Kernel::Void hal_set_pc_to_hart(Rv64HartType hart, Kernel::VoidPtr epc); diff --git a/dev/ZKAKit/HintKit/CompilerHint.h b/dev/ZKAKit/HintKit/CompilerHint.h deleted file mode 100644 index 00afc9fa..00000000 --- a/dev/ZKAKit/HintKit/CompilerHint.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifndef __HINTKIT_COMPILER_HINT_H__ -#define __HINTKIT_COMPILER_HINT_H__ - -#ifdef __TK__ -#pragma compiler(hint_manifest) -#endif - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut - -#endif // ifndef __HINTKIT_COMPILER_HINT_H__ diff --git a/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h b/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h index c020f4d4..44ea1042 100644 --- a/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h +++ b/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h @@ -14,7 +14,7 @@ /// @note Last Rev Sun 28 Jul CET 2024 /// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM -#define kMaxHartInsideSched (8U) +#define kMaxAPInsideSched (8U) namespace Kernel { @@ -25,13 +25,13 @@ namespace Kernel enum ThreadKind { - kHartSystemReserved, // System reserved thread, well user can't use it - kHartStandard, // user thread, cannot be used by Kernel - kHartFallback, // fallback thread, cannot be used by user if not clear or + kAPSystemReserved, // System reserved thread, well user can't use it + kAPStandard, // user thread, cannot be used by Kernel + kAPFallback, // fallback thread, cannot be used by user if not clear or // used by Kernel. - kHartBoot, // The core we booted from, the mama. - kInvalidHart, - kHartCount, + kAPBoot, // The core we booted from, the mama. + kInvalidAP, + kAPCount, }; typedef enum ThreadKind ThreadKind; @@ -72,7 +72,7 @@ namespace Kernel private: HAL::StackFramePtr fStack{nullptr}; - ThreadKind fKind{ThreadKind::kHartStandard}; + ThreadKind fKind{ThreadKind::kAPStandard}; ThreadID fID{0}; ProcessID fSourcePID{-1}; Bool fWakeup{false}; @@ -89,7 +89,7 @@ namespace Kernel /// \brief Class to manage the thread scheduling. /// - class HardwareThreadScheduler final : public ISchedulerObject + class HardwareThreadScheduler final : public ISchedulable { private: friend class UserProcessHelper; @@ -133,7 +133,7 @@ namespace Kernel SizeT Capacity() noexcept; private: - Array fThreadList; + Array fThreadList; ThreadID fCurrentThread{0}; }; diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h index 59e1a525..a974fa3a 100644 --- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h +++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h @@ -273,7 +273,7 @@ namespace Kernel /// @brief Process scheduler class. /// The main class which you call to schedule user processes. - class UserProcessScheduler final : public ISchedulerObject + class UserProcessScheduler final : public ISchedulable { friend class UserProcessHelper; diff --git a/dev/ZKAKit/NetworkKit/LTE.h b/dev/ZKAKit/NetworkKit/LTE.h index c6c01f64..7aa99ec6 100644 --- a/dev/ZKAKit/NetworkKit/LTE.h +++ b/dev/ZKAKit/NetworkKit/LTE.h @@ -11,6 +11,6 @@ #define _INC_NETWORK_LTE_H_ #include -#include +#include #endif // ifndef _INC_NETWORK_LTE_H_ diff --git a/dev/ZKAKit/NewKit/Defines.h b/dev/ZKAKit/NewKit/Defines.h index 142e552e..9a11eed0 100644 --- a/dev/ZKAKit/NewKit/Defines.h +++ b/dev/ZKAKit/NewKit/Defines.h @@ -81,7 +81,7 @@ namespace Kernel kEndianBig, kEndianLittle, kEndianMixed, - kCount + kEndianCount }; /// @brief Forward object. @@ -106,14 +106,14 @@ namespace Kernel /// @brief Encoding interface, used as a proxy to convert T to Char* /// Used to cast A to B or B to A. - class IEncoderObject + class ICodec { public: - explicit IEncoderObject() = default; - virtual ~IEncoderObject() = default; + explicit ICodec() = default; + virtual ~ICodec() = default; - IEncoderObject& operator=(const IEncoderObject&) = default; - IEncoderObject(const IEncoderObject&) = default; + ICodec& operator=(const ICodec&) = default; + ICodec(const ICodec&) = default; public: /// @brief Convert type to bytes. @@ -126,6 +126,17 @@ namespace Kernel return nullptr; } + /// @brief Construct from type to class. + /// @tparam T the type to convert. + /// @param type (a1) the data. + /// @return a1 as Char* + template + OutputClass* Construct(Char* type) noexcept + { + FactoryClass class_fac; + return class_fac.template From(type); + } + /// @brief Convert T class to Y class. /// @tparam T the class type of type. /// @tparam Y the result class. @@ -134,7 +145,7 @@ namespace Kernel template Y As(T type) noexcept { - if (type.IsSerializable()) + if (type.template IsSerializable()) { return reinterpret_cast(type); } @@ -145,31 +156,31 @@ namespace Kernel /// \brief Scheduler interface, represents a scheduler object. /// @note This is used to schedule tasks, such as threads, drivers, user threads, etc. - class ISchedulerObject + class ISchedulable { public: - explicit ISchedulerObject() = default; - virtual ~ISchedulerObject() = default; + explicit ISchedulable() = default; + virtual ~ISchedulable() = default; - ISchedulerObject& operator=(const ISchedulerObject&) = default; - ISchedulerObject(const ISchedulerObject&) = default; + ISchedulable& operator=(const ISchedulable&) = default; + ISchedulable(const ISchedulable&) = default; /// @brief Is this object only accepting user tasks? virtual const Bool IsUser() { - return false; + return NO; } /// @brief Is this object only accepting kernel tasks? virtual const Bool IsKernel() { - return false; + return NO; } /// @brief Is this object offloading to another CPU? virtual const Bool HasMP() { - return false; + return NO; } }; } // namespace Kernel diff --git a/dev/ZKAKit/POSIXKit/signal.h b/dev/ZKAKit/POSIXKit/signal.h new file mode 100644 index 00000000..6698ff34 --- /dev/null +++ b/dev/ZKAKit/POSIXKit/signal.h @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +/** https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html */ + +#include + +typedef Kernel::UInt32 signal_t; + +#define SIGKILL 0 +#define SIGPAUS 1 +#define SIGEXEC 2 +#define SIGTRAP 3 +#define SIGABRT 4 +#define SIGCONT 5 \ No newline at end of file diff --git a/dev/ZKAKit/POSIXKit/unix_layer.h b/dev/ZKAKit/POSIXKit/unix_layer.h new file mode 100644 index 00000000..c278aa19 --- /dev/null +++ b/dev/ZKAKit/POSIXKit/unix_layer.h @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include diff --git a/dev/ZKAKit/PosixKit/Signals.h b/dev/ZKAKit/PosixKit/Signals.h deleted file mode 100644 index 57a27268..00000000 --- a/dev/ZKAKit/PosixKit/Signals.h +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -typedef Kernel::UInt32 signal_t; - -#define SIGKILL 0 -#define SIGPAUS 1 -#define SIGEXEC 2 -#define SIGTRAP 3 \ No newline at end of file diff --git a/dev/ZKAKit/src/FS/HPFS.cc b/dev/ZKAKit/src/FS/HPFS.cc index e08ee5a7..58478dea 100644 --- a/dev/ZKAKit/src/FS/HPFS.cc +++ b/dev/ZKAKit/src/FS/HPFS.cc @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/ZKAKit/src/HardwareThreadScheduler.cc b/dev/ZKAKit/src/HardwareThreadScheduler.cc index e06942d9..036fa898 100644 --- a/dev/ZKAKit/src/HardwareThreadScheduler.cc +++ b/dev/ZKAKit/src/HardwareThreadScheduler.cc @@ -9,39 +9,56 @@ #include #include -///! BUGS: 0 - -///! @file MP.cc +/***********************************************************************************/ +///! @file HardwareThreadScheduler.cc ///! @brief This file handles multi processing in the Kernel. ///! @brief Multi processing is needed for multi-tasking operations. +/***********************************************************************************/ namespace Kernel { - HardwareThreadScheduler kHardwareThreadScheduler; + /***********************************************************************************/ + /// @note Those symbols are needed in order to switch and validate the stack. + /***********************************************************************************/ + + EXTERN Bool hal_check_stack(HAL::StackFramePtr frame_ptr); + EXTERN_C Bool mp_register_process(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, ProcessID pid); + + STATIC HardwareThreadScheduler kHardwareThreadScheduler; ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. + /***********************************************************************************/ ///! @brief C++ constructor. + /***********************************************************************************/ HardwareThread::HardwareThread() = default; + /***********************************************************************************/ ///! @brief C++ destructor. + /***********************************************************************************/ HardwareThread::~HardwareThread() = default; + /***********************************************************************************/ //! @brief returns the id of the thread. + /***********************************************************************************/ const ThreadID& HardwareThread::ID() noexcept { return fID; } + /***********************************************************************************/ //! @brief returns the kind of thread we have. + /***********************************************************************************/ const ThreadKind& HardwareThread::Kind() noexcept { return fKind; } + /***********************************************************************************/ //! @brief is the thread busy? //! @return whether the thread is busy or not. + /***********************************************************************************/ Bool HardwareThread::IsBusy() noexcept { STATIC Int64 busy_timer = 0U; @@ -57,7 +74,9 @@ namespace Kernel return fBusy; } + /***********************************************************************************/ /// @brief Get processor stack frame. + /***********************************************************************************/ HAL::StackFramePtr HardwareThread::StackFrame() noexcept { @@ -72,10 +91,12 @@ namespace Kernel HardwareThread::operator bool() { - return fStack; + return this->fStack && !this->fBusy; } + /***********************************************************************************/ /// @brief Wakeup the processor. + /***********************************************************************************/ Void HardwareThread::Wake(const bool wakeup) noexcept { @@ -87,15 +108,12 @@ namespace Kernel mp_wakeup_thread(fStack); } - /// @note Those symbols are needed in order to switch and validate the stack. - - EXTERN Bool hal_check_stack(HAL::StackFramePtr frame_ptr); - EXTERN_C Bool mp_register_process(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, ProcessID pid); - + /***********************************************************************************/ /// @brief Switch to hardware thread. /// @param stack the new hardware thread. /// @retval true stack was changed, code is running. /// @retval false stack is invalid, previous code is running. + /***********************************************************************************/ Bool HardwareThread::Switch(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, const ProcessID& pid) { if (!frame || @@ -123,47 +141,59 @@ namespace Kernel return ret; } + /***********************************************************************************/ ///! @brief Tells if processor is waked up. + /***********************************************************************************/ bool HardwareThread::IsWakeup() noexcept { return fWakeup; } + /***********************************************************************************/ ///! @brief Constructor and destructors. - ///! @brief Default constructor. + /***********************************************************************************/ + HardwareThreadScheduler::HardwareThreadScheduler() = default; + /***********************************************************************************/ ///! @brief Default destructor. + /***********************************************************************************/ HardwareThreadScheduler::~HardwareThreadScheduler() = default; + /***********************************************************************************/ /// @brief Shared singleton function + /***********************************************************************************/ HardwareThreadScheduler& HardwareThreadScheduler::The() { return kHardwareThreadScheduler; } - /// @brief Get Stack Frame of Core + /***********************************************************************************/ + /// @brief Get Stack Frame of AP. + /***********************************************************************************/ HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept { return fThreadList[fCurrentThread].fStack; } + /***********************************************************************************/ /** * Get Hardware thread at index. * @param idx the index * @return the reference to the hardware thread. */ + /***********************************************************************************/ Ref HardwareThreadScheduler::operator[](const SizeT& idx) { if (idx == 0) { - if (fThreadList[idx].Kind() != kHartSystemReserved) + if (fThreadList[idx].Kind() != kAPSystemReserved) { - fThreadList[idx].fKind = kHartBoot; + fThreadList[idx].fKind = kAPBoot; } } - else if (idx >= kMaxHartInsideSched) + else if (idx >= kMaxAPInsideSched) { static HardwareThread* fakeThread = nullptr; return {fakeThread}; @@ -172,28 +202,37 @@ namespace Kernel return &fThreadList[idx]; } + /***********************************************************************************/ /** * Check if thread pool isn't empty. * @return */ + /***********************************************************************************/ HardwareThreadScheduler::operator bool() noexcept { return !fThreadList.Empty(); } + /***********************************************************************************/ /** * Reverse operator bool * @return */ + /***********************************************************************************/ bool HardwareThreadScheduler::operator!() noexcept { return fThreadList.Empty(); } + /***********************************************************************************/ /// @brief Returns the amount of core present. - /// @return the number of cores. + /// @return the number of APs. + /***********************************************************************************/ SizeT HardwareThreadScheduler::Capacity() noexcept { + if (fThreadList.Empty()) + return 0UL; + return fThreadList.Capacity(); } } // namespace Kernel diff --git a/dev/ZKAKit/src/ThreadLocalStorage.cc b/dev/ZKAKit/src/ThreadLocalStorage.cc index c6089824..5fdf56aa 100644 --- a/dev/ZKAKit/src/ThreadLocalStorage.cc +++ b/dev/ZKAKit/src/ThreadLocalStorage.cc @@ -32,8 +32,8 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* tib_ptr) !tib_ptr->Record) return false; - IEncoderObject encoder; - const char* tib_as_bytes = encoder.AsBytes(tib_ptr); + ICodec encoder; + const Char* tib_as_bytes = encoder.AsBytes(tib_ptr); kcout << "Checking for a valid cookie inside the TIB...\r"; diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc index 3c7e8879..4b24d98a 100644 --- a/dev/ZKAKit/src/UserProcessScheduler.cc +++ b/dev/ZKAKit/src/UserProcessScheduler.cc @@ -515,13 +515,16 @@ namespace Kernel for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { - if (HardwareThreadScheduler::The()[index].Leak()->Kind() == kInvalidHart) + if (!HardwareThreadScheduler::The()[index].Leak()) + continue; + + if (HardwareThreadScheduler::The()[index].Leak()->Kind() == kInvalidAP) continue; if (HardwareThreadScheduler::The()[index].Leak()->Kind() != - ThreadKind::kHartBoot && + ThreadKind::kAPBoot && HardwareThreadScheduler::The()[index].Leak()->Kind() != - ThreadKind::kHartSystemReserved) + ThreadKind::kAPSystemReserved) { PID prev_pid = UserProcessHelper::TheCurrentPID(); UserProcessHelper::TheCurrentPID().Leak().Leak() = new_pid; -- cgit v1.2.3