summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/POWER
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/kernel/HALKit/POWER
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/POWER')
-rw-r--r--dev/kernel/HALKit/POWER/AP.h56
-rw-r--r--dev/kernel/HALKit/POWER/HalApplicationProcessor.cc60
-rw-r--r--dev/kernel/HALKit/POWER/HalDebugOutput.cc21
-rw-r--r--dev/kernel/HALKit/POWER/HalHardwareThread.cc2
-rw-r--r--dev/kernel/HALKit/POWER/HalVirtualMemory.cc51
-rw-r--r--dev/kernel/HALKit/POWER/Processor.h76
6 files changed, 125 insertions, 141 deletions
diff --git a/dev/kernel/HALKit/POWER/AP.h b/dev/kernel/HALKit/POWER/AP.h
index 4558804b..f938d6a1 100644
--- a/dev/kernel/HALKit/POWER/AP.h
+++ b/dev/kernel/HALKit/POWER/AP.h
@@ -1,13 +1,13 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
- File: AP.h
- Purpose: POWER hardware threads.
+ File: AP.h
+ Purpose: POWER hardware threads.
- Revision History:
+ Revision History:
- 14/04/24: Added file (amlel)
+ 14/04/24: Added file (amlel)
------------------------------------------- */
@@ -15,27 +15,25 @@
#include <NewKit/Defines.h>
-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::UIntPtr fStackPtr;
- Kernel::UIntPtr fFramePtr;
- Kernel::UInt8 fPrivileged : 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
+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::UIntPtr fStackPtr;
+ Kernel::UIntPtr fFramePtr;
+ Kernel::UInt8 fPrivileged : 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
diff --git a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc
index ca2153e3..eb44b72b 100644
--- a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc
+++ b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc
@@ -1,41 +1,35 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
+#include <HALKit/POWER/AP.h>
#include <HALKit/POWER/Processor.h>
#include <KernelKit/DebugOutput.h>
-#include <HALKit/POWER/AP.h>
-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;
-
- hal_set_pc_to_hart(reinterpret_cast<HAL_HARDWARE_THREAD*>(stack->R15), reinterpret_cast<VoidPtr>(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<HAL_HARDWARE_THREAD*>(stack->R15), reinterpret_cast<VoidPtr>(Kernel::Detail::mp_hang_fn));
- }
-} // namespace Kernel \ No newline at end of file
+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;
+
+ hal_set_pc_to_hart(reinterpret_cast<HAL_HARDWARE_THREAD*>(stack->R15),
+ reinterpret_cast<VoidPtr>(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<HAL_HARDWARE_THREAD*>(stack->R15),
+ reinterpret_cast<VoidPtr>(Kernel::Detail::mp_hang_fn));
+}
+} // namespace Kernel \ No newline at end of file
diff --git a/dev/kernel/HALKit/POWER/HalDebugOutput.cc b/dev/kernel/HALKit/POWER/HalDebugOutput.cc
index 8142364c..bcc6922c 100644
--- a/dev/kernel/HALKit/POWER/HalDebugOutput.cc
+++ b/dev/kernel/HALKit/POWER/HalDebugOutput.cc
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -11,17 +11,14 @@ using namespace Kernel;
/// @brief Writes to COM1.
/// @param bytes
-void ke_io_write(const Char* bytes)
-{
- if (!bytes)
- return;
+void ke_io_write(const Char* bytes) {
+ if (!bytes) return;
- SizeT index = 0;
- SizeT len = rt_string_len(bytes, 256U);
+ SizeT index = 0;
+ SizeT len = rt_string_len(bytes, 256U);
- while (index < len)
- {
- // TODO
- ++index;
- }
+ while (index < len) {
+ // TODO
+ ++index;
+ }
}
diff --git a/dev/kernel/HALKit/POWER/HalHardwareThread.cc b/dev/kernel/HALKit/POWER/HalHardwareThread.cc
index 40bb7d8a..2c7c69ba 100644
--- a/dev/kernel/HALKit/POWER/HalHardwareThread.cc
+++ b/dev/kernel/HALKit/POWER/HalHardwareThread.cc
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
diff --git a/dev/kernel/HALKit/POWER/HalVirtualMemory.cc b/dev/kernel/HALKit/POWER/HalVirtualMemory.cc
index 5c20458e..07c40134 100644
--- a/dev/kernel/HALKit/POWER/HalVirtualMemory.cc
+++ b/dev/kernel/HALKit/POWER/HalVirtualMemory.cc
@@ -1,49 +1,46 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
+#include <HALKit/POWER/MMU.h>
#include <HALKit/POWER/Processor.h>
#include <KernelKit/DebugOutput.h>
-#include <HALKit/POWER/MMU.h>
/// @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);
+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();
+ 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;
- }
+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);
+ 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);
+ hal_write_tlb(mas0, mas1, mas2, mas3, mas7);
- return true;
+ return true;
}
/// @brief Flush TLB
-EXTERN_C void hal_flush_tlb()
-{
- asm volatile("isync;tlbwe;msync;isync");
+EXTERN_C void hal_flush_tlb() {
+ asm volatile("isync;tlbwe;msync;isync");
}
diff --git a/dev/kernel/HALKit/POWER/Processor.h b/dev/kernel/HALKit/POWER/Processor.h
index 507805c7..850b636d 100644
--- a/dev/kernel/HALKit/POWER/Processor.h
+++ b/dev/kernel/HALKit/POWER/Processor.h
@@ -1,8 +1,8 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
- Purpose: POWER processor header.
+ Purpose: POWER processor header.
------------------------------------------- */
@@ -11,52 +11,50 @@
#include <NewKit/Defines.h>
#include <NewKit/Utils.h>
-#define rtl_nop_op() asm volatile("mr 0, 0")
+#define rtl_nop_op() asm volatile("mr 0, 0")
#define kHalPPCAlignment __attribute__((aligned(4)))
-namespace Kernel::HAL
-{
- typedef UIntPtr Reg;
-
- /// @brief Stack frame (as retrieved from assembly.)
- struct PACKED StackFrame final
- {
- Reg R8{0};
- Reg R9{0};
- Reg R10{0};
- Reg R11{0};
- Reg R12{0};
- Reg R13{0};
- Reg R14{0};
- Reg R15{0};
- Reg SP{0};
- Reg BP{0};
- };
-
- typedef StackFrame* StackFramePtr;
-
- inline void rt_halt()
- {
- while (true)
- {
- NoOp(); // no oop.
- }
- }
-
- inline void rt_cli()
- {
- NoOp(); // no oop
- }
-} // namespace Kernel::HAL
+namespace Kernel::HAL {
+typedef UIntPtr Reg;
+
+/// @brief Stack frame (as retrieved from assembly.)
+struct PACKED StackFrame final {
+ Reg R8{0};
+ Reg R9{0};
+ Reg R10{0};
+ Reg R11{0};
+ Reg R12{0};
+ Reg R13{0};
+ Reg R14{0};
+ Reg R15{0};
+ Reg SP{0};
+ Reg BP{0};
+};
+
+typedef StackFrame* StackFramePtr;
+
+inline void rt_halt() {
+ while (true) {
+ NoOp(); // no oop.
+ }
+}
+
+inline void rt_cli() {
+ NoOp(); // no oop
+}
+} // namespace Kernel::HAL
EXTERN_C Kernel::Void int_handle_math(Kernel::UIntPtr sp);
EXTERN_C Kernel::Void int_handle_pf(Kernel::UIntPtr sp);
/// @brief Set TLB.
-Kernel::Bool hal_set_tlb(Kernel::UInt8 tlb, Kernel::UInt32 epn, Kernel::UInt64 rpn, Kernel::UInt8 perms, Kernel::UInt8 wimge, Kernel::UInt8 ts, Kernel::UInt8 esel, Kernel::UInt8 tsize, Kernel::UInt8 iprot);
+Kernel::Bool hal_set_tlb(Kernel::UInt8 tlb, Kernel::UInt32 epn, Kernel::UInt64 rpn,
+ Kernel::UInt8 perms, Kernel::UInt8 wimge, Kernel::UInt8 ts,
+ Kernel::UInt8 esel, Kernel::UInt8 tsize, Kernel::UInt8 iprot);
/// @brief Write TLB.
-Kernel::Void hal_write_tlb(Kernel::UInt32 mas0, Kernel::UInt32 mas1, Kernel::UInt32 mas2, Kernel::UInt32 mas3, Kernel::UInt32 mas7);
+Kernel::Void hal_write_tlb(Kernel::UInt32 mas0, Kernel::UInt32 mas1, Kernel::UInt32 mas2,
+ Kernel::UInt32 mas3, Kernel::UInt32 mas7);
/// @brief Flush TLB.
EXTERN_C Kernel::Void hal_flush_tlb();