diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-10 10:14:07 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-10 10:14:07 +0200 |
| commit | d108de7b8ad0f92bdc9f3951e762c09c762fd174 (patch) | |
| tree | 161ce51a5efeeecd40278e806b343dc206e272fe /Kernel | |
| parent | 5ce8823643f02e4d04c80e2dcf944b442b2ba69b (diff) | |
MHR-36: Expose POWER64 VMS and common StackFrame across platforms. And code refactors.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel')
22 files changed, 96 insertions, 93 deletions
diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index bf9bd8e5..f01d5f21 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -11,11 +11,11 @@ #include <NewKit/Function.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #include <HALKit/AMD64/Hypervisor.hpp> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #elif defined(__NEWOS_POWER64__) -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #elif defined(__NEWOS_ARM64__) #include <HALKit/ARM64/Processor.hxx> #else diff --git a/Kernel/HALKit/64x0/HalVirtualMemory.cxx b/Kernel/HALKit/64x0/HalVirtualMemory.cxx index f62f888f..03f9afc7 100644 --- a/Kernel/HALKit/64x0/HalVirtualMemory.cxx +++ b/Kernel/HALKit/64x0/HalVirtualMemory.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> using namespace Kernel; diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index ca6a7417..3fc8ae7a 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #include <NewKit/String.hpp> #include <ArchKit/ArchKit.hpp> #include <KernelKit/KernelHeap.hpp> diff --git a/Kernel/HALKit/AMD64/HalAPIC.cxx b/Kernel/HALKit/AMD64/HalAPIC.cxx index a148acf9..22f6583e 100644 --- a/Kernel/HALKit/AMD64/HalAPIC.cxx +++ b/Kernel/HALKit/AMD64/HalAPIC.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> namespace Kernel::HAL { diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx index cb7b1eeb..86bf635c 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #include <NewKit/KernelCheck.hpp> #include <ArchKit/ArchKit.hpp> #include <KernelKit/Semaphore.hpp> diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.hpp b/Kernel/HALKit/AMD64/HalPageAlloc.hxx index 8887b623..8887b623 100644 --- a/Kernel/HALKit/AMD64/HalPageAlloc.hpp +++ b/Kernel/HALKit/AMD64/HalPageAlloc.hxx diff --git a/Kernel/HALKit/AMD64/HalProcessor.cpp b/Kernel/HALKit/AMD64/HalProcessor.cxx index 01f3879a..e71e7108 100644 --- a/Kernel/HALKit/AMD64/HalProcessor.cpp +++ b/Kernel/HALKit/AMD64/HalProcessor.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> /** * @file Processor.cpp diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hxx index 8ec0b6f6..ecdd8dd0 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hxx @@ -17,7 +17,7 @@ #include <NewKit/Defines.hpp> #include <NewKit/Utils.hpp> #include <FirmwareKit/Handover.hxx> -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> EXTERN_C { @@ -158,6 +158,7 @@ namespace Kernel::HAL typedef UIntPtr Reg; + /// @brief Stack frame (as retrieved from assembly.) struct PACKED StackFrame final { Reg IntNum, Exception; diff --git a/Kernel/HALKit/ARM64/HalPageAlloc.hpp b/Kernel/HALKit/ARM64/HalPageAlloc.hxx index 8286b5cd..8286b5cd 100644 --- a/Kernel/HALKit/ARM64/HalPageAlloc.hpp +++ b/Kernel/HALKit/ARM64/HalPageAlloc.hxx diff --git a/Kernel/HALKit/ARM64/Processor.hxx b/Kernel/HALKit/ARM64/Processor.hxx index fcffe065..c7ceae7d 100644 --- a/Kernel/HALKit/ARM64/Processor.hxx +++ b/Kernel/HALKit/ARM64/Processor.hxx @@ -53,4 +53,4 @@ inline Kernel::UIntPtr kKernelVirtualSize = 0UL; inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> diff --git a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 4469eee9..2cfe6e70 100644 --- a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> -#include <HALKit/AXP/Processor.hpp> +#include <HALKit/AXP/Processor.hxx> /// @brief Internal call for syscall, to work with C++. /// @param stack diff --git a/Kernel/HALKit/POWER/HalHardware.cxx b/Kernel/HALKit/POWER/HalHardware.cxx index 15407eb3..f8f40ff1 100644 --- a/Kernel/HALKit/POWER/HalHardware.cxx +++ b/Kernel/HALKit/POWER/HalHardware.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> namespace Kernel diff --git a/Kernel/HALKit/POWER/HalHart.cxx b/Kernel/HALKit/POWER/HalHart.cxx index 614828cb..38babb12 100644 --- a/Kernel/HALKit/POWER/HalHart.cxx +++ b/Kernel/HALKit/POWER/HalHart.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> #include <HALKit/POWER/Hart.hxx> diff --git a/Kernel/HALKit/POWER/HalSerialPort.cxx b/Kernel/HALKit/POWER/HalSerialPort.cxx index abddd291..6a802a72 100644 --- a/Kernel/HALKit/POWER/HalSerialPort.cxx +++ b/Kernel/HALKit/POWER/HalSerialPort.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> using namespace Kernel; diff --git a/Kernel/HALKit/POWER/HalThread.cxx b/Kernel/HALKit/POWER/HalThread.cxx index 18d84d4f..3e0ab088 100644 --- a/Kernel/HALKit/POWER/HalThread.cxx +++ b/Kernel/HALKit/POWER/HalThread.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> EXTERN_C Kernel::HAL::StackFramePtr rt_get_current_context() diff --git a/Kernel/HALKit/POWER/HalVirtualMemory.cxx b/Kernel/HALKit/POWER/HalVirtualMemory.cxx index eb04a43d..d068a374 100644 --- a/Kernel/HALKit/POWER/HalVirtualMemory.cxx +++ b/Kernel/HALKit/POWER/HalVirtualMemory.cxx @@ -7,20 +7,14 @@ #include <HALKit/POWER/ppc-cpu.h> #include <HALKit/POWER/ppc-mmu.h> -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> -/// @note refer to our SoC documentation. +/// @note refer to the SoC documentation. using namespace Kernel; -/// @brief Write directly to the specific TLB. -/// @param mas0 -/// @param mas1 -/// @param mas2 -/// @param mas3 -/// @param mas7 -static void hal_write_tlb(uint32_t mas0, uint32_t mas1, uint32_t mas2, uint32_t mas3, uint32_t mas7) +Void hal_write_tlb(UInt32 mas0, UInt32 mas1, UInt32 mas2, UInt32 mas3, UInt32 mas7) { mtspr(MAS0, mas0); mtspr(MAS1, mas1); @@ -31,23 +25,26 @@ static void hal_write_tlb(uint32_t mas0, uint32_t mas1, uint32_t mas2, uint32_t hal_flush_tlb(); } -void hal_set_tlb(uint8_t tlb, uint32_t epn, uint64_t rpn, uint8_t perms, uint8_t wimge, uint8_t ts, uint8_t esel, uint8_t tsize, uint8_t iprot) +Bool hal_set_tlb(UInt8 tlb, UInt32 epn, UInt64 rpn, UInt8 perms, UInt8 wimge, UInt8 ts, UInt8 esel, UInt8 tsize, UInt8 iprot) { if ((mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1 && (tsize & 1)) { // this mmu-version does not allow odd tsize values - return; + return false; } - uint32_t mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); - uint32_t mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); - uint32_t mas2 = FSL_BOOKE_MAS2(epn, wimge); - uint32_t mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); - uint32_t 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); + + return true; } -/// @brief Flush system TLB. +/// @brief Flush TLB EXTERN_C void hal_flush_tlb() { asm volatile("isync;tlbwe;msync;isync"); diff --git a/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx b/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx index 8a24506a..03f5a387 100644 --- a/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx +++ b/Kernel/HALKit/POWER/MBCI/HalMBCIHost.cxx @@ -4,5 +4,5 @@ ------------------------------------------- */ -#include <HALKit/POWER/Processor.hpp> +#include <HALKit/POWER/Processor.hxx> #include <KernelKit/DebugOutput.hpp> diff --git a/Kernel/HALKit/POWER/Processor.hpp b/Kernel/HALKit/POWER/Processor.hpp deleted file mode 100644 index 5ff7eef3..00000000 --- a/Kernel/HALKit/POWER/Processor.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - - Purpose: POWER processor header. - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#include <NewKit/Utils.hpp> - -#define kHalPPCAlignment __attribute__((aligned(4))) - -namespace Kernel::HAL -{ - typedef UIntPtr Reg; - - struct kHalPPCAlignment StackFrame - { - Reg R0; - Reg R1; - Reg R2; - Reg R3; - Reg R4; - Reg R5; - Reg R6; - Reg R7; - Reg R8; - Reg PC; - Reg SP; - }; - - typedef StackFrame* StackFramePtr; - - inline void rt_halt() - { - while (1) - { - asm volatile("mr 0, 0"); // no oop. - } - } - - inline void rt_cli() - { - asm volatile("mr 0, 0"); // no oop - } -} // namespace Kernel::HAL - -EXTERN_C void int_handle_math(Kernel::UIntPtr sp); -EXTERN_C void int_handle_pf(Kernel::UIntPtr sp); - -/// @brief Flush system TLB. -EXTERN_C void hal_flush_tlb(); diff --git a/Kernel/HALKit/POWER/Processor.hxx b/Kernel/HALKit/POWER/Processor.hxx new file mode 100644 index 00000000..26f739d3 --- /dev/null +++ b/Kernel/HALKit/POWER/Processor.hxx @@ -0,0 +1,60 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + + Purpose: POWER processor header. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hpp> +#include <NewKit/Utils.hpp> + +#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 IntNum, Exception; + Reg A0, A2, BP, SP, A3, A4, A5, A6; + Reg R8, R9, R10, R11, R12, R13, R14, R15; + Reg Gs, Fs; + }; + + 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/Kernel/Sources/HalPageAlloc.cxx b/Kernel/Sources/HalPageAlloc.cxx index 0339745b..c3831ee1 100644 --- a/Kernel/Sources/HalPageAlloc.cxx +++ b/Kernel/Sources/HalPageAlloc.cxx @@ -7,9 +7,9 @@ #include <ArchKit/ArchKit.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif #include <NewKit/Defines.hpp> diff --git a/Kernel/Sources/PageManager.cxx b/Kernel/Sources/PageManager.cxx index 35693310..451e2041 100644 --- a/Kernel/Sources/PageManager.cxx +++ b/Kernel/Sources/PageManager.cxx @@ -8,9 +8,9 @@ #include <NewKit/PageManager.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif // ifdef __NEWOS_AMD64__ || defined(__NEWOS_ARM64__) //! null deref will throw (Page Zero detected, aborting app!) diff --git a/Kernel/Sources/Pmm.cxx b/Kernel/Sources/Pmm.cxx index 22813206..19e32327 100644 --- a/Kernel/Sources/Pmm.cxx +++ b/Kernel/Sources/Pmm.cxx @@ -12,7 +12,7 @@ #endif #if defined(__NEWOS_AMD64__) -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #endif namespace Kernel |
