From 05f085c9055fa5bd13bdba40fc40fb3f00d69fab Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 26 Oct 2024 07:59:10 +0200 Subject: IMP: Fixes and improvements. Signed-off-by: Amlal --- dev/SCIKit/CompilerHint.h | 23 +++ dev/SCIKit/Foundation.h | 249 +++++++++++++++++++++++++++ dev/SCIKit/LPC.h | 48 ++++++ dev/SCIKit/ReadMe.md | 5 + dev/SCIKit/build.json | 21 +++ dev/SCIKit/makefile | 12 ++ dev/SCIKit/scm-design.drawio | 28 +++ dev/SCIKit/src/Foundation.cc | 45 +++++ dev/sci/ReadMe.md | 5 - dev/sci/makefile | 12 -- dev/sci/sci.json | 21 --- dev/sci/sci_base.h | 281 ------------------------------- dev/sci/sci_hint.h | 23 --- dev/sci/sci_lpc.h | 48 ------ dev/sci/scm-design.drawio | 28 --- dev/sci/source_deploy.xml | 6 - dev/sci/src/sci_mm.cc | 45 ----- dev/zba/src/BootFileReader.cc | 2 +- dev/zba/src/BootString.cc | 2 +- dev/zba/src/BootTextWriter.cc | 2 +- dev/zba/src/BootThread.cc | 195 +++++++++++++++++++++ dev/zba/src/HEL/AMD64/BootAHCI.cc | 4 +- dev/zba/src/HEL/AMD64/BootATA.cc | 2 +- dev/zba/src/HEL/AMD64/BootMain.cc | 45 +++-- dev/zba/src/Thread.cc | 195 --------------------- dev/zka/CFKit/GUIDWizard.h | 4 +- dev/zka/CFKit/LoaderUtils.h | 55 ------ dev/zka/CFKit/Utils.h | 55 ++++++ dev/zka/HALKit/AMD64/HalCPU.cc | 4 +- dev/zka/HALKit/AMD64/HalDebugPort.cc | 2 +- dev/zka/HALKit/AMD64/HalPagingMgr.cc | 2 +- dev/zka/HALKit/AMD64/HalTimer.cc | 4 +- dev/zka/HALKit/AMD64/Storage/AHCI.cc | 2 +- dev/zka/HALKit/AMD64/Storage/ATA-DMA.cc | 2 +- dev/zka/HALKit/AMD64/Storage/ATA-PIO.cc | 2 +- dev/zka/HALKit/ARM64/HalPagingMgr.cc | 2 +- dev/zka/HALKit/ARM64/HalTimer.cc | 2 +- dev/zka/HALKit/ARM64/Storage/HalFlash.cc | 2 +- dev/zka/src/DriveMgr.cc | 2 +- dev/zka/src/ErrorOr.cc | 2 +- dev/zka/src/GUIDWizard.cc | 38 ++--- dev/zka/src/HardwareThreadScheduler.cc | 2 +- dev/zka/src/Heap.cc | 2 +- dev/zka/src/IPEFDLLObject.cc | 2 +- dev/zka/src/NeFS+IO.cc | 2 +- dev/zka/src/Stream.cc | 2 +- dev/zka/src/ThreadLocalStorage.cc | 2 +- dev/zka/src/Timer.cc | 2 +- dev/zka/src/User.cc | 2 +- dev/zka/src/UserProcessScheduler.cc | 4 +- dev/zka/src/UserProcessTeam.cc | 2 +- tools/Common.h | 14 ++ tools/Framework.h | 13 ++ tools/common_zka.h | 7 - tools/framework.h | 13 -- tools/make_framework.json | 2 +- tools/make_zxd.json | 13 -- tools/src/MakeFramework.cc | 42 +++++ tools/src/make_framework.cc | 42 ----- tools/src/make_zxd.cc | 72 -------- tools/zxd.h | 50 ------ zka-dev.files | 26 ++- zka-dev.includes | 3 + 63 files changed, 839 insertions(+), 1007 deletions(-) create mode 100644 dev/SCIKit/CompilerHint.h create mode 100644 dev/SCIKit/Foundation.h create mode 100644 dev/SCIKit/LPC.h create mode 100644 dev/SCIKit/ReadMe.md create mode 100644 dev/SCIKit/build.json create mode 100644 dev/SCIKit/makefile create mode 100644 dev/SCIKit/scm-design.drawio create mode 100644 dev/SCIKit/src/Foundation.cc delete mode 100644 dev/sci/ReadMe.md delete mode 100644 dev/sci/makefile delete mode 100644 dev/sci/sci.json delete mode 100644 dev/sci/sci_base.h delete mode 100644 dev/sci/sci_hint.h delete mode 100644 dev/sci/sci_lpc.h delete mode 100644 dev/sci/scm-design.drawio delete mode 100644 dev/sci/source_deploy.xml delete mode 100644 dev/sci/src/sci_mm.cc create mode 100644 dev/zba/src/BootThread.cc delete mode 100644 dev/zba/src/Thread.cc delete mode 100644 dev/zka/CFKit/LoaderUtils.h create mode 100644 dev/zka/CFKit/Utils.h create mode 100644 tools/Common.h create mode 100644 tools/Framework.h delete mode 100644 tools/common_zka.h delete mode 100644 tools/framework.h delete mode 100644 tools/make_zxd.json create mode 100644 tools/src/MakeFramework.cc delete mode 100644 tools/src/make_framework.cc delete mode 100644 tools/src/make_zxd.cc delete mode 100644 tools/zxd.h diff --git a/dev/SCIKit/CompilerHint.h b/dev/SCIKit/CompilerHint.h new file mode 100644 index 00000000..b550bac5 --- /dev/null +++ b/dev/SCIKit/CompilerHint.h @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __SCI_HINT_H__ +#define __SCI_HINT_H__ + +#pragma compiler(hint_manifest) + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut + +#endif // ifndef __SCI_HINT_H__ diff --git a/dev/SCIKit/Foundation.h b/dev/SCIKit/Foundation.h new file mode 100644 index 00000000..d0ba87a1 --- /dev/null +++ b/dev/SCIKit/Foundation.h @@ -0,0 +1,249 @@ +/* ------------------------------------------- + +Copyright ZKA Web Services Co. + +File: sci_base.h +Purpose: SCI core header file (C++ only). + +------------------------------------------- */ + +#ifndef SCI_BASE_H +#define SCI_BASE_H + +#define ATTRIBUTE(X) __attribute__((X)) +#define IMPORT_CXX extern "C++" +#define IMPORT_C extern "C" + +typedef bool Bool; +typedef void Void; + +typedef __UINT64_TYPE__ UInt64; +typedef __UINT32_TYPE__ UInt32; +typedef __UINT16_TYPE__ UInt16; +typedef __UINT8_TYPE__ UInt8; + +typedef __SIZE_TYPE__ SizeT; + +typedef __INT64_TYPE__ SInt64; +typedef __INT32_TYPE__ SInt32; +typedef __INT16_TYPE__ SInt16; +typedef __INT8_TYPE__ SInt8; + +typedef void* VoidPtr; +typedef __UINTPTR_TYPE__ UIntPtr; +typedef char Char; + +#include +#include + +// ------------------------------------------------------------------------------------------ // +/// @brief Handle Type Definitions. +// ------------------------------------------------------------------------------------------ // + +typedef VoidPtr SCIObject; + +typedef SCIObject DLLObject; +typedef SCIObject IOObject; +typedef SCIObject SCMObject; +typedef SCIObject ThreadObject; +typedef SCIObject SocketObject; +typedef SCIObject ShellObject; +typedef SCIObject UIObject; + +// ------------------------------------------------------------------------------------------ // +/// @brief Dynamic Loader API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Get function which is part of the DLL. +/// @param symbol the symbol to look for +/// @param dll_handle the DLL handle. +/// @return the proc pointer. +IMPORT_C SCIObject LdrGetDLLSymbolFromHandle(_Input const Char* symbol, _Input SCIObject dll_handle); + +/// @brief Open DLL handle. +/// @param path +/// @param drv +/// @return +IMPORT_C SCIObject LdrOpenDLLHandle(_Input const Char* path, _Input const Char* drive_letter); + +/// @brief Close DLL handle +/// @param dll_handle +/// @return +IMPORT_C Void LdrCloseDLLHandle(_Input SCIObject* dll_handle); + +// ------------------------------------------------------------------------------------------ // +// File API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Opens a file from a drive. +/// @param fs_path the filesystem path. +/// @param drive_letter drive name, use NULL to use default one. +/// @return the file descriptor of the file. +IMPORT_C SCIObject IoOpenFile(const Char* fs_path, const Char* drive_letter); + +/// @brief Closes a file and flushes its content. +/// @param file_desc the file descriptor. +/// @return void. +IMPORT_C Void IoCloseFile(_Input SCIObject file_desc); + +/// @brief Write data to a file. +/// @param file_desc the file descriptor. +/// @param out_data the data to write. +/// @param sz_data the size of the data to write. +/// @return the number of bytes written. +IMPORT_C UInt32 IoWriteFile(_Input SCIObject file_desc, _Output VoidPtr out_data, SizeT sz_data); + +/// @brief Read data from a file. +/// @param file_desc the file descriptor. +/// @param out_data the data to read. +/// @param sz_data the size of the data to read. +IMPORT_C UInt32 IoReadFile(_Input SCIObject file_desc, _Output VoidPtr* out_data, SizeT sz_data); + +/// @brief Rewind the file pointer to the beginning of the file. +/// @param file_desc the file descriptor. +/// @return the number of bytes read. +IMPORT_C UInt64 IoRewindFile(_Input SCIObject file_desc); + +/// @brief Tell the current position of the file pointer. +/// @param file_desc the file descriptor. +/// @return the current position of the file pointer. +IMPORT_C UInt64 IoTellFile(_Input SCIObject file_desc); + +/// @brief Seek file offset from file descriptor. +IMPORT_C UInt64 IoSeekFile(_Input SCIObject file_desc, UInt64 file_offset); + +// ------------------------------------------------------------------------ +// TLS API. +// ------------------------------------------------------------------------ + +/// @brief Installs the Thread Information Block and Global Information Block inside the current process. +/// @param void. +/// @return > 0 error ocurred or already present, = 0 success. +IMPORT_C UInt32 RtlTlsInstall(Void); + +// ------------------------------------------------------------------------ +// Memory Management API. +// ------------------------------------------------------------------------ + +/// @brief Creates a new heap from the process's address space. +/// @param len the length of it. +/// @param flags the flags of it. +/// @return heap pointer. +IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); + +/// @brief Destroys the pointer +/// @param heap the heap itself. +/// @return void. +IMPORT_C Void MmDestroyHeap(_Input VoidPtr heap); + +/// @brief Change protection flags of a memory region. +IMPORT_C Void MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); + +/// @brief Change protection flags of a memory region. +IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); + +/// @brief Fill memory region with CRC32. +IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); + +/// @brief Copy memory region. +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); + +/// @brief Fill memory region. +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); + +// ------------------------------------------------------------------------ +// Error handling API. +// ------------------------------------------------------------------------ + +IMPORT_C SInt32 ErrGetLastError(Void); + +// ------------------------------------------------------------------------ +// Threading API. +// ------------------------------------------------------------------------ + +/// @brief Exit the current thread. +/// @param exit_code the exit code. +IMPORT_C Void ThrExitCurrentThread(_Input SInt32 exit_code); + +/// @brief Exit the main thread. +/// @param exit_code the exit code. +IMPORT_C Void ThrExitMainThread(_Input SInt32 exit_code); + +/// @brief Exit a thread. +/// @param thread the thread to exit. +/// @param exit_code the exit code. +IMPORT_C Void ThrExitThread(_Input ThreadObject thread, _Input SInt32 exit_code); + +/// @brief Thread procedure function type. +typedef Void (*ThreadProc)(Void); + +/// @brief Creates a thread. +/// @param procedure the thread procedure. +/// @param argument_count number of arguments inside that thread. +/// @param flags Thread flags. +/// @return the thread object. +IMPORT_C ThreadObject ThrCreateThread(ThreadProc procedure, SInt32 argument_count, SInt32 flags); + +/// @brief Yields the current thread. +/// @param thread the thread to yield. +IMPORT_C Void ThrYieldThread(Void); + +/// @brief Joins a thread. +/// @param thread the thread to join. +IMPORT_C Void ThrJoinThread(Void); + +/// @brief Detach sa thread. +/// @param thread the thread to detach. +IMPORT_C Void ThrDetachThread(Void); + +// ------------------------------------------------------------------------ +// Drive Management API. +// ------------------------------------------------------------------------ + +/// @brief Get the default drive letter. +/// @param void. +/// @return the drive letter. +IMPORT_C Char* DrvGetDefaultDriveLetter(Void); + +/// @brief Get the drive letter from a path. +/// @param path the path. +/// @return the drive letter. +IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); + +/// @brief Get a mounted drive from a letter. +/// @param letter the letter (A..Z). +/// @return the drive object. +IMPORT_C SCIObject DrvGetMountedDrive(_Input const Char letter); + +/// @brief Mount a drive. +/// @param path the path to mount. +/// @param letter the letter to mount. +IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); + +/// @brief Unmount a drive. +/// @param letter the letter to unmount. +IMPORT_C Void DrvUnmountDrive(_Input const Char letter); + +// ------------------------------------------------------------------------ +// Event handling API, use to listen to OS specific events. +// ------------------------------------------------------------------------ + +/// @brief Add an event listener. +/// @param event_name the event name. +/// @param listener the listener to add. +/// @return the event listener. +IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input SCIObject listener); + +/// @brief Remove an event listener. +/// @param event_name the event name. +/// @param listener the listener to remove. +/// @return the event listener. +IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input SCIObject listener); + +/// @brief Dispatch an event. +/// @param event_name the event name. +/// @param event_data the event data. +/// @return the event data. +IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); + +#endif // ifndef SCI_BASE_H diff --git a/dev/SCIKit/LPC.h b/dev/SCIKit/LPC.h new file mode 100644 index 00000000..c634b790 --- /dev/null +++ b/dev/SCIKit/LPC.h @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#define ErrLocalIsOk() (kLastError == kErrorSuccess) +#define ErrLocalFailed() (kLastError != kErrorSuccess) +#define ErrLocal() (kLastError) + +typedef SInt32 ErrObject; + +inline constexpr ErrObject kErrorSuccess = 0; +inline constexpr ErrObject kErrorExecutable = 33; +inline constexpr ErrObject kErrorExecutableLib = 34; +inline constexpr ErrObject kErrorFileNotFound = 35; +inline constexpr ErrObject kErrorDirectoryNotFound = 36; +inline constexpr ErrObject kErrorDiskReadOnly = 37; +inline constexpr ErrObject kErrorDiskIsFull = 38; +inline constexpr ErrObject kErrorProcessFault = 39; +inline constexpr ErrObject kErrorSocketHangUp = 40; +inline constexpr ErrObject kErrorThreadLocalStorage = 41; +inline constexpr ErrObject kErrorMath = 42; +inline constexpr ErrObject kErrorNoNetwork = 43; +inline constexpr ErrObject kErrorHeapOutOfMemory = 44; +inline constexpr ErrObject kErrorNoSuchDisk = 45; +inline constexpr ErrObject kErrorFileExists = 46; +inline constexpr ErrObject kErrorFormatFailed = 47; +inline constexpr ErrObject kErrorNetworkTimeout = 48; +inline constexpr ErrObject kErrorInternal = 49; +inline constexpr ErrObject kErrorForkAlreadyExists = 50; +inline constexpr ErrObject kErrorOutOfTeamSlot = 51; +inline constexpr ErrObject kErrorHeapNotPresent = 52; +inline constexpr ErrObject kErrorNoEntrypoint = 53; +inline constexpr ErrObject kErrorDiskIsCorrupted = 54; +inline constexpr ErrObject kErrorDisk = 55; +inline constexpr ErrObject kErrorInvalidData = 56; +inline constexpr ErrObject kErrorAsync = 57; +inline constexpr ErrObject kErrorNonBlocking = 58; +inline constexpr ErrObject kErrorIPC = 59; +inline constexpr ErrObject kErrorSign = 60; +inline constexpr ErrObject kErrorInvalidCreds = 61; +inline constexpr ErrObject kErrorUnimplemented = 0; + +/// @brief The last error reported by the system to the process. +IMPORT_C ErrObject kLastError; diff --git a/dev/SCIKit/ReadMe.md b/dev/SCIKit/ReadMe.md new file mode 100644 index 00000000..f3b5a156 --- /dev/null +++ b/dev/SCIKit/ReadMe.md @@ -0,0 +1,5 @@ +# ZKA's SCI. + +System Call and Component Interface, used maninly to communicate with Kernel and registered objects. + +###### (c) ZKA Web Services Co, all rights reserved. diff --git a/dev/SCIKit/build.json b/dev/SCIKit/build.json new file mode 100644 index 00000000..104be044 --- /dev/null +++ b/dev/SCIKit/build.json @@ -0,0 +1,21 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../"], + "sources_path": ["src/*.cc"], + "output_name": "sci.dll", + "compiler_flags": [ + "-fPIC", + "-ffreestanding", + "-shared", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17" + ], + "cpp_macros": [ + "__SCI_IMPL__", + "cSCIVersion=0x0100", + "cSCIVersionHighest=0x0100", + "cSCIVersionLowest=0x0100" + ] +} diff --git a/dev/SCIKit/makefile b/dev/SCIKit/makefile new file mode 100644 index 00000000..f18fbeff --- /dev/null +++ b/dev/SCIKit/makefile @@ -0,0 +1,12 @@ +###################### +# (C) ZKA +# XPCOM/SCI kit makefile. +###################### + +CC=g++ +FLAGS=-I../ -shared -fPIC -D__ZKA_SYMS__ +OUTPUT=sci.dll + +.PHONY: build-sci +build-sci: + $(CC) $(wildcard .cc) $(FLAGS) -o $(OUTPUT) diff --git a/dev/SCIKit/scm-design.drawio b/dev/SCIKit/scm-design.drawio new file mode 100644 index 00000000..22bcace6 --- /dev/null +++ b/dev/SCIKit/scm-design.drawio @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/SCIKit/src/Foundation.cc b/dev/SCIKit/src/Foundation.cc new file mode 100644 index 00000000..93104a45 --- /dev/null +++ b/dev/SCIKit/src/Foundation.cc @@ -0,0 +1,45 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#include + +/// @file sci_base.cc +/// @brief Base Memory Manager functions for SCI.dll + +/// @brief Copy memory region. +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) +{ + if (!len || + !dest || + !src) + { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) + { + ((Char*)dest)[i] = ((Char*)src)[i]; + } + + return dest; +} + +/// @brief Fill memory region with **value**. +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) +{ + if (!len || + !dest) + { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) + { + ((Char*)dest)[i] = value; + } + + return dest; +} diff --git a/dev/sci/ReadMe.md b/dev/sci/ReadMe.md deleted file mode 100644 index f3b5a156..00000000 --- a/dev/sci/ReadMe.md +++ /dev/null @@ -1,5 +0,0 @@ -# ZKA's SCI. - -System Call and Component Interface, used maninly to communicate with Kernel and registered objects. - -###### (c) ZKA Web Services Co, all rights reserved. diff --git a/dev/sci/makefile b/dev/sci/makefile deleted file mode 100644 index f18fbeff..00000000 --- a/dev/sci/makefile +++ /dev/null @@ -1,12 +0,0 @@ -###################### -# (C) ZKA -# XPCOM/SCI kit makefile. -###################### - -CC=g++ -FLAGS=-I../ -shared -fPIC -D__ZKA_SYMS__ -OUTPUT=sci.dll - -.PHONY: build-sci -build-sci: - $(CC) $(wildcard .cc) $(FLAGS) -o $(OUTPUT) diff --git a/dev/sci/sci.json b/dev/sci/sci.json deleted file mode 100644 index 104be044..00000000 --- a/dev/sci/sci.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["../"], - "sources_path": ["src/*.cc"], - "output_name": "sci.dll", - "compiler_flags": [ - "-fPIC", - "-ffreestanding", - "-shared", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17" - ], - "cpp_macros": [ - "__SCI_IMPL__", - "cSCIVersion=0x0100", - "cSCIVersionHighest=0x0100", - "cSCIVersionLowest=0x0100" - ] -} diff --git a/dev/sci/sci_base.h b/dev/sci/sci_base.h deleted file mode 100644 index 0860e72f..00000000 --- a/dev/sci/sci_base.h +++ /dev/null @@ -1,281 +0,0 @@ -/* ------------------------------------------- - -Copyright ZKA Web Services Co. - -File: sci_base.h -Purpose: SCI core header file (C++ only). - -------------------------------------------- */ - -#ifndef __SCI_BASE_H__ -#define __SCI_BASE_H__ - -#define ATTRIBUTE(X) __attribute__((X)) -#define IMPORT_XPCOM extern "XPCOM" -#define IMPORT_CXX extern "C++" -#define IMPORT_C extern "C" - -typedef bool Bool; -typedef void Void; - -typedef __UINT64_TYPE__ UInt64; -typedef __UINT32_TYPE__ UInt32; -typedef __UINT16_TYPE__ UInt16; -typedef __UINT8_TYPE__ UInt8; - -typedef __SIZE_TYPE__ SizeT; - -typedef __INT64_TYPE__ SInt64; -typedef __INT32_TYPE__ SInt32; -typedef __INT16_TYPE__ SInt16; -typedef __INT8_TYPE__ SInt8; - -typedef void* VoidPtr; -typedef __UINTPTR_TYPE__ UIntPtr; -typedef char Char; - -#include -#include - -// ------------------------------------------------------------------------------------------ // -/// @brief Handle Type Definitions. -// ------------------------------------------------------------------------------------------ // - -typedef VoidPtr SCIObject; - -typedef SCIObject DLLObject; -typedef SCIObject IOObject; -typedef SCIObject SCMObject; -typedef SCIObject ThreadObject; -typedef SCIObject SocketObject; -typedef SCIObject ShellObject; -typedef SCIObject UIObject; - -// ------------------------------------------------------------------------------------------ // -/// @brief Dynamic Loader API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Get function which is part of the DLL. -/// @param symbol the symbol to look for -/// @param dll_handle the DLL handle. -/// @return the proc pointer. -IMPORT_C SCIObject LdrGetDLLSymbolFromHandle(_Input const Char* symbol, _Input SCIObject dll_handle); - -/// @brief Open DLL handle. -/// @param path -/// @param drv -/// @return -IMPORT_C SCIObject LdrOpenDLLHandle(_Input const Char* path, _Input const Char* drive_letter); - -/// @brief Close DLL handle -/// @param dll_handle -/// @return -IMPORT_C Void LdrCloseDLLHandle(_Input SCIObject* dll_handle); - -// ------------------------------------------------------------------------------------------ // -// File API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Opens a file from a drive. -/// @param fs_path the filesystem path. -/// @param drive_letter drive name, use NULL to use default one. -/// @return the file descriptor of the file. -IMPORT_C SCIObject IoOpenFile(const Char* fs_path, const Char* drive_letter); - -/// @brief Closes a file and flushes its content. -/// @param file_desc the file descriptor. -/// @return void. -IMPORT_C Void IoCloseFile(_Input SCIObject file_desc); - -/// @brief Write data to a file. -/// @param file_desc the file descriptor. -/// @param out_data the data to write. -/// @param sz_data the size of the data to write. -/// @return the number of bytes written. -IMPORT_C UInt32 IoWriteFile(_Input SCIObject file_desc, _Output VoidPtr out_data, SizeT sz_data); - -/// @brief Read data from a file. -/// @param file_desc the file descriptor. -/// @param out_data the data to read. -/// @param sz_data the size of the data to read. -IMPORT_C UInt32 IoReadFile(_Input SCIObject file_desc, _Output VoidPtr* out_data, SizeT sz_data); - -/// @brief Rewind the file pointer to the beginning of the file. -/// @param file_desc the file descriptor. -/// @return the number of bytes read. -IMPORT_C UInt64 IoRewindFile(_Input SCIObject file_desc); - -/// @brief Tell the current position of the file pointer. -/// @param file_desc the file descriptor. -/// @return the current position of the file pointer. -IMPORT_C UInt64 IoTellFile(_Input SCIObject file_desc); - -/// @brief Seek file offset from file descriptor. -IMPORT_C UInt64 IoSeekFile(_Input SCIObject file_desc, UInt64 file_offset); - -// ------------------------------------------------------------------------ -// TLS API. -// ------------------------------------------------------------------------ - -/// @brief Installs the Thread Information Block and Global Information Block inside the current process. -/// @param void. -/// @return > 0 error ocurred or already present, = 0 success. -IMPORT_C UInt32 RtlTlsInstall(Void); - -#ifndef __XPCOM_IMPL__ - -// ------------------------------------------------------------------------ -// XPCOM API. -// ------------------------------------------------------------------------ - -/// @brief Allocate new XPCOM object. -/// @tparam TCLS the class type. -/// @tparam UCLSID UCLS factory class type. -/// @param uclsidOfCls UCLS factory class -/// @return TCLS interface -template -TCLS* XPCOMQueryClass(_Input UCLSID* uclsidOfCls, _Input Args&&... args); - -/// @brief Release XPCOM object. -/// @tparam TCLS the class type. -/// @param cls the class to release. -/// @return status code. -template -SInt32 XPCOMReleaseClass(_Input TCLS* cls); - -/// @brief Creates an XPCOM instance in the process. -/// @param handle_instance the XPCOM handle. -/// @param flags the XPCOM flags. -IMPORT_C SInt32 XPCOMCreateInstance(_Input UInt32 flags, _Output SCIObject* handle_instance); - -/// @brief Destroys an XPCOM instance of the process. -/// @param handle_instance the XPCOM handle. -IMPORT_C Void XPCOMDestroyInstance(_Input SCIObject handle_instance); - -#endif // !__XPCOM_IMPL__ - -// ------------------------------------------------------------------------ -// Memory Management API. -// ------------------------------------------------------------------------ - -/// @brief Creates a new heap from the process's address space. -/// @param len the length of it. -/// @param flags the flags of it. -/// @return heap pointer. -IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); - -/// @brief Destroys the pointer -/// @param heap the heap itself. -/// @return void. -IMPORT_C Void MmDestroyHeap(_Input VoidPtr heap); - -/// @brief Change protection flags of a memory region. -IMPORT_C Void MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); - -/// @brief Change protection flags of a memory region. -IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); - -/// @brief Fill memory region with CRC32. -IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); - -/// @brief Copy memory region. -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); - -/// @brief Fill memory region. -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); - -// ------------------------------------------------------------------------ -// Error handling API. -// ------------------------------------------------------------------------ - -IMPORT_C SInt32 ErrGetLastError(Void); - -// ------------------------------------------------------------------------ -// Threading API. -// ------------------------------------------------------------------------ - -/// @brief Exit the current thread. -/// @param exit_code the exit code. -IMPORT_C Void ThrExitCurrentThread(_Input SInt32 exit_code); - -/// @brief Exit the main thread. -/// @param exit_code the exit code. -IMPORT_C Void ThrExitMainThread(_Input SInt32 exit_code); - -/// @brief Exit a thread. -/// @param thread the thread to exit. -/// @param exit_code the exit code. -IMPORT_C Void ThrExitThread(_Input ThreadObject thread, _Input SInt32 exit_code); - -typedef Void (*ThreadProc)(Void); - -/// @brief Create a thread. -/// @param procedure the thread procedure. -/// @param argument_count number of arguments inside that thread. -/// @param flags Thread flags. -/// @return the thread object. -IMPORT_C ThreadObject ThrCreateThread(ThreadProc procedure, SInt32 argument_count, SInt32 flags); - -/// @brief Yield the current thread. -/// @param thread the thread to yield. -IMPORT_C Void ThrExitYieldThread(Void); - -/// @brief Join a thread. -/// @param thread the thread to join. -IMPORT_C Void ThrExitJoinThread(Void); - -/// @brief Detach a thread. -/// @param thread the thread to detach. -IMPORT_C Void ThrExitDetachThread(Void); - -// ------------------------------------------------------------------------ -// Drive Management API. -// ------------------------------------------------------------------------ - -/// @brief Get the default drive letter. -/// @param void. -/// @return the drive letter. -IMPORT_C Char* DrvGetDefaultDriveLetter(Void); - -/// @brief Get the drive letter from a path. -/// @param path the path. -/// @return the drive letter. -IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); - -/// @brief Get a mounted drive from a letter. -/// @param letter the letter (A..Z). -/// @return the drive object. -IMPORT_C SCIObject DrvGetMountedDrive(_Input const Char letter); - -/// @brief Mount a drive. -/// @param path the path to mount. -/// @param letter the letter to mount. -IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); - -/// @brief Unmount a drive. -/// @param letter the letter to unmount. -IMPORT_C Void DrvUnmountDrive(_Input const Char letter); - -// ------------------------------------------------------------------------ -// Event handling API, use to listen to OS specific events. -// ------------------------------------------------------------------------ - -/// @brief Add an event listener. -/// @param event_name the event name. -/// @param listener the listener to add. -/// @return the event listener. -IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input SCIObject listener); - -/// @brief Remove an event listener. -/// @param event_name the event name. -/// @param listener the listener to remove. -/// @return the event listener. -IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input SCIObject listener); - -/// @brief Dispatch an event. -/// @param event_name the event name. -/// @param event_data the event data. -/// @return the event data. -IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); - -#endif // ifndef __SCI_BASE_H__ diff --git a/dev/sci/sci_hint.h b/dev/sci/sci_hint.h deleted file mode 100644 index b550bac5..00000000 --- a/dev/sci/sci_hint.h +++ /dev/null @@ -1,23 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#ifndef __SCI_HINT_H__ -#define __SCI_HINT_H__ - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut - -#endif // ifndef __SCI_HINT_H__ diff --git a/dev/sci/sci_lpc.h b/dev/sci/sci_lpc.h deleted file mode 100644 index c634b790..00000000 --- a/dev/sci/sci_lpc.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#define ErrLocalIsOk() (kLastError == kErrorSuccess) -#define ErrLocalFailed() (kLastError != kErrorSuccess) -#define ErrLocal() (kLastError) - -typedef SInt32 ErrObject; - -inline constexpr ErrObject kErrorSuccess = 0; -inline constexpr ErrObject kErrorExecutable = 33; -inline constexpr ErrObject kErrorExecutableLib = 34; -inline constexpr ErrObject kErrorFileNotFound = 35; -inline constexpr ErrObject kErrorDirectoryNotFound = 36; -inline constexpr ErrObject kErrorDiskReadOnly = 37; -inline constexpr ErrObject kErrorDiskIsFull = 38; -inline constexpr ErrObject kErrorProcessFault = 39; -inline constexpr ErrObject kErrorSocketHangUp = 40; -inline constexpr ErrObject kErrorThreadLocalStorage = 41; -inline constexpr ErrObject kErrorMath = 42; -inline constexpr ErrObject kErrorNoNetwork = 43; -inline constexpr ErrObject kErrorHeapOutOfMemory = 44; -inline constexpr ErrObject kErrorNoSuchDisk = 45; -inline constexpr ErrObject kErrorFileExists = 46; -inline constexpr ErrObject kErrorFormatFailed = 47; -inline constexpr ErrObject kErrorNetworkTimeout = 48; -inline constexpr ErrObject kErrorInternal = 49; -inline constexpr ErrObject kErrorForkAlreadyExists = 50; -inline constexpr ErrObject kErrorOutOfTeamSlot = 51; -inline constexpr ErrObject kErrorHeapNotPresent = 52; -inline constexpr ErrObject kErrorNoEntrypoint = 53; -inline constexpr ErrObject kErrorDiskIsCorrupted = 54; -inline constexpr ErrObject kErrorDisk = 55; -inline constexpr ErrObject kErrorInvalidData = 56; -inline constexpr ErrObject kErrorAsync = 57; -inline constexpr ErrObject kErrorNonBlocking = 58; -inline constexpr ErrObject kErrorIPC = 59; -inline constexpr ErrObject kErrorSign = 60; -inline constexpr ErrObject kErrorInvalidCreds = 61; -inline constexpr ErrObject kErrorUnimplemented = 0; - -/// @brief The last error reported by the system to the process. -IMPORT_C ErrObject kLastError; diff --git a/dev/sci/scm-design.drawio b/dev/sci/scm-design.drawio deleted file mode 100644 index 22bcace6..00000000 --- a/dev/sci/scm-design.drawio +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dev/sci/source_deploy.xml b/dev/sci/source_deploy.xml deleted file mode 100644 index 30c64973..00000000 --- a/dev/sci/source_deploy.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - *.h - *.idl - - diff --git a/dev/sci/src/sci_mm.cc b/dev/sci/src/sci_mm.cc deleted file mode 100644 index a776fe4a..00000000 --- a/dev/sci/src/sci_mm.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#include - -/// @file sci_base.cxx -/// @brief Base Memory Manager functions for SCI.dll - -/// @brief Copy memory region. -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) -{ - if (!len || - !dest || - !src) - { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) - { - ((Char*)dest)[i] = ((Char*)src)[i]; - } - - return dest; -} - -/// @brief Fill memory region with **value**. -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) -{ - if (!len || - !dest) - { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) - { - ((Char*)dest)[i] = value; - } - - return dest; -} diff --git a/dev/zba/src/BootFileReader.cc b/dev/zba/src/BootFileReader.cc index 835fcb05..ab5d53ee 100644 --- a/dev/zba/src/BootFileReader.cc +++ b/dev/zba/src/BootFileReader.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: FileReader.cxx + File: FileReader.cc Purpose: New Boot FileReader, Read complete file and store it in a buffer. diff --git a/dev/zba/src/BootString.cc b/dev/zba/src/BootString.cc index faa7f168..6bc5cf9d 100644 --- a/dev/zba/src/BootString.cc +++ b/dev/zba/src/BootString.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: String.cxx + File: String.cc Purpose: ZBA string library Revision History: diff --git a/dev/zba/src/BootTextWriter.cc b/dev/zba/src/BootTextWriter.cc index 650484b3..e394d193 100644 --- a/dev/zba/src/BootTextWriter.cc +++ b/dev/zba/src/BootTextWriter.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: String.cxx + File: String.cc Purpose: ZBA string library Revision History: diff --git a/dev/zba/src/BootThread.cc b/dev/zba/src/BootThread.cc new file mode 100644 index 00000000..c185b367 --- /dev/null +++ b/dev/zba/src/BootThread.cc @@ -0,0 +1,195 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// External boot services symbol. +EXTERN EfiBootServices* BS; + +/// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. + +namespace Boot +{ + BThread::BThread(VoidPtr blob) + : fBlob(blob), fStartAddress(nullptr) + { + // detect the format. + const Char* blob_bytes = reinterpret_cast(fBlob); + + BTextWriter writer; + + if (!blob_bytes) + { + // failed to provide a valid pointer. + return; + } + + if (blob_bytes[0] == kMagMz0 && + blob_bytes[1] == kMagMz1) + { + LDR_EXEC_HEADER_PTR header_ptr = CFKit::ldr_find_exec_header(blob_bytes); + LDR_OPTIONAL_HEADER_PTR opt_header_ptr = CFKit::ldr_find_opt_exec_header(blob_bytes); + + if (!header_ptr || !opt_header_ptr) + return; + +#ifdef __ZKA_AMD64__ + if (header_ptr->mMachine != kPeMachineAMD64 || + header_ptr->mSignature != kPeSignature) + { + writer.Write("ZBA: Not a PE32+ executable.\r"); + return; + } +#elif defined(__ZKA_ARM64__) + if (header_ptr->mMachine != kPeMachineAMD64 || + header_ptr->mSignature != kPeSignature) + { + writer.Write("ZBA: Not a PE32+ executable.\r"); + return; + } +#endif // __ZKA_AMD64__ || __ZKA_ARM64__ + + if (opt_header_ptr->mSubsystem != kZKASubsystem) + { + writer.Write("ZBA: Not a ZKA Subsystem executable.\r"); + return; + } + + writer.Write("ZBA: PE32+ executable detected (ZKA Subsystem).\r"); + + auto numSecs = header_ptr->mNumberOfSections; + + writer.Write("ZBA: Major Linker Ver: ").Write(opt_header_ptr->mMajorLinkerVersion).Write("\r"); + writer.Write("ZBA: Minor Linker Ver: ").Write(opt_header_ptr->mMinorLinkerVersion).Write("\r"); + writer.Write("ZBA: Major Subsystem Ver: ").Write(opt_header_ptr->mMajorSubsystemVersion).Write("\r"); + writer.Write("ZBA: Minor Subsystem Ver: ").Write(opt_header_ptr->mMinorSubsystemVersion).Write("\r"); + writer.Write("ZBA: Magic: ").Write(header_ptr->mSignature).Write("\r"); + + constexpr auto cPageSize = 512; + + EfiPhysicalAddress loadStartAddress = opt_header_ptr->mImageBase; + loadStartAddress += opt_header_ptr->mBaseOfData; + + writer.Write("ZBA: ImageBase: ").Write(loadStartAddress).Write("\r"); + + auto numPages = opt_header_ptr->mSizeOfImage / cPageSize; + BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress); + + LDR_SECTION_HEADER_PTR sectPtr = (LDR_SECTION_HEADER_PTR)(((Char*)opt_header_ptr) + header_ptr->mSizeOfOptionalHeader); + + constexpr auto sectionForCode = ".text"; + constexpr auto sectionForNewLdr = ".ldr"; + constexpr auto sectionForBSS = ".bss"; + + for (SizeT sectIndex = 0; sectIndex < numSecs; ++sectIndex) + { + LDR_SECTION_HEADER_PTR sect = §Ptr[sectIndex]; + + SetMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), 0, sect->mSizeOfRawData); + + if (StrCmp(sectionForCode, sect->mName) == 0) + { + fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + opt_header_ptr->mAddressOfEntryPoint); + writer.Write("ZBA: Executable entry address: ").Write((UIntPtr)fStartAddress).Write("\r"); + } + else if (StrCmp(sectionForNewLdr, sect->mName) == 0) + { + struct HANDOVER_INFORMATION_STUB + { + UInt64 HandoverMagic; + UInt32 HandoverType; + UInt32 HandoverPad; + UInt32 HandoverArch; + }* handover_struc = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData); + + if (handover_struc->HandoverMagic != kHandoverMagic && + handover_struc->HandoverType != HEL::kTypeKernel) + { +#ifdef __ZKA_AMD64__ + if (handover_struc->HandoverArch != HEL::kArchAMD64) + { + CGDrawString("ZBA: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + ::EFI::Stop(); + } +#endif + +#ifdef __ZKA_ARM64__ + if (handover_struc->HandoverArch != HEL::kArchARM64) + { + CGDrawString("ZBA: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + ::EFI::Stop(); + } +#endif + CGDrawString("ZBA: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + + ::EFI::Stop(); + } + } + + writer.Write("ZBA: Raw offset: ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r"); + + CopyMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), (VoidPtr)((UIntPtr)fBlob + sect->mPointerToRawData), sect->mSizeOfRawData); + } + } + else if (blob_bytes[0] == kPefMagic[0] && + blob_bytes[1] == kPefMagic[1] && + blob_bytes[2] == kPefMagic[2] && + blob_bytes[3] == kPefMagic[3]) + { + // ========================================= // + // PEF executable detected. + // ========================================= // + + fStartAddress = nullptr; + writer.Write("ZBA: PEF executable detected, won't load it.\r"); + writer.Write("ZBA: note: PEF executables aren't loadable by default.\r"); + } + else + { + writer.Write("ZBA: Invalid executable.\r"); + } + } + + /// @note handover header has to be valid! + Void BThread::Start(HEL::HANDOVER_INFO_HEADER* handover) + { + HEL::HandoverProc err_fn = [](HEL::HANDOVER_INFO_HEADER* rcx) -> void { + CGDrawString("ZBA: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); + ::EFI::Stop(); + }; + + if (!fStartAddress) + { + err_fn(handover); + } + + reinterpret_cast(fStartAddress)(handover); + } + + const Char* BThread::GetName() + { + return fBlobName; + } + + Void BThread::SetName(const Char* name) + { + CopyMem(fBlobName, name, StrLen(name)); + } + + bool BThread::IsValid() + { + return fStartAddress != nullptr; + } +} // namespace Boot diff --git a/dev/zba/src/HEL/AMD64/BootAHCI.cc b/dev/zba/src/HEL/AMD64/BootAHCI.cc index 5899f177..60520ac9 100644 --- a/dev/zba/src/HEL/AMD64/BootAHCI.cc +++ b/dev/zba/src/HEL/AMD64/BootAHCI.cc @@ -5,9 +5,9 @@ ------------------------------------------- */ /** - * @file AHCI.cxx + * @file BootAHCI.cc * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) - * @brief AHCI driver. + * @brief AHCI support for ZBA. * @version 0.1 * @date 2024-02-02 * diff --git a/dev/zba/src/HEL/AMD64/BootATA.cc b/dev/zba/src/HEL/AMD64/BootATA.cc index 0faba789..34f1df29 100644 --- a/dev/zba/src/HEL/AMD64/BootATA.cc +++ b/dev/zba/src/HEL/AMD64/BootATA.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ /** - * @file ATA.cxx + * @file BootATA.cc * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) * @brief ATA driver. * @version 0.1 diff --git a/dev/zba/src/HEL/AMD64/BootMain.cc b/dev/zba/src/HEL/AMD64/BootMain.cc index 392fce0d..e939ac18 100644 --- a/dev/zba/src/HEL/AMD64/BootMain.cc +++ b/dev/zba/src/HEL/AMD64/BootMain.cc @@ -17,17 +17,17 @@ #include #include -// make the compiler shut up. +// Makes the compiler shut up. #ifndef kMachineModel #define kMachineModel "ZKA SSD" #endif // !kMachineModel -#ifndef cExpectedWidth -#define cExpectedWidth 1280 +#ifndef kExpectedWidth +#define kExpectedWidth 1280 #endif -#ifndef cExpectedHeight -#define cExpectedHeight 720 +#ifndef kExpectedHeight +#define kExpectedHeight 720 #endif /** Graphics related. */ @@ -38,18 +38,18 @@ STATIC EfiGUID kGopGuid; EXTERN_C Void rt_reset_hardware(); -/** - @brief Finds and stores the GOP. -*/ - EXTERN EfiBootServices* BS; -STATIC Void boot_init_fb() noexcept +/** + @brief Finds and stores the GOP object. +*/ +STATIC Bool boot_init_fb() noexcept { kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); kGop = nullptr; - BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop); + if (BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop) /= kEfiOk) + return No; kGopStride = 4; @@ -60,8 +60,8 @@ STATIC Void boot_init_fb() noexcept kGop->QueryMode(kGop, i, &sz, &infoPtr); - if (infoPtr->HorizontalResolution == cExpectedWidth && - infoPtr->VerticalResolution == cExpectedHeight) + if (infoPtr->HorizontalResolution == kExpectedWidth && + infoPtr->VerticalResolution == kExpectedHeight) { kGop->SetMode(kGop, i); break; @@ -93,15 +93,16 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, UInt32 rev_desc = 0; #ifdef __ZKA_USE_FB__ - boot_init_fb(); ///! Init the GOP. + if (!boot_init_fb()) + return -1; ///! Init the GOP. - for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries; - ++indexVT) + for (SizeT index_vt = 0; index_vt < SystemTable->NumberOfTableEntries; + ++index_vt) { Char* vendor_table = reinterpret_cast( - SystemTable->ConfigurationTable[indexVT].VendorTable); + SystemTable->ConfigurationTable[index_vt].VendorTable); - /// ACPI's 'RSD PTR', which contains hardware tables (MADT, FACP...) + // ACPI's 'RSD PTR', which contains the ACPI SDT (MADT, FACP...) if (vendor_table[0] == 'R' && vendor_table[1] == 'S' && vendor_table[2] == 'D' && vendor_table[3] == ' ' && vendor_table[4] == 'P' && vendor_table[5] == 'T' && @@ -164,7 +165,6 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, // format the disk. // ---------------------------------------------------- // -#ifdef __AHCI__ if (!partition_factory.IsPartitionValid()) { Boot::BDiskFormatFactory::BFileDescriptor root; @@ -177,7 +177,6 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, rt_reset_hardware(); } -#endif BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); @@ -231,7 +230,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, if (reader_syschk.Blob()) { syschk_thread = new Boot::BThread(reader_syschk.Blob()); - syschk_thread->SetName("System Check."); + syschk_thread->SetName("System Check (Integrity check)"); } syschk_thread->Start(handover_hdr); @@ -268,7 +267,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, if (reader_kernel.Blob()) { kernel_thread = new Boot::BThread(reader_kernel.Blob()); - kernel_thread->SetName("Minimal Kernel."); + kernel_thread->SetName("OS Kernel (Microkernel)."); handover_hdr->f_KernelImage = reader_kernel.Blob(); } @@ -315,7 +314,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, #endif // __ZKA_USE_FB__ // ---------------------------------------------------- // - // Finally load Kernel, and the cr3 to it. + // Finally load the operating system kernel. // ---------------------------------------------------- // kernel_thread->Start(handover_hdr); diff --git a/dev/zba/src/Thread.cc b/dev/zba/src/Thread.cc deleted file mode 100644 index d009a633..00000000 --- a/dev/zba/src/Thread.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -// External boot services symbol. -EXTERN EfiBootServices* BS; - -/// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. - -namespace Boot -{ - BThread::BThread(VoidPtr blob) - : fBlob(blob), fStartAddress(nullptr) - { - // detect the format. - const Char* blob_bytes = reinterpret_cast(fBlob); - - BTextWriter writer; - - if (!blob_bytes) - { - // failed to provide a valid pointer. - return; - } - - if (blob_bytes[0] == kMagMz0 && - blob_bytes[1] == kMagMz1) - { - LDR_EXEC_HEADER_PTR header_ptr = CFKit::ldr_find_exec_header(blob_bytes); - LDR_OPTIONAL_HEADER_PTR opt_header_ptr = CFKit::ldr_find_opt_exec_header(blob_bytes); - - if (!header_ptr || !opt_header_ptr) - return; - -#ifdef __ZKA_AMD64__ - if (header_ptr->mMachine != kPeMachineAMD64 || - header_ptr->mSignature != kPeSignature) - { - writer.Write("ZBA: Not a PE32+ executable.\r"); - return; - } -#elif defined(__ZKA_ARM64__) - if (header_ptr->mMachine != kPeMachineAMD64 || - header_ptr->mSignature != kPeSignature) - { - writer.Write("ZBA: Not a PE32+ executable.\r"); - return; - } -#endif // __ZKA_AMD64__ || __ZKA_ARM64__ - - if (opt_header_ptr->mSubsystem != kZKASubsystem) - { - writer.Write("ZBA: Not a ZKA Subsystem executable.\r"); - return; - } - - writer.Write("ZBA: PE32+ executable detected (ZKA Subsystem).\r"); - - auto numSecs = header_ptr->mNumberOfSections; - - writer.Write("ZBA: Major Linker Ver: ").Write(opt_header_ptr->mMajorLinkerVersion).Write("\r"); - writer.Write("ZBA: Minor Linker Ver: ").Write(opt_header_ptr->mMinorLinkerVersion).Write("\r"); - writer.Write("ZBA: Major Subsystem Ver: ").Write(opt_header_ptr->mMajorSubsystemVersion).Write("\r"); - writer.Write("ZBA: Minor Subsystem Ver: ").Write(opt_header_ptr->mMinorSubsystemVersion).Write("\r"); - writer.Write("ZBA: Magic: ").Write(header_ptr->mSignature).Write("\r"); - - constexpr auto cPageSize = 512; - - EfiPhysicalAddress loadStartAddress = opt_header_ptr->mImageBase; - loadStartAddress += opt_header_ptr->mBaseOfData; - - writer.Write("ZBA: ImageBase: ").Write(loadStartAddress).Write("\r"); - - auto numPages = opt_header_ptr->mSizeOfImage / cPageSize; - BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress); - - LDR_SECTION_HEADER_PTR sectPtr = (LDR_SECTION_HEADER_PTR)(((Char*)opt_header_ptr) + header_ptr->mSizeOfOptionalHeader); - - constexpr auto sectionForCode = ".text"; - constexpr auto sectionForNewLdr = ".ldr"; - constexpr auto sectionForBSS = ".bss"; - - for (SizeT sectIndex = 0; sectIndex < numSecs; ++sectIndex) - { - LDR_SECTION_HEADER_PTR sect = §Ptr[sectIndex]; - - SetMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), 0, sect->mSizeOfRawData); - - if (StrCmp(sectionForCode, sect->mName) == 0) - { - fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + opt_header_ptr->mAddressOfEntryPoint); - writer.Write("ZBA: Executable entry address: ").Write((UIntPtr)fStartAddress).Write("\r"); - } - else if (StrCmp(sectionForNewLdr, sect->mName) == 0) - { - struct HANDOVER_INFORMATION_STUB - { - UInt64 HandoverMagic; - UInt32 HandoverType; - UInt32 HandoverPad; - UInt32 HandoverArch; - }* handover_struc = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData); - - if (handover_struc->HandoverMagic != kHandoverMagic && - handover_struc->HandoverType != HEL::kTypeKernel) - { -#ifdef __ZKA_AMD64__ - if (handover_struc->HandoverArch != HEL::kArchAMD64) - { - CGDrawString("ZBA: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); - ::EFI::Stop(); - } -#endif - -#ifdef __ZKA_ARM64__ - if (handover_struc->HandoverArch != HEL::kArchARM64) - { - CGDrawString("ZBA: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); - ::EFI::Stop(); - } -#endif - CGDrawString("ZBA: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); - - ::EFI::Stop(); - } - } - - writer.Write("ZBA: Raw offset: ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r"); - - CopyMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), (VoidPtr)((UIntPtr)fBlob + sect->mPointerToRawData), sect->mSizeOfRawData); - } - } - else if (blob_bytes[0] == kPefMagic[0] && - blob_bytes[1] == kPefMagic[1] && - blob_bytes[2] == kPefMagic[2] && - blob_bytes[3] == kPefMagic[3]) - { - // ========================================= // - // PEF executable detected. - // ========================================= // - - fStartAddress = nullptr; - writer.Write("ZBA: PEF executable detected, won't load it.\r"); - writer.Write("ZBA: note: PEF executables aren't loadable by default.\r"); - } - else - { - writer.Write("ZBA: Invalid executable.\r"); - } - } - - /// @note handover header has to be valid! - Void BThread::Start(HEL::HANDOVER_INFO_HEADER* handover) - { - HEL::HandoverProc err_fn = [](HEL::HANDOVER_INFO_HEADER* rcx) -> void { - CGDrawString("ZBA: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); - ::EFI::Stop(); - }; - - if (!fStartAddress) - { - err_fn(handover); - } - - reinterpret_cast(fStartAddress)(handover); - } - - const Char* BThread::GetName() - { - return fBlobName; - } - - Void BThread::SetName(const Char* name) - { - CopyMem(fBlobName, name, StrLen(name)); - } - - bool BThread::IsValid() - { - return fStartAddress != nullptr; - } -} // namespace Boot diff --git a/dev/zka/CFKit/GUIDWizard.h b/dev/zka/CFKit/GUIDWizard.h index 4a41cf7f..b4a92249 100644 --- a/dev/zka/CFKit/GUIDWizard.h +++ b/dev/zka/CFKit/GUIDWizard.h @@ -19,6 +19,6 @@ namespace CFKit::XRN::Version1 { using namespace Kernel; - Ref cf_make_sequence(const ArrayList& seq); - ErrorOr> cf_try_guid_to_string(Ref& guid); + Ref cf_make_sequence(const ArrayList& seq); + ErrorOr> cf_try_guid_to_string(Ref& guid); } // namespace CFKit::XRN::Version1 diff --git a/dev/zka/CFKit/LoaderUtils.h b/dev/zka/CFKit/LoaderUtils.h deleted file mode 100644 index edaa38d0..00000000 --- a/dev/zka/CFKit/LoaderUtils.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __CFKIT_LOADER_UTILS_H__ -#define __CFKIT_LOADER_UTILS_H__ - -#include -#include - -namespace CFKit -{ - using namespace Kernel; - - /// @brief Finds 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 Finds 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 Finds 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 Finds 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 CFKit - -#endif // ifndef __CFKIT_LOADER_UTILS_H__ diff --git a/dev/zka/CFKit/Utils.h b/dev/zka/CFKit/Utils.h new file mode 100644 index 00000000..370eca45 --- /dev/null +++ b/dev/zka/CFKit/Utils.h @@ -0,0 +1,55 @@ +#ifndef CFKIT_UTILS_H +#define CFKIT_UTILS_H + +#include +#include + +namespace CFKit +{ + using namespace Kernel; + + /// @brief Finds 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 Finds 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 Finds 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 Finds 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 CFKit + +#endif // ifndef CFKIT_UTILS_H diff --git a/dev/zka/HALKit/AMD64/HalCPU.cc b/dev/zka/HALKit/AMD64/HalCPU.cc index 80729346..d24bfc0a 100644 --- a/dev/zka/HALKit/AMD64/HalCPU.cc +++ b/dev/zka/HALKit/AMD64/HalCPU.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: HalCPU.cxx + File: HalCPU.cc Purpose: Platform processor routines. ------------------------------------------- */ @@ -11,7 +11,7 @@ #include /** - * @file HalCPU.cxx + * @file HalCPU.cc * @brief Common CPU API. */ diff --git a/dev/zka/HALKit/AMD64/HalDebugPort.cc b/dev/zka/HALKit/AMD64/HalDebugPort.cc index 6c8ebf2b..c6acfac6 100644 --- a/dev/zka/HALKit/AMD64/HalDebugPort.cc +++ b/dev/zka/HALKit/AMD64/HalDebugPort.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -//! @file DebuggerPort.cxx +//! @file DebuggerPort.cc //! @brief UART debug via packets. #include diff --git a/dev/zka/HALKit/AMD64/HalPagingMgr.cc b/dev/zka/HALKit/AMD64/HalPagingMgr.cc index afc86eeb..1a7202d7 100644 --- a/dev/zka/HALKit/AMD64/HalPagingMgr.cc +++ b/dev/zka/HALKit/AMD64/HalPagingMgr.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: HalPagingMgr.cxx + File: HalPagingMgr.cc Purpose: Platform Paging Manager.. ------------------------------------------- */ diff --git a/dev/zka/HALKit/AMD64/HalTimer.cc b/dev/zka/HALKit/AMD64/HalTimer.cc index 6d552a09..c7f6bea3 100644 --- a/dev/zka/HALKit/AMD64/HalTimer.cc +++ b/dev/zka/HALKit/AMD64/HalTimer.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: HalTimer.cxx + File: HalTimer.cc Purpose: HAL timer Revision History: @@ -23,7 +23,7 @@ #define cHPETInterruptRegValue (0x2C) ///! BUGS: 0 -///! @file HalTimer.cxx +///! @file HalTimer.cc ///! @brief Hardware Timer (HPET) namespace Kernel::Detail diff --git a/dev/zka/HALKit/AMD64/Storage/AHCI.cc b/dev/zka/HALKit/AMD64/Storage/AHCI.cc index 1d237465..1a9b640f 100644 --- a/dev/zka/HALKit/AMD64/Storage/AHCI.cc +++ b/dev/zka/HALKit/AMD64/Storage/AHCI.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ /** - * @file AHCI.cxx + * @file AHCI.cc * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) * @brief AHCI driver. * @version 0.1 diff --git a/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cc b/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cc index ddf08501..841960e1 100644 --- a/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cc +++ b/dev/zka/HALKit/AMD64/Storage/ATA-DMA.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ /** - * @file ATA-DMA.cxx + * @file ATA-DMA.cc * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) * @brief ATA driver (DMA mode). * @version 0.1 diff --git a/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cc b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cc index f3907fa3..eaefbd58 100644 --- a/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cc +++ b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ /** - * @file ATA-PIO.cxx + * @file ATA-PIO.cc * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) * @brief ATA driver (PIO mode). * @version 0.1 diff --git a/dev/zka/HALKit/ARM64/HalPagingMgr.cc b/dev/zka/HALKit/ARM64/HalPagingMgr.cc index 0182c315..52dd738b 100644 --- a/dev/zka/HALKit/ARM64/HalPagingMgr.cc +++ b/dev/zka/HALKit/ARM64/HalPagingMgr.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: HalPagingMgr.cxx + File: HalPagingMgr.cc Purpose: Platform Paging Manager.. ------------------------------------------- */ diff --git a/dev/zka/HALKit/ARM64/HalTimer.cc b/dev/zka/HALKit/ARM64/HalTimer.cc index d3f8c457..18b15bf3 100644 --- a/dev/zka/HALKit/ARM64/HalTimer.cc +++ b/dev/zka/HALKit/ARM64/HalTimer.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: HalTimer.cxx + File: HalTimer.cc Purpose: HAL timer Revision History: diff --git a/dev/zka/HALKit/ARM64/Storage/HalFlash.cc b/dev/zka/HALKit/ARM64/Storage/HalFlash.cc index d64d9d82..24999070 100644 --- a/dev/zka/HALKit/ARM64/Storage/HalFlash.cc +++ b/dev/zka/HALKit/ARM64/Storage/HalFlash.cc @@ -7,7 +7,7 @@ #include #include -/// @file Flash.cxx +/// @file Flash.cc /// @brief Flash memory builtin. #ifdef __USE_MBCI_FLASH__ diff --git a/dev/zka/src/DriveMgr.cc b/dev/zka/src/DriveMgr.cc index 16e3c12d..e2011785 100644 --- a/dev/zka/src/DriveMgr.cc +++ b/dev/zka/src/DriveMgr.cc @@ -13,7 +13,7 @@ #include /***********************************************************************************/ -/// @file DriveMgr.cxx +/// @file DriveMgr.cc /// @brief Drive Manager API. /***********************************************************************************/ diff --git a/dev/zka/src/ErrorOr.cc b/dev/zka/src/ErrorOr.cc index 9c10745e..b6b3aca4 100644 --- a/dev/zka/src/ErrorOr.cc +++ b/dev/zka/src/ErrorOr.cc @@ -7,6 +7,6 @@ #include /***********************************************************************************/ -/// @file ErrorOr.cxx /// +/// @file ErrorOr.cc /// /// @brief ErrorOr container class. /// /***********************************************************************************/ diff --git a/dev/zka/src/GUIDWizard.cc b/dev/zka/src/GUIDWizard.cc index a904696f..d72c77eb 100644 --- a/dev/zka/src/GUIDWizard.cc +++ b/dev/zka/src/GUIDWizard.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: GUIDWizard.cxx + File: GUIDWizard.cc Purpose: GUID helper code Revision History: @@ -13,53 +13,53 @@ #include // begin of ascii 'readable' characters. (A, C, C, 1, 2) -#define kAsciiBegin 47 +#define kUUIDAsciiBegin 47 // @brief Size of UUID. #define kUUIDSize 37 namespace CFKit::XRN::Version1 { - auto cf_make_sequence(const ArrayList& uuidSeq) -> Ref + auto cf_make_sequence(const ArrayList& uuidSeq) -> Ref { GUIDSequence* seq = new GUIDSequence(); MUST_PASS(seq); - Ref seq_ref{*seq}; + Ref seq_ref{seq}; - seq_ref.Leak().fMs1 = uuidSeq[0]; - seq_ref.Leak().fMs2 = uuidSeq[1]; - seq_ref.Leak().fMs3 = uuidSeq[2]; - seq_ref.Leak().fMs4[0] = uuidSeq[3]; - seq_ref.Leak().fMs4[1] = uuidSeq[4]; - seq_ref.Leak().fMs4[2] = uuidSeq[5]; - seq_ref.Leak().fMs4[3] = uuidSeq[6]; - seq_ref.Leak().fMs4[4] = uuidSeq[7]; - seq_ref.Leak().fMs4[5] = uuidSeq[8]; - seq_ref.Leak().fMs4[6] = uuidSeq[9]; - seq_ref.Leak().fMs4[7] = uuidSeq[10]; + seq_ref.Leak()->fMs1 = uuidSeq[0]; + seq_ref.Leak()->fMs2 = uuidSeq[1]; + seq_ref.Leak()->fMs3 = uuidSeq[2]; + seq_ref.Leak()->fMs4[0] = uuidSeq[3]; + seq_ref.Leak()->fMs4[1] = uuidSeq[4]; + seq_ref.Leak()->fMs4[2] = uuidSeq[5]; + seq_ref.Leak()->fMs4[3] = uuidSeq[6]; + seq_ref.Leak()->fMs4[4] = uuidSeq[7]; + seq_ref.Leak()->fMs4[5] = uuidSeq[8]; + seq_ref.Leak()->fMs4[6] = uuidSeq[9]; + seq_ref.Leak()->fMs4[7] = uuidSeq[10]; return seq_ref; } // @brief Tries to make a guid out of a string. // This function is not complete for now - auto cf_try_guid_to_string(Ref& seq) -> ErrorOr> + auto cf_try_guid_to_string(Ref& seq) -> ErrorOr> { Char buf[kUUIDSize]; for (SizeT index = 0; index < 16; ++index) { - buf[index] = seq.Leak().u8[index] + kAsciiBegin; + buf[index] = seq.Leak()->u8[index] + kUUIDAsciiBegin; } for (SizeT index = 16; index < 24; ++index) { - buf[index] = seq.Leak().u16[index] + kAsciiBegin; + buf[index] = seq.Leak()->u16[index] + kUUIDAsciiBegin; } for (SizeT index = 24; index < 28; ++index) { - buf[index] = seq.Leak().u32[index] + kAsciiBegin; + buf[index] = seq.Leak()->u32[index] + kUUIDAsciiBegin; } auto view = StringBuilder::Construct(buf); diff --git a/dev/zka/src/HardwareThreadScheduler.cc b/dev/zka/src/HardwareThreadScheduler.cc index 37d81f04..c1d06531 100644 --- a/dev/zka/src/HardwareThreadScheduler.cc +++ b/dev/zka/src/HardwareThreadScheduler.cc @@ -11,7 +11,7 @@ ///! BUGS: 0 -///! @file MP.cxx +///! @file MP.cc ///! @brief This file handles multi processing in the Kernel. ///! @brief Multi processing is needed for multi-tasking operations. diff --git a/dev/zka/src/Heap.cc b/dev/zka/src/Heap.cc index 45b7aa73..8db31178 100644 --- a/dev/zka/src/Heap.cc +++ b/dev/zka/src/Heap.cc @@ -19,7 +19,7 @@ ------------------------------------------- */ -//! @file Heap.cxx +//! @file Heap.cc //! @brief Kernel's heap manager, serves as the main memory manager. #define kKernelHeapMagic (0xD4D7D5) diff --git a/dev/zka/src/IPEFDLLObject.cc b/dev/zka/src/IPEFDLLObject.cc index d7fe2948..0f0ac483 100644 --- a/dev/zka/src/IPEFDLLObject.cc +++ b/dev/zka/src/IPEFDLLObject.cc @@ -31,7 +31,7 @@ using namespace Kernel; /***********************************************************************************/ -/// @file PEFSharedObjectRT.cxx +/// @file PEFSharedObjectRT.cc /// @brief PEF's shared object runtime. /***********************************************************************************/ diff --git a/dev/zka/src/NeFS+IO.cc b/dev/zka/src/NeFS+IO.cc index 5a5f60c6..b55707f9 100644 --- a/dev/zka/src/NeFS+IO.cc +++ b/dev/zka/src/NeFS+IO.cc @@ -9,7 +9,7 @@ /************************************************************* * - * File: NeFS+IO.cxx + * File: NeFS+IO.cc * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * diff --git a/dev/zka/src/Stream.cc b/dev/zka/src/Stream.cc index cf5cb4a4..be1f2308 100644 --- a/dev/zka/src/Stream.cc +++ b/dev/zka/src/Stream.cc @@ -2,7 +2,7 @@ Copyright ZKA Web Services Co. - File: Stream.cxx + File: Stream.cc Purpose: Stream object Revision History: diff --git a/dev/zka/src/ThreadLocalStorage.cc b/dev/zka/src/ThreadLocalStorage.cc index ef8aba6c..8c75d522 100644 --- a/dev/zka/src/ThreadLocalStorage.cc +++ b/dev/zka/src/ThreadLocalStorage.cc @@ -14,7 +14,7 @@ /***********************************************************************************/ /// @bugs: 0 -/// @file ThreadLocalStorage.cxx +/// @file ThreadLocalStorage.cc /// @brief Process Thread Local Storage. /***********************************************************************************/ diff --git a/dev/zka/src/Timer.cc b/dev/zka/src/Timer.cc index e7ad488a..a36ac0c3 100644 --- a/dev/zka/src/Timer.cc +++ b/dev/zka/src/Timer.cc @@ -7,7 +7,7 @@ #include ///! BUGS: 0 -///! @file Timer.cxx +///! @file Timer.cc ///! @brief Software Timer implementation using namespace Kernel; diff --git a/dev/zka/src/User.cc b/dev/zka/src/User.cc index 9037d729..80a14041 100644 --- a/dev/zka/src/User.cc +++ b/dev/zka/src/User.cc @@ -4,7 +4,7 @@ * ZKA * Copyright ZKA Web Services Co., all rights reserved. * - * File: User.cxx + * File: User.cc * Purpose: User class, used to provide authentication and security. * * ======================================================== diff --git a/dev/zka/src/UserProcessScheduler.cc b/dev/zka/src/UserProcessScheduler.cc index 0081367a..05c2b35e 100644 --- a/dev/zka/src/UserProcessScheduler.cc +++ b/dev/zka/src/UserProcessScheduler.cc @@ -2,13 +2,13 @@ Copyright ZKA Web Services Co. - FILE: UserProcessScheduler.cxx + FILE: UserProcessScheduler.cc PURPOSE: EL0/Ring-3 Process scheduler. ------------------------------------------- */ /***********************************************************************************/ -/// @file UserProcessScheduler.cxx +/// @file UserProcessScheduler.cc /// @brief User process scheduler. /***********************************************************************************/ diff --git a/dev/zka/src/UserProcessTeam.cc b/dev/zka/src/UserProcessTeam.cc index 22b158b9..982a9388 100644 --- a/dev/zka/src/UserProcessTeam.cc +++ b/dev/zka/src/UserProcessTeam.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ /***********************************************************************************/ -/// @file UserProcessTeam.cxx +/// @file UserProcessTeam.cc /// @brief UserProcess teams implementation. /***********************************************************************************/ diff --git a/tools/Common.h b/tools/Common.h new file mode 100644 index 00000000..e80f1d11 --- /dev/null +++ b/tools/Common.h @@ -0,0 +1,14 @@ +/** + Sat Oct 26 07:03:28 AM CEST 2024 + (C) ZKA Web Services Co. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include diff --git a/tools/Framework.h b/tools/Framework.h new file mode 100644 index 00000000..0572a521 --- /dev/null +++ b/tools/Framework.h @@ -0,0 +1,13 @@ +/** + Thu Oct 17 07:57:43 CEST 2024 + (C) ZKA Web Services Co. +*/ + +#pragma once + +#include + +#define kFKDLLDirectory "ZKA/DLL/" +#define kFKManifestDirectory "ZKA/Manifests/" +#define kFKRootDirectory "ZKA/" +#define kFKExtension ".framework" diff --git a/tools/common_zka.h b/tools/common_zka.h deleted file mode 100644 index 3b7a1b19..00000000 --- a/tools/common_zka.h +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include diff --git a/tools/framework.h b/tools/framework.h deleted file mode 100644 index 66a8e497..00000000 --- a/tools/framework.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - Thu Oct 17 07:57:43 CEST 2024 - (C) ZKA Web Services Co. -*/ - -#pragma once - -#include - -#define kFKDLLDirectory "ZKA/DLL/" -#define kFKManifestDirectory "ZKA/Manifests/" -#define kFKRootDirectory "ZKA/" -#define kFKExtension ".framework" diff --git a/tools/make_framework.json b/tools/make_framework.json index c597e5d6..4ef2d7b6 100644 --- a/tools/make_framework.json +++ b/tools/make_framework.json @@ -2,7 +2,7 @@ "compiler_path": "g++", "compiler_std": "c++20", "headers_path": ["./"], - "sources_path": ["src/make_framework.cxx"], + "sources_path": ["src/MakeFramework.cc"], "output_name": "make_framework.exe", "cpp_macros": [ "__MKF_AMD64__", diff --git a/tools/make_zxd.json b/tools/make_zxd.json deleted file mode 100644 index 1c25c1a2..00000000 --- a/tools/make_zxd.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compiler_path": "g++", - "compiler_std": "c++20", - "headers_path": ["./"], - "sources_path": ["src/make_zxd.cxx"], - "output_name": "make_zxd.exe", - "cpp_macros": [ - "__DRVSIGN_AMD64__", - "cDSVersion=0x0100", - "cDSVersionHighest=0x0100", - "cDSVersionLowest=0x0100" - ] -} diff --git a/tools/src/MakeFramework.cc b/tools/src/MakeFramework.cc new file mode 100644 index 00000000..11077ddf --- /dev/null +++ b/tools/src/MakeFramework.cc @@ -0,0 +1,42 @@ +/* + * Created on Thu Oct 17 08:00:42 CEST 2024 + * + * Copyright (c) 2024 ZKA Web Services Co + */ + +#include +#include + +/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. +/// @note ZXD is a format for ZKA signed drivers. +int main(int argc, char* argv[]) +{ + for (size_t i = 1ul; i < argc; ++i) + { + if (strcmp(argv[i], "/?") == 0) + { + std::cout << "make_framework: Framework Creation Tool.\n"; + std::cout << "make_framework: © ZKA Web Services Co, all rights reserved.\n"; + + return 0; + } + } + + auto path = std::string(argv[1]); + + if (!path.ends_with(kFKExtension)) + return 1; + + std::filesystem::path path_arg = path; + + if (std::filesystem::create_directory(path_arg)) + { + std::filesystem::create_directory(path_arg / kFKRootDirectory); + std::filesystem::create_directory(path_arg / kFKManifestDirectory); + std::filesystem::create_directory(path_arg / kFKDLLDirectory); + + return 0; + } + + return 1; +} diff --git a/tools/src/make_framework.cc b/tools/src/make_framework.cc deleted file mode 100644 index 718a9ad1..00000000 --- a/tools/src/make_framework.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Created on Thu Oct 17 08:00:42 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#include -#include - -/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. -/// @note ZXD is a format for ZKA signed drivers. -int main(int argc, char* argv[]) -{ - for (size_t i = 1ul; i < argc; ++i) - { - if (strcmp(argv[i], "/?") == 0) - { - std::cout << "make_framework: Framework Tool.\n"; - std::cout << "make_framework: © ZKA Web Services Co, all rights reserved.\n"; - - return 0; - } - } - - auto path = std::string(argv[1]); - - if (!path.ends_with(kFKExtension)) - return 1; - - std::filesystem::path path_arg = path; - - if (std::filesystem::create_directory(path_arg)) - { - std::filesystem::create_directory(path_arg / kFKRootDirectory); - std::filesystem::create_directory(path_arg / kFKManifestDirectory); - std::filesystem::create_directory(path_arg / kFKDLLDirectory); - - return 0; - } - - return 1; -} diff --git a/tools/src/make_zxd.cc b/tools/src/make_zxd.cc deleted file mode 100644 index 535b51db..00000000 --- a/tools/src/make_zxd.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Created on Thu Aug 22 09:29:13 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#include - -/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. -/// @note ZXD is a format for ZKA signed drivers. -int main(int argc, char* argv[]) -{ - for (size_t i = 1ul; i < argc; ++i) - { - if (strcmp(argv[i], "/?") == 0) - { - std::cout << "make_zxd: ZXD Tool.\n"; - std::cout << "make_zxd: © ZKA Web Services Co, all rights reserved.\n"; - - return 0; - } - } - - if (!std::filesystem::exists(argv[1]) || - !std::string(argv[1]).ends_with(kDriverExt)) - return -1; - - ZXD::ZXD_HEADER zxd_hdr{0}; - - zxd_hdr.d_binary_version = 1; - - memcpy(zxd_hdr.d_binary_magic, kSignedDriverMagic, strlen(kSignedDriverMagic)); - memcpy(zxd_hdr.d_binary_name, argv[1], strlen(argv[1])); - - zxd_hdr.d_binary_size = std::filesystem::file_size(argv[1]); - - memset(zxd_hdr.d_binary_padding, 0x00, 512); - - zxd_hdr.d_binary_checksum = 0; - - std::string signed_path = argv[1]; - signed_path.erase(signed_path.find(kDriverExt), strlen(kDriverExt)); - signed_path += kDriverSignedExt; - - std::ofstream of_drv(signed_path, std::ios::binary); - std::ifstream if_drv(argv[1], std::ios::binary); - - std::stringstream ss; - ss << if_drv.rdbuf(); - - if (!ZXD::zxd_check_for_mz(ss.str())) - { - std::filesystem::remove(signed_path); - std::cout << "zxdmake: Couldn't sign current driver, Input driver isn't a valid executable.\n"; - - return 1; - } - - for (auto ch : ss.str()) - { - zxd_hdr.d_binary_checksum |= ch; - } - - zxd_hdr.d_binary_checksum ^= zxd_hdr.d_binary_size; - - of_drv.write((char*)&zxd_hdr, sizeof(ZXD::ZXD_HEADER)); - of_drv.write(ss.str().c_str(), ss.str().size()); - - std::cout << "zxdmake: Signing is done, quiting, Checksum: " << zxd_hdr.d_binary_checksum << ".\n"; - - return 0; -} diff --git a/tools/zxd.h b/tools/zxd.h deleted file mode 100644 index 07702595..00000000 --- a/tools/zxd.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Created on Thu Aug 22 09:29:13 CEST 2024 - * - * Copyright (c) 2024 ZKA Web Services Co - */ - -#pragma once - -#include - -#define kDriverSignedExt ".zxd" -#define kDriverExt ".sys" -#define kSignedDriverMagic " ZXD" - -#define cZXDPaddingSize (512) -#define cZXDMagicSize (5) - -namespace ZXD -{ - /// - /// ZXD header. - /// - struct ZXD_HEADER final - { - char d_binary_padding[cZXDPaddingSize]; - // doesn't change. - char d_binary_magic[cZXDMagicSize]; - std::int32_t d_binary_version; - // can change. - char d_binary_name[4096]; - std::uint64_t d_binary_checksum; - std::uint64_t d_binary_size; - }; - - /***********************************************************************************/ - /* @brief These two handles the detection of a MZ header. */ - /***********************************************************************************/ - - inline bool zxd_check_for_mz(const char* mz_blob) noexcept - { - return mz_blob[0] == 'M' && - mz_blob[1] == 'Z'; - } - - inline bool zxd_check_for_mz(std::string mz_blob) noexcept - { - return mz_blob[0] == 'M' && - mz_blob[1] == 'Z'; - } -} // namespace ZXD diff --git a/zka-dev.files b/zka-dev.files index 60c53225..aab39fc7 100644 --- a/zka-dev.files +++ b/zka-dev.files @@ -1,3 +1,4 @@ +dev/SCIKit/src/Foundation.cc dev/base/EncryptFS/build.json dev/base/EncryptFS/disk_crypt.h dev/base/EncryptFS/src/disk_crypt.cc @@ -54,13 +55,11 @@ dev/modules/MBCI/MBCI.h dev/modules/NVME/NVME.h dev/modules/SCSI/SCSI.h dev/modules/XHCI/Defines.h -dev/sci/sci.json -dev/sci/sci_base.h -dev/sci/sci_hint.h -dev/sci/sci_lpc.h -dev/sci/source_deploy.xml -dev/sci/src/sci_mm.cc -dev/sci/xpcom_core.h +dev/SCIKit/CompilerHint.h +dev/SCIKit/Foundation.h +dev/SCIKit/LPC.h +dev/SCIKit/build.json +dev/SCIKit/xpcom_core.h dev/zba/BootKit/BitManip.h dev/zba/BootKit/BootKit.h dev/zba/BootKit/Device.h @@ -83,6 +82,7 @@ dev/zba/src/BootFileReader.cc dev/zba/src/BootString.cc dev/zba/src/BootSupport.cc dev/zba/src/BootTextWriter.cc +dev/zba/src/BootThread.cc dev/zba/src/HEL/64X000/Boot64x0.S dev/zba/src/HEL/AMD64/BootAHCI.cc dev/zba/src/HEL/AMD64/BootAPI.S @@ -93,12 +93,11 @@ dev/zba/src/HEL/ARM64/BootMain.cc dev/zba/src/HEL/ARM64/BootPlatform.cc dev/zba/src/HEL/POWER/CoreBootStartup.S dev/zba/src/New+Delete.cc -dev/zba/src/Thread.cc dev/zka/ArchKit/ArchKit.h dev/zka/CFKit/GUIDWizard.h dev/zka/CFKit/GUIDWrapper.h -dev/zka/CFKit/LoaderUtils.h dev/zka/CFKit/Property.h +dev/zka/CFKit/Utils.h dev/zka/CompilerKit/CompilerKit.h dev/zka/CompilerKit/Detail.h dev/zka/CompilerKit/Version.h @@ -298,11 +297,8 @@ dev/zka/src/UserProcessScheduler.cc dev/zka/src/UserProcessTeam.cc dev/zka/src/Utils.cc dev/zka/src/Variant.cc -tools/common_zka.h -tools/framework.h +tools/Common.h +tools/Framework.h tools/make_framework.json -tools/make_zxd.json -tools/src/make_framework.cc -tools/src/make_zxd.cc -tools/zxd.h compile_flags.txt +tools/src/MakeFramework.cc diff --git a/zka-dev.includes b/zka-dev.includes index e69de29b..87fb7352 100644 --- a/zka-dev.includes +++ b/zka-dev.includes @@ -0,0 +1,3 @@ +dev/zba +dev/ +dev/zka -- cgit v1.2.3