summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/ARM64
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-19 17:56:55 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-19 17:57:16 +0200
commit19d0857d84cbc0267a8b222368e143bdcdaaf9a7 (patch)
tree8d8a274003cbe6837a5f565e97a810d0774f0624 /Kernel/HALKit/ARM64
parent720e24cea004356da037648b92fd7eb02f3c74a8 (diff)
ARM64: Got into the linking stage, writing missing drivers in HAL now.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/HALKit/ARM64')
-rw-r--r--Kernel/HALKit/ARM64/HalPageAlloc.hpp82
-rw-r--r--Kernel/HALKit/ARM64/HalPageInternal.S5
-rw-r--r--Kernel/HALKit/ARM64/Hart.hxx4
-rw-r--r--Kernel/HALKit/ARM64/Processor.hxx55
-rw-r--r--Kernel/HALKit/ARM64/Storage/Flash.cxx27
5 files changed, 171 insertions, 2 deletions
diff --git a/Kernel/HALKit/ARM64/HalPageAlloc.hpp b/Kernel/HALKit/ARM64/HalPageAlloc.hpp
new file mode 100644
index 00000000..57e1e193
--- /dev/null
+++ b/Kernel/HALKit/ARM64/HalPageAlloc.hpp
@@ -0,0 +1,82 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#pragma once
+
+/** ---------------------------------------------------
+
+ * THIS FILE CONTAINS CODE FOR ARM64 PAGING.
+
+------------------------------------------------------- */
+
+#include <NewKit/Defines.hpp>
+
+#ifndef kPTEMax
+#define kPTEMax (0x200)
+#endif //! kPTEMax
+
+#ifndef kPTEAlign
+#define kPTEAlign (0x1000)
+#endif //! kPTEAlign
+
+#ifndef kPTESize
+#define kPTESize (0x1000)
+#endif // !kPTESize
+
+EXTERN_C void hal_flush_tlb();
+
+namespace NewOS::HAL
+{
+ struct PACKED PageTable64 final
+ {
+ bool Present : 1;
+ bool Rw : 1;
+ bool User : 1;
+ bool Wt : 1;
+ bool Cache : 1;
+ bool Accessed : 1;
+ NewOS::Int32 Reserved : 6;
+ NewOS::UInt64 PhysicalAddress : 36;
+ NewOS::Int32 Reserved1 : 15;
+ bool ExecDisable : 1;
+ };
+
+ namespace Detail
+ {
+ enum class ControlRegisterBits
+ {
+ ProtectedModeEnable = 0,
+ MonitorCoProcessor = 1,
+ Emulation = 2,
+ TaskSwitched = 3,
+ ExtensionType = 4,
+ NumericError = 5,
+ WriteProtect = 16,
+ AlignementMask = 18,
+ NotWriteThrough = 29,
+ CacheDisable = 30,
+ PageEnable = 31,
+ };
+
+ inline UInt8 control_register_cast(ControlRegisterBits reg)
+ {
+ return static_cast<UInt8>(reg);
+ }
+ } // namespace Detail
+
+ struct PageDirectory64 final
+ {
+ PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax];
+ };
+
+ VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size);
+} // namespace NewOS::HAL
+
+namespace NewOS
+{
+ typedef HAL::PageTable64 PTE;
+ typedef HAL::PageDirectory64 PDE;
+} // namespace NewOS
diff --git a/Kernel/HALKit/ARM64/HalPageInternal.S b/Kernel/HALKit/ARM64/HalPageInternal.S
new file mode 100644
index 00000000..8fcf40ff
--- /dev/null
+++ b/Kernel/HALKit/ARM64/HalPageInternal.S
@@ -0,0 +1,5 @@
+.text
+
+hal_flush_tlb:
+ tlbi
+ ret
diff --git a/Kernel/HALKit/ARM64/Hart.hxx b/Kernel/HALKit/ARM64/Hart.hxx
index 1b16a072..5769b01e 100644
--- a/Kernel/HALKit/ARM64/Hart.hxx
+++ b/Kernel/HALKit/ARM64/Hart.hxx
@@ -16,8 +16,8 @@ typedef NewOS::Int32 Arm64HartType;
/// @brief Set PC to specific hart.
/// @param hart the hart
/// @param epc the pc.
-/// @return
-EXTERN_C NewOS::Void hal_switch_to_hart(Arm64HartType hart, NewOS::VoidPtr epc);
+/// @return
+EXTERN_C NewOS::Void hal_set_pc_to_hart(Arm64HartType hart, NewOS::VoidPtr epc);
/// @brief Hart IPI enum
enum {
diff --git a/Kernel/HALKit/ARM64/Processor.hxx b/Kernel/HALKit/ARM64/Processor.hxx
new file mode 100644
index 00000000..8b06794f
--- /dev/null
+++ b/Kernel/HALKit/ARM64/Processor.hxx
@@ -0,0 +1,55 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/Utils.hpp>
+#include <FirmwareKit/Handover.hxx>
+
+#ifdef kCPUBackendName
+#undef kCPUBackendName
+#endif // ifdef kCPUBackendName
+
+#define kPTESize 512 /* 64-bit PT */
+
+#define kCPUBackendName "ARM64"
+
+#ifdef __ZETA_MACHINE__
+#define kVirtualAddressStartOffset (0x80000000)
+#else
+#error !!! please provide that macro. !!!
+#endif
+
+namespace NewOS::HAL
+{
+ struct PACKED Register64 final
+ {
+ UShort Limit;
+ UIntPtr Base;
+ };
+
+ typedef UIntPtr Reg;
+ typedef Register64 Register;
+
+ struct PACKED StackFrame final
+ {
+ Reg IntNum, Exception;
+ Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
+ Reg R8, R9, R10, R11, R12, R13, R14, R15;
+ Reg Gs, Fs;
+ };
+
+ typedef StackFrame* StackFramePtr;
+}
+
+inline NewOS::VoidPtr kKernelVirtualStart = (NewOS::VoidPtr)kVirtualAddressStartOffset;
+inline NewOS::UIntPtr kKernelVirtualSize = 0UL;
+
+inline NewOS::VoidPtr kKernelPhysicalStart = nullptr;
+
+#include <HALKit/ARM64/HalPageAlloc.hpp>
diff --git a/Kernel/HALKit/ARM64/Storage/Flash.cxx b/Kernel/HALKit/ARM64/Storage/Flash.cxx
new file mode 100644
index 00000000..8afd0f58
--- /dev/null
+++ b/Kernel/HALKit/ARM64/Storage/Flash.cxx
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#include <NewKit/Defines.hpp>
+#include <ArchKit/ArchKit.hpp>
+
+/// @brief MBCI flash drive.
+
+#ifdef __FLASH_MEM__
+
+namespace NewOS
+{
+ SizeT drv_std_get_sector_count(void)
+ {
+ return 0;
+ }
+
+ SizeT drv_std_get_drv_size(void)
+ {
+ return 0;
+ }
+} // namespace NewOS
+
+#endif // if __FLASH_MEM__ (MBCI)