From 507b3a76de36e41bdfd1c14d94a397990b26a423 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 6 Sep 2024 09:38:00 +0200 Subject: [ IMP ] A first set of software patches regarding the OS kernel and it's components. Signed-off-by: Amlal --- dev/DLL/RunSCM/build.json | 2 +- dev/HPFS/Defines.hxx | 15 +++++ dev/HPFS/Sources/IFSMain.cxx | 14 +++++ dev/HPFS/Sources/IFSMain.rs | 12 ---- dev/HPFS/Sources/compile_flags.txt | 1 + dev/HPFS/hpfs.json | 30 ++++++--- dev/SCI/makefile | 2 +- dev/SCI/sci_base.hxx | 30 +++++---- dev/SCI/scm-design.drawio | 2 +- dev/SCI/xpcom_core.hxx | 6 +- dev/SCI/xpcom_sms.idl | 2 +- dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 13 ++-- dev/ZBA/amd64-efi.make | 2 +- dev/ZKA/FSKit/NeFS.hxx | 91 ++++++++++++++------------- dev/ZKA/FirmwareKit/Handover.hxx | 4 +- dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 70 +++++++++++++++------ dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 2 +- dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 2 +- dev/ZKA/KernelKit/HardwareThreadScheduler.hxx | 2 + dev/ZKA/KernelKit/IPEFDLLObject.hxx | 4 +- dev/ZKA/KernelKit/UserProcessScheduler.hxx | 4 +- dev/ZKA/NewKit/Ref.hxx | 2 +- dev/ZKA/Sources/CodeMgr.cxx | 8 +-- dev/ZKA/Sources/ExeMain.cxx | 14 +++-- dev/ZKA/Sources/FS/NeFS.cxx | 4 +- dev/ZKA/Sources/HardwareThreadScheduler.cxx | 13 ++-- dev/ZKA/Sources/IPEFDLLObject.cxx | 10 +-- dev/ZKA/Sources/ThreadLocalStorage.cxx | 36 ----------- dev/ZKA/Sources/UserProcessScheduler.cxx | 74 +++++++++------------- dev/ZKA/Sources/UserThreadScheduler.cxx | 49 +++++++++++++++ 30 files changed, 300 insertions(+), 220 deletions(-) create mode 100644 dev/HPFS/Defines.hxx create mode 100644 dev/HPFS/Sources/IFSMain.cxx delete mode 100644 dev/HPFS/Sources/IFSMain.rs create mode 100644 dev/HPFS/Sources/compile_flags.txt create mode 100644 dev/ZKA/Sources/UserThreadScheduler.cxx (limited to 'dev') diff --git a/dev/DLL/RunSCM/build.json b/dev/DLL/RunSCM/build.json index 14aae6af..e1294f74 100644 --- a/dev/DLL/RunSCM/build.json +++ b/dev/DLL/RunSCM/build.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./", "../../"], "sources_path": ["Sources/*.cxx"], - "output_name": "runscm.exe", + "output_name": "runxpcom.exe", "compiler_flags": [ "-ffreestanding", "-fno-rtti", diff --git a/dev/HPFS/Defines.hxx b/dev/HPFS/Defines.hxx new file mode 100644 index 00000000..8d0536a0 --- /dev/null +++ b/dev/HPFS/Defines.hxx @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: Defines.hxx + PURPOSE: HPFS IFS defines. + +------------------------------------------- */ + +#pragma once + +typedef __INT32_TYPE__ HPFS_INT32; +typedef void HPFS_VOID; + +#define cHPFSVersion 0x0100 diff --git a/dev/HPFS/Sources/IFSMain.cxx b/dev/HPFS/Sources/IFSMain.cxx new file mode 100644 index 00000000..229efb15 --- /dev/null +++ b/dev/HPFS/Sources/IFSMain.cxx @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: IFSMain.cxx + PURPOSE: HPFS IFS entrypoint. + +------------------------------------------- */ + +#include + +HPFS_INT32 IFSStart(HPFS_VOID) { + return 0; +} diff --git a/dev/HPFS/Sources/IFSMain.rs b/dev/HPFS/Sources/IFSMain.rs deleted file mode 100644 index 5a49585a..00000000 --- a/dev/HPFS/Sources/IFSMain.rs +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - FILE: IFSMain.rs - PURPOSE: HPFS IFS. - -------------------------------------------- */ - -fn IFSStart() { - -} \ No newline at end of file diff --git a/dev/HPFS/Sources/compile_flags.txt b/dev/HPFS/Sources/compile_flags.txt new file mode 100644 index 00000000..7c66a118 --- /dev/null +++ b/dev/HPFS/Sources/compile_flags.txt @@ -0,0 +1 @@ +-I../../ diff --git a/dev/HPFS/hpfs.json b/dev/HPFS/hpfs.json index 3a13297b..a7ba778e 100644 --- a/dev/HPFS/hpfs.json +++ b/dev/HPFS/hpfs.json @@ -1,11 +1,21 @@ { - "compiler_path": "rustc", - "compiler_std": "", - "sources_path": ["Sources/*.rs"], - "output_name": "hpfs.sys", - "compiler_flags": [ - ], - "cpp_macros": [ - ] - } - \ No newline at end of file + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../"], + "sources_path": ["Sources/*.cxx"], + "output_name": "hpfs.sys", + "compiler_flags": [ + "-fPIC", + "-ffreestanding", + "-shared", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17" + ], + "cpp_macros": [ + "__HPFS_IMPL__", + "cHPFSVersion=0x0100", + "cHPFSVersionHighest=0x0100", + "cHPFSVersionLowest=0x0100" + ] +} diff --git a/dev/SCI/makefile b/dev/SCI/makefile index 4193cd70..05593216 100644 --- a/dev/SCI/makefile +++ b/dev/SCI/makefile @@ -1,6 +1,6 @@ ###################### # (C) ZKA -# SCM/SCI kit makefile. +# XPCOM/SCI kit makefile. ###################### CC=g++ diff --git a/dev/SCI/sci_base.hxx b/dev/SCI/sci_base.hxx index 0cff8f0d..7f7565de 100644 --- a/dev/SCI/sci_base.hxx +++ b/dev/SCI/sci_base.hxx @@ -43,7 +43,7 @@ class IUnknown; // Refrenced from an IDB entry. class UnknownUCLSID; // From the IDB, the constructor of the object, e.g: WordUCLSID. class UUID; -/// @brief Allocate new SCM class. +/// @brief Allocate new XPCOM class. /// @tparam TCLS /// @tparam UCLSID /// @param uclsidOfCls @@ -54,7 +54,7 @@ TCLS* XPCOMQueryInterface(UCLSID uclsidOfCls, Args... args); template SInt32 XPCOMReleaseClass(TCLS** cls); -/// @brief Release SCM class. +/// @brief Release XPCOM class. /// @tparam TCLS /// @param cls /// @return @@ -157,13 +157,13 @@ IMPORT_C UInt64 IoSeekFile(_Input ZKAObject file_desc, UInt64 file_offset); /// @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 TlsInstallIB(UInt0); +IMPORT_C UInt32 TlsInstall(UInt0); // ------------------------------------------------------------------------ -// SCM API. +// XPCOM API. // ------------------------------------------------------------------------ -/// @brief Allocate new SCM object. +/// @brief Allocate new XPCOM object. /// @tparam TCLS the class type. /// @tparam UCLSID UCLS factory class type. /// @param uclsidOfCls UCLS factory class @@ -171,20 +171,20 @@ IMPORT_C UInt32 TlsInstallIB(UInt0); template TCLS* XPCOMQueryInterface(_Input UCLSID* uclsidOfCls, _Input Args&&... args); -/// @brief Release SCM object. +/// @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 SCM instance in the process. -/// @param handle_instance the SCM handle. -/// @param flags the SCM flags. +/// @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 ZKAObject* handle_instance); -/// @brief Destroys an SCM instance of the process. -/// @param handle_instance the SCM handle. +/// @brief Destroys an XPCOM instance of the process. +/// @param handle_instance the XPCOM handle. IMPORT_C UInt0 XPCOMDestroyInstance(_Input ZKAObject handle_instance); // ------------------------------------------------------------------------ @@ -218,12 +218,16 @@ IMPORT_C SInt32 ErrGetLastError(UInt0); // Threading API. // ------------------------------------------------------------------------ -IMPORT_C UInt0 ThrExitCurrentThread(SInt32 exit_code); -IMPORT_C UInt0 ThrExitMainThread(SInt32 exit_code); +IMPORT_C UInt0 ThrExitCurrentThread(_Input SInt32 exit_code); +IMPORT_C UInt0 ThrExitMainThread(_Input SInt32 exit_code); IMPORT_C UInt0 ThrExitYieldThread(UInt0); IMPORT_C UInt0 ThrExitJoinThread(UInt0); IMPORT_C UInt0 ThrExitDetachThread(UInt0); +// ------------------------------------------------------------------------ +// Disk Management API. +// ------------------------------------------------------------------------ + #endif // ifndef __SCI_BASE_HXX__ diff --git a/dev/SCI/scm-design.drawio b/dev/SCI/scm-design.drawio index be77883c..22bcace6 100644 --- a/dev/SCI/scm-design.drawio +++ b/dev/SCI/scm-design.drawio @@ -19,7 +19,7 @@ - + diff --git a/dev/SCI/xpcom_core.hxx b/dev/SCI/xpcom_core.hxx index 3183d0e4..63bcf403 100644 --- a/dev/SCI/xpcom_core.hxx +++ b/dev/SCI/xpcom_core.hxx @@ -3,7 +3,7 @@ Copyright ZKA Technologies. File: rt.internal.inl -Purpose: Base code of SCM. +Purpose: Base code of XPCOM. ------------------------------------------- */ @@ -37,7 +37,7 @@ public: virtual VoidPtr QueryInterface(UUID * p_uuid) = 0; }; -/// @brief Allocate new SCM object. +/// @brief Allocate new XPCOM object. /// @tparam TCLS the class type. /// @tparam UCLSID UCLS factory class type. /// @param uclsidOfCls UCLS factory class @@ -49,7 +49,7 @@ inline TCLS* XPCOMQueryInterface(UCLSID* uclsidOfCls, Args&&... args) return uclsidOfCls->QueryInterfaceWithArgs(args...); } -/// @brief Release SCM object. +/// @brief Release XPCOM object. /// @tparam TCLS the class type. /// @param cls the class to release. /// @return status code. diff --git a/dev/SCI/xpcom_sms.idl b/dev/SCI/xpcom_sms.idl index de77d99e..ae37d285 100644 --- a/dev/SCI/xpcom_sms.idl +++ b/dev/SCI/xpcom_sms.idl @@ -3,7 +3,7 @@ Copyright ZKA Technologies. File: rt.internal.inl -Purpose: Base code of SCM. +Purpose: Base code of XPCOM. ------------------------------------------- */ diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 9cccc922..3e78414c 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -211,11 +211,10 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handoverHdrPtr->f_BitMapStart = 0; - while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk) + while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverBitMapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk) ; - handoverHdrPtr->f_VirtualSize = - Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ + handoverHdrPtr->f_BitMapSize = kHandoverBitMapSz; /* # of pages */ handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST; @@ -291,13 +290,13 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, urbanistTTF.Blob()) { handoverHdrPtr->f_StartupChime = chimeWav.Blob(); - handoverHdrPtr->f_ChimeSz = chimeWav.Size(); + handoverHdrPtr->f_ChimeSz = chimeWav.Size(); handoverHdrPtr->f_StartupImage = readerSysDrv.Blob(); - handoverHdrPtr->f_StartupSz = readerSysDrv.Size(); + handoverHdrPtr->f_StartupSz = readerSysDrv.Size(); handoverHdrPtr->f_KernelImage = readerKernel.Blob(); - handoverHdrPtr->f_KernelSz = readerKernel.Size(); + handoverHdrPtr->f_KernelSz = readerKernel.Size(); handoverHdrPtr->f_TTFallbackFont = urbanistTTF.Blob(); - handoverHdrPtr->f_FontSz = urbanistTTF.Size(); + handoverHdrPtr->f_FontSz = urbanistTTF.Size(); } else { diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 1f8bf1b1..0e159c41 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -36,7 +36,7 @@ EMU_FLAGS=-net none -m 8G -M q35 \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -serial stdio -no-reboot + -device ide-hd,drive=disk_2,bus=ahci.0 -d int -no-reboot -no-shutdown LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/FSKit/NeFS.hxx b/dev/ZKA/FSKit/NeFS.hxx index 2bf17863..7bec2a4b 100644 --- a/dev/ZKA/FSKit/NeFS.hxx +++ b/dev/ZKA/FSKit/NeFS.hxx @@ -26,80 +26,83 @@ default. @author Amlal EL Mahrouss */ -#define kNeFSInvalidFork (-1) +#define kNeFSInvalidFork (-1) #define kNeFSInvalidCatalog (-1) -#define kNeFSNodeNameLen (256) +#define kNeFSNodeNameLen (256) -#define kNeFSSectorSz (512) -#define kNeFSForkDataSz (kib_cast(8)) +#define kNeFSSectorSz (512) +#define kNeFSForkDataSz (kib_cast(8)) #define kNeFSIdentLen (8) -#define kNeFSIdent " NeFS" -#define kNeFSPadLen (392) +#define kNeFSIdent " NeFS" +#define kNeFSPadLen (392) #define kNeFSMetaFilePrefix '$' #define kNeFSVersionInteger (0x0128) -#define kNeFSVerionString "1.28" +#define kNeFSVerionString "1.28" /// @brief Standard fork types. -#define kNeFSDataFork "main_data" +#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 kNeFSCatalogKindDir (2) #define kNeFSCatalogKindAlias (3) -#define kNeFSForkSize (512) - -//! shared between network or -//! other filesystems. Export forks as .zip when copying. +//! Shared between network and/or partitions. Export forks as .zip when copying. #define kNeFSCatalogKindShared (4) -#define kNeFSCatalogKindResource (5) +#define kNeFSCatalogKindResource (5) #define kNeFSCatalogKindExecutable (6) #define kNeFSCatalogKindPage (8) -#define kNeFSPartitionTypeStandard (7) -#define kNeFSPartitionTypePage (8) -#define kNeFSPartitionTypeBoot (9) - #define kNeFSCatalogKindDevice (9) -#define kNeFSCatalogKindLock (10) +#define kNeFSCatalogKindLock (10) -#define kNeFSCatalogKindRLE (11) +#define kNeFSCatalogKindRLE (11) #define kNeFSCatalogKindMetaFile (12) -#define kNeFSCatalogKindTTF (13) -#define kNeFSCatalogKindRIFF (14) -#define kNeFSSeparator '\\' +#define kNeFSCatalogKindTTF (13) +#define kNeFSCatalogKindRIFF (14) + +#define kNeFSSeparator '\\' #define kNeFSSeparatorAlt '/' -#define kNeFSUpDir ".." -#define kNeFSRoot "\\" +#define kNeFSUpDir ".." +#define kNeFSRoot "\\" #define kNeFSRootAlt "/" -#define kNeFSLF '\r' +#define kNeFSLF '\r' #define kNeFSEOF (-1) #define kNeFSBitWidth (sizeof(Kernel::Char)) #define kNeFSLbaType (Kernel::Lba) -/// Start After the PM headers, pad 1024 bytes. +/// @note Start after the partition map header. (Virtual addressing) #define kNeFSRootCatalogStartAddress (1024) -#define kNeFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK)) +#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 kNeFSFlagDeleted (70) #define kNeFSFlagUnallocated (0) -#define kNeFSFlagCreated (71) +#define kNeFSFlagCreated (71) #define kNeFSMimeNameLen (200) @@ -111,14 +114,14 @@ struct NFS_ROOT_PARTITION_BLOCK; enum { - kNeFSHardDrive = 0xC0, // Hard Drive - kNeFSSolidStateDrive = 0xC1, // Solid State Drive - kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD + 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, + kNeFSScsi = 0xC4, // SCSI Hard Drive + kNeFSFlashDrive = 0xC6, + kNeFSUnknown = 0xFF, // Unknown device. + kNeFSDriveCount = 7, }; /// @brief Catalog type. @@ -225,7 +228,7 @@ namespace Kernel { public: explicit NeFSParser() = default; - ~NeFSParser() = default; + ~NeFSParser() = default; public: ZKA_COPY_DEFAULT(NeFSParser); @@ -236,15 +239,15 @@ namespace Kernel /// @param theFork the fork itself. /// @return the fork _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork); + _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); + _Input const Char* name, + Boolean dataOrRsrc); _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); @@ -254,7 +257,7 @@ namespace Kernel _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); - _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind); @@ -264,12 +267,12 @@ namespace Kernel _Input Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, - _Input const Char* forkName); + _Input const Char* forkName); VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, _Input Bool isRsrcFork, _Input SizeT dataSz, - _Input const Char* forkName); + _Input const Char* forkName); bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index b4558560..8d25ec6d 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -24,7 +24,7 @@ #define kHandoverMagic 0xBADCC #define kHandoverVersion 0x114 -#define kHandoverHeapSz gib_cast(3) +#define kHandoverBitMapSz gib_cast(3) #define kHandoverStructSz sizeof(HEL::HandoverInformationHeader) namespace Kernel::HEL @@ -57,7 +57,7 @@ namespace Kernel::HEL UInt64 f_Version; VoidPtr f_BitMapStart; - SizeT f_VirtualSize; + SizeT f_BitMapSize; VoidPtr f_PhysicalStart; VoidPtr f_KernelImage; diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 221cb044..800d8b3d 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -6,7 +6,7 @@ #include -#define cVMHMagic ((Kernel::UIntPtr)0x10210) +#define cBitMpMagic ((Kernel::UIntPtr)0x10210) #ifdef __ZKA_AMD64__ #include @@ -29,21 +29,47 @@ namespace Kernel /// @return The new address which was found. VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept { + auto base = reinterpret_cast(base_ptr); + while (base_ptr && size) { UIntPtr* ptr_bit_set = reinterpret_cast(base_ptr); - if (ptr_bit_set[0] != cVMHMagic) + if (ptr_bit_set[0] == cBitMpMagic) + { + if (ptr_bit_set[1] != 0 && + ptr_bit_set[1] <= size && + ptr_bit_set[2] == No) + { + ptr_bit_set[1] = size; + ptr_bit_set[2] = Yes; + + kcout << "BMPMgr: Allocated pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; + + if (rw) + mm_update_pte(base_ptr, eFlagsRw); + + if (user) + mm_update_pte(base_ptr, eFlagsUser); + + return (VoidPtr)ptr_bit_set; + } + } + else { - ptr_bit_set[0] = cVMHMagic; + UIntPtr* ptr_bit_set = reinterpret_cast(base_ptr); + + ptr_bit_set[0] = cBitMpMagic; ptr_bit_set[1] = size; - ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + ptr_bit_set[2] = Yes; - kcout << "ALLOC STATUS\r"; - kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; - kcout << "ALLOC STATUS\r"; + kcout << "BMPMgr: Allocated pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; if (rw) mm_update_pte(base_ptr, eFlagsRw); @@ -54,7 +80,10 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } - base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + __BIGGEST_ALIGNMENT__ + ptr_bit_set[1]); + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + (ptr_bit_set[0] != cBitMpMagic ? size : ptr_bit_set[1])); + + if (reinterpret_cast(base_ptr) >= (kHandoverHeader->f_BitMapSize + base)) + break; } return nullptr; @@ -73,6 +102,11 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + if (!ptr_new) + { + ke_stop(RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM); + } + return ((UIntPtr*)ptr_new); } @@ -84,18 +118,16 @@ namespace Kernel UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr); if (!ptr_bit_set[0] || - ptr_bit_set[0] != cVMHMagic) + ptr_bit_set[0] != cBitMpMagic) return false; - kcout << "FREE STATUS\r"; - kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; - kcout << "FREE STATUS\r"; + kcout << "BMPMgr: Freed pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; - ptr_bit_set[0] = 0UL; - ptr_bit_set[1] = 0UL; - ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + ptr_bit_set[0] = cBitMpMagic; + ptr_bit_set[2] = No; return true; } diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 79d9c097..c73eed5f 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -93,7 +93,7 @@ EXTERN_C void hal_init_platform( Kernel::Void hal_real_init(Kernel::Void) noexcept { // get page size. - kKernelVirtualSize = kHandoverHeader->f_VirtualSize; + kKernelVirtualSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast( diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index 140c3370..d6bed3ba 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -77,7 +77,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kAllocationInProgress = false; // get page size. - kKernelVirtualSize = kHandoverHeader->f_VirtualSize; + kKernelVirtualSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast( diff --git a/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx index cf5d6754..f5b64883 100644 --- a/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx +++ b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx @@ -90,6 +90,8 @@ namespace Kernel private: explicit HardwareThreadScheduler(); + friend class UserProcessHelper; + public: ~HardwareThreadScheduler(); ZKA_COPY_DEFAULT(HardwareThreadScheduler); diff --git a/dev/ZKA/KernelKit/IPEFDLLObject.hxx b/dev/ZKA/KernelKit/IPEFDLLObject.hxx index 013173d1..91e0d1ff 100644 --- a/dev/ZKA/KernelKit/IPEFDLLObject.hxx +++ b/dev/ZKA/KernelKit/IPEFDLLObject.hxx @@ -98,8 +98,8 @@ namespace Kernel typedef IPEFDLLObject* IDLL; - EXTERN_C IDLL rtl_init_shared_object(UserProcess* header); - EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful); + 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/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index 9585da29..c35b65e1 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -295,10 +295,10 @@ namespace Kernel { public: STATIC bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, const PID& new_pid); - STATIC bool CanBeScheduled(UserProcess& process); + STATIC bool CanBeScheduled(const UserProcess process); STATIC PID& TheCurrentPID(); STATIC SizeT StartScheduling(); - STATIC Void Init(); + }; const UInt32& sched_get_exit_code(void) noexcept; diff --git a/dev/ZKA/NewKit/Ref.hxx b/dev/ZKA/NewKit/Ref.hxx index 7f5167c2..5a2bf091 100644 --- a/dev/ZKA/NewKit/Ref.hxx +++ b/dev/ZKA/NewKit/Ref.hxx @@ -32,7 +32,7 @@ namespace Kernel if (!fClass) return *this; - *fClass = ref; + fClass = &ref; return *this; } diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx index 1d4f4a6e..49968e73 100644 --- a/dev/ZKA/Sources/CodeMgr.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -14,10 +14,10 @@ namespace Kernel /// @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* processName) noexcept + bool sched_execute_thread(MainKind main, const Char* process_name) noexcept { if (!main) - return false; + return No; UserProcess proc; proc.SetImageStart(reinterpret_cast(main)); @@ -25,8 +25,8 @@ namespace Kernel proc.Kind = UserProcess::kExeKind; proc.StackSize = mib_cast(4); - rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); + rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name)); - return UserProcessScheduler::The().Add(proc) == kErrorSuccess; + return UserProcessScheduler::The().Add(proc) != 0; } } // namespace Kernel diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx index 2aed9bf7..d8d1ea6e 100644 --- a/dev/ZKA/Sources/ExeMain.cxx +++ b/dev/ZKA/Sources/ExeMain.cxx @@ -65,11 +65,11 @@ namespace Kernel::Detail CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } - const Kernel::SizeT cDirCount = 7UL; + const Kernel::SizeT cDirCount = 9UL; const Kernel::Char* cDirStr[cDirCount] = { "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", - "\\Users\\", "\\Library\\", "\\Mount\\"}; + "\\Users\\", "\\Library\\", "\\Mount\\", "\\Games\\", "\\Applications\\Java\\"}; if (fNeFS->GetParser()) { @@ -117,11 +117,18 @@ EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void) } } +namespace Kernel +{ + EXTERN UserProcessScheduler* cProcessScheduler; +} + /// @brief Application entrypoint. /// @param Void /// @return Void EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { + Kernel::cProcessScheduler = nullptr; + CG::CGDrawBackground(); cKernelWnd = nullptr; @@ -148,8 +155,7 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0)); - Kernel::UserProcessHelper::Init(); - + Kernel::UserProcessHelper::StartScheduling(); Kernel::sched_execute_thread(HangCPU, "HANG TEST"); while (Yes) diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx index 68078ec3..409ca663 100644 --- a/dev/ZKA/Sources/FS/NeFS.cxx +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -814,8 +814,8 @@ NeFSSearchThroughCatalogList: 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; + kcout << "Found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "Found catalog at: " << catalog->Name << endl; out_lba = startCatalogList; return catalogPtr; diff --git a/dev/ZKA/Sources/HardwareThreadScheduler.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx index b130ef63..c5d04bbc 100644 --- a/dev/ZKA/Sources/HardwareThreadScheduler.cxx +++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx @@ -17,6 +17,8 @@ namespace Kernel { + HardwareThreadScheduler* cHardwareThreadScheduler = nullptr; + ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -107,7 +109,7 @@ namespace Kernel { mp_do_context_switch_pre(); mp_do_context_switch(image, stack_ptr, fStack); - + return true; } } @@ -124,7 +126,10 @@ namespace Kernel ///! @brief Constructor and destructors. ///! @brief Default constructor. - HardwareThreadScheduler::HardwareThreadScheduler() = default; + HardwareThreadScheduler::HardwareThreadScheduler() + { + kcout << "Initializing class done!" << endl; + } ///! @brief Default destructor. HardwareThreadScheduler::~HardwareThreadScheduler() = default; @@ -132,8 +137,8 @@ namespace Kernel /// @brief Shared singleton function HardwareThreadScheduler& HardwareThreadScheduler::The() { - STATIC HardwareThreadScheduler sched; - return sched; + MUST_PASS(cHardwareThreadScheduler); + return *cHardwareThreadScheduler; } /// @brief Get Stack Frame of Core diff --git a/dev/ZKA/Sources/IPEFDLLObject.cxx b/dev/ZKA/Sources/IPEFDLLObject.cxx index 913912a4..a8505eb3 100644 --- a/dev/ZKA/Sources/IPEFDLLObject.cxx +++ b/dev/ZKA/Sources/IPEFDLLObject.cxx @@ -18,11 +18,11 @@ Revision History: - 01/02/24: Rework shared sharedObj ABI, except a rtl_init_shared_object and - rtl_fini_shared_object (amlel) 15/02/24: Breaking changes, changed the name of the + 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_shared_object + 07/28/24: Replace rt_library_free with rtl_fini_dll ------------------------------------------- */ @@ -37,7 +37,7 @@ using namespace Kernel; /** @brief Library initializer. */ /***********************************************************************************/ -EXTERN_C IDLL rtl_init_shared_object(UserProcess* header) +EXTERN_C IDLL rtl_init_dll(UserProcess* header) { IDLL sharedObj = tls_new_class(); @@ -80,7 +80,7 @@ EXTERN_C IDLL rtl_init_shared_object(UserProcess* header) /** @param successful Reports if successful or not. */ /***********************************************************************************/ -EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful) +EXTERN_C Void rtl_fini_dll(UserProcess* header, IDLL lib, Bool* successful) { MUST_PASS(successful); diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index 35f2dbcd..825761de 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -21,42 +21,6 @@ using namespace Kernel; -namespace Kernel::Detail -{ - /// \brief UserProcess thread information header. - struct THREAD_HEADER_BLOCK final - { - STATIC constexpr SizeT cMaxLen = 256; - - Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"}; - ProcessStatusKind fThreadStatus; - Int64 fThreadID; - UIntPtr fCode{0}; - UIntPtr fStack{0}; - UIntPtr fData{0}; - - Void Exit() noexcept - { - this->fThreadStatus = ProcessStatusKind::kKilled; - } - - UIntPtr GetStack() noexcept - { - return fStack; - } - - UIntPtr GetData() noexcept - { - return fData; - } - - UIntPtr GetPC() noexcept - { - return fCode; - } - }; -} // namespace Detail - /** * @brief Checks for cookie inside the TIB. * @param tib the TIB to check. diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 8c46b1cf..f480bccc 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -12,6 +12,7 @@ /// @brief User Process scheduler. /***********************************************************************************/ +#include "HALKit/AMD64/Processor.hxx" #include #include #include @@ -213,7 +214,7 @@ namespace Kernel if (this->Kind == kDLLKind) { Bool success = false; - rtl_fini_shared_object(this, this->DLLPtr, &success); + rtl_fini_dll(this, this->DLLPtr, &success); if (success) { @@ -237,7 +238,7 @@ namespace Kernel process.MemoryPD = reinterpret_cast(hal_read_cr3()); #endif // __ZKA_AMD64__ - process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame)); + process.StackFrame = new HAL::StackFrame(0); if (!process.StackFrame) { @@ -248,28 +249,26 @@ namespace Kernel // Create heap according to type of process. if (process.Kind == UserProcess::kDLLKind) { - process.DLLPtr = rtl_init_shared_object(&process); + process.DLLPtr = rtl_init_dll(&process); } - if (process.Image) + if (!process.Image) { - // get preferred stack size by app. - const auto cMaxStackSize = process.StackSize; - process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize); - - if (process.StackReserve) + if (process.Kind != UserProcess::kDLLKind) { process.Crash(); return -kErrorProcessFault; } } - else + + // get preferred stack size by app. + const auto cMaxStackSize = process.StackSize; + process.StackReserve = new UInt8[cMaxStackSize]; + + if (!process.StackReserve) { - if (process.Kind != UserProcess::kDLLKind) - { - process.Crash(); - return -kErrorProcessFault; - } + process.Crash(); + return -kErrorProcessFault; } process.Status = ProcessStatusKind::kStarting; @@ -277,9 +276,6 @@ namespace Kernel ++mTeam.mProcessAmount; - while (1) - ; - mTeam.AsArray()[process.ProcessId] = process; return process.ProcessId; @@ -318,6 +314,8 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. + kcout << "Finding available process...\r"; + for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { auto& process = mTeam.AsArray()[process_index]; @@ -326,7 +324,7 @@ namespace Kernel if (UserProcessHelper::CanBeScheduled(process)) { // set the current process. - mTeam.AsRef() = mTeam.AsArray()[process.ProcessId]; + mTeam.AsRef() = process; process.PTime = static_cast(process.Affinity); @@ -339,10 +337,6 @@ namespace Kernel process.Crash(); continue; } - - process.Exit(); - - continue; } else { @@ -378,35 +372,16 @@ namespace Kernel return cProcessScheduler->CurrentProcess().Leak().ProcessId; } - Void UserProcessHelper::Init() - { - if (mm_is_valid_heap(cProcessScheduler)) - delete cProcessScheduler; - - cProcessScheduler = nullptr; - cProcessScheduler = new UserProcessScheduler(); - MUST_PASS(cProcessScheduler); - } - /// @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(UserProcess& process) + bool UserProcessHelper::CanBeScheduled(const UserProcess process) { if (process.Status == ProcessStatusKind::kFrozen || process.Status == ProcessStatusKind::kDead) return false; - if (process.Kind == UserProcess::kDLLKind) - { - if (auto start = process.DLLPtr->Load(kPefStart, rt_string_len(kPefStart), kPefCode); - start) - { - process.Image = start; - } - } - return process.PTime < 1; } @@ -414,8 +389,21 @@ namespace Kernel * @brief Scheduler helper class. */ + EXTERN + HardwareThreadScheduler* cHardwareThreadScheduler; + SizeT UserProcessHelper::StartScheduling() { + if (!cHardwareThreadScheduler) + { + cHardwareThreadScheduler = new HardwareThreadScheduler(); + } + + if (!cProcessScheduler) + { + cProcessScheduler = new UserProcessScheduler(); + } + SizeT ret = cProcessScheduler->Run(); return ret; } diff --git a/dev/ZKA/Sources/UserThreadScheduler.cxx b/dev/ZKA/Sources/UserThreadScheduler.cxx new file mode 100644 index 00000000..739f00ad --- /dev/null +++ b/dev/ZKA/Sources/UserThreadScheduler.cxx @@ -0,0 +1,49 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include + +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; + Int64* fProcessID{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 Detail -- cgit v1.2.3