diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
| commit | 59578978610f6af245f571a011694a51d94dc530 (patch) | |
| tree | 3553807ef1c8095248520ee823c1426aef8738d8 /Kernel/ArchKit/ArchKit.hxx | |
| parent | 9afcd1c001703c32964fed5906f36a2d913e91e9 (diff) | |
[unstable] [META] refactor whole project.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/ArchKit/ArchKit.hxx')
| -rw-r--r-- | Kernel/ArchKit/ArchKit.hxx | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Kernel/ArchKit/ArchKit.hxx b/Kernel/ArchKit/ArchKit.hxx new file mode 100644 index 00000000..85b0668f --- /dev/null +++ b/Kernel/ArchKit/ArchKit.hxx @@ -0,0 +1,105 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Array.hxx> +#include <NewKit/Defines.hxx> +#include <NewKit/Function.hxx> + +#include <FirmwareKit/Handover.hxx> + +#ifdef __NEWOS_AMD64__ +#include <HALKit/AMD64/HalPageAlloc.hxx> +#include <HALKit/AMD64/Hypervisor.hxx> +#include <HALKit/AMD64/Processor.hxx> +#elif defined(__NEWOS_POWER64__) +#include <HALKit/POWER/Processor.hxx> +#elif defined(__NEWOS_ARM64__) +#include <HALKit/ARM64/Processor.hxx> +#else +#error !!! unknown architecture !!! +#endif + +namespace Kernel +{ + inline SSizeT rt_hash_seed(const char* seed, int mul) + { + SSizeT hash = 0; + + for (SSizeT idx = 0; seed[idx] != 0; ++idx) + { + hash += seed[idx]; + hash ^= mul; + } + + return hash; + } + + /// @brief write to mapped memory register + /// @param base the base address. + /// @param reg the register. + /// @param value the write to write on it. + inline Void ke_dma_write(UInt32 base, UInt32 reg, UInt32 value) noexcept + { + *(volatile UInt32*)((UInt64)base + reg) = value; + } + + /// @brief read from mapped memory register. + /// @param base base address + /// @param reg the register. + /// @return the value inside the register. + inline UInt32 ke_dma_read(UInt32 base, UInt32 reg) noexcept + { + return *(volatile UInt32*)((UInt64)base + reg); + } + + /// @brief Print a region of memory. + /// @param start + /// @param length + inline Void ke_print_raw_memory(const void* start, Size length) + { + const UInt8* ptr = (const UInt8*)start; + + for (Size i = 0; i < length; i++) + { + if (i % 16 == 0) + { + kcout.HexNumber((UIntPtr)ptr + i); + } + else + { + kcout.HexNumber(ptr[i]); + } + + kcout << " "; + } + + kcout << "\r"; + } +} // namespace Kernel + +#define kKernelMaxSystemCalls (256) + +typedef Kernel::Void (*rt_syscall_proc)(Kernel::VoidPtr); + +struct RTSyscallInfoHdr final +{ + Kernel::Int64 fHash; + Kernel::Bool fHooked; + rt_syscall_proc fProc; +}; + +inline Kernel::Array<RTSyscallInfoHdr, + kKernelMaxSystemCalls> + kSyscalls; + +inline Kernel::Array<RTSyscallInfoHdr, + kKernelMaxSystemCalls> + kKerncalls; + +EXTERN_C Kernel::HAL::StackFramePtr rt_get_current_context(); +EXTERN_C Kernel::Void rt_do_context_switch(Kernel::HAL::StackFramePtr stackFrame); |
