From f0acad6f3206079d804b2f59aace0dc32dbeb6dc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 19 Feb 2026 08:14:48 +0100 Subject: kernel: lots of tweaks and improvements, WIP: ASN, FileMgr support for OpenHeFS. Signed-off-by: Amlal El Mahrouss --- src/kernel/HALKit/POWER/HalApplicationProcessor.cc | 40 -------------------- .../HALKit/POWER/HalApplicationProcessor.cpp | 40 ++++++++++++++++++++ src/kernel/HALKit/POWER/HalDebugOutput.cc | 22 ----------- src/kernel/HALKit/POWER/HalDebugOutput.cpp | 22 +++++++++++ src/kernel/HALKit/POWER/HalHardwareThread.cc | 6 --- src/kernel/HALKit/POWER/HalHardwareThread.cpp | 6 +++ src/kernel/HALKit/POWER/HalVirtualMemory.cc | 44 ---------------------- src/kernel/HALKit/POWER/HalVirtualMemory.cpp | 44 ++++++++++++++++++++++ 8 files changed, 112 insertions(+), 112 deletions(-) delete mode 100644 src/kernel/HALKit/POWER/HalApplicationProcessor.cc create mode 100644 src/kernel/HALKit/POWER/HalApplicationProcessor.cpp delete mode 100644 src/kernel/HALKit/POWER/HalDebugOutput.cc create mode 100644 src/kernel/HALKit/POWER/HalDebugOutput.cpp delete mode 100644 src/kernel/HALKit/POWER/HalHardwareThread.cc create mode 100644 src/kernel/HALKit/POWER/HalHardwareThread.cpp delete mode 100644 src/kernel/HALKit/POWER/HalVirtualMemory.cc create mode 100644 src/kernel/HALKit/POWER/HalVirtualMemory.cpp (limited to 'src/kernel/HALKit/POWER') diff --git a/src/kernel/HALKit/POWER/HalApplicationProcessor.cc b/src/kernel/HALKit/POWER/HalApplicationProcessor.cc deleted file mode 100644 index 64333086..00000000 --- a/src/kernel/HALKit/POWER/HalApplicationProcessor.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include - -/// @note This part of the HAL needs an owner. - -namespace Kernel::Detail { -STATIC void mp_hang_fn(void) { - while (YES); -} -} // namespace Kernel::Detail - -namespace Kernel { -/// @brief wakes up thread. -/// wakes up thread from hang. -void mp_wakeup_thread(HAL::StackFramePtr stack) { - if (!stack) return; - - MUST_PASS(stack->R15 > 0); - MUST_PASS(stack->IP > 0); - - hal_set_pc_to_hart(reinterpret_cast(stack->R15), - reinterpret_cast(stack->IP)); -} - -/// @brief makes thread sleep. -/// hooks and hangs thread to prevent code from executing. -void mp_hang_thread(HAL::StackFramePtr stack) { - if (!stack) return; - - MUST_PASS(stack->R15 > 0); - - hal_set_pc_to_hart(reinterpret_cast(stack->R15), - reinterpret_cast(Kernel::Detail::mp_hang_fn)); -} -} // namespace Kernel diff --git a/src/kernel/HALKit/POWER/HalApplicationProcessor.cpp b/src/kernel/HALKit/POWER/HalApplicationProcessor.cpp new file mode 100644 index 00000000..64333086 --- /dev/null +++ b/src/kernel/HALKit/POWER/HalApplicationProcessor.cpp @@ -0,0 +1,40 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include + +/// @note This part of the HAL needs an owner. + +namespace Kernel::Detail { +STATIC void mp_hang_fn(void) { + while (YES); +} +} // namespace Kernel::Detail + +namespace Kernel { +/// @brief wakes up thread. +/// wakes up thread from hang. +void mp_wakeup_thread(HAL::StackFramePtr stack) { + if (!stack) return; + + MUST_PASS(stack->R15 > 0); + MUST_PASS(stack->IP > 0); + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), + reinterpret_cast(stack->IP)); +} + +/// @brief makes thread sleep. +/// hooks and hangs thread to prevent code from executing. +void mp_hang_thread(HAL::StackFramePtr stack) { + if (!stack) return; + + MUST_PASS(stack->R15 > 0); + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), + reinterpret_cast(Kernel::Detail::mp_hang_fn)); +} +} // namespace Kernel diff --git a/src/kernel/HALKit/POWER/HalDebugOutput.cc b/src/kernel/HALKit/POWER/HalDebugOutput.cc deleted file mode 100644 index c43e575d..00000000 --- a/src/kernel/HALKit/POWER/HalDebugOutput.cc +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include - -using namespace Kernel; - -/// @brief Writes to COM1. -/// @param bytes -void ke_io_write(const Char* bytes) { - if (!bytes) return; - - SizeT index = 0; - SizeT len = rt_string_len(bytes, 256U); - - while (index < len) { - // TODO - ++index; - } -} diff --git a/src/kernel/HALKit/POWER/HalDebugOutput.cpp b/src/kernel/HALKit/POWER/HalDebugOutput.cpp new file mode 100644 index 00000000..c43e575d --- /dev/null +++ b/src/kernel/HALKit/POWER/HalDebugOutput.cpp @@ -0,0 +1,22 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include + +using namespace Kernel; + +/// @brief Writes to COM1. +/// @param bytes +void ke_io_write(const Char* bytes) { + if (!bytes) return; + + SizeT index = 0; + SizeT len = rt_string_len(bytes, 256U); + + while (index < len) { + // TODO + ++index; + } +} diff --git a/src/kernel/HALKit/POWER/HalHardwareThread.cc b/src/kernel/HALKit/POWER/HalHardwareThread.cc deleted file mode 100644 index fff5b68b..00000000 --- a/src/kernel/HALKit/POWER/HalHardwareThread.cc +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include diff --git a/src/kernel/HALKit/POWER/HalHardwareThread.cpp b/src/kernel/HALKit/POWER/HalHardwareThread.cpp new file mode 100644 index 00000000..fff5b68b --- /dev/null +++ b/src/kernel/HALKit/POWER/HalHardwareThread.cpp @@ -0,0 +1,6 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include diff --git a/src/kernel/HALKit/POWER/HalVirtualMemory.cc b/src/kernel/HALKit/POWER/HalVirtualMemory.cc deleted file mode 100644 index 0c954f29..00000000 --- a/src/kernel/HALKit/POWER/HalVirtualMemory.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include - -/// @note Refer to SoC documentation. - -using namespace Kernel; - -EXTERN_C Void hal_write_tlb(UInt32 mas0, UInt32 mas1, UInt32 mas2, UInt32 mas3, UInt32 mas7) { - hal_mtspr(MAS0, mas0); - hal_mtspr(MAS1, mas1); - hal_mtspr(MAS2, mas2); - hal_mtspr(MAS3, mas3); - hal_mtspr(MAS7, mas7); - - hal_flush_tlb(); -} - -EXTERN_C Bool hal_set_tlb(UInt8 tlb, UInt32 epn, UInt64 rpn, UInt8 perms, UInt8 wimge, UInt8 ts, - UInt8 esel, UInt8 tsize, UInt8 iprot) { - if ((hal_mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1 && (tsize & 1)) { - // this MMU does not allow odd tsize values - return false; - } - - UInt32 mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); - UInt32 mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); - UInt32 mas2 = FSL_BOOKE_MAS2(epn, wimge); - UInt32 mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); - UInt32 mas7 = FSL_BOOKE_MAS7(rpn); - - hal_write_tlb(mas0, mas1, mas2, mas3, mas7); - - return true; -} - -/// @brief Flush TLB -EXTERN_C void hal_flush_tlb() { - asm volatile("isync;tlbwe;msync;isync"); -} diff --git a/src/kernel/HALKit/POWER/HalVirtualMemory.cpp b/src/kernel/HALKit/POWER/HalVirtualMemory.cpp new file mode 100644 index 00000000..0c954f29 --- /dev/null +++ b/src/kernel/HALKit/POWER/HalVirtualMemory.cpp @@ -0,0 +1,44 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include + +/// @note Refer to SoC documentation. + +using namespace Kernel; + +EXTERN_C Void hal_write_tlb(UInt32 mas0, UInt32 mas1, UInt32 mas2, UInt32 mas3, UInt32 mas7) { + hal_mtspr(MAS0, mas0); + hal_mtspr(MAS1, mas1); + hal_mtspr(MAS2, mas2); + hal_mtspr(MAS3, mas3); + hal_mtspr(MAS7, mas7); + + hal_flush_tlb(); +} + +EXTERN_C Bool hal_set_tlb(UInt8 tlb, UInt32 epn, UInt64 rpn, UInt8 perms, UInt8 wimge, UInt8 ts, + UInt8 esel, UInt8 tsize, UInt8 iprot) { + if ((hal_mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1 && (tsize & 1)) { + // this MMU does not allow odd tsize values + return false; + } + + UInt32 mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); + UInt32 mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); + UInt32 mas2 = FSL_BOOKE_MAS2(epn, wimge); + UInt32 mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); + UInt32 mas7 = FSL_BOOKE_MAS7(rpn); + + hal_write_tlb(mas0, mas1, mas2, mas3, mas7); + + return true; +} + +/// @brief Flush TLB +EXTERN_C void hal_flush_tlb() { + asm volatile("isync;tlbwe;msync;isync"); +} -- cgit v1.2.3