summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKAKit/HALKit/POWER
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2024-10-28 07:01:58 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2024-10-28 07:01:58 +0100
commite0024d9ea688ee91a77abc0e28c5ea24b13ca67d (patch)
treea4e29bd919cbeccf2689e81a5d52bfc02f2a8b77 /dev/ZKAKit/HALKit/POWER
parent36a3600ff7fc65a63b7386b7a680dbe8e647bd8f (diff)
IMP: Refactor whole source code to make it even.
- That is because previously the source was both in lowercase and lettercase. Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/HALKit/POWER')
-rw-r--r--dev/ZKAKit/HALKit/POWER/.gitkeep0
-rw-r--r--dev/ZKAKit/HALKit/POWER/APM/.gitkeep0
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalContextSwitchPowerPC.s30
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalHart.cc25
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalSerialPort.cc27
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalStartSequence.s14
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalThread.cc8
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalVirtualMemory.cc49
-rw-r--r--dev/ZKAKit/HALKit/POWER/Hart.h36
-rw-r--r--dev/ZKAKit/HALKit/POWER/MBCI/.gitkeep0
-rw-r--r--dev/ZKAKit/HALKit/POWER/MBCI/HalMBCIHost.cc8
-rw-r--r--dev/ZKAKit/HALKit/POWER/Processor.h62
-rw-r--r--dev/ZKAKit/HALKit/POWER/ReadMe.md4
13 files changed, 263 insertions, 0 deletions
diff --git a/dev/ZKAKit/HALKit/POWER/.gitkeep b/dev/ZKAKit/HALKit/POWER/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/.gitkeep
diff --git a/dev/ZKAKit/HALKit/POWER/APM/.gitkeep b/dev/ZKAKit/HALKit/POWER/APM/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/APM/.gitkeep
diff --git a/dev/ZKAKit/HALKit/POWER/HalContextSwitchPowerPC.s b/dev/ZKAKit/HALKit/POWER/HalContextSwitchPowerPC.s
new file mode 100644
index 00000000..380dc375
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalContextSwitchPowerPC.s
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+.align 4
+.type name, @function
+.text
+.globl mp_do_task_switch
+
+/* r3 (3) = assigner stack, r4 (4) = assignee stack */
+mp_do_task_switch:
+ lwz 0(%4), 0(%3)
+ lwz 4(%4), 4(%3)
+ lwz 8(%4), 8(%3)
+ lwz 12(%4), 12(%3)
+ lwz 14(%4), 14(%3)
+ lwz 18(%4), 18(%3)
+ lwz 22(%4), 22(%3)
+ lwz 24(%4), 24(%3)
+ lwz 28(%4), 28(%3)
+ lwz 32(%4), 32(%3)
+ lwz 34(%4), 34(%3)
+ lwz 38(%4), 38(%3)
+
+ /* also change exception level */
+
+ /* we are done here, the assignee should start executing code now. */
+ blr
diff --git a/dev/ZKAKit/HALKit/POWER/HalHart.cc b/dev/ZKAKit/HALKit/POWER/HalHart.cc
new file mode 100644
index 00000000..ff5025d5
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalHart.cc
@@ -0,0 +1,25 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.h>
+#include <KernelKit/DebugOutput.h>
+#include <HALKit/POWER/Hart.h>
+
+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/HalSerialPort.cc b/dev/ZKAKit/HALKit/POWER/HalSerialPort.cc
new file mode 100644
index 00000000..29bc8fa5
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalSerialPort.cc
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.h>
+#include <KernelKit/DebugOutput.h>
+
+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, 255);
+
+ while (index < len)
+ {
+ // TODO
+ ++index;
+ }
+}
diff --git a/dev/ZKAKit/HALKit/POWER/HalStartSequence.s b/dev/ZKAKit/HALKit/POWER/HalStartSequence.s
new file mode 100644
index 00000000..b9f1bee8
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalStartSequence.s
@@ -0,0 +1,14 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+.globl __ImageStart
+.extern hal_init_platform
+.align 4
+.text
+
+__ImageStart:
+ bl hal_init_platform
+ blr
diff --git a/dev/ZKAKit/HALKit/POWER/HalThread.cc b/dev/ZKAKit/HALKit/POWER/HalThread.cc
new file mode 100644
index 00000000..7a0d5ccb
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalThread.cc
@@ -0,0 +1,8 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.h>
+#include <KernelKit/DebugOutput.h>
diff --git a/dev/ZKAKit/HALKit/POWER/HalVirtualMemory.cc b/dev/ZKAKit/HALKit/POWER/HalVirtualMemory.cc
new file mode 100644
index 00000000..e21d7074
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/HalVirtualMemory.cc
@@ -0,0 +1,49 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#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);
+
+ 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/dev/ZKAKit/HALKit/POWER/Hart.h b/dev/ZKAKit/HALKit/POWER/Hart.h
new file mode 100644
index 00000000..2e40784e
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/Hart.h
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+ File: Hart.h
+ Purpose: POWER hardware threads.
+
+ Revision History:
+
+ 14/04/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.h>
+
+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/POWER/MBCI/.gitkeep b/dev/ZKAKit/HALKit/POWER/MBCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/MBCI/.gitkeep
diff --git a/dev/ZKAKit/HALKit/POWER/MBCI/HalMBCIHost.cc b/dev/ZKAKit/HALKit/POWER/MBCI/HalMBCIHost.cc
new file mode 100644
index 00000000..7a0d5ccb
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/MBCI/HalMBCIHost.cc
@@ -0,0 +1,8 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.h>
+#include <KernelKit/DebugOutput.h>
diff --git a/dev/ZKAKit/HALKit/POWER/Processor.h b/dev/ZKAKit/HALKit/POWER/Processor.h
new file mode 100644
index 00000000..4df55fc4
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/Processor.h
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+ Purpose: POWER processor header.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.h>
+#include <NewKit/Utils.h>
+
+#define NoOp() 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
+
+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);
+
+/// @brief Write TLB.
+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();
diff --git a/dev/ZKAKit/HALKit/POWER/ReadMe.md b/dev/ZKAKit/HALKit/POWER/ReadMe.md
new file mode 100644
index 00000000..a9751581
--- /dev/null
+++ b/dev/ZKAKit/HALKit/POWER/ReadMe.md
@@ -0,0 +1,4 @@
+POWER Hardware Abstraction Layer
+
+- Supported CPU: POWER
+- Supported Firmware: CoreBoot \ No newline at end of file