summaryrefslogtreecommitdiffhomepage
path: root/dev/zka
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-22 17:46:11 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-22 17:46:11 +0200
commit8719b4570a2d10dd49a0d3a47e24f5c55bdda85e (patch)
treeba095740888f3768e08b2ea058b0ea6da2d0403d /dev/zka
parent45944b3d2dab04b763fcc6d10164fe8069e60b08 (diff)
:boom: A big refactor on the filesystem structure.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/zka')
-rw-r--r--dev/zka/ArchKit/ArchKit.hxx110
-rw-r--r--dev/zka/CFKit/GUIDWizard.hxx22
-rw-r--r--dev/zka/CFKit/GUIDWrapper.hxx58
-rw-r--r--dev/zka/CFKit/LoaderUtils.hxx53
-rw-r--r--dev/zka/CFKit/Property.hxx47
-rw-r--r--dev/zka/CFKit/URL.hxx33
-rw-r--r--dev/zka/CompilerKit/CompilerKit.hxx13
-rw-r--r--dev/zka/CompilerKit/Detail.hxx27
-rw-r--r--dev/zka/CompilerKit/Version.hxx5
-rw-r--r--dev/zka/CompressKit/RLE.hxx18
-rw-r--r--dev/zka/Docs/Explicit Partition Map.pdfbin0 -> 12326 bytes
-rw-r--r--dev/zka/Docs/SPECIFICATION.md62
-rw-r--r--dev/zka/Docs/TODO-LIST.md25
-rw-r--r--dev/zka/FSKit/Defines.hxx11
-rw-r--r--dev/zka/FSKit/HPFS.hxx12
-rw-r--r--dev/zka/FSKit/IndexableProperty.hxx63
-rw-r--r--dev/zka/FSKit/NeFS.hxx329
-rw-r--r--dev/zka/FirmwareKit/.gitkeep0
-rw-r--r--dev/zka/FirmwareKit/CoreBoot/.gitkeep0
-rw-r--r--dev/zka/FirmwareKit/EFI.hxx9
-rw-r--r--dev/zka/FirmwareKit/EFI/API.hxx114
-rw-r--r--dev/zka/FirmwareKit/EFI/EFI.hxx883
-rw-r--r--dev/zka/FirmwareKit/EPM.hxx122
-rw-r--r--dev/zka/FirmwareKit/Handover.hxx116
-rw-r--r--dev/zka/HALKit/.gitkeep0
-rw-r--r--dev/zka/HALKit/64x0/.hgkeep0
-rw-r--r--dev/zka/HALKit/64x0/APM/.hgkeep0
-rw-r--r--dev/zka/HALKit/64x0/HalVirtualMemory.cxx17
-rw-r--r--dev/zka/HALKit/64x0/MBCI/.gitkeep0
-rw-r--r--dev/zka/HALKit/64x0/ReadMe.md4
-rw-r--r--dev/zka/HALKit/AMD64/CPUID.hxx81
-rw-r--r--dev/zka/HALKit/AMD64/HalACPIFactoryInterface.cxx208
-rw-r--r--dev/zka/HALKit/AMD64/HalAPICMgr.cxx36
-rw-r--r--dev/zka/HALKit/AMD64/HalBMPMgr.cxx182
-rw-r--r--dev/zka/HALKit/AMD64/HalBoot.asm22
-rw-r--r--dev/zka/HALKit/AMD64/HalCommAPI.cxx116
-rw-r--r--dev/zka/HALKit/AMD64/HalControlRegister.s45
-rw-r--r--dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx129
-rw-r--r--dev/zka/HALKit/AMD64/HalCoreMPScheduler.cxx241
-rw-r--r--dev/zka/HALKit/AMD64/HalDebugOutput.cxx145
-rw-r--r--dev/zka/HALKit/AMD64/HalDebugPort.cxx40
-rw-r--r--dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx82
-rw-r--r--dev/zka/HALKit/AMD64/HalInterruptAPI.asm323
-rw-r--r--dev/zka/HALKit/AMD64/HalKernelMain.cxx95
-rw-r--r--dev/zka/HALKit/AMD64/HalMPContextSwitch.asm59
-rw-r--r--dev/zka/HALKit/AMD64/HalRoutineWait.s9
-rw-r--r--dev/zka/HALKit/AMD64/HalSchedulerCore.cxx56
-rw-r--r--dev/zka/HALKit/AMD64/HalTimer.cxx86
-rw-r--r--dev/zka/HALKit/AMD64/HalUtils.asm33
-rw-r--r--dev/zka/HALKit/AMD64/Hypervisor.hxx25
-rw-r--r--dev/zka/HALKit/AMD64/MBCI/.gitkeep0
-rw-r--r--dev/zka/HALKit/AMD64/PCI/Database.cxx11
-rw-r--r--dev/zka/HALKit/AMD64/PCI/Device.cxx141
-rw-r--r--dev/zka/HALKit/AMD64/PCI/Dma.cxx82
-rw-r--r--dev/zka/HALKit/AMD64/PCI/Express.cxx11
-rw-r--r--dev/zka/HALKit/AMD64/PCI/IO.cxx7
-rw-r--r--dev/zka/HALKit/AMD64/PCI/Iterator.cxx39
-rw-r--r--dev/zka/HALKit/AMD64/PCI/PCI.cxx7
-rw-r--r--dev/zka/HALKit/AMD64/Paging.hxx99
-rw-r--r--dev/zka/HALKit/AMD64/Processor.hxx296
-rw-r--r--dev/zka/HALKit/AMD64/ReadMe.md4
-rw-r--r--dev/zka/HALKit/AMD64/Storage/AHCI.cxx123
-rw-r--r--dev/zka/HALKit/AMD64/Storage/ATA-DMA.cxx38
-rw-r--r--dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx199
-rw-r--r--dev/zka/HALKit/ARM64/.gitkeep0
-rw-r--r--dev/zka/HALKit/ARM64/APM/.gitkeep0
-rw-r--r--dev/zka/HALKit/ARM64/HalKernelMain.cxx68
-rw-r--r--dev/zka/HALKit/ARM64/HalPageInternal.S5
-rw-r--r--dev/zka/HALKit/ARM64/HalSchedulerCore.cxx48
-rw-r--r--dev/zka/HALKit/ARM64/HalTimer.cxx16
-rw-r--r--dev/zka/HALKit/ARM64/MBCI/.keepme0
-rw-r--r--dev/zka/HALKit/ARM64/Paging.hxx120
-rw-r--r--dev/zka/HALKit/ARM64/Processor.hxx50
-rw-r--r--dev/zka/HALKit/ARM64/ReadMe.md3
-rw-r--r--dev/zka/HALKit/ARM64/Storage/.gitkeep0
-rw-r--r--dev/zka/HALKit/ARM64/Storage/HalFlash.cxx66
-rw-r--r--dev/zka/HALKit/AXP/CR.s11
-rw-r--r--dev/zka/HALKit/AXP/CoreInterruptHandlerDEC.cpp0
-rw-r--r--dev/zka/HALKit/AXP/CoreSyscallHandlerDEC.cpp24
-rw-r--r--dev/zka/HALKit/AXP/HAL.s13
-rw-r--r--dev/zka/HALKit/AXP/Processor.hxx7
-rw-r--r--dev/zka/HALKit/AXP/README1
-rw-r--r--dev/zka/HALKit/AXP/README.TXT1
-rw-r--r--dev/zka/HALKit/AXP/SYSCALL.s10
-rw-r--r--dev/zka/HALKit/AXP/VM.s5
-rw-r--r--dev/zka/HALKit/POWER/.gitkeep0
-rw-r--r--dev/zka/HALKit/POWER/APM/.gitkeep0
-rw-r--r--dev/zka/HALKit/POWER/HalContextSwitchPowerPC.s30
-rw-r--r--dev/zka/HALKit/POWER/HalHart.cxx25
-rw-r--r--dev/zka/HALKit/POWER/HalSerialPort.cxx27
-rw-r--r--dev/zka/HALKit/POWER/HalStartSequence.s14
-rw-r--r--dev/zka/HALKit/POWER/HalThread.cxx8
-rw-r--r--dev/zka/HALKit/POWER/HalVirtualMemory.cxx51
-rw-r--r--dev/zka/HALKit/POWER/Hart.hxx36
-rw-r--r--dev/zka/HALKit/POWER/MBCI/.gitkeep0
-rw-r--r--dev/zka/HALKit/POWER/MBCI/HalMBCIHost.cxx8
-rw-r--r--dev/zka/HALKit/POWER/Processor.hxx60
-rw-r--r--dev/zka/HALKit/POWER/ReadMe.md4
-rw-r--r--dev/zka/HALKit/RISCV/.keep0
-rw-r--r--dev/zka/HALKit/RISCV/APM/.gitkeep0
-rw-r--r--dev/zka/HALKit/RISCV/Hart.hxx24
-rw-r--r--dev/zka/HALKit/RISCV/ReadMe.md4
-rw-r--r--dev/zka/HALKit/RISCV/Storage/.gitkeep0
-rw-r--r--dev/zka/HALKit/X86S/.gitkeep0
-rw-r--r--dev/zka/HALKit/X86S/ACPI/.gitkeep0
-rw-r--r--dev/zka/HALKit/X86S/Storage/.gitkeep0
-rw-r--r--dev/zka/HintKit/CompilerHint.hxx23
-rw-r--r--dev/zka/KernelKit/CodeMgr.hxx31
-rw-r--r--dev/zka/KernelKit/DebugOutput.hxx196
-rw-r--r--dev/zka/KernelKit/Defines.hxx11
-rw-r--r--dev/zka/KernelKit/DeviceMgr.hxx132
-rw-r--r--dev/zka/KernelKit/DriveMgr.hxx152
-rw-r--r--dev/zka/KernelKit/FileMgr.hxx420
-rw-r--r--dev/zka/KernelKit/Framebuffer.hxx85
-rw-r--r--dev/zka/KernelKit/HardwareThreadScheduler.hxx147
-rw-r--r--dev/zka/KernelKit/Heap.hxx71
-rw-r--r--dev/zka/KernelKit/IDLLObject.hxx44
-rw-r--r--dev/zka/KernelKit/IPEFDLLObject.hxx105
-rw-r--r--dev/zka/KernelKit/LPC.hxx61
-rw-r--r--dev/zka/KernelKit/LoaderInterface.hxx33
-rw-r--r--dev/zka/KernelKit/LockDelegate.hxx67
-rw-r--r--dev/zka/KernelKit/MSDOS.hxx52
-rw-r--r--dev/zka/KernelKit/PCI/Database.hxx38
-rw-r--r--dev/zka/KernelKit/PCI/Device.hxx80
-rw-r--r--dev/zka/KernelKit/PCI/Dma.hxx81
-rw-r--r--dev/zka/KernelKit/PCI/Dma.inl20
-rw-r--r--dev/zka/KernelKit/PCI/Express.hxx11
-rw-r--r--dev/zka/KernelKit/PCI/IO-Impl-AMD64.inl54
-rw-r--r--dev/zka/KernelKit/PCI/IO.hxx59
-rw-r--r--dev/zka/KernelKit/PCI/Iterator.hxx43
-rw-r--r--dev/zka/KernelKit/PCI/PCI.hxx59
-rw-r--r--dev/zka/KernelKit/PE.hxx143
-rw-r--r--dev/zka/KernelKit/PECodeMgr.hxx24
-rw-r--r--dev/zka/KernelKit/PEF.hxx116
-rw-r--r--dev/zka/KernelKit/PEFCodeMgr.hxx67
-rw-r--r--dev/zka/KernelKit/Semaphore.hxx43
-rw-r--r--dev/zka/KernelKit/ThreadLocalStorage.hxx54
-rw-r--r--dev/zka/KernelKit/ThreadLocalStorage.inl74
-rw-r--r--dev/zka/KernelKit/Timer.hxx82
-rw-r--r--dev/zka/KernelKit/User.hxx76
-rw-r--r--dev/zka/KernelKit/UserProcessScheduler.hxx331
-rw-r--r--dev/zka/KernelKit/XCOFF.hxx51
-rw-r--r--dev/zka/KernelRsrc.rsrc25
-rw-r--r--dev/zka/Modules/.gitkeep0
-rw-r--r--dev/zka/Modules/ACPI/.gitkeep0
-rw-r--r--dev/zka/Modules/ACPI/ACPI.hxx88
-rw-r--r--dev/zka/Modules/ACPI/ACPIFactoryInterface.hxx60
-rw-r--r--dev/zka/Modules/AHCI/.gitkeep0
-rw-r--r--dev/zka/Modules/AHCI/AHCI.hxx370
-rw-r--r--dev/zka/Modules/APM/.gitkeep0
-rw-r--r--dev/zka/Modules/ATA/ATA.hxx156
-rw-r--r--dev/zka/Modules/CoreCG/Accessibility.hxx47
-rw-r--r--dev/zka/Modules/CoreCG/FbRenderer.hxx154
-rw-r--r--dev/zka/Modules/CoreCG/Math.hxx22
-rw-r--r--dev/zka/Modules/CoreCG/Rsrc/Cursor.rsrc64
-rw-r--r--dev/zka/Modules/CoreCG/Rsrc/WndControls.rsrc61
-rw-r--r--dev/zka/Modules/CoreCG/TextRenderer.hxx176
-rw-r--r--dev/zka/Modules/CoreCG/WindowRenderer.hxx265
-rw-r--r--dev/zka/Modules/Flash/Flash.hxx21
-rw-r--r--dev/zka/Modules/GL/.keepme0
-rw-r--r--dev/zka/Modules/GPRS/.keepme0
-rw-r--r--dev/zka/Modules/HPET/.gitkeep0
-rw-r--r--dev/zka/Modules/HPET/Defines.hxx42
-rw-r--r--dev/zka/Modules/IEEE802/.gitkeep0
-rw-r--r--dev/zka/Modules/LTE/.keepme0
-rw-r--r--dev/zka/Modules/LTE/IO.hxx28
-rw-r--r--dev/zka/Modules/MBCI/Interface.hxx10
-rw-r--r--dev/zka/Modules/MBCI/MBCI.hxx99
-rw-r--r--dev/zka/Modules/NVME/.gitkeep0
-rw-r--r--dev/zka/Modules/NVME/Defines.hxx112
-rw-r--r--dev/zka/Modules/OHCI/.gitkeep0
-rw-r--r--dev/zka/Modules/ReadMe.md12
-rw-r--r--dev/zka/Modules/SCSI/.gitkeep0
-rw-r--r--dev/zka/Modules/SCSI/SCSI.hxx14
-rw-r--r--dev/zka/Modules/WiFi/.gitkeep0
-rw-r--r--dev/zka/Modules/XHCI/.gitkeep0
-rw-r--r--dev/zka/Modules/XHCI/Defines.hxx70
-rwxr-xr-xdev/zka/MoveAll.ARM64.sh7
-rwxr-xr-xdev/zka/MoveAll.X64.sh7
-rw-r--r--dev/zka/NetworkKit/IP.hxx83
-rw-r--r--dev/zka/NetworkKit/IPC.hxx91
-rw-r--r--dev/zka/NetworkKit/LTE.hxx16
-rw-r--r--dev/zka/NetworkKit/MAC.hxx29
-rw-r--r--dev/zka/NetworkKit/NetworkDevice.hxx80
-rw-r--r--dev/zka/NetworkKit/NetworkDevice.inl32
-rw-r--r--dev/zka/NewKit/Array.hxx73
-rw-r--r--dev/zka/NewKit/ArrayList.hxx58
-rw-r--r--dev/zka/NewKit/Atom.hxx46
-rw-r--r--dev/zka/NewKit/Crc32.hxx23
-rw-r--r--dev/zka/NewKit/CxxAbi.hxx28
-rw-r--r--dev/zka/NewKit/Defines.hxx189
-rw-r--r--dev/zka/NewKit/ErrorOr.hxx72
-rw-r--r--dev/zka/NewKit/Function.hxx53
-rw-r--r--dev/zka/NewKit/Json.hxx137
-rw-r--r--dev/zka/NewKit/KernelCheck.hxx71
-rw-r--r--dev/zka/NewKit/Macros.hxx133
-rw-r--r--dev/zka/NewKit/MutableArray.hxx239
-rw-r--r--dev/zka/NewKit/New.hxx18
-rw-r--r--dev/zka/NewKit/NewKit.hxx21
-rw-r--r--dev/zka/NewKit/OwnPtr.hxx94
-rw-r--r--dev/zka/NewKit/PageMgr.hxx81
-rw-r--r--dev/zka/NewKit/Pair.hxx14
-rw-r--r--dev/zka/NewKit/Pmm.hxx44
-rw-r--r--dev/zka/NewKit/Ref.hxx104
-rw-r--r--dev/zka/NewKit/Stream.hxx58
-rw-r--r--dev/zka/NewKit/String.hxx88
-rw-r--r--dev/zka/NewKit/Utils.hxx29
-rw-r--r--dev/zka/NewKit/Variant.hxx64
-rw-r--r--dev/zka/Objects/.hgkeep0
-rw-r--r--dev/zka/ReadMe.md3
-rw-r--r--dev/zka/StorageKit/AHCI.hxx33
-rw-r--r--dev/zka/StorageKit/ATA.hxx39
-rw-r--r--dev/zka/StorageKit/NVME.hxx36
-rw-r--r--dev/zka/StorageKit/PRDT.hxx36
-rw-r--r--dev/zka/StorageKit/SCSI.hxx11
-rw-r--r--dev/zka/StorageKit/Storage.hxx22
-rw-r--r--dev/zka/amd64-efi.make85
-rw-r--r--dev/zka/arm64-efi.make64
-rw-r--r--dev/zka/power64-cb.make4
-rw-r--r--dev/zka/riscv64-cb.make0
-rw-r--r--dev/zka/src/Array.cxx7
-rw-r--r--dev/zka/src/ArrayList.cxx7
-rw-r--r--dev/zka/src/Atom.cxx10
-rw-r--r--dev/zka/src/CodeMgr.cxx33
-rw-r--r--dev/zka/src/Crc32.cxx74
-rw-r--r--dev/zka/src/CxxAbi-AMD64.cxx91
-rw-r--r--dev/zka/src/CxxAbi-ARM64.cxx74
-rw-r--r--dev/zka/src/Defines.cxx7
-rw-r--r--dev/zka/src/DeviceMgr.cxx7
-rw-r--r--dev/zka/src/DriveMgr.cxx151
-rw-r--r--dev/zka/src/ErrorOr.cxx12
-rw-r--r--dev/zka/src/FS/FAT32.cxx12
-rw-r--r--dev/zka/src/FS/NeFS.cxx1055
-rw-r--r--dev/zka/src/FileMgr.cxx190
-rw-r--r--dev/zka/src/Framebuffer.cxx113
-rw-r--r--dev/zka/src/GUIDWizard.cxx72
-rw-r--r--dev/zka/src/GUIDWrapper.cxx11
-rw-r--r--dev/zka/src/HardwareThreadScheduler.cxx195
-rw-r--r--dev/zka/src/Heap.cxx268
-rw-r--r--dev/zka/src/IDLLObject.cxx15
-rw-r--r--dev/zka/src/IPEFDLLObject.cxx100
-rw-r--r--dev/zka/src/IndexableProperty.cxx59
-rw-r--r--dev/zka/src/Json.cxx12
-rw-r--r--dev/zka/src/KernelCheck.cxx155
-rw-r--r--dev/zka/src/LPC.cxx34
-rw-r--r--dev/zka/src/LockDelegate.cxx12
-rw-r--r--dev/zka/src/MutableArray.cxx7
-rw-r--r--dev/zka/src/NeFS+FileMgr.cxx110
-rw-r--r--dev/zka/src/NeFS+IO.cxx101
-rw-r--r--dev/zka/src/Network/IP.cxx126
-rw-r--r--dev/zka/src/Network/IPC.cxx114
-rw-r--r--dev/zka/src/Network/NetworkDevice.cxx35
-rw-r--r--dev/zka/src/New+Delete.cxx50
-rw-r--r--dev/zka/src/OwnPtr.cxx7
-rw-r--r--dev/zka/src/PEFCodeMgr.cxx258
-rw-r--r--dev/zka/src/PRDT.cxx22
-rw-r--r--dev/zka/src/PageMgr.cxx111
-rw-r--r--dev/zka/src/Pmm.cxx94
-rw-r--r--dev/zka/src/Property.cxx27
-rw-r--r--dev/zka/src/Ref.cxx7
-rw-r--r--dev/zka/src/Semaphore.cxx62
-rw-r--r--dev/zka/src/Storage/AHCIDeviceInterface.cxx35
-rw-r--r--dev/zka/src/Storage/ATADeviceInterface.cxx88
-rw-r--r--dev/zka/src/Storage/NVMEDeviceInterface.cxx28
-rw-r--r--dev/zka/src/Storage/SCSIDeviceInterface.cxx11
-rw-r--r--dev/zka/src/Stream.cxx12
-rw-r--r--dev/zka/src/String.cxx257
-rw-r--r--dev/zka/src/ThreadLocalStorage.cxx68
-rw-r--r--dev/zka/src/Timer.cxx47
-rw-r--r--dev/zka/src/URL.cxx98
-rw-r--r--dev/zka/src/User.cxx138
-rw-r--r--dev/zka/src/UserProcessScheduler.cxx484
-rw-r--r--dev/zka/src/UserProcessTeam.cxx38
-rw-r--r--dev/zka/src/UserThreadScheduler.cxx49
-rw-r--r--dev/zka/src/Utils.cxx212
-rw-r--r--dev/zka/src/Variant.cxx31
276 files changed, 18912 insertions, 0 deletions
diff --git a/dev/zka/ArchKit/ArchKit.hxx b/dev/zka/ArchKit/ArchKit.hxx
new file mode 100644
index 00000000..3c617705
--- /dev/null
+++ b/dev/zka/ArchKit/ArchKit.hxx
@@ -0,0 +1,110 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Function.hxx>
+
+#include <FirmwareKit/Handover.hxx>
+
+#ifdef __ZKA_AMD64__
+#include <HALKit/AMD64/Paging.hxx>
+#include <HALKit/AMD64/Hypervisor.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+#elif defined(__ZKA_POWER64__)
+#include <HALKit/POWER/Processor.hxx>
+#elif defined(__ZKA_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 << 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;
+
+ operator bool()
+ {
+ return fHooked;
+ }
+};
+
+inline Kernel::Array<HAL_SYSCALL_RECORD,
+ kKernelMaxSystemCalls>
+ kSyscalls;
+
+inline Kernel::Array<HAL_SYSCALL_RECORD,
+ kKernelMaxSystemCalls>
+ kKerncalls;
+
+EXTERN_C Kernel::HAL::StackFramePtr mp_get_current_context();
+EXTERN_C Kernel::Void mp_do_user_switch(Kernel::Void);
diff --git a/dev/zka/CFKit/GUIDWizard.hxx b/dev/zka/CFKit/GUIDWizard.hxx
new file mode 100644
index 00000000..034aceea
--- /dev/null
+++ b/dev/zka/CFKit/GUIDWizard.hxx
@@ -0,0 +1,22 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CFKit/GUIDWrapper.hxx>
+#include <NewKit/Array.hxx>
+#include <NewKit/ArrayList.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Ref.hxx>
+#include <NewKit/Stream.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel::XRN::Version1
+{
+ Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq);
+ ErrorOr<Ref<Kernel::StringView>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid);
+} // namespace Kernel::XRN::Version1
diff --git a/dev/zka/CFKit/GUIDWrapper.hxx b/dev/zka/CFKit/GUIDWrapper.hxx
new file mode 100644
index 00000000..8810f303
--- /dev/null
+++ b/dev/zka/CFKit/GUIDWrapper.hxx
@@ -0,0 +1,58 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+#include <NewKit/Stream.hxx>
+
+/* GUID for C++ Components */
+
+#define kXRNNil "@{........-....-M...-N...-............}"
+
+// eXtensible Resource Information
+namespace Kernel::XRN
+{
+ union GUIDSequence {
+ alignas(8) UShort u8[16];
+ alignas(8) UShort u16[8];
+ alignas(8) UInt u32[4];
+ alignas(8) ULong u64[2];
+
+ struct
+ {
+ alignas(8) UInt fMs1;
+ UShort fMs2;
+ UShort fMs3;
+ UChar fMs4[8];
+ };
+ };
+
+ class GUID final
+ {
+ public:
+ explicit GUID() = default;
+ ~GUID() = default;
+
+ public:
+ GUID& operator=(const GUID&) = default;
+ GUID(const GUID&) = default;
+
+ public:
+ GUIDSequence& operator->() noexcept
+ {
+ return fUUID;
+ }
+ GUIDSequence& Leak() noexcept
+ {
+ return fUUID;
+ }
+
+ private:
+ GUIDSequence fUUID;
+ };
+} // namespace Kernel::XRN
diff --git a/dev/zka/CFKit/LoaderUtils.hxx b/dev/zka/CFKit/LoaderUtils.hxx
new file mode 100644
index 00000000..7385fc2e
--- /dev/null
+++ b/dev/zka/CFKit/LoaderUtils.hxx
@@ -0,0 +1,53 @@
+#ifndef __CFKIT_LOADER_UTILS_HXX__
+#define __CFKIT_LOADER_UTILS_HXX__
+
+#include <KernelKit/PE.hxx>
+#include <KernelKit/MSDOS.hxx>
+
+namespace Kernel
+{
+ /// @brief Find the PE header inside the blob.
+ inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> LDR_EXEC_HEADER_PTR
+ {
+ if (!ptrDos)
+ return nullptr;
+
+ if (ptrDos->eMagic[0] != kMagMz0)
+ return nullptr;
+
+ if (ptrDos->eMagic[1] != kMagMz1)
+ return nullptr;
+
+ return (LDR_EXEC_HEADER_PTR)(VoidPtr)(&ptrDos->eLfanew + 1);
+ }
+
+ /// @brief Find the PE optional header inside the blob.
+ inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> LDR_OPTIONAL_HEADER_PTR
+ {
+ if (!ptrDos)
+ return nullptr;
+
+ auto exec = ldr_find_exec_header(ptrDos);
+
+ if (!exec)
+ return nullptr;
+
+ return (LDR_OPTIONAL_HEADER_PTR)(VoidPtr)(&exec->mCharacteristics + 1);
+ }
+
+ /// @brief Find the PE header inside the blob.
+ /// @note overloaded function.
+ inline auto ldr_find_exec_header(const Char* ptrDos) -> LDR_EXEC_HEADER_PTR
+ {
+ return ldr_find_exec_header((DosHeaderPtr)ptrDos);
+ }
+
+ /// @brief Find the PE header inside the blob.
+ /// @note overloaded function.
+ inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> LDR_OPTIONAL_HEADER_PTR
+ {
+ return ldr_find_opt_exec_header((DosHeaderPtr)ptrDos);
+ }
+} // namespace Kernel
+
+#endif // ifndef __CFKIT_LOADER_UTILS_HXX__
diff --git a/dev/zka/CFKit/Property.hxx b/dev/zka/CFKit/Property.hxx
new file mode 100644
index 00000000..eb9b4816
--- /dev/null
+++ b/dev/zka/CFKit/Property.hxx
@@ -0,0 +1,47 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __INC_PROPS_HPP__
+#define __INC_PROPS_HPP__
+
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Function.hxx>
+#include <NewKit/String.hxx>
+
+#define cMaxPropLen 4096
+
+namespace Kernel
+{
+ /// @brief handle to anything (number, ptr, string...)
+ using PropertyId = UIntPtr;
+
+ /// @brief Kernel property class.
+ /// @example \Properties\SmpCores or \Properties\KernelVersion
+ class Property
+ {
+ public:
+ Property() = default;
+ virtual ~Property();
+
+ public:
+ Property& operator=(const Property&) = default;
+ Property(const Property&) = default;
+
+ bool StringEquals(StringView& name);
+ PropertyId& GetValue();
+ StringView& GetKey();
+
+ private:
+ StringView fName{cMaxPropLen};
+ PropertyId fAction{No};
+ };
+
+ template <SizeT N>
+ using PropertyArray = Array<Property, N>;
+} // namespace Kernel
+
+#endif // !__INC_PROPS_HPP__
diff --git a/dev/zka/CFKit/URL.hxx b/dev/zka/CFKit/URL.hxx
new file mode 100644
index 00000000..02cced28
--- /dev/null
+++ b/dev/zka/CFKit/URL.hxx
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_URL_HPP_
+#define _INC_URL_HPP_
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel
+{
+ class URL final
+ {
+ public:
+ explicit URL(StringView& strUrl);
+ ~URL();
+
+ public:
+ Ref<ErrorOr<StringView>> Location() noexcept;
+ Ref<ErrorOr<StringView>> Protocol() noexcept;
+
+ private:
+ Ref<StringView> fUrlView;
+ };
+
+ ErrorOr<StringView> url_extract_location(const Char* url);
+ ErrorOr<StringView> url_extract_protocol(const Char* url);
+} // namespace Kernel
+
+#endif /* ifndef _INC_URL_HPP_ */
diff --git a/dev/zka/CompilerKit/CompilerKit.hxx b/dev/zka/CompilerKit/CompilerKit.hxx
new file mode 100644
index 00000000..f2ec4db2
--- /dev/null
+++ b/dev/zka/CompilerKit/CompilerKit.hxx
@@ -0,0 +1,13 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_CL_HPP
+#define _INC_CL_HPP
+
+#include <CompilerKit/Detail.hxx>
+#include <CompilerKit/Version.hxx>
+
+#endif /* ifndef _INC_CL_HPP */
diff --git a/dev/zka/CompilerKit/Detail.hxx b/dev/zka/CompilerKit/Detail.hxx
new file mode 100644
index 00000000..d0b8d153
--- /dev/null
+++ b/dev/zka/CompilerKit/Detail.hxx
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#ifdef __NEWOSKRNL__
+#include <NewKit/Defines.hxx>
+#endif // ifdef __NEWOSKRNL__
+
+#define ZKA_COPY_DELETE(KLASS) \
+ KLASS& operator=(const KLASS&) = delete; \
+ KLASS(const KLASS&) = delete;
+
+#define ZKA_COPY_DEFAULT(KLASS) \
+ KLASS& operator=(const KLASS&) = default; \
+ KLASS(const KLASS&) = default;
+
+#define ZKA_MOVE_DELETE(KLASS) \
+ KLASS& operator=(KLASS&&) = delete; \
+ KLASS(KLASS&&) = delete;
+
+#define ZKA_MOVE_DEFAULT(KLASS) \
+ KLASS& operator=(KLASS&&) = default; \
+ KLASS(KLASS&&) = default;
diff --git a/dev/zka/CompilerKit/Version.hxx b/dev/zka/CompilerKit/Version.hxx
new file mode 100644
index 00000000..83f7f534
--- /dev/null
+++ b/dev/zka/CompilerKit/Version.hxx
@@ -0,0 +1,5 @@
+#pragma once
+
+/// <COMMIT NUMBER>.<YEAR>.<PROGRAM VERSION>
+#define BOOTLOADER_VERSION "843.2024.1"
+#define KERNEL_VERSION "843.2024.1"
diff --git a/dev/zka/CompressKit/RLE.hxx b/dev/zka/CompressKit/RLE.hxx
new file mode 100644
index 00000000..647cf00b
--- /dev/null
+++ b/dev/zka/CompressKit/RLE.hxx
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __KERNELKIT_RLE_HXX__
+#define __KERNELKIT_RLE_HXX__
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ EXTERN_C Void rle_compress(VoidPtr data, Size sz, VoidPtr out, Size out_sz);
+ EXTERN_C Void rle_decompress(VoidPtr data, Size sz, VoidPtr out, Size out_sz);
+} // namespace Kernel
+
+#endif // !ifndef __KERNELKIT_RLE_HXX__
diff --git a/dev/zka/Docs/Explicit Partition Map.pdf b/dev/zka/Docs/Explicit Partition Map.pdf
new file mode 100644
index 00000000..1e2f5318
--- /dev/null
+++ b/dev/zka/Docs/Explicit Partition Map.pdf
Binary files differ
diff --git a/dev/zka/Docs/SPECIFICATION.md b/dev/zka/Docs/SPECIFICATION.md
new file mode 100644
index 00000000..c38fa122
--- /dev/null
+++ b/dev/zka/Docs/SPECIFICATION.md
@@ -0,0 +1,62 @@
+===================================
+
+# 0: General Information
+
+===================================
+
+- ABI and Format: PEF/PE32+.
+- Kernel architecture: Portable hybrid Kernel.
+- Language: C++/(Assembly (AMD64, X64000, X86S, ARM64, POWER, RISCV))
+
+===================================
+
+# 1: The Kernel
+
+===================================
+
+- Drive/Device Abstraction.
+- SMP, Preemptive Multi Threading.
+- Separation of Files/Devices.
+- Networking.
+- Hardware Abstraction Layer.
+- Native Filesystem support (NeFS, FAT32 and ffs2).
+- Program Loaders interfaces.
+- TLS (Thread Local Storage) support.
+- Semaphore, Locks, Timers.
+- Canary mechanisms.
+- Dynamic Sys.
+- Cross Platform.
+- Permission Selectors.
+
+===================================
+
+# 2: The Filesystem
+
+===================================
+
+- Catalog object with associated forks.
+- Large storage support.
+- Long file names.
+- UNIX path style.
+
+==================================
+
+# 3: Common naming conventions:
+
+==================================
+
+- Kernel -> ke_init_x
+- RunTime -> rt_copy_mem
+- Hal -> hal_foo_bar
+
+===================================
+
+# 4: The newosldr
+
+===================================
+
+- Capable of booting from a network drive.
+- Loads a PE file which is the Kernel.
+- Sanity checks, based on the number of sections.
+- Handover compliant.
+- Does check for a valid partition (useful in the case of recovering)
diff --git a/dev/zka/Docs/TODO-LIST.md b/dev/zka/Docs/TODO-LIST.md
new file mode 100644
index 00000000..2b4ea96c
--- /dev/null
+++ b/dev/zka/Docs/TODO-LIST.md
@@ -0,0 +1,25 @@
+# TODO list
+
+- We need preemptive multi-threading. [ X ]
+- We then need sync primitives. [ X ]
+- We also need a system library for the OS. [ X ]
+- We need a bootloader for AMD64 [ X ]
+ - Implement Boot Services [ X ]
+ - Design Handover [ X ]
+ - Load Kernel into memory [ X ]
+ - Fix bug in Kernel loader, which causes a 06 #UD. [ X ]
+ - Load Kernel [ X ]
+ - Add IDT [ X ]
+ - AHCI driver [ WiP ]
+- Context switch x87/SSE/AVX registers [ X ]
+- Framebuffer [ X ]
+- ATA support [ X ]
+- Make installer [ X ]
+
+Status:
+
+NEWOSLDR: Need to boot from EPM partition. [ X ]
+<br>
+newoskrnl: New Filesystem is done. [ X ]
+
+**Refer to Jira please!**
diff --git a/dev/zka/FSKit/Defines.hxx b/dev/zka/FSKit/Defines.hxx
new file mode 100644
index 00000000..de33dd3a
--- /dev/null
+++ b/dev/zka/FSKit/Defines.hxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define FSKIT_VERSION "1.00"
diff --git a/dev/zka/FSKit/HPFS.hxx b/dev/zka/FSKit/HPFS.hxx
new file mode 100644
index 00000000..6f5ff3f4
--- /dev/null
+++ b/dev/zka/FSKit/HPFS.hxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+/// @file HPFS.hxx
+/// @brief HPFS support. \ No newline at end of file
diff --git a/dev/zka/FSKit/IndexableProperty.hxx b/dev/zka/FSKit/IndexableProperty.hxx
new file mode 100644
index 00000000..56e5de1c
--- /dev/null
+++ b/dev/zka/FSKit/IndexableProperty.hxx
@@ -0,0 +1,63 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CFKit/Property.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/DriveMgr.hxx>
+
+#define kIndexerNodeNameLength 255
+#define kIndexerClaimed 0xCF
+
+namespace Kernel
+{
+ namespace Indexer
+ {
+ struct IndexProperty final
+ {
+ public:
+ Char Drive[kDriveNameLen];
+ Char Path[kIndexerNodeNameLength];
+ };
+
+ class IndexableProperty final : public Property
+ {
+ public:
+ explicit IndexableProperty()
+ : Property()
+ {
+ Kernel::StringView strProp(cMaxPropLen);
+ strProp += "\\Properties\\Indexable";
+
+ this->GetKey() = strProp;
+ }
+
+ ~IndexableProperty() override = default;
+
+ ZKA_COPY_DEFAULT(IndexableProperty);
+
+ public:
+ IndexProperty& Leak() noexcept;
+
+ public:
+ void AddFlag(Int16 flag);
+ void RemoveFlag(Int16 flag);
+ Int16 HasFlag(Int16 flag);
+
+ private:
+ IndexProperty fIndex;
+ UInt32 fFlags;
+ };
+
+ /// @brief Index a file into the indexer instance.
+ /// @param filename path
+ /// @param filenameLen used bytes in path.
+ /// @param indexer the filesystem indexer.
+ /// @return none.
+ Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& indexer);
+ } // namespace Indexer
+} // namespace Kernel
diff --git a/dev/zka/FSKit/NeFS.hxx b/dev/zka/FSKit/NeFS.hxx
new file mode 100644
index 00000000..442b19ce
--- /dev/null
+++ b/dev/zka/FSKit/NeFS.hxx
@@ -0,0 +1,329 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ FILE: NeFS.hxx
+ PURPOSE: NeFS (New FileSystem) support, can be used with kernel, HPFS is preferred.
+
+ Revision History:
+
+ ?/?/?: Added file (amlel)
+ 12/02/24: Add UUID macro for EPM and GPT partition schemes.
+ 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by
+default.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <HintKit/CompilerHint.hxx>
+#include <KernelKit/DriveMgr.hxx>
+#include <NewKit/Defines.hxx>
+
+/**
+ @brief New File System specification.
+ @author Amlal EL Mahrouss
+*/
+
+#define kNeFSInvalidFork (-1)
+#define kNeFSInvalidCatalog (-1)
+#define kNeFSNodeNameLen (256)
+
+#define kNeFSSectorSz (512)
+#define kNeFSForkDataSz (mib_cast(16))
+
+#define kNeFSIdentLen (8)
+#define kNeFSIdent " NeFS"
+#define kNeFSPadLen (392)
+
+#define kNeFSMetaFilePrefix '$'
+
+#define kNeFSVersionInteger (0x0128)
+#define kNeFSVerionString "1.28"
+
+/// @brief Standard fork types.
+#define kNeFSDataFork "main_data"
+#define kNeFSResourceFork "main_rsrc"
+
+#define kNeFSForkSize (sizeof(NFS_FORK_STRUCT))
+
+#define kNeFSPartitionTypeStandard (7)
+#define kNeFSPartitionTypePage (8)
+#define kNeFSPartitionTypeBoot (9)
+
+#define kNeFSCatalogKindFile (1)
+#define kNeFSCatalogKindDir (2)
+#define kNeFSCatalogKindAlias (3)
+
+//! Shared between network and/or partitions. Export forks as .zip when copying.
+#define kNeFSCatalogKindShared (4)
+
+#define kNeFSCatalogKindResource (5)
+#define kNeFSCatalogKindExecutable (6)
+
+#define kNeFSCatalogKindPage (8)
+
+#define kNeFSCatalogKindDevice (9)
+#define kNeFSCatalogKindLock (10)
+
+#define kNeFSCatalogKindRLE (11)
+#define kNeFSCatalogKindMetaFile (12)
+
+#define kNeFSCatalogKindTTF (13)
+#define kNeFSCatalogKindRIFF (14)
+
+#define kNeFSSeparator '\\'
+#define kNeFSSeparatorAlt '/'
+
+#define kNeFSUpDir ".."
+#define kNeFSRoot "\\"
+#define kNeFSRootAlt "/"
+
+#define kNeFSLF '\r'
+#define kNeFSEOF (-1)
+
+#define kNeFSBitWidth (sizeof(Kernel::Char))
+#define kNeFSLbaType (Kernel::Lba)
+
+/// @note Start after the partition map header. (Virtual addressing)
+#define kNeFSRootCatalogStartAddress (1024)
+#define kNeFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK))
+
+#define kResourceTypeDialog (10)
+#define kResourceTypeString (11)
+#define kResourceTypeMenu (12)
+#define kResourceTypeSound (13)
+#define kResourceTypeFont (14)
+
+#define kConfigLen (64)
+#define kPartLen (32)
+
+#define kNeFSFlagDeleted (70)
+#define kNeFSFlagUnallocated (0)
+#define kNeFSFlagCreated (71)
+
+#define kNeFSMimeNameLen (200)
+
+#define kNeFSForkNameLen (200U)
+
+struct NFS_CATALOG_STRUCT;
+struct NFS_FORK_STRUCT;
+struct NFS_ROOT_PARTITION_BLOCK;
+
+enum
+{
+ kNeFSHardDrive = 0xC0, // Hard Drive
+ kNeFSSolidStateDrive = 0xC1, // Solid State Drive
+ kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD
+ kNeFSMassStorageDevice = 0xCC, // USB
+ kNeFSScsi = 0xC4, // SCSI Hard Drive
+ kNeFSFlashDrive = 0xC6,
+ kNeFSUnknown = 0xFF, // Unknown device.
+ kNeFSDriveCount = 7,
+};
+
+/// @brief Catalog type.
+struct PACKED NFS_CATALOG_STRUCT final
+{
+ Kernel::Char Name[kNeFSNodeNameLen];
+ Kernel::Char Mime[kNeFSMimeNameLen];
+
+ /// Catalog status flag.
+ Kernel::UInt16 Flags;
+ /// Custom catalog flags.
+ Kernel::UInt16 FileFlags;
+ /// Catalog kind.
+ Kernel::Int32 Kind;
+
+ /// Size of the data fork.
+ Kernel::Lba DataForkSize;
+
+ /// Size of all resource forks.
+ Kernel::Lba ResourceForkSize;
+
+ Kernel::Lba DataFork;
+ Kernel::Lba ResourceFork;
+
+ Kernel::Lba NextSibling;
+ Kernel::Lba PrevSibling;
+};
+
+/// @brief Fork type, contains a data page.
+/// @note The way we store is way different than how other filesystems do, specific chunk of code are
+/// written into either the data fork or resource fork, the resource fork is reserved for file metadata.
+/// whereas the data fork is reserved for file data.
+struct PACKED NFS_FORK_STRUCT final
+{
+ Kernel::Char ForkName[kNeFSForkNameLen];
+ Kernel::Char CatalogName[kNeFSNodeNameLen];
+
+ Kernel::Int32 Flags;
+ Kernel::Int32 Kind;
+
+ Kernel::Int64 ResourceId;
+ Kernel::Int32 ResourceKind;
+ Kernel::Int32 ResourceFlags;
+
+ Kernel::Lba DataOffset; // 8 Where to look for this data?
+ Kernel::SizeT DataSize; /// Data size according using sector count.
+
+ Kernel::Lba NextSibling;
+ Kernel::Lba PreviousSibling;
+};
+
+/// @brief Partition block type
+struct PACKED NFS_ROOT_PARTITION_BLOCK final
+{
+ Kernel::Char Ident[kNeFSIdentLen];
+ Kernel::Char PartitionName[kPartLen];
+
+ Kernel::Int32 Flags;
+ Kernel::Int32 Kind;
+
+ Kernel::Lba StartCatalog;
+ Kernel::SizeT CatalogCount;
+
+ Kernel::SizeT DiskSize;
+
+ Kernel::SizeT FreeCatalog;
+ Kernel::SizeT FreeSectors;
+
+ Kernel::SizeT SectorCount;
+ Kernel::SizeT SectorSize;
+
+ Kernel::UInt64 Version;
+
+ Kernel::Lba EpmBlock;
+
+ Kernel::Char Pad[kNeFSPadLen];
+};
+
+namespace Kernel
+{
+ enum
+ {
+ kNeFSSubDriveA,
+ kNeFSSubDriveB,
+ kNeFSSubDriveC,
+ kNeFSSubDriveD,
+ kNeFSSubDriveInvalid,
+ kNeFSSubDriveCount,
+ };
+
+ /// \brief Resource fork kind.
+ enum
+ {
+ kNeFSRsrcForkKind = 0,
+ kNeFSDataForkKind = 1
+ };
+
+ ///
+ /// \name NeFSParser
+ /// \brief NeFS parser class. (catalog creation, remove removal, root,
+ /// forks...) Designed like the DOM, detects the filesystem automatically.
+ ///
+ class NeFSParser final
+ {
+ public:
+ explicit NeFSParser() = default;
+ ~NeFSParser() = default;
+
+ public:
+ ZKA_COPY_DEFAULT(NeFSParser);
+
+ public:
+ /// @brief Creates a new fork inside the New filesystem partition.
+ /// @param catalog it's catalog
+ /// @param theFork the fork itself.
+ /// @return the fork
+ _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
+ _Input NFS_FORK_STRUCT& theFork);
+
+ /// @brief Find fork inside New filesystem.
+ /// @param catalog the catalog.
+ /// @param name the fork name.
+ /// @return the fork.
+ _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog,
+ _Input const Char* name,
+ Boolean dataOrRsrc);
+
+ _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork);
+
+ _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork);
+
+ _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba);
+
+ _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name);
+
+ _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name,
+ _Input const Int32& flags,
+ _Input const Int32& kind);
+
+ _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name);
+
+ Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
+ _Input Bool isRsrcFork,
+ _Input VoidPtr data,
+ _Input SizeT sizeOfData,
+ _Input const Char* forkName);
+
+ VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
+ _Input Bool isRsrcFork,
+ _Input SizeT dataSz,
+ _Input const Char* forkName);
+
+ bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off);
+
+ SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog);
+
+ bool RemoveCatalog(_Input const Char* catalog);
+
+ bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog);
+
+ /// @brief Make a EPM+NeFS drive out of the disk.
+ /// @param drive The drive to write on.
+ /// @return If it was sucessful, see ErrLocal().
+ bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name);
+
+ public:
+ Int32 fDriveIndex{kNeFSSubDriveA};
+ };
+
+ ///
+ /// \name NeFileSystemHelper
+ /// \brief Filesystem helper and utils.
+ ///
+
+ class NeFileSystemHelper final
+ {
+ public:
+ STATIC const Char* Root();
+ STATIC const Char* UpDir();
+ STATIC const Char Separator();
+ STATIC const Char MetaFile();
+ };
+
+ namespace Detail
+ {
+ Boolean fs_init_newfs(Void) noexcept;
+ } // namespace Detail
+} // namespace Kernel
+
+/// @brief Write to newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt,
+ Kernel::DriveTrait& DrvTrait,
+ Kernel::Int32 DrvIndex);
+
+/// @brief Read from newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt,
+ Kernel::DriveTrait& DrvTrait,
+ Kernel::Int32 DrvIndex);
diff --git a/dev/zka/FirmwareKit/.gitkeep b/dev/zka/FirmwareKit/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/FirmwareKit/.gitkeep
diff --git a/dev/zka/FirmwareKit/CoreBoot/.gitkeep b/dev/zka/FirmwareKit/CoreBoot/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/FirmwareKit/CoreBoot/.gitkeep
diff --git a/dev/zka/FirmwareKit/EFI.hxx b/dev/zka/FirmwareKit/EFI.hxx
new file mode 100644
index 00000000..a6c4616f
--- /dev/null
+++ b/dev/zka/FirmwareKit/EFI.hxx
@@ -0,0 +1,9 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <FirmwareKit/EFI/EFI.hxx>
+
+/// @note this header is used to reference the EFI/EFI.hxx \ No newline at end of file
diff --git a/dev/zka/FirmwareKit/EFI/API.hxx b/dev/zka/FirmwareKit/EFI/API.hxx
new file mode 100644
index 00000000..6245e0e4
--- /dev/null
+++ b/dev/zka/FirmwareKit/EFI/API.hxx
@@ -0,0 +1,114 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __EFI_API__
+#define __EFI_API__
+
+#include <FirmwareKit/EFI/EFI.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/MSDOS.hxx>
+#include <KernelKit/PE.hxx>
+
+#define kZKASubsystem 17
+
+#ifdef __NEWOSLDR__
+// forward decl.
+class BTextWriter;
+
+#define __BOOTKIT_NO_INCLUDE__ 1
+
+#include <BootKit/BootKit.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#endif // ifdef __NEWOSLDR__
+
+inline EfiSystemTable* ST = nullptr;
+inline EfiBootServices* BS = nullptr;
+
+EXTERN_C void rt_cli();
+EXTERN_C void rt_hlt();
+
+namespace EFI
+{
+ /// @brief Halt and clear interrupts.
+ /// @return
+ inline Void Stop() noexcept
+ {
+ while (1)
+ {
+ rt_hlt();
+ rt_cli();
+ }
+ }
+
+ /**
+@brief Exit EFI API to let the OS load correctly.
+Bascially frees everything we have in the EFI side.
+*/
+ inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept
+ {
+ if (!ST)
+ return;
+
+ ST->BootServices->ExitBootServices(ImageHandle, MapKey);
+ }
+
+ enum
+ {
+ kPartEPM,
+ kPartGPT,
+ kPartMBR,
+ kPartCnt,
+ };
+
+ inline UInt32 Platform() noexcept
+ {
+ return kPeMachineAMD64;
+ }
+
+ /***
+ * @brief Throw an error, stop execution as well.
+ * @param ErrorCode error code to be print.
+ * @param Reason reason to be print.
+ */
+ inline void ThrowError(const EfiCharType* ErrorCode,
+ const EfiCharType* Reason) noexcept
+ {
+ ST->ConOut->OutputString(ST->ConOut, L"\r*** STOP ***\r");
+
+ ST->ConOut->OutputString(ST->ConOut, L"*** Error: ");
+ ST->ConOut->OutputString(ST->ConOut, ErrorCode);
+
+ ST->ConOut->OutputString(ST->ConOut, L", Reason: ");
+ ST->ConOut->OutputString(ST->ConOut, Reason);
+
+ ST->ConOut->OutputString(ST->ConOut, L" ***\r");
+
+ EFI::Stop();
+ }
+} // namespace EFI
+
+inline void InitEFI(EfiSystemTable* SystemTable) noexcept
+{
+ if (!SystemTable)
+ return;
+
+ ST = SystemTable;
+ BS = ST->BootServices;
+
+ ST->ConOut->ClearScreen(SystemTable->ConOut);
+ ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow);
+
+ ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr);
+ ST->ConOut->EnableCursor(ST->ConOut, false);
+}
+
+#ifdef __NEWOSLDR__
+
+#include <BootKit/Platform.hxx>
+
+#endif // ifdef __NEWOSLDR__
+
+#endif /* ifndef __EFI_API__ */
diff --git a/dev/zka/FirmwareKit/EFI/EFI.hxx b/dev/zka/FirmwareKit/EFI/EFI.hxx
new file mode 100644
index 00000000..76a1d933
--- /dev/null
+++ b/dev/zka/FirmwareKit/EFI/EFI.hxx
@@ -0,0 +1,883 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __EFI__
+#define __EFI__
+
+/**
+@brief Kernel Implementation of EFI.
+@note This API is in WiP, so it's not 'pretty', just deal with it. We'll be
+improving that later.
+@author Amlal El Mahrouss
+*/
+
+#include <NewKit/Defines.hxx>
+
+using namespace Kernel;
+
+/* we always use stdcall in EFI, the pascal way of calling functions. */
+
+#ifndef EPI_API
+#define EFI_API __attribute__((ms_abi))
+#endif // ifndef EPI_API
+
+#define IN
+#define OUT
+#define OPTIONAL
+
+// Forward decls
+
+struct EfiTableHeader;
+struct EfiLoadFileProtocol;
+struct EfiSimpleTextOutputProtocol;
+struct EfiDevicePathProtocol;
+struct EfiBootServices;
+struct EfiMemoryDescriptor;
+struct EfiSystemTable;
+struct EfiGUID;
+struct EfiFileDevicePathProtocol;
+struct EfiHandle;
+struct EfiGraphicsOutputProtocol;
+struct EfiBitmask;
+struct EfiFileProtocol;
+
+typedef UInt64 EfiStatusType;
+
+/// @brief Core Handle Kind
+/// This is like NT's Win32 HANDLE type.
+typedef struct EfiHandle
+{
+}* EfiHandlePtr;
+
+/* UEFI uses wide characters by default. */
+typedef WideChar EfiCharType;
+
+typedef UInt64 EfiPhysicalAddress;
+typedef UIntPtr EfiVirtualAddress;
+
+/// What's BootBolicy?
+/// If TRUE, indicates that the request originates from the boot manager, and
+/// that the boot manager is attempting to load FilePath as a boot selection. If
+/// FALSE, then FilePath must match an exact file to be loaded.
+
+typedef UInt64(EFI_API* EfiTextString)(struct EfiSimpleTextOutputProtocol* This,
+ const WideChar* OutputString);
+
+typedef UInt64(EFI_API* EfiTextAttrib)(struct EfiSimpleTextOutputProtocol* This,
+ const WideChar Attribute);
+
+typedef UInt64(EFI_API* EfiTextClear)(struct EfiSimpleTextOutputProtocol* This);
+
+typedef UInt64(EFI_API* EfiLoadFile)(EfiLoadFileProtocol* This,
+ EfiFileDevicePathProtocol* FilePath,
+ Boolean BootPolicy,
+ UInt32* BufferSize,
+ VoidPtr Buffer);
+
+typedef UInt64(EFI_API* EfiCopyMem)(VoidPtr DstBuf, VoidPtr SrcBuf, SizeT Length);
+typedef UInt64(EFI_API* EfiSetMem)(VoidPtr DstBuf, Char Byte, SizeT Length);
+
+typedef UInt64(EFI_API* EfiHandleProtocol)(EfiHandlePtr Handle, EfiGUID* Guid, VoidPtr* Device);
+
+typedef UInt64(EFI_API* EfiLocateDevicePath)(EfiGUID* Protocol,
+ EfiDevicePathProtocol** DevicePath,
+ EfiHandlePtr Device);
+
+typedef UInt64(EFI_API* EfiStartImage)(EfiHandlePtr Handle, VoidPtr ArgsSize, VoidPtr ArgsPtr);
+
+typedef UInt64(EFI_API* EfiLoadImage)(Boolean BootPolicy,
+ EfiHandlePtr ParentHandle,
+ EfiFileDevicePathProtocol* DeviceFile,
+ VoidPtr buffer,
+ SizeT size,
+ EfiHandlePtr* ppHandle);
+
+/// EFI pool helpers, taken from iPXE.
+
+typedef enum EfiMemoryType
+{
+ ///
+ /// Not used.
+ ///
+ EfiReservedMemoryType,
+ ///
+ /// The code portions of a loaded application.
+ /// (Note that UEFI OS loaders are UEFI applications.)
+ ///
+ EfiLoaderCode,
+ ///
+ /// The data portions of a loaded application and the default data allocation
+ /// type used by an application to allocate pool memory.
+ ///
+ EfiLoaderData,
+ ///
+ /// The code portions of a loaded Boot Services Driver.
+ ///
+ EfiBootServicesCode,
+ ///
+ /// The data portions of a loaded Boot Serves Driver, and the default data
+ /// allocation type used by a Boot Services Driver to allocate pool memory.
+ ///
+ EfiBootServicesData,
+ ///
+ /// The code portions of a loaded Runtime Services Driver.
+ ///
+ EfiRuntimeServicesCode,
+ ///
+ /// The data portions of a loaded Runtime Services Driver and the default
+ /// data allocation type used by a Runtime Services Driver to allocate pool
+ /// memory.
+ ///
+ EfiRuntimeServicesData,
+ ///
+ /// Free (unallocated) memory.
+ ///
+ EfiConventionalMemory,
+ ///
+ /// Memory in which errors have been detected.
+ ///
+ EfiUnusableMemory,
+ ///
+ /// Memory that holds the ACPI tables.
+ ///
+ EfiACPIReclaimMemory,
+ ///
+ /// Address space reserved for use by the firmware.
+ ///
+ EfiACPIMemoryNVS,
+ ///
+ /// Used by system firmware to request that a memory-mapped IO region
+ /// be mapped by the OS to a virtual address so it can be accessed by EFI
+ /// runtime services.
+ ///
+ EfiMemoryMappedIO,
+ ///
+ /// System memory-mapped IO region that is used to translate memory
+ /// cycles to IO cycles by the processor.
+ ///
+ EfiMemoryMappedIOPortSpace,
+ ///
+ /// Address space reserved by the firmware for code that is part of the
+ /// processor.
+ ///
+ EfiPalCode,
+ ///
+ /// A memory region that operates as EfiConventionalMemory,
+ /// however it happens to also support byte-addressable non-volatility.
+ ///
+ EfiPersistentMemory,
+ ///
+ /// A memory region that describes system memory that has not been accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiUnacceptedMemoryType,
+ ///
+ /// The last type of memory.
+ /// Not a real type.
+ ///
+ EfiMaxMemoryType,
+} EfiMemoryType;
+
+typedef enum EfiAllocateType
+{
+ /// Anything that satisfy the request.
+ AllocateAnyPages,
+ AllocateMaxAddress,
+ ///
+ /// Allocate pages at a specified address.
+ ///
+ AllocateAddress,
+ ///
+ /// Maximum enumeration value that may be used for bounds checking.
+ ///
+ MaxAllocateType
+} EfiAllocateType;
+
+typedef struct EfiMemoryDescriptor
+{
+ ///
+ /// Kind of the memory region.
+ /// Kind EFI_MEMORY_TYPE is defined in the
+ /// AllocatePages() function description.
+ ///
+ UInt32 Kind;
+ ///
+ /// Physical address of the first byte in the memory region. PhysicalStart
+ /// must be aligned on a 4 KiB boundary, and must not be above
+ /// 0xfffffffffffff000. Kind EFI_PHYSICAL_ADDRESS is defined in the
+ /// AllocatePages() function description
+ ///
+ EfiPhysicalAddress PhysicalStart;
+ ///
+ /// Virtual address of the first byte in the memory region.
+ /// VirtualStart must be aligned on a 4 KiB boundary,
+ /// and must not be above 0xfffffffffffff000.
+ ///
+ EfiVirtualAddress VirtualStart;
+ ///
+ /// NumberOfPagesNumber of 4 KiB pages in the memory region.
+ /// NumberOfPages must not be 0, and must not be any value
+ /// that would represent a memory page with a start address,
+ /// either physical or virtual, above 0xfffffffffffff000.
+ ///
+ UInt64 NumberOfPages;
+ ///
+ /// Attributes of the memory region that describe the bit mask of capabilities
+ /// for that memory region, and not necessarily the current settings for that
+ /// memory region.
+ ///
+ UInt64 Attribute;
+} EfiMemoryDescriptor;
+
+typedef UInt64(EFI_API* EfiAllocatePool)(EfiMemoryType PoolType, UInt32 Size, VoidPtr* Buffer);
+
+typedef UInt64(EFI_API* EfiFreePool)(VoidPtr Buffer);
+
+typedef UInt64(EFI_API* EfiCalculateCrc32)(VoidPtr Data, UInt32 DataSize, UInt32* CrcOut);
+
+/**
+@brief Present in every header, used to identify a UEFI structure.
+*/
+typedef struct EfiTableHeader
+{
+ UInt64 Signature;
+ UInt32 Revision;
+ UInt32 HeaderSize;
+ UInt32 Crc32;
+ UInt32 Reserved;
+} EfiTableHeader;
+
+#define EFI_ACPI_TABLE_PROTOCOL_GUID \
+ { \
+ 0xffe06bdd, 0x6107, 0x46a6, \
+ { \
+ 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \
+ } \
+ }
+
+#define EFI_LOAD_FILE_PROTOCOL_GUID \
+ { \
+ 0x56EC3091, 0x954C, 0x11d2, \
+ { \
+ 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
+ } \
+ }
+
+#define EFI_LOAD_FILE2_PROTOCOL_GUID \
+ { \
+ 0x4006c0c1, 0xfcb3, 0x403e, \
+ { \
+ 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \
+ } \
+ }
+
+#define EFI_LOADED_IMAGE_PROTOCOL_GUID \
+ { \
+ 0x5B1B31A1, 0x9562, 0x11d2, \
+ { \
+ 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
+ } \
+ }
+
+#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
+ { \
+ 0x9042a9de, 0x23dc, 0x4a38, \
+ { \
+ 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \
+ } \
+ }
+
+#define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
+ { \
+ 0x0964e5b22, 0x6459, 0x11d2, \
+ { \
+ 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
+ } \
+ }
+
+#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
+ { \
+ 0xbc62157e, 0x3e33, 0x4fec, \
+ { \
+ 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \
+ } \
+ }
+
+#define EFI_DEVICE_PATH_PROTOCOL_GUID \
+ { \
+ 0x9576e91, 0x6d3f, 0x11d2, \
+ { \
+ 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
+ } \
+ }
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
+ { \
+ 0x0964e5b22, 0x6459, 0x11d2, \
+ { \
+ 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
+ } \
+ }
+
+typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle);
+
+enum
+{
+ kPixelRedGreenBlueReserved8BitPerColor,
+ kPixelBlueGreenRedReserved8BitPerColor,
+ kPixelBitMask,
+ kPixelBltOnly,
+ kPixelFormatMax
+};
+
+typedef struct EfiBitmask
+{
+ UInt32 RedMask;
+ UInt32 GreenMask;
+ UInt32 BlueMask;
+ UInt32 ReservedMask;
+} EfiBitmask;
+
+typedef struct
+{
+ UInt8 Blue;
+ UInt8 Green;
+ UInt8 Red;
+ UInt8 Reserved;
+} EfiGraphicsOutputBltPixel;
+
+typedef enum EfiGraphicsOutputProtocolBltOperation
+{
+ EfiBltVideoFill,
+ EfiBltVideoToBltBuffer,
+ EfiBltBufferToVideo,
+ EfiBltVideoToVideo,
+ EfiGraphicsOutputBltOperationMax
+} EfiGraphicsOutputProtocolBltOperation;
+
+typedef struct EfiGraphicsOutputProtocolModeInformation
+{
+ UInt32 Version;
+ UInt32 HorizontalResolution;
+ UInt32 VerticalResolution;
+ UInt32 PixelFormat;
+ EfiBitmask PixelInformation;
+ UInt32 PixelsPerScanLine;
+} EfiGraphicsOutputProtocolModeInformation;
+
+typedef UInt64(EFI_API* EfiGraphicsOutputProtocolQueryMode)(
+ EfiGraphicsOutputProtocol* This, UInt32 ModeNumber, UInt32* SizeOfInfo, EfiGraphicsOutputProtocolModeInformation** Info);
+
+typedef UInt64(EFI_API* EfiGraphicsOutputProtocolSetMode)(
+ EfiGraphicsOutputProtocol* This, UInt32 ModeNumber);
+
+typedef UInt64(EFI_API* EfiGraphicsOutputProtocolBlt)(
+ EfiGraphicsOutputProtocol* This, EfiGraphicsOutputBltPixel* BltBuffer, EfiGraphicsOutputProtocolBltOperation BltOperation, UInt32 SourceX, UInt32 SourceY, UInt32 DestinationX, UInt32 DestinationY, UInt32 Width, UInt32 Height, UInt32 Delta);
+
+typedef struct
+{
+ UInt32 MaxMode;
+ UInt32 Mode;
+ EfiGraphicsOutputProtocolModeInformation* Info;
+ UInt32 SizeOfInfo;
+ UIntPtr FrameBufferBase;
+ UInt32 FrameBufferSize;
+} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;
+
+typedef struct EfiGraphicsOutputProtocol
+{
+ EfiGraphicsOutputProtocolQueryMode QueryMode;
+ EfiGraphicsOutputProtocolSetMode SetMode;
+ EfiGraphicsOutputProtocolBlt Blt;
+ EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE* Mode;
+} EfiGraphicsOutputProtocol;
+
+typedef struct EfiLoadImageProtocol
+{
+ UInt32 Revision;
+ EfiHandlePtr ParentHandle;
+ EfiSystemTable* SystemTable;
+
+ // Source location of the image
+ EfiHandlePtr DeviceHandle;
+ EfiDevicePathProtocol* FilePath;
+ Void* Reserved;
+
+ // Image’s load options
+ UInt32 LoadOptionsSize;
+ Void* LoadOptions;
+
+ // Location where image was loaded
+ Void* ImageBase;
+ UInt64 ImageSize;
+ EfiMemoryType ImageCodeType;
+ EfiMemoryType ImageDataType;
+ EfiImageUnload Unload;
+} EfiLoadImageProtocol;
+
+typedef struct EfiLoadFileProtocol
+{
+ EfiLoadFile LoadFile;
+} EfiLoadFileProtocol;
+
+typedef struct EfiDevicePathProtocol
+{
+ UInt8 Kind;
+ UInt8 SubType;
+ UInt8 Length[2];
+} EfiDevicePathProtocol;
+
+typedef struct EfiFileDevicePathProtocol
+{
+ EfiDevicePathProtocol Proto;
+
+ ///
+ /// File Path of this struct
+ ///
+ WideChar Path[kPathLen];
+} EfiFileDevicePathProtocol;
+
+typedef UInt64(EFI_API* EfiExitBootServices)(VoidPtr ImageHandle,
+ UInt32 MapKey);
+
+typedef UInt64(EFI_API* EfiAllocatePages)(EfiAllocateType AllocType,
+ EfiMemoryType MemType,
+ UInt32 Count,
+ EfiPhysicalAddress* Memory);
+
+typedef UInt64(EFI_API* EfiFreePages)(EfiPhysicalAddress* Memory, UInt32 Pages);
+
+typedef UInt64(EFI_API* EfiGetMemoryMap)(UInt32* MapSize,
+ EfiMemoryDescriptor* DescPtr,
+ UInt32* MapKey,
+ UInt32* DescSize,
+ UInt32* DescVersion);
+
+/**
+ * @brief GUID type, something you can also find in CFKit.
+ */
+typedef struct EfiGUID final
+{
+ UInt32 Data1;
+ UInt16 Data2;
+ UInt16 Data3;
+ UInt8 Data4[8];
+} EfiGUID;
+
+/***
+ * Protocol stuff...
+ */
+
+/** some helpers */
+#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
+#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
+#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
+#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
+#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
+#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
+
+typedef UInt64(EFI_API* EfiLocateProtocol)(EfiGUID* Protocol,
+ VoidPtr Registration,
+ VoidPtr* Interface);
+
+typedef UInt64(EFI_API* EfiOpenProtocol)(EfiHandlePtr Handle, EfiGUID* Guid, VoidPtr* Interface, EfiHandlePtr AgentHandle, EfiHandlePtr ControllerHandle, UInt32 Attributes);
+
+typedef UInt64(EFI_API* EfiEnableCursor)(EfiSimpleTextOutputProtocol* This, Boolean Visible);
+
+/**
+@name EfiBootServices
+@brief UEFI Boot Services record, it contains functions necessary to a
+firmware level application.
+*/
+typedef struct EfiBootServices
+{
+ EfiTableHeader SystemTable;
+ VoidPtr RaiseTPL;
+ VoidPtr RestoreTPL;
+ EfiAllocatePages AllocatePages;
+ EfiFreePages FreePages;
+ EfiGetMemoryMap GetMemoryMap;
+ EfiAllocatePool AllocatePool;
+ EfiFreePool FreePool;
+ VoidPtr CreateEvent;
+ VoidPtr SetTimer;
+ VoidPtr WaitForEvent;
+ VoidPtr SignalEvent;
+ VoidPtr CloseEvent;
+ VoidPtr CheckEvent;
+ VoidPtr InstallProtocolInterface;
+ VoidPtr ReinstallProtocolInterface;
+ VoidPtr UninstallProtocolInterface;
+ EfiHandleProtocol HandleProtocol;
+ VoidPtr Reserved;
+ VoidPtr RegisterProtocolNotify;
+ VoidPtr LocateHandle;
+ EfiLocateDevicePath LocateDevicePath;
+ VoidPtr InstallConfigurationTable;
+ EfiLoadImage LoadImage;
+ EfiStartImage StartImage;
+ VoidPtr Exit;
+ VoidPtr UnloadImage;
+ EfiExitBootServices ExitBootServices;
+ VoidPtr GetNextMonotonicCount;
+ VoidPtr Stall;
+ EfiStatusType(EFI_API* SetWatchdogTimer)(UInt32 Timeout, UInt64 WatchdogCode, UInt32 DataSize, EfiCharType* Data);
+ VoidPtr ConnectController;
+ VoidPtr DisconnectController;
+ EfiOpenProtocol OpenProtocol;
+ VoidPtr CloseProtocol;
+ VoidPtr OpenProtocolInformation;
+ VoidPtr ProtocolsPerHandle;
+ VoidPtr LocateHandleBuffer;
+ EfiLocateProtocol LocateProtocol;
+ VoidPtr InstallMultipleProtocolInterfaces;
+ VoidPtr UninstallMultipleProtocolInterfaces;
+ EfiCalculateCrc32 CalculateCrc32;
+ EfiCopyMem CopyMem;
+ EfiSetMem SetMem;
+ VoidPtr CreateEventEx;
+} EfiBootServices;
+
+#define kEntireDevPath 0xFF
+#define kThisInstancePath 0x01
+
+/**
+@brief PrintF like protocol.
+*/
+typedef struct EfiSimpleTextOutputProtocol
+{
+ VoidPtr Reset;
+ EfiTextString OutputString;
+ VoidPtr TestString;
+ VoidPtr QueryMode;
+ VoidPtr SetMode;
+ EfiTextAttrib SetAttribute;
+ EfiTextClear ClearScreen;
+ VoidPtr SetCursorPosition;
+ EfiEnableCursor EnableCursor;
+ VoidPtr Mode;
+} EfiSimpleTextOutputProtocol;
+
+typedef UInt64(EFI_API* EfiOpenVolume)(struct EfiSimpleFilesystemProtocol*,
+ struct EfiFileProtocol**);
+
+struct EfiSimpleFilesystemProtocol
+{
+ UInt64 Revision;
+ EfiOpenVolume OpenVolume;
+};
+
+/**
+@brief The Structure that they give you when booting.
+*/
+typedef struct EfiSystemTable
+{
+ EfiTableHeader SystemHeader;
+ WideChar* FirmwareVendor;
+ UInt32 FirmwareRevision;
+ EfiHandlePtr ConsoleInHandle;
+ VoidPtr ConIn;
+ EfiHandlePtr ConsoleOutHandle;
+ EfiSimpleTextOutputProtocol* ConOut;
+ EfiHandlePtr StandardErrorHandle;
+ VoidPtr StdErr;
+ VoidPtr RuntimeServices;
+ EfiBootServices* BootServices;
+ UInt64 NumberOfTableEntries;
+ struct
+ {
+ EfiGUID VendorGUID;
+ VoidPtr VendorTable;
+ }* ConfigurationTable;
+} EfiSystemTable;
+
+#define kEfiOk 0
+#define kEfiFail -1
+#define kBufferTooSmall 5
+
+#define EFI_EXTERN_C extern "C"
+
+typedef struct EfiIPV4
+{
+ UInt8 Addr[4];
+} EfiIPV4;
+
+///
+/// 16-byte buffer. An IPv6 internet protocol address.
+///
+typedef struct EfiIPV6
+{
+ UInt8 Addr[16];
+} EfiIPV6;
+
+#define kEFIYellow (0x01 | 0x02 | 0x04 | 0x08)
+
+#ifdef __x86_64
+#define __EFI_x86_64__ 1
+#endif // __x86_64
+
+enum
+{
+ kEFIHwDevicePath = 0x01,
+ kEFIAcpiDevicePath = 0x02,
+ kEFIMessaingDevicePath = 0x03,
+ kEFIMediaDevicePath = 0x04,
+ kEFIBiosBootPath = 0x05,
+ kEFIEndOfPath = 0x06,
+ kEFICount = 6,
+};
+
+#define END_DEVICE_PATH_TYPE 0x7f
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
+
+#define kEfiOffsetOf(T, F) __builtin_offsetof(T, F)
+
+/// File I/O macros
+
+#define kEFIFileRead 0x0000000000000001
+#define kEFIFileWrite 0x0000000000000002
+#define kEFIFileCreate 0x0000000000000000
+
+#define kEFIReadOnly 0x01
+#define kEFIHidden 0x02
+#define kEFISystem 0x04
+#define kEFIReserved 0x08
+#define kEFIDirectory 0x10
+#define kEFIArchive 0x20
+
+typedef struct EfiIOToken
+{
+ //
+ // If Event is NULL, then blocking I/O is performed.
+ // If Event is not NULL and non-blocking I/O is supported, then non-blocking
+ // I/O is performed, and Event will be signaled when the read request is
+ // completed. The caller must be prepared to handle the case where the
+ // callback associated with Event occurs before the original asynchronous I/O
+ // request call returns.
+ //
+ UInt64 Event;
+
+ //
+ // Defines whether or not the signaled event encountered an error.
+ //
+ UInt64 Status;
+
+ //
+ // For OpenEx(): Not Used, ignored.
+ // For ReadEx(): On input, the size of the Buffer. On output, the amount of
+ // data returned in Buffer.
+ // In both cases, the size is measured in bytes.
+ // For WriteEx(): On input, the size of the Buffer. On output, the amount of
+ // data actually written.
+ // In both cases, the size is measured in bytes.
+ // For FlushEx(): Not used, ignored.
+ //
+ UInt32 BufferSize;
+
+ //
+ // For OpenEx(): Not Used, ignored.
+ // For ReadEx(): The buffer into which the data is read.
+ // For WriteEx(): The buffer of data to write.
+ // For FlushEx(): Not Used, ignored.
+ //
+ Void* Buffer;
+} EfiIOToken;
+
+typedef struct EfiFileProtocol
+{
+ UInt64 Revision;
+
+ EfiStatusType(EFI_API* Open)(struct EfiFileProtocol* This,
+ struct EfiFileProtocol** Out,
+ EfiCharType* CharType,
+ UInt64 OpenMode,
+ UInt64 Attrib);
+
+ EfiStatusType(EFI_API* Close)(struct EfiFileProtocol* This);
+
+ EfiStatusType(EFI_API* Delete)(struct EfiFileProtocol* This);
+
+ EfiStatusType(EFI_API* Read)(struct EfiFileProtocol* This, UInt64* BufSize, VoidPtr BufOut);
+
+ EfiStatusType(EFI_API* Write)(struct EfiFileProtocol* This, UInt64* BufSize, VoidPtr BufOut);
+
+ EfiStatusType(EFI_API* GetPosition)(EfiFileProtocol* This, UInt64* Position);
+
+ EfiStatusType(EFI_API* SetPosition)(EfiFileProtocol* This, UInt64* Position);
+
+ EfiStatusType(EFI_API* GetInfo)(struct EfiFileProtocol*, struct EfiGUID*, UInt32*, void*);
+
+ EfiStatusType(EFI_API* SetInfo)(struct EfiFileProtocol*, struct EfiGUID*, UInt32*, void*);
+
+ EfiStatusType(EFI_API* Flush)(EfiFileProtocol*);
+
+ EfiStatusType(EFI_API* OpenEx)(EfiFileProtocol* This,
+ EfiFileProtocol** OutHandle,
+ EfiCharType* Path,
+ UInt64 Mode,
+ UInt64 Attrib,
+ struct EfiIOToken* Token);
+
+ EfiStatusType(EFI_API* ReadEx)(EfiFileProtocol* This,
+ struct EfiIOToken* Token);
+
+ EfiStatusType(EFI_API* WriteEx)(EfiFileProtocol* This,
+ struct EfiIOToken* Token);
+
+ EfiStatusType(EFI_API* FlushEx)(EfiFileProtocol* This,
+ struct EfiIOToken* Token);
+} EfiFileProtocol, *EfiFileProtocolPtr;
+
+typedef UInt64 EfiCursorType;
+
+typedef struct EfiTime
+{
+ UInt16 Year;
+ UInt8 Month;
+ UInt8 Day;
+ UInt8 Hour;
+ UInt8 Minute;
+ UInt8 Second;
+ UInt8 Pad1;
+ UInt32 Nanosecond;
+ Int16 TimeZone;
+ UInt8 Daylight;
+ UInt8 Pad2;
+} EfiTime;
+
+#define EFI_FILE_INFO_GUID \
+ { \
+ 0x09576e92, 0x6d3f, 0x11d2, \
+ { \
+ 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \
+ } \
+ }
+
+struct EfiFileInfo final
+{
+ /// @brief Structure size.
+ UInt64 Size;
+ /// @brief File size.
+ UInt64 FileSize;
+ /// @brief Physical size on disk.
+ UInt64 PhysicalSize;
+ /// @brief Create time.
+ EfiTime CreateTime;
+ /// @brief Last access time.
+ EfiTime LastAccessTime;
+ /// @brief Edit time.
+ EfiTime EditTime;
+ /// @brief Attributes.
+ UInt64 Attribute;
+ /// @brief VLA file name.
+ WideChar FileName[1];
+};
+
+#define EFI_FILE_PROTOCOL_REVISION 0x00010000
+#define EFI_FILE_PROTOCOL_REVISION2 0x00020000
+#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
+
+#define EFI_EXTRA_DESCRIPTOR_SIZE 8
+
+#define EFI_MP_SERVICES_PROTOCOL_GUID \
+ { \
+ 0x3fdda605, 0xa76e, 0x4f46, \
+ { \
+ 0xad, 0x29, 0x12, 0xf4, \
+ 0x53, 0x1b, 0x3d, 0x08 \
+ } \
+ }
+
+//*******************************************************
+// EFI_CPU_PHYSICAL_LOCATION
+// @note As in the EFI specs.
+//*******************************************************
+typedef struct _EfiCPUPhyiscalLocation
+{
+ UInt32 Package;
+ UInt32 Core;
+ UInt32 Thread;
+} EfiCPUPhyiscalLocation;
+
+typedef union _EfiExtendedProcessorInformation {
+ EfiCPUPhyiscalLocation Location2;
+} EfiExtendedProcessorInformation;
+
+typedef struct _EfiProcessorInformation
+{
+ UInt64 ProcessorId;
+ UInt32 StatusFlag;
+ EfiCPUPhyiscalLocation Location;
+ EfiExtendedProcessorInformation ExtendedInformation;
+} EfiProcessorInformation;
+
+#define PROCESSOR_AS_BSP_BIT 0x00000001
+#define PROCESSOR_ENABLED_BIT 0x00000002
+#define PROCESSOR_HEALTH_STATUS_BIT 0x00000004
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS)(
+ IN struct _EfiMpServicesProtocol* Self,
+ OUT UInt32* NumberOfProcessors,
+ OUT UInt32* NumberOfEnabledProcessors);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_GET_PROCESSOR_INFO)(
+ IN struct _EfiMpServicesProtocol* Self,
+ IN UInt32* ProcessorNumber,
+ OUT struct _EfiProcessorInformation* NumberOfEnabledProcessors);
+
+#define END_OF_CPU_LIST 0xffffffff
+
+typedef void EFI_API (*EFI_AP_PROCEDURE)(
+ IN VoidPtr ProcedureArgument);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_STARTUP_ALL_APS)(
+ IN struct _EfiMpServicesProtocol* This,
+ IN EFI_AP_PROCEDURE Procedure,
+ IN Boolean SingleThread,
+ IN VoidPtr WaitEvent OPTIONAL, // EFI_EVENT first, but unused here.
+ IN UInt32 TimeoutInMicroSeconds,
+ IN Void* ProcedureArgument OPTIONAL,
+ OUT UInt32** FailedCpuList OPTIONAL);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_SWITCH_BSP)(
+ IN struct _EfiMpServicesProtocol* This,
+ IN UInt32 ProcessorNumber,
+ IN Boolean EnableOldBSP);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_STARTUP_THIS_AP)(
+ IN struct _EfiMpServicesProtocol* This,
+ IN EFI_AP_PROCEDURE Procedure,
+ IN UInt32 ProcessorNumber,
+ IN VoidPtr WaitEvent OPTIONAL,
+ IN UInt32 TimeoutInMicroseconds,
+ IN Void* ProcedureArgument OPTIONAL,
+ OUT Boolean* Finished OPTIONAL);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_ENABLEDISABLEAP)(
+ IN struct _EfiMpServicesProtocol* This,
+ IN UInt32 ProcessorNumber,
+ IN Boolean EnableAP,
+ IN UInt32* HealthFlag OPTIONAL);
+
+typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_WHOAMI)(
+ IN struct _EfiMpServicesProtocol* This,
+ OUT UInt32* ProcessorNumber);
+
+typedef struct _EfiMpServicesProtocol
+{
+ EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS GetNumberOfProcessors;
+ EFI_MP_SERVICES_GET_PROCESSOR_INFO GetProcessorInfo;
+ EFI_MP_SERVICES_STARTUP_ALL_APS StartupAllAPs;
+ EFI_MP_SERVICES_STARTUP_THIS_AP StartupThisAP;
+ EFI_MP_SERVICES_SWITCH_BSP SwitchBSP;
+ EFI_MP_SERVICES_ENABLEDISABLEAP EnableDisableAP;
+ EFI_MP_SERVICES_WHOAMI WhoAmI;
+} EfiMpServicesProtocol;
+
+#endif // ifndef __EFI__
diff --git a/dev/zka/FirmwareKit/EPM.hxx b/dev/zka/FirmwareKit/EPM.hxx
new file mode 100644
index 00000000..f5a6eed2
--- /dev/null
+++ b/dev/zka/FirmwareKit/EPM.hxx
@@ -0,0 +1,122 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ @brief The Explicit Partition Map scheme.
+*/
+
+#ifndef __FIRMWARE_EPM_HXX__
+#define __FIRMWARE_EPM_HXX__
+
+#include <NewKit/Defines.hxx>
+
+#define kEPMNameLength (32)
+#define kEPMFilesystemLength (16)
+#define kEPMMagicLength (5)
+
+/* @brief AMD64 magic for EPM */
+#define kEPMMagic86 "EPMAM"
+
+/* @brief RISC-V magic for EPM */
+#define kEPMMagicRISCV "EPMRV"
+
+/* @brief ARM magic for EPM */
+#define kEPMMagicARM "EPMAR"
+
+/* @brief 64x0 magic for EPM */
+#define kEPMMagic64k "EPM64"
+
+/* @brief 32x0 magic for EPM */
+
+#define kEPMMagic32k "EPM32"
+
+/* @brief POWER magic for EPM */
+
+#define kEPMMagicPPC "EPMPC"
+
+/* @brief UEFI magic for EPM */
+
+#define kEPMMagicUEFI "EPMUE"
+
+/* @brief CoreBoot magic for EPM */
+
+#define kEPMMagicCoreBoot "EPMCB"
+
+/* @brief Invalid magic for EPM */
+
+#define kEPMMagicError "EPM??"
+
+#ifdef __ZKA_AMD64__
+#define kEPMMagic kEPMMagic86
+#else
+#ifdef __ZKA_ARM64__
+#define kEPMMagic kEPMMagicARM
+#else
+#define kEPMMagic kEPMMagicError
+#endif
+#endif
+
+///! @brief partition must start at this address.
+///! Anything below is reserved for Data backup by the Main OS.
+#define kEPMStartPartitionBlk (sizeof(_BOOT_BLOCK_STRUCT))
+
+///! @brief Current EPM revision.
+#define kEPMRevision (0xAD)
+
+///! @brief Current EPM revision.
+#define kEPMRevisionUEFI (0xAF)
+
+/// !@brief EPM base address.
+#define kEpmBase (0U)
+
+struct _BLOCK_GUID_STRUCT;
+struct _BOOT_BLOCK_STRUCT;
+
+/* The first 0 > 128 addresses of a disk contains these headers. */
+
+/// @brief EPM GUID structure.
+typedef struct _BLOCK_GUID_STRUCT
+{
+ Kernel::UInt32 Data1;
+ Kernel::UInt16 Data2;
+ Kernel::UInt16 Data3;
+ Kernel::UInt8 Data4[8];
+} BLOCK_GUID_STRUCT;
+
+/**
+ * @brief The EPM boot block.
+ * @note NumBlock and LbaStart are ignored on some platforms.
+ */
+struct PACKED _BOOT_BLOCK_STRUCT
+{
+ Kernel::Char Magic[kEPMMagicLength];
+ Kernel::Char Name[kEPMNameLength];
+ BLOCK_GUID_STRUCT Uuid;
+ Kernel::Int32 Version;
+ Kernel::Int64 NumBlocks;
+ Kernel::Int64 SectorSz;
+ Kernel::Int64 LbaStart; // base offset
+ Kernel::Int64 LbaEnd; // addition of lba_start to get the end of partition.
+ Kernel::Int16 Kind;
+ Kernel::Int32 FsVersion;
+ Kernel::Char Fs[kEPMFilesystemLength]; /* NeFS, ffs2... */
+ Kernel::Char Reserved[401]; // to fill a full sector.
+};
+
+///! @brief Version kind enum.
+///! @brief Use in boot block version field.
+
+enum
+{
+ kEPMEmbeddedOS = 0xcf, // Embedded OS
+ kEPMLinux = 0x8f, // Linux on EPM
+ kEPMBSD = 0x9f, // Berkeley Soft. Distribution
+ kEPMNewOS = 0x1f, // This OS.
+};
+
+typedef struct _BOOT_BLOCK_STRUCT BOOT_BLOCK_STRUCT;
+
+#endif // ifndef __FIRMWARE_EPM_HXX__
diff --git a/dev/zka/FirmwareKit/Handover.hxx b/dev/zka/FirmwareKit/Handover.hxx
new file mode 100644
index 00000000..13c34eca
--- /dev/null
+++ b/dev/zka/FirmwareKit/Handover.hxx
@@ -0,0 +1,116 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file Handover.hxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief The handover boot protocol.
+ * @version 1.15
+ * @date 2024-02-23
+ *
+ * @copyright Copyright (c) 2024, ZKA Technologies
+ *
+ */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define kHandoverMagic 0xBADCC
+#define kHandoverVersion 0x0117
+
+/* Initial bitmap pointer location and size. */
+#define kHandoverBitMapSz (gib_cast(3))
+
+/* Executable base */
+#define kHandoverExecBase (0x4000000)
+
+#define kHandoverStructSz sizeof(HEL::HANDOVER_INFO_HEADER)
+
+namespace Kernel::HEL
+{
+ /**
+ @brief The executable type enum.
+ */
+ enum
+ {
+ kTypeKernel = 100,
+ kTypeKernelDriver = 101,
+ kTypeRsrc = 102,
+ kTypeInvalid = 103,
+ kTypeCount = 4,
+ };
+
+ /**
+ @brief The executable architecture enum.
+ */
+
+ enum
+ {
+ kArchAMD64 = 122,
+ kArchARM64 = 123,
+ kArchRISCV = 124,
+ kArchCount = 3,
+ };
+
+ struct HANDOVER_INFO_HEADER final
+ {
+ UInt64 f_Magic;
+ UInt64 f_Version;
+
+ VoidPtr f_BitMapStart;
+ SizeT f_BitMapSize;
+
+ VoidPtr f_PageStart;
+
+ VoidPtr f_KernelImage;
+ SizeT f_KernelSz;
+ VoidPtr f_StartupChime;
+ SizeT f_ChimeSz;
+ VoidPtr f_StartupImage;
+ SizeT f_StartupSz;
+ VoidPtr f_TTFallbackFont;
+ SizeT f_FontSz;
+
+ WideChar f_FirmwareVendorName[32];
+ SizeT f_FirmwareVendorLen;
+
+ VoidPtr f_FirmwareCustomTables[2]; // On EFI 0: BS 1: ST
+
+ struct
+ {
+ VoidPtr f_SmBios;
+ VoidPtr f_VendorPtr;
+ VoidPtr f_MpPtr;
+ Bool f_MultiProcessingEnabled;
+ } f_HardwareTables;
+
+ struct
+ {
+ UIntPtr f_The;
+ SizeT f_Size;
+ UInt32 f_Width;
+ UInt32 f_Height;
+ UInt32 f_PixelFormat;
+ UInt32 f_PixelPerLine;
+ } f_GOP;
+
+ UInt64 f_FirmwareSpecific[8];
+ };
+
+ enum
+ {
+ kHandoverSpecificKind,
+ kHandoverSpecificAttrib,
+ kHandoverSpecificMemoryEfi,
+ };
+
+ /// @brief Alias of bootloader main type.
+ typedef void (*HandoverProc)(HANDOVER_INFO_HEADER* handoverInfo);
+} // namespace Kernel::HEL
+
+/// @brief Bootloader global header.
+inline Kernel::HEL::HANDOVER_INFO_HEADER* kHandoverHeader = nullptr;
diff --git a/dev/zka/HALKit/.gitkeep b/dev/zka/HALKit/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/.gitkeep
diff --git a/dev/zka/HALKit/64x0/.hgkeep b/dev/zka/HALKit/64x0/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/64x0/.hgkeep
diff --git a/dev/zka/HALKit/64x0/APM/.hgkeep b/dev/zka/HALKit/64x0/APM/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/64x0/APM/.hgkeep
diff --git a/dev/zka/HALKit/64x0/HalVirtualMemory.cxx b/dev/zka/HALKit/64x0/HalVirtualMemory.cxx
new file mode 100644
index 00000000..1b0c9153
--- /dev/null
+++ b/dev/zka/HALKit/64x0/HalVirtualMemory.cxx
@@ -0,0 +1,17 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+using namespace Kernel;
+
+/// @brief Flush system TLB, looks like the POWER version, as it acts the same, no specific instruction for that.
+/// @note The 88K MMU should be present as well.
+EXTERN_C void hal_flush_tlb()
+{
+ asm volatile("invltlb");
+}
diff --git a/dev/zka/HALKit/64x0/MBCI/.gitkeep b/dev/zka/HALKit/64x0/MBCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/64x0/MBCI/.gitkeep
diff --git a/dev/zka/HALKit/64x0/ReadMe.md b/dev/zka/HALKit/64x0/ReadMe.md
new file mode 100644
index 00000000..2e72d5bf
--- /dev/null
+++ b/dev/zka/HALKit/64x0/ReadMe.md
@@ -0,0 +1,4 @@
+64x0 Hardware Abstraction Layer
+
+- Supported CPU: ZKA Technologies 64x0
+- Supported Firmware: CoreBoot \ No newline at end of file
diff --git a/dev/zka/HALKit/AMD64/CPUID.hxx b/dev/zka/HALKit/AMD64/CPUID.hxx
new file mode 100644
index 00000000..ae6e42c5
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/CPUID.hxx
@@ -0,0 +1,81 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: CPUID.hxx
+ Purpose: CPUID flags.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+enum
+{
+ eCPU_FEATURE_ECX_SSE3 = 1 << 0,
+ eCPU_FEATURE_ECX_PCLMUL = 1 << 1,
+ eCPU_FEATURE_ECX_DTES64 = 1 << 2,
+ eCPU_FEATURE_ECX_MONITOR = 1 << 3,
+ eCPU_FEATURE_ECX_DS_CPL = 1 << 4,
+ eCPU_FEATURE_ECX_VMX = 1 << 5,
+ eCPU_FEATURE_ECX_SMX = 1 << 6,
+ eCPU_FEATURE_ECX_EST = 1 << 7,
+ eCPU_FEATURE_ECX_TM2 = 1 << 8,
+ eCPU_FEATURE_ECX_SSSE3 = 1 << 9,
+ eCPU_FEATURE_ECX_CID = 1 << 10,
+ eCPU_FEATURE_ECX_SDBG = 1 << 11,
+ eCPU_FEATURE_ECX_FMA = 1 << 12,
+ eCPU_FEATURE_ECX_CX16 = 1 << 13,
+ eCPU_FEATURE_ECX_XTPR = 1 << 14,
+ eCPU_FEATURE_ECX_PDCM = 1 << 15,
+ eCPU_FEATURE_ECX_PCID = 1 << 17,
+ eCPU_FEATURE_ECX_DCA = 1 << 18,
+ eCPU_FEATURE_ECX_SSE4_1 = 1 << 19,
+ eCPU_FEATURE_ECX_SSE4_2 = 1 << 20,
+ eCPU_FEATURE_ECX_X2APIC = 1 << 21,
+ eCPU_FEATURE_ECX_MOVBE = 1 << 22,
+ eCPU_FEATURE_ECX_POP3C = 1 << 23,
+ eCPU_FEATURE_ECX_TSC = 1 << 24,
+ eCPU_FEATURE_ECX_AES = 1 << 25,
+ eCPU_FEATURE_ECX_XSAVE = 1 << 26,
+ eCPU_FEATURE_ECX_OSXSAVE = 1 << 27,
+ eCPU_FEATURE_ECX_AVX = 1 << 28,
+ eCPU_FEATURE_ECX_F16C = 1 << 29,
+ eCPU_FEATURE_ECX_RDRAND = 1 << 30,
+ eCPU_FEATURE_ECX_HYPERVISOR = 1 << 31,
+ eCPU_FEATURE_EDX_FPU = 1 << 0,
+ eCPU_FEATURE_EDX_VME = 1 << 1,
+ eCPU_FEATURE_EDX_DE = 1 << 2,
+ eCPU_FEATURE_EDX_PSE = 1 << 3,
+ eCPU_FEATURE_EDX_TSC = 1 << 4,
+ eCPU_FEATURE_EDX_MSR = 1 << 5,
+ eCPU_FEATURE_EDX_PAE = 1 << 6,
+ eCPU_FEATURE_EDX_MCE = 1 << 7,
+ eCPU_FEATURE_EDX_CX8 = 1 << 8,
+ eCPU_FEATURE_EDX_APIC = 1 << 9,
+ eCPU_FEATURE_EDX_SEP = 1 << 11,
+ eCPU_FEATURE_EDX_MTRR = 1 << 12,
+ eCPU_FEATURE_EDX_PGE = 1 << 13,
+ eCPU_FEATURE_EDX_MCA = 1 << 14,
+ eCPU_FEATURE_EDX_CMOV = 1 << 15,
+ eCPU_FEATURE_EDX_PAT = 1 << 16,
+ eCPU_FEATURE_EDX_PSE36 = 1 << 17,
+ eCPU_FEATURE_EDX_PSN = 1 << 18,
+ eCPU_FEATURE_EDX_CLFLUSH = 1 << 19,
+ eCPU_FEATURE_EDX_DS = 1 << 21,
+ eCPU_FEATURE_EDX_ACPI = 1 << 22,
+ eCPU_FEATURE_EDX_MMX = 1 << 23,
+ eCPU_FEATURE_EDX_FXSR = 1 << 24,
+ eCPU_FEATURE_EDX_SSE = 1 << 25,
+ eCPU_FEATURE_EDX_SSE2 = 1 << 26,
+ eCPU_FEATURE_EDX_SS = 1 << 27,
+ eCPU_FEATURE_EDX_HTT = 1 << 28,
+ eCPU_FEATURE_EDX_TM = 1 << 29,
+ eCPU_FEATURE_EDX_IA64 = 1 << 30,
+ eCPU_FEATURE_EDX_PBE = 1 << 31
+};
+
+typedef long long int hal_cpu_feature_type; \ No newline at end of file
diff --git a/dev/zka/HALKit/AMD64/HalACPIFactoryInterface.cxx b/dev/zka/HALKit/AMD64/HalACPIFactoryInterface.cxx
new file mode 100644
index 00000000..1cb8ce07
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalACPIFactoryInterface.cxx
@@ -0,0 +1,208 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+#include <NewKit/String.hxx>
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/Heap.hxx>
+
+namespace Kernel
+{
+ namespace Detail
+ {
+ struct FADT final : public SDT
+ {
+ UInt32 FirmwareCtrl;
+ UInt32 Dsdt;
+
+ // field used in ACPI 1.0; no longer in use, for compatibility only
+ UInt8 Reserved;
+
+ UInt8 PreferredPowerManagementProfile;
+ UInt16 SCI_Interrupt;
+ UInt32 SMI_CommandPort;
+ UInt8 AcpiEnable;
+ UInt8 AcpiDisable;
+ UInt8 S4BIOS_REQ;
+ UInt8 PSTATE_Control;
+ UInt32 PM1aEventBlock;
+ UInt32 PM1bEventBlock;
+ UInt32 PM1aControlBlock;
+ UInt32 PM1bControlBlock;
+ UInt32 PM2ControlBlock;
+ UInt32 PMTimerBlock;
+ UInt32 GPE0Block;
+ UInt32 GPE1Block;
+ UInt8 PM1EventLength;
+ UInt8 PM1ControlLength;
+ UInt8 PM2ControlLength;
+ UInt8 PMTimerLength;
+ UInt8 GPE0Length;
+ UInt8 GPE1Length;
+ UInt8 GPE1Base;
+ UInt8 CStateControl;
+ UInt16 WorstC2Latency;
+ UInt16 WorstC3Latency;
+ UInt16 FlushSize;
+ UInt16 FlushStride;
+ UInt8 DutyOffset;
+ UInt8 DutyWidth;
+ UInt8 DayAlarm;
+ UInt8 MonthAlarm;
+ UInt8 Century;
+
+ // reserved in ACPI 1.0; used since ACPI 2.0+
+ UInt16 BootArchitectureFlags;
+
+ UInt8 Reserved2;
+ UInt32 Flags;
+
+ // 12 byte structure; see below for details
+ ACPI_ADDRESS ResetReg;
+
+ UInt8 ResetValue;
+ UInt8 Reserved3[3];
+
+ // 64bit pointers - Available on ACPI 2.0+
+ UInt64 X_FirmwareControl;
+ UInt64 X_Dsdt;
+
+ ACPI_ADDRESS X_PM1aEventBlock;
+ ACPI_ADDRESS X_PM1bEventBlock;
+ ACPI_ADDRESS X_PM1aControlBlock;
+ ACPI_ADDRESS X_PM1bControlBlock;
+ ACPI_ADDRESS X_PM2ControlBlock;
+ ACPI_ADDRESS X_PMTimerBlock;
+ ACPI_ADDRESS X_GPE0Block;
+ ACPI_ADDRESS X_GPE1Block;
+ };
+ } // namespace Detail
+
+ ACPIFactoryInterface::ACPIFactoryInterface(VoidPtr rsdPtr)
+ : fRsdp(rsdPtr), fEntries(0)
+ {
+ }
+
+ Void ACPIFactoryInterface::Shutdown()
+ {
+ failed_to_shutdown:
+ // in case no acpi mode, or it's not available.
+ while (Yes)
+ {
+ asm volatile("cli; hlt");
+ }
+ }
+
+ /// @brief Reboot machine in either ACPI or by triple faulting.
+ /// @return nothing it's a reboot.
+ Void ACPIFactoryInterface::Reboot()
+ {
+ failed_to_reboot:
+ asm volatile(".intel_syntax noprefix; "
+ "rt_reset_hardware:; "
+ "cli; "
+ "wait_gate1: ; "
+ "in al,0x64 ; "
+ "and al,2 ; "
+ "jnz wait_gate1 ; "
+ "mov al,0x0D1 ; "
+ "out 0x64,al ; "
+ "wait_gate2: ; "
+ "in al,0x64 ; "
+ "and al,2 ; "
+ "jnz wait_gate2 ; "
+ "mov al,0x0FE ; "
+ "out 0x60,al ; "
+ "xor rax,rax ; "
+ "lidt [rax] ; "
+ "reset_wait: ; "
+ "jmp reset_wait ; "
+ ".att_syntax; ");
+ }
+
+ /// @brief Finds a descriptor table inside ACPI XSDT.
+ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const Char* signature)
+ {
+ MUST_PASS(fRsdp);
+
+ if (!signature)
+ return ErrorOr<voidPtr>{-1};
+
+ if (*signature == 0)
+ return ErrorOr<voidPtr>{-1};
+
+ RSDP* rsdPtr = reinterpret_cast<RSDP*>(this->fRsdp);
+
+ if (rsdPtr->Revision <= 1)
+ return ErrorOr<voidPtr>{-1};
+
+ RSDT* xsdt = reinterpret_cast<RSDT*>(rsdPtr->RsdtAddress);
+
+ Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32);
+
+ /***
+ crucial to avoid - overflows.
+ */
+ if (num < 1)
+ {
+ /// stop here, we should have entries...
+ ke_stop(RUNTIME_CHECK_ACPI);
+ return ErrorOr<voidPtr>{-1};
+ }
+
+ this->fEntries = num;
+
+ kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl;
+ kcout << "ACPI: Revision: " << number(xsdt->Revision) << endl;
+ kcout << "ACPI: Signature: " << xsdt->Signature << endl;
+ kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl;
+
+ const short cAcpiSignatureLength = 4;
+
+ for (Size index = 0; index < this->fEntries; ++index)
+ {
+ SDT* sdt = reinterpret_cast<SDT*>(xsdt->AddressArr[index]);
+
+ kcout << "ACPI: Checksum: " << number(sdt->Checksum) << endl;
+ kcout << "ACPI: Revision: " << number(sdt->Revision) << endl;
+
+ for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index)
+ {
+ if (sdt->Signature[signature_index] != signature[signature_index])
+ break;
+
+ if (signature_index == (cAcpiSignatureLength - 1))
+ {
+ kcout << "ACPI: Found the SDT. " << endl;
+ return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>(xsdt->AddressArr[index]));
+ }
+ }
+ }
+
+ return ErrorOr<voidPtr>{-1};
+ }
+
+ /***
+ @brief check SDT header
+ @param checksum the header to checksum
+ @param len the length of it.
+*/
+ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len)
+ {
+ if (len == 0)
+ return -1;
+
+ char chr = 0;
+
+ for (int index = 0; index < len; ++index)
+ {
+ chr += checksum[index];
+ }
+
+ return chr == 0;
+ }
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/HalAPICMgr.cxx b/dev/zka/HALKit/AMD64/HalAPICMgr.cxx
new file mode 100644
index 00000000..caa2ce0b
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalAPICMgr.cxx
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+
+namespace Kernel::HAL
+{
+ /// @brief Read from APIC controller.
+ /// @param reg register.
+ UInt32 APICController::Read(UInt32 reg) noexcept
+ {
+ MUST_PASS(this->fApic);
+
+ UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic;
+ ioapic[0] = (reg & 0xff);
+
+ return ioapic[4];
+ }
+
+ /// @brief Write to APIC controller.
+ /// @param reg register.
+ /// @param value value.
+ Void APICController::Write(UInt32 reg, UInt32 value) noexcept
+ {
+ MUST_PASS(this->fApic);
+
+ UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic;
+
+ ioapic[0] = (reg & 0xFF);
+ ioapic[4] = value;
+ }
+} // namespace Kernel::HAL
diff --git a/dev/zka/HALKit/AMD64/HalBMPMgr.cxx b/dev/zka/HALKit/AMD64/HalBMPMgr.cxx
new file mode 100644
index 00000000..b788902a
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalBMPMgr.cxx
@@ -0,0 +1,182 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+
+#define cBitMpMagic ((Kernel::UIntPtr)0x10210)
+
+#ifdef __ZKA_AMD64__
+#include <HALKit/AMD64/Paging.hxx>
+#elif defined(__ZKA_ARM64__)
+#include <HALKit/ARM64/Paging.hxx>
+#endif
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/KernelCheck.hxx>
+
+#define cBitMapMagIdx 0
+#define cBitMapSizeIdx 1
+#define cBitMapUsedIdx 2
+
+namespace Kernel
+{
+ namespace HAL
+ {
+ namespace Detail
+ {
+ /// \brief Proxy Interface to allocate a bitmap.
+ class IBitMapAllocator final
+ {
+ public:
+ explicit IBitMapAllocator() = default;
+ ~IBitMapAllocator() = default;
+
+ ZKA_COPY_DELETE(IBitMapAllocator);
+
+ auto IsBitMap(VoidPtr page_ptr) -> Bool
+ {
+ if (!page_ptr)
+ return No;
+
+ UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr);
+
+ if (!ptr_bit_set[cBitMapMagIdx] ||
+ ptr_bit_set[cBitMapMagIdx] != cBitMpMagic)
+ return No;
+
+ return Yes;
+ }
+
+ auto FreeBitMap(VoidPtr page_ptr) -> Bool
+ {
+ if (this->IsBitMap(page_ptr) == No)
+ return No;
+
+ UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr);
+
+ ptr_bit_set[cBitMapMagIdx] = cBitMpMagic;
+ ptr_bit_set[cBitMapUsedIdx] = No;
+
+ this->GetBitMapStatus(ptr_bit_set);
+
+ mm_map_page(ptr_bit_set, ~eFlagsPresent);
+ mm_map_page(ptr_bit_set, ~eFlagsRw);
+ mm_map_page(ptr_bit_set, ~eFlagsUser);
+
+ return Yes;
+ }
+
+ /// @brief Iterate over availables pages for a free one.
+ /// @return The new address which was found.
+ auto FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) -> VoidPtr
+ {
+ VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kPageSize);
+
+ while (base && size)
+ {
+ UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base);
+
+ if (ptr_bit_set[cBitMapMagIdx] == cBitMpMagic &&
+ ptr_bit_set[cBitMapSizeIdx] <= size)
+ {
+ if (ptr_bit_set[cBitMapUsedIdx] == No)
+ {
+ ptr_bit_set[cBitMapSizeIdx] = size;
+ ptr_bit_set[cBitMapUsedIdx] = Yes;
+
+ this->GetBitMapStatus(ptr_bit_set);
+
+ return (VoidPtr)ptr_bit_set;
+ }
+ }
+ else if (ptr_bit_set[cBitMapMagIdx] != cBitMpMagic)
+ {
+ UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr);
+
+ ptr_bit_set[cBitMapMagIdx] = cBitMpMagic;
+ ptr_bit_set[cBitMapSizeIdx] = size;
+ ptr_bit_set[cBitMapUsedIdx] = Yes;
+
+ this->GetBitMapStatus(ptr_bit_set);
+
+ return (VoidPtr)ptr_bit_set;
+ }
+
+ base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + (ptr_bit_set[0] != cBitMpMagic ? size : ptr_bit_set[1]));
+
+ if ((UIntPtr)base_ptr < (reinterpret_cast<UIntPtr>(base) + kHandoverHeader->f_BitMapSize))
+ return nullptr;
+ }
+
+ return nullptr;
+ }
+
+ /// @brief Print Bitmap status
+ auto GetBitMapStatus(UIntPtr* ptr_bit_set) -> Void
+ {
+ if (!this->IsBitMap(ptr_bit_set))
+ {
+ kcout << "Not a BitMap: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ return;
+ }
+
+ kcout << "Magic BitMap Number: " << hex_number(ptr_bit_set[cBitMapMagIdx]) << endl;
+ kcout << "Allocated: " << (ptr_bit_set[cBitMapUsedIdx] ? "Yes" : "No") << endl;
+ kcout << "Size of BitMap (B): " << number(ptr_bit_set[cBitMapSizeIdx]) << endl;
+ kcout << "Size of BitMap (KIB): " << number(KIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of BitMap (MIB): " << number(MIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of BitMap (GIB): " << number(GIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of BitMap (TIB): " << number(TIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Address Of BitMap: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ }
+ };
+ } // namespace Detail
+
+ /// @brief Allocate a new page to be used by the OS.
+ /// @param rw read/write bit.
+ /// @param user user bit.
+ /// @return
+ auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr
+ {
+ VoidPtr ptr_new = nullptr;
+ Detail::IBitMapAllocator traits;
+
+ ptr_new = traits.FindBitMap(kKernelBitMpStart, size, rw, user);
+
+ if (!ptr_new)
+ {
+ ke_stop(RUNTIME_CHECK_PAGE);
+ }
+
+ if (rw)
+ mm_map_page(ptr_new, eFlagsRw | eFlagsPresent);
+ else if (user && rw)
+ mm_map_page(ptr_new, eFlagsUser | eFlagsRw | eFlagsPresent);
+ else if (user)
+ mm_map_page(ptr_new, eFlagsUser | eFlagsPresent);
+ else
+ mm_map_page(ptr_new, eFlagsPresent);
+
+ return (UIntPtr*)ptr_new;
+ }
+
+ auto mm_free_bitmap(VoidPtr page_ptr) -> Bool
+ {
+ if (!page_ptr)
+ return No;
+
+ Detail::IBitMapAllocator traits;
+ Bool ret = traits.FreeBitMap(page_ptr);
+
+ if (ret)
+ {
+ mm_map_page(page_ptr, ~eFlagsPresent);
+ }
+
+ return ret;
+ }
+ } // namespace HAL
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/HalBoot.asm b/dev/zka/HALKit/AMD64/HalBoot.asm
new file mode 100644
index 00000000..21f99a49
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalBoot.asm
@@ -0,0 +1,22 @@
+;; /*
+;; * ========================================================
+;; *
+;; * ZKA
+;; * Copyright ZKA Technologies., all rights reserved.
+;; *
+;; * ========================================================
+;; */
+
+[bits 64]
+
+;; Global symbol of this unit
+[extern hal_init_platform]
+
+%define kTypeKernel 100
+%define kArchAmd64 122
+%define kHandoverMagic 0xBADCC
+
+section .ldr
+
+HandoverMagic: dq kHandoverMagic
+HandoverType: dw kTypeKernel
diff --git a/dev/zka/HALKit/AMD64/HalCommAPI.cxx b/dev/zka/HALKit/AMD64/HalCommAPI.cxx
new file mode 100644
index 00000000..11c442b4
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalCommAPI.cxx
@@ -0,0 +1,116 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: HalProcessor.cxx
+ Purpose: Platform processor routines.
+
+------------------------------------------- */
+
+#include <HALKit/AMD64/Paging.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+
+/**
+ * @file HalCommAPI.cxx
+ * @brief CPU Common API.
+ */
+
+#define PhysShift36(ADDR) ((UInt64)ADDR >> 12)
+
+namespace Kernel::HAL
+{
+ /// @brief Maps or allocates a page from virt_addr.
+ /// @param virt_addr a valid virtual address.
+ /// @param phys_addr point to physical address.
+ /// @param flags the flags to put on the page.
+ /// @return Status code of page manip.
+ EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags)
+ {
+ ZKA_UNUSED(virt_addr);
+ ZKA_UNUSED(flags);
+
+ return 0;
+ }
+
+ Void Out8(UInt16 port, UInt8 value)
+ {
+ asm volatile("outb %%al, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+ }
+
+ Void Out16(UInt16 port, UInt16 value)
+ {
+ asm volatile("outw %%ax, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+ }
+
+ Void Out32(UInt16 port, UInt32 value)
+ {
+ asm volatile("outl %%eax, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+ }
+
+ UInt8 In8(UInt16 port)
+ {
+ UInt8 value = 0UL;
+ asm volatile("inb %1, %%al"
+ : "=a"(value)
+ : "Nd"(port)
+ : "memory");
+
+ return value;
+ }
+
+ UInt16 In16(UInt16 port)
+ {
+ UInt16 value = 0UL;
+ asm volatile("inw %1, %%ax"
+ : "=a"(value)
+ : "Nd"(port)
+ : "memory");
+
+ return value;
+ }
+
+ UInt32 In32(UInt16 port)
+ {
+ UInt32 value = 0UL;
+ asm volatile("inl %1, %%eax"
+ : "=a"(value)
+ : "Nd"(port)
+ : "memory");
+
+ return value;
+ }
+
+ Void rt_halt()
+ {
+ asm volatile("hlt");
+ }
+
+ Void rt_cli()
+ {
+ asm volatile("cli");
+ }
+
+ Void rt_sti()
+ {
+ asm volatile("sti");
+ }
+
+ Void rt_cld()
+ {
+ asm volatile("cld");
+ }
+
+ Void rt_std()
+ {
+ asm volatile("std");
+ }
+} // namespace Kernel::HAL
diff --git a/dev/zka/HALKit/AMD64/HalControlRegister.s b/dev/zka/HALKit/AMD64/HalControlRegister.s
new file mode 100644
index 00000000..80b584ce
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalControlRegister.s
@@ -0,0 +1,45 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+.globl hal_write_cr3
+.globl hal_write_cr0
+.globl hal_read_cr2
+.globl hal_read_cr3
+.globl hal_read_cr0
+.globl hal_flush_tlb
+.globl hal_invl_tlb
+
+.text
+
+hal_invl_tlb:
+ invlpg (%rcx)
+ retq
+
+hal_flush_tlb:
+ call hal_read_cr3
+ mov %rax, %rcx
+ call hal_write_cr3
+ retq
+
+hal_read_cr3:
+ movq %cr3, %rax
+ retq
+
+hal_read_cr0:
+ movq %cr0, %rax
+ retq
+
+hal_read_cr2:
+ movq %cr2, %rax
+ retq
+
+hal_write_cr3:
+ movq %rcx, %cr3
+ retq
+
+hal_write_cr0:
+ movq %rcx, %cr0
+ retq
diff --git a/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
new file mode 100644
index 00000000..c6b8303d
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
@@ -0,0 +1,129 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel
+{
+ EXTERN UserProcessScheduler* cProcessScheduler;
+}
+
+/// @brief Handle GPF fault.
+/// @param rsp
+EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+
+ Kernel::UserProcessHelper::StartScheduling();
+ Kernel::ke_stop(RUNTIME_CHECK_PROCESS);
+}
+
+/// @brief Handle page fault.
+/// @param rsp
+EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+
+ Kernel::UserProcessHelper::StartScheduling();
+ Kernel::ke_stop(RUNTIME_CHECK_PROCESS);
+}
+
+EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessHelper::StartScheduling();
+}
+
+/// @brief Handle math fault.
+/// @param rsp
+EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+
+ Kernel::UserProcessHelper::StartScheduling();
+ Kernel::ke_stop(RUNTIME_CHECK_PROCESS);
+}
+
+/// @brief Handle any generic fault.
+/// @param rsp
+EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_PROCESS);
+}
+
+/// @brief Handle #UD fault.
+/// @param rsp
+EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp)
+{
+ if (Kernel::cProcessScheduler == nullptr)
+ {
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+
+ Kernel::UserProcessHelper::StartScheduling();
+ Kernel::ke_stop(RUNTIME_CHECK_PROCESS);
+}
+
+/// @brief Enter syscall from assembly.
+/// @param stack the stack pushed from assembly routine.
+/// @return nothing.
+EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr rdx)
+{
+ if (rcx <= (kSyscalls.Count() - 1))
+ {
+ kcout << "syscall: Enter Fn.\r";
+
+ if (kSyscalls[rcx].fHooked)
+ (kSyscalls[rcx].fProc)((Kernel::VoidPtr)rdx);
+
+ kcout << "syscall: Exit Fn.\r";
+ }
+}
+
+/// @brief Enter Kernel call from assembly (DDK only).
+/// @param stack the stack pushed from assembly routine.
+/// @return nothing.
+EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr rdx, Kernel::UIntPtr r8, Kernel::UIntPtr r9)
+{
+ if (rcx <= (kSyscalls.Count() - 1))
+ {
+ kcout << "kerncall: Enter Fn.\r";
+
+ if (kKerncalls[rcx].fHooked)
+ (kKerncalls[rcx].fProc)((Kernel::VoidPtr)rdx);
+
+ kcout << "kerncall: Exit Fn.\r";
+ }
+}
diff --git a/dev/zka/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/zka/HALKit/AMD64/HalCoreMPScheduler.cxx
new file mode 100644
index 00000000..18302f34
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalCoreMPScheduler.cxx
@@ -0,0 +1,241 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/Semaphore.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/Timer.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+
+// Needed for SMP. //
+#include <FirmwareKit/EFI.hxx>
+#include <KernelKit/HardwareThreadScheduler.hxx>
+
+#define kApicSignature "APIC"
+
+#define kAPIC_ICR_Low 0x300
+#define kAPIC_ICR_High 0x310
+#define kAPIC_SIPI_Vector 0x00500
+#define kAPIC_EIPI_Vector 0x00400
+
+#define kAPIC_BASE_MSR 0x1B
+#define kAPIC_BASE_MSR_BSP 0x100
+#define kAPIC_BASE_MSR_ENABLE 0x800
+
+#define cSMPMax (32U)
+
+/// @note: _hal_switch_context is internal
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+//! NOTE: fGSI stands 'Field Global System Interrupt'
+
+///////////////////////////////////////////////////////////////////////////////////////
+
+namespace Kernel::HAL
+{
+ struct MADT_TABLE;
+
+ EXTERN_C Void _hal_spin_core(Void);
+
+ STATIC struct MADT_TABLE* kMADTBlock = nullptr;
+ STATIC Bool kSMPAware = false;
+ STATIC Int64 kSMPCount = 0;
+
+ STATIC Int32 cSMPInterrupt = 0;
+ STATIC UInt64 cSMPCores[cSMPMax] = {0};
+ STATIC VoidPtr kRawMADT = nullptr;
+
+ /// @brief Multiple APIC Descriptor Table.
+ struct MADT_TABLE final : public SDT
+ {
+ UInt32 Address; // Madt address
+ UInt8 Flags; // Madt flags
+
+ struct
+ {
+ UInt8 Type;
+ UInt8 Len;
+
+ union {
+ struct
+ {
+ UInt8 IoID;
+ UInt8 Resv;
+ UInt32 IoAddress;
+ UInt32 GISBase;
+ } IOAPIC;
+
+ struct
+ {
+ UInt8 Source;
+ UInt8 IRQSource;
+ UInt32 GSI;
+ UInt16 Flags;
+ } IOAPIC_NMI;
+
+ struct
+ {
+ UInt8 ProcessorID;
+ UInt16 Flags;
+ UInt8 LINT;
+ } LAPIC;
+
+ struct
+ {
+ UInt16 Reserved;
+ UInt64 Address;
+ } LAPIC_ADDRESS_OVERRIDE;
+
+ struct
+ {
+ UInt16 Reserved;
+ UInt32 x2APICID;
+ UInt32 Flags;
+ UInt32 AcpiID;
+ } LAPIC_ADDRESS;
+ };
+ } List[]; // Records List
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+ /***********************************************************************************/
+ /// @brief Send start IPI for CPU.
+ /// @param apicId
+ /// @param vector
+ /// @param targetAddress
+ /// @return
+ /***********************************************************************************/
+
+ Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress)
+ {
+ Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24));
+ Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_SIPI_Vector | vector);
+ }
+
+ /***********************************************************************************/
+ /// @brief Send end IPI for CPU.
+ /// @param apicId
+ /// @param vector
+ /// @param targetAddress
+ /// @return
+ /***********************************************************************************/
+ Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress)
+ {
+ Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24));
+ Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector);
+ }
+
+ EXTERN_C Bool mp_register_process(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr stack_frame);
+
+ /// @brief Called when the AP is ready.
+ /// @internal
+ EXTERN_C Void hal_on_ap_startup(Void)
+ {
+ while (Yes)
+ {
+ }
+ }
+
+ struct PROCESS_CONTROL_BLOCK final
+ {
+ HAL::StackFramePtr f_Frame;
+ UInt8* f_Stack;
+ VoidPtr f_Image;
+ } fBlocks[kSchedProcessLimitPerTeam] = {0};
+
+ EXTERN_C HAL::StackFramePtr mp_get_current_context(Void)
+ {
+ return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame;
+ }
+
+ EXTERN_C Bool mp_register_process(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr stack_frame)
+ {
+ if (kSMPAware)
+ {
+ fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame = stack_frame;
+ fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Stack = stack_ptr;
+ fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Image = image;
+
+ return Yes;
+ }
+
+ return No;
+ }
+
+ /***********************************************************************************/
+ /// @brief Fetch and enable cores inside main CPU.
+ /// @param vendor_ptr RSD PTR structure.
+ /***********************************************************************************/
+ Void mp_get_cores(VoidPtr vendor_ptr) noexcept
+ {
+ if (!vendor_ptr)
+ return;
+
+ auto hw_and_pow_int = PowerFactoryInterface(vendor_ptr);
+ kRawMADT = hw_and_pow_int.Find(kApicSignature).Leak().Leak();
+
+ kMADTBlock = reinterpret_cast<MADT_TABLE*>(kRawMADT);
+
+ kSMPAware = false;
+
+ if (kMADTBlock)
+ {
+ SizeT index = 0;
+
+ // reset values.
+
+ cSMPInterrupt = 0;
+ kSMPCount = 0;
+
+ kcout << "Probing MADT cores...\r";
+
+ UIntPtr madt_address = kMADTBlock->Address;
+
+ while (Yes)
+ {
+ if (kMADTBlock->List[index].Type > 9 ||
+ kSMPCount > cSMPMax)
+ break;
+
+ switch (kMADTBlock->List[index].Type)
+ {
+ case 0x00: {
+ cSMPCores[index] = kMADTBlock->List[index].LAPIC.ProcessorID;
+ kcout << "Core ID: " << number(cSMPCores[index]) << endl;
+ ++kSMPCount;
+ break;
+ }
+ case 0x05: {
+ madt_address = kMADTBlock->List[index].LAPIC_ADDRESS_OVERRIDE.Address;
+ kcout << "Address: " << number(madt_address) << endl;
+ break;
+ }
+ }
+
+ ++index;
+ }
+
+ kcout << "# of cores: " << number(kSMPCount) << endl;
+
+ // Kernel is now SMP aware.
+ // That means that the scheduler is now available (on MP Kernels)
+
+ kSMPAware = true;
+
+ const auto cStartIPI = 0x34;
+
+ /// TODO: Notify AP core that it must start.
+ }
+ }
+} // namespace Kernel::HAL
+
+///////////////////////////////////////////////////////////////////////////////////////
diff --git a/dev/zka/HALKit/AMD64/HalDebugOutput.cxx b/dev/zka/HALKit/AMD64/HalDebugOutput.cxx
new file mode 100644
index 00000000..296bbcec
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalDebugOutput.cxx
@@ -0,0 +1,145 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/Framebuffer.hxx>
+#include <NewKit/Utils.hxx>
+#include <NewKit/New.hxx>
+
+namespace Kernel
+{
+ enum CommStatus
+ {
+ kStateInvalid,
+ kStateReady = 0xCF,
+ kStateTransmit = 0xFC,
+ kStateCnt = 3
+ };
+
+ namespace Detail
+ {
+ constexpr short PORT = 0x3F8;
+
+ static int kState = kStateInvalid;
+
+ /// @brief Init COM1.
+ /// @return
+ bool hal_serial_init() noexcept
+ {
+#ifdef __DEBUG__
+ if (kState == kStateReady || kState == kStateTransmit)
+ return true;
+
+ HAL::Out8(PORT + 1, 0x00); // Disable all interrupts
+ HAL::Out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ HAL::Out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
+ HAL::Out8(PORT + 1, 0x00); // (hi byte)
+ HAL::Out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
+ HAL::Out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
+ HAL::Out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
+ HAL::Out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
+ HAL::Out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if
+ // serial returns same byte)
+
+ // Check if serial is faulty (i.e: not same byte as sent)
+ if (HAL::In8(PORT) != 0xAE)
+ {
+ ke_stop(RUNTIME_CHECK_HANDSHAKE);
+ }
+
+ kState = kStateReady;
+
+ // If serial is not faulty set it in normal operation mode
+ // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
+ HAL::Out8(Detail::PORT + 4, 0x0F);
+#endif // __DEBUG__
+
+ return true;
+ }
+ } // namespace Detail
+
+ EXTERN_C void ke_io_write(const Char* bytes)
+ {
+#ifdef __DEBUG__
+ Detail::hal_serial_init();
+
+ if (!bytes || Detail::kState != kStateReady)
+ return;
+ if (*bytes == 0)
+ return;
+
+ Detail::kState = kStateTransmit;
+
+ SizeT index = 0;
+ SizeT len = 0;
+
+ index = 0;
+ len = rt_string_len(bytes, 255);
+
+ while (index < len)
+ {
+ if (bytes[index] == '\r')
+ HAL::Out8(Detail::PORT, '\r');
+
+ HAL::Out8(Detail::PORT, bytes[index] == '\r' ? '\n' : bytes[index]);
+ ++index;
+ }
+
+ Detail::kState = kStateReady;
+#endif // __DEBUG__
+ }
+
+ EXTERN_C void ke_io_read(const Char* bytes)
+ {
+#ifdef __DEBUG__
+ Detail::hal_serial_init();
+
+ if (!bytes || Detail::kState != kStateReady)
+ return;
+
+ Detail::kState = kStateTransmit;
+
+ SizeT index = 0;
+
+ ///! TODO: Look on how to wait for the UART to complete.
+ while (true)
+ {
+ auto in = HAL::In8(Detail::PORT);
+
+ ///! If enter pressed then break.
+ if (in == 0xD)
+ {
+ break;
+ }
+
+ if (in < '0' || in < 'A' || in < 'a')
+ {
+ if (in != '@' || in != '!' || in != '?' || in != '.' || in != '/' ||
+ in != ':')
+ {
+ continue;
+ }
+ }
+
+ ((char*)bytes)[index] = in;
+
+ ++index;
+ }
+
+ ((char*)bytes)[index] = 0;
+
+ Detail::kState = kStateReady;
+#endif // __DEBUG__
+ }
+
+ TerminalDevice TerminalDevice::The() noexcept
+ {
+ TerminalDevice out(Kernel::ke_io_write, Kernel::ke_io_read);
+ return out;
+ }
+
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/HalDebugPort.cxx b/dev/zka/HALKit/AMD64/HalDebugPort.cxx
new file mode 100644
index 00000000..1ea52b8d
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalDebugPort.cxx
@@ -0,0 +1,40 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+//! @file DebuggerPort.cxx
+//! @brief UART debug via packets.
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+// after that we have start of additional data.
+
+namespace Kernel
+{
+ void rt_debug_listen(DebuggerPortHeader* theHook) noexcept
+ {
+ if (theHook == nullptr)
+ return;
+
+ for (UInt32 i = 0U; i < kDebugMaxPorts; ++i)
+ {
+ HAL::Out16(theHook->fPort[i], kDebugMag0);
+ HAL::rt_wait_400ns();
+
+ HAL::Out16(theHook->fPort[i], kDebugMag1);
+ HAL::rt_wait_400ns();
+
+ HAL::Out16(theHook->fPort[i], kDebugMag2);
+ HAL::rt_wait_400ns();
+
+ HAL::Out16(theHook->fPort[i], kDebugMag3);
+ HAL::rt_wait_400ns();
+
+ if (HAL::In16(theHook->fPort[i] != kDebugUnboundPort))
+ theHook->fBoundCnt++;
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx
new file mode 100644
index 00000000..44263a1c
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx
@@ -0,0 +1,82 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+
+namespace Kernel::HAL
+{
+ namespace Detail
+ {
+ STATIC ::Kernel::Detail::AMD64::InterruptDescriptorAMD64
+ kInterruptVectorTable[kKernelIdtSize];
+
+ STATIC Void hal_remap_intel_pic_ctrl(Void) noexcept
+ {
+ auto a1 = HAL::In8(0xa1); // save masks
+ auto a2 = HAL::In8(0xa2);
+
+ HAL::Out8(0x20, 0x11);
+
+ HAL::Out8(0xA0, 0x11);
+
+ HAL::Out8(0x21, 32);
+ HAL::Out8(0xA1, 40);
+
+ HAL::Out8(0x21, 4);
+ HAL::Out8(0xA1, 2);
+
+ HAL::Out8(0x21, 0x01);
+ HAL::Out8(0xA1, 0x01);
+
+ HAL::Out8(0x21, a2);
+ HAL::Out8(0xA1, a1);
+ }
+ } // namespace Detail
+
+ /// @brief Loads the provided Global Descriptor Table.
+ /// @param gdt
+ /// @return
+ Void GDTLoader::Load(RegisterGDT& gdt)
+ {
+ hal_load_gdt(gdt);
+ }
+
+ Void IDTLoader::Load(Register64& idt)
+ {
+ volatile ::Kernel::UIntPtr** ptr_ivt = (volatile ::Kernel::UIntPtr**)idt.Base;
+
+ for (UInt16 idt_indx = 0; idt_indx < (kKernelIdtSize); ++idt_indx)
+ {
+ Detail::kInterruptVectorTable[idt_indx].Selector = kIDTSelector;
+ Detail::kInterruptVectorTable[idt_indx].Ist = 0;
+ Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kInterruptGate;
+ Detail::kInterruptVectorTable[idt_indx].OffsetLow = ((UIntPtr)ptr_ivt[idt_indx] & 0xFFFF);
+ Detail::kInterruptVectorTable[idt_indx].OffsetMid = (((UIntPtr)ptr_ivt[idt_indx] >> 16) & 0xFFFF);
+ Detail::kInterruptVectorTable[idt_indx].OffsetHigh =
+ (((UIntPtr)ptr_ivt[idt_indx] >> 32) & 0xFFFFFFFF);
+
+ Detail::kInterruptVectorTable[idt_indx].Zero = 0x0;
+ }
+
+ idt.Base = (UIntPtr)&Detail::kInterruptVectorTable;
+ idt.Limit = sizeof(::Kernel::Detail::AMD64::InterruptDescriptorAMD64) *
+ (kKernelIdtSize)-1;
+
+ hal_load_idt(idt);
+
+ Detail::hal_remap_intel_pic_ctrl();
+ }
+
+ void GDTLoader::Load(Ref<RegisterGDT>& gdt)
+ {
+ GDTLoader::Load(gdt.Leak());
+ }
+
+ void IDTLoader::Load(Ref<Register64>& idt)
+ {
+ IDTLoader::Load(idt.Leak());
+ }
+} // namespace Kernel::HAL
diff --git a/dev/zka/HALKit/AMD64/HalInterruptAPI.asm b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm
new file mode 100644
index 00000000..cdbb2d1f
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm
@@ -0,0 +1,323 @@
+;; /*
+;; * ---------------------------------------------------
+;; *
+;; * Copyright ZKA Technologies., all rights reserved.
+;; *
+;; * File: HalInterruptAPI.asm
+;; * Purpose: Interrupt API, redirect raw interrupts into their handlers.
+;; *
+;; * ---------------------------------------------------
+;; */
+
+[bits 64]
+
+%define kInterruptId 0x21
+
+%macro IntExp 1
+global __ZKA_INT_%1
+__ZKA_INT_%1:
+ cld
+ o64 iret
+%endmacro
+
+%macro IntNormal 1
+global __ZKA_INT_%1
+__ZKA_INT_%1:
+ cld
+ o64 iret
+%endmacro
+
+; This file handles the core interrupt table
+; Last edited 31/01/24
+
+global ke_handle_irq
+global kInterruptVectorTable
+
+extern idt_handle_gpf
+extern idt_handle_pf
+extern ke_io_write
+extern idt_handle_ud
+extern idt_handle_generic
+
+section .text
+
+IntNormal 0
+IntNormal 1
+
+IntNormal 2
+
+IntNormal 3
+IntNormal 4
+IntNormal 5
+
+;; Invalid opcode interrupt
+__ZKA_INT_6:
+ cld
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_ud
+
+ pop rax
+
+ std
+ o64 iret
+
+IntNormal 7
+
+;; Invalid opcode interrupt
+__ZKA_INT_8:
+ cld
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_generic
+
+ pop rax
+
+ std
+ o64 iret
+
+IntNormal 9
+IntExp 10
+IntExp 11
+
+IntExp 12
+
+__ZKA_INT_13:
+ cld
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_gpf
+
+ pop rax
+
+ std
+ o64 iret
+
+__ZKA_INT_14:
+ cld
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_pf
+
+ pop rax
+
+ std
+ o64 iret
+
+IntNormal 15
+IntNormal 16
+IntExp 17
+IntNormal 18
+IntNormal 19
+IntNormal 20
+IntNormal 21
+
+IntNormal 22
+
+IntNormal 23
+IntNormal 24
+IntNormal 25
+IntNormal 26
+IntNormal 27
+IntNormal 28
+IntNormal 29
+IntExp 30
+IntNormal 31
+IntNormal 32
+IntNormal 33
+IntNormal 34
+IntNormal 35
+IntNormal 36
+IntNormal 37
+IntNormal 38
+IntNormal 39
+IntNormal 40
+
+IntNormal 41
+
+IntNormal 42
+IntNormal 43
+IntNormal 44
+IntNormal 45
+IntNormal 46
+IntNormal 47
+IntNormal 48
+IntNormal 49
+
+[extern hal_system_call_enter]
+[extern hal_kernel_call_enter]
+
+__ZKA_INT_50:
+ cld
+
+ push r8
+ push r9
+ push r10
+ push rsp
+
+ jmp hal_system_call_enter
+
+ add rsp, 16
+ pop rsp
+ pop r10
+ pop r9
+ pop r8
+
+ std
+ o64 iret
+
+__ZKA_INT_51:
+ cld
+
+ push rcx
+ push rdx
+ push r8
+ push r9
+ push rax
+
+ call hal_kernel_call_enter
+
+ pop rax
+ pop r9
+ pop r8
+ pop rdx
+ pop rcx
+
+ std
+ o64 iret
+
+[extern hal_on_ap_startup]
+
+PRESENT equ 1 << 7
+NOT_SYS equ 1 << 4
+EXEC equ 1 << 3
+DC equ 1 << 2
+RW equ 1 << 1
+ACCESSED equ 1 << 0
+
+; Flags bits
+GRAN_4K equ 1 << 7
+SZ_32 equ 1 << 6
+LONG_MODE equ 1 << 5
+
+__ZKA_INT_52:
+ cld
+ jmp hal_on_ap_startup
+ std
+ ret
+
+IntNormal 53
+IntNormal 54
+IntNormal 55
+IntNormal 56
+IntNormal 57
+IntNormal 58
+IntNormal 59
+IntNormal 60
+
+%assign i 61
+%rep 195
+ IntNormal i
+%assign i i+1
+%endrep
+
+section .text
+
+[global hal_load_gdt]
+
+hal_load_gdt:
+ cld
+
+ lgdt [rcx]
+
+ mov ax, 0x10
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov ss, ax
+
+ mov rax, 0x08
+ push rax
+ push hal_reload_segments
+
+ o64 retf
+
+extern hal_real_init
+
+hal_reload_segments:
+ std
+ ;; Write address of syscall handler.
+
+ mov rdx, [mp_system_call_handler]
+ shr rdx, 32
+ mov rcx, 0xC0000082
+ wrmsr
+
+ ;; Set segments of syscall handler.
+
+ xor rax, rax
+ mov rdx, 0x230008
+ mov rcx, 0xC0000081
+ wrmsr
+
+ mov ecx, 0xC0000080
+ rdmsr
+ or eax, 1
+ wrmsr
+
+ jmp hal_real_init
+ ret
+
+global hal_load_idt
+global hal_user_code_start
+
+extern hal_system_call_enter
+global mp_system_call_handler
+
+mp_system_call_handler:
+
+ push r8
+ push r9
+ push r10
+ push r11
+ push r12
+ push r13
+ push r14
+ push r15
+
+ jmp hal_system_call_enter
+
+ pop r15
+ pop r14
+ pop r13
+ pop r12
+ pop r11
+ pop r10
+ pop r9
+ pop r8
+
+ o64 sysret
+
+hal_load_idt:
+ cld
+ lidt [rcx]
+ std
+ ret
+
+section .data
+
+kInterruptVectorTable:
+ %assign i 0
+ %rep 256
+ dq __ZKA_INT_%+i
+ %assign i i+1
+ %endrep
diff --git a/dev/zka/HALKit/AMD64/HalKernelMain.cxx b/dev/zka/HALKit/AMD64/HalKernelMain.cxx
new file mode 100644
index 00000000..767cc903
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalKernelMain.cxx
@@ -0,0 +1,95 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/FileMgr.hxx>
+#include <KernelKit/Framebuffer.hxx>
+#include <KernelKit/Heap.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <NewKit/Json.hxx>
+#include <Modules/CoreCG/Accessibility.hxx>
+#include <KernelKit/CodeMgr.hxx>
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <NetworkKit/IPC.hxx>
+#include <CFKit/Property.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+#include <Modules/CoreCG/WindowRenderer.hxx>
+
+namespace Kernel::HAL
+{
+ /// @brief Gets the system cores using the MADT.
+ /// @param rsdPtr The 'RSD PTR' data structure.
+ EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr) noexcept;
+} // namespace Kernel::HAL
+
+EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
+
+/// @brief Kernel init procedure.
+EXTERN_C void hal_init_platform(
+ Kernel::HEL::HANDOVER_INFO_HEADER* HandoverHeader)
+{
+ kHandoverHeader = HandoverHeader;
+
+ if (kHandoverHeader->f_Magic != kHandoverMagic &&
+ kHandoverHeader->f_Version != kHandoverVersion)
+ {
+ return;
+ }
+
+ CG::CGDrawBackground();
+
+ // get page size.
+ kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
+
+ // get virtual address start (for the heap)
+ kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
+ reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
+
+ STATIC CONST auto cEntriesCount = 6;
+
+ /* GDT, mostly descriptors for user and kernel segments. */
+ STATIC Kernel::HAL::Detail::ZKA_GDT_ENTRY ALIGN(0x08) cGdt[cEntriesCount] = {
+ {.fLimitLow = 0, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x00, .fFlags = 0x00, .fBaseHigh = 0}, // Null entry
+ {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x9A, .fFlags = 0xAF, .fBaseHigh = 0}, // Kernel code
+ {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x92, .fFlags = 0xCF, .fBaseHigh = 0}, // Kernel data
+ {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xF2, .fFlags = 0xCF, .fBaseHigh = 0}, // User data
+ {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xFA, .fFlags = 0xAF, .fBaseHigh = 0}, // User code
+ };
+
+ // Load memory descriptors.
+ Kernel::HAL::RegisterGDT gdtBase;
+
+ gdtBase.Base = reinterpret_cast<Kernel::UIntPtr>(cGdt);
+ gdtBase.Limit = (sizeof(Kernel::HAL::Detail::ZKA_GDT_ENTRY) * cEntriesCount) - 1;
+
+ //! GDT will load hal_read_init after it successfully loads the segments.
+ Kernel::HAL::GDTLoader gdtLoader;
+ gdtLoader.Load(gdtBase);
+
+ Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+}
+
+EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept
+{
+ Kernel::HAL::Register64 idtBase;
+ idtBase.Base = (Kernel::UIntPtr)kInterruptVectorTable;
+
+ Kernel::HAL::IDTLoader idtLoader;
+ idtLoader.Load(idtBase);
+
+ if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
+ Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
+
+ Kernel::NeFileSystemMgr* mgr = Kernel::mm_new_class<Kernel::NeFileSystemMgr>();
+ Kernel::NeFileSystemMgr::Mount(mgr);
+
+ mp_do_user_switch();
+
+ Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+}
diff --git a/dev/zka/HALKit/AMD64/HalMPContextSwitch.asm b/dev/zka/HALKit/AMD64/HalMPContextSwitch.asm
new file mode 100644
index 00000000..4251f232
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalMPContextSwitch.asm
@@ -0,0 +1,59 @@
+;; /*
+;; * ========================================================
+;; *
+;; * ZKA
+;; * Copyright ZKA Technologies., all rights reserved.
+;; *
+;; * ========================================================
+;; */
+
+[bits 64]
+
+[global mp_do_user_switch]
+[global mp_do_context_switch_pre]
+[global mp_user_switch_proc]
+[global mp_user_switch_proc_real]
+[global mp_user_switch_proc_stack_end]
+
+section .text
+
+;; @brief Switch to user mode.
+mp_do_user_switch:
+ mov rbp, rsp
+ mov rsp, mp_user_switch_proc_stack_end
+
+ mov rdx, mp_user_switch_proc
+ invlpg [rdx]
+
+ mov ax, 0x18 | 3
+ mov ds, ax
+ mov es, ax
+ mov gs, ax
+ mov fs, ax
+
+ push 0x18 | 3
+
+ mov rax, mp_user_switch_proc_stack_end
+ push rax
+
+ o64 pushf
+
+ push 0x20 | 3
+
+ mov rdx, mp_user_switch_proc
+ push rdx
+
+ o64 iret
+
+section .bss
+
+mp_user_switch_proc_stack_begin:
+ resb 4*4096
+mp_user_switch_proc_stack_end:
+
+section .text
+
+mp_user_switch_proc:
+ nop
+ jmp $
+mp_user_switch_proc_end:
diff --git a/dev/zka/HALKit/AMD64/HalRoutineWait.s b/dev/zka/HALKit/AMD64/HalRoutineWait.s
new file mode 100644
index 00000000..d794882d
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalRoutineWait.s
@@ -0,0 +1,9 @@
+.globl rt_wait_400ns
+
+.section .text
+rt_wait_400ns:
+ jmp .loop
+ .loop:
+ jmp .loop2
+ .loop2:
+ ret
diff --git a/dev/zka/HALKit/AMD64/HalSchedulerCore.cxx b/dev/zka/HALKit/AMD64/HalSchedulerCore.cxx
new file mode 100644
index 00000000..9dcce147
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalSchedulerCore.cxx
@@ -0,0 +1,56 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/AMD64/Processor.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+using namespace Kernel;
+
+Void UserProcess::SetImageStart(VoidPtr imageStart) noexcept
+{
+ if (imageStart == nullptr)
+ this->Crash();
+
+ this->Image = imageStart;
+}
+
+namespace Kernel
+{
+ /***********************************************************************************/
+ /// @brief Unimplemented function (crashes by default)
+ /// @param
+ /***********************************************************************************/
+
+ EXTERN_C Void __zka_pure_call(void)
+ {
+ asm volatile("mov %r8, 0; mov %r9, 1; syscall");
+ }
+
+ Bool hal_check_stack(HAL::StackFramePtr stack_ptr)
+ {
+ if (!stack_ptr)
+ return false;
+
+ return true;
+ }
+
+ /// @brief Wakes up thread.
+ /// Wakes up thread from the hang state.
+ Void mp_wakeup_thread(HAL::StackFrame* stack)
+ {
+ Kernel::UserProcessHelper::StartScheduling();
+ }
+
+ /// @brief makes the thread sleep on a loop.
+ /// hooks and hangs thread to prevent code from executing.
+ Void mp_hang_thread(HAL::StackFrame* stack)
+ {
+ while (Yes)
+ {
+ /* Nothing to do, code is spinning */
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/HalTimer.cxx b/dev/zka/HALKit/AMD64/HalTimer.cxx
new file mode 100644
index 00000000..4a5d38cf
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalTimer.cxx
@@ -0,0 +1,86 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: HalTimer.cxx
+ Purpose: HAL timer
+
+ Revision History:
+
+ 07/07/24: Added file (amlel)
+
+------------------------------------------- */
+
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/Timer.hxx>
+
+// timer slot 0
+
+#define cHPETCounterRegValue (0x00)
+#define cHPETConfigRegValue (0x20)
+#define cHPETCompRegValue (0x24)
+#define cHPETInterruptRegValue (0x2C)
+
+///! BUGS: 0
+///! @file HalTimer.cxx
+///! @brief Hardware Timer (HPET)
+
+namespace Kernel::Detail
+{
+ struct HPET_BLOCK : public Kernel::SDT
+ {
+ Kernel::UInt8 hardware_rev_id;
+ Kernel::UInt8 comparator_count : 5;
+ Kernel::UInt8 counter_size : 1;
+ Kernel::UInt8 reserved : 1;
+ Kernel::UInt8 legacy_replacement : 1;
+ Kernel::UInt16 pci_vendor_id;
+ ACPI_ADDRESS address;
+ Kernel::UInt8 hpet_number;
+ Kernel::UInt16 minimum_tick;
+ Kernel::UInt8 page_protection;
+ } PACKED;
+} // namespace Kernel::Detail
+
+using namespace Kernel;
+
+HardwareTimer::HardwareTimer(Int64 ms)
+ : fWaitFor(ms)
+{
+ auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr);
+
+ auto hpet = (Detail::HPET_BLOCK*)power.Find("HPET").Leak().Leak();
+ MUST_PASS(hpet);
+
+ fDigitalTimer = (IntPtr*)hpet->address.Address;
+}
+
+HardwareTimer::~HardwareTimer()
+{
+ fDigitalTimer = nullptr;
+ fWaitFor = 0;
+}
+
+Int32 HardwareTimer::Wait() noexcept
+{
+ if (fWaitFor < 1)
+ return -1;
+
+ // if not enabled yet.
+ if (!(*(fDigitalTimer + cHPETConfigRegValue) & (1 << 0)))
+ {
+ *(fDigitalTimer + cHPETConfigRegValue) |= (1 << 0); // enable it
+ *(fDigitalTimer + cHPETConfigRegValue) |= (1 << 3); // one shot conf
+ }
+
+ UInt64 ticks = fWaitFor / ((*(fDigitalTimer) >> 32) & __UINT32_MAX__);
+ UInt64 prev = *(fDigitalTimer + cHPETCounterRegValue);
+
+ prev += ticks;
+
+ while (*(fDigitalTimer + cHPETCounterRegValue) < (ticks))
+ ;
+
+ return 0;
+}
diff --git a/dev/zka/HALKit/AMD64/HalUtils.asm b/dev/zka/HALKit/AMD64/HalUtils.asm
new file mode 100644
index 00000000..0e4caf2b
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/HalUtils.asm
@@ -0,0 +1,33 @@
+;; /*
+;; * ========================================================
+;; *
+;; * ZKA
+;; * Copyright ZKA Technologies., all rights reserved.
+;; *
+;; * ========================================================
+;; */
+
+[bits 64]
+
+[global rt_install_tib]
+
+section .text
+
+;; changed: rs, fs
+;; expected: rcx, rdx
+
+rt_install_tib:
+ mov rcx, gs ;; TIB -> Thread Information Block
+ mov rdx, fs ;; PIB -> Process Information Block
+ ret
+
+;; //////////////////////////////////////////////////// ;;
+
+[extern cBspDone]
+[extern kApicMadtAddressesCount]
+[extern hal_on_ap_startup]
+[global hal_ap_trampoline]
+
+hal_ap_trampoline:
+hal_ap_trampoline_1:
+ jmp hal_on_ap_startup
diff --git a/dev/zka/HALKit/AMD64/Hypervisor.hxx b/dev/zka/HALKit/AMD64/Hypervisor.hxx
new file mode 100644
index 00000000..7871288f
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Hypervisor.hxx
@@ -0,0 +1,25 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ MAKE_STRING_ENUM(HYPERVISOR)
+ ENUM_STRING(Qemu, "TCGTCGTCGTCG");
+ ENUM_STRING(KVM, " KVMKVMKVM ");
+ ENUM_STRING(VMWare, "VMwareVMware");
+ ENUM_STRING(VirtualBox, "VBoxVBoxVBox");
+ ENUM_STRING(Xen, "XenVMMXenVMM");
+ ENUM_STRING(Microsoft, "Microsoft Hv");
+ ENUM_STRING(Parallels, " prl hyperv ");
+ ENUM_STRING(ParallelsAlt, " lrpepyh vr ");
+ ENUM_STRING(Bhyve, "bhyve bhyve ");
+ ENUM_STRING(Qnx, " QNXQVMBSQG ");
+ END_STRING_ENUM()
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/MBCI/.gitkeep b/dev/zka/HALKit/AMD64/MBCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/MBCI/.gitkeep
diff --git a/dev/zka/HALKit/AMD64/PCI/Database.cxx b/dev/zka/HALKit/AMD64/PCI/Database.cxx
new file mode 100644
index 00000000..971d43f9
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/Database.cxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/Database.hxx>
+
+namespace Kernel
+{
+}
diff --git a/dev/zka/HALKit/AMD64/PCI/Device.cxx b/dev/zka/HALKit/AMD64/PCI/Device.cxx
new file mode 100644
index 00000000..bc6ba2bb
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/Device.cxx
@@ -0,0 +1,141 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/PCI/Device.hxx>
+
+Kernel::UInt ZKA_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+{
+ Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
+ ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
+ (bar & 0xFC);
+
+ Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
+ target);
+
+ return Kernel::HAL::In32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
+}
+
+void ZKA_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
+{
+ Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
+ ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
+ (bar & ~3);
+
+ Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
+ target);
+}
+
+#define PCI_BAR_IO 0x01
+#define PCI_BAR_LOWMEM 0x02
+#define PCI_BAR_64 0x04
+#define PCI_BAR_PREFETCH 0x08
+
+namespace Kernel::PCI
+{
+ Device::Device(UShort bus, UShort device, UShort func, UInt32 bar)
+ : fBus(bus), fDevice(device), fFunction(func), fBar(bar)
+ {
+ // get bar 0
+ auto bar_zero = 0x10 + bar * sizeof(UInt32);
+ fBar = this->Read(bar_zero, 4);
+ }
+
+ Device::~Device() = default;
+
+ UInt Device::Read(UInt bar, Size sz)
+ {
+ ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
+
+ if (sz == 4)
+ return HAL::In32((UShort)PciConfigKind::ConfigData + (bar & 3));
+ if (sz == 2)
+ return HAL::In16((UShort)PciConfigKind::ConfigData + (bar & 3));
+ if (sz == 1)
+ return HAL::In8((UShort)PciConfigKind::ConfigData + (bar & 3));
+
+ return 0xFFFF;
+ }
+
+ void Device::Write(UInt bar, UIntPtr data, Size sz)
+ {
+ ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
+
+ if (sz == 4)
+ HAL::Out32((UShort)PciConfigKind::ConfigData + (fBar & 3), (UInt)data);
+ if (sz == 2)
+ HAL::Out16((UShort)PciConfigKind::ConfigData + (fBar & 3), (UShort)data);
+ if (sz == 1)
+ HAL::Out8((UShort)PciConfigKind::ConfigData + (fBar & 3), (UChar)data);
+ }
+
+ UShort Device::DeviceId()
+ {
+ return (UShort)(ZKA_PCIReadRaw(0x0 >> 16, fBus, fDevice, fFunction));
+ }
+
+ UShort Device::VendorId()
+ {
+ return (UShort)(ZKA_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
+ }
+
+ UShort Device::InterfaceId()
+ {
+ return (UShort)(ZKA_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
+ }
+
+ UChar Device::Class()
+ {
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 24);
+ }
+
+ UChar Device::Subclass()
+ {
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 16);
+ }
+
+ UChar Device::ProgIf()
+ {
+ return (UChar)(ZKA_PCIReadRaw(0x08, fBus, fDevice, fFunction) >> 8);
+ }
+
+ UChar Device::HeaderType()
+ {
+ return (UChar)(ZKA_PCIReadRaw(0xC, fBus, fDevice, fFunction) >> 16);
+ }
+
+ void Device::EnableMmio()
+ {
+ bool enable = Read(0x04, sizeof(UChar)) | (1 << 1);
+ Write(0x04, enable, sizeof(UShort));
+ }
+
+ void Device::BecomeBusMaster()
+ {
+ bool enable = Read(0x04, sizeof(UShort)) | (1 << 2);
+ Write(0x04, enable, sizeof(UShort));
+ }
+
+ UInt32 Device::Bar()
+ {
+ return fBar;
+ }
+
+ UShort Device::Vendor()
+ {
+ UShort vendor = VendorId();
+
+ if (vendor != (UShort)PciConfigKind::Invalid)
+ fDevice = (UShort)Read(0x0, sizeof(UShort));
+
+ return fDevice;
+ }
+
+ Device::operator bool()
+ {
+ return VendorId() != (UShort)PciConfigKind::Invalid;
+ }
+} // namespace Kernel::PCI
diff --git a/dev/zka/HALKit/AMD64/PCI/Dma.cxx b/dev/zka/HALKit/AMD64/PCI/Dma.cxx
new file mode 100644
index 00000000..bf1730d8
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/Dma.cxx
@@ -0,0 +1,82 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/Dma.hxx>
+
+namespace Kernel
+{
+ DMAWrapper::operator bool()
+ {
+ return fAddress;
+ }
+
+ bool DMAWrapper::operator!()
+ {
+ return !fAddress;
+ }
+
+ Boolean DMAWrapper::Check(UIntPtr offset) const
+ {
+ if (!fAddress)
+ return false;
+ if (offset == 0)
+ return true;
+
+ kcout << "[DMAWrapper::IsIn] Checking offset..\n";
+ return reinterpret_cast<UIntPtr>(fAddress) >= offset;
+ }
+
+ bool DMAWrapper::Write(const UIntPtr& bit, const UIntPtr& offset)
+ {
+ if (!fAddress)
+ return false;
+
+ kcout << "[DMAWrapper::Write] Writing at address..\n";
+
+ auto addr =
+ (volatile UIntPtr*)(reinterpret_cast<UIntPtr>(fAddress) + offset);
+ *addr = bit;
+
+ return true;
+ }
+
+ UIntPtr DMAWrapper::Read(const UIntPtr& offset)
+ {
+ kcout << "[DMAWrapper::Read] checking fAddress..\n";
+ if (!fAddress)
+ return 0;
+
+ kcout << "[DMAWrapper::Read] Reading fAddress..\n";
+ return *(volatile UIntPtr*)(reinterpret_cast<UIntPtr>(fAddress) + offset);
+ ;
+ }
+
+ UIntPtr DMAWrapper::operator[](const UIntPtr& offset)
+ {
+ return this->Read(offset);
+ }
+
+ OwnPtr<IOBuf<Char*>> DMAFactory::Construct(OwnPtr<DMAWrapper>& dma)
+ {
+ if (!dma)
+ return {};
+
+ OwnPtr<IOBuf<Char*>> dmaOwnPtr =
+ make_ptr<IOBuf<Char*>, char*>(reinterpret_cast<char*>(dma->fAddress));
+
+ if (!dmaOwnPtr)
+ return {};
+
+ kcout << "Returning the new OwnPtr<IOBuf<Char*>>!\r";
+ return dmaOwnPtr;
+ }
+
+ DMAWrapper& DMAWrapper::operator=(voidPtr Ptr)
+ {
+ fAddress = Ptr;
+ return *this;
+ }
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/PCI/Express.cxx b/dev/zka/HALKit/AMD64/PCI/Express.cxx
new file mode 100644
index 00000000..6a926827
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/Express.cxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/Express.hxx>
+
+namespace Kernel
+{
+}
diff --git a/dev/zka/HALKit/AMD64/PCI/IO.cxx b/dev/zka/HALKit/AMD64/PCI/IO.cxx
new file mode 100644
index 00000000..ea91c7b7
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/IO.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/IO.hxx>
diff --git a/dev/zka/HALKit/AMD64/PCI/Iterator.cxx b/dev/zka/HALKit/AMD64/PCI/Iterator.cxx
new file mode 100644
index 00000000..ea38e717
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/Iterator.cxx
@@ -0,0 +1,39 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/Iterator.hxx>
+
+namespace Kernel::PCI
+{
+ Iterator::Iterator(const Types::PciDeviceKind& type)
+ {
+ // probe devices.
+ for (int bus = 0; bus < ZKA_BUS_COUNT; ++bus)
+ {
+ for (int device = 0; device < ZKA_DEVICE_COUNT; ++device)
+ {
+ for (int function = 0; function < ZKA_FUNCTION_COUNT; ++function)
+ {
+ Device dev(bus, device, function, type == Types::PciDeviceKind::MassStorageController ? 5 : 1);
+
+ if (dev.Class() == (UChar)type)
+ {
+ fDevices[bus] = dev;
+ }
+ }
+ }
+ }
+ }
+
+ Iterator::~Iterator()
+ {
+ }
+
+ Ref<PCI::Device> Iterator::operator[](const Size& at)
+ {
+ return fDevices[at];
+ }
+} // namespace Kernel::PCI
diff --git a/dev/zka/HALKit/AMD64/PCI/PCI.cxx b/dev/zka/HALKit/AMD64/PCI/PCI.cxx
new file mode 100644
index 00000000..59e3b06e
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/PCI/PCI.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/PCI/PCI.hxx>
diff --git a/dev/zka/HALKit/AMD64/Paging.hxx b/dev/zka/HALKit/AMD64/Paging.hxx
new file mode 100644
index 00000000..f127d0e4
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Paging.hxx
@@ -0,0 +1,99 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+/** ---------------------------------------------------
+
+ * THIS FILE CONTAINS CODE FOR X86_64 PAGING.
+
+------------------------------------------------------- */
+
+#include <NewKit/Defines.hxx>
+
+#ifndef kPageMax
+#define kPageMax (0x200)
+#endif //! kPageMax
+
+#ifndef kPageAlign
+#define kPageAlign (0x08)
+#endif //! kPageAlign
+
+#ifndef kPageSize
+#define kPageSize (0x100)
+#endif // !kPageSize
+
+#ifndef kAlign
+#define kAlign __BIGGEST_ALIGNMENT__
+#endif // !kAlign
+
+EXTERN_C void hal_flush_tlb();
+EXTERN_C void hal_invl_tlb(Kernel::VoidPtr addr);
+EXTERN_C void hal_write_cr3(Kernel::VoidPtr cr3);
+EXTERN_C void hal_write_cr0(Kernel::VoidPtr bit);
+
+EXTERN_C Kernel::VoidPtr hal_read_cr0(); // @brief CPU control register.
+EXTERN_C Kernel::VoidPtr hal_read_cr2(); // @brief Fault address.
+EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page table.
+
+namespace Kernel::HAL
+{
+ /// @brief Final page entry (Not PML, PDPT)
+ struct PACKED ZKA_PTE final
+ {
+ UInt64 Present : 1;
+ UInt64 Wr : 1;
+ UInt64 User : 1;
+ UInt64 Wt : 1;
+ UInt64 Cache : 1;
+ UInt64 Accessed : 1;
+ UInt64 Dirty : 1;
+ UInt64 MemoryType : 1;
+ UInt64 Global : 1;
+ UInt64 Resvered1 : 3;
+ UInt64 PhysicalAddress : 36;
+ UInt64 Reserved2 : 10;
+ UInt64 ProtectionKey : 5;
+ UInt64 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 ZKA_PDE final
+ {
+ ZKA_PTE* ALIGN(kPageAlign) fEntries[kPageMax];
+ };
+
+ auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr;
+ auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
+} // namespace Kernel::HAL
+
+namespace Kernel
+{
+ typedef HAL::ZKA_PTE PTE;
+ typedef HAL::ZKA_PDE PDE;
+} // namespace Kernel
diff --git a/dev/zka/HALKit/AMD64/Processor.hxx b/dev/zka/HALKit/AMD64/Processor.hxx
new file mode 100644
index 00000000..e39cac0a
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Processor.hxx
@@ -0,0 +1,296 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Prcoessor.hxx
+ Purpose: AMD64 processor abstraction.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Utils.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <HALKit/AMD64/Paging.hxx>
+
+EXTERN_C
+{
+#include <cpuid.h>
+}
+
+#define IsActiveLow(FLG) (FLG & 2)
+#define IsLevelTriggered(FLG) (FLG & 8)
+
+#define kInterruptGate (0x8E)
+#define kTrapGate (0xEF)
+#define kTaskGate (0b10001100)
+#define kIDTSelector (0x08)
+
+namespace Kernel
+{
+ namespace Detail::AMD64
+ {
+ struct PACKED InterruptDescriptorAMD64 final
+ {
+ UInt16 OffsetLow; // offset bits 0..15
+ UInt16 Selector; // a code segment selector in GDT or LDT
+ UInt8 Ist;
+ UInt8 TypeAttributes;
+ UInt16 OffsetMid;
+ UInt32 OffsetHigh;
+ UInt32 Zero; // reserved
+ };
+ } // namespace Detail::AMD64
+} // namespace Kernel
+
+namespace Kernel::HAL
+{
+ /// @brief Virtual memory flags.
+ enum
+ {
+ eFlagsPresent = 0x1,
+ eFlagsRw = 0x2,
+ eFlagsUser = 0x4,
+ eFlagsCount = 3,
+ };
+
+ /// @brief Set a PTE from pd_base.
+ /// @param virt_addr a valid virtual address.
+ /// @param phys_addr point to physical address.
+ /// @param flags the flags to put on the page.
+ /// @return Status code of page manip.
+ EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags);
+
+ EXTERN_C UChar In8(UInt16 port);
+ EXTERN_C UShort In16(UInt16 port);
+ EXTERN_C UInt In32(UInt16 port);
+
+ EXTERN_C void Out16(UShort port, UShort byte);
+ EXTERN_C void Out8(UShort port, UChar byte);
+ EXTERN_C void Out32(UShort port, UInt byte);
+
+ EXTERN_C void rt_wait_400ns();
+ EXTERN_C void rt_halt();
+ EXTERN_C void rt_cli();
+ EXTERN_C void rt_sti();
+ EXTERN_C void rt_cld();
+ EXTERN_C void rt_std();
+
+ struct PACKED Register64 final
+ {
+ UShort Limit;
+ UIntPtr Base;
+ };
+
+ struct PACKED RegisterGDT final
+ {
+ UShort Limit;
+ UIntPtr Base;
+ };
+
+ using RawRegister = UInt64;
+ using Reg = RawRegister;
+ using InterruptId = UInt16; /* For each element in the IVT */
+
+ /// @brief Stack frame (as retrieved from assembly.)
+ struct PACKED StackFrame final
+ {
+ RawRegister R8{0};
+ RawRegister R9{0};
+ RawRegister R10{0};
+ RawRegister FS{0};
+ RawRegister R12{0};
+ RawRegister R13{0};
+ RawRegister R14{0};
+ RawRegister R15{0};
+ RawRegister GS{0};
+ };
+
+ typedef StackFrame* StackFramePtr;
+
+ class InterruptDescriptor final
+ {
+ public:
+ UShort Offset;
+ UShort Selector;
+ UChar Ist;
+ UChar Atrributes;
+
+ UShort SecondOffset;
+ UInt ThirdOffset;
+ UInt Zero;
+
+ operator bool()
+ {
+ return Offset != 0xFFFF;
+ }
+ };
+
+ using InterruptDescriptorArray = Array<InterruptDescriptor, 256>;
+
+ class SegmentDescriptor final
+ {
+ public:
+ UInt16 Base;
+ UInt8 BaseMiddle;
+ UInt8 BaseHigh;
+
+ UShort Limit;
+ UChar Gran;
+ UChar AccessByte;
+ };
+
+ /***
+ * @brief Segment Boolean operations
+ */
+ class SegmentDescriptorComparator final
+ {
+ public:
+ Bool IsValid(SegmentDescriptor& seg)
+ {
+ return seg.Base > seg.Limit;
+ }
+
+ Bool Equals(SegmentDescriptor& seg, SegmentDescriptor& segRight)
+ {
+ return seg.Base == segRight.Base && seg.Limit == segRight.Limit;
+ }
+ };
+
+ using SegmentArray = Array<SegmentDescriptor, 6>;
+
+ class GDTLoader final
+ {
+ public:
+ static Void Load(RegisterGDT& gdt);
+ static Void Load(Ref<RegisterGDT>& gdt);
+ };
+
+ class IDTLoader final
+ {
+ public:
+ static Void Load(Register64& idt);
+ static Void Load(Ref<Register64>& idt);
+ };
+
+ Void mp_get_cores(VoidPtr rsdPtr) noexcept;
+ Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
+ Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
+
+ /// @brief Do a cpuid to check if MSR exists on CPU.
+ /// @retval true it does exists.
+ /// @retval false it doesn't.
+ inline Bool hal_has_msr() noexcept
+ {
+ static UInt32 eax, unused, edx; // eax, edx
+
+ __get_cpuid(1, &eax, &unused, &unused, &edx);
+
+ // edx returns the flag for MSR (which is 1 shifted to 5.)
+ return edx & (1 << 5);
+ }
+
+ /// @brief Get Model-specific register.
+ /// @param msr MSR
+ /// @param lo low byte
+ /// @param hi high byte
+ inline Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept
+ {
+ if (!lo || !hi)
+ return;
+
+ asm volatile("rdmsr"
+ : "=a"(*lo), "=d"(*hi)
+ : "c"(msr));
+ }
+
+ /// @brief Set Model-specific register.
+ /// @param msr MSR
+ /// @param lo low byte
+ /// @param hi high byte
+ inline Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept
+ {
+ asm volatile("wrmsr"
+ :
+ : "a"(lo), "d"(hi), "c"(msr));
+ }
+
+ /// @brief Processor specific namespace.
+ namespace Detail
+ {
+ /* @brief TSS struct. */
+ struct ZKA_TSS final
+ {
+ UInt32 fReserved1;
+ UInt64 fRsp0;
+ UInt64 fRsp1;
+ UInt64 fRsp2;
+ UInt64 fReserved2;
+ UInt64 fIst1;
+ UInt64 fIst2;
+ UInt64 fIst3;
+ UInt64 fIst4;
+ UInt64 fIst5;
+ UInt64 fIst6;
+ UInt64 fIst7;
+ UInt64 fReserved3;
+ UInt16 fReserved4;
+ UInt16 fIopb;
+ };
+
+ /**
+ @brief Global descriptor table entry, either null, code or data.
+ */
+
+ struct PACKED ZKA_GDT_ENTRY final
+ {
+ UInt16 fLimitLow;
+ UInt16 fBaseLow;
+ UInt8 fBaseMid;
+ UInt8 fAccessByte;
+ UInt8 fFlags;
+ UInt8 fBaseHigh;
+ };
+ } // namespace Detail
+
+ class APICController
+ {
+ public:
+ explicit APICController(VoidPtr base)
+ : fApic(base)
+ {
+ }
+
+ ~APICController() = default;
+
+ ZKA_COPY_DEFAULT(APICController);
+
+ public:
+ UInt32 Read(UInt32 reg) noexcept;
+ Void Write(UInt32 reg, UInt32 value) noexcept;
+
+ private:
+ VoidPtr fApic{nullptr};
+ };
+} // namespace Kernel::HAL
+
+EXTERN_C Kernel::Void idt_handle_generic(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_math(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_pf(Kernel::UIntPtr rsp);
+
+EXTERN_C Kernel::Void hal_load_idt(Kernel::HAL::Register64 ptr);
+EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
+
+/// @brief Maximum size of the IDT.
+#define kKernelIdtSize (0x100)
+#define kKernelInterruptId 0x32
+
+inline Kernel::VoidPtr kKernelBitMpStart = nullptr;
+inline Kernel::UIntPtr kKernelBitMpSize = 0UL;
diff --git a/dev/zka/HALKit/AMD64/ReadMe.md b/dev/zka/HALKit/AMD64/ReadMe.md
new file mode 100644
index 00000000..bb936737
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/ReadMe.md
@@ -0,0 +1,4 @@
+# AMD64 Hardware Abstraction Layer
+
+- Supported CPU: AMD64 CPU
+- Supported Firmware: EDK 2
diff --git a/dev/zka/HALKit/AMD64/Storage/AHCI.cxx b/dev/zka/HALKit/AMD64/Storage/AHCI.cxx
new file mode 100644
index 00000000..95d73c03
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Storage/AHCI.cxx
@@ -0,0 +1,123 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file AHCI.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief AHCI driver.
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright ZKA Technologies.
+ *
+ */
+
+#include <Modules/AHCI/AHCI.hxx>
+#include <KernelKit/PCI/Iterator.hxx>
+
+#ifdef __AHCI__
+enum
+{
+ kSATAProgIfAHCI = 0x01,
+ kSATASubClass = 0x06
+};
+
+STATIC Kernel::PCI::Device kAhciDevice;
+STATIC HbaPort* kAhciPort = nullptr;
+
+/// @brief Initializes an AHCI disk.
+/// @param PortsImplemented the amount of port that have been detected.
+/// @return
+Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
+{
+ using namespace Kernel;
+
+ PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
+
+ for (SizeT devIndex = 0; devIndex < ZKA_BUS_COUNT; ++devIndex)
+ {
+ if (iterator[devIndex].Leak().Subclass() == kSATASubClass &&
+ iterator[devIndex].Leak().ProgIf() == kSATAProgIfAHCI)
+ {
+ iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device.
+ iterator[devIndex].Leak().BecomeBusMaster(); /// become bus master for this ahci device, so that we can control it.
+
+ kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference.
+
+ HbaMem* mem_ahci = (HbaMem*)kAhciDevice.Bar();
+
+ UInt32 ports_implemented = mem_ahci->Pi;
+ Int32 ahci_index = 0;
+
+ const auto cMaxAhciDevices = 32;
+ const auto cAhciSig = 0x00000101;
+ const auto cAhciPresent = 0x03;
+ const auto cAhciIPMActive = 0x01;
+
+ auto detected = false;
+
+ while (ahci_index < cMaxAhciDevices)
+ {
+ if (ports_implemented)
+ {
+ kcout << "Port is implemented by host.\r";
+
+ UInt8 ipm = (mem_ahci->Ports[ahci_index].Ssts >> 8) & 0x0F;
+ UInt8 det = mem_ahci->Ports[ahci_index].Ssts & 0x0F;
+
+ if (mem_ahci->Ports[ahci_index].Sig == cAhciSig &&
+ det == cAhciPresent &&
+ ipm == cAhciIPMActive)
+ {
+ kcout << "Found AHCI controller.\r";
+ kcout << "Device is of SATA type.\r";
+
+ detected = true;
+
+ kAhciPort = &mem_ahci->Ports[ahci_index];
+
+ // start command engine.
+ // drv_start_ahci_engine();
+ }
+ }
+
+ ports_implemented >>= 1;
+ ahci_index++;
+ }
+
+ return detected;
+ }
+ }
+
+ return false;
+}
+
+Kernel::Boolean drv_std_detected(Kernel::Void)
+{
+ return kAhciDevice.DeviceId() != 0xFFFF;
+}
+
+Kernel::Void drv_std_read(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size)
+{
+}
+
+Kernel::Void drv_std_write(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size)
+{
+}
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+Kernel::SizeT drv_get_sector_count()
+{
+ return 0;
+}
+
+/// @brief Get the drive size.
+Kernel::SizeT drv_get_size()
+{
+ return 0;
+}
+#endif // __AHCI__
diff --git a/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cxx b/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cxx
new file mode 100644
index 00000000..49d10a7e
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cxx
@@ -0,0 +1,38 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file ATA-DMA.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief ATA driver (DMA mode).
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Technologies
+ *
+ */
+
+#include <StorageKit/PRDT.hxx>
+
+#include <Modules/ATA/ATA.hxx>
+#include <ArchKit/ArchKit.hxx>
+
+using namespace Kernel;
+
+EXTERN_C Int32 kPRDTTransferStatus;
+STATIC PRDT kPRDT;
+
+#ifdef __ATA_DMA__
+
+#ifdef __ATA_PIO__
+#error !!! You cant have both PIO and DMA enabled! !!!
+#endif /* ifdef __ATA_PIO__ */
+
+#ifdef __AHCI__
+#error !!! You cant have both ATA and AHCI enabled! !!!
+#endif /* ifdef __AHCI__ */
+
+#endif /* ifdef __ATA_DMA__ */
diff --git a/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx
new file mode 100644
index 00000000..e09a4277
--- /dev/null
+++ b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx
@@ -0,0 +1,199 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file ATA-PIO.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief ATA driver (PIO mode).
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Technologies
+ *
+ */
+
+#include <Modules/ATA/ATA.hxx>
+#include <ArchKit/ArchKit.hxx>
+
+#ifdef __ATA_PIO__
+
+using namespace Kernel;
+using namespace Kernel::HAL;
+
+/// bugs: 0
+
+#define kATADataLen 256
+
+STATIC Boolean kATADetected = false;
+STATIC Int32 kATADeviceType = kATADeviceCount;
+STATIC Char kATAData[kATADataLen] = {0};
+
+Boolean drv_std_wait_io(UInt16 IO)
+{
+ for (int i = 0; i < 400; i++)
+ In8(IO + ATA_REG_STATUS);
+
+ATAWaitForIO_Retry:
+ auto statRdy = In8(IO + ATA_REG_STATUS);
+
+ if ((statRdy & ATA_SR_BSY))
+ goto ATAWaitForIO_Retry;
+
+ATAWaitForIO_Retry2:
+ statRdy = In8(IO + ATA_REG_STATUS);
+
+ if (statRdy & ATA_SR_ERR)
+ return false;
+
+ if (!(statRdy & ATA_SR_DRDY))
+ goto ATAWaitForIO_Retry2;
+
+ return true;
+}
+
+Void drv_std_select(UInt16 Bus)
+{
+ if (Bus == ATA_PRIMARY_IO)
+ Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL);
+ else
+ Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL);
+}
+
+Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster)
+{
+ UInt16 IO = Bus;
+
+ drv_std_select(IO);
+
+ kcout << "Initializing drive...\r";
+
+ATAInit_Retry:
+ // Bus init, NEIN bit.
+ Out8(IO + ATA_REG_NEIN, 1);
+
+ // identify until it's good
+
+ auto statRdy = In8(IO + ATA_REG_STATUS);
+
+ if (statRdy & ATA_SR_ERR)
+ {
+ kcout << "Failing drive...\r";
+
+ return false;
+ }
+
+ if ((statRdy & ATA_SR_BSY))
+ {
+ kcout << "Retrying...";
+ goto ATAInit_Retry;
+ }
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
+
+ /// fetch serial info
+ /// model, speed, number of sectors...
+
+ drv_std_wait_io(IO);
+
+ for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData)
+ {
+ kATAData[indexData] = In16(IO + ATA_REG_DATA);
+ }
+
+ OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO;
+
+ OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE;
+
+ kcout << "Created IDE module.\r";
+
+ return true;
+}
+
+Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size)
+{
+ Lba /= SectorSz;
+
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
+
+ drv_std_wait_io(IO);
+ drv_std_select(IO);
+
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+
+ Out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
+
+ Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
+ Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
+
+ drv_std_wait_io(IO);
+
+ for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff)
+ {
+ drv_std_wait_io(IO);
+ Buf[IndexOff] = In16(IO + ATA_REG_DATA);
+ drv_std_wait_io(IO);
+ }
+
+ drv_std_wait_io(IO);
+}
+
+Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size)
+{
+ Lba /= SectorSz;
+
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
+
+ drv_std_wait_io(IO);
+ drv_std_select(IO);
+
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+
+ Out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz));
+
+ Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
+ Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
+
+ drv_std_wait_io(IO);
+
+ for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff)
+ {
+ drv_std_wait_io(IO);
+ Out16(IO + ATA_REG_DATA, Buf[IndexOff]);
+ drv_std_wait_io(IO);
+ }
+
+ drv_std_wait_io(IO);
+}
+
+/// @brief is ATA detected?
+Boolean drv_std_detected(Void)
+{
+ return kATADetected;
+}
+
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+Kernel::SizeT drv_get_sector_count()
+{
+ return (kATAData[61] << 16) | kATAData[60];
+}
+
+/// @brief Get the drive size.
+Kernel::SizeT drv_get_size()
+{
+ return drv_get_sector_count() * kATASectorSize;
+}
+
+#endif /* ifdef __ATA_PIO__ */
diff --git a/dev/zka/HALKit/ARM64/.gitkeep b/dev/zka/HALKit/ARM64/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/.gitkeep
diff --git a/dev/zka/HALKit/ARM64/APM/.gitkeep b/dev/zka/HALKit/ARM64/APM/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/APM/.gitkeep
diff --git a/dev/zka/HALKit/ARM64/HalKernelMain.cxx b/dev/zka/HALKit/ARM64/HalKernelMain.cxx
new file mode 100644
index 00000000..a1b75ccf
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/HalKernelMain.cxx
@@ -0,0 +1,68 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/FileMgr.hxx>
+#include <KernelKit/Framebuffer.hxx>
+#include <KernelKit/Heap.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <NewKit/Json.hxx>
+#include <Modules/CoreCG/Accessibility.hxx>
+#include <KernelKit/CodeMgr.hxx>
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <NetworkKit/IPC.hxx>
+#include <CFKit/Property.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+
+namespace Kernel::HAL
+{
+ /// @brief Gets the system cores using the MADT.
+ /// @param rsdPtr The 'RSD PTR' data structure.
+ EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr) noexcept;
+} // namespace Kernel::HAL
+
+Kernel::Void hal_real_init(Kernel::Void) noexcept;
+EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void);
+
+EXTERN_C void hal_init_platform(
+ Kernel::HEL::HANDOVER_INFO_HEADER* HandoverHeader)
+{
+ /* Setup globals. */
+
+ kHandoverHeader = HandoverHeader;
+
+ if (kHandoverHeader->f_Magic != kHandoverMagic &&
+ kHandoverHeader->f_Version != kHandoverVersion)
+ {
+ return;
+ }
+
+ CG::CGDrawBackground();
+
+ // get page size.
+ kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
+
+ // get virtual address start (for the heap)
+ kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
+ reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
+
+ if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
+ Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
+
+ kcout << "Creating filesystem and such.\r";
+
+ if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
+ Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
+
+ Kernel::NeFileSystemMgr::Mount(Kernel::mm_new_class<Kernel::NeFileSystemMgr>());
+
+ mp_do_user_switch();
+
+ Kernel::ke_stop(RUNTIME_CHECK_FAILED);
+}
diff --git a/dev/zka/HALKit/ARM64/HalPageInternal.S b/dev/zka/HALKit/ARM64/HalPageInternal.S
new file mode 100644
index 00000000..8fcf40ff
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/HalPageInternal.S
@@ -0,0 +1,5 @@
+.text
+
+hal_flush_tlb:
+ tlbi
+ ret
diff --git a/dev/zka/HALKit/ARM64/HalSchedulerCore.cxx b/dev/zka/HALKit/ARM64/HalSchedulerCore.cxx
new file mode 100644
index 00000000..7545b350
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/HalSchedulerCore.cxx
@@ -0,0 +1,48 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/UserProcessScheduler.hxx>
+
+using namespace Kernel;
+
+Void UserProcess::SetImageStart(UIntPtr& imageStart) noexcept
+{
+ if (imageStart == 0)
+ this->Crash();
+
+ this->StackFrame->BP = imageStart;
+ this->StackFrame->SP = this->StackFrame->BP;
+}
+
+namespace Kernel
+{
+ bool hal_check_stack(HAL::StackFramePtr stackPtr)
+ {
+ if (!stackPtr)
+ return false;
+ if (stackPtr->BP == 0 || stackPtr->SP == 0)
+ return false;
+
+ return true;
+ }
+
+ /// @brief Wakes up thread.
+ /// Wakes up thread from the hang state.
+ Void mp_wakeup_thread(HAL::StackFrame* stack)
+ {
+ ZKA_UNUSED(stack);
+ }
+
+ /// @brief makes the thread sleep on a loop.
+ /// hooks and hangs thread to prevent code from executing.
+ Void mp_hang_thread(HAL::StackFrame* stack)
+ {
+ while (Yes)
+ {
+ /* Nothing to do, code is spinning */
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/HALKit/ARM64/HalTimer.cxx b/dev/zka/HALKit/ARM64/HalTimer.cxx
new file mode 100644
index 00000000..4ef87227
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/HalTimer.cxx
@@ -0,0 +1,16 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: HalTimer.cxx
+ Purpose: HAL timer
+
+ Revision History:
+
+ 07/07/24: Added file (amlel)
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+
+struct TIMER_INFO;
diff --git a/dev/zka/HALKit/ARM64/MBCI/.keepme b/dev/zka/HALKit/ARM64/MBCI/.keepme
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/MBCI/.keepme
diff --git a/dev/zka/HALKit/ARM64/Paging.hxx b/dev/zka/HALKit/ARM64/Paging.hxx
new file mode 100644
index 00000000..7fe020ef
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/Paging.hxx
@@ -0,0 +1,120 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+/** ---------------------------------------------------
+
+ * THIS FILE CONTAINS CODE FOR ARMV8 PAGING.
+
+------------------------------------------------------- */
+
+#include <NewKit/Defines.hxx>
+
+#ifndef kPageMax
+#define kPageMax (0x200)
+#endif //! kPageMax
+
+#ifndef kPageAlign
+#define kPageAlign (0x1000)
+#endif //! kPageAlign
+
+#ifndef kPageSize
+#define kPageSize (0x1000)
+#endif // !kPageSize
+
+//! short format address range
+
+#define c16KBPage 0b000
+#define c8KBPage 0b001
+#define c4KBPage 0b010
+#define c2KBPage 0b011
+#define c1KBPage 0b100
+#define c512BPage 0b101
+#define c256BPage 0b110
+#define c128BPage 0b111
+
+/// Long format address range
+
+#define cPageMAll \
+ { \
+ 0b000, 0b000 \
+ }
+#define cPageMToMax(M) \
+ { \
+ M, 0b000 \
+ }
+#define cPageMaxToM(M) \
+ { \
+ 0b000, M \
+ }
+#define cPageMToN(M, N) \
+ { \
+ M, N \
+ }
+
+namespace Kernel::HAL
+{
+ struct PACKED PTE_4KB final
+ {
+ UInt64 Valid : 1;
+ UInt64 Table : 1;
+ UInt64 AttrIndex : 3;
+ UInt64 NS : 1;
+ UInt64 AP : 2;
+ UInt64 SH : 2;
+ UInt64 AF : 1;
+ UInt64 NG : 1;
+ UInt64 Reserved1 : 1;
+ UInt64 Contiguous : 1;
+ UInt64 Dirty : 1;
+ UInt64 Reserved : 2;
+ UInt64 PhysicalAddress : 36;
+ UInt64 Reserved3 : 4;
+ UInt64 PXN : 1;
+ UInt64 XN : 1;
+ UInt64 Reserved4 : 9;
+ };
+
+ 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 PDE_4KB final
+ {
+ PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax];
+ };
+
+ auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr;
+ auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
+} // namespace Kernel::HAL
+
+namespace Kernel
+{
+ typedef HAL::PTE_4KB PTE;
+ typedef HAL::PDE_4KB PDE;
+} // namespace Kernel
+
+EXTERN_C void hal_flush_tlb();
diff --git a/dev/zka/HALKit/ARM64/Processor.hxx b/dev/zka/HALKit/ARM64/Processor.hxx
new file mode 100644
index 00000000..533457a9
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/Processor.hxx
@@ -0,0 +1,50 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Utils.hxx>
+#include <FirmwareKit/Handover.hxx>
+
+#define kPageSize 512 /* 64-bit PT */
+
+#define kCPUBackendName "ARMv8"
+
+namespace Kernel::HAL
+{
+ struct PACKED Register64 final
+ {
+ UShort Limit;
+ UIntPtr Base;
+ };
+
+ typedef UIntPtr Reg;
+ typedef Register64 Register;
+
+ /// @note let's keep the same name as AMD64 HAL.
+ 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};
+ };
+
+ typedef StackFrame* StackFramePtr;
+} // namespace Kernel::HAL
+
+inline Kernel::VoidPtr kKernelBitMpStart = nullptr;
+inline Kernel::UIntPtr kKernelBitMpSize = 0UL;
+
+inline Kernel::VoidPtr kKernelPhysicalStart = nullptr;
+
+#include <HALKit/ARM64/Paging.hxx>
diff --git a/dev/zka/HALKit/ARM64/ReadMe.md b/dev/zka/HALKit/ARM64/ReadMe.md
new file mode 100644
index 00000000..c51229f2
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/ReadMe.md
@@ -0,0 +1,3 @@
+# ARM64 Hardware Abstraction Layer
+
+- Supported Firmware: CoreBoot/EDK/OpenMobileBoot
diff --git a/dev/zka/HALKit/ARM64/Storage/.gitkeep b/dev/zka/HALKit/ARM64/Storage/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/Storage/.gitkeep
diff --git a/dev/zka/HALKit/ARM64/Storage/HalFlash.cxx b/dev/zka/HALKit/ARM64/Storage/HalFlash.cxx
new file mode 100644
index 00000000..a479da93
--- /dev/null
+++ b/dev/zka/HALKit/ARM64/Storage/HalFlash.cxx
@@ -0,0 +1,66 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Defines.hxx>
+#include <ArchKit/ArchKit.hxx>
+
+/// @file Flash.cxx
+/// @brief Flash memory builtin.
+
+#ifdef __USE_MBCI_FLASH__
+
+#define cMaxFlash (4U)
+
+namespace Kernel
+{
+ /// /:\\BRIDGE\\FLSH\\1
+ constexpr auto cFlashBridgeMagic = "FLSH";
+ constexpr auto cFlashBridgeRevision = 1;
+
+ STATIC const Boolean kFlashEnabled = No;
+ STATIC SizeT kFlashSize[cMaxFlash] = {};
+ STATIC SizeT kFlashSectorSz[cMaxFlash] = {};
+
+ /// @brief Enable flash memory builtin.
+ STATIC Void drv_enable_flash(Int32 slot);
+
+ /// @brief Disable flash memory builtin.
+ STATIC Void drv_disable_flash(Int32 slot);
+
+ /// @brief get sector count.
+ /// @return drive sector count.
+ SizeT drv_get_sector_count(Int32 slot)
+ {
+ if (slot > cMaxFlash)
+ return 0;
+
+ return kFlashSectorSz[slot];
+ }
+
+ /// @brief get device size.
+ /// @return drive size
+ SizeT drv_get_size(Int32 slot)
+ {
+ if (slot > cMaxFlash)
+ return 0;
+
+ return kFlashSize[slot];
+ }
+
+ /// @brief Enable flash memory at slot.
+ STATIC Void drv_enable_flash(Int32 arg)
+ {
+ kcout << "Enabled FLSH hardware.\r";
+ }
+
+ /// @brief Disable flash memory at slot.
+ STATIC Void drv_disable_flash(Int32 arg)
+ {
+ kcout << "Disabled FLSH hardware.\r";
+ }
+} // namespace Kernel
+
+#endif // if __USE_MBCI_FLASH__ (Bridge)
diff --git a/dev/zka/HALKit/AXP/CR.s b/dev/zka/HALKit/AXP/CR.s
new file mode 100644
index 00000000..4d68257d
--- /dev/null
+++ b/dev/zka/HALKit/AXP/CR.s
@@ -0,0 +1,11 @@
+.globl read_lr1
+.globl read_lr0
+
+.section .text
+ read_lr0:
+ movq %r30, %cr3
+ ret
+
+ hal_read_cr0:
+ movq %r30, %cr0
+ ret \ No newline at end of file
diff --git a/dev/zka/HALKit/AXP/CoreInterruptHandlerDEC.cpp b/dev/zka/HALKit/AXP/CoreInterruptHandlerDEC.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/AXP/CoreInterruptHandlerDEC.cpp
diff --git a/dev/zka/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/dev/zka/HALKit/AXP/CoreSyscallHandlerDEC.cpp
new file mode 100644
index 00000000..254e1ab6
--- /dev/null
+++ b/dev/zka/HALKit/AXP/CoreSyscallHandlerDEC.cpp
@@ -0,0 +1,24 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <HALKit/AXP/Processor.hxx>
+
+/// @brief Internal call for syscall, to work with C++.
+/// @param stack
+/// @return nothing.
+EXTERN_C void rt_syscall_handle(Kernel::HAL::StackFrame* stack)
+{
+ if (stack->Rcx <= (kSyscalls.Count() - 1))
+ {
+ kcout << "syscall: enter.\r";
+
+ if (kSyscalls[stack->Rcx].Leak().Leak().fHooked)
+ (kSyscalls[stack->Rcx].Leak().Leak().fProc)(stack);
+
+ kcout << "syscall: exit.\r";
+ }
+}
diff --git a/dev/zka/HALKit/AXP/HAL.s b/dev/zka/HALKit/AXP/HAL.s
new file mode 100644
index 00000000..0178527f
--- /dev/null
+++ b/dev/zka/HALKit/AXP/HAL.s
@@ -0,0 +1,13 @@
+.globl rt_wait_400ns
+
+.section .text
+rt_wait_400ns:
+ jmp .L
+.L:
+ jmp .L2
+ wtint ;; wait for interrupt
+.L2:
+
+ ret
+
+
diff --git a/dev/zka/HALKit/AXP/Processor.hxx b/dev/zka/HALKit/AXP/Processor.hxx
new file mode 100644
index 00000000..25a434a0
--- /dev/null
+++ b/dev/zka/HALKit/AXP/Processor.hxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once \ No newline at end of file
diff --git a/dev/zka/HALKit/AXP/README b/dev/zka/HALKit/AXP/README
new file mode 100644
index 00000000..91e7b134
--- /dev/null
+++ b/dev/zka/HALKit/AXP/README
@@ -0,0 +1 @@
+This is for DEC Alpha.
diff --git a/dev/zka/HALKit/AXP/README.TXT b/dev/zka/HALKit/AXP/README.TXT
new file mode 100644
index 00000000..11e138f9
--- /dev/null
+++ b/dev/zka/HALKit/AXP/README.TXT
@@ -0,0 +1 @@
+An toy HAL to test the Kernel portability.
diff --git a/dev/zka/HALKit/AXP/SYSCALL.s b/dev/zka/HALKit/AXP/SYSCALL.s
new file mode 100644
index 00000000..19cab808
--- /dev/null
+++ b/dev/zka/HALKit/AXP/SYSCALL.s
@@ -0,0 +1,10 @@
+.section .text
+system_handle_user_call:
+ .cfi_startproc
+
+ push %r0
+ jmp %r1
+ mov %r30, %r2
+
+ .cfi_endproc
+ retsys \ No newline at end of file
diff --git a/dev/zka/HALKit/AXP/VM.s b/dev/zka/HALKit/AXP/VM.s
new file mode 100644
index 00000000..7024086b
--- /dev/null
+++ b/dev/zka/HALKit/AXP/VM.s
@@ -0,0 +1,5 @@
+.global hal_flush_tlb
+
+.section .text
+hal_flush_tlb:
+ swppal \ No newline at end of file
diff --git a/dev/zka/HALKit/POWER/.gitkeep b/dev/zka/HALKit/POWER/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/POWER/.gitkeep
diff --git a/dev/zka/HALKit/POWER/APM/.gitkeep b/dev/zka/HALKit/POWER/APM/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/POWER/APM/.gitkeep
diff --git a/dev/zka/HALKit/POWER/HalContextSwitchPowerPC.s b/dev/zka/HALKit/POWER/HalContextSwitchPowerPC.s
new file mode 100644
index 00000000..588de23a
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalContextSwitchPowerPC.s
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+.align 4
+.type name, @function
+.text
+.globl mp_do_user_switch
+
+/* r3 (3) = assigner stack, r4 (4) = assignee stack */
+mp_do_user_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/zka/HALKit/POWER/HalHart.cxx b/dev/zka/HALKit/POWER/HalHart.cxx
new file mode 100644
index 00000000..ce27ddad
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalHart.cxx
@@ -0,0 +1,25 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <HALKit/POWER/Hart.hxx>
+
+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/zka/HALKit/POWER/HalSerialPort.cxx b/dev/zka/HALKit/POWER/HalSerialPort.cxx
new file mode 100644
index 00000000..c8d49c0c
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalSerialPort.cxx
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+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/zka/HALKit/POWER/HalStartSequence.s b/dev/zka/HALKit/POWER/HalStartSequence.s
new file mode 100644
index 00000000..68110f8d
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalStartSequence.s
@@ -0,0 +1,14 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+.globl __ImageStart
+.extern hal_init_platform
+.align 4
+.text
+
+__ImageStart:
+ bl hal_init_platform
+ blr
diff --git a/dev/zka/HALKit/POWER/HalThread.cxx b/dev/zka/HALKit/POWER/HalThread.cxx
new file mode 100644
index 00000000..3e2f1703
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalThread.cxx
@@ -0,0 +1,8 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
diff --git a/dev/zka/HALKit/POWER/HalVirtualMemory.cxx b/dev/zka/HALKit/POWER/HalVirtualMemory.cxx
new file mode 100644
index 00000000..589c2cda
--- /dev/null
+++ b/dev/zka/HALKit/POWER/HalVirtualMemory.cxx
@@ -0,0 +1,51 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/ppc-cpu.h>
+#include <HALKit/POWER/ppc-mmu.h>
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+/// @note refer to the SoC documentation.
+
+using namespace Kernel;
+
+Void hal_write_tlb(UInt32 mas0, UInt32 mas1, UInt32 mas2, UInt32 mas3, UInt32 mas7)
+{
+ mtspr(MAS0, mas0);
+ mtspr(MAS1, mas1);
+ mtspr(MAS2, mas2);
+ mtspr(MAS3, mas3);
+ mtspr(MAS7, mas7);
+
+ hal_flush_tlb();
+}
+
+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 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/zka/HALKit/POWER/Hart.hxx b/dev/zka/HALKit/POWER/Hart.hxx
new file mode 100644
index 00000000..02020320
--- /dev/null
+++ b/dev/zka/HALKit/POWER/Hart.hxx
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Hart.hxx
+ Purpose: POWER hardware threads.
+
+ Revision History:
+
+ 14/04/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+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 fPageFlags;
+ 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/zka/HALKit/POWER/MBCI/.gitkeep b/dev/zka/HALKit/POWER/MBCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/POWER/MBCI/.gitkeep
diff --git a/dev/zka/HALKit/POWER/MBCI/HalMBCIHost.cxx b/dev/zka/HALKit/POWER/MBCI/HalMBCIHost.cxx
new file mode 100644
index 00000000..3e2f1703
--- /dev/null
+++ b/dev/zka/HALKit/POWER/MBCI/HalMBCIHost.cxx
@@ -0,0 +1,8 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <HALKit/POWER/Processor.hxx>
+#include <KernelKit/DebugOutput.hxx>
diff --git a/dev/zka/HALKit/POWER/Processor.hxx b/dev/zka/HALKit/POWER/Processor.hxx
new file mode 100644
index 00000000..75922d88
--- /dev/null
+++ b/dev/zka/HALKit/POWER/Processor.hxx
@@ -0,0 +1,60 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ Purpose: POWER processor header.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Utils.hxx>
+
+#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};
+ };
+
+ 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/zka/HALKit/POWER/ReadMe.md b/dev/zka/HALKit/POWER/ReadMe.md
new file mode 100644
index 00000000..a9751581
--- /dev/null
+++ b/dev/zka/HALKit/POWER/ReadMe.md
@@ -0,0 +1,4 @@
+POWER Hardware Abstraction Layer
+
+- Supported CPU: POWER
+- Supported Firmware: CoreBoot \ No newline at end of file
diff --git a/dev/zka/HALKit/RISCV/.keep b/dev/zka/HALKit/RISCV/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/RISCV/.keep
diff --git a/dev/zka/HALKit/RISCV/APM/.gitkeep b/dev/zka/HALKit/RISCV/APM/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/RISCV/APM/.gitkeep
diff --git a/dev/zka/HALKit/RISCV/Hart.hxx b/dev/zka/HALKit/RISCV/Hart.hxx
new file mode 100644
index 00000000..0f5e021e
--- /dev/null
+++ b/dev/zka/HALKit/RISCV/Hart.hxx
@@ -0,0 +1,24 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Hart.hxx
+ Purpose: RISC-V hardware threads.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+typedef Kernel::Int32 Rv64HartType;
+
+/// @brief Set PC to specific hart.
+/// @param hart the hart
+/// @param epc the pc.
+/// @return
+EXTERN_C Kernel::Void hal_set_pc_to_hart(Rv64HartType hart, Kernel::VoidPtr epc);
diff --git a/dev/zka/HALKit/RISCV/ReadMe.md b/dev/zka/HALKit/RISCV/ReadMe.md
new file mode 100644
index 00000000..b099aa31
--- /dev/null
+++ b/dev/zka/HALKit/RISCV/ReadMe.md
@@ -0,0 +1,4 @@
+RISCV64 Hardware Abstraction Layer
+
+- Supported CPU: RISCV64
+- Supported Firmware: CoreBoot \ No newline at end of file
diff --git a/dev/zka/HALKit/RISCV/Storage/.gitkeep b/dev/zka/HALKit/RISCV/Storage/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/RISCV/Storage/.gitkeep
diff --git a/dev/zka/HALKit/X86S/.gitkeep b/dev/zka/HALKit/X86S/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/X86S/.gitkeep
diff --git a/dev/zka/HALKit/X86S/ACPI/.gitkeep b/dev/zka/HALKit/X86S/ACPI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/X86S/ACPI/.gitkeep
diff --git a/dev/zka/HALKit/X86S/Storage/.gitkeep b/dev/zka/HALKit/X86S/Storage/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/HALKit/X86S/Storage/.gitkeep
diff --git a/dev/zka/HintKit/CompilerHint.hxx b/dev/zka/HintKit/CompilerHint.hxx
new file mode 100644
index 00000000..f0316b50
--- /dev/null
+++ b/dev/zka/HintKit/CompilerHint.hxx
@@ -0,0 +1,23 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __HINTKIT_COMPILER_HINT_HXX__
+#define __HINTKIT_COMPILER_HINT_HXX__
+
+#pragma compiler(hint_manifest)
+
+#define _Input
+#define _Output
+
+#define _Optional
+
+#define _StrictCheckInput
+#define _StrictCheckOutput
+
+#define _InOut
+#define _StrictInOut
+
+#endif // ifndef __HINTKIT_COMPILER_HINT_HXX__
diff --git a/dev/zka/KernelKit/CodeMgr.hxx b/dev/zka/KernelKit/CodeMgr.hxx
new file mode 100644
index 00000000..c8f9cca9
--- /dev/null
+++ b/dev/zka/KernelKit/CodeMgr.hxx
@@ -0,0 +1,31 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: CodeMgr.hpp
+ Purpose: Code Mgr and Shared Objects.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+ 3/8/24: Add UPP struct.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/PECodeMgr.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
+
+namespace Kernel
+{
+ /// @brief Main process entrypoint.
+ typedef void (*MainKind)(void);
+
+ /// @brief Executes a new process from a function. Kernel code only.
+ /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible.
+ /// @param main the start of the process.
+ /// @return if the process was started or not.
+ bool sched_execute_thread(MainKind main, const Char* process_name) noexcept;
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/DebugOutput.hxx b/dev/zka/KernelKit/DebugOutput.hxx
new file mode 100644
index 00000000..162e2ed4
--- /dev/null
+++ b/dev/zka/KernelKit/DebugOutput.hxx
@@ -0,0 +1,196 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/OwnPtr.hxx>
+#include <NewKit/Stream.hxx>
+
+#define kDebugMaxPorts 16
+
+#define kDebugUnboundPort 0x0FEED
+
+#define kDebugMag0 'N'
+#define kDebugMag1 'D'
+#define kDebugMag2 'B'
+#define kDebugMag3 'G'
+
+#define kDebugSourceFile 0
+#define kDebugLine 33
+#define kDebugTeam 43
+#define kDebugEOP 49
+
+namespace Kernel
+{
+ class TerminalDevice;
+
+ inline TerminalDevice end_line();
+ inline TerminalDevice number(const Long& x);
+ inline TerminalDevice hex_number(const Long& x);
+
+ // @brief Emulates a VT100 terminal.
+ class TerminalDevice final : public DeviceInterface<const Char*>
+ {
+ public:
+ TerminalDevice(void (*print)(const Char*), void (*get)(const Char*))
+ : DeviceInterface<const Char*>(print, get)
+ {
+ }
+
+ virtual ~TerminalDevice() = default;
+
+ /// @brief returns device name (terminal name)
+ /// @return string type (const Char*)
+ virtual const Char* Name() const override
+ {
+ return ("TerminalDevice");
+ }
+
+ ZKA_COPY_DEFAULT(TerminalDevice);
+
+ STATIC TerminalDevice The() noexcept;
+ };
+
+ inline TerminalDevice end_line()
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ selfTerm.operator<<("\r");
+ return selfTerm;
+ }
+
+ inline TerminalDevice carriage_return()
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ selfTerm.operator<<("\r");
+ return selfTerm;
+ }
+
+ inline TerminalDevice tabulate()
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ selfTerm.operator<<("\t");
+ return selfTerm;
+ }
+
+ /// @brief emulate a terminal bell, like the VT100 does.
+ inline TerminalDevice bell()
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ selfTerm.operator<<("\a");
+ return selfTerm;
+ }
+
+ namespace Detail
+ {
+ inline TerminalDevice _write_number(const Long& x, TerminalDevice& term)
+ {
+ UInt64 y = (x > 0 ? x : -x) / 10;
+ UInt64 h = (x > 0 ? x : -x) % 10;
+
+ if (y)
+ _write_number(y, term);
+
+ /* fail if the number is not base-10 */
+ if (h > 10)
+ {
+ _write_number('?', term);
+ return term;
+ }
+
+ if (y < 0)
+ y = -y;
+
+ const Char cNumbers[11] = "0123456789";
+
+ Char buf[2];
+ buf[0] = cNumbers[h];
+ buf[1] = 0;
+
+ term.operator<<(buf);
+ return term;
+ }
+
+ inline TerminalDevice _write_number_hex(const Long& x, TerminalDevice& term)
+ {
+ UInt64 y = (x > 0 ? x : -x) / 16;
+ UInt64 h = (x > 0 ? x : -x) % 16;
+
+ if (y)
+ _write_number_hex(y, term);
+
+ /* fail if the hex number is not base-16 */
+ if (h > 15)
+ {
+ _write_number_hex('?', term);
+ return term;
+ }
+
+ if (y < 0)
+ y = -y;
+
+ const Char cNumbers[17] = "0123456789ABCDEF";
+
+ Char buf[2];
+ buf[0] = cNumbers[h];
+ buf[1] = 0;
+
+ term.operator<<(buf);
+ return term;
+ }
+ } // namespace Detail
+
+ inline TerminalDevice hex_number(const Long& x)
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ Detail::_write_number_hex(x, selfTerm);
+ selfTerm.operator<<("h");
+
+ return selfTerm;
+ }
+
+ inline TerminalDevice number(const Long& x)
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ Detail::_write_number(x, selfTerm);
+
+ return selfTerm;
+ }
+
+ inline TerminalDevice get_console_in(Char* buf)
+ {
+ TerminalDevice selfTerm = TerminalDevice::The();
+
+ selfTerm >> buf;
+
+ return selfTerm;
+ }
+
+ typedef Char rt_debug_type[255];
+
+ class DebuggerPortHeader final
+ {
+ public:
+ Int16 fPort[kDebugMaxPorts];
+ Int16 fBoundCnt;
+ };
+} // namespace Kernel
+
+#ifdef kcout
+#undef kcout
+#endif // ifdef kcout
+
+#define kcout \
+ (Kernel::TerminalDevice::The() << "\e[0;31m [ " << __FILE__ << ": LINE: " << Kernel::number(__LINE__)); \
+ (Kernel::TerminalDevice::The() << " ] \e[0m" << ": ")
+#define endl Kernel::TerminalDevice::The() << Kernel::end_line()
diff --git a/dev/zka/KernelKit/Defines.hxx b/dev/zka/KernelKit/Defines.hxx
new file mode 100644
index 00000000..e76b1b2f
--- /dev/null
+++ b/dev/zka/KernelKit/Defines.hxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define KERNELKIT_VERSION "1.02"
diff --git a/dev/zka/KernelKit/DeviceMgr.hxx b/dev/zka/KernelKit/DeviceMgr.hxx
new file mode 100644
index 00000000..473af601
--- /dev/null
+++ b/dev/zka/KernelKit/DeviceMgr.hxx
@@ -0,0 +1,132 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/* -------------------------------------------
+
+ Revision History:
+
+ 31/01/24: Add kDeviceCnt (amlel)
+
+ ------------------------------------------- */
+
+#pragma once
+
+/* Device manager. */
+/* @file KernelKit/DeviceMgr.hpp */
+/* @brief Device abstraction and I/O buffer. */
+
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Ref.hxx>
+
+#define cDevicePath "\\Mount\\"
+
+// Last Rev
+// Wed, Apr 3, 2024 9:09:41 AM
+
+namespace Kernel
+{
+ template <typename T>
+ class DeviceInterface;
+
+ template <typename T>
+ class DeviceInterface
+ {
+ public:
+ explicit DeviceInterface(void (*Out)(T), void (*In)(T))
+ : fOut(Out), fIn(In)
+ {
+ }
+
+ virtual ~DeviceInterface() = default;
+
+ public:
+ DeviceInterface& operator=(const DeviceInterface<T>&) = default;
+ DeviceInterface(const DeviceInterface<T>&) = default;
+
+ public:
+ virtual DeviceInterface<T>& operator<<(T Data)
+ {
+ fOut(Data);
+ return *this;
+ }
+
+ virtual DeviceInterface<T>& operator>>(T Data)
+ {
+ fIn(Data);
+ return *this;
+ }
+
+ virtual const char* Name() const
+ {
+ return "DeviceInterface";
+ }
+
+ operator bool()
+ {
+ return fOut && fIn;
+ }
+
+ Bool operator!()
+ {
+ return !fOut || !fIn;
+ }
+
+ private:
+ Void (*fOut)(T Data) = {nullptr};
+ Void (*fIn)(T Data) = {nullptr};
+ };
+
+ ///
+ /// @brief Input Output Buffer
+ /// Used mainly to communicate between hardware.
+ ///
+ template <typename T>
+ class IOBuf final
+ {
+ public:
+ explicit IOBuf(T Dat)
+ : fData(Dat)
+ {
+ // at least pass something valid when instancating this struct.
+ MUST_PASS(Dat);
+ }
+
+ IOBuf& operator=(const IOBuf<T>&) = default;
+ IOBuf(const IOBuf<T>&) = default;
+
+ ~IOBuf() = default;
+
+ public:
+ template <typename R>
+ R operator->() const
+ {
+ return fData;
+ }
+
+ template <typename R>
+ R& operator[](Size index) const
+ {
+ return fData[index];
+ }
+
+ private:
+ T fData;
+ };
+
+ ///! @brief Device enum types.
+ enum
+ {
+ kDeviceTypeIDE,
+ kDeviceTypeEthernet,
+ kDeviceTypeWiFi,
+ kDeviceTypeRS232,
+ kDeviceTypeSCSI,
+ kDeviceTypeSHCI,
+ kDeviceTypeUSB,
+ kDeviceTypeMedia,
+ kDeviceTypeCount,
+ };
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/DriveMgr.hxx b/dev/zka/KernelKit/DriveMgr.hxx
new file mode 100644
index 00000000..e2e0bc3a
--- /dev/null
+++ b/dev/zka/KernelKit/DriveMgr.hxx
@@ -0,0 +1,152 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __INC_DRIVE_MANAGER_HXX__
+#define __INC_DRIVE_MANAGER_HXX__
+
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/DeviceMgr.hxx>
+#include <KernelKit/LPC.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+
+#define kDriveMgrCount (4U)
+
+#define kDriveInvalidID (-1)
+#define kDriveNameLen (32)
+
+#define DrvSectorCnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ))
+
+namespace Kernel
+{
+ enum
+ {
+ kInvalidDrive = -1,
+ kBlockDevice = 0xAD,
+ kMassStorage = 0xDA,
+ kFloppyDisc = 0xCD,
+ kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray
+ /// combine with below.
+ kReadOnly = 0x10, // Read only drive
+ kEPMDrive = 0x11, // Explicit Partition Map.
+ kEPTDrive = 0x12, // ESP w/ EPM partition.
+ kMBRDrive = 0x13, // IBM PC classic partition scheme
+ kDriveCnt = 9,
+ };
+
+ typedef Int64 rt_drive_id_type;
+
+ /// @brief Media drive trait type.
+ struct DriveTrait final
+ {
+ Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB...
+ Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc.
+ rt_drive_id_type fId; // Drive id.
+ Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive
+
+ /// @brief Packet drive (StorageKit compilant.)
+ struct DrivePacket final
+ {
+ VoidPtr fPacketContent; //! packet body.
+ Char fPacketMime[kDriveNameLen]; //! identify what we're sending.
+ SizeT fPacketSize; //! packet size
+ UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false
+ Boolean fPacketGood;
+ Lba fLba;
+ } fPacket;
+
+ Void (*fInput)(DrivePacket* packetPtr);
+ Void (*fOutput)(DrivePacket* packetPtr);
+ Void (*fVerify)(DrivePacket* packetPtr);
+ Void (*fInit)(DrivePacket* packetPtr);
+ const Char* (*fDriveKind)(Void);
+ };
+
+ ///! drive as a device.
+ typedef DriveTrait* DriveTraitPtr;
+
+ /**
+ * @brief Mounted drives interface.
+ * @note This class has all of it's drive set to nullptr, allocate them using
+ * GetAddressOf(index).
+ */
+ class MountpointInterface final
+ {
+ public:
+ explicit MountpointInterface() = default;
+ ~MountpointInterface() = default;
+
+ ZKA_COPY_DEFAULT(MountpointInterface);
+
+ public:
+ DriveTrait& A()
+ {
+ return mA;
+ }
+ DriveTrait& B()
+ {
+ return mB;
+ }
+ DriveTrait& C()
+ {
+ return mC;
+ }
+ DriveTrait& D()
+ {
+ return mD;
+ }
+
+ DriveTraitPtr GetAddressOf(Int32 index)
+ {
+ ErrLocal() = kErrorSuccess;
+
+ switch (index)
+ {
+ case 0:
+ return &mA;
+ case 1:
+ return &mB;
+ case 2:
+ return &mC;
+ case 3:
+ return &mD;
+ default: {
+ ErrLocal() = kErrorNoSuchDisk;
+ kcout << "No such disk.\n";
+
+ break;
+ }
+ }
+
+ return nullptr;
+ }
+
+ private:
+ DriveTrait mA, mB, mC, mD;
+ };
+
+ /// @brief Unimplemented drive.
+ /// @param pckt
+ /// @return
+ Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt);
+
+ /// @brief Gets the drive kind (ATA, SCSI, AHCI...)
+ /// @param
+ /// @return the drive kind (ATA, Flash, NVM)
+ const Char* io_drive_kind(Void);
+
+ /// @brief Makes a new drive.
+ /// @return the new drive as a trait.
+ DriveTrait io_construct_drive(void) noexcept;
+
+ /// @brief Fetches the main drive.
+ /// @return the new drive as a trait.
+ DriveTrait io_construct_main_drive(void) noexcept;
+} // namespace Kernel
+
+#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */
diff --git a/dev/zka/KernelKit/FileMgr.hxx b/dev/zka/KernelKit/FileMgr.hxx
new file mode 100644
index 00000000..cd557485
--- /dev/null
+++ b/dev/zka/KernelKit/FileMgr.hxx
@@ -0,0 +1,420 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: FileMgr.hxx
+ Purpose: Kernel file manager.
+
+------------------------------------------- */
+
+/* -------------------------------------------
+
+ Revision History:
+
+ 31/01/24: Update documentation (amlel)
+ 05/07/24: NeFS support, and fork support, updated constants and specs
+ as well.
+
+ ------------------------------------------- */
+
+#pragma once
+
+#ifdef __FSKIT_USE_NEFS__
+#include <FSKit/NeFS.hxx>
+#endif // __FSKIT_USE_NEFS__
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <HintKit/CompilerHint.hxx>
+#include <KernelKit/LPC.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/Stream.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <KernelKit/Heap.hxx>
+#include <NewKit/Ref.hxx>
+
+/// @brief Filesystem manager, abstraction over mounted filesystem.
+/// Works like the VFS or IFS.
+
+#define cRestrictR "r"
+#define cRestrictRB "rb"
+#define cRestrictW "w"
+#define cRestrictWB "rw"
+#define cRestrictRWB "rwb"
+
+#define cRestrictMax 5
+
+#define node_cast(PTR) reinterpret_cast<Kernel::NodePtr>(PTR)
+
+/**
+ @note Refer to first enum.
+*/
+#define cFileOpsCount 4
+#define cFileMimeGeneric "n-application-kind/all"
+
+/** @brief invalid position. (n-pos) */
+#define kNPos (SizeT)(-1);
+
+namespace Kernel
+{
+ enum
+ {
+ cFileWriteAll = 100,
+ cFileReadAll = 101,
+ cFileReadChunk = 102,
+ cFileWriteChunk = 103,
+ cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1,
+ // file flags
+ cFileFlagRsrc = 104,
+ cFileFlagData = 105,
+ };
+
+ typedef VoidPtr NodePtr;
+
+ /**
+ @brief Filesystem Mgr Interface class
+ @brief Used to provide common I/O for a specific filesystem.
+*/
+ class IFilesystemMgr
+ {
+ public:
+ explicit IFilesystemMgr() = default;
+ virtual ~IFilesystemMgr() = default;
+
+ public:
+ ZKA_COPY_DEFAULT(IFilesystemMgr);
+
+ public:
+ /// @brief Mounts a new filesystem into an active state.
+ /// @param interface the filesystem interface
+ /// @return
+ static bool Mount(IFilesystemMgr* interface);
+
+ /// @brief Unmounts the active filesystem
+ /// @return
+ static IFilesystemMgr* Unmount();
+
+ /// @brief Getter, gets the active filesystem.
+ /// @return
+ static IFilesystemMgr* GetMounted();
+
+ public:
+ virtual NodePtr Create(_Input const Char* path) = 0;
+ virtual NodePtr CreateAlias(_Input const Char* path) = 0;
+ virtual NodePtr CreateDirectory(_Input const Char* path) = 0;
+ virtual NodePtr CreateSwapFile(const Char* path) = 0;
+
+ public:
+ virtual bool Remove(_Input const Char* path) = 0;
+
+ public:
+ virtual NodePtr Open(_Input const Char* path, _Input const Char* r) = 0;
+
+ public:
+ virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0;
+
+ virtual _Output VoidPtr Read(_Input NodePtr node,
+ _Input Int32 flags,
+ _Input SizeT sz) = 0;
+
+ virtual Void Write(_Input const Char* name,
+ _Input NodePtr node,
+ _Input VoidPtr data,
+ _Input Int32 flags,
+ _Input SizeT size) = 0;
+
+ virtual _Output VoidPtr Read(_Input const Char* name,
+ _Input NodePtr node,
+ _Input Int32 flags,
+ _Input SizeT sz) = 0;
+
+ public:
+ virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0;
+
+ public:
+ virtual SizeT Tell(_Input NodePtr node) = 0;
+ virtual bool Rewind(_Input NodePtr node) = 0;
+ };
+
+#ifdef __FSKIT_USE_NEFS__
+ /**
+ * @brief Based of IFilesystemMgr, takes care of managing NeFS
+ * disks.
+ */
+ class NeFileSystemMgr final : public IFilesystemMgr
+ {
+ public:
+ explicit NeFileSystemMgr();
+ ~NeFileSystemMgr() override;
+
+ public:
+ ZKA_COPY_DEFAULT(NeFileSystemMgr);
+
+ public:
+ NodePtr Create(const Char* path) override;
+ NodePtr CreateAlias(const Char* path) override;
+ NodePtr CreateDirectory(const Char* path) override;
+ NodePtr CreateSwapFile(const Char* path) override;
+
+ public:
+ bool Remove(_Input const Char* path) override;
+ NodePtr Open(_Input const Char* path, _Input const Char* r) override;
+ Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT sz) override;
+ VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) override;
+ bool Seek(_Input NodePtr node, _Input SizeT off) override;
+ SizeT Tell(_Input NodePtr node) override;
+ bool Rewind(_Input NodePtr node) override;
+
+ Void Write(_Input const Char* name,
+ _Input NodePtr node,
+ _Input VoidPtr data,
+ _Input Int32 flags,
+ _Input SizeT size) override;
+
+ _Output VoidPtr Read(_Input const Char* name,
+ _Input NodePtr node,
+ _Input Int32 flags,
+ _Input SizeT sz) override;
+
+ public:
+ /// @brief Get NeFS parser class.
+ /// @return The filesystem parser class.
+ NeFSParser* GetParser() noexcept;
+
+ private:
+ NeFSParser* fImpl{nullptr};
+ };
+
+#endif // ifdef __FSKIT_USE_NEFS__
+
+ /**
+ * Usable FileStream
+ * @tparam Encoding file encoding (char, wchar_t...)
+ * @tparam FSClass Filesystem contract who takes care of it.
+ */
+ template <typename Encoding = Char,
+ typename FSClass = IFilesystemMgr>
+ class FileStream final
+ {
+ public:
+ explicit FileStream(const Encoding* path, const Encoding* restrict_type);
+ ~FileStream();
+
+ public:
+ FileStream& operator=(const FileStream&);
+ FileStream(const FileStream&);
+
+ public:
+ ErrorOr<Int64> WriteAll(const VoidPtr data) noexcept
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictWrite &&
+ this->fFileRestrict != eRestrictWriteBinary)
+ return ErrorOr<Int64>(kErrorInvalidData);
+
+ if (data == nullptr)
+ return ErrorOr<Int64>(kErrorInvalidData);
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ man->Write(fFile, data, cFileWriteAll);
+ return ErrorOr<Int64>(0);
+ }
+
+ return ErrorOr<Int64>(kErrorInvalidData);
+ }
+
+ VoidPtr ReadAll() noexcept
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictRead &&
+ this->fFileRestrict != eRestrictReadBinary)
+ return nullptr;
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ VoidPtr ret = man->Read(fFile, cFileReadAll, 0);
+ return ret;
+ }
+
+ return nullptr;
+ }
+
+ ErrorOr<Int64> WriteAll(const Char* fName, const VoidPtr data) noexcept
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictWrite &&
+ this->fFileRestrict != eRestrictWriteBinary)
+ return ErrorOr<Int64>(kErrorInvalidData);
+
+ if (data == nullptr)
+ return ErrorOr<Int64>(kErrorInvalidData);
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ man->Write(fName, fFile, data, cFileWriteAll);
+ return ErrorOr<Int64>(0);
+ }
+
+ return ErrorOr<Int64>(kErrorInvalidData);
+ }
+
+ VoidPtr Read(const Char* fName) noexcept
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictRead &&
+ this->fFileRestrict != eRestrictReadBinary)
+ return nullptr;
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0);
+ return ret;
+ }
+
+ return nullptr;
+ }
+
+ VoidPtr Read(SizeT offset, SizeT sz)
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictRead &&
+ this->fFileRestrict != eRestrictReadBinary)
+ return nullptr;
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ man->Seek(fFile, offset);
+ auto ret = man->Read(fFile, cFileReadChunk, sz);
+
+ return ret;
+ }
+
+ return nullptr;
+ }
+
+ Void Write(SizeT offset, voidPtr data, SizeT sz)
+ {
+ if (this->fFileRestrict != eRestrictReadWrite &&
+ this->fFileRestrict != eRestrictReadWriteBinary &&
+ this->fFileRestrict != eRestrictWrite &&
+ this->fFileRestrict != eRestrictWriteBinary)
+ return;
+
+ auto man = FSClass::GetMounted();
+
+ if (man)
+ {
+ man->Seek(fFile, offset);
+ man->Write(fFile, data, sz, cFileReadChunk);
+ }
+ }
+
+ public:
+ /// @brief Leak node pointer.
+ /// @return The node pointer.
+ NodePtr Leak()
+ {
+ return fFile;
+ }
+
+ /// @brief Leak MIME.
+ /// @return The MIME.
+ Char* MIME() noexcept
+ {
+ return const_cast<char*>(fMime);
+ }
+
+ enum
+ {
+ eRestrictRead,
+ eRestrictReadBinary,
+ eRestrictWrite,
+ eRestrictWriteBinary,
+ eRestrictReadWrite,
+ eRestrictReadWriteBinary,
+ };
+
+ private:
+ NodePtr fFile{nullptr};
+ Int32 fFileRestrict{};
+ const Char* fMime{cFileMimeGeneric};
+ };
+
+ using FileStreamUTF8 = FileStream<Char>;
+ using FileStreamUTF16 = FileStream<WideChar>;
+
+ typedef UInt64 CursorType;
+
+ /// @brief constructor
+ template <typename Encoding, typename Class>
+ FileStream<Encoding, Class>::FileStream(const Encoding* path,
+ const Encoding* restrict_type)
+ : fFile(Class::GetMounted()->Open(path, restrict_type))
+ {
+ static const auto cLength = 255;
+
+ /// @brief restrict information about the file descriptor.
+ struct RESTRICT_MAP final
+ {
+ Char fRestrict[cLength];
+ Int32 fMappedTo;
+ };
+
+ const SizeT cRestrictCount = cRestrictMax;
+ const RESTRICT_MAP cRestrictList[] = {
+ {
+ .fRestrict = cRestrictR,
+ .fMappedTo = eRestrictRead,
+ },
+ {
+ .fRestrict = cRestrictRB,
+ .fMappedTo = eRestrictReadBinary,
+ },
+ {
+ .fRestrict = cRestrictRWB,
+ .fMappedTo = eRestrictReadWriteBinary,
+ },
+ {
+ .fRestrict = cRestrictW,
+ .fMappedTo = eRestrictWrite,
+ },
+ {
+ .fRestrict = cRestrictWB,
+ .fMappedTo = eRestrictReadWrite,
+ }};
+
+ for (SizeT index = 0; index < cRestrictCount; ++index)
+ {
+ if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict,
+ rt_string_len(cRestrictList[index].fRestrict)) == 0)
+ {
+ fFileRestrict = cRestrictList[index].fMappedTo;
+ break;
+ }
+ }
+
+ kcout << "new file: " << path << ".\r";
+ }
+
+ /// @brief destructor
+ template <typename Encoding, typename Class>
+ FileStream<Encoding, Class>::~FileStream()
+ {
+ mm_delete_heap(fFile);
+ }
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/Framebuffer.hxx b/dev/zka/KernelKit/Framebuffer.hxx
new file mode 100644
index 00000000..dac9b514
--- /dev/null
+++ b/dev/zka/KernelKit/Framebuffer.hxx
@@ -0,0 +1,85 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Framebuffer.hpp
+ Purpose: Framebuffer object.
+
+------------------------------------------- */
+
+#ifndef __INC_FB_HPP__
+#define __INC_FB_HPP__
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ enum class FramebufferColorKind : UChar
+ {
+ RGB32,
+ RGB16,
+ RGB8,
+ INVALID,
+ };
+
+ class FramebufferContext final
+ {
+ public:
+ UIntPtr fBase;
+ UIntPtr fBpp;
+ UInt fWidth;
+ UInt fHeight;
+ };
+
+ class Framebuffer final
+ {
+ public:
+ explicit Framebuffer(Ref<FramebufferContext*>& addr);
+ ~Framebuffer() = default;
+
+ Framebuffer& operator=(const Framebuffer&) = delete;
+ Framebuffer(const Framebuffer&) = default;
+
+ volatile UIntPtr* operator[](const UIntPtr& pos);
+
+ operator bool();
+
+ const FramebufferColorKind& Color(
+ const FramebufferColorKind& colour = FramebufferColorKind::INVALID);
+
+ Ref<FramebufferContext*>& Leak();
+
+ /// @brief Draws a rectangle inside the fb.
+ /// @param width the width of it
+ /// @param height the height of it
+ /// @param x its x coord.
+ /// @param y its y coord.
+ /// @param color the color of it.
+ /// @return the framebuffer object.
+ Framebuffer& DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color);
+
+ /// @brief Puts a pixel on the screen.
+ /// @param x where in X
+ /// @param y where in Y
+ /// @param color the color of it.
+ /// @return the framebuffer object.
+ Framebuffer& PutPixel(SizeT x, SizeT y, UInt32 color);
+
+ private:
+ Ref<FramebufferContext*> fFrameBufferAddr;
+ FramebufferColorKind fColour;
+ };
+
+ /***********************************************************************************/
+ /// Some common colors.
+ /***********************************************************************************/
+
+ extern const UInt32 kRgbRed;
+ extern const UInt32 kRgbGreen;
+ extern const UInt32 kRgbBlue;
+ extern const UInt32 kRgbBlack;
+ extern const UInt32 kRgbWhite;
+} // namespace Kernel
+
+#endif /* ifndef __INC_FB_HPP__ */
diff --git a/dev/zka/KernelKit/HardwareThreadScheduler.hxx b/dev/zka/KernelKit/HardwareThreadScheduler.hxx
new file mode 100644
index 00000000..83f6ebd9
--- /dev/null
+++ b/dev/zka/KernelKit/HardwareThreadScheduler.hxx
@@ -0,0 +1,147 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __INC_MP_MANAGER_HPP__
+#define __INC_MP_MANAGER_HPP__
+
+#include <ArchKit/ArchKit.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/Ref.hxx>
+
+/// @note Last Rev Sun 28 Jul CET 2024
+/// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM
+
+#define cMaxHWThreads (8U)
+
+namespace Kernel
+{
+ class HardwareThread;
+ class HardwareThreadScheduler;
+
+ using ThreadID = UInt32;
+
+ enum ThreadKind
+ {
+ kHartSystemReserved, // System reserved thread, well user can't use it
+ kHartStandard, // user thread, cannot be used by Kernel
+ kHartFallback, // fallback thread, cannot be used by user if not clear or
+ // used by Kernel.
+ kHartBoot, // The core we booted from, the mama.
+ kInvalidHart,
+ kHartCount,
+ };
+
+ typedef enum ThreadKind ThreadKind;
+ typedef ThreadID ThreadID;
+
+ ///
+ /// \name HardwareThread
+ /// \brief Abstraction over the CPU's core, used to run processes or threads.
+ ///
+
+ class HardwareThread final
+ {
+ public:
+ explicit HardwareThread();
+ ~HardwareThread();
+
+ public:
+ ZKA_COPY_DEFAULT(HardwareThread)
+
+ public:
+ operator bool();
+
+ public:
+ void Wake(const bool wakeup = false) noexcept;
+ void Busy(const bool busy = false) noexcept;
+
+ public:
+ bool Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame);
+ bool IsWakeup() noexcept;
+
+ public:
+ HAL::StackFramePtr StackFrame() noexcept;
+ const ThreadKind& Kind() noexcept;
+ bool IsBusy() noexcept;
+ const ThreadID& ID() noexcept;
+
+ private:
+ HAL::StackFramePtr fStack{nullptr};
+ ThreadKind fKind{ThreadKind::kHartStandard};
+ ThreadID fID{0};
+ ProcessID fSourcePID{-1};
+ Bool fWakeup{false};
+ Bool fBusy{false};
+ UInt64 fPTime{0};
+
+ private:
+ friend class HardwareThreadScheduler;
+ friend class UserProcessHelper;
+ };
+
+ ///
+ /// \name HardwareThreadScheduler
+ /// \brief Class to manage the thread scheduling.
+ ///
+
+ class HardwareThreadScheduler final : public ISchedulerObject
+ {
+ private:
+ friend class UserProcessHelper;
+
+ public:
+ explicit HardwareThreadScheduler();
+ ~HardwareThreadScheduler();
+ ZKA_COPY_DEFAULT(HardwareThreadScheduler);
+
+ public:
+ HAL::StackFramePtr Leak() noexcept;
+
+ public:
+ Ref<HardwareThread*> operator[](const SizeT& idx);
+ bool operator!() noexcept;
+ operator bool() noexcept;
+
+ const Bool IsUser() override
+ {
+ return Yes;
+ }
+
+ const Bool IsKernel() override
+ {
+ return No;
+ }
+
+ const Bool HasMP() override
+ {
+ return kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled;
+ }
+
+ public:
+ /// @brief Shared instance of the MP Mgr.
+ /// @return the reference to the mp manager class.
+ STATIC HardwareThreadScheduler& The();
+
+ public:
+ /// @brief Returns the amount of threads present in the system.
+ /// @returns SizeT the amount of cores present.
+ SizeT Count() noexcept;
+
+ private:
+ Array<HardwareThread, cMaxHWThreads> fThreadList;
+ ThreadID fCurrentThread{0};
+ };
+
+ /// @brief wakes up thread.
+ /// wakes up thread from hang.
+ Void mp_wakeup_thread(HAL::StackFramePtr stack);
+
+ /// @brief makes thread sleep.
+ /// hooks and hangs thread to prevent code from executing.
+ Void mp_hang_thread(HAL::StackFramePtr stack);
+} // namespace Kernel
+
+#endif // !__INC_MP_MANAGER_HPP__
diff --git a/dev/zka/KernelKit/Heap.hxx b/dev/zka/KernelKit/Heap.hxx
new file mode 100644
index 00000000..cb8da37d
--- /dev/null
+++ b/dev/zka/KernelKit/Heap.hxx
@@ -0,0 +1,71 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_KERNEL_HEAP_HXX_
+#define _INC_KERNEL_HEAP_HXX_
+
+// last-rev 30/01/24
+// file: KernelHeap.hxx
+// description: heap allocation for the Kernel.
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ /// @brief Declare pointer as free.
+ /// @param heap_ptr the pointer.
+ /// @return
+ Int32 mm_delete_heap(VoidPtr heap_ptr);
+
+ /// @brief Declare a new size for heap_ptr.
+ /// @param heap_ptr the pointer.
+ /// @return
+ VoidPtr mm_realloc_heap(VoidPtr heap_ptr, SizeT new_sz);
+
+ /// @brief Check if pointer is a valid Kernel pointer.
+ /// @param heap_ptr the pointer
+ /// @return if it exists.
+ Boolean mm_is_valid_heap(VoidPtr heap_ptr);
+
+ /// @brief Allocate chunk of memory.
+ /// @param sz Size of pointer
+ /// @param rw Read Write bit.
+ /// @param user User enable bit.
+ /// @return The newly allocated pointer.
+ VoidPtr mm_new_heap(const SizeT sz, const Bool rw, const Bool user);
+
+ /// @brief Protect the heap with a CRC value.
+ /// @param heap_ptr pointer.
+ /// @return if it valid: point has crc now., otherwise fail.
+ Boolean mm_protect_heap(VoidPtr heap_ptr);
+
+ /// @brief Makes a Kernel page.
+ /// @param heap_ptr the page pointer.
+ /// @return status code
+ Int32 mm_make_ke_page(VoidPtr heap_ptr);
+
+ template <typename T, typename... Args>
+ inline T* mm_new_class(Args&&... args)
+ {
+ T* cls = (T*)mm_new_heap(sizeof(T), No, No);
+ MUST_PASS(cls);
+
+ *cls = T(move(args)...);
+
+ return cls;
+ }
+
+ template <typename T>
+ inline Void mm_delete_class(T* cls)
+ {
+ cls->~T();
+ mm_delete_heap((VoidPtr)cls);
+
+ cls = nullptr;
+ }
+} // namespace Kernel
+
+#endif // !_INC_KERNEL_HEAP_HXX_
diff --git a/dev/zka/KernelKit/IDLLObject.hxx b/dev/zka/KernelKit/IDLLObject.hxx
new file mode 100644
index 00000000..21c2848a
--- /dev/null
+++ b/dev/zka/KernelKit/IDLLObject.hxx
@@ -0,0 +1,44 @@
+/*
+ * ========================================================
+ *
+ * Kernel
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ class IDLLObject
+ {
+ public:
+ explicit IDLLObject() = default;
+ virtual ~IDLLObject() = default;
+
+ struct DLL_TRAITS final
+ {
+ VoidPtr fImageObject{nullptr};
+ VoidPtr fImageEntrypointOffset{nullptr};
+
+ Bool IsValid()
+ {
+ return fImageObject && fImageEntrypointOffset;
+ }
+ };
+
+ ZKA_COPY_DEFAULT(IDLLObject);
+
+ virtual DLL_TRAITS** GetAddressOf() = 0;
+ virtual DLL_TRAITS* Get() = 0;
+
+ virtual Void Mount(DLL_TRAITS* to_mount) = 0;
+ virtual Void Unmount() = 0;
+ };
+
+ /// @brief Pure implementation, missing method/function handler.
+ EXTERN_C void __zka_pure_call(void);
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/IPEFDLLObject.hxx b/dev/zka/KernelKit/IPEFDLLObject.hxx
new file mode 100644
index 00000000..c41d3365
--- /dev/null
+++ b/dev/zka/KernelKit/IPEFDLLObject.hxx
@@ -0,0 +1,105 @@
+/*
+ * ========================================================
+ *
+ * Kernel
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#ifndef __KERNELKIT_SHARED_OBJECT_HXX__
+#define __KERNELKIT_SHARED_OBJECT_HXX__
+
+#include <KernelKit/PEF.hxx>
+#include <NewKit/Defines.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/IDLLObject.hxx>
+
+namespace Kernel
+{
+ /**
+ * @brief Shared Library class
+ * Load library from this class
+ */
+ class IPEFDLLObject final : public IDLLObject
+ {
+ public:
+ explicit IPEFDLLObject() = default;
+ ~IPEFDLLObject() = default;
+
+ public:
+ ZKA_COPY_DEFAULT(IPEFDLLObject);
+
+ private:
+ DLL_TRAITS* fMounted{nullptr};
+
+ public:
+ DLL_TRAITS** GetAddressOf()
+ {
+ return &fMounted;
+ }
+
+ DLL_TRAITS* Get()
+ {
+ return fMounted;
+ }
+
+ public:
+ void Mount(DLL_TRAITS* to_mount)
+ {
+ if (!to_mount || !to_mount->fImageObject)
+ return;
+
+ fMounted = to_mount;
+
+ if (fLoader && to_mount)
+ {
+ delete fLoader;
+ fLoader = nullptr;
+ }
+
+ if (!fLoader)
+ {
+ fLoader = new PEFLoader(fMounted->fImageObject);
+ }
+ }
+
+ void Unmount()
+ {
+ if (fMounted)
+ fMounted = nullptr;
+ };
+
+ template <typename SymbolType>
+ SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind)
+ {
+ if (symbol_name == nullptr || *symbol_name == 0)
+ return nullptr;
+ if (len > kPathLen || len < 1)
+ return nullptr;
+
+ auto ret =
+ reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kind));
+
+ if (!ret)
+ {
+ if (kind == kPefCode)
+ return (VoidPtr)&__zka_pure_call;
+
+ return nullptr;
+ }
+
+ return ret;
+ }
+
+ private:
+ PEFLoader* fLoader{nullptr};
+ };
+
+ typedef IPEFDLLObject* IDLL;
+
+ EXTERN_C IDLL rtl_init_dll(UserProcess* header);
+ EXTERN_C Void rtl_fini_dll(UserProcess* header, IDLL lib, Bool* successful);
+} // namespace Kernel
+
+#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */
diff --git a/dev/zka/KernelKit/LPC.hxx b/dev/zka/KernelKit/LPC.hxx
new file mode 100644
index 00000000..9a14c798
--- /dev/null
+++ b/dev/zka/KernelKit/LPC.hxx
@@ -0,0 +1,61 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+/// @file LPC.hxx
+/// @brief Local Process Codes.
+
+#define ErrLocalIsOk() (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() == Kernel::kErrorSuccess)
+#define ErrLocalFailed() (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() != Kernel::kErrorSuccess)
+#define ErrLocal() Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode()
+
+namespace Kernel
+{
+ typedef Int32 HError;
+
+ inline constexpr HError kErrorSuccess = 0;
+ inline constexpr HError kErrorExecutable = 33;
+ inline constexpr HError kErrorExecutableLib = 34;
+ inline constexpr HError kErrorFileNotFound = 35;
+ inline constexpr HError kErrorDirectoryNotFound = 36;
+ inline constexpr HError kErrorDiskReadOnly = 37;
+ inline constexpr HError kErrorDiskIsFull = 38;
+ inline constexpr HError kErrorProcessFault = 39;
+ inline constexpr HError kErrorSocketHangUp = 40;
+ inline constexpr HError kErrorThreadLocalStorage = 41;
+ inline constexpr HError kErrorMath = 42;
+ inline constexpr HError kErrorNoNetwork = 43;
+ inline constexpr HError kErrorHeapOutOfMemory = 44;
+ inline constexpr HError kErrorNoSuchDisk = 45;
+ inline constexpr HError kErrorFileExists = 46;
+ inline constexpr HError kErrorFormatFailed = 47;
+ inline constexpr HError kErrorNetworkTimeout = 48;
+ inline constexpr HError kErrorInternal = 49;
+ inline constexpr HError kErrorForkAlreadyExists = 50;
+ inline constexpr HError kErrorOutOfTeamSlot = 51;
+ inline constexpr HError kErrorHeapNotPresent = 52;
+ inline constexpr HError kErrorNoEntrypoint = 53;
+ inline constexpr HError kErrorDiskIsCorrupted = 54;
+ inline constexpr HError kErrorDisk = 55;
+ inline constexpr HError kErrorInvalidData = 56;
+ inline constexpr HError kErrorAsync = 57;
+ inline constexpr HError kErrorNonBlocking = 58;
+ inline constexpr HError kErrorIPC = 59;
+ inline constexpr HError kErrorSign = 60;
+ inline constexpr HError kErrorInvalidCreds = 61;
+ inline constexpr HError kErrorUnimplemented = 0;
+
+ /// @brief Reports a bug to system check.
+ Void err_bug_check_raise(void) noexcept;
+
+ /// @brief Does a system wide bug check.
+ /// @param void no params.
+ /// @return if error-free: false, otherwise true.
+ Boolean err_bug_check(void) noexcept;
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/LoaderInterface.hxx b/dev/zka/KernelKit/LoaderInterface.hxx
new file mode 100644
index 00000000..ab251bec
--- /dev/null
+++ b/dev/zka/KernelKit/LoaderInterface.hxx
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <HintKit/CompilerHint.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/ErrorOr.hxx>
+
+namespace Kernel
+{
+ /// @brief This interface is used to make loader contracts (MSCOFF, PEF).
+ /// @author @Amlal-El-Mahrouss
+ class LoaderInterface
+ {
+ public:
+ explicit LoaderInterface() = default;
+ virtual ~LoaderInterface() = default;
+
+ ZKA_COPY_DEFAULT(LoaderInterface);
+
+ public:
+ virtual _Output const Char* AsString() = 0;
+ virtual _Output const Char* MIME() = 0;
+ virtual _Output const Char* Path() = 0;
+ virtual _Output ErrorOr<VoidPtr> FindStart() = 0;
+ virtual _Output VoidPtr FindSymbol(_Input const Char* name, _Input Int32 kind) = 0;
+ };
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/LockDelegate.hxx b/dev/zka/KernelKit/LockDelegate.hxx
new file mode 100644
index 00000000..d678e3d4
--- /dev/null
+++ b/dev/zka/KernelKit/LockDelegate.hxx
@@ -0,0 +1,67 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Atom.hxx>
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ enum
+ {
+ kLockDone = 200,
+ kLockTimedOut,
+ };
+
+ /// @brief Lock condition pointer.
+ typedef Boolean* LockPtr;
+
+ /// @brief Locking delegate class, hangs until limit.
+ /// @tparam N the amount of cycles to wait.
+ template <SizeT N>
+ class LockDelegate final
+ {
+ public:
+ LockDelegate() = delete;
+
+ public:
+ explicit LockDelegate(LockPtr expr)
+ {
+ auto spin = 0U;
+
+ while (spin != N)
+ {
+ if (*expr)
+ {
+ fLockStatus | kLockDone;
+ break;
+ }
+ }
+
+ if (spin == N)
+ fLockStatus | kLockTimedOut;
+ }
+
+ ~LockDelegate() = default;
+
+ LockDelegate& operator=(const LockDelegate&) = delete;
+ LockDelegate(const LockDelegate&) = delete;
+
+ bool Done()
+ {
+ return fLockStatus[kLockDone] == kLockDone;
+ }
+
+ bool HasTimedOut()
+ {
+ return fLockStatus[kLockTimedOut] != kLockTimedOut;
+ }
+
+ private:
+ Atom<UInt> fLockStatus;
+ };
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/MSDOS.hxx b/dev/zka/KernelKit/MSDOS.hxx
new file mode 100644
index 00000000..6ce11cbd
--- /dev/null
+++ b/dev/zka/KernelKit/MSDOS.hxx
@@ -0,0 +1,52 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: MSDOS.hpp
+ Purpose: MS-DOS header for Kernel.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#ifndef __MSDOS_EXEC__
+#define __MSDOS_EXEC__
+
+#include <KernelKit/PE.hxx>
+#include <NewKit/Defines.hxx>
+
+// Last Rev
+// Sat Feb 24 CET 2024
+
+#define kMagMz0 'M'
+#define kMagMz1 'Z'
+
+typedef Kernel::UInt32 DosWord;
+typedef Kernel::Long DosLong;
+
+typedef struct _DosHeader
+{
+ Kernel::UInt8 eMagic[2];
+ DosWord eMagLen;
+ DosWord ePagesCount;
+ DosWord eCrlc;
+ DosWord eCParHdr;
+ DosWord eMinAlloc;
+ DosWord eMaxAlloc;
+ DosWord eStackSeg;
+ DosWord eStackPtr;
+ DosWord eChksum;
+ DosWord eIp;
+ DosWord eCs;
+ DosWord eLfarlc;
+ DosWord eOvno;
+ DosWord eRes[4];
+ DosWord eOemid;
+ DosWord eOeminfo;
+ DosWord eRes2[10];
+ DosLong eLfanew;
+} DosHeader, *DosHeaderPtr;
+
+#endif /* ifndef __MSDOS_EXEC__ */
diff --git a/dev/zka/KernelKit/PCI/Database.hxx b/dev/zka/KernelKit/PCI/Database.hxx
new file mode 100644
index 00000000..c5f3c953
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Database.hxx
@@ -0,0 +1,38 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <KernelKit/PCI/Device.hxx>
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ namespace Types
+ {
+ // https://wiki.osdev.org/PCI
+ enum class PciDeviceKind : UChar
+ {
+ MassStorageController = 0x1,
+ NetworkController = 0x2,
+ DisplayController = 0x3,
+ MultimediaController = 0x4,
+ MemoryController = 0x5,
+ Bridge = 0x6,
+ CommunicationController = 0x7,
+ GenericSystemPeripheral = 0x8,
+ InputDeviceController = 0x9,
+ DockingStation = 0xa,
+ Processor = 0xb,
+ SerialBusController = 0xc,
+ WirelessController = 0xd,
+ IntelligentController = 0xe,
+ SatelliteCommunicationsController = 0xf,
+ CoProcessor = 0x40,
+ Unassgined = 0xf,
+ Invalid = Unassgined,
+ };
+ } // namespace Types
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/PCI/Device.hxx b/dev/zka/KernelKit/PCI/Device.hxx
new file mode 100644
index 00000000..b1c011e9
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Device.hxx
@@ -0,0 +1,80 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel::PCI
+{
+ enum class PciConfigKind : UShort
+ {
+ ConfigAddress = 0xCF8,
+ ConfigData = 0xCFC,
+ Invalid = 0xFFF
+ };
+
+ class Device final
+ {
+ public:
+ Device() = default;
+
+ public:
+ explicit Device(UShort bus, UShort device, UShort function, UInt32 bar);
+
+ Device& operator=(const Device&) = default;
+
+ Device(const Device&) = default;
+
+ ~Device();
+
+ public:
+ UInt Read(UInt bar, Size szData);
+ void Write(UInt bar, UIntPtr data, Size szData);
+
+ public:
+ operator bool();
+
+ public:
+ template <typename T>
+ UInt Read(UInt bar)
+ {
+ static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported");
+ return Read(bar, sizeof(T));
+ }
+
+ template <typename T>
+ void Write(UInt bar, UIntPtr data)
+ {
+ static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported");
+ Write(bar, data, sizeof(T));
+ }
+
+ public:
+ UShort DeviceId();
+ UShort VendorId();
+ UShort InterfaceId();
+ UChar Class();
+ UChar Subclass();
+ UChar ProgIf();
+ UChar HeaderType();
+ UInt32 Bar();
+
+ public:
+ void EnableMmio();
+ void BecomeBusMaster(); // for PCI-DMA, PC-DMA does not need that.
+
+ UShort Vendor();
+
+ private:
+ UShort fBus;
+ UShort fDevice;
+ UShort fFunction;
+ UInt32 fBar;
+ };
+} // namespace Kernel::PCI
+
+EXTERN_C void NewOSPCISetCfgTarget(Kernel::UInt bar);
+EXTERN_C Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar);
diff --git a/dev/zka/KernelKit/PCI/Dma.hxx b/dev/zka/KernelKit/PCI/Dma.hxx
new file mode 100644
index 00000000..b265f738
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Dma.hxx
@@ -0,0 +1,81 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <KernelKit/PCI/Device.hxx>
+#include <NewKit/Array.hxx>
+#include <NewKit/OwnPtr.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ enum class DmaKind
+ {
+ PCI, // Bus mastering is required to be turned on. Basiaclly a request
+ // control system. 64-Bit access depends on the PAE bit and the device
+ // (if Double Address Cycle is available)
+ ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM.
+ Invalid,
+ };
+
+ class DMAWrapper final
+ {
+ public:
+ explicit DMAWrapper() = delete;
+
+ public:
+ explicit DMAWrapper(nullPtr) = delete;
+ explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI)
+ : fAddress(Ptr), fKind(Kind)
+ {
+ }
+
+ public:
+ DMAWrapper& operator=(voidPtr Ptr);
+
+ public:
+ DMAWrapper& operator=(const DMAWrapper&) = default;
+ DMAWrapper(const DMAWrapper&) = default;
+
+ public:
+ ~DMAWrapper() = default;
+
+ template <class T>
+ T* operator->();
+
+ template <class T>
+ T* Get(const UIntPtr off = 0);
+
+ public:
+ operator bool();
+ bool operator!();
+
+ public:
+ bool Write(const UIntPtr& bit, const UIntPtr& offset);
+ UIntPtr Read(const UIntPtr& offset);
+ Boolean Check(UIntPtr offset) const;
+
+ public:
+ UIntPtr operator[](const UIntPtr& offset);
+
+ private:
+ voidPtr fAddress{nullptr};
+ DmaKind fKind{DmaKind::Invalid};
+
+ private:
+ friend class DMAFactory;
+ };
+
+ class DMAFactory final
+ {
+ public:
+ static OwnPtr<IOBuf<Char*>> Construct(OwnPtr<DMAWrapper>& dma);
+ };
+} // namespace Kernel
+
+#include <KernelKit/PCI/Dma.inl>
diff --git a/dev/zka/KernelKit/PCI/Dma.inl b/dev/zka/KernelKit/PCI/Dma.inl
new file mode 100644
index 00000000..1c164af8
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Dma.inl
@@ -0,0 +1,20 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+namespace Kernel
+{
+ template <class T>
+ T* DMAWrapper::operator->()
+ {
+ return fAddress;
+ }
+
+ template <class T>
+ T* DMAWrapper::Get(const UIntPtr offset)
+ {
+ return reinterpret_cast<T*>((UIntPtr)fAddress + offset);
+ }
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/PCI/Express.hxx b/dev/zka/KernelKit/PCI/Express.hxx
new file mode 100644
index 00000000..1d6a86d0
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Express.hxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define PCI_EXPRESS_BUS_COUNT (4096)
diff --git a/dev/zka/KernelKit/PCI/IO-Impl-AMD64.inl b/dev/zka/KernelKit/PCI/IO-Impl-AMD64.inl
new file mode 100644
index 00000000..84c24620
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/IO-Impl-AMD64.inl
@@ -0,0 +1,54 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: IO-Impl-AMD64.hpp
+ Purpose: I/O for AMD64.
+
+ Revision History:
+
+ 30/01/24: Add file. (amlel)
+ 02/02/24: Update I/O routines. (amlel)
+
+------------------------------------------- */
+
+namespace Kernel
+{
+ template <SizeT Sz>
+ template <typename T>
+ T IOArray<Sz>::In(SizeT index)
+ {
+ switch (sizeof(T))
+ {
+#ifdef __ZKA_AMD64__
+ case 4:
+ return HAL::In32(fPorts[index].Leak());
+ case 2:
+ return HAL::In16(fPorts[index].Leak());
+ case 1:
+ return HAL::In8(fPorts[index].Leak());
+#endif
+ default:
+ return 0xFFFF;
+ }
+ }
+
+ template <SizeT Sz>
+ template <typename T>
+ void IOArray<Sz>::Out(SizeT index, T value)
+ {
+ switch (sizeof(T))
+ {
+#ifdef __ZKA_AMD64__
+ case 4:
+ HAL::Out32(fPorts[index].Leak(), value);
+ case 2:
+ HAL::Out16(fPorts[index].Leak(), value);
+ case 1:
+ HAL::Out8(fPorts[index].Leak(), value);
+#endif
+ default:
+ break;
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/PCI/IO.hxx b/dev/zka/KernelKit/PCI/IO.hxx
new file mode 100644
index 00000000..a86bcc52
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/IO.hxx
@@ -0,0 +1,59 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.hxx>
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ template <SizeT Sz>
+ class IOArray final
+ {
+ public:
+ IOArray() = delete;
+
+ IOArray(nullPtr) = delete;
+
+ explicit IOArray(Array<UShort, Sz>& ports)
+ : fPorts(ports)
+ {
+ }
+ ~IOArray()
+ {
+ }
+
+ IOArray& operator=(const IOArray&) = default;
+
+ IOArray(const IOArray&) = default;
+
+ operator bool()
+ {
+ return !fPorts.Empty();
+ }
+
+ public:
+ template <typename T>
+ T In(SizeT index);
+
+ template <typename T>
+ void Out(SizeT index, T value);
+
+ private:
+ Array<UShort, Sz> fPorts;
+ };
+
+ using IOArray16 = IOArray<16>;
+} // namespace Kernel
+
+#ifdef __x86_64__
+#include <KernelKit/PCI/IO-Impl-AMD64.inl>
+#else
+#error Please provide platform specific code for the I/O
+#endif // ifdef __x86_64__
diff --git a/dev/zka/KernelKit/PCI/Iterator.hxx b/dev/zka/KernelKit/PCI/Iterator.hxx
new file mode 100644
index 00000000..24c6e610
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/Iterator.hxx
@@ -0,0 +1,43 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __PCI_ITERATOR_HPP__
+#define __PCI_ITERATOR_HPP__
+
+#include <KernelKit/PCI/Database.hxx>
+#include <KernelKit/PCI/Device.hxx>
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+#define ZKA_BUS_COUNT (256)
+#define ZKA_DEVICE_COUNT (33)
+#define ZKA_FUNCTION_COUNT (8)
+
+namespace Kernel::PCI
+{
+ class Iterator final
+ {
+ public:
+ Iterator() = delete;
+
+ public:
+ explicit Iterator(const Types::PciDeviceKind& deviceType);
+
+ Iterator& operator=(const Iterator&) = default;
+ Iterator(const Iterator&) = default;
+
+ ~Iterator();
+
+ public:
+ Ref<PCI::Device> operator[](const Size& sz);
+
+ private:
+ Array<PCI::Device, ZKA_BUS_COUNT> fDevices;
+ };
+} // namespace Kernel::PCI
+
+#endif // __PCI_ITERATOR_HPP__
diff --git a/dev/zka/KernelKit/PCI/PCI.hxx b/dev/zka/KernelKit/PCI/PCI.hxx
new file mode 100644
index 00000000..3289db04
--- /dev/null
+++ b/dev/zka/KernelKit/PCI/PCI.hxx
@@ -0,0 +1,59 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define cPCIConfigAddressPort (0xCF8)
+#define cPCIConfigDataPort (0xCFC)
+
+#define cPCIDeviceCount (32)
+#define cPCIFuncCount (8)
+#define cPCIBusCount (255)
+
+namespace Kernel::PCI
+{
+ // model
+ struct DeviceHeader
+ {
+ UInt16 VendorId;
+ UInt16 DeviceId;
+ UInt8 Command;
+ UInt8 Status;
+ UInt8 RevisionId;
+ UInt8 ProgIf;
+ UInt8 SubClass;
+ UInt8 Class;
+ UInt8 CacheLineSz;
+ UInt8 LatencyTimer;
+ UInt8 HeaderType;
+ UInt8 Bist;
+ UInt8 Bus;
+ UInt8 Device;
+ UInt8 Function;
+ };
+
+ namespace Detail
+ {
+ class BAR
+ {
+ public:
+ UIntPtr BAR;
+ SizeT Size;
+ };
+ } // namespace Detail
+
+ class BAR
+ {
+ public:
+ Detail::BAR BAR1;
+ Detail::BAR BAR2;
+ Detail::BAR BAR3;
+ Detail::BAR BAR4;
+ Detail::BAR BAR5;
+ };
+} // namespace Kernel::PCI
diff --git a/dev/zka/KernelKit/PE.hxx b/dev/zka/KernelKit/PE.hxx
new file mode 100644
index 00000000..bab723ef
--- /dev/null
+++ b/dev/zka/KernelKit/PE.hxx
@@ -0,0 +1,143 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: PE.hxx
+ Purpose: Portable Executable for Kernel.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#ifndef __KERNELKIT_INC_PE_HXX__
+#define __KERNELKIT_INC_PE_HXX__
+
+#include <NewKit/Defines.hxx>
+
+#define kPeMagic 0x00004550
+
+#define kPeDLLBase 0x4000000
+#define kPeEXEBase 0x1000000
+
+#define kMagPE32 0x010b
+#define kMagPE64 0x020b
+
+#define kPeMachineAMD64 0x8664
+#define kPeMachineARM64 0xaa64
+
+typedef struct LDR_EXEC_HEADER final
+{
+ Kernel::UInt32 mSignature;
+ Kernel::UInt16 mMachine;
+ Kernel::UInt16 mNumberOfSections;
+ Kernel::UInt32 mTimeDateStamp;
+ Kernel::UInt32 mPointerToSymbolTable;
+ Kernel::UInt32 mNumberOfSymbols;
+ Kernel::UInt16 mSizeOfOptionalHeader;
+ Kernel::UInt16 mCharacteristics;
+} LDR_EXEC_HEADER, *LDR_EXEC_HEADER_PTR;
+
+typedef struct LDR_OPTIONAL_HEADER final
+{
+ Kernel::UInt16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit)
+ Kernel::UInt8 mMajorLinkerVersion;
+ Kernel::UInt8 mMinorLinkerVersion;
+ Kernel::UInt32 mSizeOfCode;
+ Kernel::UInt32 mSizeOfInitializedData;
+ Kernel::UInt32 mSizeOfUninitializedData;
+ Kernel::UInt32 mAddressOfEntryPoint;
+ Kernel::UInt32 mBaseOfCode;
+ Kernel::UInt32 mBaseOfData;
+ Kernel::UInt32 mImageBase;
+ Kernel::UInt32 mSectionAlignment;
+ Kernel::UInt32 mFileAlignment;
+ Kernel::UInt16 mMajorOperatingSystemVersion;
+ Kernel::UInt16 mMinorOperatingSystemVersion;
+ Kernel::UInt16 mMajorImageVersion;
+ Kernel::UInt16 mMinorImageVersion;
+ Kernel::UInt16 mMajorSubsystemVersion;
+ Kernel::UInt16 mMinorSubsystemVersion;
+ Kernel::UInt32 mWin32VersionValue;
+ Kernel::UInt32 mSizeOfImage;
+ Kernel::UInt32 mSizeOfHeaders;
+ Kernel::UInt32 mCheckSum;
+ Kernel::UInt16 mSubsystem;
+ Kernel::UInt16 mDllCharacteristics;
+ Kernel::UInt32 mSizeOfStackReserve;
+ Kernel::UInt32 mSizeOfStackCommit;
+ Kernel::UInt32 mSizeOfHeapReserve;
+ Kernel::UInt32 mSizeOfHeapCommit;
+ Kernel::UInt32 mLoaderFlags;
+ Kernel::UInt32 mNumberOfRvaAndSizes;
+} LDR_OPTIONAL_HEADER, *LDR_OPTIONAL_HEADER_PTR;
+
+typedef struct LDR_SECTION_HEADER final
+{
+ Kernel::Char mName[8];
+ Kernel::UInt32 mVirtualSize;
+ Kernel::UInt32 mVirtualAddress;
+ Kernel::UInt32 mSizeOfRawData;
+ Kernel::UInt32 mPointerToRawData;
+ Kernel::UInt32 mPointerToRelocations;
+ Kernel::UInt32 mPointerToLineNumbers;
+ Kernel::UInt16 mNumberOfRelocations;
+ Kernel::UInt16 mNumberOfLinenumbers;
+ Kernel::UInt32 mCharacteristics;
+} LDR_SECTION_HEADER, *LDR_SECTION_HEADER_PTR;
+
+enum kExecDataDirParams
+{
+ kExecExport,
+ kExecImport,
+ kExecInvalid,
+ kExecCount,
+};
+
+typedef struct LDR_EXPORT_DIRECTORY
+{
+ Kernel::UInt32 mCharacteristics;
+ Kernel::UInt32 mTimeDateStamp;
+ Kernel::UInt16 mMajorVersion;
+ Kernel::UInt16 mMinorVersion;
+ Kernel::UInt32 mName;
+ Kernel::UInt32 mBase;
+ Kernel::UInt32 mNumberOfFunctions;
+ Kernel::UInt32 mNumberOfNames;
+ Kernel::UInt32 mAddressOfFunctions; // export table rva
+ Kernel::UInt32 mAddressOfNames;
+ Kernel::UInt32 mAddressOfNameOrdinal; // ordinal table rva
+} LDR_EXPORT_DIRECTORY, *LDR_EXPORT_DIRECTORY_PTR;
+
+typedef struct LDR_IMPORT_DIRECTORY
+{
+ union {
+ Kernel::UInt32 mCharacteristics;
+ Kernel::UInt32 mOriginalFirstThunk;
+ };
+ Kernel::UInt32 mTimeDateStamp;
+ Kernel::UInt32 mForwarderChain;
+ Kernel::UInt32 mNameRva;
+ Kernel::UInt32 mThunkTableRva;
+} LDR_IMPORT_DIRECTORY, *LDR_IMPORT_DIRECTORY_PTR;
+
+typedef struct LDR_DATA_DIRECTORY
+{
+ Kernel::UInt32 VirtualAddress;
+ Kernel::UInt32 Size;
+} LDR_DATA_DIRECTORY, *LDR_DATA_DIRECTORY_PTR;
+
+typedef struct LDR_IMAGE_HEADER
+{
+ LDR_EXEC_HEADER mHeader;
+ LDR_OPTIONAL_HEADER mOptHdr;
+} LDR_IMAGE_HEADER, *LDR_IMAGE_HEADER_PTR;
+
+enum
+{
+ eUserSection = 0x00000020,
+ cPEResourceId = 0xFFaadd00,
+};
+
+#endif /* ifndef __KERNELKIT_INC_PE_HXX__ */
diff --git a/dev/zka/KernelKit/PECodeMgr.hxx b/dev/zka/KernelKit/PECodeMgr.hxx
new file mode 100644
index 00000000..7b84fbc1
--- /dev/null
+++ b/dev/zka/KernelKit/PECodeMgr.hxx
@@ -0,0 +1,24 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: PECodeMgr.hxx
+ Purpose: PE32+ Code Mgr and Shared Objects.
+
+ Revision History:
+
+ 12/02/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+////////////////////////////////////////////////////
+
+// LAST REV: Mon Feb 12 13:52:01 CET 2024
+
+////////////////////////////////////////////////////
+
+#include <KernelKit/PE.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/String.hxx>
diff --git a/dev/zka/KernelKit/PEF.hxx b/dev/zka/KernelKit/PEF.hxx
new file mode 100644
index 00000000..e8066cf5
--- /dev/null
+++ b/dev/zka/KernelKit/PEF.hxx
@@ -0,0 +1,116 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: PEF.hxx
+ Purpose: Preferred Executable Format for Kernel.
+
+ Revision History:
+
+ ?/?/23: Added file (amlel)
+
+------------------------------------------- */
+
+#ifndef __KERNELKIT_INC_PEF_HXX__
+#define __KERNELKIT_INC_PEF_HXX__
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/LoaderInterface.hxx>
+#include <NewKit/Defines.hxx>
+
+#define kPefMagic "Joy!"
+#define kPefMagicFat "yoJ!"
+
+#define kPefMagicLen 5
+
+#define kPefVersion 3
+#define kPefNameLen 255
+
+namespace Kernel
+{
+ enum
+ {
+ kPefArchIntel86S,
+ kPefArchAMD64,
+ kPefArchRISCV,
+ kPefArch64x0, /* 64x0. ISA */
+ kPefArch32x0, /* 32x0. ISA */
+ kPefArchPowerPC,
+ kPefArchARM64,
+ kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1,
+ kPefArchInvalid = 0xFF,
+ };
+
+ enum
+ {
+ kPefSubArchAMD,
+ kPefSubArchIntel,
+ kPefSubArchGeneric,
+ kPefSubArchIBM,
+ };
+
+ enum
+ {
+ kPefKindExec = 1, /* .exe */
+ kPefKindSharedObject = 2, /* .lib */
+ kPefKindObject = 4, /* .obj */
+ kPefKindDebug = 5, /* .dbg */
+ kPefKindDriver = 6,
+ kPefKindCount,
+ };
+
+ typedef struct PEFContainer final
+ {
+ Char Magic[kPefMagicLen];
+ UInt32 Linker;
+ UInt32 Version;
+ UInt32 Kind;
+ UInt32 Abi;
+ UInt32 Cpu;
+ UInt32 SubCpu; /* Cpu specific information */
+ UIntPtr Start;
+ SizeT HdrSz; /* Size of header */
+ SizeT Count; /* container header count */
+ } PACKED PEFContainer;
+
+ /* First PEFCommandHeader starts after PEFContainer */
+
+ typedef struct PEFCommandHeader final
+ {
+ Char Name[kPefNameLen]; /* container name */
+ UInt32 Cpu; /* container cpu */
+ UInt32 SubCpu; /* container sub-cpu */
+ UInt32 Flags; /* container flags */
+ UInt16 Kind; /* container kind */
+ UIntPtr Offset; /* content offset */
+ SizeT Size; /* content Size */
+ } PACKED PEFCommandHeader;
+
+ enum
+ {
+ kPefCode = 0xC,
+ kPefData = 0xD,
+ kPefZero = 0xE,
+ kPefLinkerID = 0x1,
+ };
+} // namespace Kernel
+
+/* not mandatory, only for non fork based filesystems */
+#define kPefExt ".exe"
+#define kPefDylibExt ".dll"
+#define kPefLibExt ".lib"
+#define kPefObjectExt ".obj"
+#define kPefDebugExt ".dbg"
+#define kPefDriverExt ".sys"
+
+// Kernel System Binary Interface.
+#define kPefAbi (0x5046)
+
+#define kPefBaseOrigin (0x40000000)
+
+#define kPefStart "__ImageStart"
+
+#define kPefForkKind kPefMagic
+#define kPefForkKindFAT kPefMagicFat
+
+#endif /* ifndef __KERNELKIT_INC_PEF_HXX__ */
diff --git a/dev/zka/KernelKit/PEFCodeMgr.hxx b/dev/zka/KernelKit/PEFCodeMgr.hxx
new file mode 100644
index 00000000..2b07e4f8
--- /dev/null
+++ b/dev/zka/KernelKit/PEFCodeMgr.hxx
@@ -0,0 +1,67 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_CODE_MANAGER_PEF_HXX_
+#define _INC_CODE_MANAGER_PEF_HXX_
+
+#include <KernelKit/PEF.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/String.hxx>
+#include <KernelKit/FileMgr.hxx>
+
+#define kPefApplicationMime "application/vnd-zka-executable"
+
+namespace Kernel
+{
+ ///
+ /// \name PEFLoader
+ /// \brief PEF loader class.
+ ///
+ class PEFLoader : public LoaderInterface
+ {
+ private:
+ explicit PEFLoader() = delete;
+
+ public:
+ explicit PEFLoader(const VoidPtr blob);
+ explicit PEFLoader(const Char* path);
+ ~PEFLoader() override;
+
+ public:
+ ZKA_COPY_DEFAULT(PEFLoader);
+
+ public:
+ const Char* Path() override;
+ const Char* AsString() override;
+ const Char* MIME() override;
+
+ public:
+ ErrorOr<VoidPtr> FindStart() override;
+ VoidPtr FindSymbol(const Char* name, Int32 kind) override;
+
+ public:
+ bool IsLoaded() noexcept;
+
+ private:
+#ifdef __FSKIT_USE_NEFS__
+ OwnPtr<FileStream<Char, NeFileSystemMgr>> fFile;
+#else
+ OwnPtr<FileStream<Char>> fFile;
+#endif // __FSKIT_USE_NEFS__
+
+ Ref<StringView> fPath;
+ VoidPtr fCachedBlob;
+ bool fFatBinary;
+ bool fBad;
+ };
+
+ namespace Utils
+ {
+ bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept;
+ } // namespace Utils
+} // namespace Kernel
+
+#endif // ifndef _INC_CODE_MANAGER_PEF_HXX_
diff --git a/dev/zka/KernelKit/Semaphore.hxx b/dev/zka/KernelKit/Semaphore.hxx
new file mode 100644
index 00000000..74c5f8da
--- /dev/null
+++ b/dev/zka/KernelKit/Semaphore.hxx
@@ -0,0 +1,43 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <KernelKit/Timer.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+
+namespace Kernel
+{
+ class UserProcess;
+
+ typedef UserProcess* UserProcessPtr;
+
+ /// @brief Access control class, which locks a task until one is done.
+ class Semaphore final
+ {
+ public:
+ explicit Semaphore() = default;
+ ~Semaphore() = default;
+
+ public:
+ bool IsLocked() const;
+ bool Unlock() noexcept;
+
+ public:
+ void WaitForProcess() noexcept;
+
+ public:
+ bool Lock(UserProcess* process);
+ bool LockOrWait(UserProcess* process, TimerInterface* timer);
+
+ public:
+ ZKA_COPY_DEFAULT(Semaphore);
+
+ private:
+ UserProcessPtr fLockingProcess{nullptr};
+ };
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/ThreadLocalStorage.hxx b/dev/zka/KernelKit/ThreadLocalStorage.hxx
new file mode 100644
index 00000000..a25d8926
--- /dev/null
+++ b/dev/zka/KernelKit/ThreadLocalStorage.hxx
@@ -0,0 +1,54 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _KERNELKIT_TLS_HPP
+#define _KERNELKIT_TLS_HPP
+
+#include <NewKit/Defines.hxx>
+
+///! @brief Thread Local Storage for newoskrnl.
+
+#define kCookieMag0 'Z'
+#define kCookieMag1 'K'
+#define kCookieMag2 'A'
+
+#define kTLSCookieLen (3U)
+
+struct THREAD_INFORMATION_BLOCK;
+
+/// @brief Thread Information Block.
+/// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64)
+struct PACKED THREAD_INFORMATION_BLOCK final
+{
+ Kernel::Char f_Cookie[kTLSCookieLen]{0}; //! Thread magic number.
+ Kernel::VoidPtr f_ThreadRecord{nullptr}; //! Thread information record.
+};
+
+///! @brief Cookie Sanity check.
+Kernel::Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib);
+
+///! @brief new ptr syscall.
+template <typename T>
+T* tls_new_ptr(void) noexcept;
+
+///! @brief delete ptr syscall.
+template <typename T>
+Kernel::Boolean tls_delete_ptr(T* ptr) noexcept;
+
+template <typename T, typename... Args>
+T* tls_new_class(Args&&... args);
+
+/// @brief TLS install TIB and PIB. (syscall)
+EXTERN_C Kernel::Void rt_install_tib(THREAD_INFORMATION_BLOCK* TIB, THREAD_INFORMATION_BLOCK* PIB);
+
+/// @brief TLS check (syscall)
+EXTERN_C Kernel::Bool tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept;
+
+#include <KernelKit/ThreadLocalStorage.inl>
+
+// last rev 7/7/24
+
+#endif /* ifndef _KERNELKIT_TLS_HPP */
diff --git a/dev/zka/KernelKit/ThreadLocalStorage.inl b/dev/zka/KernelKit/ThreadLocalStorage.inl
new file mode 100644
index 00000000..7a1ef247
--- /dev/null
+++ b/dev/zka/KernelKit/ThreadLocalStorage.inl
@@ -0,0 +1,74 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+//! @file ThreadLocalStorage.inl
+//! @brief Allocate resources from the process's heap storage.
+
+#ifndef _INC_PROCESS_SCHEDULER_HXX_
+#include <KernelKit/UserProcessScheduler.hxx>
+#endif
+
+template <typename T>
+inline T* tls_new_ptr(void) noexcept
+{
+ using namespace Kernel;
+
+ auto ref_process = UserProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
+
+ T* pointer = (T*)ref_process.Leak().New(sizeof(T));
+ return pointer;
+}
+
+//! @brief TLS delete implementation.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(T* ptr) noexcept
+{
+ if (!ptr)
+ return false;
+
+ using namespace Kernel;
+
+ auto ref_process = UserProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
+
+ return ref_process.Leak().Delete(ptr, sizeof(T));
+}
+
+/// @brief Allocate a C++ class, and then call the constructor of it.
+/// @tparam T
+/// @tparam ...Args
+/// @param ...args
+/// @return
+template <typename T, typename... Args>
+T* tls_new_class(Args&&... args)
+{
+ T* ptr = tls_new_ptr<T>();
+
+ using namespace Kernel;
+
+ if (ptr)
+ {
+ *ptr = T(forward(args)...);
+ return ptr;
+ }
+
+ return nullptr;
+}
+
+/// @brief Delete a C++ class (call constructor first.)
+/// @tparam T
+/// @param ptr
+/// @return
+template <typename T>
+inline Kernel::Bool tls_delete_class(T* ptr)
+{
+ if (!ptr)
+ return false;
+
+ ptr->~T();
+ return tls_delete_ptr(ptr);
+}
diff --git a/dev/zka/KernelKit/Timer.hxx b/dev/zka/KernelKit/Timer.hxx
new file mode 100644
index 00000000..3d997848
--- /dev/null
+++ b/dev/zka/KernelKit/Timer.hxx
@@ -0,0 +1,82 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.hxx>
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/LPC.hxx>
+
+namespace Kernel
+{
+ class SoftwareTimer;
+ class TimerInterface;
+
+ class TimerInterface
+ {
+ public:
+ /// @brief Default constructor
+ explicit TimerInterface() = default;
+ virtual ~TimerInterface() = default;
+
+ public:
+ ZKA_COPY_DEFAULT(TimerInterface);
+
+ public:
+ virtual Int32 Wait() noexcept;
+ };
+
+ class SoftwareTimer final : public TimerInterface
+ {
+ public:
+ explicit SoftwareTimer(Int64 seconds);
+ ~SoftwareTimer() override;
+
+ public:
+ ZKA_COPY_DEFAULT(SoftwareTimer);
+
+ public:
+ Int32 Wait() noexcept override;
+
+ private:
+ IntPtr* fDigitalTimer{nullptr};
+ Int64 fWaitFor{0};
+ };
+
+ class HardwareTimer final : public TimerInterface
+ {
+ public:
+ explicit HardwareTimer(Int64 seconds);
+ ~HardwareTimer() override;
+
+ public:
+ ZKA_COPY_DEFAULT(HardwareTimer);
+
+ public:
+ Int32 Wait() noexcept override;
+
+ private:
+ IntPtr* fDigitalTimer{nullptr};
+ Int64 fWaitFor{0};
+ };
+
+ inline Int64 Milliseconds(Int64 time)
+ {
+ if (time < 0)
+ return 0;
+
+ // TODO: nanoseconds maybe?
+ return 1000 * 1000 * time;
+ }
+
+ inline Int64 Seconds(Int64 time)
+ {
+ if (time < 0)
+ return 0;
+
+ return 1000 * Milliseconds(time);
+ }
+} // namespace Kernel
diff --git a/dev/zka/KernelKit/User.hxx b/dev/zka/KernelKit/User.hxx
new file mode 100644
index 00000000..ce16576b
--- /dev/null
+++ b/dev/zka/KernelKit/User.hxx
@@ -0,0 +1,76 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_USER_HXX_
+#define _INC_USER_HXX_
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <KernelKit/LPC.hxx>
+#include <NewKit/String.hxx>
+#include <NewKit/Defines.hxx>
+
+// user mode users.
+#define kSuperUser "ZKA USER\\SUPER"
+#define kGuestUser "ZKA USER\\GUEST"
+
+#define kUsersFile "\\Users\\$UsrRcrd"
+#define kUsersDir "\\Users\\"
+
+#define kMaxUserNameLen (255)
+#define kMaxUserTokenLen (255)
+
+namespace Kernel
+{
+ class User;
+
+ enum class RingKind
+ {
+ kRingStdUser = 1,
+ kRingSuperUser = 2,
+ kRingGuestUser = 5,
+ kRingCount = 3,
+ };
+
+ class User final
+ {
+ public:
+ explicit User() = delete;
+
+ User(const Int32& sel, const Char* userName);
+ User(const RingKind& kind, const Char* userName);
+
+ ~User();
+
+ public:
+ ZKA_COPY_DEFAULT(User)
+
+ public:
+ bool operator==(const User& lhs);
+ bool operator!=(const User& lhs);
+
+ public:
+ /// @brief Get software ring
+ const RingKind& Ring() noexcept;
+
+ /// @brief Get user name
+ Char* Name() noexcept;
+
+ /// @brief Is he a standard user?
+ Bool IsStdUser() noexcept;
+
+ /// @brief Is she a super user?
+ Bool IsSuperUser() noexcept;
+
+ Bool TrySave(const Char* password) noexcept;
+
+ private:
+ RingKind fRing{RingKind::kRingStdUser};
+ Char fUserName[kMaxUserNameLen] = {0};
+ Char fUserToken[kMaxUserTokenLen] = {0};
+ };
+} // namespace Kernel
+
+#endif /* ifndef _INC_USER_HXX_ */
diff --git a/dev/zka/KernelKit/UserProcessScheduler.hxx b/dev/zka/KernelKit/UserProcessScheduler.hxx
new file mode 100644
index 00000000..3a6f03a1
--- /dev/null
+++ b/dev/zka/KernelKit/UserProcessScheduler.hxx
@@ -0,0 +1,331 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_PROCESS_SCHEDULER_HXX_
+#define _INC_PROCESS_SCHEDULER_HXX_
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/LockDelegate.hxx>
+#include <KernelKit/User.hxx>
+#include <NewKit/MutableArray.hxx>
+
+#define kSchedMinMicroTime (AffinityKind::kStandard)
+#define kSchedInvalidPID (-1)
+#define kSchedProcessLimitPerTeam (16U)
+
+////////////////////////////////////////////////////
+
+// LAST REV: Mon Feb 12 13:52:01 CET 2024
+
+////////////////////////////////////////////////////
+
+namespace Kernel
+{
+ //! @note Forward declarations.
+
+ class UserProcess;
+ class IPEFDLLObject;
+ class UserProcessTeam;
+ class UserProcessScheduler;
+ class UserProcessHelper;
+
+ //! @brief UserProcess identifier.
+ typedef Int64 ProcessID;
+
+ //! @brief UserProcess name length.
+ inline constexpr SizeT kProcessLen = 256U;
+
+ //! @brief UserProcess status enum.
+ enum class ProcessStatusKind : Int32
+ {
+ kStarting,
+ kRunning,
+ kKilled,
+ kFrozen,
+ kDead
+ };
+
+ //! @brief Affinity is the amount of nano-seconds this process is going
+ //! to run.
+ enum class AffinityKind : Int32
+ {
+ kRealTime = 500,
+ kVeryHigh = 250,
+ kHigh = 200,
+ kStandard = 1000,
+ kLowUsage = 1500,
+ kVeryLowUsage = 2000,
+ };
+
+ // operator overloading.
+
+ inline bool operator<(AffinityKind lhs, AffinityKind rhs)
+ {
+ Int32 lhs_int = static_cast<Int>(lhs);
+ Int32 rhs_int = static_cast<Int>(rhs);
+
+ return lhs_int < rhs_int;
+ }
+
+ inline bool operator>(AffinityKind lhs, AffinityKind rhs)
+ {
+ Int32 lhs_int = static_cast<Int>(lhs);
+ Int32 rhs_int = static_cast<Int>(rhs);
+
+ return lhs_int > rhs_int;
+ }
+
+ inline bool operator<=(AffinityKind lhs, AffinityKind rhs)
+ {
+ Int32 lhs_int = static_cast<Int>(lhs);
+ Int32 rhs_int = static_cast<Int>(rhs);
+
+ return lhs_int <= rhs_int;
+ }
+
+ inline bool operator>=(AffinityKind lhs, AffinityKind rhs)
+ {
+ Int32 lhs_int = static_cast<Int>(lhs);
+ Int32 rhs_int = static_cast<Int>(rhs);
+
+ return lhs_int >= rhs_int;
+ }
+
+ // end of operator overloading.
+
+ enum ProcessSubsystemEnum
+ {
+ eProcessSubsystemSecurity,
+ eProcessSubsystemNative,
+ eProcessSubsystemInvalid,
+ eProcessSubsystemCount,
+ };
+
+ using ProcessSubsystem = ProcessSubsystemEnum;
+ using ProcessTime = UInt64;
+ using PID = Int64;
+
+ // for permission manager, tells where we run the code.
+ enum class ProcessLevelRing : Int32
+ {
+ kRingStdUser = 1,
+ kRingSuperUser = 2,
+ kRingGuestUser = 5,
+ kRingCount = 5,
+ };
+
+ // Helper types.
+ using ImagePtr = VoidPtr;
+ using HeapPtrKind = VoidPtr;
+
+ /// @name UserProcess
+ /// @brief User process block.
+ /// Holds information about the running process/thread.
+ struct UserProcess final
+ {
+ public:
+ explicit UserProcess(VoidPtr startImage = nullptr)
+ : Image(startImage)
+ {
+ }
+
+ ~UserProcess() = default;
+
+ ZKA_COPY_DEFAULT(UserProcess)
+
+ public:
+ Void SetImageStart(VoidPtr imageStart) noexcept;
+ const UInt32& GetExitCode() noexcept;
+
+ public:
+ Char Name[kProcessLen] = {"PROCESS #0 (TEAM 0)"};
+ ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid};
+ User* Owner{nullptr};
+ HAL::StackFramePtr StackFrame{nullptr};
+ AffinityKind Affinity{AffinityKind::kStandard};
+ ProcessStatusKind Status{ProcessStatusKind::kDead};
+ UInt8* StackReserve{nullptr};
+
+ // Memory, images pointers.
+ ImagePtr Image{nullptr};
+
+ SizeT StackSize{mib_cast(8)};
+
+ //! @brief Shared library handle, reserved for kDLLKind types of executables only.
+ IPEFDLLObject* DLLPtr{nullptr};
+
+ /// @brief Parent process, reserved for threads only.
+ UserProcess* Parent{nullptr};
+
+ // Memory usage.
+ SizeT MemoryCursor{0};
+ SizeT MemoryLimit{gib_cast(128)};
+
+ struct PROCESS_MEMORY_ENTRY
+ {
+ VoidPtr MemoryEntry;
+
+ struct PROCESS_MEMORY_ENTRY* MemoryPrev;
+ struct PROCESS_MEMORY_ENTRY* MemoryNext;
+ }* MemoryEntryList{nullptr};
+
+ SizeT MemoryPD{0};
+
+ enum
+ {
+ kExeKind = 1,
+ kDLLKind = 2,
+ kKindCount,
+ };
+
+ ProcessTime PTime{0};
+ PID ProcessId{kSchedInvalidPID};
+ Int32 Kind{kExeKind};
+
+ public:
+ //! @brief boolean operator, check status.
+ operator bool()
+ {
+ return Status != ProcessStatusKind::kDead;
+ }
+
+ ///! @brief Crashes the app, exits with code ~0.
+ Void Crash();
+
+ ///! @brief Exits the app.
+ Void Exit(const Int32& exit_code = 0);
+
+ ///! @brief TLS allocate.
+ ///! @param sz size of new ptr.
+ VoidPtr New(const SizeT& sz);
+
+ ///! @brief TLS free.
+ ///! @param ptr the pointer to free.
+ ///! @param sz the size of it.
+ Boolean Delete(VoidPtr ptr, const SizeT& sz);
+
+ ///! @brief Wakes up threads.
+ Void Wake(const bool wakeup = false);
+
+ // UserProcess getters.
+ public:
+ ///! @brief Get the process's name
+ ///! @example 'C Runtime Library'
+ const Char* GetProcessName() noexcept;
+
+ //! @brief return local error code of process.
+ //! @return Int32 local error code.
+ Int32& GetLocalCode() noexcept;
+
+ const User* GetOwner() noexcept;
+ const ProcessStatusKind& GetStatus() noexcept;
+ const AffinityKind& GetAffinity() noexcept;
+
+ private:
+ UInt32 fLastExitCode{0};
+ Int32 fLocalCode{0};
+
+ friend UserProcessScheduler;
+ friend UserProcessHelper;
+ };
+
+ /// \brief Processs Team (contains multiple processes inside it.)
+ /// Equivalent to a process batch
+ class UserProcessTeam final
+ {
+ public:
+ explicit UserProcessTeam() = default;
+ ~UserProcessTeam() = default;
+
+ ZKA_COPY_DEFAULT(UserProcessTeam);
+
+ Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray();
+ Ref<UserProcess>& AsRef();
+ ProcessID& Id() noexcept;
+
+ public:
+ Array<UserProcess, kSchedProcessLimitPerTeam> mProcessList;
+ Ref<UserProcess> mCurrentProcess;
+ SizeT mProcessAmount{0};
+ ProcessID mTeamId{0};
+ };
+
+ using UserProcessPtr = UserProcess*;
+
+ /// @brief UserProcess scheduler class.
+ /// The main class which you call to schedule processes.
+ class UserProcessScheduler final : public ISchedulerObject
+ {
+ friend class UserProcessHelper;
+
+ public:
+ explicit UserProcessScheduler() = default;
+
+ ~UserProcessScheduler() = default;
+
+ ZKA_COPY_DEFAULT(UserProcessScheduler)
+
+ operator bool();
+ bool operator!();
+
+ public:
+ UserProcessTeam& CurrentTeam();
+
+ public:
+ SizeT Add(UserProcess processRef);
+ Bool Remove(ProcessID processSlot);
+
+ const Bool IsUser() override
+ {
+ return Yes;
+ }
+
+ const Bool IsKernel() override
+ {
+ return No;
+ }
+
+ const Bool HasMP() override
+ {
+ return kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled;
+ }
+
+ public:
+ Ref<UserProcess>& CurrentProcess();
+ SizeT Run() noexcept;
+
+ public:
+ STATIC UserProcessScheduler& The();
+
+ private:
+ UserProcessTeam mTeam;
+ };
+
+ /*
+ * \brief UserProcess helper class, which contains needed utilities for the scheduler.
+ */
+
+ class UserProcessHelper final
+ {
+ public:
+ STATIC bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, const PID& new_pid);
+ STATIC bool CanBeScheduled(const UserProcess& process);
+ STATIC PID& TheCurrentPID();
+ STATIC SizeT StartScheduling();
+ };
+
+ const UInt32& sched_get_exit_code(void) noexcept;
+} // namespace Kernel
+
+#include <KernelKit/ThreadLocalStorage.hxx>
+
+////////////////////////////////////////////////////
+
+// END
+
+////////////////////////////////////////////////////
+
+#endif /* ifndef _INC_PROCESS_SCHEDULER_HXX_ */
diff --git a/dev/zka/KernelKit/XCOFF.hxx b/dev/zka/KernelKit/XCOFF.hxx
new file mode 100644
index 00000000..82c6dd35
--- /dev/null
+++ b/dev/zka/KernelKit/XCOFF.hxx
@@ -0,0 +1,51 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: XCOFF.hpp
+ Purpose: XCOFF for Kernel.
+
+ Revision History:
+
+ 04/07/24: Added file (amlel)
+
+------------------------------------------- */
+
+#ifndef __INC_XCOFF_HXX__
+#define __INC_XCOFF_HXX__
+
+#include <NewKit/Defines.hxx>
+
+#define cXCOFF64Magic (0x01F7)
+
+#define cXCOFFRelFlg (0x0001)
+#define cXCOFFExecutable (0x0002)
+#define cXCOFFLnno (0x0004)
+#define cXCOFFLSyms (0x0008)
+
+struct XCoffFileHeader;
+struct XCoffForkHeader;
+
+/// @brief XCoff file header, meant for POWER apps.
+typedef struct XCoffFileHeader
+{
+ Kernel::UInt16 fMagic;
+ Kernel::UInt16 fTarget;
+ Kernel::UInt16 fNumSecs;
+ Kernel::UInt32 fTimeDat;
+ Kernel::UIntPtr fSymPtr;
+ Kernel::UInt32 fNumSyms;
+ Kernel::UInt16 fOptHdr; // ?: Number of bytes in optional header
+} XCoffFileHeader32, XCoffFileHeader64;
+
+#define cForkNameLen (255)
+
+/// @brief This the executable manifest fork.
+typedef struct XCoffForkHeader
+{
+ Kernel::Char fPropertiesXMLFork[cForkNameLen];
+ Kernel::Char fDynamicLoaderFork[cForkNameLen];
+ Kernel::Char fCodeSignFork[cForkNameLen];
+} XCoffForkHeader;
+
+#endif // ifndef __INC_XCOFF_HXX__
diff --git a/dev/zka/KernelRsrc.rsrc b/dev/zka/KernelRsrc.rsrc
new file mode 100644
index 00000000..dd476da2
--- /dev/null
+++ b/dev/zka/KernelRsrc.rsrc
@@ -0,0 +1,25 @@
+#include "CompilerKit/Version.hxx"
+
+1 VERSIONINFO
+FILEVERSION 1,0,0,0
+PRODUCTVERSION 1,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080904E4"
+ BEGIN
+ VALUE "CompanyName", "ZKA Technologies."
+ VALUE "FileDescription", "ZKA Kernel and System."
+ VALUE "FileVersion", KERNEL_VERSION
+ VALUE "InternalName", "newoskrnl"
+ VALUE "LegalCopyright", "(c) ZKA Technologies, all rights reserved."
+ VALUE "OriginalFilename", "newoskrnl.exe"
+ VALUE "ProductName", "ZKA Operating System"
+ VALUE "ProductVersion", KERNEL_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x809, 1252
+ END
+END
diff --git a/dev/zka/Modules/.gitkeep b/dev/zka/Modules/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/.gitkeep
diff --git a/dev/zka/Modules/ACPI/.gitkeep b/dev/zka/Modules/ACPI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/ACPI/.gitkeep
diff --git a/dev/zka/Modules/ACPI/ACPI.hxx b/dev/zka/Modules/ACPI/ACPI.hxx
new file mode 100644
index 00000000..00ba4f9e
--- /dev/null
+++ b/dev/zka/Modules/ACPI/ACPI.hxx
@@ -0,0 +1,88 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __ACPI__
+#define __ACPI__
+
+/**
+ https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html
+*/
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ class PACKED SDT
+ {
+ public:
+ Char Signature[4];
+ UInt32 Length;
+ UInt8 Revision;
+ Char Checksum;
+ Char OemId[6];
+ Char OemTableId[8];
+ UInt32 OemRev;
+ UInt32 CreatorID;
+ UInt32 CreatorRevision;
+ };
+
+ class PACKED RSDP : public SDT
+ {
+ public:
+ UInt32 RsdtAddress;
+ UIntPtr XsdtAddress;
+ UInt8 ExtendedChecksum;
+ UInt8 Reserved0[3];
+ };
+
+ class PACKED ConfigHeader
+ {
+ public:
+ UInt64 BaseAddress;
+ UInt16 PciSegGroup;
+ UInt8 StartBus;
+ UInt8 EndBus;
+ UInt32 Reserved;
+ };
+
+ enum ACPI_ADDRESS_SPACE_KIND : UInt8
+ {
+ eSystemMemory = 0,
+ eSystemIO = 1,
+ ePci = 2,
+ eController = 3,
+ eSmBus = 4,
+ eCount = 5,
+ eInvalid = 0xFF,
+ };
+
+ class PACKED ACPI_ADDRESS final
+ {
+ public:
+ UInt8 AddressSpaceId;
+ UInt8 RegisterBitWidth;
+ UInt8 RegisterBitOffset;
+ UInt8 Reserved;
+ UIntPtr Address;
+ };
+
+ class PACKED RSDT final
+ {
+ public:
+ Char Signature[4];
+ UInt32 Length;
+ UInt8 Revision;
+ Char Checksum;
+ Char OemId[6];
+ Char OemTableId[8];
+ UInt32 OemRev;
+ UInt32 CreatorID;
+ UInt32 CreatorRevision;
+ UInt32 AddressArr[];
+ };
+} // namespace Kernel
+
+#endif // !__ACPI__
diff --git a/dev/zka/Modules/ACPI/ACPIFactoryInterface.hxx b/dev/zka/Modules/ACPI/ACPIFactoryInterface.hxx
new file mode 100644
index 00000000..0d724f3b
--- /dev/null
+++ b/dev/zka/Modules/ACPI/ACPIFactoryInterface.hxx
@@ -0,0 +1,60 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __MOD_ACPI_HXX__
+#define __MOD_ACPI_HXX__
+
+#include <KernelKit/DebugOutput.hxx>
+#include <Modules/ACPI/ACPI.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ class ACPIFactoryInterface;
+
+ typedef ACPIFactoryInterface PowerFactoryInterface;
+
+ class ACPIFactoryInterface final
+ {
+ public:
+ explicit ACPIFactoryInterface(voidPtr rsdPtr);
+ ~ACPIFactoryInterface() = default;
+
+ ACPIFactoryInterface& operator=(const ACPIFactoryInterface&) = default;
+ ACPIFactoryInterface(const ACPIFactoryInterface&) = default;
+
+ public:
+ Void Shutdown(); // shutdown
+ Void Reboot(); // soft-reboot
+
+ public:
+ /// @brief Descriptor find factory.
+ /// @param signature The signature of the descriptor table (MADT, ACPI...)
+ /// @return the blob inside an ErrorOr object.
+ ErrorOr<voidPtr> Find(const Char* signature);
+
+ /// @brief Checksum factory.
+ /// @param checksum the data to checksum
+ /// @param len it's size
+ /// @return if it succeed
+ bool Checksum(const Char* checksum, SSizeT len); // watch for collides!
+
+ public:
+ ErrorOr<voidPtr> operator[](const Char* signature)
+ {
+ return this->Find(signature);
+ }
+
+ private:
+ VoidPtr fRsdp; // pointer to root descriptor.
+ SSizeT fEntries; // number of entries, -1 tells that no invalid entries were
+ // found.
+ };
+} // namespace Kernel
+
+#endif // !__MOD_ACPI_HXX__
diff --git a/dev/zka/Modules/AHCI/.gitkeep b/dev/zka/Modules/AHCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/AHCI/.gitkeep
diff --git a/dev/zka/Modules/AHCI/AHCI.hxx b/dev/zka/Modules/AHCI/AHCI.hxx
new file mode 100644
index 00000000..e588ec25
--- /dev/null
+++ b/dev/zka/Modules/AHCI/AHCI.hxx
@@ -0,0 +1,370 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Defines.hxx
+ Purpose: AHCI header.
+
+ Revision History:
+
+ 03/02/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <Modules/ACPI/ACPI.hxx>
+
+// Forward declarations of structs.
+
+#define kAHCISectorSize (512U)
+
+struct HbaPort;
+struct FisData;
+struct FisRegD2H;
+struct FisRegH2D;
+
+/// @brief Frame information type.
+enum
+{
+ kFISTypeRegH2D = 0x27, // Register FIS - host to device
+ kFISTypeRegD2H = 0x34, // Register FIS - device to host
+ kFISTypeDMAAct = 0x39, // DMA activate FIS - device to host
+ kFISTypeDMASetup = 0x41, // DMA setup FIS - bidirectional
+ kFISTypeData = 0x46, // Data FIS - bidirectional
+ kFISTypeBIST = 0x58, // BIST activate FIS - bidirectional
+ kFISTypePIOSetup = 0x5F, // PIO setup FIS - device to host
+ kFISTypeDevBits = 0xA1, // Set device bits FIS - device to host
+};
+
+enum
+{
+ kAHCICmdIdentify = 0xEC,
+ kAHCICmdReadDma = 0xC8,
+ kAHCICmdReadDmaEx = 0x25,
+ kAHCICmdWriteDma = 0xCA,
+ kAHCICmdWriteDmaEx = 0x35
+};
+
+typedef struct FisRegH2D final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_REG_H2D
+
+ Kernel::UInt8 PortMul : 4; // Port multiplier
+ Kernel::UInt8 Reserved0 : 3; // Reserved
+ Kernel::UInt8 CmdOrCtrl : 1; // 1: Command, 0: Control
+
+ Kernel::UInt8 Command; // Command register
+ Kernel::UInt8 Featurel; // Feature register, 7:0
+
+ // DWORD 1
+ Kernel::UInt8 Lba0; // LBA low register, 7:0
+ Kernel::UInt8 Lba1; // LBA mid register, 15:8
+ Kernel::UInt8 Lba2; // LBA high register, 23:16
+ Kernel::UInt8 Device; // Device register
+
+ // DWORD 2
+ Kernel::UInt8 Lba3; // LBA register, 31:24
+ Kernel::UInt8 Lba4; // LBA register, 39:32
+ Kernel::UInt8 Lba5; // LBA register, 47:40
+ Kernel::UInt8 FeatureHigh; // Feature register, 15:8
+
+ // DWORD 3
+ Kernel::UInt8 CountLow; // Count register, 7:0
+ Kernel::UInt8 CountHigh; // Count register, 15:8
+ Kernel::UInt8 Icc; // Isochronous command completion
+ Kernel::UInt8 Control; // Control register
+
+ // DWORD 4
+ Kernel::UInt8 Reserved1[4]; // Reserved
+} FisRegH2D;
+
+typedef struct FisRegD2H final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_REG_D2H
+
+ Kernel::UInt8 PortMul : 4; // Port multiplier
+ Kernel::UInt8 Reserved0 : 2; // Reserved
+ Kernel::UInt8 InterruptBit : 1; // Interrupt bit
+ Kernel::UInt8 Reserved1 : 1; // Reserved
+
+ Kernel::UInt8 Status; // Status register
+ Kernel::UInt8 Rrror; // Error register
+
+ // DWORD 1
+ Kernel::UInt8 Lba0; // LBA low register, 7:0
+ Kernel::UInt8 Lba1; // LBA mid register, 15:8
+ Kernel::UInt8 Lba2; // LBA high register, 23:16
+ Kernel::UInt8 Device; // Device register
+
+ // DWORD 2
+ Kernel::UInt8 Lba3; // LBA register, 31:24
+ Kernel::UInt8 Lba4; // LBA register, 39:32
+ Kernel::UInt8 Lba5; // LBA register, 47:40
+ Kernel::UInt8 Rsv2; // Reserved
+
+ // DWORD 3
+ Kernel::UInt8 CountLow; // Count register, 7:0
+ Kernel::UInt8 CountHigh; // Count register, 15:8
+ Kernel::UInt8 Rsv3[2]; // Reserved
+
+ // DWORD 4
+ Kernel::UInt8 Rsv4[4]; // Reserved
+} FisRegD2H;
+
+typedef struct FisData final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_DATA
+
+ Kernel::UInt8 PortMul : 4; // Port multiplier
+ Kernel::UInt8 Reserved0 : 4; // Reserved
+
+ Kernel::UInt8 Reserved1[2]; // Reserved
+
+ // DWORD 1 ~ N
+ Kernel::UInt32 Data[1]; // Payload
+} FisData;
+
+typedef struct FisPioSetup final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_PIO_SETUP
+
+ Kernel::UInt8 PortMul : 4; // Port multiplier
+ Kernel::UInt8 Reserved0 : 1; // Reserved
+ Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host
+ Kernel::UInt8 InterruptBit : 1; // Interrupt bit
+ Kernel::UInt8 Reserved1 : 1;
+
+ Kernel::UInt8 Status; // Status register
+ Kernel::UInt8 Error; // Error register
+
+ // DWORD 1
+ Kernel::UInt8 Lba0; // LBA low register, 7:0
+ Kernel::UInt8 Lba1; // LBA mid register, 15:8
+ Kernel::UInt8 Lba2; // LBA high register, 23:16
+ Kernel::UInt8 Device; // Device register
+
+ // DWORD 2
+ Kernel::UInt8 Lba3; // LBA register, 31:24
+ Kernel::UInt8 Lba4; // LBA register, 39:32
+ Kernel::UInt8 Lba5; // LBA register, 47:40
+ Kernel::UInt8 Rsv2; // Reserved
+
+ // DWORD 3
+ Kernel::UInt8 CountLow; // Count register, 7:0
+ Kernel::UInt8 CountHigh; // Count register, 15:8
+ Kernel::UInt8 Rsv3; // Reserved
+ Kernel::UInt8 EStatus; // New value of status register
+
+ // DWORD 4
+ Kernel::UInt16 TranferCount; // Transfer count
+ Kernel::UInt8 Rsv4[2]; // Reserved
+} FisPioSetup;
+
+typedef struct FisDmaSetup final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_DMA_SETUP
+
+ Kernel::UInt8 PortMul : 4; // Port multiplier
+ Kernel::UInt8 Reserved0 : 1; // Reserved
+ Kernel::UInt8 DTD : 1; // Data transfer direction, 1 - device to host
+ Kernel::UInt8 InterruptBit : 1; // Interrupt bit
+ Kernel::UInt8 AutoEnable : 1; // Auto-activate. Specifies if DMA Activate FIS is needed
+
+ Kernel::UInt8 Reserved1[2]; // Reserved
+
+ // DWORD 1&2
+ Kernel::UInt64 DmaBufferId; // DMA Buffer Identifier. Used to Identify DMA buffer in
+ // host memory. SATA Spec says host specific and not in
+ // Spec. Trying AHCI spec might work.
+
+ // DWORD 3
+ Kernel::UInt32 Rsvd; // More reserved
+
+ // DWORD 4
+ Kernel::UInt32 DmabufOffset; // Byte offset into buffer. First 2 bits must be 0
+
+ // DWORD 5
+ Kernel::UInt32 TransferCount; // Number of bytes to transfer. Bit 0 must be 0
+
+ // DWORD 6
+ Kernel::UInt32 Reserved3; // Reserved
+} FisDmaSetup;
+
+typedef struct FisDevBits final
+{
+ // DWORD 0
+ Kernel::UInt8 FisType; // FIS_TYPE_DMA_SETUP (A1h)
+
+ Kernel::UInt8 Reserved0 : 5; // Reserved
+ Kernel::UInt8 R0 : 1;
+ Kernel::UInt8 InterruptBit : 1;
+ Kernel::UInt8 N : 1;
+
+ Kernel::UInt8 StatusLow : 3;
+ Kernel::UInt8 R1 : 1;
+ Kernel::UInt8 StatusHigh : 3;
+
+ Kernel::UInt8 R2 : 1;
+ Kernel::UInt8 Error;
+
+ // DWORD 1
+ Kernel::UInt32 Act;
+} FisDevBits;
+
+/// \brief Enable AHCI device bit in GHC register.
+#ifndef kAhciGHC_AE
+#define kAhciGHC_AE (31)
+#endif //! ifndef kAhciGHC_AE
+
+typedef struct HbaPort final
+{
+ Kernel::UInt32 Clb; // 0x00, command list base address, 1K-byte aligned
+ Kernel::UInt32 Clbu; // 0x04, command list base address upper 32 bits
+ Kernel::UInt32 Fb; // 0x08, FIS base address, 256-byte aligned
+ Kernel::UInt32 Fbu; // 0x0C, FIS base address upper 32 bits
+ Kernel::UInt32 Is; // 0x10, interrupt status
+ Kernel::UInt32 Ie; // 0x14, interrupt enable
+ Kernel::UInt32 Cmd; // 0x18, command and status
+ Kernel::UInt32 Reserved0; // 0x1C, Reserved
+ Kernel::UInt32 Tfd; // 0x20, task file data
+ Kernel::UInt32 Sig; // 0x24, signature
+ Kernel::UInt32 Ssts; // 0x28, SATA status (SCR0:SStatus)
+ Kernel::UInt32 Sctl; // 0x2C, SATA control (SCR2:SControl)
+ Kernel::UInt32 Serr; // 0x30, SATA error (SCR1:SError)
+ Kernel::UInt32 Sact; // 0x34, SATA active (SCR3:SActive)
+ Kernel::UInt32 Ci; // 0x38, command issue
+ Kernel::UInt32 Sntf; // 0x20, SATA notification (SCR4:SNotification)
+ Kernel::UInt32 Fbs; // 0x40, FIS-based switch control
+ Kernel::UInt32 Reserved1[11]; // 0x44 ~ 0x6F, Reserved
+ Kernel::UInt32 Vendor[4]; // 0x70 ~ 0x7F, vendor specific
+} HbaPort;
+
+typedef struct HbaMem final
+{
+ // 0x00 - 0x2B, Generic Host Control
+ Kernel::UInt32 Cap; // 0x00, Host capability
+ Kernel::UInt32 Ghc; // 0x04, Global host control
+ Kernel::UInt32 Is; // 0x08, Interrupt status
+ Kernel::UInt32 Pi; // 0x0C, Port implemented
+ Kernel::UInt32 Vs; // 0x10, Version
+ Kernel::UInt32 Ccc_ctl; // 0x14, Command completion coalescing control
+ Kernel::UInt32 Ccc_pts; // 0x18, Command completion coalescing ports
+ Kernel::UInt32 Em_loc; // 0x1C, Enclosure management location
+ Kernel::UInt32 Em_ctl; // 0x20, Enclosure management control
+ Kernel::UInt32 Cap2; // 0x24, Host capabilities extended
+ Kernel::UInt32 Bohc; // 0x28, BIOS/OS handoff control and status
+
+ Kernel::UInt16 Resv0;
+ Kernel::UInt32 Resv2;
+
+ HbaPort Ports[1]; // 1 ~ 32, 32 is the max ahci devices per controller.
+} HbaMem;
+
+typedef struct HbaCmdHeader final
+{
+ // DW0
+ Kernel::UInt8 Cfl : 5; // Command FIS length in DWORDS, 2 ~ 16
+ Kernel::UInt8 Atapi : 1; // ATAPI
+ Kernel::UInt8 Write : 1; // Write, 1: H2D, 0: D2H
+ Kernel::UInt8 Prefetchable : 1; // Prefetchable
+
+ Kernel::UInt8 Reset : 1; // Reset
+ Kernel::UInt8 BIST : 1; // BIST
+ Kernel::UInt8 Clear : 1; // Clear busy upon R_OK
+ Kernel::UInt8 Reserved0 : 1; // Reserved
+ Kernel::UInt8 Pmp : 4; // Port multiplier port
+
+ Kernel::UInt16 Prdtl; // Physical region descriptor table length in entries
+ volatile Kernel::UInt32 Prdbc; // Physical region descriptor byte count transferred
+
+ Kernel::UInt32 Ctba; // Command table descriptor base address
+ Kernel::UInt32 Ctbau; // Command table descriptor base address upper 32 bits
+
+ Kernel::UInt32 Reserved1[4]; // Reserved
+} HbaCmdHeader;
+
+typedef struct HbaFis final
+{
+ // 0x00
+ FisDmaSetup Dsfis; // DMA Setup FIS
+ Kernel::UInt8 Pad0[4];
+ // 0x20
+ FisPioSetup Psfis; // PIO Setup FIS
+ Kernel::UInt8 Pad1[12];
+ // 0x40
+ FisRegD2H Rfis; // Register – Device to Host FIS
+ Kernel::UInt8 Pad2[4];
+ // 0x58
+ FisDevBits Sdbfis; // Set Device Bit FIS
+ // 0x60
+ Kernel::UInt8 Ufis[64];
+ // 0xA0
+ Kernel::UInt8 Rsv[0x100 - 0xA0];
+} HbaFis;
+
+typedef struct HbaPrdtEntry final
+{
+ Kernel::UInt32 Dba; // Data base address
+ Kernel::UInt32 Dbau; // Data base address upper 32 bits
+ Kernel::UInt32 Reserved0; // Reserved
+ // DW3
+ Kernel::UInt32 Dbc : 22; // Byte count, 4M max
+ Kernel::UInt32 Reserved1 : 9; // Reserved
+ Kernel::UInt32 InterruptBit : 1; // Interrupt on completion
+} HbaPrdtEntry;
+
+typedef struct HbaCmdTbl final
+{
+ Kernel::UInt8 Cfis[64]; // Command FIS
+ Kernel::UInt8 Acmd[16]; // ATAPI command, 12 or 16 bytes
+ Kernel::UInt8 Rsv[48]; // Reserved
+ struct HbaPrdtEntry prdtEntries[1]; // Physical region descriptor table entries, 0 ~ 65535
+} HbaCmdTbl;
+
+/* EOF */
+
+#if defined(__AHCI__)
+
+/// @brief Initializes an AHCI disk.
+/// @param PortsImplemented the amount of port that have been detected.
+/// @return
+Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented);
+
+Kernel::Boolean drv_std_detected(Kernel::Void);
+
+/// @brief Read from disk.
+/// @param Lba
+/// @param Buf
+/// @param SectorSz
+/// @param Size
+/// @return
+Kernel::Void drv_std_read(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size);
+
+/// @brief Write to disk.
+/// @param Lba
+/// @param Buf
+/// @param SectorSz
+/// @param Size
+/// @return
+Kernel::Void drv_std_write(Kernel::UInt64 Lba, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size);
+
+/// @brief get sector count.
+Kernel::SizeT drv_get_sector_count();
+
+/// @brief get device size.
+Kernel::SizeT drv_get_size();
+
+/// @brief get sector count.
+Kernel::SizeT drv_get_sector_count();
+
+/// @brief get device size.
+Kernel::SizeT drv_get_size();
+
+#endif // ifdef __NEWOSKRNL__
diff --git a/dev/zka/Modules/APM/.gitkeep b/dev/zka/Modules/APM/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/APM/.gitkeep
diff --git a/dev/zka/Modules/ATA/ATA.hxx b/dev/zka/Modules/ATA/ATA.hxx
new file mode 100644
index 00000000..f550ddc6
--- /dev/null
+++ b/dev/zka/Modules/ATA/ATA.hxx
@@ -0,0 +1,156 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Defines.hxx
+ Purpose: ATA header.
+
+ Revision History:
+
+ 03/02/24: Added file (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#ifndef __AHCI__
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/Defines.hxx>
+
+///! Status register
+#define ATA_SR_BSY 0x80
+#define ATA_SR_DRDY 0x40
+#define ATA_SR_DF 0x20
+#define ATA_SR_DSC 0x10
+#define ATA_SR_DRQ 0x08
+#define ATA_SR_CORR 0x04
+#define ATA_SR_IDX 0x02
+#define ATA_SR_ERR 0x01
+
+///! Error register
+#define ATA_ER_BBK 0x80
+#define ATA_ER_UNC 0x40
+#define ATA_ER_MC 0x20
+#define ATA_ER_IDNF 0x10
+#define ATA_ER_MCR 0x08
+#define ATA_ER_ABRT 0x04
+#define ATA_ER_TK0NF 0x02
+#define ATA_ER_AMNF 0x01
+
+#define ATA_CMD_READ_PIO 0x20
+#define ATA_CMD_READ_PIO_EXT 0x24
+#define ATA_CMD_READ_DMA 0xC8
+#define ATA_CMD_READ_DMA_EXT 0x25
+#define ATA_CMD_WRITE_PIO 0x30
+#define ATA_CMD_WRITE_PIO_EXT 0x34
+#define ATA_CMD_WRITE_DMA 0xCA
+#define ATA_CMD_WRITE_DMA_EXT 0x35
+#define ATA_CMD_CACHE_FLUSH 0xE7
+#define ATA_CMD_CACHE_FLUSH_EXT 0xEA
+#define ATA_CMD_PACKET 0xA0
+#define ATA_CMD_IDENTIFY_PACKET 0xA1
+#define ATA_CMD_IDENTIFY 0xEC
+
+///! ident offsets, use with data that we got from ATA_CMD_IDENTIFY.
+#define ATA_IDENT_DEVICE_TYPE 0
+#define ATA_IDENT_CYLINDERS 2
+#define ATA_IDENT_HEADS 6
+#define ATA_IDENT_SECTORS 12
+#define ATA_IDENT_SERIAL 20
+#define ATA_IDENT_MODEL 54
+#define ATA_IDENT_CAPABILITIES 98
+#define ATA_IDENT_FIELDVALID 106
+#define ATA_IDENT_MAX_LBA 120
+#define ATA_IDENT_COMMANDSETS 164
+#define ATA_IDENT_MAX_LBA_EXT 200
+
+#define ATA_MASTER 0x00
+#define ATA_SLAVE 0x01
+
+///! Register
+#define ATA_REG_DATA 0x00
+#define ATA_REG_ERROR 0x01
+#define ATA_REG_FEATURES 0x01
+#define ATA_REG_SEC_COUNT0 0x02
+#define ATA_REG_LBA0 0x03
+#define ATA_REG_LBA1 0x04
+#define ATA_REG_LBA2 0x05
+#define ATA_REG_HDDEVSEL 0x06
+#define ATA_REG_COMMAND 0x07
+#define ATA_REG_STATUS 0x07
+#define ATA_REG_SEC_COUNT1 0x08
+#define ATA_REG_LBA3 0x09
+#define ATA_REG_LBA4 0x0A
+#define ATA_REG_LBA5 0x0B
+#define ATA_REG_CONTROL 0x0C
+#define ATA_REG_ALT_STATUS 0x0C
+#define ATA_REG_DEV_ADDRESS 0x0D
+
+#define ATA_REG_NEIN 0x01
+
+#define ATA_PRIMARY_IO 0x1F0
+#define ATA_SECONDARY_IO 0x170
+#define ATA_PRIMARY_DCR_AS 0x3F6
+#define ATA_SECONDARY_DCR_AS 0x376
+
+///! Irq
+#define ATA_PRIMARY_IRQ 14
+#define ATA_SECONDARY_IRQ 15
+
+///! Channels
+#define ATA_PRIMARY 0x00
+#define ATA_SECONDARY 0x01
+
+#define ATA_CYL_LOW 3
+#define ATA_CYL_MID 4
+#define ATA_CYL_HIGH 5
+
+///! IO Direction
+#define ATA_READ 0x00
+#define ATA_WRITE 0x013
+
+#define ATA_PRIMARY_SEL 0xA0
+#define ATA_SECONDARY_SEL 0xB0
+
+///! ATA address register.
+#define ATA_ADDRESS1(x) (x + 3)
+#define ATA_ADDRESS2(x) (x + 4)
+#define ATA_ADDRESS3(x) (x + 5)
+
+///! ATA command register.
+#define ATA_COMMAND(x) (x + 7)
+
+#define kATASectorSize (512U)
+
+enum
+{
+ kATADevicePATA,
+ kATADeviceSATA,
+ kATADevicePATA_PI,
+ kATADeviceSATA_PI,
+ kATADeviceCount,
+};
+
+#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
+
+Kernel::Boolean drv_std_init(Kernel::UInt16 Bus, Kernel::UInt8 Drive, Kernel::UInt16& OutBus, Kernel::UInt8& OutMaster);
+
+Kernel::Boolean drv_std_detected(Kernel::Void);
+
+Kernel::Void drv_std_select(Kernel::UInt16 Bus);
+
+Kernel::Boolean drv_std_wait_io(Kernel::UInt16 IO);
+
+Kernel::Void drv_std_read(Kernel::UInt64 Lba, Kernel::UInt16 IO, Kernel::UInt8 Master, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size);
+
+Kernel::Void drv_std_write(Kernel::UInt64 Lba, Kernel::UInt16 IO, Kernel::UInt8 Master, Kernel::Char* Buf, Kernel::SizeT SectorSz, Kernel::SizeT Size);
+
+/// @brief get sector count.
+Kernel::SizeT drv_get_sector_count();
+
+/// @brief get device size.
+Kernel::SizeT drv_get_size();
+
+#endif // ifdef __NEWOSKRNL__
+#endif // ifndef __ATA_PIO__ || __AHCI__
diff --git a/dev/zka/Modules/CoreCG/Accessibility.hxx b/dev/zka/Modules/CoreCG/Accessibility.hxx
new file mode 100644
index 00000000..4a3efbcb
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/Accessibility.hxx
@@ -0,0 +1,47 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __CORECG_ACCESS_HXX__
+#define __CORECG_ACCESS_HXX__
+
+#include <NewKit/NewKit.hxx>
+#include <KernelKit/LPC.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <Modules/CoreCG/Math.hxx>
+#include <ArchKit/ArchKit.hxx>
+
+namespace CG
+{
+ using namespace Kernel;
+
+ /// @brief common User interface class.
+ class UIAccessibilty final
+ {
+ explicit UIAccessibilty() = default;
+ ~UIAccessibilty() = default;
+
+ public:
+ ZKA_COPY_DELETE(UIAccessibilty);
+
+ STATIC UIAccessibilty& The()
+ {
+ STATIC UIAccessibilty the;
+ return the;
+ }
+
+ Int64 Width() noexcept
+ {
+ return kHandoverHeader->f_GOP.f_Width;
+ }
+
+ Int64 Height() noexcept
+ {
+ return kHandoverHeader->f_GOP.f_Height;
+ }
+ };
+} // namespace CG
+
+#endif // !__CORECG_ACCESS_HXX__
diff --git a/dev/zka/Modules/CoreCG/FbRenderer.hxx b/dev/zka/Modules/CoreCG/FbRenderer.hxx
new file mode 100644
index 00000000..ca660602
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/FbRenderer.hxx
@@ -0,0 +1,154 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#define CGInit() Kernel::SizeT __GXCursor = 0
+
+#define CGColor(R, G, B) RGB(R, G, B)
+
+#define cCGClearClr CGColor(0x0, 0x0, 0x0)
+
+#define CGFini() __GXCursor = 0
+
+/// @brief Performs OR drawing on the framebuffer.
+#define CGDrawBitMapInRegionA(_BitMp, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT i = _BaseX; i < (_Height + _BaseX); ++i) \
+ { \
+ for (Kernel::SizeT u = _BaseY; u < (_Width + _BaseY); ++u) \
+ { \
+ *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ i + \
+ 4 * u))) |= (_BitMp)[__GXCursor]; \
+ \
+ ++__GXCursor; \
+ } \
+ }
+
+/// @brief Draws a resource.
+#define CGDrawBitMapInRegion(_BitMp, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT i = _BaseX; i < (_Height + _BaseX); ++i) \
+ { \
+ for (Kernel::SizeT u = _BaseY; u < (_Width + _BaseY); ++u) \
+ { \
+ *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ i + \
+ 4 * u))) = (_BitMp)[__GXCursor]; \
+ \
+ ++__GXCursor; \
+ } \
+ }
+
+#define CGDrawBitMapInRegionToRgn(_Rgn, _BitMp, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT i = _BaseX; i < (_Height + _BaseX); ++i) \
+ { \
+ for (Kernel::SizeT u = _BaseY; u < (_Width + _BaseY); ++u) \
+ { \
+ *(((Kernel::UInt32*)(_Rgn + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ i + \
+ 4 * u))) = (_BitMp)[__GXCursor]; \
+ \
+ ++__GXCursor; \
+ } \
+ }
+
+/// @brief Cleans a resource.
+#define CGClearRegion(_Height, _Width, _BaseX, _BaseY) \
+ \
+ for (Kernel::SizeT i = _BaseX; i < _Height + _BaseX; ++i) \
+ { \
+ for (Kernel::SizeT u = _BaseY; u < _Width + _BaseY; ++u) \
+ { \
+ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ i + \
+ 4 * u))) = cCGClearClr; \
+ } \
+ }
+
+/// @brief Draws inside a zone.
+#define CGDrawInRegion(_Clr, _Height, _Width, _BaseX, _BaseY) \
+ \
+ for (Kernel::SizeT x_base = _BaseX; x_base < (_Width + _BaseX); ++x_base) \
+ { \
+ for (Kernel::SizeT y_base = _BaseY; y_base < (_Height + _BaseY); ++y_base) \
+ { \
+ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ x_base + \
+ 4 * y_base))) = _Clr; \
+ } \
+ }
+
+/// @brief Draws inside a zone.
+#define CGDrawInRegionToRgn(_Rgn, _Clr, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT x_base = _BaseX; x_base < (_Width + _BaseX); ++x_base) \
+ { \
+ for (Kernel::SizeT y_base = _BaseY; y_base < (_Height + _BaseY); ++y_base) \
+ { \
+ *(((volatile Kernel::UInt32*)(_Rgn + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ x_base + \
+ 4 * y_base))) = _Clr[__GXCursor]; \
+ ++__GXCursor; \
+ } \
+ }
+
+#define CGDrawInRegionToVideoRgn(_VideoRgn, _Clr, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT x_base = _BaseX; x_base < (_Width + _BaseX); ++x_base) \
+ { \
+ for (Kernel::SizeT y_base = _BaseY; y_base < (_Height + _BaseY); ++y_base) \
+ { \
+ *(((volatile Kernel::UInt32*)(_VideoRgn + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ x_base + \
+ 4 * y_base))) = _Clr; \
+ ++__GXCursor; \
+ } \
+ }
+
+#define CGDrawInRegionToVideoRgnA(_VideoRgn, _Clr, _Height, _Width, _BaseX, _BaseY) \
+ __GXCursor = 0; \
+ \
+ for (Kernel::SizeT x_base = _BaseX; x_base < (_Width + _BaseX); ++x_base) \
+ { \
+ for (Kernel::SizeT y_base = _BaseY; y_base < (_Height + _BaseY); ++y_base) \
+ { \
+ *(((volatile Kernel::UInt32*)(_VideoRgn + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ x_base + \
+ 4 * y_base))) |= _Clr; \
+ ++__GXCursor; \
+ } \
+ }
+
+#define CGDrawInRegionA(_Clr, _Height, _Width, _BaseX, _BaseY) \
+ \
+ for (Kernel::SizeT x_base = _BaseX; x_base < (_Width + _BaseX); ++x_base) \
+ { \
+ for (Kernel::SizeT y_base = _BaseY; y_base < (_Height + _BaseY); ++y_base) \
+ { \
+ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \
+ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
+ x_base + \
+ 4 * y_base))) |= _Clr; \
+ } \
+ }
diff --git a/dev/zka/Modules/CoreCG/Math.hxx b/dev/zka/Modules/CoreCG/Math.hxx
new file mode 100644
index 00000000..bfa28a3d
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/Math.hxx
@@ -0,0 +1,22 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+/// @file Math.hxx
+/// @brief Linear interpolation implementation.
+
+typedef float CGReal;
+
+/// @brief Linear interpolation equation solver.
+/// @param from where?
+/// @param to to?
+/// @param at which state we're at **to**.
+inline CGReal CGLerp(CGReal to, CGReal from, CGReal stat)
+{
+ CGReal difference = to - from;
+ return from + (difference * stat);
+}
diff --git a/dev/zka/Modules/CoreCG/Rsrc/Cursor.rsrc b/dev/zka/Modules/CoreCG/Rsrc/Cursor.rsrc
new file mode 100644
index 00000000..2283cb32
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/Rsrc/Cursor.rsrc
@@ -0,0 +1,64 @@
+#define cCurHeight (57)
+#define cCurWidth (53)
+
+#define cCurLength (3021)
+
+static const unsigned int Cursor[cCurLength] = {
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0x474747, 0x474747, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x363636, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x363636, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xa5a5a5, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x686868, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x585858, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0x585858, 0x222222, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x363636, 0x000000, 0x000000, 0x000000, 0x686868, 0xebebeb, 0xf9f9f9, 0x969696, 0x000000, 0x000000, 0x000000, 0x222222, 0xdedede, 0xf9f9f9, 0xdedede, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x575757, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xdedede, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x000000, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0x575757, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x000000, 0x585858, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x000000, 0x777777, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0x474747, 0x474747, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x777777, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xcfcfcf, 0x000000, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x363636, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0xb3b3b3, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x686868, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x363636, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x222222, 0x222222, 0x363636, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x222222, 0x000000, 0x000000, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x686868, 0x686868, 0xcfcfcf, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xcfcfcf, 0xd0d0d0, 0xdedede, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x222222, 0x000000, 0x000000, 0xa5a5a5, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x000000, 0x686868, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xcfcfcf, 0x000000, 0x000000, 0x585858, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x363636, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x686868, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xd0d0d0, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x585858, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xb3b3b3, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xa5a5a5, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x0e0e0e, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x686868, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x969696, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xcfcfcf, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xb3b3b3, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x0e0e0e, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x787878, 0x000000, 0x777777, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x0e0e0e, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0xb4b4b4, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x0e0e0e, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x686868, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0xb4b4b4, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x000000, 0x000000, 0xebebeb, 0xf9f9f9, 0xdedede, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcfcfcf, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x979797, 0x000000, 0x474747, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x474747, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0x363636, 0x000000, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xececec, 0x0e0e0e, 0x000000, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0x878787, 0x000000, 0x777777, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xa5a5a5, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x343434, 0xebebeb, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x575757, 0x000000, 0x878787, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xb3b3b3, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x343434, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x0e0e0e, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x222222, 0x222222, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xc2c2c2, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x686868, 0xdedede, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x686868, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x777777, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xdedede, 0x222222, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xcfcfcf, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0x585858, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x222222, 0xc2c2c2, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xf9f9f9, 0xebebeb, 0x585858, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x474747, 0x878787, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0xa5a5a5, 0x979797, 0x686868, 0x0e0e0e, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
+};
diff --git a/dev/zka/Modules/CoreCG/Rsrc/WndControls.rsrc b/dev/zka/Modules/CoreCG/Rsrc/WndControls.rsrc
new file mode 100644
index 00000000..a7024fde
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/Rsrc/WndControls.rsrc
@@ -0,0 +1,61 @@
+#define FLATCONTROLS_HEIGHT 24
+#define FLATCONTROLS_WIDTH 44
+
+// array size is 3168
+static inline const unsigned int FlatControls[] = {
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x3e3e3e, 0xe0e0e0, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xe0e0e0, 0x3e3e3e, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
+ 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
+};
+
+#define FLATCONTROLS_CLOSE_HEIGHT 24
+#define FLATCONTROLS_CLOSE_WIDTH 44
+
+// array size is 3168
+static inline const unsigned int FlatControlsClose[] = {
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xfac7c7, 0xee3636, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xee3535, 0xfac7c7, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616,
+ 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616, 0xeb1616
+};
diff --git a/dev/zka/Modules/CoreCG/TextRenderer.hxx b/dev/zka/Modules/CoreCG/TextRenderer.hxx
new file mode 100644
index 00000000..34caa420
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/TextRenderer.hxx
@@ -0,0 +1,176 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+
+#define FONT_SIZE_X 8
+#define FONT_SIZE_Y 8
+#define FONT_NOF_CHARS 128
+
+inline const Kernel::UInt8 cFontBitmap[FONT_NOF_CHARS][FONT_SIZE_X] = {
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0003
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0004
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0005
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0006
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0007
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0008
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0009
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000A
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000B
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000C
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000D
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000E
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+000F
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0010
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0011
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0012
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0013
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0014
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0015
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0016
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0017
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0018
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0019
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001A
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001B
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001C
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001D
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001E
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+001F
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space)
+ {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!)
+ {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (")
+ {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#)
+ {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, // U+0024 ($)
+ {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, // U+0025 (%)
+ {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, // U+0026 (&)
+ {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0027 (')
+ {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, // U+0028 (()
+ {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, // U+0029 ())
+ {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, // U+002A (*)
+ {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, // U+002B (+)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+002C (,)
+ {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, // U+002D (-)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+002E (.)
+ {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, // U+002F (/)
+ {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, // U+0030 (0)
+ {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, // U+0031 (1)
+ {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, // U+0032 (2)
+ {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, // U+0033 (3)
+ {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, // U+0034 (4)
+ {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, // U+0035 (5)
+ {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, // U+0036 (6)
+ {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, // U+0037 (7)
+ {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, // U+0038 (8)
+ {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, // U+0039 (9)
+ {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, // U+003A (:)
+ {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, // U+003B (;)
+ {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, // U+003C (<)
+ {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, // U+003D (=)
+ {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, // U+003E (>)
+ {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, // U+003F (?)
+ {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, // U+0040 (@)
+ {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, // U+0041 (A)
+ {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, // U+0042 (B)
+ {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, // U+0043 (C)
+ {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, // U+0044 (D)
+ {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, // U+0045 (E)
+ {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, // U+0046 (F)
+ {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, // U+0047 (G)
+ {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, // U+0048 (H)
+ {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0049 (I)
+ {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, // U+004A (J)
+ {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, // U+004B (K)
+ {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, // U+004C (L)
+ {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, // U+004D (M)
+ {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, // U+004E (N)
+ {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, // U+004F (O)
+ {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, // U+0050 (P)
+ {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, // U+0051 (Q)
+ {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, // U+0052 (R)
+ {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, // U+0053 (S)
+ {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0054 (T)
+ {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, // U+0055 (U)
+ {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0056 (V)
+ {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, // U+0057 (W)
+ {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, // U+0058 (X)
+ {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, // U+0059 (Y)
+ {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, // U+005A (Z)
+ {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, // U+005B ([)
+ {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, // U+005C (\)
+ {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, // U+005D (])
+ {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, // U+005E (^)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, // U+005F (_)
+ {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0060 (`)
+ {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, // U+0061 (a)
+ {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, // U+0062 (b)
+ {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, // U+0063 (c)
+ {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, // U+0064 (d)
+ {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, // U+0065 (e)
+ {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, // U+0066 (f)
+ {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0067 (g)
+ {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, // U+0068 (h)
+ {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+0069 (i)
+ {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, // U+006A (j)
+ {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, // U+006B (k)
+ {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, // U+006C (l)
+ {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, // U+006D (m)
+ {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, // U+006E (n)
+ {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, // U+006F (o)
+ {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, // U+0070 (p)
+ {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, // U+0071 (q)
+ {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, // U+0072 (r)
+ {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, // U+0073 (s)
+ {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, // U+0074 (t)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, // U+0075 (u)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, // U+0076 (v)
+ {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, // U+0077 (w)
+ {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, // U+0078 (x)
+ {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, // U+0079 (y)
+ {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, // U+007A (z)
+ {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, // U+007B ({)
+ {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, // U+007C (|)
+ {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, // U+007D (})
+ {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+007E (~)
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // U+007F
+
+};
+
+inline Kernel::Void CGRenderStringFromBitMap(const Kernel::UInt8* bitmap, const Kernel::SizeT& x_sz, const Kernel::SizeT& y_sz, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color)
+{
+ Kernel::Int32 x, y;
+ Kernel::Int32 set;
+
+ x = 0;
+ y = 0;
+ set = 0;
+
+ for (; y < y_sz; ++y)
+ {
+ for (x = 0; x < x_sz; ++x)
+ {
+ set = bitmap[x] & (1 << y);
+
+ if (set)
+ CGDrawInRegion(color, 1, 1, ((x_dst) + x), ((y_dst) + y));
+ }
+ }
+}
+
+inline Kernel::Void CGDrawString(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color)
+{
+ for (Kernel::SizeT i = 0; text[i] != 0; ++i)
+ {
+ CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, x_dst, y_dst, color);
+ y_dst += FONT_SIZE_Y;
+ }
+}
diff --git a/dev/zka/Modules/CoreCG/WindowRenderer.hxx b/dev/zka/Modules/CoreCG/WindowRenderer.hxx
new file mode 100644
index 00000000..775b80c0
--- /dev/null
+++ b/dev/zka/Modules/CoreCG/WindowRenderer.hxx
@@ -0,0 +1,265 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <Modules/CoreCG/Accessibility.hxx>
+#include <KernelKit/Heap.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/LPC.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Utils.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <Modules/CoreCG/Rsrc/WndControls.rsrc>
+#include <Modules/CoreCG/TextRenderer.hxx>
+
+namespace CG
+{
+ using namespace Kernel;
+
+ struct UI_WINDOW_STRUCT;
+
+ enum
+ {
+ cWndFlagNoShow = 0x02,
+ cWndFlagButton = 0x04,
+ cWndFlagWindow = 0x06,
+ cWndFlagButtonSelect = 0x08,
+ cWndFlagHideCloseControl = 0x010,
+ cWndFlagCloseControlSelect = 0x012,
+ };
+
+ struct UI_WINDOW_STRUCT final
+ {
+ static constexpr auto cChildElementCount = 255;
+
+ Char w_window_name[255]{0};
+ Char w_class_name[255]{0};
+ Int32 w_type{0};
+ Int32 w_sub_type{0};
+ Int32 w_x{0};
+ Int32 w_y{0};
+ Int32 w_w{0};
+ Int32 w_h{0};
+ Size w_child_count{0};
+ struct UI_WINDOW_STRUCT* w_child_elements[cChildElementCount]{0};
+ struct UI_WINDOW_STRUCT* w_parent{nullptr};
+ UInt32* w_display_ptr{nullptr};
+ Bool w_needs_repaint{false};
+ };
+
+ typedef struct UI_WINDOW_STRUCT UI_WINDOW_STRUCT;
+
+ /// \brief Draw background (either image or solid color)
+ inline Void CGDrawBackground(UInt32* raw_bmp = nullptr, SizeT width = 0, SizeT height = 0) noexcept
+ {
+ CGInit();
+
+ if (!raw_bmp)
+ {
+ const auto cColorBackground = CGColor(0x45, 0x00, 0x06);
+
+ CGDrawInRegion(cColorBackground, CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(),
+ 0, 0);
+ }
+ else
+ {
+ CGDrawBitMapInRegion(raw_bmp, height, width,
+ 0, 0);
+ }
+
+ CGFini();
+ }
+
+ inline struct UI_WINDOW_STRUCT* CGCreateWindow(Int32 kind, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height, UI_WINDOW_STRUCT* parent = nullptr)
+ {
+ UI_WINDOW_STRUCT* wnd = new UI_WINDOW_STRUCT();
+
+ if (!wnd)
+ {
+ ErrLocal() = kErrorHeapOutOfMemory;
+ return nullptr;
+ }
+
+ rt_copy_memory((VoidPtr)window_name, wnd->w_window_name, rt_string_len(window_name));
+ rt_copy_memory((VoidPtr)class_name, wnd->w_class_name, rt_string_len(class_name));
+
+ if (parent)
+ {
+ wnd->w_parent = parent;
+
+ ++wnd->w_parent->w_child_count;
+ wnd->w_parent->w_child_elements[wnd->w_parent->w_child_count - 1] = wnd;
+ }
+
+ wnd->w_sub_type = 0;
+ wnd->w_type = kind;
+ wnd->w_x = x;
+ wnd->w_y = y;
+
+ wnd->w_w = width;
+ wnd->w_h = height;
+
+ wnd->w_display_ptr = new UInt32[width * height];
+ rt_set_memory(wnd->w_display_ptr, CGColor(0xF5, 0xF5, 0xF5), width * height);
+
+ return wnd;
+ }
+
+ /// \brief Destroys a window and it's contents.
+ inline Bool CGDestroyWindow(struct UI_WINDOW_STRUCT* wnd)
+ {
+ if (wnd)
+ {
+ if (!mm_is_valid_heap(wnd))
+ {
+ wnd = nullptr;
+ return true;
+ }
+
+ wnd->w_needs_repaint = No;
+
+ for (SizeT index = 0UL; index < wnd->w_child_count; ++index)
+ {
+ CGDestroyWindow(wnd->w_child_elements[index]);
+ }
+
+ delete wnd;
+ wnd = nullptr;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ inline Kernel::Void CGDrawStringToWnd(UI_WINDOW_STRUCT* wnd, const Kernel::Char* text, Kernel::Int32 y_dst, Kernel::Int32 x_dst, Kernel::Int32 color)
+ {
+ y_dst += wnd->w_y + FLATCONTROLS_HEIGHT;
+ x_dst += wnd->w_x;
+
+ if (y_dst > (wnd->w_h + wnd->w_y))
+ return;
+
+ for (Kernel::SizeT i = 0; text[i] != 0; ++i)
+ {
+ if (x_dst > (wnd->w_w + wnd->w_x))
+ break;
+
+ CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, y_dst, x_dst, color);
+ x_dst += FONT_SIZE_Y;
+ }
+ }
+
+ inline SizeT CGDrawWindowList(UI_WINDOW_STRUCT** wnd, SizeT wnd_cnt)
+ {
+ if (wnd_cnt == 0 ||
+ !wnd)
+ return 0;
+
+ SizeT cnt = 0;
+
+ for (SizeT index = 0; index < wnd_cnt; ++index)
+ {
+ if (!wnd[index] ||
+ (wnd[index]->w_type == cWndFlagNoShow) ||
+ !wnd[index]->w_needs_repaint)
+ continue;
+
+ CGInit();
+
+ wnd[index]->w_needs_repaint = false;
+
+ if (UIAccessibilty::The().Width() < wnd[index]->w_x)
+ {
+ if ((wnd[index]->w_x - UIAccessibilty::The().Width()) > 1)
+ {
+ wnd[index]->w_x -= wnd[index]->w_x - UIAccessibilty::The().Width();
+ }
+ else
+ {
+ wnd[index]->w_x = 0;
+ }
+ }
+
+ if (UIAccessibilty::The().Height() < wnd[index]->w_y)
+ {
+ if ((wnd[index]->w_y - UIAccessibilty::The().Height()) > 1)
+ {
+ wnd[index]->w_y -= wnd[index]->w_y - UIAccessibilty::The().Width();
+ }
+ else
+ {
+ wnd[index]->w_y = 0;
+ }
+ }
+
+ ++cnt;
+
+ // Draw fake controls, just for the looks of it (WINDOW ONLY)
+ if (wnd[index]->w_type == cWndFlagWindow)
+ {
+ CGDrawBitMapInRegion(wnd[index]->w_display_ptr, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x);
+ CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w, FLATCONTROLS_HEIGHT, wnd[index]->w_y, wnd[index]->w_x);
+
+ if (wnd[index]->w_sub_type != cWndFlagHideCloseControl)
+ {
+ if (wnd[index]->w_sub_type == cWndFlagCloseControlSelect)
+ {
+ CGDrawBitMapInRegion(FlatControlsClose, FLATCONTROLS_CLOSE_HEIGHT, FLATCONTROLS_CLOSE_WIDTH, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - FLATCONTROLS_WIDTH);
+ }
+ else
+ {
+ CGDrawBitMapInRegion(FlatControls, FLATCONTROLS_HEIGHT, FLATCONTROLS_WIDTH, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - FLATCONTROLS_WIDTH);
+ }
+ }
+
+ CGDrawString(wnd[index]->w_window_name, wnd[index]->w_y + 8, wnd[index]->w_x + 8, CGColor(0x00, 0x00, 0x00));
+ }
+ /// @note buttons in this library are dynamic, it's because we want to avoid as much as computations as possible.
+ /// (Such as getting the middle coordinates of a button, to center the text.)
+ else if (wnd[index]->w_type == cWndFlagButtonSelect)
+ {
+ auto x_center = wnd[index]->w_x + 6;
+ auto y_center = wnd[index]->w_y + 7;
+
+ CGDrawInRegion(CGColor(0xD3, 0x74, 0x00), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x);
+ CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1);
+ CGDrawStringToWnd(wnd[index], wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00));
+ }
+ else if (wnd[index]->w_type == cWndFlagButton)
+ {
+ auto x_center = wnd[index]->w_x + 6;
+ auto y_center = wnd[index]->w_y + 7;
+
+ CGDrawInRegion(CGColor(0xDC, 0xDC, 0xDC), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x);
+ CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1);
+ CGDrawString(wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00));
+ }
+
+ CGFini();
+
+ // draw child windows and controls.
+ // doesn't have to be a window, enabling then windows in windows.
+
+ for (SizeT child = 0; child < wnd[index]->w_child_count; ++child)
+ {
+ wnd[index]->w_child_elements[child]->w_x += wnd[index]->w_x;
+ wnd[index]->w_child_elements[child]->w_y += wnd[index]->w_y + FLATCONTROLS_HEIGHT;
+
+ if ((wnd[index]->w_child_elements[child]->w_w + wnd[index]->w_child_elements[child]->w_x) > (wnd[index]->w_x + wnd[index]->w_w) ||
+ (wnd[index]->w_child_elements[child]->w_h + wnd[index]->w_child_elements[child]->w_y) > (wnd[index]->w_y + wnd[index]->w_h))
+ continue;
+
+ CGDrawWindowList(&wnd[index]->w_child_elements[child], 1);
+ }
+
+ CGFini();
+ }
+
+ return cnt;
+ }
+} // namespace CG
diff --git a/dev/zka/Modules/Flash/Flash.hxx b/dev/zka/Modules/Flash/Flash.hxx
new file mode 100644
index 00000000..ccea5a9a
--- /dev/null
+++ b/dev/zka/Modules/Flash/Flash.hxx
@@ -0,0 +1,21 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#ifdef __USE_MBCI_FLASH__
+
+#include <NewKit/Defines.hxx>
+
+/// @brief get sector count.
+/// @return drive sector count.
+Kernel::SizeT drv_get_sector_count();
+
+/// @brief get device size.
+/// @return drive size
+Kernel::SizeT drv_get_size();
+
+#endif // ifdef __USE_MBCI_FLASH__
diff --git a/dev/zka/Modules/GL/.keepme b/dev/zka/Modules/GL/.keepme
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/GL/.keepme
diff --git a/dev/zka/Modules/GPRS/.keepme b/dev/zka/Modules/GPRS/.keepme
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/GPRS/.keepme
diff --git a/dev/zka/Modules/HPET/.gitkeep b/dev/zka/Modules/HPET/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/HPET/.gitkeep
diff --git a/dev/zka/Modules/HPET/Defines.hxx b/dev/zka/Modules/HPET/Defines.hxx
new file mode 100644
index 00000000..7b6e4589
--- /dev/null
+++ b/dev/zka/Modules/HPET/Defines.hxx
@@ -0,0 +1,42 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: HPET.hxx
+ Purpose: HPET builtin.
+
+ Revision History:
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <Modules/ACPI/ACPI.hxx>
+
+namespace Kernel
+{
+ struct PACKED HPETAddressStructure final
+ {
+ Kernel::UInt8 AddressSpaceId; // 0 - system memory, 1 - system I/O
+ Kernel::UInt8 RegisterBitWidth;
+ Kernel::UInt8 RegisterBitOffset;
+ Kernel::UInt8 Reserved;
+ Kernel::UInt64 Address;
+ };
+
+ struct PACKED HPETHeader final : public SDT
+ {
+ Kernel::UInt8 HardwareRevId;
+ Kernel::UInt8 ComparatorCount : 5;
+ Kernel::UInt8 CounterSize : 1;
+ Kernel::UInt8 Reserved : 1;
+ Kernel::UInt8 LegacyReplacement : 1;
+ Kernel::UInt16 PciVendorId;
+ HPETAddressStructure Address;
+ Kernel::UInt8 HpetNumber;
+ Kernel::UInt16 MinimumTick;
+ Kernel::UInt8 PageProtection;
+ };
+
+} // namespace Kernel
diff --git a/dev/zka/Modules/IEEE802/.gitkeep b/dev/zka/Modules/IEEE802/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/IEEE802/.gitkeep
diff --git a/dev/zka/Modules/LTE/.keepme b/dev/zka/Modules/LTE/.keepme
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/LTE/.keepme
diff --git a/dev/zka/Modules/LTE/IO.hxx b/dev/zka/Modules/LTE/IO.hxx
new file mode 100644
index 00000000..15546515
--- /dev/null
+++ b/dev/zka/Modules/LTE/IO.hxx
@@ -0,0 +1,28 @@
+/* -------------------------------------------
+
+Copyright ZKA Technologies..
+
+File: LTE\IO.hxx.
+Purpose: LTE I/O.
+
+------------------------------------------- */
+
+#ifndef _INC_NETWORK_LTE_IO_HXX_
+#define _INC_NETWORK_LTE_IO_HXX_
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+
+/// @brief Long Term Evolution I/O routines.
+
+/// @brief Turn on SIM slot.
+Kernel::Boolean lte_turn_on_slot(Kernel::Int32 slot);
+
+/// @brief Turn off SIM slot.
+Kernel::Boolean lte_turn_off_slot(Kernel::Int32 slot);
+
+/// @brief Send AT command.
+Kernel::Boolean lte_send_at_command(Kernel::Char* buf,
+ Kernel::Size bufSz);
+
+#endif // ifndef _INC_NETWORK_LTE_IO_HXX_
diff --git a/dev/zka/Modules/MBCI/Interface.hxx b/dev/zka/Modules/MBCI/Interface.hxx
new file mode 100644
index 00000000..b3d5debb
--- /dev/null
+++ b/dev/zka/Modules/MBCI/Interface.hxx
@@ -0,0 +1,10 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <Modules/MBCI/MBCI.hxx>
diff --git a/dev/zka/Modules/MBCI/MBCI.hxx b/dev/zka/Modules/MBCI/MBCI.hxx
new file mode 100644
index 00000000..8f6a7f01
--- /dev/null
+++ b/dev/zka/Modules/MBCI/MBCI.hxx
@@ -0,0 +1,99 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _INC_MODULE_MBCI_HXX_
+#define _INC_MODULE_MBCI_HXX_
+
+#include <NewKit/Defines.hxx>
+#include <Modules/ACPI/ACPI.hxx>
+
+/**
+- VCC (IN) (OUT for MCU)
+- CLK (IN) (OUT for MCU)
+- ACK (BI) (Contains an Acknowledge Packet Frame)
+- D0- (IN) (Starts with the Host Interface Packet Frame)
+- D1- (IN) (Starts with the Host Interface Packet Frame)
+- D0+ (OUT) (Starts with the Host Interface Packet Frame)
+- D1+ (OUT) (Starts with the Host Interface Packet Frame)
+- GND (IN) (OUT for MCU)
+ */
+
+#define cMBCIZeroSz (8)
+#define cMBCIMagic "MBCI "
+
+namespace Kernel
+{
+ struct IMBCIHost;
+ struct IMBCIHostPacketFrame;
+
+ /// @brief MBCI Packet frame header
+ struct PACKED IMBCIHostPacketFrame final
+ {
+ UInt32 Magic;
+ UInt32 HostId;
+ UInt32 Flags;
+ UInt32 VendorId;
+ UInt32 DeviceId;
+ UInt32 DeviceSpeed;
+ Bool Acknowledge;
+ Char Zero[cMBCIZeroSz];
+ };
+
+ enum
+ {
+ eMBCISpeedDeviceInvalid,
+ eMBCILowSpeedDevice,
+ eMBCIHighSpeedDevice,
+ eMBCISpeedDeviceCount,
+ };
+
+ /// @brief MBCI Host Interface header.
+ struct PACKED IMBCIHost final
+ {
+ UInt32 Magic;
+ UInt32 HostId;
+ UInt16 VendorId;
+ UInt16 DeviceId;
+ UInt8 MemoryType;
+ UInt16 HostType;
+ UInt16 HostFlags;
+ UInt8 Error;
+ UInt8 Status;
+ UInt8 InterruptEnable;
+ UInt64 BaseAddressRegister;
+ UInt64 BaseAddressRegisterSize;
+ Char Zero[cMBCIZeroSz];
+ };
+
+ /// @brief MBCI host flags.
+ enum MBCIHostFlags
+ {
+ eMBCIHostFlagsSupportsNothing, // Invalid MBCI device.
+ eMBCIHostFlagsSupportsAPM, // Advanced Power Management.
+ eMBCIHostFlagsSupportsDaisyChain, // Is daisy chained.
+ eMBCIHostFlagsSupportsHWInterrupts, // Has HW interrupts.
+ eMBCIHostFlagsSupportsDMA, // Has DMA.
+ eMBCIHostFlagsExtended = __UINT16_MAX__, // Extended flags table.
+ };
+
+ enum MBCIHostKind
+ {
+ eMBCIHostKindHardDisk,
+ eMBCIHostKindOpticalDisk,
+ eMBCIHostKindKeyboardLow,
+ eMBCIHostKindMouseLow,
+ eMBCIHostKindMouseHigh,
+ eMBCIHostKindKeyboardHigh,
+ eMBCIHostKindNetworkInterface,
+ eMBCIHostKindDaisyChain,
+ eMBCIHostKindStartExtended = __UINT16_MAX__, // Extended vendor table.
+ };
+
+ /// @brief An AuthKey is a context used to decrpy data from an MBCI packet.
+ typedef UInt64 MBCIAuthyKeyType;
+} // namespace Kernel
+
+#endif // ifndef _INC_MODULE_MBCI_HXX_
diff --git a/dev/zka/Modules/NVME/.gitkeep b/dev/zka/Modules/NVME/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/NVME/.gitkeep
diff --git a/dev/zka/Modules/NVME/Defines.hxx b/dev/zka/Modules/NVME/Defines.hxx
new file mode 100644
index 00000000..3e8b9c98
--- /dev/null
+++ b/dev/zka/Modules/NVME/Defines.hxx
@@ -0,0 +1,112 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ Revision History:
+
+ ??/??/24: Added file (amlel)
+ 23 Jul 24: Update filename to Defines.hxx and using ALIGN_NVME for NVME structs. (amlel)
+
+------------------------------------------- */
+
+#ifndef __MODULE_NVME_HXX__
+#define __MODULE_NVME_HXX__
+
+#include <NewKit/Defines.hxx>
+
+/// TODO: checklist in: https://wiki.osdev.org/NVMe
+
+#define ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::NVMEInt32)))
+
+namespace Kernel
+{
+ typedef UInt32 NVMEInt32;
+
+ struct ALIGN_NVME NVMEBar0 final
+ {
+ NVMEInt32 fCap;
+ NVMEInt32 fVer;
+ NVMEInt32 fIntMaskSet;
+ NVMEInt32 fIntMaskClr;
+ NVMEInt32 fContrlConf;
+ NVMEInt32 fContrlStat;
+ NVMEInt32 fAdminQueueAttr;
+ NVMEInt32 fAdminSubmissionQueue;
+ NVMEInt32 fAdminCompletionQueue;
+ };
+
+ struct ALIGN_NVME NVMEQueue final
+ {
+ NVMEInt32 fOpcode;
+ NVMEInt32 fNSID;
+ NVMEInt32 fReserved[3];
+ NVMEInt32 fMetadataPtr[5];
+ NVMEInt32 fDataPtr[9];
+ NVMEInt32 CommandSpecific[15];
+ };
+
+ enum
+ {
+ eCreateCompletionQueueNVME = 0x05,
+ eCreateSubmissionQueueNVME = 0x01,
+ eIdentifyNVME = 0x06,
+ eReadNVME = 0x02,
+ eWriteNVME = 0x01,
+ };
+
+ template <Int32 Opcode>
+ inline Bool nvme_create_admin_command(NVMEQueue* entry, UInt32 nsid, UInt32 prpTransfer[3], UInt32 startingLba[2], UInt32 lowTransferBlocks)
+ {
+ if (entry == nullptr)
+ return false;
+
+ entry->CommandSpecific[9] = startingLba[0];
+ entry->CommandSpecific[10] = startingLba[1];
+
+ entry->CommandSpecific[11] = lowTransferBlocks;
+
+ entry->CommandSpecific[5] = prpTransfer[0];
+ entry->CommandSpecific[6] = prpTransfer[1];
+ entry->CommandSpecific[7] = prpTransfer[2];
+
+ entry->CommandSpecific[0] = nsid;
+
+ return true;
+ }
+
+ template <Int32 Opcode>
+ inline Bool nvme_create_io_command(NVMEQueue* entry, UInt64 baseAddress, UInt32 identLoAndQueueSizeHi, UInt32 flagsLoAndQueueComplIdHi, UInt32 identify, Bool provideIdentify = false, Bool namespaceIdentify = false)
+ {
+ if (entry == nullptr)
+ return false;
+
+ if (baseAddress == 0)
+ return false;
+
+ entry->fOpcode = Opcode;
+
+ entry->CommandSpecific[5] = (baseAddress & 0xFF);
+ entry->CommandSpecific[6] = static_cast<UInt32>(baseAddress);
+
+ if (!provideIdentify)
+ {
+ entry->CommandSpecific[9] = identLoAndQueueSizeHi;
+ entry->CommandSpecific[10] = flagsLoAndQueueComplIdHi;
+ }
+ else
+ {
+ entry->CommandSpecific[9] = identify;
+
+ if (namespaceIdentify)
+ {
+ entry->CommandSpecific[0] = 1;
+ }
+ }
+
+ // use (1 << 0) as contigunous is better supported.
+
+ return true;
+ }
+} // namespace Kernel
+
+#endif // ifndef __MODULE_NVME_HXX__
diff --git a/dev/zka/Modules/OHCI/.gitkeep b/dev/zka/Modules/OHCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/OHCI/.gitkeep
diff --git a/dev/zka/Modules/ReadMe.md b/dev/zka/Modules/ReadMe.md
new file mode 100644
index 00000000..de72cb1a
--- /dev/null
+++ b/dev/zka/Modules/ReadMe.md
@@ -0,0 +1,12 @@
+# Kernel modules
+
+Pluggable modules for builtin hardware support within the Kernel.
+
+## Maintainers
+
+ACPI: Amlal EL Mahrouss.
+AHCI: Amlal EL Mahrouss.
+CoreCG: Amlal EL Mahrouss.
+PS2: Amlal EL Mahrouss.
+ATA: Amlal EL Mahrouss.
+MBCI: Amlal El Mahrouss.
diff --git a/dev/zka/Modules/SCSI/.gitkeep b/dev/zka/Modules/SCSI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/SCSI/.gitkeep
diff --git a/dev/zka/Modules/SCSI/SCSI.hxx b/dev/zka/Modules/SCSI/SCSI.hxx
new file mode 100644
index 00000000..5283bc01
--- /dev/null
+++ b/dev/zka/Modules/SCSI/SCSI.hxx
@@ -0,0 +1,14 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+/// @file SCSI.hxx
+/// @brief Serial SCSI driver.
+
+typedef Kernel::UInt16 scsi_packet_type[12];
diff --git a/dev/zka/Modules/WiFi/.gitkeep b/dev/zka/Modules/WiFi/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/WiFi/.gitkeep
diff --git a/dev/zka/Modules/XHCI/.gitkeep b/dev/zka/Modules/XHCI/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Modules/XHCI/.gitkeep
diff --git a/dev/zka/Modules/XHCI/Defines.hxx b/dev/zka/Modules/XHCI/Defines.hxx
new file mode 100644
index 00000000..b882607c
--- /dev/null
+++ b/dev/zka/Modules/XHCI/Defines.hxx
@@ -0,0 +1,70 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Defines.hxx
+ Purpose: XHCI (and backwards) header.
+
+ Revision History:
+
+ 01/02/24: Added file (amlel)
+ 03/02/24: Update filename to Defines.hxx (amlel)
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+using namespace Kernel;
+
+#define kUSBCommand (UInt16)0x0
+#define kUSBStatus (UInt16)0x2
+#define kUSBInterruptEnable (UInt16)0x4
+#define kUSBFrameNum (UInt16)0x6
+#define kUSBFrameListBaseAddress (UInt16)0x8
+#define kUSBFrameModifyStart (UInt16)0xC
+#define kUSBPort1StatusCtrl (UInt16)0x10
+#define kUSBPort2StatusCtrl (UInt16)0x12
+
+typedef struct USBCommandRegister final
+{
+ UInt8 mReserved[8]; // Reserved
+ UInt8
+ mMaxPacket; // 0 = Max packet size 32 bits 1 = Max packet size 64 bits
+ UInt8 mConfigure;
+ UInt8 mSoftwareDebug;
+ UInt8 mGlobalResume;
+ UInt8 mGlobalSuspend;
+ UInt8 mHostCtrlReset;
+ UInt8 mRun; // 1 = Controller execute frame list entries
+} USBCommandRegister;
+
+typedef struct USBStatusRegister final
+{
+ UInt8 mReserved[8]; // Reserved
+ UInt8 mHalted; // 1 = bit 0 in CMD is zero 0 = bit 0 in CMD is 1
+ UInt8 mProcessError;
+ UInt8 mSystemError;
+ UInt8 mResumeDetected;
+ UInt8 mErrorInterrupt;
+ UInt8 mInterrupt;
+} USBStatusRegister;
+
+typedef struct USBInterruptEnableRegister final
+{
+ UInt8 mReserved[4]; // Reserved
+ UInt8 mShortPacket; // 1=Enable interrupt 0=Disable interrupt
+ UInt8 mComplete; // 1=Enable interrupt 0=Disable interrupt
+ UInt8 mResume; // 1=Enable interrupt 0=Disable interrupt
+ UInt8 mTimeoutCRC; // 1=Enable interrupt 0=Disable interrupt
+} USBInterruptEnableRegister;
+
+/*
+ Some terminology:
+
+ Frame Number: Number of processed entry of the Frame List.
+ Frame List Base Address:
+ 32-bit physical adress of Frame List. Remember that first 12 bytes are
+ always 0. The Frame List must contain 1024 entries.
+*/
diff --git a/dev/zka/MoveAll.ARM64.sh b/dev/zka/MoveAll.ARM64.sh
new file mode 100755
index 00000000..5198559f
--- /dev/null
+++ b/dev/zka/MoveAll.ARM64.sh
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+for file in *.o; do
+ mv -- "$file" "${file%.o}.obj"
+done
+
+mv *.obj Objects/
diff --git a/dev/zka/MoveAll.X64.sh b/dev/zka/MoveAll.X64.sh
new file mode 100755
index 00000000..664ad472
--- /dev/null
+++ b/dev/zka/MoveAll.X64.sh
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+for file in *.o; do
+ mv -- "$file" "${file%.o}.obj"
+done
+
+mv *.obj HALKit/AMD64/*.obj Objects/ \ No newline at end of file
diff --git a/dev/zka/NetworkKit/IP.hxx b/dev/zka/NetworkKit/IP.hxx
new file mode 100644
index 00000000..70d9fd76
--- /dev/null
+++ b/dev/zka/NetworkKit/IP.hxx
@@ -0,0 +1,83 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel
+{
+ class RawIPAddress6;
+ class RawIPAddress;
+ class IPFactory;
+
+ class RawIPAddress final
+ {
+ private:
+ explicit RawIPAddress(char bytes[4]);
+ ~RawIPAddress() = default;
+
+ RawIPAddress& operator=(const RawIPAddress&) = delete;
+ RawIPAddress(const RawIPAddress&) = default;
+
+ public:
+ char* Address();
+
+ char& operator[](const Size& index);
+
+ bool operator==(const RawIPAddress& ipv6);
+ bool operator!=(const RawIPAddress& ipv6);
+
+ private:
+ char fAddr[4];
+
+ friend IPFactory; // it is the one creating these addresses, thus this
+ // is why the constructors are private.
+ };
+
+ /**
+ * @brief IPv6 address.
+ */
+ class RawIPAddress6 final
+ {
+ private:
+ explicit RawIPAddress6(char Bytes[8]);
+ ~RawIPAddress6() = default;
+
+ RawIPAddress6& operator=(const RawIPAddress6&) = delete;
+ RawIPAddress6(const RawIPAddress6&) = default;
+
+ public:
+ char* Address()
+ {
+ return fAddr;
+ }
+
+ char& operator[](const Size& index);
+
+ bool operator==(const RawIPAddress6& ipv6);
+ bool operator!=(const RawIPAddress6& ipv6);
+
+ private:
+ char fAddr[8];
+
+ friend IPFactory;
+ };
+
+ /**
+ * @brief IP Creation helpers
+ */
+ class IPFactory final
+ {
+ public:
+ static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6>& ipv6);
+ static ErrorOr<StringView> ToStringView(Ref<RawIPAddress>& ipv4);
+ static bool IpCheckVersion4(const Char* ip);
+ };
+} // namespace Kernel
diff --git a/dev/zka/NetworkKit/IPC.hxx b/dev/zka/NetworkKit/IPC.hxx
new file mode 100644
index 00000000..e8597910
--- /dev/null
+++ b/dev/zka/NetworkKit/IPC.hxx
@@ -0,0 +1,91 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies..
+
+ File: IPC.hxx.
+ Purpose: IPC protocol.
+
+------------------------------------------- */
+
+#ifndef _INC_IPC_ENDPOINT_HXX_
+#define _INC_IPC_ENDPOINT_HXX_
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+#include <HintKit/CompilerHint.hxx>
+#include <CompressKit/RLE.hxx>
+
+/// @file IPC.hxx
+/// @brief IPC EP protocol.
+
+/// IA separator.
+#define cXPCOMRemoteSeparator ":"
+
+/// Interchange address, consists of PID:TEAM.
+#define cXPCOMRemoteInvalid "00:00"
+
+#define cXPCOMHeaderMagic (0x4950434)
+
+namespace Kernel
+{
+ struct IPC_ADDRESS_STRUCT;
+ struct IPC_MESSAGE_STRUCT;
+
+ /// @brief 128-bit IPC address.
+ struct PACKED IPC_ADDRESS_STRUCT final
+ {
+ UInt64 UserProcessID;
+ UInt64 UserProcessTeam;
+
+ ////////////////////////////////////
+ // some operators.
+ ////////////////////////////////////
+
+ bool operator==(const IPC_ADDRESS_STRUCT& addr) noexcept
+ {
+ return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam;
+ }
+
+ bool operator==(IPC_ADDRESS_STRUCT& addr) noexcept
+ {
+ return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam;
+ }
+ };
+
+ typedef struct IPC_ADDRESS_STRUCT IPCEPAddressKind;
+
+ enum
+ {
+ eIPCEPLittleEndian = 0,
+ eIPCEPBigEndian = 1,
+ eIPCEPMixedEndian = 2,
+ };
+
+ constexpr auto cXPCOMMsgSize = 6094U;
+
+ /// @brief IPC connection header, message cannot be greater than 6K.
+ typedef struct IPC_MESSAGE_STRUCT final
+ {
+ UInt32 IpcHeaderMagic; // cRemoteHeaderMagic
+ UInt8 IpcEndianess; // 0 : LE, 1 : BE
+ SizeT IpcPacketSize;
+ IPCEPAddressKind IpcFrom;
+ IPCEPAddressKind IpcTo;
+ UInt32 IpcCRC32;
+ UInt32 IpcMsg;
+ UInt32 IpcMsgSz;
+ UInt8 IpcData[cXPCOMMsgSize];
+ } PACKED IPC_MESSAGE_STRUCT;
+
+ /// @brief Sanitize packet function
+ /// @retval true packet is correct.
+ /// @retval false packet is incorrect and process has crashed.
+ Bool ipc_sanitize_packet(_Input IPC_MESSAGE_STRUCT* pckt_in);
+
+ /// @brief Construct packet function
+ /// @retval true packet is correct.
+ /// @retval false packet is incorrect and process has crashed.
+ Bool ipc_construct_packet(_Output IPC_MESSAGE_STRUCT** pckt_in);
+} // namespace Kernel
+
+#endif // _INC_IPC_ENDPOINT_HXX_
diff --git a/dev/zka/NetworkKit/LTE.hxx b/dev/zka/NetworkKit/LTE.hxx
new file mode 100644
index 00000000..2c390163
--- /dev/null
+++ b/dev/zka/NetworkKit/LTE.hxx
@@ -0,0 +1,16 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies..
+
+ File: LTE.hxx.
+ Purpose: LTE protocol classes.
+
+------------------------------------------- */
+
+#ifndef _INC_NETWORK_LTE_HXX_
+#define _INC_NETWORK_LTE_HXX_
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+
+#endif // ifndef _INC_NETWORK_LTE_HXX_
diff --git a/dev/zka/NetworkKit/MAC.hxx b/dev/zka/NetworkKit/MAC.hxx
new file mode 100644
index 00000000..8a7b141e
--- /dev/null
+++ b/dev/zka/NetworkKit/MAC.hxx
@@ -0,0 +1,29 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel
+{
+ class MacAddressGetter;
+
+ /// \brief This retrieves the MAC address of the device.
+ /// \note Listens for the current NIC.
+ class MacAddressGetter final
+ {
+ public:
+ explicit MacAddressGetter() = default;
+
+ public:
+ StringView& AsString();
+ Array<WideChar, 12>& AsBytes();
+ };
+
+} // namespace Kernel
diff --git a/dev/zka/NetworkKit/NetworkDevice.hxx b/dev/zka/NetworkKit/NetworkDevice.hxx
new file mode 100644
index 00000000..ed575e3e
--- /dev/null
+++ b/dev/zka/NetworkKit/NetworkDevice.hxx
@@ -0,0 +1,80 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __INC_NETWORK_DEVICE_HPP__
+#define __INC_NETWORK_DEVICE_HPP__
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <NetworkKit/IP.hxx>
+
+/// @note Can either work with: Ethernet, GPRS, WiFi
+
+namespace Kernel
+{
+ struct NetworkDeviceCommand;
+ class NetworkDevice;
+
+ /**
+ * \brief Network device interface, establishes a connection to the NIC.
+ */
+ class NetworkDevice final : public DeviceInterface<NetworkDeviceCommand>
+ {
+ public:
+ NetworkDevice(void (*out)(NetworkDeviceCommand),
+ void (*in)(NetworkDeviceCommand),
+ void (*onCleanup)(void) = nullptr);
+
+ ~NetworkDevice() override;
+
+ public:
+ NetworkDevice& operator=(const NetworkDevice&) = default;
+ NetworkDevice(const NetworkDevice&) = default;
+
+ public:
+ const Char* Name() const override;
+ Boolean Name(const Char* strView);
+
+ private:
+ static constexpr auto cNetworkNameLen = 512;
+
+ Void (*fCleanup)(void);
+ Char fNetworkName[cNetworkNameLen];
+ };
+
+ struct NetworkDeviceCommand final
+ {
+ UInt32 CommandName;
+ UInt32 CommandType;
+ UInt32 CommandFlags;
+ VoidPtr CommandBuffer;
+ SizeT CommandSizeBuffer;
+ };
+
+ /// @brief TCP device.
+ using TCPNetworkDevice = NetworkDevice;
+
+ /// @brief UDP device.
+ using UDPNetworkDevice = NetworkDevice;
+
+ /// @brief PPP device.
+ using PPPNetworkDevice = NetworkDevice;
+
+ /// @brief IPC device.
+ using IPCEPNetworkDevice = NetworkDevice;
+
+ /// @brief GRPS device.
+ using GPRSNetworkDevice = NetworkDevice;
+
+ /// @brief GSM device.
+ using GSMNetworkDevice = NetworkDevice;
+
+ /// @brief LTE device.
+ using LTENetworkDevice = NetworkDevice;
+} // namespace Kernel
+
+#include <NetworkKit/NetworkDevice.inl>
+
+#endif // !__INC_NETWORK_DEVICE_HPP__
diff --git a/dev/zka/NetworkKit/NetworkDevice.inl b/dev/zka/NetworkKit/NetworkDevice.inl
new file mode 100644
index 00000000..4bc2a153
--- /dev/null
+++ b/dev/zka/NetworkKit/NetworkDevice.inl
@@ -0,0 +1,32 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/***
+ Dtor and ctors.
+*/
+
+namespace Kernel
+{
+ NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand),
+ void (*in)(NetworkDeviceCommand),
+ void (*on_cleanup)(void))
+ : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup)
+ {
+ kcout << "NetworkDevice initialized.\r";
+
+ MUST_PASS(out && in && on_cleanup);
+ }
+
+ NetworkDevice::~NetworkDevice()
+ {
+ MUST_PASS(fCleanup);
+
+ kcout << "NetworkDevice cleanup.\r";
+
+ if (fCleanup)
+ fCleanup();
+ }
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Array.hxx b/dev/zka/NewKit/Array.hxx
new file mode 100644
index 00000000..7538ef02
--- /dev/null
+++ b/dev/zka/NewKit/Array.hxx
@@ -0,0 +1,73 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ template <typename T, Size N>
+ class Array final
+ {
+ public:
+ explicit Array()
+ {
+ for (SizeT i = 0; i < N; i++)
+ {
+ if (!fArray[i])
+ fArray[i] = T();
+ }
+ }
+
+ ~Array() = default;
+
+ Array& operator=(const Array&) = default;
+ Array(const Array&) = default;
+
+ T& operator[](const SizeT& At)
+ {
+ return fArray[At];
+ }
+
+ Boolean Empty() const
+ {
+ return No;
+ }
+
+ const SizeT Capacity()
+ {
+ return N;
+ }
+
+ const SizeT Count()
+ {
+ SizeT count = 0;
+
+ for (SizeT i = 0; i < N; i++)
+ {
+ if (fArray[i])
+ ++count;
+ }
+
+ return count;
+ }
+
+ const T* CData()
+ {
+ return fArray;
+ }
+
+ operator bool()
+ {
+ return !Empty();
+ }
+
+ private:
+ T fArray[N];
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/ArrayList.hxx b/dev/zka/NewKit/ArrayList.hxx
new file mode 100644
index 00000000..03b0a360
--- /dev/null
+++ b/dev/zka/NewKit/ArrayList.hxx
@@ -0,0 +1,58 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ template <typename T>
+ class ArrayList final
+ {
+ public:
+ explicit ArrayList(T* list)
+ : fList(reinterpret_cast<T>(list))
+ {
+ }
+
+ ~ArrayList() = default;
+
+ ArrayList& operator=(const ArrayList&) = default;
+ ArrayList(const ArrayList&) = default;
+
+ T* Data()
+ {
+ return fList;
+ }
+
+ const T* CData()
+ {
+ return fList;
+ }
+
+ T& operator[](int index) const
+ {
+ return fList[index];
+ }
+
+ operator bool()
+ {
+ return fList;
+ }
+
+ private:
+ T* fList;
+
+ friend class InitHelpers;
+ };
+
+ template <typename ValueType>
+ ArrayList<ValueType> make_list(ValueType val)
+ {
+ return ArrayList<ValueType>{val};
+ }
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Atom.hxx b/dev/zka/NewKit/Atom.hxx
new file mode 100644
index 00000000..616179e9
--- /dev/null
+++ b/dev/zka/NewKit/Atom.hxx
@@ -0,0 +1,46 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ template <typename T>
+ class Atom final
+ {
+ public:
+ explicit Atom() = default;
+ ~Atom() = default;
+
+ public:
+ Atom& operator=(const Atom&) = delete;
+ Atom(const Atom&) = delete;
+
+ public:
+ T operator[](Size sz)
+ {
+ return (fArrayOfAtoms & sz);
+ }
+ void operator|(Size sz)
+ {
+ fArrayOfAtoms |= sz;
+ }
+
+ friend Boolean operator==(Atom<T>& atomic, const T& idx)
+ {
+ return atomic[idx] == idx;
+ }
+
+ friend Boolean operator!=(Atom<T>& atomic, const T& idx)
+ {
+ return atomic[idx] == idx;
+ }
+
+ private:
+ T fArrayOfAtoms;
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Crc32.hxx b/dev/zka/NewKit/Crc32.hxx
new file mode 100644
index 00000000..36dc89a0
--- /dev/null
+++ b/dev/zka/NewKit/Crc32.hxx
@@ -0,0 +1,23 @@
+/*
+ * ========================================================
+ *
+ * ZKA
+ * Date Added: 13/02/2023
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#ifndef __CRC32_H__
+#define __CRC32_H__
+
+#include <NewKit/Defines.hxx>
+
+#define kCrcCnt (256)
+
+namespace Kernel
+{
+ UInt ke_calculate_crc32(const Char* crc, UInt len) noexcept;
+} // namespace Kernel
+
+#endif // !__CRC32_H__
diff --git a/dev/zka/NewKit/CxxAbi.hxx b/dev/zka/NewKit/CxxAbi.hxx
new file mode 100644
index 00000000..f0b3cf51
--- /dev/null
+++ b/dev/zka/NewKit/CxxAbi.hxx
@@ -0,0 +1,28 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+#ifndef __NDK__
+
+#define kDSOMaxObjects (128)
+
+struct atexit_func_entry_t
+{
+ void (*destructor_func)(void*);
+ void* obj_ptr;
+ void* dso_handle;
+};
+
+typedef unsigned uarch_t;
+
+namespace cxxabiv1
+{
+ typedef void* __guard;
+}
+
+#endif // __GNUC__
diff --git a/dev/zka/NewKit/Defines.hxx b/dev/zka/NewKit/Defines.hxx
new file mode 100644
index 00000000..d6049afd
--- /dev/null
+++ b/dev/zka/NewKit/Defines.hxx
@@ -0,0 +1,189 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Macros.hxx>
+
+#define NEWKIT_VERSION "1.01"
+#define NEWKIT_VERSION_CB 0x0101
+
+#if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__)
+#include <crt/__ndk_defines.hxx>
+#endif
+
+#ifdef __has_feature
+#if !__has_feature(cxx_nullptr)
+#if !__has_nullptr
+#error !!! You must at least have nullptr featured on your C++ compiler. !!!
+#endif
+#endif
+#endif
+
+/// @brief The **newoskrnl** namespace where it's API resides.
+namespace Kernel
+{
+ using voidPtr = void*;
+ using VoidPtr = void*;
+ using nullPtr = decltype(nullptr);
+ using NullPtr = decltype(nullptr);
+
+ using Int = int;
+ using Int32 = int;
+ using UShort = unsigned short;
+ using UInt16 = unsigned short;
+ using Short = short;
+ using Int16 = short;
+ using UInt = unsigned int;
+ using UInt32 = unsigned int;
+ using Long = __INT64_TYPE__;
+ using Int64 = __INT64_TYPE__;
+ using ULong = __UINT64_TYPE__;
+ using UInt64 = __UINT64_TYPE__;
+ using Boolean = bool;
+ using Bool = bool;
+ using Char = char;
+ using UChar = unsigned char;
+ using UInt8 = unsigned char;
+
+ using SSize = Int64;
+ using SSizeT = Int64;
+ using Size = __SIZE_TYPE__;
+ using SizeT = __SIZE_TYPE__;
+ using IntPtr = __INTPTR_TYPE__;
+ using UIntPtr = __UINTPTR_TYPE__;
+ using IntFast = __INT_FAST32_TYPE__;
+ using IntFast64 = __INT_FAST64_TYPE__;
+ using PtrDiff = __PTRDIFF_TYPE__;
+
+ typedef UIntPtr* Ptr64;
+ typedef UInt32* Ptr32;
+
+ using Utf8Char = char8_t;
+ using Utf16Char = char16_t;
+ using WideChar = wchar_t;
+ using Utf32Char = char32_t;
+
+ typedef UInt32 PhysicalAddressKind;
+ typedef UIntPtr VirtualAddressKind;
+
+ using Void = void;
+
+ using Lba = UInt64;
+
+ enum class Endian : UInt8
+ {
+ kEndianInvalid,
+ kEndianBig,
+ kEndianLittle,
+ kEndianMixed,
+ kCount
+ };
+
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Encoding interface, used as a proxy to convert T to Char*
+ /// Used to cast A to B or B to A.
+ class IEncoderObject
+ {
+ public:
+ explicit IEncoderObject() = default;
+ virtual ~IEncoderObject() = default;
+
+ IEncoderObject& operator=(const IEncoderObject&) = default;
+ IEncoderObject(const IEncoderObject&) = default;
+
+ public:
+ /// @brief Convert type to bytes.
+ /// @tparam T the type.
+ /// @param type (a1) the data.
+ /// @return a1 as Char*
+ template <typename T>
+ Char* AsBytes(T type) noexcept
+ {
+ return nullptr;
+ }
+
+ /// @brief Convert T class to Y class.
+ /// @tparam T the class type of type.
+ /// @tparam Y the result class.
+ /// @param type the class to cast.
+ /// @return the class as Y.
+ template <typename T, typename Y>
+ Y As(T type) noexcept
+ {
+ if (type.IsSerializable())
+ {
+ return reinterpret_cast<Char*>(type);
+ }
+
+ return type.template As<Y>();
+ }
+ };
+
+ /// \brief Scheduler interface, represents a scheduler object.
+ class ISchedulerObject
+ {
+ public:
+ explicit ISchedulerObject() = default;
+ virtual ~ISchedulerObject() = default;
+
+ ISchedulerObject& operator=(const ISchedulerObject&) = default;
+ ISchedulerObject(const ISchedulerObject&) = default;
+
+ /// @brief Is this object only accepting user tasks?
+ virtual const Bool IsUser()
+ {
+ return false;
+ }
+
+ /// @brief Is this object only accepting kernel tasks?
+ virtual const Bool IsKernel()
+ {
+ return false;
+ }
+
+ /// @brief Is this object offloading to another CPU?
+ virtual const Bool HasMP()
+ {
+ return false;
+ }
+ };
+} // namespace Kernel
+
+#define DEDUCE_ENDIAN(address, value) \
+ (((reinterpret_cast<Kernel::Char*>(address)[0]) == (value)) \
+ ? (Kernel::Endian::kEndianBig) \
+ : (Kernel::Endian::kEndianLittle))
+
+#define Yes true
+#define No false
+
+#define VoidStar Kernel::VoidPtr
+
+#ifdef cInitObject
+#undef cInitObject
+#endif // ifdef cInitObject
+
+#define cInitObject(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__)
diff --git a/dev/zka/NewKit/ErrorOr.hxx b/dev/zka/NewKit/ErrorOr.hxx
new file mode 100644
index 00000000..e280cb77
--- /dev/null
+++ b/dev/zka/NewKit/ErrorOr.hxx
@@ -0,0 +1,72 @@
+/*
+ * ========================================================
+ *
+ * ZKA
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ using ErrorT = UInt;
+
+ template <typename T>
+ class ErrorOr final
+ {
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
+
+ public:
+ explicit ErrorOr(Int32 err)
+ : mId(err)
+ {
+ }
+
+ explicit ErrorOr(nullPtr Null)
+ {
+ }
+
+ explicit ErrorOr(T Class)
+ : mRef(Class, true)
+ {
+ }
+
+ ErrorOr& operator=(const ErrorOr&) = default;
+ ErrorOr(const ErrorOr&) = default;
+
+ ErrorOr& operator=(const Ref<T>& refErr)
+ {
+ mRef = refErr;
+ return *this;
+ }
+
+ Ref<T>& Leak()
+ {
+ return mRef;
+ }
+
+ Int32 Error()
+ {
+ return mId;
+ }
+
+ operator bool()
+ {
+ return mRef;
+ }
+
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+ };
+
+ using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Function.hxx b/dev/zka/NewKit/Function.hxx
new file mode 100644
index 00000000..e54ff456
--- /dev/null
+++ b/dev/zka/NewKit/Function.hxx
@@ -0,0 +1,53 @@
+#ifndef _INC_FUNCTION_HPP__
+#define _INC_FUNCTION_HPP__
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ template <typename T, typename... Args>
+ class Function final
+ {
+ public:
+ Function() = default;
+
+ public:
+ explicit Function(T (*Fn)(Args... args))
+ : fFn(Fn)
+ {
+ }
+
+ ~Function() = default;
+
+ Function& operator=(const Function&) = default;
+ Function(const Function&) = default;
+
+ template <typename... XArgs>
+ T operator()(Args... args)
+ {
+ return fFn(args...);
+ }
+
+ template <typename... XArgs>
+ T Call(Args... args)
+ {
+ return fFn(args...);
+ }
+
+ operator bool()
+ {
+ return fFn;
+ }
+
+ bool operator!()
+ {
+ return !fFn;
+ }
+
+ private:
+ T(*fFn)
+ (Args... args);
+ };
+} // namespace Kernel
+
+#endif // !_INC_FUNCTION_HPP__
diff --git a/dev/zka/NewKit/Json.hxx b/dev/zka/NewKit/Json.hxx
new file mode 100644
index 00000000..e37dc93d
--- /dev/null
+++ b/dev/zka/NewKit/Json.hxx
@@ -0,0 +1,137 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+// last-rev: 30/01/24
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Stream.hxx>
+#include <NewKit/String.hxx>
+#include <NewKit/Utils.hxx>
+
+#define cMaxJsonPath 4096
+#define cJSONLen 32
+#define cJSONNull "null"
+
+namespace Kernel
+{
+ /// @brief Json value class
+ class JsonType final
+ {
+ public:
+ explicit JsonType()
+ {
+ auto len = cJSONLen;
+ StringView key = StringView(len);
+ key += cJSONNull;
+
+ this->AsKey() = key;
+ this->AsValue() = key;
+ }
+
+ explicit JsonType(SizeT lhsLen, SizeT rhsLen)
+ : fKey(lhsLen), fValue(rhsLen)
+ {
+ }
+
+ ~JsonType() = default;
+
+ ZKA_COPY_DEFAULT(JsonType);
+
+ const Bool& IsUndefined()
+ {
+ return fUndefined;
+ }
+
+ private:
+ Bool fUndefined; // is this instance undefined?
+ StringView fKey;
+ StringView fValue;
+
+ public:
+ /// @brief returns the key of the json
+ /// @return the key as string view.
+ StringView& AsKey()
+ {
+ return fKey;
+ }
+
+ /// @brief returns the value of the json.
+ /// @return the key as string view.
+ StringView& AsValue()
+ {
+ return fValue;
+ }
+
+ static JsonType kNull;
+ };
+
+ /// @brief Json stream reader helper.
+ struct JsonStreamReader final
+ {
+ STATIC JsonType In(const Char* full_array)
+ {
+ if (full_array[0] != '{')
+ return JsonType::kNull;
+
+ SizeT len = rt_string_len(full_array);
+ Boolean probe_value = false;
+
+ SizeT key_len = 0;
+ SizeT value_len = 0;
+
+ JsonType type(cMaxJsonPath, cMaxJsonPath);
+
+ for (SizeT i = 1; i < len; ++i)
+ {
+ if (full_array[i] == '\r' ||
+ full_array[i] == '\n')
+ continue;
+
+ if (probe_value)
+ {
+ if (full_array[i] == '}' ||
+ full_array[i] == ',')
+ {
+ probe_value = false;
+
+ ++value_len;
+ }
+ else
+ {
+ type.AsValue().Data()[value_len] = full_array[i];
+
+ ++value_len;
+ }
+ }
+ else
+ {
+ if (full_array[i] == ':')
+ {
+ probe_value = true;
+ type.AsKey().Data()[key_len] = 0;
+ ++key_len;
+ }
+ else
+ {
+ type.AsKey().Data()[key_len] = full_array[i];
+
+ ++key_len;
+ }
+ }
+ }
+
+ type.AsValue().Data()[value_len] = 0;
+
+ return type;
+ }
+ };
+
+ using JsonStream = Stream<JsonStreamReader, JsonType>;
+} // namespace Kernel
diff --git a/dev/zka/NewKit/KernelCheck.hxx b/dev/zka/NewKit/KernelCheck.hxx
new file mode 100644
index 00000000..a9d1a452
--- /dev/null
+++ b/dev/zka/NewKit/KernelCheck.hxx
@@ -0,0 +1,71 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ void ke_runtime_check(bool bExpression, const Char* file, const Char* line);
+}
+
+#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG)
+
+#define __MUST_PASS(EXPR, FILE, LINE) \
+ Kernel::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE))
+
+#ifdef __DEBUG__
+#define MUST_PASS(EXPR) __MUST_PASS((EXPR), __FILE__, __LINE__)
+#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION)
+#else
+#define MUST_PASS(EXPR) (Kernel::Void)(EXPR)
+#define assert(EXPR) (Kernel::Void)(EXPR)
+#endif
+
+enum RUNTIME_CHECK
+{
+ RUNTIME_CHECK_FAILED = -1,
+ RUNTIME_CHECK_POINTER = 0,
+ RUNTIME_CHECK_EXPRESSION,
+ RUNTIME_CHECK_FILE,
+ RUNTIME_CHECK_IPC,
+ RUNTIME_CHECK_TLS,
+ RUNTIME_CHECK_HANDSHAKE,
+ RUNTIME_CHECK_ACPI,
+ RUNTIME_CHECK_INVALID_PRIVILEGE,
+ RUNTIME_CHECK_PROCESS,
+ RUNTIME_CHECK_BAD_BEHAVIOR,
+ RUNTIME_CHECK_BOOTSTRAP,
+ RUNTIME_CHECK_UNEXCPECTED,
+ RUNTIME_CHECK_FILESYSTEM,
+ RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM,
+ RUNTIME_CHECK_PAGE,
+ RUNTIME_CHECK_COUNT,
+};
+
+namespace Kernel
+{
+ /// @brief Dumping factory class.
+ class RecoveryFactory final
+ {
+ public:
+ STATIC Void Recover() noexcept;
+ };
+
+ void ke_stop(const Int& id);
+} // namespace Kernel
+
+#ifdef TRY
+#undef TRY
+#endif
+
+#define TRY(FN) \
+ if (!FN()) \
+ { \
+ MUST_PASS(false); \
+ }
diff --git a/dev/zka/NewKit/Macros.hxx b/dev/zka/NewKit/Macros.hxx
new file mode 100644
index 00000000..51b9575b
--- /dev/null
+++ b/dev/zka/NewKit/Macros.hxx
@@ -0,0 +1,133 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#ifndef KIB
+#define KIB(X) (Kernel::UInt64)((X) / 1024)
+#endif
+
+#ifndef kib_cast
+#define kib_cast(X) (Kernel::UInt64)((X) * 1024)
+#endif
+
+#ifndef MIB
+#define MIB(X) (Kernel::UInt64)((Kernel::UInt64)KIB(X) / 1024)
+#endif
+
+#ifndef mib_cast
+#define mib_cast(X) (Kernel::UInt64)((Kernel::UInt64)kib_cast(X) * 1024)
+#endif
+
+#ifndef GIB
+#define GIB(X) (Kernel::UInt64)((Kernel::UInt64)MIB(X) / 1024)
+#endif
+
+#ifndef gib_cast
+#define gib_cast(X) (Kernel::UInt64)((Kernel::UInt64)mib_cast(X) * 1024)
+#endif
+
+#ifndef TIB
+#define TIB(X) (Kernel::UInt64)((Kernel::UInt64)GIB(X) / 1024)
+#endif
+
+#ifndef tib_cast
+#define tib_cast(X) ((Kernel::UInt64)gib_cast(X) * 1024)
+#endif
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) \
+ (((sizeof(a) / sizeof(*(a))) / \
+ (static_cast<Kernel::Size>(!(sizeof(a) % sizeof(*(a)))))))
+#endif
+
+#ifndef ALIGN
+#define ALIGN(X) __attribute__((aligned(X)))
+#endif // #ifndef ALIGN
+
+#ifndef ATTRIBUTE
+#define ATTRIBUTE(X) __attribute__((X))
+#endif // #ifndef ATTRIBUTE
+
+#ifndef __ZKA_VER__
+#define __ZKA_VER__ (2024)
+#endif // !__ZKA_VER__
+
+#ifndef EXTERN_C
+#define EXTERN_C extern "C"
+#endif
+
+#ifndef MAKE_ENUM
+#define MAKE_ENUM(NAME) \
+ enum NAME \
+ {
+#endif
+
+#ifndef END_ENUM
+#define END_ENUM() \
+ } \
+ ;
+#endif
+
+#ifndef MAKE_STRING_ENUM
+#define MAKE_STRING_ENUM(NAME) \
+ namespace NAME \
+ {
+#endif
+
+#ifndef ENUM_STRING
+#define ENUM_STRING(NAME, VAL) inline constexpr const char* e##NAME = VAL
+#endif
+
+#ifndef END_STRING_ENUM
+#define END_STRING_ENUM() }
+#endif
+
+#ifndef ALLOCA
+#define ALLOCA(Sz) __builtin_alloca(Sz)
+#endif // #ifndef ALLOCA
+
+#ifndef CANT_REACH
+#define CANT_REACH() __builtin_unreachable()
+#endif
+
+#define kInvalidAddress 0xFBFBFBFBFBFBFBFB
+#define kBadAddress 0x0000000000000000
+#define kMaxAddr 0xFFFFFFFFFFFFFFFF
+#define kPathLen 0x100
+
+#define PACKED ATTRIBUTE(packed)
+#define NO_EXEC ATTRIBUTE(noexec)
+
+#define EXTERN extern
+#define STATIC static
+
+#define CONST const
+
+#define STRINGIFY(X) #X
+#define ZKA_UNUSED(X) ((Kernel::Void)X)
+
+#ifndef RGB
+#define RGB(R, G, B) (Kernel::UInt32)(R | G << 0x8 | B << 0x10)
+#endif // !RGB
+
+/// @brief The system page file.
+#define kSysPage "\\System\\syspage.sys"
+
+/// @brief The main system driver.
+#define kSysDrv "\\System\\startup.sys"
+
+/// @brief The main font file.
+#define kSysTTF "\\System\\urbanist.ttf"
+
+/// @brief License file
+#define kLicenseTxt "\\System\\License.txt"
+
+/// @brief The main kernel file.
+#define kSysChime "\\System\\startup.wav"
+
+/// @brief The main system loader.
+#define kSysProcess "ZKA AUTHORITY\\KERNEL"
diff --git a/dev/zka/NewKit/MutableArray.hxx b/dev/zka/NewKit/MutableArray.hxx
new file mode 100644
index 00000000..1f9a63c0
--- /dev/null
+++ b/dev/zka/NewKit/MutableArray.hxx
@@ -0,0 +1,239 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <NewKit/Array.hxx>
+#include <NewKit/Defines.hxx>
+
+#define TRY_FIND_NODE(NAME, NODE) \
+ auto* NAME = NODE; \
+ while (NAME) \
+ { \
+ if (NAME->fIndex == Index) \
+ return NAME->fVal; \
+ NAME = NAME->fNext; \
+ }
+
+#define TRY_FIND_NODE2(NAME, NODE) \
+ auto* NAME = NODE; \
+ while (NAME) \
+ { \
+ if (NAME->fIndex == Index) \
+ return Ref<T>{NAME->fVal}; \
+ NAME = NAME->fNext; \
+ }
+
+#define TRY_REMOVE_NODE(NODE) \
+ if (NODE && NODE->fIndex == Index) \
+ { \
+ NODE->fUsed = false; \
+ NODE->fIndex = 0; \
+ \
+ return true; \
+ }
+
+// FIXME: this is a shitty algorithm, which is consumer hungry.
+// Remove and occurences of that, and remove that class.
+namespace Kernel
+{
+ template <typename T>
+ class MutableArray;
+
+ template <typename T, T _PlaceHolderValue>
+ class NullableMutableArray;
+
+ template <typename T>
+ class MutableLinkedList
+ {
+ public:
+ T fVal;
+ SizeT fIndex{0};
+ Boolean fUsed{false};
+
+ MutableLinkedList* fPrev{nullptr};
+ MutableLinkedList* fNext{nullptr};
+ };
+
+ template <typename T, T _PlaceHolderValue>
+ class NullableMutableArray
+ {
+ public:
+ // explicit this.
+ explicit NullableMutableArray()
+ : fFirstNode(new MutableLinkedList<T>())
+ {
+ }
+
+ /*
+ * We free all the nodes allocated by the array
+ * and store the next one inside "NextIt"
+ */
+
+ virtual ~NullableMutableArray()
+ {
+ auto* It = fFirstNode;
+ MutableLinkedList<T>* NextIt = nullptr;
+
+ while (It)
+ {
+ NextIt = It->fNext;
+ delete It;
+
+ It = NextIt;
+ }
+ }
+
+ NullableMutableArray& operator=(const NullableMutableArray&) = default;
+ NullableMutableArray(const NullableMutableArray&) = default;
+
+ operator bool()
+ {
+ return Count() > 1;
+ }
+
+ public:
+ T operator[](const SizeT& Index) const
+ {
+ TRY_FIND_NODE(first, fFirstNode);
+ TRY_FIND_NODE(last, fLastNode);
+
+ return _PlaceHolderValue;
+ }
+
+ SizeT Count() const
+ {
+ return fNodeCount;
+ }
+
+ public:
+ Boolean Remove(const SizeT& Index)
+ {
+ TRY_REMOVE_NODE(fFirstNode);
+ TRY_REMOVE_NODE(fLastNode);
+
+ return false;
+ }
+
+ Boolean Add(const T val)
+ {
+ auto* iterationNode = fFirstNode;
+ MUST_PASS(iterationNode);
+
+ while (iterationNode)
+ {
+ if (!iterationNode->fUsed)
+ {
+ iterationNode->fVal = val;
+ iterationNode->fIndex = 0;
+
+ iterationNode->fUsed = true;
+
+ ++fNodeCount;
+
+ return true;
+ }
+
+ iterationNode = iterationNode->fNext;
+ }
+
+ return false;
+ }
+
+ private:
+ /* Avoid useless lookups */
+ MutableLinkedList<T>* fLastNode{nullptr};
+ MutableLinkedList<T>* fFirstNode{nullptr};
+
+ /* Number of nodes inside of this dynamic array. */
+ Kernel::SizeT fNodeCount{0};
+
+ private:
+ // don't remove that
+ friend MutableArray<T>;
+ };
+
+ template <typename T>
+ class MutableArray : public NullableMutableArray<voidPtr, nullptr>
+ {
+ public:
+ // explicit this.
+ explicit MutableArray() = default;
+ virtual ~MutableArray() = default;
+
+ ZKA_COPY_DEFAULT(MutableArray)
+
+ public:
+ Boolean Add(const T val)
+ {
+ auto* iterationNode = fFirstNode;
+
+ if (!iterationNode)
+ {
+ fFirstNode = new MutableLinkedList<T>();
+ iterationNode = fFirstNode;
+ }
+
+ MUST_PASS(iterationNode);
+
+ while (iterationNode)
+ {
+ if (!iterationNode->fUsed)
+ {
+ iterationNode->fVal = val;
+ iterationNode->fIndex = 0;
+
+ iterationNode->fUsed = true;
+
+ ++fNodeCount;
+
+ return true;
+ }
+
+ iterationNode = iterationNode->fNext;
+ }
+
+ return false;
+ }
+
+ public:
+ Ref<T> operator[](const SizeT& Index) const
+ {
+ TRY_FIND_NODE2(first, fFirstNode);
+ TRY_FIND_NODE2(last, fLastNode);
+
+ return {};
+ }
+
+ SizeT Count() const
+ {
+ return fNodeCount;
+ }
+
+ bool Contains(T& value) noexcept
+ {
+ MutableLinkedList<T>* first = fFirstNode;
+
+ while (first)
+ {
+ if (first->fVal == value && first->fUsed)
+ return true;
+
+ first = first->fNext;
+ }
+
+ return false;
+ }
+
+ private:
+ /* Avoid useless lookups */
+ MutableLinkedList<T>* fLastNode{nullptr};
+ MutableLinkedList<T>* fFirstNode{nullptr};
+
+ /* Number of nodes inside of this dynamic array. */
+ Kernel::SizeT fNodeCount{0};
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/New.hxx b/dev/zka/NewKit/New.hxx
new file mode 100644
index 00000000..8605b9c3
--- /dev/null
+++ b/dev/zka/NewKit/New.hxx
@@ -0,0 +1,18 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+#pragma once
+
+#include <KernelKit/Heap.hxx>
+
+typedef __SIZE_TYPE__ size_t; // gcc will complain about that
+
+void* operator new(size_t ptr);
+void* operator new[](size_t ptr);
+
+void operator delete(void* ptr);
+void operator delete(void* ptr, unsigned long);
+void operator delete[](void* ptr);
diff --git a/dev/zka/NewKit/NewKit.hxx b/dev/zka/NewKit/NewKit.hxx
new file mode 100644
index 00000000..1daa6af2
--- /dev/null
+++ b/dev/zka/NewKit/NewKit.hxx
@@ -0,0 +1,21 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hxx>
+#include <NewKit/ArrayList.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Json.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <KernelKit/LockDelegate.hxx>
+#include <NewKit/MutableArray.hxx>
+#include <NewKit/New.hxx>
+#include <NewKit/OwnPtr.hxx>
+#include <NewKit/Ref.hxx>
+#include <NewKit/Stream.hxx>
+#include <NewKit/Utils.hxx>
diff --git a/dev/zka/NewKit/OwnPtr.hxx b/dev/zka/NewKit/OwnPtr.hxx
new file mode 100644
index 00000000..6e42b33f
--- /dev/null
+++ b/dev/zka/NewKit/OwnPtr.hxx
@@ -0,0 +1,94 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ template <typename T>
+ class OwnPtr;
+
+ template <typename T>
+ class NonNullRefPtr;
+
+ template <typename T>
+ class OwnPtr final
+ {
+ public:
+ OwnPtr()
+ {
+ }
+ ~OwnPtr()
+ {
+ this->Delete();
+ }
+
+ OwnPtr& operator=(const OwnPtr&) = default;
+ OwnPtr(const OwnPtr&) = default;
+
+ public:
+ template <typename... Args>
+ bool New(Args&&... arg)
+ {
+ if (fCls)
+ {
+ return false;
+ }
+
+ fCls = new T(arg...);
+ return fCls;
+ }
+
+ void Delete()
+ {
+ if (fCls)
+ delete fCls;
+
+ fCls = nullptr;
+ }
+
+ T* operator->() const
+ {
+ return fCls;
+ };
+ T* Raw()
+ {
+ return fCls;
+ }
+
+ Ref<T> AsRef()
+ {
+ return Ref<T>(fCls);
+ }
+
+ operator bool()
+ {
+ return fCls;
+ }
+ bool operator!()
+ {
+ return !fCls;
+ }
+
+ private:
+ T* fCls;
+ };
+
+ template <typename T, typename... Args>
+ OwnPtr<T> make_ptr(Args... args)
+ {
+ OwnPtr<T> ret;
+ ret.template New<Args...>(forward(args)...);
+ MUST_PASS(ret);
+
+ return ret;
+ }
+} // namespace Kernel
diff --git a/dev/zka/NewKit/PageMgr.hxx b/dev/zka/NewKit/PageMgr.hxx
new file mode 100644
index 00000000..4faf5c3a
--- /dev/null
+++ b/dev/zka/NewKit/PageMgr.hxx
@@ -0,0 +1,81 @@
+// a way to create and find our pages.
+// I'm thinking about a separate way of getting a paged area.
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ class PageMgr;
+
+ class PTEWrapper final
+ {
+ public:
+ explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0);
+
+ ~PTEWrapper();
+
+ PTEWrapper& operator=(const PTEWrapper&) = default;
+ PTEWrapper(const PTEWrapper&) = default;
+
+ public:
+ const UIntPtr VirtualAddress();
+
+ void NoExecute(const bool enable = false);
+ const Bool& NoExecute();
+
+ operator bool()
+ {
+ return fVirtAddr;
+ }
+
+ bool Reclaim();
+ bool Shareable();
+ bool Present();
+ bool Access();
+
+ private:
+ Boolean fRw;
+ Boolean fUser;
+ Boolean fExecDisable;
+ UIntPtr fVirtAddr;
+ Boolean fCache;
+ Boolean fShareable;
+ Boolean fWt;
+ Boolean fPresent;
+ Boolean fAccessed;
+
+ private:
+ friend class PageMgr;
+ friend class Pmm;
+ };
+
+ struct PageMgr final
+ {
+ public:
+ PageMgr() = default;
+ ~PageMgr() = default;
+
+ PageMgr& operator=(const PageMgr&) = default;
+ PageMgr(const PageMgr&) = default;
+
+ public:
+ PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz);
+ bool Free(Ref<PTEWrapper>& wrapper);
+
+ private:
+ void FlushTLB();
+
+ private:
+ friend PTEWrapper;
+ friend class Pmm;
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Pair.hxx b/dev/zka/NewKit/Pair.hxx
new file mode 100644
index 00000000..e7ca064a
--- /dev/null
+++ b/dev/zka/NewKit/Pair.hxx
@@ -0,0 +1,14 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Pmm.hxx b/dev/zka/NewKit/Pmm.hxx
new file mode 100644
index 00000000..cdf498d9
--- /dev/null
+++ b/dev/zka/NewKit/Pmm.hxx
@@ -0,0 +1,44 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/PageMgr.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ class Pmm;
+ class PTEWrapper;
+
+ class Pmm final
+ {
+ public:
+ explicit Pmm();
+ ~Pmm();
+
+ Pmm& operator=(const Pmm&) = delete;
+ Pmm(const Pmm&) = default;
+
+ Ref<PTEWrapper> RequestPage(Boolean user = false, Boolean readWrite = false);
+ Boolean FreePage(Ref<PTEWrapper> refPage);
+
+ Boolean ToggleRw(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean TogglePresent(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean ToggleUser(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean ToggleShare(Ref<PTEWrapper> refPage, Boolean enable = true);
+
+ /// @brief Get the page manager of this.
+ Ref<PageMgr>& Leak()
+ {
+ return fPageMgr;
+ }
+
+ private:
+ Ref<PageMgr> fPageMgr;
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Ref.hxx b/dev/zka/NewKit/Ref.hxx
new file mode 100644
index 00000000..5a2bf091
--- /dev/null
+++ b/dev/zka/NewKit/Ref.hxx
@@ -0,0 +1,104 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _NEWKIT_REF_HPP_
+#define _NEWKIT_REF_HPP_
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <KernelKit/Heap.hxx>
+
+namespace Kernel
+{
+ template <typename T>
+ class Ref final
+ {
+ public:
+ Ref() = default;
+ ~Ref() = default;
+
+ public:
+ Ref(T cls, const bool& strong = false)
+ : fClass(&cls), fStrong(strong)
+ {
+ }
+
+ Ref& operator=(T ref)
+ {
+ if (!fClass)
+ return *this;
+
+ fClass = &ref;
+ return *this;
+ }
+
+ public:
+ T operator->() const
+ {
+ MUST_PASS(*fClass);
+ return *fClass;
+ }
+
+ T& Leak() noexcept
+ {
+ return *fClass;
+ }
+
+ T& TryLeak() const noexcept
+ {
+ MUST_PASS(*fClass);
+ return *fClass;
+ }
+
+ T operator*()
+ {
+ return *fClass;
+ }
+
+ bool IsStrong() const
+ {
+ return fStrong;
+ }
+
+ operator bool() noexcept
+ {
+ return fStrong;
+ }
+
+ private:
+ T* fClass{nullptr};
+ Bool fStrong{false};
+ };
+
+ template <typename T>
+ class NonNullRef final
+ {
+ public:
+ NonNullRef() = delete;
+ NonNullRef(nullPtr) = delete;
+
+ NonNullRef(T* ref)
+ : fRef(ref, true)
+ {
+ MUST_PASS(ref);
+ }
+
+ Ref<T>& operator->()
+ {
+ MUST_PASS(fRef);
+ return fRef;
+ }
+
+ NonNullRef& operator=(const NonNullRef<T>& ref) = delete;
+ NonNullRef(const NonNullRef<T>& ref) = default;
+
+ private:
+ Ref<T> fRef{nullptr};
+ };
+} // namespace Kernel
+
+#endif // ifndef _NEWKIT_REF_HPP_
diff --git a/dev/zka/NewKit/Stream.hxx b/dev/zka/NewKit/Stream.hxx
new file mode 100644
index 00000000..e2f63b17
--- /dev/null
+++ b/dev/zka/NewKit/Stream.hxx
@@ -0,0 +1,58 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+
+namespace Kernel
+{
+ template <typename StreamTrait, typename Kind>
+ class Stream final
+ {
+ public:
+ explicit Stream(Ref<Stream> ref)
+ : fStream(ref)
+ {
+ }
+
+ ~Stream() = default;
+
+ Stream& operator=(const Stream&) = default;
+ Stream(const Stream&) = default;
+
+ template <typename Data>
+ friend Stream<StreamTrait, Kind>& operator>>(Stream<StreamTrait, Kind>& Ks, Ref<Data>& Buf)
+ {
+ Ks.fKind = Ks.fStream->In(Buf);
+ return *Ks;
+ }
+
+ template <typename Data>
+ friend Stream<StreamTrait, Kind>& operator<<(Stream<StreamTrait, Kind>& Ks, Ref<Data>& Buf)
+ {
+ Ks.fKind = Buf;
+ Ks.fStream->Out(Buf.Leak());
+ return *Ks;
+ }
+
+ Ref<StreamTrait>& AsStreamTrait()
+ {
+ return fStream;
+ }
+
+ Ref<Kind>& AsType()
+ {
+ return fKind;
+ }
+
+ private:
+ Ref<StreamTrait> fStream;
+ Ref<Kind> fKind;
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/String.hxx b/dev/zka/NewKit/String.hxx
new file mode 100644
index 00000000..1849bc77
--- /dev/null
+++ b/dev/zka/NewKit/String.hxx
@@ -0,0 +1,88 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/ErrorOr.hxx>
+#include <NewKit/Utils.hxx>
+#include <NewKit/KernelCheck.hxx>
+
+namespace Kernel
+{
+ class StringView final
+ {
+ public:
+ explicit StringView()
+ {
+ fSz = 4096;
+
+ fData = new Char[fSz];
+ MUST_PASS(fData);
+
+ rt_set_memory(fData, 0, fSz);
+ }
+
+ explicit StringView(Size Sz)
+ : fSz(Sz)
+ {
+ MUST_PASS(Sz > 1);
+ fData = new Char[Sz];
+ MUST_PASS(fData);
+
+ rt_set_memory(fData, 0, Sz);
+ }
+
+ ~StringView()
+ {
+ if (fData)
+ delete[] fData;
+ }
+
+ StringView& operator=(const StringView&) = default;
+ StringView(const StringView&) = default;
+
+ Char* Data();
+ const Char* CData() const;
+ Size Length() const;
+
+ bool operator==(const Char* rhs) const;
+ bool operator!=(const Char* rhs) const;
+
+ bool operator==(const StringView& rhs) const;
+ bool operator!=(const StringView& rhs) const;
+
+ StringView& operator+=(const Char* rhs);
+ StringView& operator+=(const StringView& rhs);
+
+ operator bool()
+ {
+ return fData;
+ }
+
+ bool operator!()
+ {
+ return fData;
+ }
+
+ private:
+ Char* fData{nullptr};
+ Size fSz{0};
+ Size fCur{0};
+
+ friend class StringBuilder;
+ };
+
+ struct StringBuilder final
+ {
+ static ErrorOr<StringView> Construct(const Char* data);
+ static const Char* FromInt(const Char* fmt, int n);
+ static const Char* FromBool(const Char* fmt, bool n);
+ static const Char* Format(const Char* fmt, const Char* from);
+ static bool Equals(const Char* lhs, const Char* rhs);
+ static bool Equals(const WideChar* lhs, const WideChar* rhs);
+ };
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Utils.hxx b/dev/zka/NewKit/Utils.hxx
new file mode 100644
index 00000000..05664a24
--- /dev/null
+++ b/dev/zka/NewKit/Utils.hxx
@@ -0,0 +1,29 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace Kernel
+{
+ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len);
+ Int rt_move_memory(const voidPtr src, voidPtr dst, Size len);
+ voidPtr rt_set_memory(voidPtr dst, UInt32 val, Size len);
+ void rt_zero_memory(voidPtr pointer, Size len);
+ Int rt_string_cmp(const Char* src, const Char* cmp, Size len);
+ const Char* alloc_string(const Char* text);
+ Size rt_string_len(const Char* str);
+ Size rt_string_len(const Char* str, SizeT _len);
+ Boolean rt_to_string(Char* buf, Int limit, Int base);
+ Boolean is_newln(Char chr);
+ Boolean is_space(Char chr);
+ Int rt_to_uppercase(Int c);
+ Int rt_to_lower(Int c);
+ voidPtr rt_string_in_string(const Char* in, const Char* needle);
+ char* rt_string_has_char(Char* str, const Char chr);
+} // namespace Kernel
diff --git a/dev/zka/NewKit/Variant.hxx b/dev/zka/NewKit/Variant.hxx
new file mode 100644
index 00000000..015cec92
--- /dev/null
+++ b/dev/zka/NewKit/Variant.hxx
@@ -0,0 +1,64 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+#include <NewKit/String.hxx>
+#include <NewKit/Json.hxx>
+
+namespace Kernel
+{
+ class Variant final
+ {
+ public:
+ enum class VariantKind
+ {
+ kString,
+ kBlob,
+ kNull,
+ kJson,
+ };
+
+ public:
+ explicit Variant() = delete;
+
+ public:
+ Variant& operator=(const Variant&) = default;
+ Variant(const Variant&) = default;
+
+ ~Variant() = default;
+
+ public:
+ explicit Variant(StringView* stringView)
+ : fPtr((voidPtr)stringView), fKind(VariantKind::kString)
+ {
+ }
+
+ explicit Variant(JsonType* json)
+ : fPtr((voidPtr)json), fKind(VariantKind::kJson)
+ {
+ }
+
+ explicit Variant(nullPtr)
+ : fPtr(nullptr), fKind(VariantKind::kNull)
+ {
+ }
+
+ explicit Variant(voidPtr ptr)
+ : fPtr(ptr), fKind(VariantKind::kBlob)
+ {
+ }
+
+ public:
+ const Char* ToString();
+ VoidPtr Leak();
+
+ private:
+ voidPtr fPtr{nullptr};
+ VariantKind fKind{VariantKind::kNull};
+ };
+} // namespace Kernel
diff --git a/dev/zka/Objects/.hgkeep b/dev/zka/Objects/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/Objects/.hgkeep
diff --git a/dev/zka/ReadMe.md b/dev/zka/ReadMe.md
new file mode 100644
index 00000000..a63661c9
--- /dev/null
+++ b/dev/zka/ReadMe.md
@@ -0,0 +1,3 @@
+# ZKA Minimal Kernel DLL.
+
+A dll which takes the role of the microKernel image.
diff --git a/dev/zka/StorageKit/AHCI.hxx b/dev/zka/StorageKit/AHCI.hxx
new file mode 100644
index 00000000..f3d771c9
--- /dev/null
+++ b/dev/zka/StorageKit/AHCI.hxx
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <KernelKit/DriveMgr.hxx>
+#include <NewKit/OwnPtr.hxx>
+
+namespace Kernel
+{
+ class AHCIDeviceInterface : public DeviceInterface<MountpointInterface*>
+ {
+ public:
+ explicit AHCIDeviceInterface(void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void));
+
+ virtual ~AHCIDeviceInterface();
+
+ public:
+ AHCIDeviceInterface& operator=(const AHCIDeviceInterface&) = default;
+ AHCIDeviceInterface(const AHCIDeviceInterface&) = default;
+
+ const Char* Name() const override;
+
+ private:
+ void (*fCleanup)(void) = {nullptr};
+ };
+} // namespace Kernel
diff --git a/dev/zka/StorageKit/ATA.hxx b/dev/zka/StorageKit/ATA.hxx
new file mode 100644
index 00000000..e954b0e7
--- /dev/null
+++ b/dev/zka/StorageKit/ATA.hxx
@@ -0,0 +1,39 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <KernelKit/DriveMgr.hxx>
+#include <NewKit/OwnPtr.hxx>
+#include <NewKit/Utils.hxx>
+
+namespace Kernel
+{
+ /// @brief ATA device interface type.
+ class ATADeviceInterface : public DeviceInterface<MountpointInterface*>
+ {
+ public:
+ explicit ATADeviceInterface(void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void));
+
+ virtual ~ATADeviceInterface();
+
+ public:
+ ATADeviceInterface& operator<<(MountpointInterface* Data) override;
+ ATADeviceInterface& operator>>(MountpointInterface* Data) override;
+
+ public:
+ ATADeviceInterface& operator=(const ATADeviceInterface&) = default;
+ ATADeviceInterface(const ATADeviceInterface&) = default;
+
+ const Char* Name() const override;
+
+ private:
+ void (*fCleanup)(void) = {nullptr};
+ };
+} // namespace Kernel
diff --git a/dev/zka/StorageKit/NVME.hxx b/dev/zka/StorageKit/NVME.hxx
new file mode 100644
index 00000000..45d00c0c
--- /dev/null
+++ b/dev/zka/StorageKit/NVME.hxx
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DeviceMgr.hxx>
+#include <KernelKit/DriveMgr.hxx>
+#include <NewKit/OwnPtr.hxx>
+
+namespace Kernel
+{
+ class NVMEDeviceInterface final : public DeviceInterface<MountpointInterface*>
+ {
+ public:
+ explicit NVMEDeviceInterface(void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void));
+
+ ~NVMEDeviceInterface() override;
+
+ public:
+ NVMEDeviceInterface& operator=(const NVMEDeviceInterface&) = default;
+ NVMEDeviceInterface(const NVMEDeviceInterface&) = default;
+
+ const Char* Name() const override;
+
+ public:
+ OwnPtr<MountpointInterface*> operator()(UInt32 dmaLow, UInt32 dmaHigh, SizeT sz);
+
+ private:
+ void (*fCleanup)(void) = {nullptr};
+ };
+} // namespace Kernel
diff --git a/dev/zka/StorageKit/PRDT.hxx b/dev/zka/StorageKit/PRDT.hxx
new file mode 100644
index 00000000..6dec22c2
--- /dev/null
+++ b/dev/zka/StorageKit/PRDT.hxx
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/PCI/Dma.hxx>
+#include <KernelKit/PCI/Iterator.hxx>
+#include <NewKit/Ref.hxx>
+
+#define kPrdtTransferSize (sizeof(Kernel::UShort))
+
+namespace Kernel
+{
+ /// @brief Tranfer information about PRD.
+ enum kPRDTTransfer
+ {
+ kPRDTTransferInProgress,
+ kPRDTTransferIsDone,
+ kPRDTTransferCount,
+ };
+
+ /// @brief Physical Region Descriptor Table.
+ struct PRDT
+ {
+ UInt32 fPhysAddress;
+ UInt32 fSectorCount;
+ UInt8 fEndBit;
+ };
+
+ void construct_prdt(Ref<PRDT>& prd);
+
+ EXTERN_C Int32 kPRDTTransferStatus;
+} // namespace Kernel
diff --git a/dev/zka/StorageKit/SCSI.hxx b/dev/zka/StorageKit/SCSI.hxx
new file mode 100644
index 00000000..5a684052
--- /dev/null
+++ b/dev/zka/StorageKit/SCSI.hxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <Modules/SCSI/SCSI.hxx>
+
+extern const scsi_packet_type kCDRomPacketTemplate;
diff --git a/dev/zka/StorageKit/Storage.hxx b/dev/zka/StorageKit/Storage.hxx
new file mode 100644
index 00000000..70f22420
--- /dev/null
+++ b/dev/zka/StorageKit/Storage.hxx
@@ -0,0 +1,22 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#define kDriveSectorSizeHDD (512U)
+#define kDriveSectorSizeSSD (512U)
+#define kDriveSectorSizeOptical (2048)
+
+namespace Kernel
+{
+ template <typename T>
+ class DeviceInterface;
+
+ class NVMEDeviceInterface;
+ class AHCIDeviceInterface;
+ class ATADeviceInterface;
+ class SCSIDeviceInterface;
+} // namespace Kernel
diff --git a/dev/zka/amd64-efi.make b/dev/zka/amd64-efi.make
new file mode 100644
index 00000000..a4bf313d
--- /dev/null
+++ b/dev/zka/amd64-efi.make
@@ -0,0 +1,85 @@
+##################################################
+# (C) ZKA Technologies, all rights reserved.
+# This is the newoskrnl's makefile.
+##################################################
+
+CC = x86_64-w64-mingw32-g++
+LD = x86_64-w64-mingw32-ld
+CCFLAGS = -fshort-wchar -c -D__ZKA_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \
+ -std=c++20 -D__ZKA_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEFS__ \
+ -D__NEWOSKRNL__ -D__HAVE_ZKA_APIS__ -D__FREESTANDING__ -D__ZKA__ -I./ -I../ -I../ZBA
+
+ASM = nasm
+
+DISK_DRV =
+
+ifneq ($(ATA_PIO_SUPPORT), )
+DISK_DRV = -D__ATA_PIO__
+endif
+
+ifneq ($(ATA_DMA_SUPPORT), )
+DISK_DRV = -D__ATA_DMA__
+endif
+
+ifneq ($(AHCI_SUPPORT), )
+DISK_DRV = -D__AHCI__
+endif
+
+ifneq ($(DEBUG_SUPPORT), )
+DEBUG_MACRO = -D__DEBUG__
+endif
+
+COPY = cp
+
+# Add assembler, linker, and object files variables.
+ASMFLAGS = -f win64
+
+# Kernel subsystem is 17 and entrypoint is hal_init_platform
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
+LDOBJ = Objects/*.obj
+
+# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.
+KERNEL_IMG = newoskrnl.exe
+
+.PHONY: error
+error:
+ @echo "=== ERROR ==="
+ @echo "=> Use a specific target."
+
+MOVEALL=./MoveAll.X64.sh
+WINDRES=x86_64-w64-mingw32-windres
+
+.PHONY: newos-amd64-epm
+newos-amd64-epm: clean
+ $(WINDRES) KernelRsrc.rsrc -O coff -o KernelRsrc.obj
+ $(CC) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cxx) \
+ $(wildcard src/FS/*.cxx) $(wildcard HALKit/AMD64/Storage/*.cxx) \
+ $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard src/Network/*.cxx) $(wildcard src/Storage/*.cxx) \
+ $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) \
+ $(wildcard HALKit/AMD64/*.s)
+ $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm
+ $(ASM) $(ASMFLAGS) HALKit/AMD64/HalMPContextSwitch.asm
+ $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBoot.asm
+ $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtils.asm
+ $(MOVEALL)
+
+OBJCOPY=x86_64-w64-mingw32-objcopy
+
+.PHONY: link-amd64-epm
+link-amd64-epm:
+ $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL_IMG)
+
+.PHONY: all
+all: newos-amd64-epm link-amd64-epm
+ @echo "Kernel => OK."
+
+.PHONY: help
+help:
+ @echo "=== HELP ==="
+ @echo "all: Build Kernel and link it."
+ @echo "link-amd64-epm: Link Kernel for EPM based disks."
+ @echo "newos-amd64-epm: Build Kernel for EPM based disks."
+
+.PHONY: clean
+clean:
+ rm -f $(LDOBJ) $(wildcard *.o) $(KERNEL_IMG)
diff --git a/dev/zka/arm64-efi.make b/dev/zka/arm64-efi.make
new file mode 100644
index 00000000..bb5f73ee
--- /dev/null
+++ b/dev/zka/arm64-efi.make
@@ -0,0 +1,64 @@
+##################################################
+# (C) ZKA Technologies, all rights reserved.
+# This is the microKernel makefile.
+##################################################
+
+CC = clang++
+LD = lld-link
+CCFLAGS = -fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__ZKA_ARM64__ -fno-rtti -fno-exceptions -I./ \
+ -target aarch64-unknown-windows \
+ -std=c++20 -D__FSKIT_USE_NEFS__ -D__ZETA_MACHINE__ -D__NEWOSKRNL__ -D__HAVE_ZKA_APIS__ -D__ZKA__ -I../
+
+ASM = clang++
+
+DISKDRIVER = -D__USE_FLASH_MEM__ -D__USE_SAS__ -D__USE_SATA__
+
+ifneq ($(DEBUG_SUPPORT), )
+DEBUG = -D__DEBUG__
+endif
+
+COPY = cp
+
+LDFLAGS = -subsystem:efi_application -entry:hal_init_platform /nodefaultlib
+LDOBJ = Objects/*.obj
+
+# This file is the Kernel, responsible of task management and memory.
+KERNEL = newoskrnl.so
+
+.PHONY: error
+error:
+ @echo "=== ERROR ==="
+ @echo "=> Use a specific target."
+
+MOVEALL=./MoveAll.ARM64.sh
+
+.PHONY: newos-arm64-epm
+newos-arm64-epm: clean
+ $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard src/*.cxx) \
+ $(wildcard src/FS/*.cxx) $(wildcard HALKit/ARM64/Storage/*.cxx) \
+ $(wildcard HALKit/ARM64/PCI/*.cxx) $(wildcard src/Network/*.cxx) $(wildcard src/Storage/*.cxx) \
+ $(wildcard HALKit/ARM64/*.cxx) $(wildcard HALKit/ARM64/*.cpp) \
+ $(wildcard HALKit/ARM64/*.s)
+
+ $(MOVEALL)
+
+OBJCOPY=x86_64-w64-mingw32-objcopy
+
+.PHONY: link-arm64-epm
+link-arm64-epm:
+ $(LD) $(LDFLAGS) $(LDOBJ) /out:$(KERNEL)
+
+.PHONY: all
+all: newos-arm64-epm link-arm64-epm
+ @echo "Kernel => OK."
+
+.PHONY: help
+help:
+ @echo "=== HELP ==="
+ @echo "all: Build Kernel and link it."
+ @echo "link-arm64-epm: Link Kernel for EPM based disks."
+ @echo "newos-arm64-epm: Build Kernel for EPM based disks."
+
+.PHONY: clean
+clean:
+ rm -f $(LDOBJ) $(wildcard *.o) $(KERNEL)
diff --git a/dev/zka/power64-cb.make b/dev/zka/power64-cb.make
new file mode 100644
index 00000000..68ec214f
--- /dev/null
+++ b/dev/zka/power64-cb.make
@@ -0,0 +1,4 @@
+##################################################
+# (C) ZKA Technologies, all rights reserved.
+# This is the microKernel makefile.
+##################################################
diff --git a/dev/zka/riscv64-cb.make b/dev/zka/riscv64-cb.make
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/zka/riscv64-cb.make
diff --git a/dev/zka/src/Array.cxx b/dev/zka/src/Array.cxx
new file mode 100644
index 00000000..202bee7e
--- /dev/null
+++ b/dev/zka/src/Array.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Array.hxx>
diff --git a/dev/zka/src/ArrayList.cxx b/dev/zka/src/ArrayList.cxx
new file mode 100644
index 00000000..71589c9b
--- /dev/null
+++ b/dev/zka/src/ArrayList.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/ArrayList.hxx>
diff --git a/dev/zka/src/Atom.cxx b/dev/zka/src/Atom.cxx
new file mode 100644
index 00000000..e5a3f407
--- /dev/null
+++ b/dev/zka/src/Atom.cxx
@@ -0,0 +1,10 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Atom.hxx>
+
+// @file Atom.cpp
+// @brief Atomic primitives
diff --git a/dev/zka/src/CodeMgr.cxx b/dev/zka/src/CodeMgr.cxx
new file mode 100644
index 00000000..13bcd640
--- /dev/null
+++ b/dev/zka/src/CodeMgr.cxx
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Utils.hxx>
+#include <KernelKit/CodeMgr.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+namespace Kernel
+{
+ /// @brief Executes a new process from a function. Kernel code only.
+ /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible.
+ /// @param main the start of the process.
+ /// @return if the process was started or not.
+ Bool sched_execute_thread(MainKind main, const Char* process_name) noexcept
+ {
+ if (!main)
+ return No;
+
+ UserProcess proc;
+ proc.SetImageStart(reinterpret_cast<VoidPtr>(main));
+
+ proc.Kind = UserProcess::kExeKind;
+ proc.StackSize = kib_cast(32);
+
+ rt_set_memory(proc.Name, 0, kProcessLen);
+ rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name));
+
+ return UserProcessScheduler::The().Add(proc) > 0;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Crc32.cxx b/dev/zka/src/Crc32.cxx
new file mode 100644
index 00000000..42dc9b8e
--- /dev/null
+++ b/dev/zka/src/Crc32.cxx
@@ -0,0 +1,74 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Crc32.hxx>
+
+// @file CRC32.cpp
+// @brief Check sequence implementation.
+
+namespace Kernel
+{
+ /// @brief The CRC32 table.
+ UInt kCrcTbl[kCrcCnt] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
+
+ /// @brief Calculate CRC32 of p
+ /// @param p the data to compute.
+ /// @param len the length of the data.
+ /// @return the CRC32.
+ UInt ke_calculate_crc32(const Char* p, UInt len) noexcept
+ {
+ UInt crc = 0xffffffff;
+
+ while (len-- != 0)
+ crc = kCrcTbl[((UInt8)crc ^ *(p++))] ^ (crc >> 8);
+
+ // return (~crc); also works, does the same thing.
+ return (crc ^ 0xffffffff);
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/CxxAbi-AMD64.cxx b/dev/zka/src/CxxAbi-AMD64.cxx
new file mode 100644
index 00000000..908e26f4
--- /dev/null
+++ b/dev/zka/src/CxxAbi-AMD64.cxx
@@ -0,0 +1,91 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifdef __ZKA_AMD64__
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/CxxAbi.hxx>
+#include <KernelKit/LPC.hxx>
+
+atexit_func_entry_t __atexit_funcs[kDSOMaxObjects];
+
+uarch_t __atexit_func_count;
+
+/// @brief Dynamic Shared Object Handle.
+Kernel::UIntPtr __dso_handle;
+
+EXTERN_C void __cxa_pure_virtual()
+{
+ kcout << "C++ placeholder method.\n";
+}
+
+EXTERN_C void ___chkstk_ms(void)
+{
+ Kernel::err_bug_check_raise();
+ Kernel::err_bug_check();
+}
+
+EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso)
+{
+ if (__atexit_func_count >= kDSOMaxObjects)
+ return -1;
+
+ __atexit_funcs[__atexit_func_count].destructor_func = f;
+ __atexit_funcs[__atexit_func_count].obj_ptr = arg;
+ __atexit_funcs[__atexit_func_count].dso_handle = dso;
+
+ __atexit_func_count++;
+
+ return 0;
+}
+
+EXTERN_C void __cxa_finalize(void* f)
+{
+ uarch_t i = __atexit_func_count;
+ if (!f)
+ {
+ while (i--)
+ {
+ if (__atexit_funcs[i].destructor_func)
+ {
+ (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
+ };
+ }
+
+ return;
+ }
+
+ while (i--)
+ {
+ if (__atexit_funcs[i].destructor_func)
+ {
+ (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
+ __atexit_funcs[i].destructor_func = 0;
+ };
+ }
+}
+
+namespace cxxabiv1
+{
+ EXTERN_C int __cxa_guard_acquire(__guard* g)
+ {
+ (void)g;
+ return 0;
+ }
+
+ EXTERN_C int __cxa_guard_release(__guard* g)
+ {
+ *(char*)g = 1;
+ return 0;
+ }
+
+ EXTERN_C void __cxa_guard_abort(__guard* g)
+ {
+ (void)g;
+ }
+} // namespace cxxabiv1
+
+#endif // ifdef __ZKA_AMD64__
diff --git a/dev/zka/src/CxxAbi-ARM64.cxx b/dev/zka/src/CxxAbi-ARM64.cxx
new file mode 100644
index 00000000..679be041
--- /dev/null
+++ b/dev/zka/src/CxxAbi-ARM64.cxx
@@ -0,0 +1,74 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifdef __ZKA_ARM64__
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/CxxAbi.hxx>
+#include <KernelKit/LPC.hxx>
+
+EXTERN_C
+{
+#include <limits.h>
+}
+
+int const cUninitialized = 0;
+int const cBeingInitialized = -1;
+int const cEpochStart = INT_MIN;
+
+EXTERN_C
+{
+ int _Init_global_epoch = cEpochStart;
+ __thread int _Init_thread_epoch = cEpochStart;
+}
+
+Kernel::UInt32 const cNKTimeout = 100; // ms
+
+EXTERN_C void __cdecl _Init_thread_wait(Kernel::UInt32 const timeout)
+{
+ MUST_PASS(timeout != INT_MAX);
+}
+
+EXTERN_C void __cdecl _Init_thread_header(int* const pOnce) noexcept
+{
+ if (*pOnce == cUninitialized)
+ {
+ *pOnce = cBeingInitialized;
+ }
+ else
+ {
+ while (*pOnce == cBeingInitialized)
+ {
+ _Init_thread_wait(cNKTimeout);
+
+ if (*pOnce == cUninitialized)
+ {
+ *pOnce = cBeingInitialized;
+ return;
+ }
+ }
+ _Init_thread_epoch = _Init_global_epoch;
+ }
+}
+
+EXTERN_C void __cdecl _Init_thread_abort(int* const pOnce) noexcept
+{
+ *pOnce = cUninitialized;
+}
+
+EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept
+{
+ ++_Init_global_epoch;
+ *pOnce = _Init_global_epoch;
+ _Init_thread_epoch = _Init_global_epoch;
+}
+
+EXTERN_C void _purecall()
+{
+ kcout << "C++ placeholder method.\n";
+}
+
+#endif // ifdef __ZKA_ARM64__
diff --git a/dev/zka/src/Defines.cxx b/dev/zka/src/Defines.cxx
new file mode 100644
index 00000000..2e8dde86
--- /dev/null
+++ b/dev/zka/src/Defines.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Defines.hxx>
diff --git a/dev/zka/src/DeviceMgr.cxx b/dev/zka/src/DeviceMgr.cxx
new file mode 100644
index 00000000..70d01984
--- /dev/null
+++ b/dev/zka/src/DeviceMgr.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DeviceMgr.hxx>
diff --git a/dev/zka/src/DriveMgr.cxx b/dev/zka/src/DriveMgr.cxx
new file mode 100644
index 00000000..f6436f75
--- /dev/null
+++ b/dev/zka/src/DriveMgr.cxx
@@ -0,0 +1,151 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/DriveMgr.hxx>
+#include <NewKit/Utils.hxx>
+
+#include <Modules/ATA/ATA.hxx>
+#include <Modules/AHCI/AHCI.hxx>
+#include <Modules/NVME/Defines.hxx>
+
+/// @file DriveMgr.cxx
+/// @brief Kernel drive manager.
+
+namespace Kernel
+{
+ STATIC UInt16 kATAIO = 0U;
+ STATIC UInt8 kATAMaster = 0U;
+
+ /// @brief reads from an ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_input(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+#ifdef __AHCI__
+ drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize);
+#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
+#endif
+ }
+
+ /// @brief Writes to an ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_output(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+#ifdef __AHCI__
+ drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize);
+#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
+#endif
+ }
+
+ /// @brief Executes a disk check on the ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_init(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+ pckt->fPacketGood = false;
+
+#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ kATAMaster = true;
+ kATAIO = ATA_PRIMARY_IO;
+
+ MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster));
+#elif defined(__AHCI__)
+ UInt16 pi = 0;
+ MUST_PASS(drv_std_init(pi));
+#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__)
+
+ pckt->fPacketGood = true;
+ }
+
+/// @brief Gets the drive kind (ATA, SCSI, AHCI...)
+/// @param
+/// @return
+#ifdef __ATA_PIO__
+ const Char* ke_drv_kind(Void)
+ {
+ return "ATA-PIO";
+ }
+#endif
+
+#ifdef __ATA_DMA__
+ const Char* ke_drv_kind(Void)
+ {
+ return "ATA-DMA";
+ }
+#endif
+
+#ifdef __AHCI__
+ const Char* ke_drv_kind(Void)
+ {
+ return "AHCI";
+ }
+#endif
+
+ /// @brief Unimplemented drive.
+ /// @param pckt
+ /// @return
+ Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt)
+ {
+ ZKA_UNUSED(pckt);
+ }
+
+ /// @brief Makes a new drive.
+ /// @return the new drive.
+ DriveTrait io_construct_drive() noexcept
+ {
+ DriveTrait trait;
+
+ rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:"));
+ trait.fKind = kInvalidDrive;
+
+ trait.fInput = io_drv_unimplemented;
+ trait.fOutput = io_drv_unimplemented;
+ trait.fVerify = io_drv_unimplemented;
+ trait.fInit = io_drv_unimplemented;
+ trait.fDriveKind = ke_drv_kind;
+
+ return trait;
+ }
+
+ /// @brief Fetches the main drive.
+ /// @return the new drive.
+ DriveTrait io_construct_main_drive() noexcept
+ {
+ DriveTrait trait;
+
+ rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:"));
+ trait.fKind = kMassStorage;
+
+ trait.fInput = ke_drv_input;
+ trait.fOutput = ke_drv_output;
+ trait.fVerify = io_drv_unimplemented;
+ trait.fInit = ke_drv_init;
+ trait.fDriveKind = ke_drv_kind;
+
+ kcout << "Construct drive with success.\r";
+
+ return trait;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/ErrorOr.cxx b/dev/zka/src/ErrorOr.cxx
new file mode 100644
index 00000000..0205506d
--- /dev/null
+++ b/dev/zka/src/ErrorOr.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/ErrorOr.hxx>
+
+/***********************************************************************************/
+/// @file ErrorOr.cxx ///
+/// @brief Error Or Value class. ///
+/***********************************************************************************/
diff --git a/dev/zka/src/FS/FAT32.cxx b/dev/zka/src/FS/FAT32.cxx
new file mode 100644
index 00000000..9e22e2a8
--- /dev/null
+++ b/dev/zka/src/FS/FAT32.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifdef __FSKIT_INCLUDES_HPFS__
+
+#include <FirmwareKit/GPT.hxx>
+#include <FirmwareKit/EPM.hxx>
+
+#endif // ifdef __FSKIT_INCLUDES_HPFS__
diff --git a/dev/zka/src/FS/NeFS.cxx b/dev/zka/src/FS/NeFS.cxx
new file mode 100644
index 00000000..69b0c401
--- /dev/null
+++ b/dev/zka/src/FS/NeFS.cxx
@@ -0,0 +1,1055 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifdef __FSKIT_USE_NEFS__
+
+#include <Modules/AHCI/AHCI.hxx>
+#include <Modules/ATA/ATA.hxx>
+#include <Modules/Flash/Flash.hxx>
+#include <FSKit/NeFS.hxx>
+#include <KernelKit/LPC.hxx>
+#include <NewKit/Crc32.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <NewKit/String.hxx>
+#include <NewKit/Utils.hxx>
+#include <FirmwareKit/EPM.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/User.hxx>
+
+using namespace Kernel;
+
+#ifdef __ED__
+/***********************************************************************************/
+/**
+ Define those external symbols, to make the editor shutup
+*/
+/***********************************************************************************/
+
+/***********************************************************************************/
+/// @brief get sector count.
+/***********************************************************************************/
+Kernel::SizeT drv_get_sector_count();
+
+/***********************************************************************************/
+/// @brief get device size.
+/***********************************************************************************/
+Kernel::SizeT drv_get_size();
+
+#endif
+
+///! BUGS: 0
+
+/***********************************************************************************/
+/// This file implements the New File System.
+/// New File System implements a B-Tree based algortihm.
+/// \\
+/// \\Path1\\ \\ath2\\
+/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink.
+/// \\Path1\\readme.rtf
+/***********************************************************************************/
+
+STATIC MountpointInterface sMountpointInterface;
+
+/***********************************************************************************/
+/// @brief Creates a new fork inside the New filesystem partition.
+/// @param catalog it's catalog
+/// @param the_fork the fork itself.
+/// @return the fork
+/***********************************************************************************/
+_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
+ _Input NFS_FORK_STRUCT& the_fork)
+{
+ if (catalog && the_fork.ForkName[0] != 0 &&
+ the_fork.DataSize <= kNeFSForkDataSz)
+ {
+ Lba lba = (the_fork.Kind == kNeFSDataForkKind) ? catalog->DataFork
+ : catalog->ResourceFork;
+
+ kcout << "fork lba: " << hex_number(lba) << endl;
+
+ if (lba <= kNeFSCatalogStartAddress)
+ return nullptr;
+
+ auto drv = sMountpointInterface.A();
+
+ /// special treatment.
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ NFS_FORK_STRUCT curFork{0};
+ NFS_FORK_STRUCT prevFork{0};
+ Lba lbaOfPreviousFork = lba;
+
+ /// do not check for anything. Loop until we get what we want, that is a free fork zone.
+ while (true)
+ {
+ if (lba <= kNeFSCatalogStartAddress)
+ break;
+
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &curFork;
+
+ drv.fInput(&drv.fPacket);
+
+ if (curFork.NextSibling > kBadAddress)
+ {
+ kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl;
+ break;
+ }
+
+ kcout << "next fork: " << hex_number(curFork.NextSibling) << endl;
+
+ if (curFork.Flags & kNeFSFlagCreated)
+ {
+ kcout << "fork already exists.\r";
+
+ /// sanity check.
+ if (StringBuilder::Equals(curFork.ForkName, the_fork.ForkName) &&
+ StringBuilder::Equals(curFork.CatalogName, catalog->Name))
+ return nullptr;
+
+ kcout << "next fork: " << hex_number(curFork.NextSibling) << endl;
+
+ lbaOfPreviousFork = lba;
+ lba = curFork.NextSibling;
+
+ prevFork = curFork;
+ }
+ else
+ {
+ /// This is a check that we have, in order to link the previous fork
+ /// entry.
+ if (lba >= kNeFSCatalogStartAddress)
+ {
+ drv.fPacket.fLba = lbaOfPreviousFork;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &prevFork;
+
+ prevFork.NextSibling = lba;
+
+ /// write to disk.
+ drv.fOutput(&drv.fPacket);
+ }
+
+ break;
+ }
+ }
+
+ constexpr auto cForkPadding =
+ 4; /// this value gives us space for the data offset.
+
+ the_fork.Flags |= kNeFSFlagCreated;
+ the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT);
+ the_fork.PreviousSibling = lbaOfPreviousFork;
+ the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT);
+
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &the_fork;
+
+ drv.fOutput(&drv.fPacket);
+
+ /// log what we have now.
+ kcout << "Wrote fork data at: " << hex_number(the_fork.DataOffset)
+ << endl;
+
+ kcout << "Wrote fork at: " << hex_number(lba) << endl;
+
+ return &the_fork;
+ }
+
+ return nullptr;
+}
+
+/***********************************************************************************/
+/// @brief Find fork inside New filesystem.
+/// @param catalog the catalog.
+/// @param name the fork name.
+/// @return the fork.
+/***********************************************************************************/
+_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
+ _Input const Char* name,
+ Boolean isDataFork)
+{
+ auto drv = sMountpointInterface.A();
+ NFS_FORK_STRUCT* the_fork = nullptr;
+
+ Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
+
+ while (lba != 0)
+ {
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = (VoidPtr)the_fork;
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16);
+
+ if (auto res =
+ fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex);
+ res)
+ {
+ switch (res)
+ {
+ case 1:
+ ErrLocal() = kErrorDiskReadOnly;
+ break;
+ case 2:
+ ErrLocal() = kErrorDiskIsFull;
+ break;
+ ErrLocal() = kErrorNoSuchDisk;
+ break;
+
+ default:
+ break;
+ }
+ return nullptr;
+ }
+
+ if (StringBuilder::Equals(the_fork->ForkName, name))
+ {
+ break;
+ }
+
+ lba = the_fork->NextSibling;
+ }
+
+ return the_fork;
+}
+
+/***********************************************************************************/
+/// @brief Simpler factory to create a catalog (assumes you want to create a
+/// file.)
+/// @param name
+/// @return catalog pointer.
+/***********************************************************************************/
+_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name)
+{
+ return this->CreateCatalog(name, 0, kNeFSCatalogKindFile);
+}
+
+/***********************************************************************************/
+/// @brief Creates a new catalog into the disk.
+/// @param name the catalog name.
+/// @param flags the flags of the catalog.
+/// @param kind the catalog kind.
+/// @return catalog pointer.
+/***********************************************************************************/
+_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
+ _Input const Int32& flags,
+ _Input const Int32& kind)
+{
+ kcout << "CreateCatalog(...)\r";
+
+ Lba out_lba = 0UL;
+
+ kcout << "Checking for extension...\r";
+
+ /// a directory should have a slash in the end.
+ if (kind == kNeFSCatalogKindDir &&
+ name[rt_string_len(name) - 1] != NeFileSystemHelper::Separator())
+ return nullptr;
+
+ /// a file shouldn't have a slash in the end.
+ if (kind != kNeFSCatalogKindDir &&
+ name[rt_string_len(name) - 1] == NeFileSystemHelper::Separator())
+ return nullptr;
+
+ NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba);
+
+ if (catalog_copy)
+ {
+ kcout << "Catalog already exists: " << name << ".\r";
+ ErrLocal() = kErrorFileExists;
+
+ return catalog_copy;
+ }
+
+ Char parentName[kNeFSNodeNameLen] = {0};
+
+ for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName)
+ {
+ parentName[indexName] = name[indexName];
+ }
+
+ if (*parentName == 0)
+ {
+ kcout << "Parent name is NUL.\r";
+ ErrLocal() = kErrorFileNotFound;
+ return nullptr;
+ }
+
+ /// Locate parent catalog, to then allocate right after it.
+
+ for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill)
+ {
+ parentName[indexFill] = name[indexFill];
+ }
+
+ SizeT indexReverseCopy = rt_string_len(parentName);
+
+ // zero character it.
+ parentName[--indexReverseCopy] = 0;
+
+ // mandatory / character, zero it.
+ parentName[--indexReverseCopy] = 0;
+
+ while (parentName[indexReverseCopy] != NeFileSystemHelper::Separator())
+ {
+ parentName[indexReverseCopy] = 0;
+ --indexReverseCopy;
+ }
+
+ NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, out_lba);
+
+ auto drive = sMountpointInterface.A();
+
+ if (catalog && catalog->Kind == kNeFSCatalogKindFile)
+ {
+ kcout << "Parent name is file.\r";
+ delete catalog;
+ return nullptr;
+ }
+ else if (!catalog)
+ {
+ Char sectorBufPartBlock[kNeFSSectorSz] = {0};
+
+ drive.fPacket.fPacketContent = sectorBufPartBlock;
+ drive.fPacket.fPacketSize = kNeFSSectorSz;
+ drive.fPacket.fLba = kNeFSRootCatalogStartAddress;
+
+ drive.fInput(&drive.fPacket);
+
+ constexpr auto cNeFSCatalogPadding = 4;
+
+ NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock;
+ out_lba = partBlock->StartCatalog;
+ }
+
+ constexpr SizeT cDefaultForkSize = kNeFSForkSize;
+
+ NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT();
+
+ Int32 flagsList = flags;
+
+ catalogChild->ResourceForkSize = cDefaultForkSize;
+ catalogChild->DataForkSize = cDefaultForkSize;
+
+ catalogChild->NextSibling = out_lba;
+ catalogChild->PrevSibling = out_lba;
+ catalogChild->Kind = kind;
+ catalogChild->Flags = kNeFSFlagCreated | flagsList;
+
+ rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name,
+ rt_string_len(name));
+
+ UInt16 catalogBuf[kNeFSSectorSz] = {0};
+
+ Lba start_free = out_lba;
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ drive.fPacket.fPacketContent = catalogBuf;
+ drive.fPacket.fPacketSize = kNeFSSectorSz;
+ drive.fPacket.fLba = start_free;
+
+ drive.fInput(&drive.fPacket);
+
+ NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf;
+
+ start_free = nextSibling->NextSibling;
+
+ catalogChild->PrevSibling = out_lba;
+
+ drive.fPacket.fLba = start_free;
+ drive.fInput(&drive.fPacket);
+
+ while (drive.fPacket.fPacketGood)
+ {
+ nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf);
+
+ if (start_free <= kNeFSRootCatalogStartAddress)
+ {
+ delete catalogChild;
+ delete catalog;
+
+ return nullptr;
+ }
+
+ // ========================== //
+ // Allocate catalog now...
+ // ========================== //
+ if ((nextSibling->Flags & kNeFSFlagCreated) == 0)
+ {
+ Char sectorBufPartBlock[kNeFSSectorSz] = {0};
+
+ drive.fPacket.fPacketContent = sectorBufPartBlock;
+ drive.fPacket.fPacketSize = kNeFSSectorSz;
+ drive.fPacket.fLba = kNeFSRootCatalogStartAddress;
+
+ drive.fInput(&drive.fPacket);
+
+ constexpr auto cNeFSCatalogPadding = 4;
+
+ NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock;
+
+ if (partBlock->FreeCatalog < 1)
+ {
+ delete catalogChild;
+ return nullptr;
+ }
+
+ catalogChild->DataFork = partBlock->DiskSize - start_free;
+ catalogChild->ResourceFork = catalogChild->DataFork;
+
+ // Write the new catalog next sibling, if we don't know this parent. //
+ // This is necessary, so that we don't have to get another lba to allocate. //
+ if (!StringBuilder::Equals(parentName, nextSibling->Name))
+ {
+ catalogChild->NextSibling =
+ start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding);
+ }
+
+ drive.fPacket.fPacketContent = catalogChild;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+ drive.fPacket.fLba = start_free;
+
+ drive.fOutput(&drive.fPacket);
+
+ // Get NeFS partition's block.
+
+ drive.fPacket.fPacketContent = sectorBufPartBlock;
+ drive.fPacket.fPacketSize = kNeFSSectorSz;
+ drive.fPacket.fLba = kNeFSRootCatalogStartAddress;
+
+ drive.fInput(&drive.fPacket);
+
+ partBlock->FreeSectors -= 1;
+ partBlock->CatalogCount += 1;
+ partBlock->FreeCatalog -= 1;
+
+ drive.fOutput(&drive.fPacket);
+
+ kcout << "Create new catalog, status: "
+ << hex_number(catalogChild->Flags) << endl;
+ kcout << "Create new catalog, name: " << catalogChild->Name
+ << endl;
+
+ delete catalog;
+ return catalogChild;
+ }
+ else if ((nextSibling->Flags & kNeFSFlagCreated) &&
+ StringBuilder::Equals(nextSibling->Name, name))
+ {
+ return nextSibling;
+ }
+
+ constexpr auto cNeFSCatalogPadding = 4;
+
+ //// @note that's how we find the next catalog in the partition block.
+ start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding);
+
+ drive.fPacket.fPacketContent = catalogBuf;
+ drive.fPacket.fPacketSize = kNeFSSectorSz;
+ drive.fPacket.fLba = start_free;
+
+ drive.fInput(&drive.fPacket);
+ }
+
+ delete catalog;
+ return nullptr;
+}
+
+/// @brief Make a EPM+NeFS drive out of the disk.
+/// @param drive The drive to write on.
+/// @return If it was sucessful, see ErrLocal().
+bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name)
+{
+ if (*part_name == 0 ||
+ endLba == 0)
+ return false;
+
+ // verify disk.
+ drive->fVerify(&drive->fPacket);
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ // if disk isn't good, then error out.
+ if (false == drive->fPacket.fPacketGood)
+ {
+ ErrLocal() = kErrorDiskIsCorrupted;
+ return false;
+ }
+
+ Char fs_buf[kNeFSSectorSz] = {0};
+
+ Lba start = kNeFSRootCatalogStartAddress;
+
+ drive->fPacket.fPacketContent = fs_buf;
+ drive->fPacket.fPacketSize = kNeFSSectorSz;
+ drive->fPacket.fLba = start;
+
+ drive->fInput(&drive->fPacket);
+
+ if (flags & kNeFSPartitionTypeBoot)
+ {
+ // make it bootable when needed.
+ Char bufEpmHdr[kNeFSSectorSz] = {0};
+
+ BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr;
+
+ // EPM header.
+
+ constexpr auto cFsName = "NeFS";
+ constexpr auto cBlockName = "ZKA:";
+
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, rt_string_len(cFsName));
+
+ epmBoot->FsVersion = kNeFSVersionInteger;
+ epmBoot->LbaStart = start;
+ epmBoot->SectorSz = kNeFSSectorSz;
+
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), epmBoot->Name, rt_string_len(cBlockName));
+ rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic));
+
+ Lba outEpmLba = kEpmBase;
+
+ Char buf[kNeFSSectorSz];
+
+ Lba prevStart = 0;
+ SizeT cnt = 0;
+
+ while (drive->fPacket.fPacketGood)
+ {
+ drive->fPacket.fPacketContent = buf;
+ drive->fPacket.fPacketSize = kNeFSSectorSz;
+ drive->fPacket.fLba = outEpmLba;
+
+ drive->fInput(&drive->fPacket);
+
+ if (buf[0] == 0)
+ {
+ epmBoot->LbaStart = prevStart;
+
+ if (epmBoot->LbaStart)
+ epmBoot->LbaStart = outEpmLba;
+
+ epmBoot->LbaEnd = endLba;
+ epmBoot->NumBlocks = cnt;
+
+ drive->fPacket.fPacketContent = bufEpmHdr;
+ drive->fPacket.fPacketSize = kNeFSSectorSz;
+ drive->fPacket.fLba = outEpmLba;
+
+ drive->fOutput(&drive->fPacket);
+
+ break;
+ }
+ else
+ {
+ prevStart = ((BOOT_BLOCK_STRUCT*)buf)->LbaStart + ((BOOT_BLOCK_STRUCT*)buf)->LbaEnd;
+ }
+
+ outEpmLba += sizeof(BOOT_BLOCK_STRUCT);
+ ++cnt;
+ }
+ }
+
+ // disk isnt faulty and data has been fetched.
+ while (drive->fPacket.fPacketGood)
+ {
+ NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf;
+
+ // check for an empty partition here.
+ if (partBlock->PartitionName[0] == 0 &&
+ rt_string_cmp(partBlock->Ident, kNeFSIdent, kNeFSIdentLen))
+ {
+ // partition is free and valid.
+
+ partBlock->Version = kNeFSVersionInteger;
+
+ const auto cUntitledHD = part_name;
+
+ rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)partBlock->Ident,
+ kNeFSIdentLen);
+
+ rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName,
+ rt_string_len(cUntitledHD));
+
+ SizeT catalogCount = 0UL;
+
+ SizeT sectorCount = drv_get_sector_count();
+ SizeT diskSize = drv_get_size();
+
+ partBlock->Kind = kNeFSPartitionTypeStandard;
+ partBlock->StartCatalog = kNeFSCatalogStartAddress;
+ partBlock->Flags = kNeFSPartitionTypeStandard;
+ partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT);
+ partBlock->SectorCount = sectorCount;
+ partBlock->DiskSize = diskSize;
+ partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT);
+
+ drive->fPacket.fPacketContent = fs_buf;
+ drive->fPacket.fPacketSize = kNeFSSectorSz;
+ drive->fPacket.fLba = kNeFSRootCatalogStartAddress;
+
+ drive->fOutput(&drive->fPacket);
+
+ kcout << "drive kind: " << drive->fDriveKind() << endl;
+
+ kcout << "partition name: " << partBlock->PartitionName << endl;
+ kcout << "start: " << hex_number(partBlock->StartCatalog) << endl;
+ kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl;
+ kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl;
+ kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl;
+ kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl;
+
+ // write the root catalog.
+ this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir);
+
+ return true;
+ }
+
+ kcout << "partition block already exists.\r";
+
+ start += partBlock->DiskSize;
+
+ drive->fPacket.fPacketContent = fs_buf;
+ drive->fPacket.fPacketSize = kNeFSSectorSz;
+ drive->fPacket.fLba = start;
+
+ drive->fInput(&drive->fPacket);
+ }
+
+ return false;
+}
+
+/// @brief Writes the data fork into a specific catalog.
+/// @param catalog the catalog itself
+/// @param data the data.
+/// @return if the catalog w rote the contents successfully.
+bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool is_rsrc_fork, _Input VoidPtr data, _Input SizeT size_of_data, _Input const Char* forkName)
+{
+ if (size_of_data > kNeFSForkDataSz ||
+ size_of_data == 0)
+ return No;
+
+ auto buf = new UInt8[kNeFSForkDataSz];
+ rt_set_memory(buf, 0, kNeFSForkDataSz);
+
+ rt_copy_memory(data, buf, size_of_data);
+
+ auto drive = sMountpointInterface.A();
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ auto startFork = (!is_rsrc_fork) ? catalog->DataFork
+ : catalog->ResourceFork;
+
+ NFS_FORK_STRUCT* fork_data_input = new NFS_FORK_STRUCT();
+ NFS_FORK_STRUCT prevFork{};
+
+ // sanity check of the fork position as the condition to run the loop.
+ while (startFork >= kNeFSCatalogStartAddress)
+ {
+ drive.fPacket.fPacketContent = fork_data_input;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fLba = startFork;
+
+ drive.fInput(&drive.fPacket);
+
+ // check the fork, if it's position is valid.
+ if (fork_data_input->DataOffset <= kNeFSCatalogStartAddress)
+ {
+ ErrLocal() = kErrorDiskIsCorrupted;
+
+ kcout << "Invalid fork offset.\r";
+
+ return false;
+ }
+
+ if (fork_data_input->Flags != kNeFSFlagUnallocated &&
+ fork_data_input->Flags != kNeFSFlagDeleted &&
+ StringBuilder::Equals(fork_data_input->ForkName, forkName) &&
+ StringBuilder::Equals(fork_data_input->CatalogName, catalog->Name) &&
+ fork_data_input->DataSize == size_of_data)
+ {
+ // ===================================================== //
+ // Store the blob now.
+ // ===================================================== //
+
+ fork_data_input->Flags |= kNeFSFlagCreated;
+
+ drive.fPacket.fPacketContent = buf;
+ drive.fPacket.fPacketSize = kNeFSForkDataSz;
+ drive.fPacket.fLba = fork_data_input->DataOffset;
+
+ kcout << "data offset: " << hex_number(fork_data_input->DataOffset) << endl;
+
+ drive.fOutput(&drive.fPacket);
+
+ drive.fPacket.fPacketContent = fork_data_input;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fLba = startFork - sizeof(NFS_FORK_STRUCT);
+
+ drive.fOutput(&drive.fPacket);
+
+ kcout << "wrote fork at offset: " << hex_number(fork_data_input->DataOffset) << endl;
+ kcout << "wrote fork at offset: " << hex_number(startFork - sizeof(NFS_FORK_STRUCT)) << endl;
+
+ delete catalog;
+
+ return true;
+ }
+
+ // stumble upon a fork, store it.
+
+ prevFork = *fork_data_input;
+
+ startFork = fork_data_input->NextSibling;
+ }
+
+ return false;
+}
+
+/// @brief
+/// @param catalogName the catalog name.
+/// @return the newly found catalog.
+_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName,
+ Lba& out_lba)
+{
+ kcout << "Start finding catalog...\r";
+
+ NFS_ROOT_PARTITION_BLOCK fs_buf{0};
+ auto drive = sMountpointInterface.A();
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ drive.fPacket.fPacketContent = &fs_buf;
+ drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
+ drive.fPacket.fLba = kNeFSRootCatalogStartAddress;
+
+ drive.fInput(&drive.fPacket);
+
+ NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf;
+
+ auto startCatalogList = part->StartCatalog;
+ const auto cCtartCatalogList = startCatalogList;
+
+ auto localSearchFirst = false;
+
+ NFS_CATALOG_STRUCT catalogBuf{0};
+
+ drive.fPacket.fLba = startCatalogList;
+ drive.fPacket.fPacketContent = &catalogBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+
+ drive.fInput(&drive.fPacket);
+
+ if (!StringBuilder::Equals(catalogName, NeFileSystemHelper::Root()))
+ {
+ Char parentName[kNeFSNodeNameLen] = {0};
+
+ for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill)
+ {
+ parentName[indexFill] = catalogName[indexFill];
+ }
+
+ SizeT indexReverseCopy = rt_string_len(parentName);
+
+ // zero character.
+ parentName[--indexReverseCopy] = 0;
+
+ // mandatory '/' character.
+ parentName[--indexReverseCopy] = 0;
+
+ while (parentName[indexReverseCopy] != NeFileSystemHelper::Separator())
+ {
+ parentName[indexReverseCopy] = 0;
+ --indexReverseCopy;
+ }
+
+ NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba);
+
+ if (parentCatalog &&
+ !StringBuilder::Equals(parentName, NeFileSystemHelper::Root()))
+ {
+ startCatalogList = parentCatalog->NextSibling;
+ delete parentCatalog;
+
+ localSearchFirst = true;
+ }
+ else if (parentCatalog)
+ {
+ delete parentCatalog;
+ }
+ else
+ {
+ return nullptr;
+ }
+ }
+
+ kcout << "Fetching catalog...\r";
+
+NeFSSearchThroughCatalogList:
+ while (drive.fPacket.fPacketGood)
+ {
+ drive.fPacket.fLba = startCatalogList;
+ drive.fPacket.fPacketContent = &catalogBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+
+ drive.fInput(&drive.fPacket);
+
+ NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf;
+
+ if (StringBuilder::Equals(catalogName, catalog->Name))
+ {
+ /// ignore unallocated catalog, break
+ if (!(catalog->Flags & kNeFSFlagCreated))
+ {
+ goto NeFSContinueSearch;
+ }
+
+ NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT();
+ rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT));
+
+ kcout << "Found catalog at: " << hex_number(startCatalogList) << endl;
+ kcout << "Found catalog at: " << catalog->Name << endl;
+
+ out_lba = startCatalogList;
+ return catalogPtr;
+ }
+
+ NeFSContinueSearch:
+ startCatalogList = catalog->NextSibling;
+
+ if (startCatalogList <= kNeFSRootCatalogStartAddress)
+ break;
+ }
+
+ if (localSearchFirst)
+ {
+ localSearchFirst = false;
+ startCatalogList = cCtartCatalogList;
+
+ goto NeFSSearchThroughCatalogList;
+ }
+
+ out_lba = 0UL;
+ return nullptr;
+}
+
+/// @brief Get catalog from filesystem.
+/// @param name the catalog's name/
+/// @return
+_Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name)
+{
+ Lba unused = 0;
+ return this->FindCatalog(name, unused);
+}
+
+/// @brief Closes a catalog, (frees it).
+/// @param catalog the catalog to close.
+/// @return
+Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog)
+{
+ if (!catalog)
+ return false;
+
+ delete catalog;
+ catalog = nullptr;
+
+ return true;
+}
+
+/// @brief Mark catalog as removed.
+/// @param catalog The catalog structure.
+/// @return if the catalog was removed or not.
+Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName)
+{
+ if (!catalogName ||
+ StringBuilder::Equals(catalogName, NeFileSystemHelper::Root()))
+ {
+ ErrLocal() = kErrorInternal;
+ return false;
+ }
+
+ Lba out_lba = 0;
+ auto catalog = this->FindCatalog(catalogName, out_lba);
+
+ if (out_lba >= kNeFSCatalogStartAddress ||
+ catalog->Flags & kNeFSFlagCreated)
+ {
+ catalog->Flags |= kNeFSFlagDeleted;
+
+ auto drive = sMountpointInterface.A();
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ drive.fPacket.fLba = out_lba; // the catalog position.
+ drive.fPacket.fPacketSize =
+ sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size.
+ drive.fPacket.fPacketContent = catalog; // the catalog itself.
+
+ drive.fOutput(&drive.fPacket); // send packet.
+
+ Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0};
+
+ drive.fPacket.fLba = kNeFSRootCatalogStartAddress;
+ drive.fPacket.fPacketContent = partitionBlockBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
+
+ drive.fInput(&drive.fPacket);
+
+ NFS_ROOT_PARTITION_BLOCK* partBlock =
+ reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf);
+
+ --partBlock->CatalogCount;
+ ++partBlock->FreeSectors;
+
+ drive.fOutput(&drive.fPacket);
+
+ return true;
+ }
+
+ delete catalog;
+ return false;
+}
+
+/// ***************************************************************** ///
+/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead.
+/// ***************************************************************** ///
+
+/***********************************************************************************/
+/// @brief Read the catalog data fork.
+/// @param catalog
+/// @param dataSz
+/// @return
+/***********************************************************************************/
+
+VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
+ _Input Bool is_rsrc_fork,
+ _Input SizeT dataSz,
+ _Input const Char* forkName)
+{
+ if (!catalog)
+ {
+ ErrLocal() = kErrorFileNotFound;
+ return nullptr;
+ }
+
+ constexpr auto cNeFSCatalogPadding = 4;
+
+ Lba dataForkLba = (!is_rsrc_fork) ? catalog->DataFork : catalog->ResourceFork;
+ Size dataForkSize = (!is_rsrc_fork) ? catalog->DataForkSize : catalog->ResourceForkSize;
+
+ kcout << "catalog " << catalog->Name
+ << ", fork: " << hex_number(dataForkLba) << endl;
+
+ NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT();
+ auto drive = sMountpointInterface.A();
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ NFS_FORK_STRUCT* fs_fork_data = nullptr;
+
+ while (dataForkLba > kNeFSCatalogStartAddress)
+ {
+ drive.fPacket.fLba = dataForkLba;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fPacketContent = fs_buf;
+
+ drive.fInput(&drive.fPacket);
+
+ fs_fork_data = fs_buf;
+
+ kcout << "ForkName: " << fs_fork_data->ForkName << endl;
+ kcout << "CatalogName: " << fs_fork_data->CatalogName << endl;
+
+ if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) &&
+ StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName))
+ break;
+
+ dataForkLba = fs_fork_data->NextSibling;
+ }
+
+ if (dataForkLba < kNeFSCatalogStartAddress)
+ {
+ delete fs_buf;
+ return nullptr;
+ }
+
+ return fs_fork_data;
+}
+
+/***********************************************************************************/
+/// @brief Seek in the data fork.
+/// @param catalog the catalog offset.
+/// @param off where to seek.
+/// @return if the seeking was successful.
+/***********************************************************************************/
+
+bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off)
+{
+ if (!catalog)
+ {
+ ErrLocal() = kErrorFileNotFound;
+ return false;
+ }
+
+ ErrLocal() = kErrorUnimplemented;
+ return false;
+}
+
+/***********************************************************************************/
+/// @brief Tell where we are inside the data fork.
+/// @param catalog
+/// @return The position on the file.
+/***********************************************************************************/
+
+SizeT NeFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog)
+{
+ if (!catalog)
+ {
+ ErrLocal() = kErrorFileNotFound;
+ return 0;
+ }
+
+ ErrLocal() = kErrorUnimplemented;
+ return 0;
+}
+
+namespace Kernel::Detail
+{
+ /***********************************************************************************/
+ /// @brief Construct NeFS drives.
+ /***********************************************************************************/
+ Boolean fs_init_newfs(Void) noexcept
+ {
+ kcout << "Creating drives...\r";
+
+ sMountpointInterface.A() = io_construct_main_drive();
+ sMountpointInterface.B() = io_construct_drive();
+ sMountpointInterface.C() = io_construct_drive();
+ sMountpointInterface.D() = io_construct_drive();
+
+ kcout << "Constructing A:\r";
+
+ sMountpointInterface.A().fInit(&sMountpointInterface.A().fPacket);
+
+ kcout << "Constructing A: [ OK ]\r";
+
+ return true;
+ }
+} // namespace Kernel::Detail
+
+#endif // ifdef __FSKIT_USE_NEFS__
diff --git a/dev/zka/src/FileMgr.cxx b/dev/zka/src/FileMgr.cxx
new file mode 100644
index 00000000..a7be26b8
--- /dev/null
+++ b/dev/zka/src/FileMgr.cxx
@@ -0,0 +1,190 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/FileMgr.hxx>
+#include <NewKit/Utils.hxx>
+
+/// BUGS: 0
+//! @brief File manager for Kernel.
+
+namespace Kernel
+{
+ STATIC IFilesystemMgr* kMounted = nullptr;
+
+ /// @brief FilesystemMgr getter.
+ /// @return The mounted filesystem.
+ _Output IFilesystemMgr* IFilesystemMgr::GetMounted()
+ {
+ return kMounted;
+ }
+
+ /// @brief Unmount filesystem.
+ /// @return The unmounted filesystem.
+ _Output IFilesystemMgr* IFilesystemMgr::Unmount()
+ {
+ if (kMounted)
+ {
+ auto mount = kMounted;
+ kMounted = nullptr;
+
+ return mount;
+ }
+
+ return nullptr;
+ }
+
+ /// @brief Mount filesystem.
+ /// @param mount_ptr The filesystem to mount.
+ /// @return if it succeeded true, otherwise false.
+ bool IFilesystemMgr::Mount(_Input IFilesystemMgr* mount_ptr)
+ {
+ if (mount_ptr != nullptr)
+ {
+ kMounted = mount_ptr;
+ return true;
+ }
+
+ return false;
+ }
+
+#ifdef __FSKIT_USE_NEFS__
+ /// @brief Opens a new file.
+ /// @param path
+ /// @param r
+ /// @return
+ _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r)
+ {
+ if (!path || *path == 0)
+ return nullptr;
+
+ if (!r || *r == 0)
+ return nullptr;
+
+ auto catalog = fImpl->GetCatalog(path);
+
+ return node_cast(catalog);
+ }
+
+ /// @brief Writes to a catalog's fork.
+ /// @param node the node ptr.
+ /// @param data the data.
+ /// @param flags the size.
+ /// @return
+ Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size)
+ {
+ if (!node)
+ return;
+ if (!size)
+ return;
+
+ constexpr auto cDataForkName = kNeFSDataFork;
+ this->Write(cDataForkName, node, data, flags, size);
+ }
+
+ /// @brief Read from filesystem fork.
+ /// @param node the catalog node.
+ /// @param flags the flags with it.
+ /// @param sz the size to read.
+ /// @return
+ _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size)
+ {
+ if (!node)
+ return nullptr;
+ if (!size)
+ return nullptr;
+
+ constexpr auto cDataForkName = kNeFSDataFork;
+ return this->Read(cDataForkName, node, flags, size);
+ }
+
+ Void NeFileSystemMgr::Write(_Input const Char* name,
+ _Input NodePtr node,
+ _Input VoidPtr data,
+ _Input Int32 flags,
+ _Input SizeT size)
+ {
+ if (!size ||
+ size > kNeFSForkSize)
+ return;
+
+ if (!data)
+ return;
+
+ ZKA_UNUSED(flags);
+
+ if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile)
+ fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), data, size,
+ name);
+ }
+
+ _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name,
+ _Input NodePtr node,
+ _Input Int32 flags,
+ _Input SizeT sz)
+ {
+ if (sz > kNeFSForkSize)
+ return nullptr;
+
+ if (!sz)
+ return nullptr;
+
+ ZKA_UNUSED(flags);
+
+ if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile)
+ return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), sz,
+ name);
+
+ return nullptr;
+ }
+
+ /// @brief Seek from Catalog.
+ /// @param node
+ /// @param off
+ /// @retval true always returns false, this is unimplemented.
+ /// @retval false always returns this, it is unimplemented.
+
+ _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off)
+ {
+ if (!node || off == 0)
+ return false;
+
+ return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off);
+ }
+
+ /// @brief Tell where the catalog is.
+ /// @param node
+ /// @retval true always returns false, this is unimplemented.
+ /// @retval false always returns this, it is unimplemented.
+
+ _Output SizeT NeFileSystemMgr::Tell(NodePtr node)
+ {
+ if (!node)
+ return kNPos;
+
+ return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node));
+ }
+
+ /// @brief Rewinds the catalog.
+ /// @param node
+ /// @retval true always returns false, this is unimplemented.
+ /// @retval false always returns this, it is unimplemented.
+
+ _Output Bool NeFileSystemMgr::Rewind(NodePtr node)
+ {
+ if (!node)
+ return false;
+
+ return this->Seek(node, 0);
+ }
+
+ /// @brief Returns the filesystem parser.
+ /// @return the Filesystem parser class.
+ _Output NeFSParser* NeFileSystemMgr::GetParser() noexcept
+ {
+ return fImpl;
+ }
+#endif // __FSKIT_USE_NEFS__
+} // namespace Kernel
diff --git a/dev/zka/src/Framebuffer.cxx b/dev/zka/src/Framebuffer.cxx
new file mode 100644
index 00000000..3794e458
--- /dev/null
+++ b/dev/zka/src/Framebuffer.cxx
@@ -0,0 +1,113 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Framebuffer.cxx
+ Purpose: Framebuffer object
+
+ Revision History:
+
+ 01/02/24: Added file (amlel)
+ 02/02/24: Add documentation (amlel)
+ 07/07/07: Moved Framebuffer methods into Kernel::
+
+------------------------------------------- */
+
+#include <KernelKit/Framebuffer.hxx>
+#include <HintKit/CompilerHint.hxx>
+
+/**
+ * @brief Framebuffer object implementation.
+ *
+ */
+
+namespace Kernel
+{
+ Framebuffer::Framebuffer(_Input Ref<FramebufferContext*>& addr)
+ : fFrameBufferAddr(addr)
+ {
+ }
+
+ /**
+ * @brief Get Pixel at **pos**
+ *
+ * @param pos position of pixel.
+ * @return volatile*
+ */
+ _Output volatile UIntPtr* Framebuffer::operator[](_Input const UIntPtr& pos)
+ {
+ return (UIntPtr*)(fFrameBufferAddr->fBase * pos);
+ }
+
+ /// @brief Boolean operator.
+ Framebuffer::operator bool()
+ {
+ return fFrameBufferAddr.Leak()->fBase != 0 &&
+ fColour != FramebufferColorKind::INVALID &&
+ fFrameBufferAddr.Leak()->fBase != kInvalidAddress;
+ }
+
+ /// @brief Set color kind of framebuffer.
+ /// @param colour
+ /// @return
+ _Output const FramebufferColorKind& Framebuffer::Color(
+ const FramebufferColorKind& colour)
+ {
+ if (fColour != FramebufferColorKind::INVALID &&
+ colour != FramebufferColorKind::INVALID)
+ {
+ fColour = colour;
+ }
+
+ return fColour;
+ }
+
+ /// @brief Leak framebuffer context.
+ /// @return The reference of the framebuffer context.
+ _Output Ref<FramebufferContext*>& Framebuffer::Leak()
+ {
+ return this->fFrameBufferAddr;
+ }
+
+ /// @brief Draws a rectangle.
+ /// @param width
+ /// @param height
+ /// @param x
+ /// @param y
+ /// @param color
+ /// @return
+ _Output Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color)
+ {
+ for (Kernel::SizeT i = x; i < width + x; ++i)
+ {
+ for (Kernel::SizeT u = y; u < height + y; ++u)
+ {
+ *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase +
+ 4 * fFrameBufferAddr.Leak()->fBpp * i +
+ 4 * u))) = color;
+ }
+ }
+
+ return *this;
+ }
+
+ /// @brief Put a pixel on the screen.
+ /// @param x
+ /// @param y
+ /// @param color
+ /// @return
+ _Output Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color)
+ {
+ *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase +
+ 4 * fFrameBufferAddr.Leak()->fBpp * x +
+ 4 * y))) = color;
+
+ return *this;
+ }
+
+ const UInt32 kRgbRed = 0x000000FF;
+ const UInt32 kRgbGreen = 0x0000FF00;
+ const UInt32 kRgbBlue = 0x00FF0000;
+ const UInt32 kRgbBlack = 0x00000000;
+ const UInt32 kRgbWhite = 0xFFFFFFFF;
+} // namespace Kernel
diff --git a/dev/zka/src/GUIDWizard.cxx b/dev/zka/src/GUIDWizard.cxx
new file mode 100644
index 00000000..aede3a19
--- /dev/null
+++ b/dev/zka/src/GUIDWizard.cxx
@@ -0,0 +1,72 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: GUIDWizard.cxx
+ Purpose: GUID helper code
+
+ Revision History:
+
+------------------------------------------- */
+
+#include <CFKit/GUIDWizard.hxx>
+#include <NewKit/Ref.hxx>
+
+// begin of ascii 'readable' characters. (A, C, C, 1, 2)
+#define kAsciiBegin 47
+// @brief Size of UUID.
+#define kUUIDSize 37
+
+namespace Kernel::XRN::Version1
+{
+ auto cf_make_sequence(const ArrayList<UInt32>& uuidSeq) -> Ref<GUIDSequence*>
+ {
+ GUIDSequence* seq = new GUIDSequence();
+ MUST_PASS(seq);
+
+ Ref<GUIDSequence*> sequenceReference{seq, true};
+
+ sequenceReference->fMs1 = uuidSeq[0];
+ sequenceReference->fMs2 = uuidSeq[1];
+ sequenceReference->fMs3 = uuidSeq[2];
+ sequenceReference->fMs4[0] = uuidSeq[3];
+ sequenceReference->fMs4[1] = uuidSeq[4];
+ sequenceReference->fMs4[2] = uuidSeq[5];
+ sequenceReference->fMs4[3] = uuidSeq[6];
+ sequenceReference->fMs4[4] = uuidSeq[7];
+ sequenceReference->fMs4[5] = uuidSeq[8];
+ sequenceReference->fMs4[6] = uuidSeq[9];
+ sequenceReference->fMs4[7] = uuidSeq[10];
+
+ return sequenceReference;
+ }
+
+ // @brief Tries to make a guid out of a string.
+ // This function is not complete for now
+ auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>>
+ {
+ Char buf[kUUIDSize];
+
+ for (SizeT index = 0; index < 16; ++index)
+ {
+ buf[index] = seq->u8[index] + kAsciiBegin;
+ }
+
+ for (SizeT index = 16; index < 24; ++index)
+ {
+ buf[index] = seq->u16[index] + kAsciiBegin;
+ }
+
+ for (SizeT index = 24; index < 28; ++index)
+ {
+ buf[index] = seq->u32[index] + kAsciiBegin;
+ }
+
+ auto view = StringBuilder::Construct(buf);
+
+ if (view)
+ return ErrorOr<Ref<StringView>>{view.Leak()};
+
+ return ErrorOr<Ref<StringView>>{-1};
+ }
+} // namespace Kernel::XRN::Version1
diff --git a/dev/zka/src/GUIDWrapper.cxx b/dev/zka/src/GUIDWrapper.cxx
new file mode 100644
index 00000000..f87d792d
--- /dev/null
+++ b/dev/zka/src/GUIDWrapper.cxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <CFKit/GUIDWrapper.hxx>
+
+namespace Kernel::XRN
+{
+}
diff --git a/dev/zka/src/HardwareThreadScheduler.cxx b/dev/zka/src/HardwareThreadScheduler.cxx
new file mode 100644
index 00000000..22a69b9b
--- /dev/null
+++ b/dev/zka/src/HardwareThreadScheduler.cxx
@@ -0,0 +1,195 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/HardwareThreadScheduler.hxx>
+#include <CFKit/Property.hxx>
+
+///! BUGS: 0
+
+///! @file MP.cxx
+///! @brief This file handles multi processing in the Kernel.
+///! @brief Multi processing is needed for multi-tasking operations.
+
+namespace Kernel
+{
+ HardwareThreadScheduler* cHardwareThreadScheduler = nullptr;
+
+ ///! A HardwareThread class takes care of it's owned hardware thread.
+ ///! It has a stack for it's core.
+
+ ///! @brief C++ constructor.
+ HardwareThread::HardwareThread() = default;
+
+ ///! @brief C++ destructor.
+ HardwareThread::~HardwareThread() = default;
+
+ //! @brief returns the id of the thread.
+ const ThreadID& HardwareThread::ID() noexcept
+ {
+ return fID;
+ }
+
+ //! @brief returns the kind of thread we have.
+ const ThreadKind& HardwareThread::Kind() noexcept
+ {
+ return fKind;
+ }
+
+ //! @brief is the thread busy?
+ Bool HardwareThread::IsBusy() noexcept
+ {
+ STATIC Int64 busy_timer = 0U;
+
+ if (busy_timer > this->fPTime)
+ {
+ busy_timer = 0U;
+ fBusy = No;
+ }
+
+ return fBusy;
+ }
+
+ /// @brief Get processor stack frame.
+
+ HAL::StackFramePtr HardwareThread::StackFrame() noexcept
+ {
+ MUST_PASS(fStack);
+ return fStack;
+ }
+
+ Void HardwareThread::Busy(const Bool busy) noexcept
+ {
+ fBusy = busy;
+ }
+
+ HardwareThread::operator bool()
+ {
+ return fStack;
+ }
+
+ /// @brief Wakeup the processor.
+
+ Void HardwareThread::Wake(const bool wakeup) noexcept
+ {
+ fWakeup = wakeup;
+
+ if (!fWakeup)
+ mp_hang_thread(fStack);
+ else
+ mp_wakeup_thread(fStack);
+ }
+
+ /// @note Those symbols are needed in order to switch and validate the stack.
+
+ EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr);
+ EXTERN_C Bool mp_register_process(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr);
+
+ /// @brief Switch to hardware thread.
+ /// @param stack the new hardware thread.
+ /// @retval true stack was changed, code is running.
+ /// @retval false stack is invalid, previous code is running.
+ Bool HardwareThread::Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame)
+ {
+ if (!frame ||
+ !image ||
+ !stack_ptr)
+ return No;
+
+ if (!this->IsWakeup())
+ return No;
+
+ if (this->IsBusy())
+ return No;
+
+ fStack = frame;
+
+ kcout << "Trying to register progress...\r";
+
+ Bool ret = mp_register_process(image, stack_ptr, fStack);
+
+ if (ret)
+ this->Busy(true);
+
+ return ret;
+ }
+
+ ///! @brief Tells if processor is waked up.
+ bool HardwareThread::IsWakeup() noexcept
+ {
+ return fWakeup;
+ }
+
+ ///! @brief Constructor and destructors.
+
+ ///! @brief Default constructor.
+ HardwareThreadScheduler::HardwareThreadScheduler() = default;
+
+ ///! @brief Default destructor.
+ HardwareThreadScheduler::~HardwareThreadScheduler() = default;
+
+ /// @brief Shared singleton function
+ HardwareThreadScheduler& HardwareThreadScheduler::The()
+ {
+ MUST_PASS(cHardwareThreadScheduler);
+ return *cHardwareThreadScheduler;
+ }
+
+ /// @brief Get Stack Frame of Core
+ HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept
+ {
+ return fThreadList[fCurrentThread].fStack;
+ }
+
+ /**
+ * Get Hardware thread at index.
+ * @param idx the index
+ * @return the reference to the hardware thread.
+ */
+ Ref<HardwareThread*> HardwareThreadScheduler::operator[](const SizeT& idx)
+ {
+ if (idx == 0)
+ {
+ if (fThreadList[idx].Kind() != kHartSystemReserved)
+ {
+ fThreadList[idx].fKind = kHartBoot;
+ }
+ }
+ else if (idx >= cMaxHWThreads)
+ {
+ static HardwareThread* fakeThread = nullptr;
+ return {fakeThread};
+ }
+
+ return &fThreadList[idx];
+ }
+
+ /**
+ * Check if thread pool isn't empty.
+ * @return
+ */
+ HardwareThreadScheduler::operator bool() noexcept
+ {
+ return !fThreadList.Empty();
+ }
+
+ /**
+ * Reverse operator bool
+ * @return
+ */
+ bool HardwareThreadScheduler::operator!() noexcept
+ {
+ return fThreadList.Empty();
+ }
+
+ /// @brief Returns the amount of core present.
+ /// @return the number of cores.
+ SizeT HardwareThreadScheduler::Count() noexcept
+ {
+ return fThreadList.Capacity();
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Heap.cxx b/dev/zka/src/Heap.cxx
new file mode 100644
index 00000000..a75eaeb1
--- /dev/null
+++ b/dev/zka/src/Heap.cxx
@@ -0,0 +1,268 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/LPC.hxx>
+#include <KernelKit/Heap.hxx>
+#include <NewKit/Crc32.hxx>
+#include <NewKit/PageMgr.hxx>
+#include <NewKit/Utils.hxx>
+
+//! @file KernelHeap.cxx
+//! @brief Kernel heap allocator.
+
+#define kKernelHeapMagic (0xD4D7D5)
+#define kKernelHeapHeaderPaddingSz (__BIGGEST_ALIGNMENT__)
+
+namespace Kernel
+{
+
+ /// @brief Contains data structures and algorithms for the heap.
+ namespace Detail
+ {
+ struct PACKED HEAP_INFORMATION_BLOCK;
+
+ /// @brief Kernel heap information block.
+ /// Located before the address bytes.
+ /// | HIB | ADDRESS |
+ struct PACKED HEAP_INFORMATION_BLOCK final
+ {
+ ///! @brief 32-bit value which contains the magic number of the heap.
+ UInt32 fMagic;
+ ///! @brief Boolean value which tells if the heap is allocated.
+ Boolean fPresent;
+ /// @brief Is this valued owned by the user?
+ Boolean fUser;
+ /// @brief Is this a page pointer?
+ Boolean fPage;
+ ///! @brief 32-bit CRC checksum.
+ UInt32 fCRC32;
+ /// @brief 64-bit pointer size.
+ SizeT fHeapSize;
+ /// @brief 64-bit target pointer.
+ UIntPtr fHeapPtr;
+ /// @brief Padding bytes for header.
+ UInt8 fPadding[kKernelHeapHeaderPaddingSz];
+ };
+
+ /// @brief Check for heap address validity.
+ /// @param heap_ptr The address_ptr
+ /// @return Bool if the pointer is valid or not.
+ auto mm_check_heap_address(VoidPtr heap_ptr) -> Bool
+ {
+ if (!heap_ptr)
+ return false;
+
+ /// Add that check in case we're having an integer underflow. ///
+
+ auto base_heap = (IntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK);
+
+ if (base_heap < 0)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ typedef HEAP_INFORMATION_BLOCK* HEAP_INFORMATION_BLOCK_PTR;
+
+ Void mm_alloc_init_timeout(Void) noexcept
+ {
+ ZKA_UNUSED(0);
+ }
+
+ Void mm_alloc_fini_timeout(Void) noexcept
+ {
+ ZKA_UNUSED(0);
+ }
+ } // namespace Detail
+
+ Detail::HEAP_INFORMATION_BLOCK_PTR kLatestAllocation = nullptr;
+
+ /// @brief Declare a new size for ptr_heap.
+ /// @param ptr_heap the pointer.
+ /// @return Newly allocated heap header.
+ voidPtr mm_realloc_heap(voidPtr ptr_heap, SizeT new_sz)
+ {
+ if (Detail::mm_check_heap_address(ptr_heap) == No)
+ return nullptr;
+
+ if (!ptr_heap || new_sz < 1)
+ return nullptr;
+
+ kcout << "This function is not implemented in the kernel, please refrain from using that.\r";
+ ke_stop(RUNTIME_CHECK_PROCESS);
+
+ return nullptr;
+ }
+
+ /// @brief Allocate chunk of memory.
+ /// @param sz Size of pointer
+ /// @param rw Read Write bit.
+ /// @param user User enable bit.
+ /// @return The newly allocated pointer.
+ VoidPtr mm_new_heap(const SizeT sz, const bool rw, const bool user)
+ {
+ Detail::mm_alloc_init_timeout();
+
+ auto sz_fix = sz;
+
+ if (sz_fix == 0)
+ return nullptr;
+
+ sz_fix += sizeof(Detail::HEAP_INFORMATION_BLOCK);
+
+ PageMgr heap_mgr;
+ auto wrapper = heap_mgr.Request(rw, user, No, sz_fix);
+
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
+ reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
+ wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK));
+
+ heap_info_ptr->fHeapSize = sz_fix;
+ heap_info_ptr->fMagic = kKernelHeapMagic;
+ heap_info_ptr->fCRC32 = No; // dont fill it for now.
+ heap_info_ptr->fHeapPtr = reinterpret_cast<UIntPtr>(heap_info_ptr) + sizeof(Detail::HEAP_INFORMATION_BLOCK);
+ heap_info_ptr->fPage = No;
+ heap_info_ptr->fUser = user;
+ heap_info_ptr->fPresent = Yes;
+
+ rt_set_memory(heap_info_ptr->fPadding, 0, kKernelHeapHeaderPaddingSz);
+
+ auto result = reinterpret_cast<VoidPtr>(heap_info_ptr->fHeapPtr);
+
+ kLatestAllocation = heap_info_ptr;
+
+ Detail::mm_alloc_fini_timeout();
+
+ return result;
+ }
+
+ /// @brief Makes a page heap.
+ /// @param heap_ptr
+ /// @return
+ Int32 mm_make_ke_page(VoidPtr heap_ptr)
+ {
+ if (Detail::mm_check_heap_address(heap_ptr) == No)
+ return -kErrorHeapNotPresent;
+
+ Detail::mm_alloc_init_timeout();
+
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
+ (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+
+ if (!heap_ptr)
+ return -kErrorHeapNotPresent;
+
+ heap_blk->fPage = true;
+
+ Detail::mm_alloc_fini_timeout();
+
+ return kErrorSuccess;
+ }
+
+ /// @brief Declare pointer as free.
+ /// @param heap_ptr the pointer.
+ /// @return
+ Int32 mm_delete_heap(VoidPtr heap_ptr)
+ {
+ if (Detail::mm_check_heap_address(heap_ptr) == No)
+ return -kErrorHeapNotPresent;
+
+ Detail::mm_alloc_init_timeout();
+
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
+ (UIntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+
+ if (heap_blk && heap_blk->fMagic == kKernelHeapMagic)
+ {
+ if (!heap_blk->fPresent)
+ {
+ Detail::mm_alloc_fini_timeout();
+ return -kErrorHeapNotPresent;
+ }
+
+ if (heap_blk->fCRC32 != 0)
+ {
+ if (heap_blk->fCRC32 !=
+ ke_calculate_crc32((Char*)heap_blk->fHeapPtr,
+ heap_blk->fHeapSize))
+ {
+ if (!heap_blk->fUser)
+ {
+ ke_stop(RUNTIME_CHECK_POINTER);
+ }
+ }
+ }
+
+ heap_blk->fHeapSize = 0UL;
+ heap_blk->fPresent = No;
+ heap_blk->fHeapPtr = 0;
+ heap_blk->fCRC32 = 0;
+ heap_blk->fMagic = 0;
+
+ PTEWrapper pageWrapper(false, false, false, reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ Ref<PTEWrapper> pteAddress{pageWrapper};
+
+ kcout << "Freeing pointer address: " << hex_number(reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)) << endl;
+
+ PageMgr heap_mgr;
+ heap_mgr.Free(pteAddress);
+
+ Detail::mm_alloc_fini_timeout();
+
+ return kErrorSuccess;
+ }
+
+ return -kErrorInternal;
+ }
+
+ /// @brief Check if pointer is a valid Kernel pointer.
+ /// @param heap_ptr the pointer
+ /// @return if it exists.
+ Boolean mm_is_valid_heap(VoidPtr heap_ptr)
+ {
+ if (heap_ptr)
+ {
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
+ (UIntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+
+ if (heap_blk && heap_blk->fPresent && heap_blk->fMagic == kKernelHeapMagic)
+ {
+ return Yes;
+ }
+ }
+
+ return No;
+ }
+
+ /// @brief Protect the heap with a CRC value.
+ /// @param heap_ptr HIB pointer.
+ /// @return if it valid: point has crc now., otherwise fail.
+ Boolean mm_protect_heap(VoidPtr heap_ptr)
+ {
+ if (heap_ptr)
+ {
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
+ (UIntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+
+ if (heap_ptr && heap_blk->fPresent && kKernelHeapMagic == heap_blk->fMagic)
+ {
+ heap_blk->fCRC32 =
+ ke_calculate_crc32((Char*)heap_blk->fHeapPtr, heap_blk->fHeapSize);
+
+ return Yes;
+ }
+ }
+
+ return No;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/IDLLObject.cxx b/dev/zka/src/IDLLObject.cxx
new file mode 100644
index 00000000..b6b6a348
--- /dev/null
+++ b/dev/zka/src/IDLLObject.cxx
@@ -0,0 +1,15 @@
+/*
+ * ========================================================
+ *
+ * newoskrnl
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <KernelKit/IDLLObject.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+#include <KernelKit/UserProcessScheduler.hxx>
+
+using namespace Kernel;
diff --git a/dev/zka/src/IPEFDLLObject.cxx b/dev/zka/src/IPEFDLLObject.cxx
new file mode 100644
index 00000000..a8505eb3
--- /dev/null
+++ b/dev/zka/src/IPEFDLLObject.cxx
@@ -0,0 +1,100 @@
+/*
+ * ========================================================
+ *
+ * newoskrnl
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/PEF.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/ThreadLocalStorage.hxx>
+#include <NewKit/Defines.hxx>
+
+/* -------------------------------------------
+
+ Revision History:
+
+ 01/02/24: Rework shared sharedObj ABI, except a rtl_init_dll and
+ rtl_fini_dll (amlel) 15/02/24: Breaking changes, changed the name of the
+ routines. (amlel)
+
+ 07/28/24: Replace rt_library_free with rtl_fini_dll
+
+ ------------------------------------------- */
+
+using namespace Kernel;
+
+/***********************************************************************************/
+/// @file PEFSharedObjectRT.cxx
+/// @brief PEF's shared object runtime.
+/***********************************************************************************/
+
+/***********************************************************************************/
+/** @brief Library initializer. */
+/***********************************************************************************/
+
+EXTERN_C IDLL rtl_init_dll(UserProcess* header)
+{
+ IDLL sharedObj = tls_new_class<IPEFDLLObject>();
+
+ if (!sharedObj)
+ {
+ header->Crash();
+
+ return nullptr;
+ }
+
+ sharedObj->Mount(tls_new_class<IPEFDLLObject::DLL_TRAITS>());
+
+ if (!sharedObj->Get())
+ {
+ header->Crash();
+
+ return nullptr;
+ }
+
+ sharedObj->Get()->fImageObject =
+ header->Image;
+
+ if (!sharedObj->Get()->fImageObject)
+ {
+ header->Crash();
+
+ return nullptr;
+ }
+
+ sharedObj->Get()->fImageEntrypointOffset =
+ sharedObj->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode);
+
+ return sharedObj;
+}
+
+/***********************************************************************************/
+/** @brief Frees the sharedObj. */
+/** @note Please check if the lib got freed! */
+/** @param lib The sharedObj to free. */
+/** @param successful Reports if successful or not. */
+/***********************************************************************************/
+
+EXTERN_C Void rtl_fini_dll(UserProcess* header, IDLL lib, Bool* successful)
+{
+ MUST_PASS(successful);
+
+ // sanity check (will also trigger a bug check if this fails)
+ if (lib == nullptr)
+ {
+ *successful = false;
+ header->Crash();
+ }
+
+ delete lib->Get();
+ delete lib;
+
+ lib = nullptr;
+
+ *successful = true;
+}
diff --git a/dev/zka/src/IndexableProperty.cxx b/dev/zka/src/IndexableProperty.cxx
new file mode 100644
index 00000000..a5f1bc0b
--- /dev/null
+++ b/dev/zka/src/IndexableProperty.cxx
@@ -0,0 +1,59 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+//! @brief Filesystem Indexer.
+
+#include <CompilerKit/CompilerKit.hxx>
+#include <FSKit/IndexableProperty.hxx>
+#include <NewKit/MutableArray.hxx>
+#include <NewKit/Utils.hxx>
+
+/// @brief File Indexer.
+/// BUGS: 0
+
+#define kMaxLenIndexer 256
+
+namespace Kernel
+{
+ namespace Indexer
+ {
+ IndexProperty& IndexableProperty::Leak() noexcept
+ {
+ return fIndex;
+ }
+
+ Void IndexableProperty::AddFlag(Int16 flag)
+ {
+ fFlags |= flag;
+ }
+
+ Void IndexableProperty::RemoveFlag(Int16 flag)
+ {
+ fFlags &= flag;
+ }
+
+ Int16 IndexableProperty::HasFlag(Int16 flag)
+ {
+ return fFlags & flag;
+ }
+
+ /// @brief Index a file into the indexer instance.
+ /// @param filename path
+ /// @param filenameLen used bytes in path.
+ /// @param indexer the filesystem indexer.
+ /// @return none.
+ Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& indexer)
+ {
+ if (!indexer.HasFlag(kIndexerClaimed))
+ {
+ indexer.AddFlag(kIndexerClaimed);
+ rt_copy_memory((VoidPtr)indexer.Leak().Path, (VoidPtr)filename, filenameLen);
+
+ kcout << "filesystem: index new file: " << filename << endl;
+ }
+ }
+ } // namespace Indexer
+} // namespace Kernel
diff --git a/dev/zka/src/Json.cxx b/dev/zka/src/Json.cxx
new file mode 100644
index 00000000..df0d0ef8
--- /dev/null
+++ b/dev/zka/src/Json.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Json.hxx>
+
+using namespace Kernel;
+
+/// @brief Undefined object, is null in length.
+cInitObject(Kernel::JsonType::kNull, Kernel::JsonType);
diff --git a/dev/zka/src/KernelCheck.cxx b/dev/zka/src/KernelCheck.cxx
new file mode 100644
index 00000000..4c316c0b
--- /dev/null
+++ b/dev/zka/src/KernelCheck.cxx
@@ -0,0 +1,155 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/Timer.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <NewKit/String.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <KernelKit/FileMgr.hxx>
+#include <Modules/CoreCG/Accessibility.hxx>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+#include <Modules/CoreCG/WindowRenderer.hxx>
+
+#define SetMem(dst, byte, sz) Kernel::rt_set_memory((Kernel::VoidPtr)dst, byte, sz)
+#define CopyMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz)
+#define MoveMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz)
+
+#define cWebsiteMacro "https://help.el-mahrouss-logic.com/"
+
+/* Each error code is attributed with an ID, which will prompt a string onto the
+ * screen. Wait for debugger... */
+
+namespace Kernel
+{
+ void ke_stop(const Kernel::Int& id)
+ {
+ CGInit();
+
+ auto panicTxt = RGB(0xff, 0xff, 0xff);
+
+ CG::CGDrawBackground();
+
+ auto start_y = 10;
+ auto x = 10;
+
+ CGDrawString("newoskrnl.exe Stopped working properly so it had to stop.", start_y, x, panicTxt);
+ start_y += 10;
+
+ // simply offset from previous string and then write the website.
+ CGDrawString("Please visit: ", start_y, x, panicTxt);
+ CGDrawString(cWebsiteMacro, start_y, x + (FONT_SIZE_X * rt_string_len("Please visit: ")), panicTxt);
+
+ CGFini();
+
+ start_y += 10;
+
+ // show text according to error id.
+
+ switch (id)
+ {
+ case RUNTIME_CHECK_PROCESS: {
+ CGDrawString("0x00000008 No more processes to run, this is because that ZKA ran out of processes.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ case RUNTIME_CHECK_ACPI: {
+ CGDrawString("0x00000006 ACPI configuration error.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ case RUNTIME_CHECK_PAGE: {
+ CGDrawString("0x0000000B Write/Read in non paged area.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ }
+ case RUNTIME_CHECK_FILESYSTEM: {
+ CGDrawString("0x0000000A Filesystem error.", start_y, x, panicTxt);
+
+ PowerFactoryInterface power(nullptr);
+ power.Shutdown();
+ break;
+ }
+ case RUNTIME_CHECK_POINTER: {
+ CGDrawString("0x00000000 Heap error, the heap is corrupted.", start_y, x, panicTxt);
+
+ PowerFactoryInterface power(nullptr);
+ power.Shutdown();
+ break;
+ }
+ case RUNTIME_CHECK_BAD_BEHAVIOR: {
+ CGDrawString("0x00000009 CPU access error.", start_y, x, panicTxt);
+
+ PowerFactoryInterface power(nullptr);
+ power.Shutdown();
+ break;
+ }
+ case RUNTIME_CHECK_BOOTSTRAP: {
+ CGDrawString("0x0000000A Boot Processor finished executing.", start_y, x, panicTxt);
+
+ PowerFactoryInterface power(nullptr);
+ power.Shutdown();
+ break;
+ }
+ case RUNTIME_CHECK_HANDSHAKE: {
+ CGDrawString("0x00000005 Handshake fault.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ case RUNTIME_CHECK_IPC: {
+ CGDrawString("0x00000003 Bad IPC/XPCOM message.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ case RUNTIME_CHECK_INVALID_PRIVILEGE: {
+ CGDrawString("0x00000007 Privilege access violation.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ case RUNTIME_CHECK_UNEXCPECTED: {
+ CGDrawString("0x0000000B Kernel access violation.", start_y, x, panicTxt);
+ break;
+ }
+ case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: {
+ CGDrawString("0x10000001 Out of virtual memory.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ case RUNTIME_CHECK_FAILED: {
+ CGDrawString("0x10000001 Kernel Bug check failed.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
+ break;
+ }
+ default: {
+ RecoveryFactory::Recover();
+ CGDrawString("0xFFFFFFFC Unknown Kernel error.", start_y, x, panicTxt);
+ break;
+ }
+ }
+ };
+
+ PowerFactoryInterface power(nullptr);
+ power.Reboot();
+ }
+
+ Void RecoveryFactory::Recover() noexcept
+ {
+ PowerFactoryInterface power(nullptr);
+ power.Reboot();
+ }
+
+ void ke_runtime_check(bool expr, const Char* file, const Char* line)
+ {
+ if (!expr)
+ {
+ kcout << "FAILED: FILE: " << file << endl;
+ kcout << "FAILED: LINE: " << line << endl;
+
+ ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/LPC.cxx b/dev/zka/src/LPC.cxx
new file mode 100644
index 00000000..46f621bb
--- /dev/null
+++ b/dev/zka/src/LPC.cxx
@@ -0,0 +1,34 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/LPC.hxx>
+#include <NewKit/KernelCheck.hxx>
+
+namespace Kernel
+{
+ STATIC Bool cRaise = false;
+
+ /// @brief Does a system wide bug check.
+ /// @param void no params.
+ /// @return if error-free: false, otherwise true.
+ Boolean err_bug_check(void) noexcept
+ {
+ if (cRaise)
+ {
+ ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
+ }
+
+ return false;
+ }
+
+ /// @brief Tells if we should raise a bug check not.
+ /// @param void
+ /// @return void
+ Void err_bug_check_raise(Void) noexcept
+ {
+ cRaise = true;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/LockDelegate.cxx b/dev/zka/src/LockDelegate.cxx
new file mode 100644
index 00000000..f23c46d3
--- /dev/null
+++ b/dev/zka/src/LockDelegate.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/LockDelegate.hxx>
+
+namespace Kernel
+{
+ /// Leave it empty for now.
+} // namespace Kernel \ No newline at end of file
diff --git a/dev/zka/src/MutableArray.cxx b/dev/zka/src/MutableArray.cxx
new file mode 100644
index 00000000..766cb304
--- /dev/null
+++ b/dev/zka/src/MutableArray.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/MutableArray.hxx>
diff --git a/dev/zka/src/NeFS+FileMgr.cxx b/dev/zka/src/NeFS+FileMgr.cxx
new file mode 100644
index 00000000..fa14aaae
--- /dev/null
+++ b/dev/zka/src/NeFS+FileMgr.cxx
@@ -0,0 +1,110 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/FileMgr.hxx>
+#include <KernelKit/Heap.hxx>
+
+#ifdef __FSKIT_USE_NEFS__
+
+/// @brief NeFS File manager.
+/// BUGS: 0
+
+namespace Kernel
+{
+ /// @brief C++ constructor
+ NeFileSystemMgr::NeFileSystemMgr()
+ {
+ MUST_PASS(Detail::fs_init_newfs());
+ fImpl = mm_new_class<NeFSParser>();
+ MUST_PASS(fImpl);
+
+ kcout << "We are done here... (NeFileSystemMgr).\r";
+ }
+
+ NeFileSystemMgr::~NeFileSystemMgr()
+ {
+ if (fImpl)
+ {
+ kcout << "Destroying FS class (NeFS)...\r";
+
+ delete fImpl;
+ fImpl = nullptr;
+ }
+ }
+
+ /// @brief Removes a node from the filesystem.
+ /// @param fileName The filename
+ /// @return If it was deleted or not.
+ bool NeFileSystemMgr::Remove(const Char* fileName)
+ {
+ if (fileName == nullptr || *fileName == 0)
+ return false;
+
+ return fImpl->RemoveCatalog(fileName);
+ }
+
+ /// @brief Creates a node with the specified.
+ /// @param path The filename path.
+ /// @return The Node pointer.
+ NodePtr NeFileSystemMgr::Create(const Char* path)
+ {
+ return node_cast(fImpl->CreateCatalog(path));
+ }
+
+ /// @brief Creates a node with is a directory.
+ /// @param path The filename path.
+ /// @return The Node pointer.
+ NodePtr NeFileSystemMgr::CreateDirectory(const Char* path)
+ {
+ return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir));
+ }
+
+ /// @brief Creates a node with is a alias.
+ /// @param path The filename path.
+ /// @return The Node pointer.
+ NodePtr NeFileSystemMgr::CreateAlias(const Char* path)
+ {
+ return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias));
+ }
+
+ /// @brief Creates a node with is a page file.
+ /// @param path The filename path.
+ /// @return The Node pointer.
+ NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path)
+ {
+ return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage));
+ }
+
+ /// @brief Gets the root directory.
+ /// @return
+ const Char* NeFileSystemHelper::Root()
+ {
+ return kNeFSRoot;
+ }
+
+ /// @brief Gets the up-dir directory.
+ /// @return
+ const Char* NeFileSystemHelper::UpDir()
+ {
+ return kNeFSUpDir;
+ }
+
+ /// @brief Gets the separator character.
+ /// @return
+ const Char NeFileSystemHelper::Separator()
+ {
+ return kNeFSSeparator;
+ }
+
+ /// @brief Gets the metafile character.
+ /// @return
+ const Char NeFileSystemHelper::MetaFile()
+ {
+ return kNeFSMetaFilePrefix;
+ }
+} // namespace Kernel
+
+#endif // ifdef __FSKIT_USE_NEFS__
diff --git a/dev/zka/src/NeFS+IO.cxx b/dev/zka/src/NeFS+IO.cxx
new file mode 100644
index 00000000..6c3aa6e1
--- /dev/null
+++ b/dev/zka/src/NeFS+IO.cxx
@@ -0,0 +1,101 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DriveMgr.hxx>
+#include <KernelKit/FileMgr.hxx>
+
+/*************************************************************
+ *
+ * File: NeFS+IO.cxx
+ * Purpose: Filesystem to mountpoint interface.
+ * Date: 3/26/24
+ *
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ *************************************************************/
+
+#ifdef __FSKIT_USE_NEFS__
+
+#include <FirmwareKit/EPM.hxx>
+
+/// Useful macros.
+
+#define NEFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS)
+#define NEFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS)
+
+using namespace Kernel;
+
+/// @brief Read from newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex)
+{
+ if (!Mnt)
+ return -1;
+
+ DrvTrait.fPacket.fPacketGood = false;
+
+ switch (DrvIndex)
+ {
+ case kNeFSSubDriveA: {
+ NEFS_READ(A, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveB: {
+ NEFS_READ(B, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveC: {
+ NEFS_READ(C, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveD: {
+ NEFS_READ(D, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ }
+
+ return DrvTrait.fPacket.fPacketGood;
+}
+
+/// @brief Write to newfs disk.
+/// @param Mnt mounted interface.
+/// @param DrvTrait drive info
+/// @param DrvIndex drive index.
+/// @return
+Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex)
+{
+ if (!Mnt)
+ return -1;
+
+ DrvTrait.fPacket.fPacketGood = false;
+
+ switch (DrvIndex)
+ {
+ case kNeFSSubDriveA: {
+ NEFS_WRITE(A, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveB: {
+ NEFS_WRITE(B, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveC: {
+ NEFS_WRITE(C, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ case kNeFSSubDriveD: {
+ NEFS_WRITE(D, DrvTrait.fPacket, Mnt);
+ break;
+ }
+ }
+
+ return DrvTrait.fPacket.fPacketGood;
+}
+
+#endif // ifdef __FSKIT_USE_NEFS__
diff --git a/dev/zka/src/Network/IP.cxx b/dev/zka/src/Network/IP.cxx
new file mode 100644
index 00000000..77571bc7
--- /dev/null
+++ b/dev/zka/src/Network/IP.cxx
@@ -0,0 +1,126 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/IP.hxx>
+#include <NewKit/Utils.hxx>
+
+namespace Kernel
+{
+ char* RawIPAddress::Address()
+ {
+ return fAddr;
+ }
+
+ RawIPAddress::RawIPAddress(char bytes[4])
+ {
+ rt_copy_memory(bytes, fAddr, 4);
+ }
+
+ bool RawIPAddress::operator==(const RawIPAddress& ipv4)
+ {
+ for (Size index = 0; index < 4; ++index)
+ {
+ if (ipv4.fAddr[index] != fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool RawIPAddress::operator!=(const RawIPAddress& ipv4)
+ {
+ for (Size index = 0; index < 4; ++index)
+ {
+ if (ipv4.fAddr[index] == fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ char& RawIPAddress::operator[](const Size& index)
+ {
+ kcout << "[RawIPAddress::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 4)
+ return IP_PLACEHOLDER;
+
+ return fAddr[index];
+ }
+
+ RawIPAddress6::RawIPAddress6(char bytes[8])
+ {
+ rt_copy_memory(bytes, fAddr, 8);
+ }
+
+ char& RawIPAddress6::operator[](const Size& index)
+ {
+ kcout << "[RawIPAddress6::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 8)
+ return IP_PLACEHOLDER;
+
+ return fAddr[index];
+ }
+
+ bool RawIPAddress6::operator==(const RawIPAddress6& ipv6)
+ {
+ for (SizeT index = 0; index < 8; ++index)
+ {
+ if (ipv6.fAddr[index] != fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6)
+ {
+ for (SizeT index = 0; index < 8; ++index)
+ {
+ if (ipv6.fAddr[index] == fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6>& ipv6)
+ {
+ auto str = StringBuilder::Construct(ipv6.Leak().Address());
+ return str;
+ }
+
+ ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress>& ipv4)
+ {
+ auto str = StringBuilder::Construct(ipv4.Leak().Address());
+ return str;
+ }
+
+ bool IPFactory::IpCheckVersion4(const Char* ip)
+ {
+ int cnter = 0;
+
+ for (Size base = 0; base < rt_string_len(ip); ++base)
+ {
+ if (ip[base] == '.')
+ {
+ cnter = 0;
+ }
+ else
+ {
+ if (cnter == 3)
+ return false;
+
+ ++cnter;
+ }
+ }
+
+ return true;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Network/IPC.cxx b/dev/zka/src/Network/IPC.cxx
new file mode 100644
index 00000000..42b0fcb9
--- /dev/null
+++ b/dev/zka/src/Network/IPC.cxx
@@ -0,0 +1,114 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/IPC.hxx>
+#include <KernelKit/LPC.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+using namespace Kernel;
+
+/// @internal
+/// @brief The internal sanitize function.
+Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt)
+{
+ auto endian = DEDUCE_ENDIAN(pckt, ((Char*)pckt)[0]);
+
+ switch (endian)
+ {
+ case Endian::kEndianBig: {
+ if (pckt->IpcEndianess == eIPCEPLittleEndian)
+ goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianLittle: {
+ if (pckt->IpcEndianess == eIPCEPBigEndian)
+ goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianMixed: {
+ if (pckt->IpcEndianess == eIPCEPMixedEndian)
+ goto ipc_check_failed;
+
+ break;
+ }
+ default:
+ goto ipc_check_failed;
+ }
+
+ if (pckt->IpcFrom == pckt->IpcTo ||
+ pckt->IpcPacketSize > cXPCOMMsgSize)
+ {
+ goto ipc_check_failed;
+ }
+
+ return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cXPCOMHeaderMagic;
+
+ipc_check_failed:
+ ErrLocal() = kErrorIPC;
+ return false;
+}
+
+namespace Kernel
+{
+ /// @brief Sanitize packet function
+ /// @retval true packet is correct.
+ /// @retval false packet is incorrect and process has crashed.
+ Bool ipc_sanitize_packet(IPC_MESSAGE_STRUCT* pckt)
+ {
+ if (!pckt ||
+ !ipc_int_sanitize_packet(pckt))
+ {
+ UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+ return false;
+ }
+
+ return true;
+ }
+
+ /// @brief Construct packet function
+ /// @retval true packet is correct.
+ /// @retval false packet is incorrect and process has crashed.
+ Bool ipc_construct_packet(_Output IPC_MESSAGE_STRUCT** pckt_in)
+ {
+ // don't do anything if it's valid already.
+ if (*pckt_in)
+ return true;
+
+ // crash process if the packet pointer of pointer is NULL.
+ if (!pckt_in)
+ {
+ UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+ return false;
+ }
+
+ *pckt_in = new IPC_MESSAGE_STRUCT();
+
+ MUST_PASS((*pckt_in));
+
+ if (*pckt_in)
+ {
+ auto endian = DEDUCE_ENDIAN((*pckt_in), ((Char*)(*pckt_in))[0]);
+
+ (*pckt_in)->IpcHeaderMagic = cXPCOMHeaderMagic;
+
+ (*pckt_in)->IpcEndianess = static_cast<UInt8>(endian);
+ (*pckt_in)->IpcPacketSize = sizeof(IPC_MESSAGE_STRUCT);
+
+ (*pckt_in)->IpcTo.UserProcessID = 0;
+ (*pckt_in)->IpcTo.UserProcessTeam = 0;
+
+ (*pckt_in)->IpcFrom.UserProcessID = Kernel::UserProcessScheduler::The().CurrentProcess().Leak().ProcessId;
+ (*pckt_in)->IpcFrom.UserProcessTeam = Kernel::UserProcessScheduler::The().CurrentTeam().mTeamId;
+
+ return true;
+ }
+
+ UserProcessScheduler::The().CurrentProcess().Leak().Crash();
+ return false;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Network/NetworkDevice.cxx b/dev/zka/src/Network/NetworkDevice.cxx
new file mode 100644
index 00000000..afb3e468
--- /dev/null
+++ b/dev/zka/src/Network/NetworkDevice.cxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/NetworkDevice.hxx>
+#include <NewKit/Utils.hxx>
+
+namespace Kernel
+{
+ /// \brief Getter for fNetworkName.
+ const Char* NetworkDevice::Name() const
+ {
+ return this->fNetworkName;
+ }
+
+ /// \brief Setter for fNetworkName.
+ Boolean NetworkDevice::Name(const Char* strView)
+ {
+ if (strView == nullptr)
+ return false;
+
+ if (*strView == 0)
+ return false;
+
+ if (rt_string_len(strView) > cNetworkNameLen)
+ return false;
+
+ rt_copy_memory((VoidPtr)strView,
+ (VoidPtr)this->fNetworkName, rt_string_len(strView));
+
+ return true;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/New+Delete.cxx b/dev/zka/src/New+Delete.cxx
new file mode 100644
index 00000000..36808a21
--- /dev/null
+++ b/dev/zka/src/New+Delete.cxx
@@ -0,0 +1,50 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/Heap.hxx>
+#include <NewKit/New.hxx>
+
+void* operator new[](size_t sz)
+{
+ if (sz == 0)
+ ++sz;
+
+ return Kernel::mm_new_heap(sz, true, false);
+}
+
+void* operator new(size_t sz)
+{
+ if (sz == 0)
+ ++sz;
+
+ return Kernel::mm_new_heap(sz, true, false);
+}
+
+void operator delete[](void* ptr)
+{
+ if (ptr == nullptr)
+ return;
+
+ Kernel::mm_delete_heap(ptr);
+}
+
+void operator delete(void* ptr)
+{
+ if (ptr == nullptr)
+ return;
+
+ Kernel::mm_delete_heap(ptr);
+}
+
+void operator delete(void* ptr, size_t sz)
+{
+ if (ptr == nullptr)
+ return;
+
+ ZKA_UNUSED(sz);
+
+ Kernel::mm_delete_heap(ptr);
+}
diff --git a/dev/zka/src/OwnPtr.cxx b/dev/zka/src/OwnPtr.cxx
new file mode 100644
index 00000000..8b0442a7
--- /dev/null
+++ b/dev/zka/src/OwnPtr.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/OwnPtr.hxx>
diff --git a/dev/zka/src/PEFCodeMgr.cxx b/dev/zka/src/PEFCodeMgr.cxx
new file mode 100644
index 00000000..80bd9206
--- /dev/null
+++ b/dev/zka/src/PEFCodeMgr.cxx
@@ -0,0 +1,258 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <KernelKit/Heap.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <NewKit/OwnPtr.hxx>
+#include <NewKit/String.hxx>
+
+/// @brief PEF stack size symbol.
+#define cPefStackSizeSymbol "SizeOfReserveStack"
+#define cPefHeapSizeSymbol "SizeOfReserveHeap"
+#define cPefNameSymbol "ProgramName"
+
+namespace Kernel
+{
+ namespace Detail
+ {
+ /// @brief Get the PEF platform signature according to the compiled backebnd
+ UInt32 rt_get_pef_platform(void) noexcept
+ {
+#ifdef __ZKA_32X0__
+ return kPefArch32x0;
+#elif defined(__ZKA_64X0__)
+ return kPefArch64x0;
+#elif defined(__ZKA_AMD64__)
+ return kPefArchAMD64;
+#elif defined(__ZKA_PPC64__)
+ return kPefArchPowerPC;
+#elif defined(__ZKA_ARM64__)
+ return kPefArchARM64;
+#else
+ return kPefArchInvalid;
+#endif // __32x0__ || __64x0__ || __x86_64__
+ }
+ } // namespace Detail
+
+ /// @brief PEF loader constructor w/ blob.
+ /// @param blob
+ PEFLoader::PEFLoader(const VoidPtr blob)
+ : fCachedBlob(blob)
+ {
+ MUST_PASS(fCachedBlob);
+ fBad = false;
+ }
+
+ /// @brief PEF loader constructor.
+ /// @param path the filesystem path.
+ PEFLoader::PEFLoader(const Char* path)
+ : fCachedBlob(nullptr), fBad(false), fFatBinary(false)
+ {
+ fFile.New(const_cast<Char*>(path), cRestrictRB);
+ fPath = StringBuilder::Construct(path).Leak();
+
+ auto cPefHeader = "PEF_CONTAINER";
+
+ fCachedBlob = fFile->Read(cPefHeader);
+
+ PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob);
+
+ if (container->Cpu == Detail::rt_get_pef_platform() &&
+ container->Magic[0] == kPefMagic[0] &&
+ container->Magic[1] == kPefMagic[1] &&
+ container->Magic[2] == kPefMagic[2] &&
+ container->Magic[3] == kPefMagic[3] &&
+ container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi)
+ {
+ return;
+ }
+ else if (container->Magic[4] == kPefMagic[0] &&
+ container->Magic[3] == kPefMagic[1] &&
+ container->Magic[2] == kPefMagic[2] &&
+ container->Magic[1] == kPefMagic[3] &&
+ container->Magic[0] == kPefMagic[0] && container->Abi == kPefAbi)
+ {
+ /// This is a fat binary.
+ this->fFatBinary = true;
+ return;
+ }
+
+ fBad = true;
+
+ if (fCachedBlob)
+ mm_delete_heap(fCachedBlob);
+
+ kcout << "CodeMgrPEF: Warning: Executable format error!\r";
+ fCachedBlob = nullptr;
+ }
+
+ /// @brief PEF destructor.
+ PEFLoader::~PEFLoader()
+ {
+ if (fCachedBlob)
+ mm_delete_heap(fCachedBlob);
+
+ fFile.Delete();
+ }
+
+ VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind)
+ {
+ if (!fCachedBlob || fBad || !name)
+ return nullptr;
+
+ PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob);
+
+ auto blob = fFile->Read(name);
+
+ PEFCommandHeader* container_header = reinterpret_cast<PEFCommandHeader*>(blob);
+
+ constexpr auto cMangleCharacter = '$';
+ const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr};
+
+ ErrorOr<StringView> errOrSym;
+
+ switch (kind)
+ {
+ case kPefCode: {
+ errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol.
+ break;
+ }
+ case kPefData: {
+ errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol.
+ break;
+ }
+ case kPefZero: {
+ errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol.
+ break;
+ }
+ default:
+ return nullptr;
+ }
+
+ char* unconstSymbol = const_cast<char*>(name);
+
+ for (SizeT i = 0UL; i < rt_string_len(unconstSymbol, kPefNameLen); ++i)
+ {
+ if (unconstSymbol[i] == ' ')
+ {
+ unconstSymbol[i] = cMangleCharacter;
+ }
+ }
+
+ errOrSym.Leak().Leak() += name;
+
+ for (SizeT index = 0; index < container->Count; ++index)
+ {
+ if (StringBuilder::Equals(container_header->Name,
+ errOrSym.Leak().Leak().CData()))
+ {
+ if (container_header->Kind == kind)
+ {
+ if (container_header->Cpu != Detail::rt_get_pef_platform())
+ {
+ if (!this->fFatBinary)
+ {
+ mm_delete_heap(blob);
+ return nullptr;
+ }
+ }
+
+ Char* blobRet = new Char[container_header->Size];
+
+ rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size);
+ mm_delete_heap(blob);
+
+ return blobRet;
+ }
+ }
+ }
+
+ mm_delete_heap(blob);
+ return nullptr;
+ }
+
+ /// @brief Finds the executable entrypoint.
+ /// @return
+ ErrorOr<VoidPtr> PEFLoader::FindStart()
+ {
+ if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym)
+ return ErrorOr<VoidPtr>(sym);
+
+ return ErrorOr<VoidPtr>(kErrorExecutable);
+ }
+
+ /// @brief Tells if the executable is loaded or not.
+ /// @return
+ bool PEFLoader::IsLoaded() noexcept
+ {
+ return !fBad && fCachedBlob;
+ }
+
+ namespace Utils
+ {
+ Bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept
+ {
+ auto errOrStart = exec.FindStart();
+
+ if (errOrStart.Error() != kErrorSuccess)
+ return false;
+
+ UserProcess proc;
+
+ proc.SetImageStart(errOrStart.Leak().Leak());
+ proc.Kind = procKind;
+ proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData);
+ proc.MemoryLimit = *(UIntPtr*)exec.FindSymbol(cPefHeapSizeSymbol, kPefData);
+
+ rt_set_memory(proc.Name, 0, kProcessLen);
+
+ if (exec.FindSymbol(cPefNameSymbol, kPefData))
+ rt_copy_memory((VoidPtr)exec.FindSymbol(cPefNameSymbol, kPefData), proc.Name, rt_string_len((Char*)exec.FindSymbol(cPefNameSymbol, kPefData)));
+ else
+ rt_copy_memory((VoidPtr) "UNNAMED PROCESS.", proc.Name, rt_string_len("UNNAMED PROCESS."));
+
+ if (!proc.StackSize)
+ {
+ const auto cDefaultStackSizeMib = 8;
+
+ proc.StackSize = mib_cast(cDefaultStackSizeMib);
+ }
+
+ return UserProcessScheduler::The().Add(proc) > 0;
+ }
+ } // namespace Utils
+
+ const Char* PEFLoader::Path()
+ {
+ return fPath.Leak().CData();
+ }
+
+ const Char* PEFLoader::AsString()
+ {
+#ifdef __32x0__
+ return "32x0 PEF executable.";
+#elif defined(__64x0__)
+ return "64x0 PEF executable.";
+#elif defined(__x86_64__)
+ return "x86_64 PEF executable.";
+#elif defined(__aarch64__)
+ return "aarch64 PEF executable.";
+#elif defined(__powerpc64__)
+ return "POWER64 PEF executable.";
+#else
+ return "???? PEF executable.";
+#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__
+ }
+
+ const Char* PEFLoader::MIME()
+ {
+ return kPefApplicationMime;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/PRDT.cxx b/dev/zka/src/PRDT.cxx
new file mode 100644
index 00000000..f9bbd685
--- /dev/null
+++ b/dev/zka/src/PRDT.cxx
@@ -0,0 +1,22 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/String.hxx>
+#include <StorageKit/PRDT.hxx>
+
+namespace Kernel
+{
+ /// @brief constructs a new PRD.
+ /// @param prd PRD reference.
+ /// @note This doesnt construct a valid, please fill it by yourself.
+ void construct_prdt(Ref<PRDT>& prd)
+ {
+ prd.Leak().fPhysAddress = 0x0;
+ prd.Leak().fSectorCount = 0x0;
+ prd.Leak().fEndBit = 0x0;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/PageMgr.cxx b/dev/zka/src/PageMgr.cxx
new file mode 100644
index 00000000..3eefe491
--- /dev/null
+++ b/dev/zka/src/PageMgr.cxx
@@ -0,0 +1,111 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/PageMgr.hxx>
+
+#ifdef __ZKA_AMD64__
+#include <HALKit/AMD64/Paging.hxx>
+#elif defined(__ZKA_ARM64__)
+#include <HALKit/ARM64/Paging.hxx>
+#endif // ifdef __ZKA_AMD64__ || defined(__ZKA_ARM64__)
+
+//! null deref will throw (Page Zero detected, aborting app!)
+#define kProtectedRegionEnd (512)
+
+namespace Kernel
+{
+ PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr)
+ : fRw(Rw),
+ fUser(User),
+ fExecDisable(ExecDisable),
+ fVirtAddr(VirtAddr),
+ fCache(false),
+ fShareable(false),
+ fWt(false),
+ fPresent(true),
+ fAccessed(false)
+ {
+ }
+
+ PTEWrapper::~PTEWrapper() = default;
+
+ /// @brief Flush virtual address.
+ /// @param VirtAddr
+ Void PageMgr::FlushTLB()
+ {
+ hal_flush_tlb();
+ }
+
+ /// @brief Reclaim freed page.
+ /// @return
+ Bool PTEWrapper::Reclaim()
+ {
+ if (!this->fPresent)
+ {
+ this->fPresent = true;
+ return true;
+ }
+
+ return false;
+ }
+
+ /// @brief Request a PTE.
+ /// @param Rw r/w?
+ /// @param User user mode?
+ /// @param ExecDisable disable execution on page?
+ /// @return
+ PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz)
+ {
+ // Store PTE wrapper right after PTE.
+ VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz);
+
+ return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)};
+ }
+
+ /// @brief Disable BitMap.
+ /// @param wrapper the wrapper.
+ /// @return If the page bitmap was cleared or not.
+ Bool PageMgr::Free(Ref<PTEWrapper>& wrapper)
+ {
+ if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper.Leak().VirtualAddress()))
+ return false;
+
+ return true;
+ }
+
+ /// @brief Virtual PTE address.
+ /// @return The virtual address of the page.
+ const UIntPtr PTEWrapper::VirtualAddress()
+ {
+ return (fVirtAddr);
+ }
+
+ bool PTEWrapper::Shareable()
+ {
+ return fShareable;
+ }
+
+ bool PTEWrapper::Present()
+ {
+ return fPresent;
+ }
+
+ bool PTEWrapper::Access()
+ {
+ return fAccessed;
+ }
+
+ void PTEWrapper::NoExecute(const bool enable)
+ {
+ this->fExecDisable = enable;
+ }
+
+ const bool& PTEWrapper::NoExecute()
+ {
+ return this->fExecDisable;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Pmm.cxx b/dev/zka/src/Pmm.cxx
new file mode 100644
index 00000000..394b634c
--- /dev/null
+++ b/dev/zka/src/Pmm.cxx
@@ -0,0 +1,94 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/Pmm.hxx>
+
+#if defined(__ZKA_ARM64__)
+#include <HALKit/ARM64/Processor.hxx>
+#endif // defined(__ZKA_ARM64__)
+
+#if defined(__ZKA_AMD64__)
+#include <HALKit/AMD64/Processor.hxx>
+#endif // defined(__ZKA_AMD64__)
+
+namespace Kernel
+{
+ /// @brief Pmm constructor.
+ Pmm::Pmm()
+ : fPageMgr()
+ {
+ kcout << "[PMM] Allocate PageMemoryMgr";
+ }
+
+ Pmm::~Pmm() = default;
+
+ /* If this returns Null pointer, enter emergency mode */
+ /// @param user is this a user page?
+ /// @param readWrite is it r/w?
+ Ref<PTEWrapper> Pmm::RequestPage(Boolean user, Boolean readWrite)
+ {
+ PTEWrapper pt = fPageMgr.Leak().Request(user, readWrite, false, kPageSize);
+
+ if (pt.fPresent)
+ {
+ kcout << "[PMM]: Allocation failed.\r";
+ return {};
+ }
+
+ return Ref<PTEWrapper>(pt);
+ }
+
+ Boolean Pmm::FreePage(Ref<PTEWrapper> PageRef)
+ {
+ if (!PageRef)
+ return false;
+
+ PageRef.Leak().fPresent = false;
+
+ return true;
+ }
+
+ Boolean Pmm::TogglePresent(Ref<PTEWrapper> PageRef, Boolean Enable)
+ {
+ if (!PageRef)
+ return false;
+
+ PageRef.Leak().fPresent = Enable;
+
+ return true;
+ }
+
+ Boolean Pmm::ToggleUser(Ref<PTEWrapper> PageRef, Boolean Enable)
+ {
+ if (!PageRef)
+ return false;
+
+ PageRef.Leak().fRw = Enable;
+
+ return true;
+ }
+
+ Boolean Pmm::ToggleRw(Ref<PTEWrapper> PageRef, Boolean Enable)
+ {
+ if (!PageRef)
+ return false;
+
+ PageRef.Leak().fRw = Enable;
+
+ return true;
+ }
+
+ Boolean Pmm::ToggleShare(Ref<PTEWrapper> PageRef, Boolean Enable)
+ {
+ if (!PageRef)
+ return false;
+
+ PageRef.Leak().fShareable = Enable;
+
+ return true;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Property.cxx b/dev/zka/src/Property.cxx
new file mode 100644
index 00000000..04b4367e
--- /dev/null
+++ b/dev/zka/src/Property.cxx
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <CFKit/Property.hxx>
+
+namespace Kernel
+{
+ Property::~Property() = default;
+
+ bool Property::StringEquals(StringView& name)
+ {
+ return this->fName && this->fName == name;
+ }
+
+ StringView& Property::GetKey()
+ {
+ return this->fName;
+ }
+
+ PropertyId& Property::GetValue()
+ {
+ return fAction;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Ref.cxx b/dev/zka/src/Ref.cxx
new file mode 100644
index 00000000..cf383271
--- /dev/null
+++ b/dev/zka/src/Ref.cxx
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Ref.hxx>
diff --git a/dev/zka/src/Semaphore.cxx b/dev/zka/src/Semaphore.cxx
new file mode 100644
index 00000000..3e30cc31
--- /dev/null
+++ b/dev/zka/src/Semaphore.cxx
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/Semaphore.hxx>
+
+namespace Kernel
+{
+ bool Semaphore::Unlock() noexcept
+ {
+ if (fLockingProcess)
+ fLockingProcess = nullptr;
+
+ return fLockingProcess == nullptr;
+ }
+
+ bool Semaphore::Lock(UserProcess* process)
+ {
+ if (!process || fLockingProcess)
+ return false;
+
+ fLockingProcess = process;
+
+ return true;
+ }
+
+ bool Semaphore::IsLocked() const
+ {
+ return fLockingProcess;
+ }
+
+ bool Semaphore::LockOrWait(UserProcess* process, TimerInterface* timer)
+ {
+ if (process == nullptr)
+ return false;
+
+ if (timer == nullptr)
+ return false;
+
+ this->Lock(process);
+
+ timer->Wait();
+
+ return this->Lock(process);
+ }
+
+ /// @brief Wait with process, either wait for process being invalid, or not being run.
+ Void Semaphore::WaitForProcess() noexcept
+ {
+ while (fLockingProcess)
+ {
+ if (fLockingProcess->GetStatus() != ProcessStatusKind::kRunning)
+ {
+ this->Unlock();
+ break;
+ }
+ }
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Storage/AHCIDeviceInterface.cxx b/dev/zka/src/Storage/AHCIDeviceInterface.cxx
new file mode 100644
index 00000000..1dc52b72
--- /dev/null
+++ b/dev/zka/src/Storage/AHCIDeviceInterface.cxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <StorageKit/AHCI.hxx>
+
+using namespace Kernel;
+
+/// @brief Class constructor
+/// @param Out Drive output
+/// @param In Drive input
+/// @param Cleanup Drive cleanup.
+AHCIDeviceInterface::AHCIDeviceInterface(void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void))
+ : DeviceInterface(Out, In), fCleanup(Cleanup)
+{
+}
+
+/// @brief Class desctructor
+AHCIDeviceInterface::~AHCIDeviceInterface()
+{
+ MUST_PASS(fCleanup);
+ if (fCleanup)
+ fCleanup();
+}
+
+/// @brief Returns the name of the device interface.
+/// @return it's name as a string.
+const Char* AHCIDeviceInterface::Name() const
+{
+ return "AHCIDeviceInterface";
+}
diff --git a/dev/zka/src/Storage/ATADeviceInterface.cxx b/dev/zka/src/Storage/ATADeviceInterface.cxx
new file mode 100644
index 00000000..78abada0
--- /dev/null
+++ b/dev/zka/src/Storage/ATADeviceInterface.cxx
@@ -0,0 +1,88 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <StorageKit/ATA.hxx>
+
+using namespace Kernel;
+
+/// @brief Class constructor
+/// @param Out Drive output
+/// @param In Drive input
+/// @param Cleanup Drive cleanup.
+ATADeviceInterface::ATADeviceInterface(
+ void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void))
+ : DeviceInterface(Out, In), fCleanup(Cleanup)
+{
+}
+
+/// @brief Class desctructor
+ATADeviceInterface::~ATADeviceInterface()
+{
+ MUST_PASS(fCleanup);
+ if (fCleanup)
+ fCleanup();
+}
+
+/// @brief Returns the name of the device interface.
+/// @return it's name as a string.
+const Char* ATADeviceInterface::Name() const
+{
+ return "ATADeviceInterface";
+}
+
+/// @brief Output operator.
+/// @param Data
+/// @return
+ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data)
+{
+ if (!Data)
+ return *this;
+
+ for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount)
+ {
+ auto interface = Data->GetAddressOf(driveCount);
+ if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0)
+ {
+ continue;
+ }
+ else if ((interface) &&
+ rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0)
+ {
+ return *this;
+ }
+ }
+
+ return (ATADeviceInterface&)DeviceInterface<MountpointInterface*>::operator<<(
+ Data);
+}
+
+/// @brief Input operator.
+/// @param Data
+/// @return
+ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data)
+{
+ if (!Data)
+ return *this;
+
+ for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount)
+ {
+ auto interface = Data->GetAddressOf(driveCount);
+ if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0)
+ {
+ continue;
+ }
+ else if ((interface) &&
+ rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) != 0)
+ {
+ return *this;
+ }
+ }
+
+ return (ATADeviceInterface&)DeviceInterface<MountpointInterface*>::operator>>(
+ Data);
+}
diff --git a/dev/zka/src/Storage/NVMEDeviceInterface.cxx b/dev/zka/src/Storage/NVMEDeviceInterface.cxx
new file mode 100644
index 00000000..5809a5e6
--- /dev/null
+++ b/dev/zka/src/Storage/NVMEDeviceInterface.cxx
@@ -0,0 +1,28 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <StorageKit/NVME.hxx>
+
+namespace Kernel
+{
+ NVMEDeviceInterface::NVMEDeviceInterface(void (*Out)(MountpointInterface* outpacket),
+ void (*In)(MountpointInterface* inpacket),
+ void (*Cleanup)(void))
+ : DeviceInterface(Out, In), fCleanup(Cleanup)
+ {
+ }
+
+ NVMEDeviceInterface::~NVMEDeviceInterface()
+ {
+ if (fCleanup)
+ fCleanup();
+ }
+
+ const Char* NVMEDeviceInterface::Name() const
+ {
+ return ("NVMEDeviceInterface");
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Storage/SCSIDeviceInterface.cxx b/dev/zka/src/Storage/SCSIDeviceInterface.cxx
new file mode 100644
index 00000000..da75a181
--- /dev/null
+++ b/dev/zka/src/Storage/SCSIDeviceInterface.cxx
@@ -0,0 +1,11 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <StorageKit/SCSI.hxx>
+
+///! @brief ATAPI SCSI packet.
+const scsi_packet_type kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0,
+ 0, 12, 0x40, 0, 0};
diff --git a/dev/zka/src/Stream.cxx b/dev/zka/src/Stream.cxx
new file mode 100644
index 00000000..3a809a8d
--- /dev/null
+++ b/dev/zka/src/Stream.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: Stream.cxx
+ Purpose: Stream object
+
+ Revision History:
+
+------------------------------------------- */
+
+#include <NewKit/Stream.hxx>
diff --git a/dev/zka/src/String.cxx b/dev/zka/src/String.cxx
new file mode 100644
index 00000000..bfa80711
--- /dev/null
+++ b/dev/zka/src/String.cxx
@@ -0,0 +1,257 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/String.hxx>
+#include <NewKit/Utils.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+namespace Kernel
+{
+ Char* StringView::Data()
+ {
+ return fData;
+ }
+
+ const Char* StringView::CData() const
+ {
+ return fData;
+ }
+
+ Size StringView::Length() const
+ {
+ return fSz;
+ }
+
+ bool StringView::operator==(const StringView& rhs) const
+ {
+ if (rhs.Length() != this->Length())
+ return false;
+
+ for (Size index = 0; index < this->Length(); ++index)
+ {
+ if (rhs.fData[index] != fData[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool StringView::operator==(const Char* rhs) const
+ {
+ if (rt_string_len(rhs) != this->Length())
+ return false;
+
+ for (Size index = 0; index < rt_string_len(rhs); ++index)
+ {
+ if (rhs[index] != fData[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool StringView::operator!=(const StringView& rhs) const
+ {
+ if (rhs.Length() != this->Length())
+ return false;
+
+ for (Size index = 0; index < rhs.Length(); ++index)
+ {
+ if (rhs.fData[index] == fData[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool StringView::operator!=(const Char* rhs) const
+ {
+ if (rt_string_len(rhs) != this->Length())
+ return false;
+
+ for (Size index = 0; index < rt_string_len(rhs); ++index)
+ {
+ if (rhs[index] == fData[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ ErrorOr<StringView> StringBuilder::Construct(const Char* data)
+ {
+ if (!data || *data == 0)
+ return {};
+
+ StringView view(rt_string_len(data));
+
+ view += data;
+
+ return ErrorOr<StringView>(view);
+ }
+
+ const Char* StringBuilder::FromInt(const Char* fmt, int i)
+ {
+ if (!fmt)
+ return ("-1");
+
+ char* ret = (char*)ALLOCA(sizeof(char) * 8 + rt_string_len(fmt));
+
+ if (!ret)
+ return ("-1");
+
+ Char result[8];
+
+ if (!rt_to_string(result, sizeof(int), i))
+ {
+ return ("-1");
+ }
+
+ const auto fmt_len = rt_string_len(fmt);
+ const auto res_len = rt_string_len(result);
+
+ for (Size idx = 0; idx < fmt_len; ++idx)
+ {
+ if (fmt[idx] == '%')
+ {
+ SizeT result_cnt = idx;
+
+ for (auto y_idx = idx; y_idx < res_len; ++y_idx)
+ {
+ ret[result_cnt] = result[y_idx];
+ ++result_cnt;
+ }
+
+ break;
+ }
+
+ ret[idx] = fmt[idx];
+ }
+
+ return ret; /* Copy that ret into a buffer, 'ALLOCA' allocates to the stack */
+ }
+
+ const Char* StringBuilder::FromBool(const Char* fmt, bool i)
+ {
+ if (!fmt)
+ return ("?");
+
+ const Char* boolean_expr = i ? "true" : "false";
+ char* ret = (char*)ALLOCA((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt));
+
+ if (!ret)
+ return ("?");
+
+ const auto fmt_len = rt_string_len(fmt);
+ const auto res_len = rt_string_len(boolean_expr);
+
+ for (Size idx = 0; idx < fmt_len; ++idx)
+ {
+ if (fmt[idx] == '%')
+ {
+ SizeT result_cnt = idx;
+
+ for (auto y_idx = idx; y_idx < res_len; ++y_idx)
+ {
+ ret[result_cnt] = boolean_expr[y_idx];
+ ++result_cnt;
+ }
+
+ break;
+ }
+
+ ret[idx] = fmt[idx];
+ }
+
+ return ret;
+ }
+
+ bool StringBuilder::Equals(const Char* lhs, const Char* rhs)
+ {
+ if (rt_string_len(rhs) != rt_string_len(lhs))
+ return false;
+
+ for (Size index = 0; index < rt_string_len(rhs); ++index)
+ {
+ if (rhs[index] != lhs[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool StringBuilder::Equals(const WideChar* lhs, const WideChar* rhs)
+ {
+ for (Size index = 0; rhs[index] != 0; ++index)
+ {
+ if (rhs[index] != lhs[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ const Char* StringBuilder::Format(const Char* fmt, const Char* fmt2)
+ {
+ if (!fmt || !fmt2)
+ return ("?");
+
+ char* ret =
+ (char*)ALLOCA(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2));
+
+ if (!ret)
+ return ("?");
+
+ for (Size idx = 0; idx < rt_string_len(fmt); ++idx)
+ {
+ if (fmt[idx] == '%')
+ {
+ Size result_cnt = idx;
+ for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx)
+ {
+ ret[result_cnt] = fmt2[y_idx];
+ ++result_cnt;
+ }
+
+ break;
+ }
+
+ ret[idx] = fmt[idx];
+ }
+
+ return ret;
+ }
+
+ STATIC void rt_string_append(Char* lhs, const Char* rhs, Int32 cur)
+ {
+ SizeT sz_rhs = rt_string_len(rhs);
+ SizeT rhs_i = 0;
+
+ for (; rhs_i < sz_rhs; ++rhs_i)
+ {
+ lhs[rhs_i + cur] = rhs[rhs_i];
+ }
+ }
+
+ StringView& StringView::operator+=(const Char* rhs)
+ {
+ rt_string_append(this->fData, rhs, this->fCur);
+ this->fCur += rt_string_len(rhs);
+
+ return *this;
+ }
+
+ StringView& StringView::operator+=(const StringView& rhs)
+ {
+ if (rt_string_len(rhs.fData) > this->Length())
+ return *this;
+
+ rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur);
+ this->fCur += rt_string_len(const_cast<Char*>(rhs.fData));
+
+ return *this;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/ThreadLocalStorage.cxx b/dev/zka/src/ThreadLocalStorage.cxx
new file mode 100644
index 00000000..587edafd
--- /dev/null
+++ b/dev/zka/src/ThreadLocalStorage.cxx
@@ -0,0 +1,68 @@
+/*
+ * ========================================================
+ *
+ * newoskrnl
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/String.hxx>
+#include <CFKit/Property.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/ThreadLocalStorage.hxx>
+
+///! BUGS: 0
+
+/***********************************************************************************/
+/// @file ThreadLocalStorage.cxx
+/// @brief TLS inside the Kernel.
+/***********************************************************************************/
+
+using namespace Kernel;
+
+/**
+ * @brief Checks for cookie inside the TIB.
+ * @param tib the TIB to check.
+ * @return if the cookie is enabled.
+ */
+
+Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib)
+{
+ if (!the_tib ||
+ !the_tib->f_ThreadRecord)
+ return false;
+
+ IEncoderObject encoder;
+ const char* tibAsBytes = encoder.AsBytes(the_tib);
+
+ kcout << "checking for a valid cookie inside the TIB...\r";
+
+ return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 &&
+ tibAsBytes[2] == kCookieMag2;
+}
+
+/**
+ * @brief System call implementation of the TLS check.
+ * @param tib_ptr The TIB record.
+ * @return
+ */
+EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept
+{
+ if (!tib_ptr)
+ {
+ kcout << "failing because of an invalid TIB...\r";
+ return false;
+ }
+
+ THREAD_INFORMATION_BLOCK* tib_struct = (THREAD_INFORMATION_BLOCK*)tib_ptr;
+
+ if (!tls_check_tib(tib_struct))
+ {
+ kcout << "crashing because of an invalid TIB...\r";
+ return false;
+ }
+
+ kcout << "Verification succeeded! staying alive...\r";
+ return true;
+}
diff --git a/dev/zka/src/Timer.cxx b/dev/zka/src/Timer.cxx
new file mode 100644
index 00000000..397c19a9
--- /dev/null
+++ b/dev/zka/src/Timer.cxx
@@ -0,0 +1,47 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <KernelKit/Timer.hxx>
+
+///! BUGS: 0
+///! @file Timer.cxx
+///! @brief Software Timer implementation
+
+using namespace Kernel;
+
+/// @brief Unimplemented as it is an interface.
+Int32 TimerInterface::Wait() noexcept
+{
+ return kErrorUnimplemented;
+}
+
+/// @brief SoftwareTimer class, meant to be generic.
+
+SoftwareTimer::SoftwareTimer(Int64 seconds)
+ : fWaitFor(seconds)
+{
+ fDigitalTimer = new IntPtr();
+ MUST_PASS(fDigitalTimer);
+}
+
+SoftwareTimer::~SoftwareTimer()
+{
+ delete fDigitalTimer;
+ fWaitFor = 0;
+}
+
+Int32 SoftwareTimer::Wait() noexcept
+{
+ if (fWaitFor < 1)
+ return -1;
+
+ while (*fDigitalTimer < (*fDigitalTimer + fWaitFor))
+ {
+ ++(*fDigitalTimer);
+ }
+
+ return 0;
+}
diff --git a/dev/zka/src/URL.cxx b/dev/zka/src/URL.cxx
new file mode 100644
index 00000000..e10310f5
--- /dev/null
+++ b/dev/zka/src/URL.cxx
@@ -0,0 +1,98 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <CFKit/URL.hxx>
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/Utils.hxx>
+
+/// BUGS: 0
+
+namespace Kernel
+{
+ URL::URL(StringView& strUrl)
+ : fUrlView(strUrl, false)
+ {
+ }
+
+ URL::~URL() = default;
+
+ /// @brief internal and reserved protocols by Kernel.
+ constexpr const Char* kURLProtocols[] = {
+ "file", // Filesystem protocol
+ "zup", // ZKA update protocol
+ "oscc", // Open System Configuration Connectivity.
+ "odbc", // ODBC connectivity.
+ "https", // HTTPS layer driver (HTTPS.sys).
+ };
+
+ constexpr const int kUrlOutSz = 1; //! such as: ://
+ constexpr const int kProtosCount = 5;
+ constexpr const int kRangeSz = 4096;
+
+ ErrorOr<StringView> url_extract_location(const Char* url)
+ {
+ if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz)
+ return ErrorOr<StringView>{-1};
+
+ StringView view(rt_string_len(url));
+
+ SizeT i = 0;
+ bool scheme_found = false;
+
+ for (; i < rt_string_len(url); ++i)
+ {
+ if (!scheme_found)
+ {
+ for (int y = 0; kProtosCount; ++y)
+ {
+ if (rt_string_in_string(view.CData(), kURLProtocols[y]))
+ {
+ i += rt_string_len(kURLProtocols[y]) + kUrlOutSz;
+ scheme_found = true;
+
+ break;
+ }
+ }
+ }
+
+ view.Data()[i] = url[i];
+ }
+
+ return ErrorOr<StringView>(view);
+ }
+
+ ErrorOr<StringView> url_extract_protocol(const Char* url)
+ {
+ if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz)
+ return ErrorOr<StringView>{-1};
+
+ ErrorOr<StringView> view{-1};
+
+ return view;
+ }
+
+ Ref<ErrorOr<StringView>> URL::Location() noexcept
+ {
+ const Char* src = fUrlView.Leak().CData();
+ auto loc = url_extract_location(src);
+
+ if (!loc)
+ return {};
+
+ return Ref<ErrorOr<StringView>>(loc);
+ }
+
+ Ref<ErrorOr<StringView>> URL::Protocol() noexcept
+ {
+ const Char* src = fUrlView.Leak().CData();
+ auto loc = url_extract_protocol(src);
+
+ if (!loc)
+ return {};
+
+ return Ref<ErrorOr<StringView>>(loc);
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/User.cxx b/dev/zka/src/User.cxx
new file mode 100644
index 00000000..066a3e06
--- /dev/null
+++ b/dev/zka/src/User.cxx
@@ -0,0 +1,138 @@
+/*
+ * ========================================================
+ *
+ * ZKA
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * File: User.cxx
+ * Purpose: User class, used to provide authentication and security.
+ *
+ * ========================================================
+ */
+
+#include <KernelKit/LPC.hxx>
+#include <KernelKit/User.hxx>
+#include <NewKit/KernelCheck.hxx>
+#include <KernelKit/FileMgr.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+#include <KernelKit/Heap.hxx>
+
+#define cStdUser (0xCF)
+#define cSuperUser (0xEF)
+
+/// BUGS: 0
+
+namespace Kernel
+{
+ namespace Detail
+ {
+ /// \brief Constructs a password by hashing the password.
+ /// \param password password to hash.
+ /// \return the hashed password
+ const Int32 cred_construct_token(Char* password, const Char* in_password, User* user, SizeT length)
+ {
+ if (!password || !user)
+ return -1;
+
+ kcout << "Constructing password...\r";
+
+ for (Size i_pass = 0; i_pass < length; ++i_pass)
+ {
+ Char cur_chr = in_password[i_pass];
+
+ if (cur_chr == 0)
+ break;
+
+ password[i_pass] = cur_chr + (user->IsStdUser() ? cStdUser : cSuperUser);
+ }
+
+ kcout << "Done constructing password...\r";
+
+ return 0;
+ }
+ } // namespace Detail
+
+ User::User(const Int32& sel, const Char* userName)
+ : fRing((RingKind)sel)
+ {
+ MUST_PASS(sel >= 0);
+ rt_copy_memory((VoidPtr)userName, this->fUserName, rt_string_len(userName));
+ }
+
+ User::User(const RingKind& ringKind, const Char* userName)
+ : fRing(ringKind)
+ {
+ rt_copy_memory((VoidPtr)userName, this->fUserName, rt_string_len(userName));
+ }
+
+ User::~User() = default;
+
+ Bool User::TrySave(const Char* password_to_fill) noexcept
+ {
+ if (!password_to_fill ||
+ *password_to_fill == 0)
+ return false;
+
+ SizeT len = rt_string_len(password_to_fill);
+
+ Char* password = new Char[len];
+ MUST_PASS(password);
+
+ // fill data first, generate hash.
+ // return false on error.
+
+ rt_copy_memory((VoidPtr)password_to_fill, password, len);
+
+ if (!Detail::cred_construct_token(password, password_to_fill, this, len))
+ {
+ delete[] password;
+ password = nullptr;
+
+ return false;
+ }
+
+ // then store password.
+
+ rt_copy_memory(password, this->fUserToken, rt_string_len(password_to_fill));
+
+ delete[] password;
+ password = nullptr;
+
+ kcout << "Saved password...\r";
+
+ return true;
+ }
+
+ bool User::operator==(const User& lhs)
+ {
+ return lhs.fRing == this->fRing;
+ }
+
+ bool User::operator!=(const User& lhs)
+ {
+ return lhs.fRing != this->fRing;
+ }
+
+ Char* User::Name() noexcept
+ {
+ return this->fUserName;
+ }
+
+ /// @brief Returns the user's ring.
+ /// @return The king of ring the user is attached to.
+ const RingKind& User::Ring() noexcept
+ {
+ return this->fRing;
+ }
+
+ Bool User::IsStdUser() noexcept
+ {
+ return this->Ring() == RingKind::kRingStdUser;
+ }
+
+ Bool User::IsSuperUser() noexcept
+ {
+ return this->Ring() == RingKind::kRingSuperUser;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/UserProcessScheduler.cxx b/dev/zka/src/UserProcessScheduler.cxx
new file mode 100644
index 00000000..88980f8d
--- /dev/null
+++ b/dev/zka/src/UserProcessScheduler.cxx
@@ -0,0 +1,484 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ FILE: UserProcessScheduler.cxx
+ PURPOSE: Low Exception Process scheduler.
+
+------------------------------------------- */
+
+/***********************************************************************************/
+/// @file UserProcessScheduler.cxx
+/// @brief User Process scheduler.
+/***********************************************************************************/
+
+#include <KernelKit/UserProcessScheduler.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
+#include <KernelKit/HardwareThreadScheduler.hxx>
+#include <KernelKit/Heap.hxx>
+#include <NewKit/String.hxx>
+#include <KernelKit/LPC.hxx>
+
+///! BUGS: 0
+
+/***********************************************************************************/
+/** TODO: Document the Kernel, SDK and kits. */
+/***********************************************************************************/
+
+namespace Kernel
+{
+ /***********************************************************************************/
+ /// @brief Exit Code global variable.
+ /***********************************************************************************/
+
+ STATIC UInt32 cLastExitCode = 0U;
+
+ /***********************************************************************************/
+ /// @brief User Process scheduler global object.
+ /***********************************************************************************/
+
+ UserProcessScheduler* cProcessScheduler = nullptr;
+
+ /// @brief Gets the last exit code.
+ /// @note Not thread-safe.
+ /// @return Int32 the last exit code.
+ const UInt32& sched_get_exit_code(void) noexcept
+ {
+ return cLastExitCode;
+ }
+
+ /***********************************************************************************/
+ /// @brief crash current process.
+ /***********************************************************************************/
+
+ Void UserProcess::Crash()
+ {
+ if (*this->Name != 0)
+ kcout << this->Name << ": crashed, error id: " << number(kErrorProcessFault) << endl;
+
+ this->Exit(kErrorProcessFault);
+ }
+
+ /// @brief Gets the local last exit code.
+ /// @note Not thread-safe.
+ /// @return Int32 the last exit code.
+ const UInt32& UserProcess::GetExitCode() noexcept
+ {
+ return this->fLastExitCode;
+ }
+
+ /***********************************************************************************/
+ /// @brief Error code variable getter.
+ /***********************************************************************************/
+
+ Int32& UserProcess::GetLocalCode() noexcept
+ {
+ return fLocalCode;
+ }
+
+ void UserProcess::Wake(const bool should_wakeup)
+ {
+ this->Status =
+ should_wakeup ? ProcessStatusKind::kRunning : ProcessStatusKind::kFrozen;
+ }
+
+ /***********************************************************************************/
+
+ /** @brief Add pointer to entry. */
+ VoidPtr UserProcess::New(const SizeT& sz)
+ {
+#ifdef __ZKA_AMD64__
+ auto pd = hal_read_cr3();
+ hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD));
+
+ auto ptr = mm_new_heap(sz, Yes, Yes);
+
+ hal_write_cr3(reinterpret_cast<VoidPtr>(pd));
+#else
+ auto ptr = mm_new_heap(sz, Yes, Yes);
+#endif
+
+ if (!this->MemoryEntryList)
+ {
+ this->MemoryEntryList = new UserProcess::PROCESS_MEMORY_ENTRY();
+ this->MemoryEntryList->MemoryEntry = ptr;
+
+ this->MemoryEntryList->MemoryPrev = nullptr;
+ this->MemoryEntryList->MemoryNext = nullptr;
+
+ return ptr;
+ }
+ else
+ {
+ auto entry = this->MemoryEntryList;
+ PROCESS_MEMORY_ENTRY* prev_entry = nullptr;
+
+ while (!entry)
+ {
+ prev_entry = entry;
+ entry = entry->MemoryNext;
+ }
+
+ entry->MemoryNext = new UserProcess::PROCESS_MEMORY_ENTRY();
+ entry->MemoryNext->MemoryEntry = ptr;
+
+ entry->MemoryNext->MemoryPrev = entry;
+ entry->MemoryNext->MemoryNext = nullptr;
+ }
+
+ return nullptr;
+ }
+
+ /***********************************************************************************/
+
+ /** @brief Free pointer from usage. */
+ Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz)
+ {
+ auto entry = this->MemoryEntryList;
+
+ while (entry)
+ {
+ if (entry->MemoryEntry == ptr)
+ {
+#ifdef __ZKA_AMD64__
+ auto pd = hal_read_cr3();
+ hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD));
+
+ Bool ret = mm_delete_heap(ptr);
+ hal_write_cr3(reinterpret_cast<VoidPtr>(pd));
+
+ return ret;
+#else
+ bool ret = mm_delete_heap(ptr);
+ return ret;
+#endif
+ }
+
+ entry = entry->MemoryNext;
+ }
+
+ return false;
+ }
+
+ /// @brief UserProcess name getter.
+ const Char* UserProcess::GetProcessName() noexcept
+ {
+ return this->Name;
+ }
+
+ /// @brief UserProcess user getter.
+ const User* UserProcess::GetOwner() noexcept
+ {
+ return this->Owner;
+ }
+
+ /// @brief UserProcess status getter.
+ const ProcessStatusKind& UserProcess::GetStatus() noexcept
+ {
+ return this->Status;
+ }
+
+ /***********************************************************************************/
+
+ /**
+ @brief Affinity is the time slot allowed for the process.
+ */
+ const AffinityKind& UserProcess::GetAffinity() noexcept
+ {
+ return this->Affinity;
+ }
+
+ /**
+ @brief Standard exit proc.
+ */
+ void UserProcess::Exit(const Int32& exit_code)
+ {
+ this->Status = ProcessStatusKind::kDead;
+
+ fLastExitCode = exit_code;
+ cLastExitCode = exit_code;
+
+ //! Delete image if not done already.
+ if (this->Image && mm_is_valid_heap(this->Image))
+ mm_delete_heap(this->Image);
+
+ if (this->StackFrame && mm_is_valid_heap(this->StackFrame))
+ mm_delete_heap((VoidPtr)this->StackFrame);
+
+ this->Image = nullptr;
+ this->StackFrame = nullptr;
+
+ if (this->Kind == kDLLKind)
+ {
+ Bool success = false;
+ rtl_fini_dll(this, this->DLLPtr, &success);
+
+ if (success)
+ {
+ this->DLLPtr = nullptr;
+ }
+ }
+
+ if (this->StackReserve)
+ delete[] this->StackReserve;
+
+ this->ProcessId = 0;
+
+ if (this->ProcessId > 0)
+ UserProcessScheduler::The().Remove(this->ProcessId);
+ }
+
+ /// @brief Add process to list.
+ /// @param process the process *Ref* class.
+ /// @return the process index inside the team.
+ SizeT UserProcessScheduler::Add(UserProcess process)
+ {
+ if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam)
+ return 0;
+
+#ifdef __ZKA_AMD64__
+ process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3());
+#endif // __ZKA_AMD64__
+
+ process.Status = ProcessStatusKind::kStarting;
+
+ process.StackFrame = (HAL::StackFramePtr)mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes);
+
+ if (!process.StackFrame)
+ {
+ process.Crash();
+ return -kErrorProcessFault;
+ }
+
+ // Create heap according to type of process.
+ if (process.Kind == UserProcess::kDLLKind)
+ {
+ process.DLLPtr = rtl_init_dll(&process);
+ }
+
+ if (!process.Image)
+ {
+ if (process.Kind != UserProcess::kDLLKind)
+ {
+ process.Crash();
+ return -kErrorProcessFault;
+ }
+ }
+
+ // get preferred stack size by app.
+ const auto cMaxStackSize = process.StackSize;
+ process.StackReserve = (UInt8*)mm_new_heap(sizeof(UInt8) * cMaxStackSize, Yes, Yes);
+
+ if (!process.StackReserve)
+ {
+ mm_delete_heap(process.StackFrame);
+ process.StackFrame = nullptr;
+ return -kErrorProcessFault;
+ }
+
+ ++mTeam.mProcessAmount;
+
+ process.ProcessId = mTeam.mProcessAmount;
+ process.Status = ProcessStatusKind::kRunning;
+
+ // avoid the pitfalls of moving process.
+ auto ret_pid = process.ProcessId;
+
+ mTeam.AsArray()[process.ProcessId] = move(process);
+
+ return ret_pid;
+ }
+
+ /***********************************************************************************/
+
+ UserProcessScheduler& UserProcessScheduler::The()
+ {
+ MUST_PASS(cProcessScheduler);
+ return *cProcessScheduler;
+ }
+
+ /***********************************************************************************/
+
+ /// @brief Remove process from list.
+ /// @param process_id process slot inside team.
+ /// @retval true process was removed.
+ /// @retval false process doesn't exist in team.
+
+ /***********************************************************************************/
+
+ Bool UserProcessScheduler::Remove(ProcessID process_id)
+ {
+ // check if process is within range.
+ if (process_id > mTeam.AsArray().Count())
+ return false;
+
+ mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead;
+ --mTeam.mProcessAmount;
+
+ return true;
+ }
+
+ /***********************************************************************************/
+
+ /// @brief Run User scheduler object.
+ /// @return Process executed within team.
+
+ /***********************************************************************************/
+
+ SizeT UserProcessScheduler::Run() noexcept
+ {
+ SizeT process_index = 0; //! we store this guy to tell the scheduler how many
+ //! things we have scheduled.
+
+ for (; process_index < mTeam.AsArray().Capacity(); ++process_index)
+ {
+ kcout << "Grabbing available process in team...\r";
+
+ auto& process = mTeam.AsArray()[process_index];
+
+ //! check if process needs to be scheduled.
+ if (UserProcessHelper::CanBeScheduled(process))
+ {
+ kcout << process.Name << ": will be runned.\r";
+
+ // Set current process header.
+ this->CurrentProcess() = process;
+
+ process.PTime = static_cast<Int32>(process.Affinity);
+
+ // tell helper to find a core to schedule on.
+ if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame,
+ process.ProcessId))
+ {
+ process.Crash();
+ continue;
+ }
+ }
+ }
+
+ kcout << "Scheduled Process Count: " << number(process_index) << endl;
+
+ return process_index;
+ }
+
+ /// @brief Gets the current scheduled team.
+ /// @return
+ UserProcessTeam& UserProcessScheduler::CurrentTeam()
+ {
+ return mTeam;
+ }
+
+ /// @internal
+
+ /// @brief Gets current running process.
+ /// @return
+ Ref<UserProcess>& UserProcessScheduler::CurrentProcess()
+ {
+ return mTeam.AsRef();
+ }
+
+ /// @brief Current proccess id getter.
+ /// @return UserProcess ID integer.
+ PID& UserProcessHelper::TheCurrentPID()
+ {
+ kcout << "UserProcessHelper::TheCurrentPID: Leaking ProcessId...\r";
+ return cProcessScheduler->CurrentProcess().Leak().ProcessId;
+ }
+
+ /// @brief Check if process can be schedulded.
+ /// @param process the process reference.
+ /// @retval true can be schedulded.
+ /// @retval false cannot be schedulded.
+ bool UserProcessHelper::CanBeScheduled(const UserProcess& process)
+ {
+ kcout << "Checking process status...\r";
+
+ if (process.Status == ProcessStatusKind::kFrozen ||
+ process.Status == ProcessStatusKind::kDead)
+ return No;
+
+ if (!process.Image &&
+ process.Kind == UserProcess::kExeKind)
+ return No;
+
+ return Yes;
+ }
+
+ /**
+ * @brief Scheduler helper class.
+ */
+
+ EXTERN
+ HardwareThreadScheduler* cHardwareThreadScheduler;
+
+ SizeT UserProcessHelper::StartScheduling()
+ {
+ if (!cHardwareThreadScheduler)
+ {
+ cHardwareThreadScheduler = mm_new_class<HardwareThreadScheduler>();
+ MUST_PASS(cHardwareThreadScheduler);
+ }
+
+ if (!cProcessScheduler)
+ {
+ cProcessScheduler = mm_new_class<UserProcessScheduler>();
+ MUST_PASS(cProcessScheduler);
+ }
+
+ SizeT ret = cProcessScheduler->Run();
+ return ret;
+ }
+
+ /**
+ * \brief Does a context switch in a CPU.
+ * \param the_stack the stackframe of the running app.
+ * \param new_pid the process's PID.
+ */
+
+ Bool UserProcessHelper::Switch(VoidPtr image_ptr, UInt8* stack, HAL::StackFramePtr frame_ptr, const PID& new_pid)
+ {
+ if (!stack || !frame_ptr || !image_ptr || new_pid < 0)
+ return No;
+
+ for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index)
+ {
+ if (HardwareThreadScheduler::The()[index].Leak()->Kind() == kInvalidHart)
+ continue;
+
+ if (HardwareThreadScheduler::The()[index].Leak()->Kind() !=
+ ThreadKind::kHartBoot &&
+ HardwareThreadScheduler::The()[index].Leak()->Kind() !=
+ ThreadKind::kHartSystemReserved)
+ {
+ PID prev_pid = UserProcessHelper::TheCurrentPID();
+ UserProcessHelper::TheCurrentPID() = new_pid;
+
+ auto prev_ptime = HardwareThreadScheduler::The()[index].Leak()->fPTime;
+ HardwareThreadScheduler::The()[index].Leak()->fPTime = UserProcessScheduler::The().CurrentTeam().AsArray()[new_pid].ProcessId;
+ Bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr);
+
+ if (!ret)
+ {
+ HardwareThreadScheduler::The()[index].Leak()->fPTime = prev_ptime;
+ UserProcessHelper::TheCurrentPID() = prev_pid;
+
+ continue;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /// @brief this checks if any process is on the team.
+ UserProcessScheduler::operator bool()
+ {
+ return mTeam.AsArray().Count() > 0;
+ }
+
+ /// @brief this checks if no process is on the team.
+ bool UserProcessScheduler::operator!()
+ {
+ return mTeam.AsArray().Count() == 0;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/UserProcessTeam.cxx b/dev/zka/src/UserProcessTeam.cxx
new file mode 100644
index 00000000..bb5726f7
--- /dev/null
+++ b/dev/zka/src/UserProcessTeam.cxx
@@ -0,0 +1,38 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/***********************************************************************************/
+/// @file UserProcessTeam.cxx
+/// @brief UserProcess teams implementation.
+/***********************************************************************************/
+
+#include <KernelKit/UserProcessScheduler.hxx>
+
+namespace Kernel
+{
+ /// @brief UserProcess list array getter.
+ /// @return The list of process to schedule.
+ Array<UserProcess, kSchedProcessLimitPerTeam>& UserProcessTeam::AsArray()
+ {
+ return mProcessList;
+ }
+
+ /// @brief Get team ID.
+ /// @return The team's ID.
+ ProcessID& UserProcessTeam::Id() noexcept
+ {
+ return mTeamId;
+ }
+
+ /// @brief Current process getter.
+ /// @return The current process header.
+ Ref<UserProcess>& UserProcessTeam::AsRef()
+ {
+ return mCurrentProcess;
+ }
+} // namespace Kernel
+
+// last rev 05-03-24
diff --git a/dev/zka/src/UserThreadScheduler.cxx b/dev/zka/src/UserThreadScheduler.cxx
new file mode 100644
index 00000000..3fc9aee4
--- /dev/null
+++ b/dev/zka/src/UserThreadScheduler.cxx
@@ -0,0 +1,49 @@
+/*
+ * ========================================================
+ *
+ * newoskrnl
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/String.hxx>
+#include <CFKit/Property.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+namespace Kernel
+{
+ /// \brief UserProcess thread information header.
+ struct USER_THREAD_BLOCK final
+ {
+ STATIC constexpr SizeT cMaxLen = 256;
+
+ Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"};
+ ProcessStatusKind fThreadStatus;
+ Int64 fThreadID;
+ UserProcessPtr fProcess{nullptr};
+ VoidPtr fCode{nullptr};
+ VoidPtr fStack{nullptr};
+ VoidPtr fData{nullptr};
+
+ Void Exit() noexcept
+ {
+ this->fThreadStatus = ProcessStatusKind::kKilled;
+ }
+
+ VoidPtr GetStack() noexcept
+ {
+ return fStack;
+ }
+
+ VoidPtr GetData() noexcept
+ {
+ return fData;
+ }
+
+ VoidPtr GetPC() noexcept
+ {
+ return fCode;
+ }
+ };
+} // namespace Kernel
diff --git a/dev/zka/src/Utils.cxx b/dev/zka/src/Utils.cxx
new file mode 100644
index 00000000..8ecfd805
--- /dev/null
+++ b/dev/zka/src/Utils.cxx
@@ -0,0 +1,212 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Utils.hxx>
+#include <KernelKit/DebugOutput.hxx>
+
+namespace Kernel
+{
+ Int rt_string_cmp(const Char* src, const Char* cmp, Size size)
+ {
+ if (!cmp ||
+ !src)
+ return 1;
+
+ Int32 counter = 0;
+
+ for (Size index = 0; index < size; ++index)
+ {
+ if (src[index] != cmp[index])
+ ++counter;
+ }
+
+ return counter;
+ }
+
+ void rt_zero_memory(voidPtr pointer, Size len)
+ {
+ rt_set_memory(pointer, 0, len);
+ }
+
+ Size rt_string_len(const Char* str, SizeT _len)
+ {
+ Size len{0};
+ while (str[len] != '\0')
+ {
+ if (len > _len)
+ {
+ return 0;
+ }
+
+ len++;
+ }
+
+ return len;
+ }
+
+ Size rt_string_len(const Char* ptr)
+ {
+ if (*ptr == 0)
+ return 0;
+
+ SizeT cnt = 0;
+
+ while (ptr[cnt] != (Char)0)
+ {
+ cnt++;
+ }
+
+ return cnt;
+ }
+
+ voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len)
+ {
+ if (!src || len < 1)
+ return nullptr;
+
+ UInt32* start = reinterpret_cast<UInt32*>(src);
+
+ while (len)
+ {
+ *start = value;
+ ++start;
+ --len;
+ }
+
+ return (voidPtr)start;
+ }
+
+ Int rt_move_memory(const voidPtr src, voidPtr dst, Size len)
+ {
+ if (len < 1)
+ return -2;
+ if (!src || !dst)
+ return -1;
+
+ char* srcChr = reinterpret_cast<Char*>(src);
+ char* dstChar = reinterpret_cast<Char*>(dst);
+ Size index = 0;
+
+ while (index < len)
+ {
+ dstChar[index] = srcChr[index];
+ srcChr[index] = 0;
+
+ ++index;
+ }
+
+ return 0;
+ }
+
+ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len)
+ {
+ if (len < 1)
+ return -2;
+
+ char* srcChr = reinterpret_cast<char*>(src);
+ char* dstChar = reinterpret_cast<char*>(dst);
+ Size index = 0;
+
+ while (index < len)
+ {
+ dstChar[index] = srcChr[index];
+ ++index;
+ }
+
+ return index;
+ }
+
+ const Char* alloc_string(const Char* text)
+ {
+ if (!text)
+ return nullptr;
+
+ const Char* string = new Char[rt_string_len(text)];
+ if (!string)
+ return nullptr;
+
+ voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char*>(text));
+ voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char*>(string));
+ rt_copy_memory(vText, vStr, rt_string_len(text));
+
+ return string;
+ }
+
+ Int rt_to_uppercase(Int character)
+ {
+ if (character >= 'a' && character <= 'z')
+ return character - 0x20;
+
+ return character;
+ }
+
+ Int rt_to_lower(Int character)
+ {
+ if (character >= 'A' && character <= 'Z')
+ return character + 0x20;
+
+ return character;
+ }
+
+ bool rt_to_string(Char* str, Int limit, Int base)
+ {
+ if (limit == 0)
+ return false;
+
+ Int copy_limit = limit;
+ Int cnt = 0;
+ Int ret = base;
+
+ while (limit != 1)
+ {
+ ret = ret % 10;
+ str[cnt] = ret;
+
+ ++cnt;
+ --limit;
+ --ret;
+ }
+
+ str[copy_limit] = '\0';
+ return true;
+ }
+
+ Boolean is_space(Char chr)
+ {
+ return chr == ' ';
+ }
+
+ Boolean is_newln(Char chr)
+ {
+ return chr == '\n';
+ }
+
+ voidPtr rt_string_in_string(const Char* in, const Char* needle)
+ {
+ for (SizeT i = 0; i < rt_string_len(in); ++i)
+ {
+ if (rt_string_cmp(in + i, needle, rt_string_len(needle)) == 0)
+ return reinterpret_cast<voidPtr>(const_cast<char*>(in + i));
+ }
+
+ return nullptr;
+ }
+
+ // @brief Checks for a string start at the character.
+
+ char* rt_string_has_char(char* str, const Char chr)
+ {
+ while (*str != chr)
+ {
+ ++str;
+
+ if (*str == 0)
+ return nullptr;
+ }
+
+ return str;
+ }
+} // namespace Kernel
diff --git a/dev/zka/src/Variant.cxx b/dev/zka/src/Variant.cxx
new file mode 100644
index 00000000..e988d783
--- /dev/null
+++ b/dev/zka/src/Variant.cxx
@@ -0,0 +1,31 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NewKit/Variant.hxx>
+
+namespace Kernel
+{
+ const Char* Variant::ToString()
+ {
+ switch (fKind)
+ {
+ case VariantKind::kJson:
+ return ("Class:{Json}");
+ case VariantKind::kString:
+ return ("Class:{String}");
+ case VariantKind::kBlob:
+ return ("Class:{Blob}");
+ default:
+ return ("Class:{Null}");
+ }
+ }
+
+ /// @brief Leak variant's instance.
+ VoidPtr Variant::Leak()
+ {
+ return fPtr;
+ }
+} // namespace Kernel