diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-09-05 19:13:02 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-09-05 19:13:02 +0000 |
| commit | 621e814da6d5005ade8a1fe3f378a363db559cf7 (patch) | |
| tree | 438f1337c0eb2ae83cf3d409c29848d396be08b2 /dev/ZKA/Sources | |
| parent | cc9ce57cac59bd443e2319e3b8f427172b93f7da (diff) | |
| parent | 3b60a1e87ab02a1b72d8bb9f7392780899d5a0d7 (diff) | |
Merged in major-refactor (pull request #19)
Major refactor
Diffstat (limited to 'dev/ZKA/Sources')
| -rw-r--r-- | dev/ZKA/Sources/CodeMgr.cxx (renamed from dev/ZKA/Sources/CodeManager.cxx) | 4 | ||||
| -rw-r--r-- | dev/ZKA/Sources/CxxAbi-AMD64.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/CxxAbi-ARM64.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/DLLMain.cxx | 111 | ||||
| -rw-r--r-- | dev/ZKA/Sources/DeviceMgr.cxx (renamed from dev/ZKA/Sources/DeviceManager.cxx) | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/DriveMgr.cxx (renamed from dev/ZKA/Sources/DriveManager.cxx) | 16 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FS/FAT32.cxx | 4 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FS/NeFS.cxx (renamed from dev/ZKA/Sources/FS/NewFS.cxx) | 295 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FileMgr.cxx (renamed from dev/ZKA/Sources/FileManager.cxx) | 46 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Framebuffer.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/HardwareThreadScheduler.cxx (renamed from dev/ZKA/Sources/MP.cxx) | 41 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Heap.cxx | 117 | ||||
| -rw-r--r-- | dev/ZKA/Sources/IDLLObject.cxx (renamed from dev/ZKA/Sources/DLLInterface.cxx) | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/IPEFDLLObject.cxx (renamed from dev/ZKA/Sources/PEFDLLInterface.cxx) | 10 | ||||
| -rw-r--r-- | dev/ZKA/Sources/IndexableProperty.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/KernelCheck.cxx | 20 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NeFS+FileMgr.cxx (renamed from dev/ZKA/Sources/NewFS+FileManager.cxx) | 43 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NeFS+IO.cxx (renamed from dev/ZKA/Sources/NewFS+IO.cxx) | 46 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NewFS+Journal.cxx | 22 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PEFCodeMgr.cxx (renamed from dev/ZKA/Sources/PEFCodeManager.cxx) | 4 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PageAllocator.cxx | 13 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PageMgr.cxx (renamed from dev/ZKA/Sources/PageManager.cxx) | 34 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Pmm.cxx | 14 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Storage/ATADeviceInterface.cxx | 4 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ThreadLocalStorage.cxx | 10 | ||||
| -rw-r--r-- | dev/ZKA/Sources/User.cxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/Sources/UserProcessScheduler.cxx | 215 | ||||
| -rw-r--r-- | dev/ZKA/Sources/UserProcessTeam.cxx (renamed from dev/ZKA/Sources/ProcessTeam.cxx) | 0 | ||||
| -rw-r--r-- | dev/ZKA/Sources/compile_flags.txt | 2 |
29 files changed, 492 insertions, 596 deletions
diff --git a/dev/ZKA/Sources/CodeManager.cxx b/dev/ZKA/Sources/CodeMgr.cxx index 7e180ac0..1d4f4a6e 100644 --- a/dev/ZKA/Sources/CodeManager.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <NewKit/Utils.hxx> -#include <KernelKit/CodeManager.hxx> +#include <KernelKit/CodeMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> namespace Kernel @@ -23,7 +23,7 @@ namespace Kernel proc.SetImageStart(reinterpret_cast<VoidPtr>(main)); proc.Kind = UserProcess::kExeKind; - proc.StackSize = kib_cast(8); + proc.StackSize = mib_cast(4); rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); diff --git a/dev/ZKA/Sources/CxxAbi-AMD64.cxx b/dev/ZKA/Sources/CxxAbi-AMD64.cxx index 0b26e9da..908e26f4 100644 --- a/dev/ZKA/Sources/CxxAbi-AMD64.cxx +++ b/dev/ZKA/Sources/CxxAbi-AMD64.cxx @@ -19,7 +19,7 @@ Kernel::UIntPtr __dso_handle; EXTERN_C void __cxa_pure_virtual() { - Kernel::kcout << "newoskrnl.exe: C++ placeholder method.\n"; + kcout << "C++ placeholder method.\n"; } EXTERN_C void ___chkstk_ms(void) diff --git a/dev/ZKA/Sources/CxxAbi-ARM64.cxx b/dev/ZKA/Sources/CxxAbi-ARM64.cxx index c11baf72..679be041 100644 --- a/dev/ZKA/Sources/CxxAbi-ARM64.cxx +++ b/dev/ZKA/Sources/CxxAbi-ARM64.cxx @@ -68,7 +68,7 @@ EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept EXTERN_C void _purecall() { - Kernel::kcout << "newoskrnl.exe: C++ placeholder method.\n"; + kcout << "C++ placeholder method.\n"; } #endif // ifdef __ZKA_ARM64__ diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 934f418c..2aed9bf7 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -11,18 +11,18 @@ #include <ArchKit/ArchKit.hxx> #include <CompilerKit/Detail.hxx> #include <FirmwareKit/Handover.hxx> -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <KernelKit/Framebuffer.hxx> #include <KernelKit/Heap.hxx> #include <KernelKit/PEF.hxx> -#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/PEFCodeMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <NewKit/Json.hxx> #include <NewKit/KernelCheck.hxx> #include <NewKit/String.hxx> #include <NewKit/Utils.hxx> -#include <KernelKit/PEFCodeManager.hxx> -#include <KernelKit/CodeManager.hxx> +#include <KernelKit/PEFCodeMgr.hxx> +#include <KernelKit/CodeMgr.hxx> #include <CFKit/Property.hxx> #include <Modules/CoreCG/WindowRenderer.hxx> #include <KernelKit/Timer.hxx> @@ -44,25 +44,25 @@ namespace Kernel::Detail /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { - Kernel::NewFilesystemManager* fNewFS{nullptr}; + Kernel::NewFilesystemMgr* fNeFS{nullptr}; public: /// @brief wizard constructor. explicit FilesystemInstaller() { - if (Kernel::FilesystemManagerInterface::GetMounted()) + if (Kernel::FilesystemMgrInterface::GetMounted()) { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNewFS = reinterpret_cast<Kernel::NewFilesystemManager*>(Kernel::FilesystemManagerInterface::GetMounted()); + CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); + fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::FilesystemMgrInterface::GetMounted()); } else { - // Mounts a NewFS from main drive. - fNewFS = new Kernel::NewFilesystemManager(); + // Mounts a NeFS from main drive. + fNeFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemManagerInterface::Mount(fNewFS); + Kernel::FilesystemMgrInterface::Mount(fNeFS); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } const Kernel::SizeT cDirCount = 7UL; @@ -71,93 +71,50 @@ namespace Kernel::Detail "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", "\\Users\\", "\\Library\\", "\\Mount\\"}; - if (fNewFS->GetParser()) + if (fNeFS->GetParser()) { for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { - auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + auto catalogDir = fNeFS->GetParser()->GetCatalog(cDirStr[dirIndx]); if (catalogDir) { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog directory already exists: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory already exists: ")), RGB(0, 0, 0)); delete catalogDir; continue; } - catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); + catalogDir = fNeFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, + kNeFSCatalogKindDir); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog directory has been created: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory has been created: ")), RGB(0, 0, 0)); delete catalogDir; } } - - NFS_CATALOG_STRUCT* catalogDisk = - this->fNewFS->GetParser()->GetCatalog(kSysPage); - const Kernel::Char* cSrcName = "8K_SYS_PAGE_KERNEL"; - - if (catalogDisk) - { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog swap file already exists: ")), RGB(0, 0, 0)); - - delete catalogDisk; - } - else - { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog swap file created: ")), RGB(0, 0, 0)); - - catalogDisk = - (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(kSysPage); - - NFS_FORK_STRUCT theDiskFork{0}; - - Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); - - Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); - - Kernel::Size sz_hdr = kNewFSForkSz; - - theDiskFork.DataSize = sz_hdr; - theDiskFork.ResourceId = kNewFSCatalogKindExecutable | kNewFSCatalogKindPage; - theDiskFork.ResourceKind = Kernel::kNewFSDataForkKind; - theDiskFork.Kind = Kernel::kNewFSDataForkKind; - - fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); - - delete catalogDisk; - } } ~FilesystemInstaller() = default; ZKA_COPY_DEFAULT(FilesystemInstaller); - /// @brief Grab the disk's NewFS reference. - /// @return NewFilesystemManager the filesystem interface - Kernel::NewFilesystemManager* Leak() + /// @brief Grab the disk's NeFS reference. + /// @return NewFilesystemMgr the filesystem interface + Kernel::NewFilesystemMgr* Leak() { - return fNewFS; + return fNeFS; } }; } // namespace Kernel::Detail -namespace Kernel +EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void) { - EXTERN UserProcessScheduler* cProcessScheduler; -} // namespace Kernel - -EXTERN_C Kernel::Void HangCPU(Kernel::Void) -{ - while (1); + while (Yes) + { + } } /// @brief Application entrypoint. @@ -186,14 +143,12 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawWindowList(&cKernelWnd, 1); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Running System Component: ", 10, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("newoskrnl.exe: Running System Component: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Running System Component: ", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running System Component: ")), RGB(0, 0, 0)); - /// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. - Kernel::cProcessScheduler = nullptr; - Kernel::UserProcessHelper::StartScheduling(); + CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Starting ZKA System...", 20, 10, RGB(0, 0, 0)); + Kernel::UserProcessHelper::Init(); Kernel::sched_execute_thread(HangCPU, "HANG TEST"); @@ -201,6 +156,4 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { Kernel::UserProcessHelper::StartScheduling(); } - - Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } diff --git a/dev/ZKA/Sources/DeviceManager.cxx b/dev/ZKA/Sources/DeviceMgr.cxx index 229e0fb7..70d01984 100644 --- a/dev/ZKA/Sources/DeviceManager.cxx +++ b/dev/ZKA/Sources/DeviceMgr.cxx @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include <KernelKit/DeviceManager.hxx> +#include <KernelKit/DeviceMgr.hxx> diff --git a/dev/ZKA/Sources/DriveManager.cxx b/dev/ZKA/Sources/DriveMgr.cxx index 84c9870f..5d0f7fc3 100644 --- a/dev/ZKA/Sources/DriveManager.cxx +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -5,18 +5,21 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.hxx> -#include <KernelKit/DriveManager.hxx> +#include <KernelKit/DriveMgr.hxx> +#include <NewKit/Utils.hxx> + + #include <Modules/ATA/ATA.hxx> #include <Modules/AHCI/AHCI.hxx> -#include <NewKit/Utils.hxx> +#include <Modules/NVME/Defines.hxx> -/// @file DriveManager.cxx +/// @file DriveMgr.cxx /// @brief Kernel drive manager. namespace Kernel { - static UInt16 kATAIO = 0U; - static UInt8 kATAMaster = 0U; + STATIC UInt16 kATAIO = 0U; + STATIC UInt8 kATAMaster = 0U; /// @brief reads from an ATA drive. /// @param pckt @@ -106,6 +109,7 @@ namespace Kernel /// @return Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) { + ZKA_UNUSED(pckt); } /// @brief Makes a new drive. @@ -139,7 +143,7 @@ namespace Kernel trait.fVerify = ke_drv_check_disk; trait.fDriveKind = io_drive_kind; - kcout << "newoskrnl.exe: Construct drive with success.\r"; + kcout << "Construct drive with success.\r"; return trait; } diff --git a/dev/ZKA/Sources/FS/FAT32.cxx b/dev/ZKA/Sources/FS/FAT32.cxx index 1f5e194b..9e22e2a8 100644 --- a/dev/ZKA/Sources/FS/FAT32.cxx +++ b/dev/ZKA/Sources/FS/FAT32.cxx @@ -4,9 +4,9 @@ ------------------------------------------- */ -#ifdef __FSKIT_INCLUDES_FAT32__ +#ifdef __FSKIT_INCLUDES_HPFS__ #include <FirmwareKit/GPT.hxx> #include <FirmwareKit/EPM.hxx> -#endif // ifdef __FSKIT_INCLUDES_FAT32__ +#endif // ifdef __FSKIT_INCLUDES_HPFS__ diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx index bf55a56f..68078ec3 100644 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -4,12 +4,12 @@ ------------------------------------------- */ -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ #include <Modules/AHCI/AHCI.hxx> #include <Modules/ATA/ATA.hxx> #include <Modules/Flash/Flash.hxx> -#include <FSKit/NewFS.hxx> +#include <FSKit/NeFS.hxx> #include <KernelKit/LPC.hxx> #include <NewKit/Crc32.hxx> #include <NewKit/KernelCheck.hxx> @@ -59,17 +59,18 @@ STATIC MountpointInterface sMountpointInterface; /// @param theFork the fork itself. /// @return the fork /***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, +_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, _Input NFS_FORK_STRUCT& theFork) { - if (catalog && theFork.ForkName[0] != 0) + if (catalog && theFork.ForkName[0] != 0 && + theFork.DataSize <= kNeFSForkDataSz) { - Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork + Lba lba = (theFork.Kind == kNeFSDataForkKind) ? catalog->DataFork : catalog->ResourceFork; - kcout << "newoskrnl.exe: fork lba: " << hex_number(lba) << endl; + kcout << "fork lba: " << hex_number(lba) << endl; - if (lba <= kNewFSCatalogStartAddress) + if (lba <= kNeFSCatalogStartAddress) return nullptr; auto drv = sMountpointInterface.A(); @@ -85,7 +86,7 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata /// do not check for anything. Loop until we get what we want, that is a free fork zone. while (true) { - if (lba <= kNewFSCatalogStartAddress) + if (lba <= kNeFSCatalogStartAddress) break; drv.fPacket.fLba = lba; @@ -96,22 +97,22 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata if (curFork.NextSibling > kBadAddress) { - kcout << "newoskrnl.exe: bad fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; break; } - kcout << "newoskrnl.exe: next fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - if (curFork.Flags == kNewFSFlagCreated) + if (curFork.Flags == kNeFSFlagCreated) { - kcout << "newoskrnl.exe: fork already exists.\r"; + kcout << "fork already exists.\r"; /// sanity check. if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && StringBuilder::Equals(curFork.CatalogName, catalog->Name)) return nullptr; - kcout << "newoskrnl.exe: next fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; lbaOfPreviousFork = lba; lba = curFork.NextSibling; @@ -122,7 +123,7 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata { /// This is a check that we have, in order to link the previous fork /// entry. - if (lba >= kNewFSCatalogStartAddress) + if (lba >= kNeFSCatalogStartAddress) { drv.fPacket.fLba = lbaOfPreviousFork; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); @@ -141,10 +142,10 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata constexpr auto cForkPadding = 4; /// this value gives us space for the data offset. - theFork.Flags = kNewFSFlagCreated; - theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; + theFork.Flags = kNeFSFlagCreated; + theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) - theFork.DataSize; theFork.PreviousSibling = lbaOfPreviousFork; - theFork.NextSibling = theFork.DataOffset - theFork.DataSize; + theFork.NextSibling = theFork.DataOffset + sizeof(NFS_FORK_STRUCT) + theFork.DataSize; drv.fPacket.fLba = lba; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); @@ -153,10 +154,10 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata drv.fOutput(&drv.fPacket); /// log what we have now. - kcout << "newoskrnl.exe: Wrote fork data at: " << hex_number(theFork.DataOffset) + kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) << endl; - kcout << "newoskrnl.exe: Wrote fork at: " << hex_number(lba) << endl; + kcout << "Wrote fork at: " << hex_number(lba) << endl; return &theFork; } @@ -170,7 +171,7 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata /// @param name the fork name. /// @return the fork. /***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, +_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, _Input const Char* name, Boolean isDataFork) { @@ -225,9 +226,9 @@ _Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalo /// @param name /// @return catalog pointer. /***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name) +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name) { - return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); + return this->CreateCatalog(name, 0, kNeFSCatalogKindFile); } /***********************************************************************************/ @@ -237,23 +238,23 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name) /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { - kcout << "newoskrnl.exe: CreateCatalog(...)\r"; + kcout << "CreateCatalog(...)\r"; Lba out_lba = 0UL; - kcout << "newoskrnl.exe: Checking for extension...\r"; + kcout << "Checking for extension...\r"; /// a directory should have a slash in the end. - if (kind == kNewFSCatalogKindDir && + if (kind == kNeFSCatalogKindDir && name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) return nullptr; /// a file shouldn't have a slash in the end. - if (kind != kNewFSCatalogKindDir && + if (kind != kNeFSCatalogKindDir && name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) return nullptr; @@ -261,13 +262,13 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (catalog_copy) { - kcout << "newoskrnl.exe: Catalog already exists: " << name << ".\r"; + kcout << "Catalog already exists: " << name << ".\r"; ErrLocal() = kErrorFileExists; return catalog_copy; } - Char parentName[kNewFSNodeNameLen] = {0}; + Char parentName[kNeFSNodeNameLen] = {0}; for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) { @@ -276,7 +277,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (*parentName == 0) { - kcout << "newoskrnl.exe: Parent name is NUL.\r"; + kcout << "Parent name is NUL.\r"; ErrLocal() = kErrorFileNotFound; return nullptr; } @@ -306,29 +307,29 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, auto drive = sMountpointInterface.A(); - if (catalog && catalog->Kind == kNewFSCatalogKindFile) + if (catalog && catalog->Kind == kNeFSCatalogKindFile) { - kcout << "newoskrnl.exe: Parent name is file.\r"; + kcout << "Parent name is file.\r"; delete catalog; return nullptr; } else if (!catalog) { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; drive.fInput(&drive.fPacket); - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; out_lba = partBlock->StartCatalog; } - constexpr SizeT cDefaultForkSize = kNewFSForkSize; + constexpr SizeT cDefaultForkSize = kNeFSForkSize; NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); @@ -340,12 +341,12 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, catalogChild->NextSibling = out_lba; catalogChild->PrevSibling = out_lba; catalogChild->Kind = kind; - catalogChild->Flags = kNewFSFlagCreated | flagsList; + catalogChild->Flags = kNeFSFlagCreated | flagsList; rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, rt_string_len(name)); - UInt16 catalogBuf[kNewFSSectorSz] = {0}; + UInt16 catalogBuf[kNeFSSectorSz] = {0}; Lba start_free = out_lba; @@ -353,7 +354,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, rt_string_len("fs/newfs-packet")); drive.fPacket.fPacketContent = catalogBuf; - drive.fPacket.fPacketSize = kNewFSSectorSz; + drive.fPacket.fPacketSize = kNeFSSectorSz; drive.fPacket.fLba = start_free; drive.fInput(&drive.fPacket); @@ -371,7 +372,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, { nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf); - if (start_free <= kNewFSRootCatalogStartAddress) + if (start_free <= kNeFSRootCatalogStartAddress) { delete catalogChild; delete catalog; @@ -382,17 +383,17 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, // ========================== // // Allocate catalog now... // ========================== // - if ((nextSibling->Flags & kNewFSFlagCreated) == 0) + if ((nextSibling->Flags & kNeFSFlagCreated) == 0) { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; drive.fInput(&drive.fPacket); - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; @@ -410,7 +411,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (!StringBuilder::Equals(parentName, nextSibling->Name)) { catalogChild->NextSibling = - start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); + start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); } drive.fPacket.fPacketContent = catalogChild; @@ -419,11 +420,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, drive.fOutput(&drive.fPacket); - // Get NewFS partition's block. + // Get NeFS partition's block. drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; drive.fInput(&drive.fPacket); @@ -433,27 +434,27 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, drive.fOutput(&drive.fPacket); - kcout << "newoskrnl.exe: Create new catalog, status: " + kcout << "Create new catalog, status: " << hex_number(catalogChild->Flags) << endl; - kcout << "newoskrnl.exe: Create new catalog, name: " << catalogChild->Name + kcout << "Create new catalog, name: " << catalogChild->Name << endl; delete catalog; return catalogChild; } - else if ((nextSibling->Flags & kNewFSFlagCreated) && + else if ((nextSibling->Flags & kNeFSFlagCreated) && StringBuilder::Equals(nextSibling->Name, name)) { return nextSibling; } - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; //// @note that's how we find the next catalog in the partition block. - start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); + start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); drive.fPacket.fPacketContent = catalogBuf; - drive.fPacket.fPacketSize = kNewFSSectorSz; + drive.fPacket.fPacketSize = kNeFSSectorSz; drive.fPacket.fLba = start_free; drive.fInput(&drive.fPacket); @@ -463,10 +464,10 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, return nullptr; } -/// @brief Make a EPM+NewFS drive out of the disk. +/// @brief Make a EPM+NeFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see ErrLocal(). -bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) +bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) { if (*part_name == 0 || endLba == 0) @@ -485,40 +486,40 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL return false; } - Char fs_buf[kNewFSSectorSz] = {0}; + Char fs_buf[kNeFSSectorSz] = {0}; - Lba start = kNewFSRootCatalogStartAddress; + Lba start = kNeFSRootCatalogStartAddress; drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; + drive->fPacket.fPacketSize = kNeFSSectorSz; drive->fPacket.fLba = start; drive->fInput(&drive->fPacket); - if (flags & kNewFSPartitionTypeBoot) + if (flags & kNeFSPartitionTypeBoot) { // make it bootable when needed. - Char bufEpmHdr[kNewFSSectorSz] = {0}; + Char bufEpmHdr[kNeFSSectorSz] = {0}; BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; // EPM header. - constexpr auto cFsName = "NewFS"; + constexpr auto cFsName = "NeFS"; constexpr auto cBlockName = "ZKA:"; rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); - epmBoot->FsVersion = kNewFSVersionInteger; + epmBoot->FsVersion = kNeFSVersionInteger; epmBoot->LbaStart = start; - epmBoot->SectorSz = kNewFSSectorSz; + epmBoot->SectorSz = kNeFSSectorSz; rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); Lba outEpmLba = kEpmBase; - Char buf[kNewFSSectorSz]; + Char buf[kNeFSSectorSz]; Lba prevStart = 0; SizeT cnt = 0; @@ -526,7 +527,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL while (drive->fPacket.fPacketGood) { drive->fPacket.fPacketContent = buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; + drive->fPacket.fPacketSize = kNeFSSectorSz; drive->fPacket.fLba = outEpmLba; drive->fInput(&drive->fPacket); @@ -542,7 +543,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL epmBoot->NumBlocks = cnt; drive->fPacket.fPacketContent = bufEpmHdr; - drive->fPacket.fPacketSize = kNewFSSectorSz; + drive->fPacket.fPacketSize = kNeFSSectorSz; drive->fPacket.fLba = outEpmLba; drive->fOutput(&drive->fPacket); @@ -566,16 +567,16 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL // check for an empty partition here. if (partBlock->PartitionName[0] == 0 && - rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) + rt_string_cmp(partBlock->Ident, kNeFSIdent, kNeFSIdentLen)) { // partition is free and valid. - partBlock->Version = kNewFSVersionInteger; + partBlock->Version = kNeFSVersionInteger; const auto cUntitledHD = part_name; - rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, - kNewFSIdentLen); + rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)partBlock->Ident, + kNeFSIdentLen); rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, rt_string_len(cUntitledHD)); @@ -585,41 +586,41 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL SizeT sectorCount = drv_std_get_sector_count(); SizeT diskSize = drv_std_get_drv_size(); - partBlock->Kind = kNewFSPartitionTypeStandard; - partBlock->StartCatalog = kNewFSCatalogStartAddress; - partBlock->Flags = kNewFSPartitionTypeStandard; + partBlock->Kind = kNeFSPartitionTypeStandard; + partBlock->StartCatalog = kNeFSCatalogStartAddress; + partBlock->Flags = kNeFSPartitionTypeStandard; partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); partBlock->SectorCount = sectorCount; partBlock->DiskSize = diskSize; partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSRootCatalogStartAddress; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = kNeFSRootCatalogStartAddress; drive->fOutput(&drive->fPacket); - kcout << "newoskrnl.exe: drive kind: " << drive->fDriveKind() << endl; + kcout << "drive kind: " << drive->fDriveKind() << endl; - kcout << "newoskrnl.exe: partition name: " << partBlock->PartitionName << endl; - kcout << "newoskrnl.exe: start: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "newoskrnl.exe: number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "newoskrnl.exe: free catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "newoskrnl.exe: free sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "newoskrnl.exe: sector size: " << hex_number(partBlock->SectorSize) << endl; + kcout << "partition name: " << partBlock->PartitionName << endl; + kcout << "start: " << hex_number(partBlock->StartCatalog) << endl; + kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; + kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl; + kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl; + kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl; // write the root catalog. - this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); + this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); return true; } - kcout << "newoskrnl.exe: partition block already exists.\r"; + kcout << "partition block already exists.\r"; start += partBlock->DiskSize; drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; + drive->fPacket.fPacketSize = kNeFSSectorSz; drive->fPacket.fLba = start; drive->fInput(&drive->fPacket); @@ -632,8 +633,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL /// @param catalog the catalog itself /// @param data the data. /// @return if the catalog w rote the contents successfully. -bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) +bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) { + if (sizeOfData > kNeFSForkDataSz || + sizeOfData == 0) + return No; + + auto buf = new UInt8[kNeFSForkDataSz]; + rt_copy_memory(data, buf, sizeOfData); + auto drive = sMountpointInterface.A(); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, @@ -646,7 +654,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool NFS_FORK_STRUCT prevFork{}; // sanity check of the fork position as the condition to run the loop. - while (startFork >= kNewFSCatalogStartAddress) + while (startFork >= kNeFSCatalogStartAddress) { drive.fPacket.fPacketContent = forkDataIn; drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); @@ -655,50 +663,43 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool drive.fInput(&drive.fPacket); // check the fork, if it's position is valid. - if (forkDataIn->DataOffset <= kNewFSCatalogStartAddress) + if (forkDataIn->DataOffset <= kNeFSCatalogStartAddress) { ErrLocal() = kErrorDiskIsCorrupted; - kcout << "newoskrnl.exe: Invalid fork offset.\r"; + kcout << "Invalid fork offset.\r"; return false; } - if (forkDataIn->Flags != kNewFSFlagUnallocated && - forkDataIn->Flags != kNewFSFlagDeleted && + if (forkDataIn->Flags != kNeFSFlagUnallocated && + forkDataIn->Flags != kNeFSFlagDeleted && StringBuilder::Equals(forkDataIn->ForkName, forkName) && - StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) + StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name) && + forkDataIn->DataSize == sizeOfData) { // ===================================================== // - // Store size of blob now. + // Store the blob now. // ===================================================== // - if (forkDataIn->DataSize < sizeOfData && - forkDataIn->DataSize < 1) - { - startFork = forkDataIn->NextSibling; - continue; - } - - forkDataIn->Flags = kNewFSFlagCreated; - forkDataIn->DataOffset = startFork + sizeof(NFS_FORK_STRUCT); - forkDataIn->DataSize = sizeOfData; + forkDataIn->Flags = kNeFSFlagCreated; - drive.fPacket.fPacketContent = data; - drive.fPacket.fPacketSize = sizeOfData; - drive.fPacket.fLba = startFork + sizeof(NFS_FORK_STRUCT); + drive.fPacket.fPacketContent = buf; + drive.fPacket.fPacketSize = kNeFSForkDataSz; + drive.fPacket.fLba = forkDataIn->DataOffset; - kcout << "newoskrnl.exe: data offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; drive.fOutput(&drive.fPacket); - drive.fPacket.fPacketContent = &forkDataIn; + drive.fPacket.fPacketContent = forkDataIn; drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; + drive.fPacket.fLba = startFork - sizeof(NFS_FORK_STRUCT); drive.fOutput(&drive.fPacket); - kcout << "newoskrnl.exe: wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "wrote fork at offset: " << hex_number(startFork - sizeof(NFS_FORK_STRUCT)) << endl; delete catalog; @@ -718,10 +719,10 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool /// @brief /// @param catalogName the catalog name. /// @return the newly found catalog. -_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogName, +_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName, Lba& out_lba) { - kcout << "newoskrnl.exe: start finding catalog...\r"; + kcout << "start finding catalog...\r"; NFS_ROOT_PARTITION_BLOCK fs_buf{0}; auto drive = sMountpointInterface.A(); @@ -731,7 +732,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogN drive.fPacket.fPacketContent = &fs_buf; drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; drive.fInput(&drive.fPacket); @@ -752,7 +753,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogN if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) { - Char parentName[kNewFSNodeNameLen] = {0}; + Char parentName[kNeFSNodeNameLen] = {0}; for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) { @@ -789,9 +790,9 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogN } } - kcout << "newoskrnl.exe: fetching catalog...\r"; + kcout << "fetching catalog...\r"; -NewFSSearchThroughCatalogList: +NeFSSearchThroughCatalogList: while (drive.fPacket.fPacketGood) { drive.fPacket.fLba = startCatalogList; @@ -805,25 +806,25 @@ NewFSSearchThroughCatalogList: if (StringBuilder::Equals(catalogName, catalog->Name)) { /// ignore unallocated catalog, break - if (!(catalog->Flags & kNewFSFlagCreated)) + if (!(catalog->Flags & kNeFSFlagCreated)) { - goto NewFSContinueSearch; + goto NeFSContinueSearch; } NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); - kcout << "newoskrnl.exe: found catalog at: " << hex_number(startCatalogList) << endl; - kcout << "newoskrnl.exe: 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; } - NewFSContinueSearch: + NeFSContinueSearch: startCatalogList = catalog->NextSibling; - if (startCatalogList <= kNewFSRootCatalogStartAddress) + if (startCatalogList <= kNeFSRootCatalogStartAddress) break; } @@ -832,7 +833,7 @@ NewFSSearchThroughCatalogList: localSearchFirst = false; startCatalogList = cCtartCatalogList; - goto NewFSSearchThroughCatalogList; + goto NeFSSearchThroughCatalogList; } out_lba = 0UL; @@ -842,7 +843,7 @@ NewFSSearchThroughCatalogList: /// @brief Get catalog from filesystem. /// @param name the catalog's name/ /// @return -_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const Char* name) +_Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name) { Lba unused = 0; return this->FindCatalog(name, unused); @@ -851,7 +852,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const Char* name) /// @brief Closes a catalog, (frees it). /// @param catalog the catalog to close. /// @return -Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) +Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) return false; @@ -865,7 +866,7 @@ Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) /// @brief Mark catalog as removed. /// @param catalog The catalog structure. /// @return if the catalog was removed or not. -Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) +Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) { if (!catalogName || StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) @@ -877,10 +878,10 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) Lba out_lba = 0; auto catalog = this->FindCatalog(catalogName, out_lba); - if (out_lba >= kNewFSCatalogStartAddress || - catalog->Flags == kNewFSFlagCreated) + if (out_lba >= kNeFSCatalogStartAddress || + catalog->Flags == kNeFSFlagCreated) { - catalog->Flags = kNewFSFlagDeleted; + catalog->Flags = kNeFSFlagDeleted; auto drive = sMountpointInterface.A(); @@ -896,7 +897,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; drive.fPacket.fPacketContent = partitionBlockBuf; drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); @@ -928,7 +929,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) /// @return /***********************************************************************************/ -VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, +VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, _Input Bool isRsrcFork, _Input SizeT dataSz, _Input const Char* forkName) @@ -939,12 +940,12 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, return nullptr; } - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; - kcout << "newoskrnl.exe: catalog " << catalog->Name + kcout << "catalog " << catalog->Name << ", fork: " << hex_number(dataForkLba) << endl; NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); @@ -955,7 +956,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, NFS_FORK_STRUCT* fs_fork_data = nullptr; - while (dataForkLba > kNewFSCatalogStartAddress) + while (dataForkLba > kNeFSCatalogStartAddress) { drive.fPacket.fLba = dataForkLba; drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); @@ -965,8 +966,8 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, fs_fork_data = fs_buf; - kcout << "newoskrnl.exe: ForkName: " << fs_fork_data->ForkName << endl; - kcout << "newoskrnl.exe: CatalogName: " << fs_fork_data->CatalogName << endl; + kcout << "ForkName: " << fs_fork_data->ForkName << endl; + kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) @@ -975,7 +976,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, dataForkLba = fs_fork_data->NextSibling; } - if (dataForkLba < kNewFSCatalogStartAddress) + if (dataForkLba < kNeFSCatalogStartAddress) { delete[] fs_buf; return nullptr; @@ -991,7 +992,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, /// @return if the seeking was successful. /***********************************************************************************/ -bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) +bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) { if (!catalog) { @@ -1009,7 +1010,7 @@ bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) /// @return The position on the file. /***********************************************************************************/ -SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) +SizeT NeFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) { @@ -1024,25 +1025,25 @@ SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) namespace Kernel::Detail { /***********************************************************************************/ - /// @brief Construct NewFS drives. + /// @brief Construct NeFS drives. /***********************************************************************************/ Boolean fs_init_newfs(Void) noexcept { - kcout << "newoskrnl.exe: Creating drives...\r"; + kcout << "Creating drives...\r"; sMountpointInterface.A() = io_construct_main_drive(); sMountpointInterface.B() = io_construct_drive(); sMountpointInterface.C() = io_construct_drive(); sMountpointInterface.D() = io_construct_drive(); - kcout << "newoskrnl.exe: Testing main drive...\r"; + kcout << "Testing A:\r"; sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - kcout << "newoskrnl.exe: Testing main drive [ OK ]...\r"; + kcout << "Testing A: [ OK ]\r"; return true; } } // namespace Kernel::Detail -#endif // ifdef __FSKIT_USE_NEWFS__ +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/FileManager.cxx b/dev/ZKA/Sources/FileMgr.cxx index 8c8fb83a..3e3977ab 100644 --- a/dev/ZKA/Sources/FileManager.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <NewKit/Utils.hxx> /// BUGS: 0 @@ -12,18 +12,18 @@ namespace Kernel { - STATIC FilesystemManagerInterface* kMounted = nullptr; + STATIC FilesystemMgrInterface* kMounted = nullptr; - /// @brief FilesystemManager getter. + /// @brief FilesystemMgr getter. /// @return The mounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() + _Output FilesystemMgrInterface* FilesystemMgrInterface::GetMounted() { return kMounted; } /// @brief Unmount filesystem. /// @return The unmounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::Unmount() + _Output FilesystemMgrInterface* FilesystemMgrInterface::Unmount() { if (kMounted) { @@ -39,7 +39,7 @@ namespace Kernel /// @brief Mount filesystem. /// @param mount_ptr The filesystem to mount. /// @return if it succeeded true, otherwise false. - bool FilesystemManagerInterface::Mount(_Input FilesystemManagerInterface* mount_ptr) + bool FilesystemMgrInterface::Mount(_Input FilesystemMgrInterface* mount_ptr) { if (mount_ptr != nullptr) { @@ -50,12 +50,12 @@ namespace Kernel return false; } -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ /// @brief Opens a new file. /// @param path /// @param r /// @return - _Output NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) + _Output NodePtr NewFilesystemMgr::Open(_Input const Char* path, _Input const Char* r) { if (!path || *path == 0) return nullptr; @@ -73,14 +73,14 @@ namespace Kernel /// @param data the data. /// @param flags the size. /// @return - Void NewFilesystemManager::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + Void NewFilesystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { if (!node) return; if (!size) return; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; this->Write(cDataForkName, node, data, flags, size); } @@ -89,25 +89,25 @@ namespace Kernel /// @param flags the flags with it. /// @param sz the size to read. /// @return - _Output VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + _Output VoidPtr NewFilesystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { if (!node) return nullptr; if (!size) return nullptr; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; return this->Read(cDataForkName, node, flags, size); } - Void NewFilesystemManager::Write(_Input const Char* name, + Void NewFilesystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { if (!size || - size > kNewFSForkSize) + size > kNeFSForkSize) return; if (!data) @@ -115,17 +115,17 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), data, size, name); } - _Output VoidPtr NewFilesystemManager::Read(_Input const Char* name, + _Output VoidPtr NewFilesystemMgr::Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, _Input SizeT sz) { - if (sz > kNewFSForkSize) + if (sz > kNeFSForkSize) return nullptr; if (!sz) @@ -133,7 +133,7 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), sz, name); @@ -146,7 +146,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output Bool NewFilesystemManager::Seek(NodePtr node, SizeT off) + _Output Bool NewFilesystemMgr::Seek(NodePtr node, SizeT off) { if (!node || off == 0) return false; @@ -159,7 +159,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output SizeT NewFilesystemManager::Tell(NodePtr node) + _Output SizeT NewFilesystemMgr::Tell(NodePtr node) { if (!node) return kNPos; @@ -172,7 +172,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output Bool NewFilesystemManager::Rewind(NodePtr node) + _Output Bool NewFilesystemMgr::Rewind(NodePtr node) { if (!node) return false; @@ -182,9 +182,9 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - _Output NewFSParser* NewFilesystemManager::GetParser() noexcept + _Output NeFSParser* NewFilesystemMgr::GetParser() noexcept { return fImpl; } -#endif // __FSKIT_USE_NEWFS__ +#endif // __FSKIT_USE_NEFS__ } // namespace Kernel diff --git a/dev/ZKA/Sources/Framebuffer.cxx b/dev/ZKA/Sources/Framebuffer.cxx index 76fe7172..3794e458 100644 --- a/dev/ZKA/Sources/Framebuffer.cxx +++ b/dev/ZKA/Sources/Framebuffer.cxx @@ -44,7 +44,7 @@ namespace Kernel { return fFrameBufferAddr.Leak()->fBase != 0 && fColour != FramebufferColorKind::INVALID && - fFrameBufferAddr.Leak()->fBase != kBadPtr; + fFrameBufferAddr.Leak()->fBase != kInvalidAddress; } /// @brief Set color kind of framebuffer. diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx index b3b62609..b130ef63 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx @@ -6,7 +6,7 @@ #include <ArchKit/ArchKit.hxx> #include <KernelKit/UserProcessScheduler.hxx> -#include <KernelKit/MP.hxx> +#include <KernelKit/HardwareThreadScheduler.hxx> #include <CFKit/Property.hxx> ///! BUGS: 0 @@ -17,12 +17,6 @@ namespace Kernel { - /***********************************************************************************/ - /// @brief MP object container property. - /***********************************************************************************/ - - Property cSMPCoreName; - ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -96,19 +90,26 @@ namespace Kernel !stack_ptr) return false; + if (this->IsBusy()) + return false; + fStack = frame; if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) { - return mp_register_process(fStack); - } - - //! SMP is disabled here. + this->Busy(true); + Bool ret = mp_register_process(fStack); + this->Busy(true); - mp_do_context_switch_pre(); - mp_do_context_switch(image, stack_ptr, fStack); - - return true; + return ret; + } + else + { + mp_do_context_switch_pre(); + mp_do_context_switch(image, stack_ptr, fStack); + + return true; + } } ///! @brief Tells if processor is waked up. @@ -123,15 +124,7 @@ namespace Kernel ///! @brief Constructor and destructors. ///! @brief Default constructor. - HardwareThreadScheduler::HardwareThreadScheduler() - { - kcout << "newoskrnl.exe: initializing HardwareThreadScheduler." << endl; - - cSMPCoreName.GetKey() += "Property\\MPClass"; - cSMPCoreName.GetValue() = (PropertyId)this; - - kcout << "newoskrnl.exe: initialized HardwareThreadScheduler." << endl; - } + HardwareThreadScheduler::HardwareThreadScheduler() = default; ///! @brief Default destructor. HardwareThreadScheduler::~HardwareThreadScheduler() = default; diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index bd7e299b..1f9af6a2 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -8,7 +8,7 @@ #include <KernelKit/LPC.hxx> #include <KernelKit/Heap.hxx> #include <NewKit/Crc32.hxx> -#include <NewKit/PageManager.hxx> +#include <NewKit/PageMgr.hxx> //! @file KernelHeap.cxx //! @brief Kernel heap allocator. @@ -19,8 +19,8 @@ namespace Kernel { SizeT kHeapCount = 0UL; - PageManager kHeapPageManager; - Bool kOperationInProgress = No; + PageMgr kHeapPageMgr; + Bool kHeapLock = No; /// @brief Contains data structures and algorithms for the heap. namespace Detail @@ -52,43 +52,43 @@ namespace Kernel Void mm_alloc_init_timeout(Void) noexcept { - kOperationInProgress = Yes; + kHeapLock = Yes; } Void mm_alloc_fini_timeout(Void) noexcept { - kOperationInProgress = No; + kHeapLock = No; } } // namespace Detail Detail::HEAP_INFORMATION_BLOCK_PTR kLatestAllocation = nullptr; - /// @brief Declare a new size for allocatedPtr. - /// @param allocatedPtr the pointer. + /// @brief Declare a new size for ptr_heap. + /// @param ptr_heap the pointer. /// @return - voidPtr mm_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz) + voidPtr mm_realloc_ke_heap(voidPtr ptr_heap, SizeT new_sz) { - if (!allocatedPtr || newSz < 1) + if (!ptr_heap || new_sz < 1) return nullptr; - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( - (UIntPtr)allocatedPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + (UIntPtr)ptr_heap - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fHeapSize = newSz; + heap_blk->fHeapSize = new_sz; - if (heapInfoBlk->fCRC32 > 0) + if (heap_blk->fCRC32 > 0) { - MUST_PASS(mm_protect_ke_heap(allocatedPtr)); + MUST_PASS(mm_protect_ke_heap(ptr_heap)); } - return allocatedPtr; + return ptr_heap; } - /// @brief allocate chunk of memory. - /// @param sz size of pointer - /// @param rw read write (true to enable it) - /// @param user is it accesible by user processes? + /// @brief Allocate chunk of memory. + /// @param sz Size of pointer + /// @param rw Read Write bit. + /// @param user User enable bit. /// @return The newly allocated pointer. VoidPtr mm_new_ke_heap(const SizeT sz, const bool rw, const bool user) { @@ -97,30 +97,31 @@ namespace Kernel auto szFix = sz; if (szFix == 0) - ++szFix; + return nullptr; - auto wrapper = kHeapPageManager.Request(rw, user, false, szFix); + auto wrapper = kHeapPageMgr.Request(rw, user, No, szFix); Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr = reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( - wrapper.VirtualAddress()); + wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK)); heap_info_ptr->fHeapSize = szFix; - heap_info_ptr->fMagic = kKernelHeapMagic; - heap_info_ptr->fCRC32 = 0U; // dont fill it for now. - heap_info_ptr->fHeapPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); - heap_info_ptr->fPage = 0UL; - heap_info_ptr->fUser = user; - heap_info_ptr->fPresent = true; + heap_info_ptr->fMagic = kKernelHeapMagic; + heap_info_ptr->fCRC32 = No; // dont fill it for now. + heap_info_ptr->fHeapPtr = reinterpret_cast<UIntPtr>(heap_info_ptr) + sizeof(Detail::HEAP_INFORMATION_BLOCK); + heap_info_ptr->fPage = No; + heap_info_ptr->fUser = user; + heap_info_ptr->fPresent = Yes; ++kHeapCount; + auto result = reinterpret_cast<VoidPtr>(heap_info_ptr->fHeapPtr); + kLatestAllocation = heap_info_ptr; Detail::mm_alloc_fini_timeout(); - return reinterpret_cast<VoidPtr>(heap_info_ptr + - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + return result; } /// @brief Makes a page heap. @@ -132,16 +133,16 @@ namespace Kernel return -kErrorInternal; if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) return -kErrorInternal; - if (((IntPtr)heap_ptr - kBadPtr) < 0) + if (((IntPtr)heap_ptr - kInvalidAddress) < 0) return -kErrorInternal; Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fPage = true; + heap_blk->fPage = true; Detail::mm_alloc_fini_timeout(); @@ -155,48 +156,50 @@ namespace Kernel { if (kHeapCount < 1) return -kErrorInternal; - if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) - return -kErrorInternal; - if (((IntPtr)heap_ptr - kBadPtr) < 0) - return -kErrorInternal; + + if (!heap_ptr) + return -kErrorInvalidData; Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk && heapInfoBlk->fMagic == kKernelHeapMagic) + if (heap_blk && heap_blk->fMagic == kKernelHeapMagic) { - if (!heapInfoBlk->fPresent) + + if (!heap_blk->fPresent) { Detail::mm_alloc_fini_timeout(); return -kErrorHeapNotPresent; } - if (heapInfoBlk->fCRC32 != 0) + if (heap_blk->fCRC32 != 0) { - if (heapInfoBlk->fCRC32 != - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, - heapInfoBlk->fHeapSize)) + if (heap_blk->fCRC32 != + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, + heap_blk->fHeapSize)) { - if (!heapInfoBlk->fUser) + if (!heap_blk->fUser) { ke_stop(RUNTIME_CHECK_POINTER); } } } - heapInfoBlk->fHeapSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fHeapPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heap_blk->fHeapSize = 0UL; + heap_blk->fPresent = No; + heap_blk->fHeapPtr = 0; + heap_blk->fCRC32 = 0; + heap_blk->fMagic = 0; + + PTEWrapper pageWrapper(false, false, false, reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + Ref<PTEWrapper> pteAddress{pageWrapper}; - PTEWrapper pageWrapper(false, false, false, reinterpret_cast<UIntPtr>(heapInfoBlk)); - Ref<PTEWrapper*> pteAddress{&pageWrapper}; + kcout << "Freeing pointer address: " << hex_number(reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)) << endl; - kHeapPageManager.Free(pteAddress); + kHeapPageMgr.Free(pteAddress); --kHeapCount; @@ -238,14 +241,14 @@ namespace Kernel { if (heap_ptr) { - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk->fPresent && kKernelHeapMagic == heapInfoBlk->fMagic) + if (heap_blk->fPresent && kKernelHeapMagic == heap_blk->fMagic) { - heapInfoBlk->fCRC32 = - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, heapInfoBlk->fHeapSize); + heap_blk->fCRC32 = + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, heap_blk->fHeapSize); return true; } diff --git a/dev/ZKA/Sources/DLLInterface.cxx b/dev/ZKA/Sources/IDLLObject.cxx index c18f2f00..b6b6a348 100644 --- a/dev/ZKA/Sources/DLLInterface.cxx +++ b/dev/ZKA/Sources/IDLLObject.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include <KernelKit/DLLInterface.hxx> +#include <KernelKit/IDLLObject.hxx> #include <KernelKit/DebugOutput.hxx> #include <KernelKit/UserProcessScheduler.hxx> diff --git a/dev/ZKA/Sources/PEFDLLInterface.cxx b/dev/ZKA/Sources/IPEFDLLObject.cxx index 70c68783..913912a4 100644 --- a/dev/ZKA/Sources/PEFDLLInterface.cxx +++ b/dev/ZKA/Sources/IPEFDLLObject.cxx @@ -9,7 +9,7 @@ #include <KernelKit/DebugOutput.hxx> #include <KernelKit/PEF.hxx> -#include <KernelKit/PEFDLLInterface.hxx> +#include <KernelKit/IPEFDLLObject.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> #include <NewKit/Defines.hxx> @@ -37,9 +37,9 @@ using namespace Kernel; /** @brief Library initializer. */ /***********************************************************************************/ -EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header) +EXTERN_C IDLL rtl_init_shared_object(UserProcess* header) { - DLLInterfacePtr sharedObj = tls_new_class<PEFDLLInterface>(); + IDLL sharedObj = tls_new_class<IPEFDLLObject>(); if (!sharedObj) { @@ -48,7 +48,7 @@ EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header) return nullptr; } - sharedObj->Mount(tls_new_class<PEFDLLInterface::DLL_TRAITS>()); + sharedObj->Mount(tls_new_class<IPEFDLLObject::DLL_TRAITS>()); if (!sharedObj->Get()) { @@ -80,7 +80,7 @@ EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header) /** @param successful Reports if successful or not. */ /***********************************************************************************/ -EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful) +EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful) { MUST_PASS(successful); diff --git a/dev/ZKA/Sources/IndexableProperty.cxx b/dev/ZKA/Sources/IndexableProperty.cxx index 84aabc6b..a5f1bc0b 100644 --- a/dev/ZKA/Sources/IndexableProperty.cxx +++ b/dev/ZKA/Sources/IndexableProperty.cxx @@ -52,7 +52,7 @@ namespace Kernel indexer.AddFlag(kIndexerClaimed); rt_copy_memory((VoidPtr)indexer.Leak().Path, (VoidPtr)filename, filenameLen); - kcout << "newoskrnl.exe: filesystem: index new file: " << filename << endl; + kcout << "filesystem: index new file: " << filename << endl; } } } // namespace Indexer diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index a05c265a..acc01dec 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -56,6 +56,7 @@ namespace Kernel { case RUNTIME_CHECK_PROCESS: { CGDrawString("0x00000008 No more processes to run, this is because that ZKA ran out of processes.", start_y, x, panicTxt); + RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_ACPI: { @@ -98,11 +99,16 @@ namespace Kernel RecoveryFactory::Recover(); break; case RUNTIME_CHECK_UNEXCPECTED: { - CGDrawString("0x0000000B Catasrophic Kernel failure.", start_y, x, panicTxt); + CGDrawString("0x0000000B Unexpected Kernel failure.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: { + CGDrawString("0x10000001 Out of Virtual Memory. (Catastrophic Failure)", start_y, x, panicTxt); + RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_FAILED: { - CGDrawString("0x10000001 Assertion failed.", start_y, x, panicTxt); + CGDrawString("0x10000001 Kernel Check.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } @@ -120,13 +126,6 @@ namespace Kernel Void RecoveryFactory::Recover() noexcept { - const auto cMaxSeconds = Seconds(4); - - HardwareTimer timer(cMaxSeconds); - timer.Wait(); - - kcout << "newoskrnl.exe: Shutting down computer...\r"; - PowerFactoryInterface power(nullptr); power.Shutdown(); } @@ -135,6 +134,9 @@ namespace Kernel { if (!expr) { + kcout << "FAILED: FILE: " << file << endl; + kcout << "FAILED: LINE: " << line << endl; + ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed } } diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NeFS+FileMgr.cxx index 98e0e3af..b3ad381f 100644 --- a/dev/ZKA/Sources/NewFS+FileManager.cxx +++ b/dev/ZKA/Sources/NeFS+FileMgr.cxx @@ -4,28 +4,29 @@ ------------------------------------------- */ -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <KernelKit/Heap.hxx> -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ -/// @brief NewFS File manager. +/// @brief NeFS File manager. /// BUGS: 0 namespace Kernel { /// @brief C++ constructor - NewFilesystemManager::NewFilesystemManager() + NewFilesystemMgr::NewFilesystemMgr() { MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NewFSParser(); + fImpl = new NeFSParser(); + MUST_PASS(fImpl); - kcout << "newoskrnl.exe: We are done here... (NewFilesystemManager).\r"; + kcout << "We are done here... (NewFilesystemMgr).\r"; } - NewFilesystemManager::~NewFilesystemManager() + NewFilesystemMgr::~NewFilesystemMgr() { - kcout << "newoskrnl.exe: Destroying it...\r"; + kcout << "Destroying it...\r"; if (fImpl) { @@ -36,7 +37,7 @@ namespace Kernel /// @brief Removes a node from the filesystem. /// @param fileName The filename /// @return If it was deleted or not. - bool NewFilesystemManager::Remove(const Char* fileName) + bool NewFilesystemMgr::Remove(const Char* fileName) { if (fileName == nullptr || *fileName == 0) return false; @@ -47,7 +48,7 @@ namespace Kernel /// @brief Creates a node with the specified. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemManager::Create(const Char* path) + NodePtr NewFilesystemMgr::Create(const Char* path) { return node_cast(fImpl->CreateCatalog(path)); } @@ -55,54 +56,54 @@ namespace Kernel /// @brief Creates a node with is a directory. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateDirectory(const Char* path) + NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node with is a alias. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateAlias(const Char* path) + NodePtr NewFilesystemMgr::CreateAlias(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } /// @brief Creates a node with is a page file. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateSwapFile(const Char* path) + NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return const Char* NewFilesystemHelper::Root() { - return kNewFSRoot; + return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return const Char* NewFilesystemHelper::UpDir() { - return kNewFSUpDir; + return kNeFSUpDir; } /// @brief Gets the separator character. /// @return const Char NewFilesystemHelper::Separator() { - return kNewFSSeparator; + return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return const Char NewFilesystemHelper::MetaFile() { - return kNewFSMetaFilePrefix; + return kNeFSMetaFilePrefix; } } // namespace Kernel -#endif // ifdef __FSKIT_USE_NEWFS__ +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NeFS+IO.cxx index ddcecde4..a86e9c29 100644 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ b/dev/ZKA/Sources/NeFS+IO.cxx @@ -4,12 +4,12 @@ ------------------------------------------- */ -#include <KernelKit/DriveManager.hxx> -#include <KernelKit/FileManager.hxx> +#include <KernelKit/DriveMgr.hxx> +#include <KernelKit/FileMgr.hxx> /************************************************************* * - * File: NewFS+IO.cxx + * File: NeFS+IO.cxx * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * @@ -17,14 +17,14 @@ * *************************************************************/ -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ #include <FirmwareKit/EPM.hxx> /// Useful macros. -#define NEWFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) -#define NEWFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) +#define NEFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) +#define NEFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) using namespace Kernel; @@ -42,20 +42,20 @@ Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvInd switch (DrvIndex) { - case kNewFSSubDriveA: { - NEWFS_READ(A, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveA: { + NEFS_READ(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { - NEWFS_READ(B, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveB: { + NEFS_READ(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { - NEWFS_READ(C, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveC: { + NEFS_READ(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { - NEWFS_READ(D, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveD: { + NEFS_READ(D, DrvTrait.fPacket, Mnt); break; } } @@ -77,20 +77,20 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn switch (DrvIndex) { - case kNewFSSubDriveA: { - NEWFS_WRITE(A, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveA: { + NEFS_WRITE(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { - NEWFS_WRITE(B, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveB: { + NEFS_WRITE(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { - NEWFS_WRITE(C, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveC: { + NEFS_WRITE(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { - NEWFS_WRITE(D, DrvTrait.fPacket, Mnt); + case kNeFSSubDriveD: { + NEFS_WRITE(D, DrvTrait.fPacket, Mnt); break; } } @@ -98,4 +98,4 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn return DrvTrait.fPacket.fPacketGood; } -#endif // ifdef __FSKIT_USE_NEWFS__ +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx deleted file mode 100644 index 6504b2bc..00000000 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ /dev/null @@ -1,22 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <KernelKit/DebugOutput.hxx> -#include <KernelKit/FileManager.hxx> - -#ifdef __FSKIT_USE_NEWFS__ - -///! BUGS: 0 -///! @file NewFS+Journal.cxx -///! @brief Journaling for NewFS. - -namespace Kernel::Journal -{ -} // namespace Kernel::Journal - -using namespace Kernel; - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/PEFCodeManager.cxx b/dev/ZKA/Sources/PEFCodeMgr.cxx index 526312e0..feafc35c 100644 --- a/dev/ZKA/Sources/PEFCodeManager.cxx +++ b/dev/ZKA/Sources/PEFCodeMgr.cxx @@ -6,7 +6,7 @@ #include <KernelKit/DebugOutput.hxx> #include <KernelKit/Heap.hxx> -#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/PEFCodeMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <NewKit/Defines.hxx> #include <NewKit/KernelCheck.hxx> @@ -87,7 +87,7 @@ namespace Kernel if (fCachedBlob) mm_delete_ke_heap(fCachedBlob); - kcout << "CodeManagerPEF: Warning: Executable format error!\r"; + kcout << "CodeMgrPEF: Warning: Executable format error!\r"; fCachedBlob = nullptr; } diff --git a/dev/ZKA/Sources/PageAllocator.cxx b/dev/ZKA/Sources/PageAllocator.cxx index dec6c470..e68d0659 100644 --- a/dev/ZKA/Sources/PageAllocator.cxx +++ b/dev/ZKA/Sources/PageAllocator.cxx @@ -11,19 +11,6 @@ /// @brief Internal namespace, used internally by Kernel. namespace Kernel::Detail { - VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz) - { - auto addr = HAL::hal_alloc_page(rw, user, pageSz); - - if (addr == kBadAddress) - { - kcout << "[create_page_wrapper] kBadAddress returned\n"; - ke_stop(RUNTIME_CHECK_POINTER); - } - - return addr; - } - void exec_disable(UIntPtr VirtualAddr) { #ifdef __ZKA_SUPPORT_NX__ diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageMgr.cxx index d14130ff..78b279f3 100644 --- a/dev/ZKA/Sources/PageManager.cxx +++ b/dev/ZKA/Sources/PageMgr.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.hxx> -#include <NewKit/PageManager.hxx> +#include <NewKit/PageMgr.hxx> #ifdef __ZKA_AMD64__ #include <HALKit/AMD64/HalPageAlloc.hxx> @@ -35,11 +35,8 @@ namespace Kernel /// @brief Flush virtual address. /// @param VirtAddr - Void PageManager::FlushTLB(UIntPtr VirtAddr) + Void PageMgr::FlushTLB() { - if (VirtAddr == kBadAddress) - return; - hal_flush_tlb(); } @@ -61,34 +58,23 @@ namespace Kernel /// @param User user mode? /// @param ExecDisable disable execution on page? /// @return - PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) + PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) { // Store PTE wrapper right after PTE. - VoidPtr ptr = Kernel::HAL::hal_alloc_page(Rw, User, Sz); - - if (ptr == kBadAddress) - { - kcout << "[create_page_wrapper] kBadAddress returned\n"; - ke_stop(RUNTIME_CHECK_POINTER); - } + VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)}; } - /// @brief Disable PTE. + /// @brief Disable BitMap. /// @param wrapper the wrapper. - /// @return - bool PageManager::Free(Ref<PTEWrapper*>& wrapper) + /// @return If the page bitmap was cleared or not. + Bool PageMgr::Free(Ref<PTEWrapper>& wrapper) { - if (wrapper) - { - if (!Kernel::HAL::hal_free_page((VoidPtr)wrapper->VirtualAddress())) - return false; + if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper.Leak().VirtualAddress())) + return false; - return true; - } - - return false; + return true; } /// @brief Virtual PTE address. diff --git a/dev/ZKA/Sources/Pmm.cxx b/dev/ZKA/Sources/Pmm.cxx index b0855281..58335a2b 100644 --- a/dev/ZKA/Sources/Pmm.cxx +++ b/dev/ZKA/Sources/Pmm.cxx @@ -19,9 +19,9 @@ namespace Kernel { /// @brief Pmm constructor. Pmm::Pmm() - : fPageManager() + : fPageMgr() { - kcout << "[PMM] Allocate PageMemoryManager"; + kcout << "[PMM] Allocate PageMemoryMgr"; } Pmm::~Pmm() = default; @@ -31,17 +31,15 @@ namespace Kernel /// @param readWrite is it r/w? Ref<PTEWrapper> Pmm::RequestPage(Boolean user, Boolean readWrite) { - PTEWrapper pt = fPageManager.Leak().Request(user, readWrite, false, kPTESize); + PTEWrapper pt = fPageMgr.Leak().Request(user, readWrite, false, kPTESize); if (pt.fPresent) { - kcout << "[PMM]: Allocation was successful.\r"; - return Ref<PTEWrapper>(pt); + kcout << "[PMM]: Allocation failed.\r"; + return {}; } - kcout << "[PMM]: Allocation failed.\r"; - - return {}; + return Ref<PTEWrapper>(pt); } Boolean Pmm::FreePage(Ref<PTEWrapper> PageRef) diff --git a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx index 183481e1..97d2e2e4 100644 --- a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx +++ b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) @@ -69,7 +69,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index f4794bdd..35f2dbcd 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -21,7 +21,7 @@ using namespace Kernel; -namespace Detail +namespace Kernel::Detail { /// \brief UserProcess thread information header. struct THREAD_HEADER_BLOCK final @@ -72,7 +72,7 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(the_tib); - kcout << "newoskrnl.exe: checking for a valid cookie inside the TIB...\r"; + kcout << "checking for a valid cookie inside the TIB...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -87,7 +87,7 @@ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { if (!tib_ptr) { - kcout << "newoskrnl.exe: failing because of an invalid TIB...\r"; + kcout << "failing because of an invalid TIB...\r"; return false; } @@ -95,10 +95,10 @@ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept if (!tls_check_tib(tib_struct)) { - kcout << "newoskrnl.exe: crashing because of an invalid TIB...\r"; + kcout << "crashing because of an invalid TIB...\r"; return false; } - kcout << "newoskrnl.exe: Verification succeeded! staying alive...\r"; + kcout << "Verification succeeded! staying alive...\r"; return true; } diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 5a4c2335..066a3e06 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -13,7 +13,7 @@ #include <KernelKit/LPC.hxx> #include <KernelKit/User.hxx> #include <NewKit/KernelCheck.hxx> -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <KernelKit/Heap.hxx> @@ -77,7 +77,6 @@ namespace Kernel SizeT len = rt_string_len(password_to_fill); Char* password = new Char[len]; - MUST_PASS(password); // fill data first, generate hash. @@ -100,7 +99,7 @@ namespace Kernel delete[] password; password = nullptr; - kcout << "newoskrnl.exe: Saved password...\r"; + kcout << "Saved password...\r"; return true; } diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index dc142b18..8c46b1cf 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -2,16 +2,19 @@ Copyright ZKA Technologies. + FILE: UserProcessScheduler.cxx + PURPOSE: User sided process scheduler. + ------------------------------------------- */ /***********************************************************************************/ /// @file UserProcessScheduler.cxx -/// @brief User UserProcess scheduler. +/// @brief User Process scheduler. /***********************************************************************************/ #include <KernelKit/UserProcessScheduler.hxx> -#include <KernelKit/PEFDLLInterface.hxx> -#include <KernelKit/MP.hxx> +#include <KernelKit/IPEFDLLObject.hxx> +#include <KernelKit/HardwareThreadScheduler.hxx> #include <KernelKit/Heap.hxx> #include <NewKit/String.hxx> #include <KernelKit/LPC.hxx> @@ -19,7 +22,7 @@ ///! BUGS: 0 /***********************************************************************************/ -/* TODO: Document more the Kernel, sdk and kits. */ +/** TODO: Document the Kernel, SDK and kits. */ /***********************************************************************************/ namespace Kernel @@ -28,10 +31,10 @@ namespace Kernel /// @brief Exit Code global variable. /***********************************************************************************/ - UInt32 cLastExitCode = 0U; + STATIC UInt32 cLastExitCode = 0U; /***********************************************************************************/ - /// @brief UserProcess scheduler instance. + /// @brief User Process scheduler global object. /***********************************************************************************/ UserProcessScheduler* cProcessScheduler = nullptr; @@ -53,11 +56,9 @@ namespace Kernel if (this->Name == 0) return; - kcout << this->Name << ": crashed. (id = " << number(kErrorProcessFault) << endl; + kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl; this->Exit(kErrorProcessFault); - - UserProcessHelper::StartScheduling(); } /// @brief Gets the local last exit code. @@ -85,27 +86,45 @@ namespace Kernel /***********************************************************************************/ + /** @brief Add pointer to entry. */ VoidPtr UserProcess::New(const SizeT& sz) { - if (this->HeapCursor) +#ifdef __ZKA_AMD64__ + auto pd = hal_read_cr3(); + hal_write_cr3(this->MemoryPD); + + auto ptr = mm_new_ke_heap(sz, Yes, Yes); + + hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); +#else + auto ptr = mm_new_ke_heap(sz, Yes, Yes); +#endif + + if (!this->MemoryEntryList) { - if (this->FreeMemory < 1) - { - ErrLocal() = kErrorHeapOutOfMemory; + this->MemoryEntryList = new UserProcess::PROCESS_MEMORY_ENTRY(); + this->MemoryEntryList->MemoryEntry = ptr; - /* We're going out of memory! crash... */ - this->Crash(); + this->MemoryEntryList->MemoryPrev = nullptr; + this->MemoryEntryList->MemoryNext = nullptr; - return nullptr; - } + return ptr; + } + else + { + auto entry = this->MemoryEntryList; - this->HeapCursor = reinterpret_cast<VoidPtr>((UIntPtr)this->HeapCursor + (sizeof(sz))); - VoidPtr cursor = this->HeapCursor; + while (entry->MemoryNext) + { + if (entry->MemoryNext) + entry = entry->MemoryNext; + } - ++this->UsedMemory; - --this->FreeMemory; + entry->MemoryNext = new UserProcess::PROCESS_MEMORY_ENTRY(); + entry->MemoryNext->MemoryEntry = ptr; - return cursor; + entry->MemoryNext->MemoryPrev = entry; + entry->MemoryNext->MemoryNext = nullptr; } return nullptr; @@ -113,39 +132,31 @@ namespace Kernel /***********************************************************************************/ - /* @brief checks if runtime pointer is in region. */ - bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz) - { - if (pool == nullptr || - pool_ptr == nullptr) - return false; - - UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr; - UIntPtr* uint_pool = (UIntPtr*)pool; - - return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr && - pool_ptr_cur_sz > pool_ptr_used_sz; - } - - /* @brief free pointer from usage. */ + /** @brief Free pointer from usage. */ Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz) { - if (sz < 1 || this->HeapCursor == this->HeapPtr) - return false; - - // also check for the amount of allocations we've done so far. - if (this->UsedMemory < 1) - return false; + auto entry = this->MemoryEntryList; - if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory)) + while (entry->MemoryNext) { - this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); - rt_zero_memory(ptr, sz); + if (entry->MemoryEntry == ptr) + { +#ifdef __ZKA_AMD64__ + auto pd = hal_read_cr3(); + hal_write_cr3(this->MemoryPD); + + bool ret = mm_delete_ke_heap(ptr); + hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); - ++this->FreeMemory; - --this->UsedMemory; + return ret; +#else + bool ret = mm_delete_ke_heap(ptr); + return ret; +#endif + } - return true; + if (entry->MemoryNext) + entry = entry->MemoryNext; } return false; @@ -185,7 +196,7 @@ namespace Kernel void UserProcess::Exit(const Int32& exit_code) { this->Status = ProcessStatusKind::kDead; - + fLastExitCode = exit_code; cLastExitCode = exit_code; @@ -213,7 +224,8 @@ namespace Kernel if (this->StackReserve) delete[] this->StackReserve; - cProcessScheduler->Remove(this->ProcessId); + if (this->ProcessId > 0) + UserProcessScheduler::The().Remove(this->ProcessId); } /// @brief Add process to list. @@ -221,46 +233,34 @@ namespace Kernel /// @return the process index inside the team. SizeT UserProcessScheduler::Add(UserProcess& process) { - if (!process.Image) - { - return -kErrorInvalidData; - } +#ifdef __ZKA_AMD64__ + process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3()); +#endif // __ZKA_AMD64__ - kcout << "UserProcessScheduler: Adding process to team...\r"; + process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame)); - // Create heap according to type of process. - if (process.Kind == UserProcess::kExeKind) - { - process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true); - } - else if (process.Kind == UserProcess::kDLLKind) + if (!process.StackFrame) { - process.DLLPtr = rtl_init_shared_object(&process); - process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true); - } - else - { - // Something went wrong, do not continue, process may be incorrect. process.Crash(); return -kErrorProcessFault; } - process.StackFrame = new HAL::StackFrame(); - - MUST_PASS(process.StackFrame); + // Create heap according to type of process. + if (process.Kind == UserProcess::kDLLKind) + { + process.DLLPtr = rtl_init_shared_object(&process); + } if (process.Image) { // get preferred stack size by app. const auto cMaxStackSize = process.StackSize; + process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize); - process.StackReserve = (UInt8*)mm_new_ke_heap(cMaxStackSize, Yes, Yes); - - // if stack pointer isn't valid. - if (!process.StackReserve) + if (process.StackReserve) { - process.StackReserve = (UInt8*)mm_new_ke_heap(kSchedMaxStackSz, Yes, Yes); - kcout << "newoskrnl.exe: Use fallback reserve size.\r"; + process.Crash(); + return -kErrorProcessFault; } } else @@ -272,18 +272,16 @@ namespace Kernel } } - process.Status = ProcessStatusKind::kStarting; - + process.Status = ProcessStatusKind::kStarting; process.ProcessId = mTeam.mProcessAmount; ++mTeam.mProcessAmount; - process.HeapCursor = process.HeapPtr; + while (1) + ; mTeam.AsArray()[process.ProcessId] = process; - kcout << "UserProcessScheduler: Adding process to team [ OK ]...\r"; - return process.ProcessId; } @@ -298,22 +296,16 @@ namespace Kernel /***********************************************************************************/ /// @brief Remove process from list. - /// @param processSlot process slot inside team. + /// @param process_id process slot inside team. /// @retval true process was removed. /// @retval false process doesn't exist in team. - Bool UserProcessScheduler::Remove(ProcessID processSlot) + Bool UserProcessScheduler::Remove(ProcessID process_id) { // check if process is within range. - if (processSlot > mTeam.AsArray().Count()) + if (process_id > mTeam.AsArray().Count()) return false; - // also check if the process isn't a dummy one. - if (mTeam.AsArray()[processSlot].Image == nullptr) - return false; - - kcout << "UserProcessScheduler: Removing process...\r"; - - mTeam.AsArray()[processSlot].Status = ProcessStatusKind::kDead; + mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead; --mTeam.mProcessAmount; return true; @@ -334,7 +326,7 @@ namespace Kernel if (UserProcessHelper::CanBeScheduled(process)) { // set the current process. - mTeam.AsRef() = process; + mTeam.AsRef() = mTeam.AsArray()[process.ProcessId]; process.PTime = static_cast<Int32>(process.Affinity); @@ -342,7 +334,7 @@ namespace Kernel // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize], process.StackFrame, - process.ProcessId)) + process.ProcessId)) { process.Crash(); continue; @@ -386,6 +378,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. @@ -401,7 +403,7 @@ namespace Kernel if (auto start = process.DLLPtr->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart), kPefCode); start) { - process.Image = start; + process.Image = start; } } @@ -414,14 +416,6 @@ namespace Kernel SizeT UserProcessHelper::StartScheduling() { - if (!cProcessScheduler) - { - cProcessScheduler = new UserProcessScheduler(); - MUST_PASS(cProcessScheduler); - - kcout << "newoskrnl.exe: Team capacity: " << number(cProcessScheduler->CurrentTeam().AsArray().Capacity()) << endl; - } - SizeT ret = cProcessScheduler->Run(); return ret; } @@ -437,8 +431,6 @@ namespace Kernel if (!stack || !frame_ptr || !image_ptr || new_pid < 0) return false; - kcout << "newoskrnl.exe: Finding hardware thread...\r"; - for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index) { if (HardwareThreadScheduler::The()[index].Leak()->Kind() == kInvalidHart) @@ -452,17 +444,16 @@ namespace Kernel HardwareThreadScheduler::The()[index].Leak()->Kind() != ThreadKind::kHartSystemReserved) { - HardwareThreadScheduler::The()[index].Leak()->Busy(true); - + PID prev_pid = UserProcessHelper::TheCurrentPID(); UserProcessHelper::TheCurrentPID() = new_pid; - kcout << "newoskrnl.exe: Found hardware thread...\r"; - bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); - HardwareThreadScheduler::The()[index].Leak()->Busy(false); - - return ret; + if (!ret) + { + UserProcessHelper::TheCurrentPID() = prev_pid; + continue; + } } } diff --git a/dev/ZKA/Sources/ProcessTeam.cxx b/dev/ZKA/Sources/UserProcessTeam.cxx index bb5726f7..bb5726f7 100644 --- a/dev/ZKA/Sources/ProcessTeam.cxx +++ b/dev/ZKA/Sources/UserProcessTeam.cxx diff --git a/dev/ZKA/Sources/compile_flags.txt b/dev/ZKA/Sources/compile_flags.txt index 33aadad4..a22ed881 100644 --- a/dev/ZKA/Sources/compile_flags.txt +++ b/dev/ZKA/Sources/compile_flags.txt @@ -3,5 +3,5 @@ -std=c++20 -I../ -I$(HOME)/ --D__FSKIT_USE_NEWFS__ +-D__FSKIT_USE_NEFS__ -D__ZKA_AMD64__ |
