From f3d931aa7cfaf96baef8383b59a8938779541ee7 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Thu, 15 Aug 2024 18:35:34 +0200 Subject: [IMP] Moved source code into dev/ folder. Signed-off-by: Amlal EL Mahrouss --- dev/Kernel/ArchKit/ArchKit.hxx | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 dev/Kernel/ArchKit/ArchKit.hxx (limited to 'dev/Kernel/ArchKit/ArchKit.hxx') diff --git a/dev/Kernel/ArchKit/ArchKit.hxx b/dev/Kernel/ArchKit/ArchKit.hxx new file mode 100644 index 00000000..a3fd81a6 --- /dev/null +++ b/dev/Kernel/ArchKit/ArchKit.hxx @@ -0,0 +1,105 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +#include + +#ifdef __NEWOS_AMD64__ +#include +#include +#include +#elif defined(__NEWOS_POWER64__) +#include +#elif defined(__NEWOS_ARM64__) +#include +#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 << hex_number((UIntPtr)ptr + i); + } + else + { + kcout << hex_number(ptr[i]); + } + + kcout << " "; + } + + kcout << "\r"; + } +} // namespace Kernel + +#define kKernelMaxSystemCalls (256) + +typedef Kernel::Void (*rt_syscall_proc)(Kernel::VoidPtr); + +struct HAL_SYSCALL_RECORD final +{ + Kernel::Int64 fHash; + Kernel::Bool fHooked; + rt_syscall_proc fProc; +}; + +inline Kernel::Array + kSyscalls; + +inline Kernel::Array + kKerncalls; + +EXTERN_C Kernel::HAL::StackFramePtr rt_get_current_context(); +EXTERN_C Kernel::Void rt_do_context_switch(Kernel::HAL::StackFramePtr stack_frame); -- cgit v1.2.3