diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-07-28 16:11:46 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-07-28 16:11:46 +0000 |
| commit | c4023005e029ae092dad2689564c490580dd5c28 (patch) | |
| tree | 3080ba07a6b552bf3d7591574cf69b2a3c8fd0fd /Kernel/Sources | |
| parent | 8c8822fff78f9ff9cd640271da9b3634c4c2f97f (diff) | |
| parent | 4db57a2d646b1538783a0675b38bada7a0f903ae (diff) | |
Merged in MHR-36 (pull request #17)
MHR-36
Diffstat (limited to 'Kernel/Sources')
61 files changed, 774 insertions, 540 deletions
diff --git a/Kernel/Sources/Array.cxx b/Kernel/Sources/Array.cxx index 2b1cb7db..40f38c00 100644 --- a/Kernel/Sources/Array.cxx +++ b/Kernel/Sources/Array.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/ArrayList.cxx b/Kernel/Sources/ArrayList.cxx index 1e12e714..2553710a 100644 --- a/Kernel/Sources/ArrayList.cxx +++ b/Kernel/Sources/ArrayList.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Atom.cxx b/Kernel/Sources/Atom.cxx index b79c1122..48526674 100644 --- a/Kernel/Sources/Atom.cxx +++ b/Kernel/Sources/Atom.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/CodeManager.cxx b/Kernel/Sources/CodeManager.cxx index 91b6c99e..3830e922 100644 --- a/Kernel/Sources/CodeManager.cxx +++ b/Kernel/Sources/CodeManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Crc32.cxx b/Kernel/Sources/Crc32.cxx index 8c555dc5..03eb4589 100644 --- a/Kernel/Sources/Crc32.cxx +++ b/Kernel/Sources/Crc32.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/CxxAbi.cxx b/Kernel/Sources/CxxAbi-AMD64.cxx index febffbc4..e1f61aaf 100644 --- a/Kernel/Sources/CxxAbi.cxx +++ b/Kernel/Sources/CxxAbi-AMD64.cxx @@ -1,9 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ +#ifdef __NEWOS_AMD64__ + #include <KernelKit/DebugOutput.hpp> #include <NewKit/CxxAbi.hpp> #include <KernelKit/HError.hpp> @@ -20,17 +22,12 @@ EXTERN_C void __cxa_pure_virtual() Kernel::kcout << "newoskrnl: C++ placeholder method.\n"; } -EXTERN_C void ___chkstk_ms() +EXTERN_C void ___chkstk_ms(void) { Kernel::err_bug_check_raise(); Kernel::err_bug_check(); } -#ifdef __NEWOS_ARM64__ -// AEABI specific. -#define atexit __aeabi_atexit -#endif - EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso) { if (__atexit_func_count >= kDSOMaxObjects) @@ -90,3 +87,5 @@ namespace cxxabiv1 (void)g; } } // namespace cxxabiv1 + +#endif // ifdef __NEWOS_AMD64__ diff --git a/Kernel/Sources/CxxAbi-ARM64.cxx b/Kernel/Sources/CxxAbi-ARM64.cxx new file mode 100644 index 00000000..46524374 --- /dev/null +++ b/Kernel/Sources/CxxAbi-ARM64.cxx @@ -0,0 +1,74 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#ifdef __NEWOS_ARM64__ + +#include <KernelKit/DebugOutput.hpp> +#include <NewKit/CxxAbi.hpp> +#include <KernelKit/HError.hpp> + +EXTERN_C +{ +#include <limits.h> +} + +int const cUninitialized = 0; +int const cBeingInitialized = -1; +int const cEpochStart = INT_MIN; + +EXTERN_C +{ + int _Init_global_epoch = cEpochStart; + __thread int _Init_thread_epoch = cEpochStart; +} + +Kernel::UInt32 const cNKTimeout = 100; // ms + +EXTERN_C void __cdecl _Init_thread_wait(Kernel::UInt32 const timeout) +{ + MUST_PASS(timeout != INT_MAX); +} + +EXTERN_C void __cdecl _Init_thread_header(int* const pOnce) noexcept +{ + if (*pOnce == cUninitialized) + { + *pOnce = cBeingInitialized; + } + else + { + while (*pOnce == cBeingInitialized) + { + _Init_thread_wait(cNKTimeout); + + if (*pOnce == cUninitialized) + { + *pOnce = cBeingInitialized; + return; + } + } + _Init_thread_epoch = _Init_global_epoch; + } +} + +EXTERN_C void __cdecl _Init_thread_abort(int* const pOnce) noexcept +{ + *pOnce = cUninitialized; +} + +EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept +{ + ++_Init_global_epoch; + *pOnce = _Init_global_epoch; + _Init_thread_epoch = _Init_global_epoch; +} + +EXTERN_C void _purecall() +{ + Kernel::kcout << "newoskrnl: C++ placeholder method.\n"; +} + +#endif // ifdef __NEWOS_ARM64__ diff --git a/Kernel/Sources/Defines.cxx b/Kernel/Sources/Defines.cxx index aa39adef..0f90f909 100644 --- a/Kernel/Sources/Defines.cxx +++ b/Kernel/Sources/Defines.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/DeviceManager.cxx b/Kernel/Sources/DeviceManager.cxx index f729c419..b3e5f0c5 100644 --- a/Kernel/Sources/DeviceManager.cxx +++ b/Kernel/Sources/DeviceManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/DriveManager.cxx b/Kernel/Sources/DriveManager.cxx index 039a4e00..58a822e1 100644 --- a/Kernel/Sources/DriveManager.cxx +++ b/Kernel/Sources/DriveManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/ErrorOr.cxx b/Kernel/Sources/ErrorOr.cxx index 94366447..077f1550 100644 --- a/Kernel/Sources/ErrorOr.cxx +++ b/Kernel/Sources/ErrorOr.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 1eef02d8..38a417cb 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ #include <Modules/AHCI/AHCI.hxx> #include <Modules/ATA/ATA.hxx> @@ -20,15 +20,29 @@ using namespace Kernel; +#ifdef __ED__ +/** + Define those external symbols, to make the editor shutup +*/ + +/// @brief get sector count. +Kernel::SizeT drv_std_get_sector_count(); + +/// @brief get device size. +Kernel::SizeT drv_std_get_drv_size(); + +#endif + + ///! BUGS: 0 /***********************************************************************************/ /// This file implements the New File System. /// New File System implements a B-Tree based algortihm. -/// /Disk -/// /Path1 /Path2 -/// /File.txt /File.pef /File.png <-- symlink. -/// /Path1/File.txt +/// \\ +/// \\Path1\\ \\ath2\\ +/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. +/// \\Path1\\readme.rtf /***********************************************************************************/ STATIC MountpointInterface sMountpointInterface; @@ -37,8 +51,8 @@ STATIC MountpointInterface sMountpointInterface; /// @param catalog it's catalog /// @param theFork the fork itself. /// @return the fork -_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, - _Input NewFork& theFork) +_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; @@ -60,8 +74,8 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); - NewFork curFork{0}; - NewFork prevFork{0}; + NFS_FORK_STRUCT curFork{0}; + NFS_FORK_STRUCT prevFork{0}; Lba lbaOfPreviousFork = lba; /// do not check for anything. Loop until we get what we want, that is a free fork zone. @@ -71,7 +85,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, break; drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &curFork; drv->fInput(&drv->fPacket); @@ -101,7 +115,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, if (lba >= kNewFSCatalogStartAddress) { drv->fPacket.fLba = lbaOfPreviousFork; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &prevFork; prevFork.NextSibling = lba; @@ -118,12 +132,12 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, 4; /// this value gives us space for the data offset. theFork.Flags = kNewFSFlagCreated; - theFork.DataOffset = lba - sizeof(NewFork) * cForkPadding; + theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; theFork.PreviousSibling = lbaOfPreviousFork; theFork.NextSibling = theFork.DataOffset - theFork.DataSize; drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = &theFork; drv->fOutput(&drv->fPacket); @@ -144,19 +158,19 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, /// @param catalog the catalog. /// @param name the fork name. /// @return the fork. -_Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, +_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, _Input const Char* name, Boolean isDataFork) { auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex); - NewFork* theFork = nullptr; + NFS_FORK_STRUCT* theFork = nullptr; Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; while (lba != 0) { drv->fPacket.fLba = lba; - drv->fPacket.fPacketSize = sizeof(NewFork); + drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv->fPacket.fPacketContent = (VoidPtr)theFork; rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime, 16); @@ -197,7 +211,7 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, /// file.) /// @param name /// @return catalog pointer. -_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) +_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name) { return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); } @@ -207,7 +221,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) /// @param flags the flags of the catalog. /// @param kind the catalog kind. /// @return catalog pointer. -_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, +_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name, _Input const Int32& flags, _Input const Int32& kind) { @@ -226,7 +240,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) return nullptr; - NewCatalog* copyExists = this->FindCatalog(name, outLba); + NFS_CATALOG_STRUCT* copyExists = this->FindCatalog(name, outLba); if (copyExists) { @@ -270,7 +284,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, --indexReverseCopy; } - NewCatalog* catalog = this->FindCatalog(parentName, outLba); + NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, outLba); if (catalog && catalog->Kind == kNewFSCatalogKindFile) { @@ -284,7 +298,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr SizeT cDefaultForkSize = kNewFSForkSize; - NewCatalog* catalogChild = new NewCatalog(); + NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); catalogChild->ResourceForkSize = cDefaultForkSize; catalogChild->DataForkSize = cDefaultForkSize; @@ -312,7 +326,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fInput(&drive->fPacket); - NewCatalog* nextSibling = (NewCatalog*)catalogBuf; + NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; startFree = nextSibling->NextSibling; @@ -323,7 +337,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, while (drive->fPacket.fPacketGood) { - nextSibling = (NewCatalog*)catalogBuf; + nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; if (startFree <= kNewFSStartLba) { @@ -346,7 +360,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr auto cNewFSCatalogPadding = 4; - NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock; + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; if (partBlock->FreeCatalog < 1) { @@ -359,10 +373,10 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, catalogChild->ResourceFork = catalogChild->DataFork; catalogChild->NextSibling = - startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogChild; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fLba = startFree; drive->fOutput(&drive->fPacket); @@ -370,7 +384,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; drive->fPacket.fLba = - startFree - (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree - (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fInput(&drive->fPacket); @@ -403,7 +417,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, constexpr auto cNewFSCatalogPadding = 4; //// @note that's how we find the next catalog in the partition block. - startFree = startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); + startFree = startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -445,13 +459,13 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// disk isnt faulty and data has been fetched. if (drive->fPacket.fPacketGood) { - NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBuf; + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf; /// check for an empty partition here. if (partBlock->PartitionName[0] == 0 && rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) { - /// partition is free and valid. + // partition is free and valid. partBlock->Version = kNewFSVersionInteger; @@ -463,17 +477,18 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, rt_string_len(cUntitledHD)); - SizeT catalogCount = 0; - SizeT sectorCount = drv_std_get_sector_count(); - SizeT diskSize = drv_std_get_drv_size(); + SizeT catalogCount = 0UL; + + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_drv_size(); partBlock->Kind = kNewFSPartitionTypeStandard; partBlock->StartCatalog = kNewFSCatalogStartAddress; partBlock->Flags = kNewFSPartitionTypeStandard; - partBlock->CatalogCount = sectorCount / sizeof(NewCatalog); + partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); partBlock->SectorCount = sectorCount; partBlock->DiskSize = diskSize; - partBlock->FreeCatalog = sectorCount / sizeof(NewCatalog); + partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -490,15 +505,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) kcout << "newoskrnl: free sectors: " << hex_number(partBlock->FreeSectors) << endl; kcout << "newoskrnl: sector size: " << hex_number(partBlock->SectorSize) << endl; - /// write the root catalog. + // write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); if (partBlock->Flags & kNewFSPartitionTypeBoot) { - /// make it bootable when needed. + // make it bootable when needed. Char bufEpmHdr[kNewFSSectorSz] = {0}; - BootBlockType* epmBoot = (BootBlockType*)bufEpmHdr; + BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; constexpr auto cFsName = "NewFS"; constexpr auto cBlockName = "Zeta:"; @@ -525,7 +540,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) kcout << "newoskrnl: partition block already exists.\r"; - /// return success as well, do not ignore that partition. + // return success as well, do not ignore that partition. return true; } @@ -536,15 +551,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// @param catalog the catalog itself /// @param data the data. /// @return if the catalog w rote the contents successfully. -bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, SizeT sizeOfData, _Input const char* forkName) +bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidPtr data, SizeT sizeOfData, _Input const char* forkName) { if (sizeOfData > catalog->DataForkSize) return false; if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return false; - NewFork* forkData = new NewFork(); - rt_set_memory(forkData, 0, sizeof(NewFork)); + NFS_FORK_STRUCT* forkData = new NFS_FORK_STRUCT(); + rt_set_memory(forkData, 0, sizeof(NFS_FORK_STRUCT)); auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); @@ -555,18 +570,18 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, rt_copy_memory(catalog->Name, forkData->CatalogName, kNewFSNodeNameLen); - /// sanity check of the fork position as the condition to run the loop. + // sanity check of the fork position as the condition to run the loop. while (startFork >= kNewFSCatalogStartAddress) { drive->fPacket.fPacketContent = forkData; - drive->fPacket.fPacketSize = sizeof(NewFork); + drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drive->fPacket.fLba = startFork; drive->fInput(&drive->fPacket); kcout << "newoskrnl: fork name: " << forkData->ForkName << endl; - /// sanity check the fork. + // check the fork, if it's position is valid. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { ErrLocal() = kErrorDiskIsCorrupted; @@ -620,7 +635,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, /// @brief /// @param catalogName the catalog name. /// @return the newly found catalog. -_Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, +_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const char* catalogName, Lba& outLba) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) @@ -628,19 +643,19 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, kcout << "newoskrnl: start finding catalog...\r"; - Char* sectorBuf = new Char[sizeof(NewPartitionBlock)]; + Char* sectorBuf = new Char[sizeof(NFS_ROOT_PARTITION_BLOCK)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); + drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); - NewPartitionBlock* part = (NewPartitionBlock*)sectorBuf; + NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf; auto startCatalogList = part->StartCatalog; const auto cCtartCatalogList = part->StartCatalog; @@ -649,7 +664,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fInput(&drive->fPacket); @@ -676,7 +691,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, --indexReverseCopy; } - NewCatalog* parentCatalog = this->FindCatalog(parentName, outLba); + NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, outLba); if (parentCatalog && !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) @@ -697,7 +712,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, _NewFSSearchThroughCatalogList: while (drive->fPacket.fPacketGood) { - NewCatalog* catalog = (NewCatalog*)sectorBuf; + NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)sectorBuf; if (StringBuilder::Equals(catalogName, catalog->Name)) { @@ -707,8 +722,8 @@ _NewFSSearchThroughCatalogList: goto _NewFSContinueSearch; } - NewCatalog* catalogPtr = new NewCatalog(); - rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); + NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); + rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); kcout << "newoskrnl: found catalog at: " << hex_number(startCatalogList) << endl; @@ -725,7 +740,7 @@ _NewFSSearchThroughCatalogList: drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; - drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive->fInput(&drive->fPacket); } @@ -747,7 +762,7 @@ _NewFSSearchThroughCatalogList: /// @brief /// @param name /// @return -_Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) +_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const char* name) { Lba unused = 0; return this->FindCatalog(name, unused); @@ -756,7 +771,7 @@ _Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) /// @brief /// @param catalog /// @return -Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) +Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) return false; @@ -794,21 +809,21 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) drive->fPacket.fLba = outLba; // the catalog position. drive->fPacket.fPacketSize = - sizeof(NewCatalog); // size of catalog. roughly the sector size. + sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. drive->fPacket.fPacketContent = catalog; // the catalog itself. drive->fOutput(&drive->fPacket); // send packet. - Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; + Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; drive->fPacket.fLba = kNewFSStartLba; drive->fPacket.fPacketContent = partitionBlockBuf; - drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); + drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); drive->fInput(&drive->fPacket); - NewPartitionBlock* partBlock = - reinterpret_cast<NewPartitionBlock*>(partitionBlockBuf); + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); ++partBlock->FreeCatalog; --partBlock->CatalogCount; @@ -833,7 +848,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) /// @return /***********************************************************************************/ -VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, +VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, _Input SizeT dataSz, _Input const char* forkName) { @@ -852,23 +867,23 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, kcout << "newoskrnl: catalog " << catalog->Name << ", fork: " << hex_number(dataForkLba) << endl; - Char* sectorBuf = new Char[sizeof(NewFork)]; + Char* sectorBuf = new Char[sizeof(NFS_FORK_STRUCT)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); - NewFork* forkData = nullptr; + NFS_FORK_STRUCT* forkData = nullptr; while (dataForkLba >= kNewFSCatalogStartAddress) { drive->fPacket.fLba = dataForkLba; - drive->fPacket.fPacketSize = sizeof(NewFork); + drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drive->fPacket.fPacketContent = sectorBuf; drive->fInput(&drive->fPacket); - forkData = (NewFork*)sectorBuf; + forkData = (NFS_FORK_STRUCT*)sectorBuf; kcout << "newoskrnl: name: " << forkData->ForkName << endl; @@ -913,7 +928,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, /// @return if the seeking was successful. /***********************************************************************************/ -bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) +bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) { if (!catalog) { @@ -931,7 +946,7 @@ bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) /// @return The position on the file. /***********************************************************************************/ -SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) +SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) { if (!catalog) { @@ -957,16 +972,16 @@ namespace Kernel::Detail sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; + Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; sMountpointInterface.A().fPacket.fLba = kNewFSStartLba; sMountpointInterface.A().fPacket.fPacketContent = partitionBlockBuf; - sMountpointInterface.A().fPacket.fPacketSize = sizeof(NewPartitionBlock); + sMountpointInterface.A().fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); sMountpointInterface.A().fInput(&sMountpointInterface.A().fPacket); - NewPartitionBlock* partBlock = - reinterpret_cast<NewPartitionBlock*>(partitionBlockBuf); + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); if (!StringBuilder::Equals(partBlock->Ident, kNewFSIdent)) { @@ -980,4 +995,4 @@ namespace Kernel::Detail } } // namespace Kernel::Detail -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/FS/compile_flags.txt b/Kernel/Sources/FS/compile_flags.txt new file mode 100644 index 00000000..39b236a9 --- /dev/null +++ b/Kernel/Sources/FS/compile_flags.txt @@ -0,0 +1,6 @@ +-nostdlib +-ffreestanding +-std=c++20 +-I./ +-I../ +-D__ED__ diff --git a/Kernel/Sources/FileManager.cxx b/Kernel/Sources/FileManager.cxx index 35913b85..dcdced27 100644 --- a/Kernel/Sources/FileManager.cxx +++ b/Kernel/Sources/FileManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,11 +12,11 @@ namespace Kernel { - static FilesystemManagerInterface* kMounted = nullptr; + STATIC FilesystemManagerInterface* kMounted = nullptr; /// @brief FilesystemManager getter. /// @return The mounted filesystem. - FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() + _Output FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() { return kMounted; } @@ -50,12 +50,12 @@ namespace Kernel return false; } -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ /// @brief Opens a new file. /// @param path /// @param r /// @return - NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) + _Output NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) { if (!path || *path == 0) return nullptr; @@ -81,8 +81,10 @@ namespace Kernel /// @return Void NewFilesystemManager::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!node) return; - if (!size) return; + if (!node) + return; + if (!size) + return; constexpr auto cDataForkName = kNewFSDataFork; this->Write(cDataForkName, node, data, flags, size); @@ -93,10 +95,12 @@ namespace Kernel /// @param flags the flags with it. /// @param sz the size to read. /// @return - VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + _Output VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { - if (!node) return nullptr; - if (!size) return nullptr; + if (!node) + return nullptr; + if (!size) + return nullptr; constexpr auto cDataForkName = kNewFSDataFork; return this->Read(cDataForkName, node, flags, size); @@ -117,8 +121,8 @@ namespace Kernel NEWOS_UNUSED(flags); - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast<NewCatalog*>(node), data, size, + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), data, size, name); } @@ -135,8 +139,8 @@ namespace Kernel NEWOS_UNUSED(flags); - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz, + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile) + return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), sz, name); return nullptr; @@ -148,12 +152,12 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - bool NewFilesystemManager::Seek(NodePtr node, SizeT off) + _Output Bool NewFilesystemManager::Seek(NodePtr node, SizeT off) { if (!node || off == 0) return false; - return fImpl->Seek(reinterpret_cast<NewCatalog*>(node), off); + return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); } /// @brief Tell where the catalog is. @@ -161,12 +165,12 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - SizeT NewFilesystemManager::Tell(NodePtr node) + _Output SizeT NewFilesystemManager::Tell(NodePtr node) { if (!node) return kNPos; - return fImpl->Tell(reinterpret_cast<NewCatalog*>(node)); + return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); } /// @brief Rewinds the catalog. @@ -174,7 +178,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - bool NewFilesystemManager::Rewind(NodePtr node) + _Output Bool NewFilesystemManager::Rewind(NodePtr node) { if (!node) return false; @@ -184,9 +188,9 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - NewFSParser* NewFilesystemManager::GetParser() noexcept + _Output NewFSParser* NewFilesystemManager::GetParser() noexcept { return fImpl; } -#endif // __FSKIT_NEWFS__ +#endif // __FSKIT_USE_NEWFS__ } // namespace Kernel diff --git a/Kernel/Sources/Framebuffer.cxx b/Kernel/Sources/Framebuffer.cxx index 205291bb..f006a9b9 100644 --- a/Kernel/Sources/Framebuffer.cxx +++ b/Kernel/Sources/Framebuffer.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Framebuffer.cxx Purpose: Framebuffer object @@ -9,88 +9,105 @@ 01/02/24: Added file (amlel) 02/02/24: Add documentation (amlel) + 07/07/07: Moved Framebuffer methods into Kernel:: ------------------------------------------- */ #include <KernelKit/Framebuffer.hpp> +#include <HintKit/CompilerHint.hxx> /** * @brief Framebuffer object implementation. * */ -using namespace Kernel; - namespace Kernel { - const UInt32 kRgbRed = 0x000000FF; - const UInt32 kRgbGreen = 0x0000FF00; - const UInt32 kRgbBlue = 0x00FF0000; - const UInt32 kRgbBlack = 0x00000000; - const UInt32 kRgbWhite = 0xFFFFFFFF; -} // namespace Kernel + Framebuffer::Framebuffer(_Input Ref<FramebufferContext*>& addr) + : fFrameBufferAddr(addr) + { + } -/** - * @brief Get Pixel at - * - * @param pos position of pixel. - * @return volatile* - */ -volatile UIntPtr* Framebuffer::operator[](const UIntPtr& pos) -{ - return (UIntPtr*)(fFrameBufferAddr->fBase * pos); -} + /** + * @brief Get Pixel at **pos** + * + * @param pos position of pixel. + * @return volatile* + */ + _Output volatile UIntPtr* Framebuffer::operator[](_Input const UIntPtr& pos) + { + return (UIntPtr*)(fFrameBufferAddr->fBase * pos); + } -/// @brief Boolean operator. -Framebuffer::operator bool() -{ - return fFrameBufferAddr.Leak()->fBase != 0 && - fColour != FramebufferColorKind::INVALID && - fFrameBufferAddr.Leak()->fBase != kBadPtr; -} - -/// @brief Set color kind of framebuffer. -/// @param colour -/// @return -const FramebufferColorKind& Framebuffer::Color( - const FramebufferColorKind& colour) -{ - if (fColour != FramebufferColorKind::INVALID && - colour != FramebufferColorKind::INVALID) + /// @brief Boolean operator. + Framebuffer::operator bool() { - fColour = colour; + return fFrameBufferAddr.Leak()->fBase != 0 && + fColour != FramebufferColorKind::INVALID && + fFrameBufferAddr.Leak()->fBase != kBadPtr; } - return fColour; -} + /// @brief Set color kind of framebuffer. + /// @param colour + /// @return + _Output const FramebufferColorKind& Framebuffer::Color( + const FramebufferColorKind& colour) + { + if (fColour != FramebufferColorKind::INVALID && + colour != FramebufferColorKind::INVALID) + { + fColour = colour; + } + + return fColour; + } -/// @brief Leak framebuffer context. -/// @return The reference of the framebuffer context. -Ref<FramebufferContext*>& Framebuffer::Leak() -{ - return this->fFrameBufferAddr; -} + /// @brief Leak framebuffer context. + /// @return The reference of the framebuffer context. + _Output Ref<FramebufferContext*>& Framebuffer::Leak() + { + return this->fFrameBufferAddr; + } -Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color) -{ - for (Kernel::SizeT i = x; i < width + x; ++i) + /// @brief Draws a rectangle. + /// @param width + /// @param height + /// @param x + /// @param y + /// @param color + /// @return + _Output Framebuffer& Framebuffer::DrawRect(SizeT width, SizeT height, SizeT x, SizeT y, UInt32 color) { - for (Kernel::SizeT u = y; u < height + y; ++u) + for (Kernel::SizeT i = x; i < width + x; ++i) { - *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + - 4 * fFrameBufferAddr.Leak()->fBpp * i + - 4 * u))) = color; + for (Kernel::SizeT u = y; u < height + y; ++u) + { + *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + + 4 * fFrameBufferAddr.Leak()->fBpp * i + + 4 * u))) = color; + } } + + return *this; } - return *this; -} + /// @brief Put a pixel on the screen. + /// @param x + /// @param y + /// @param color + /// @return + _Output Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color) + { + *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + + 4 * fFrameBufferAddr.Leak()->fBpp * x + + 4 * y))) = color; -Framebuffer& Framebuffer::PutPixel(SizeT x, SizeT y, UInt32 color) -{ - *(((volatile Kernel::UInt32*)(fFrameBufferAddr.Leak()->fBase + - 4 * fFrameBufferAddr.Leak()->fBpp * x + - 4 * y))) = color; + return *this; + } - return *this; -}
\ No newline at end of file + const UInt32 kRgbRed = 0x000000FF; + const UInt32 kRgbGreen = 0x0000FF00; + const UInt32 kRgbBlue = 0x00FF0000; + const UInt32 kRgbBlack = 0x00000000; + const UInt32 kRgbWhite = 0xFFFFFFFF; +} // namespace Kernel diff --git a/Kernel/Sources/GUIDWizard.cxx b/Kernel/Sources/GUIDWizard.cxx index 0af8e289..b65c73a8 100644 --- a/Kernel/Sources/GUIDWizard.cxx +++ b/Kernel/Sources/GUIDWizard.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: GUIDWizard.cxx Purpose: GUID helper code @@ -10,7 +10,7 @@ ------------------------------------------- */ #include <CFKit/GUIDWizard.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> // begin of ascii 'readable' characters. (A, C, C, 1, 2) #define kAsciiBegin 47 @@ -19,24 +19,31 @@ namespace Kernel::XRN::Version1 { - auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> + auto cf_make_sequence(const ArrayList<UInt32>& uuidSeq) -> Ref<GUIDSequence*> { GUIDSequence* seq = new GUIDSequence(); MUST_PASS(seq); Ref<GUIDSequence*> sequenceReference{seq, true}; - sequenceReference->fMs1 |= uuidSeq[0]; - sequenceReference->fMs2 |= uuidSeq[1]; - sequenceReference->fMs3 |= uuidSeq[2]; - sequenceReference->fMs3 |= uuidSeq[3]; + sequenceReference->fMs1 = uuidSeq[0]; + sequenceReference->fMs2 = uuidSeq[1]; + sequenceReference->fMs3 = uuidSeq[2]; + sequenceReference->fMs4[0] = uuidSeq[3]; + sequenceReference->fMs4[1] = uuidSeq[4]; + sequenceReference->fMs4[2] = uuidSeq[5]; + sequenceReference->fMs4[3] = uuidSeq[6]; + sequenceReference->fMs4[4] = uuidSeq[7]; + sequenceReference->fMs4[5] = uuidSeq[8]; + sequenceReference->fMs4[6] = uuidSeq[9]; + sequenceReference->fMs4[7] = uuidSeq[10]; return sequenceReference; } // @brief Tries to make a guid out of a string. // This function is not complete for now - auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> + auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> { Char buf[kUUIDSize]; diff --git a/Kernel/Sources/GUIDWrapper.cxx b/Kernel/Sources/GUIDWrapper.cxx index 259c76e2..c7b4fc7c 100644 --- a/Kernel/Sources/GUIDWrapper.cxx +++ b/Kernel/Sources/GUIDWrapper.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 23d63953..f10c3a15 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/HalPageAlloc.cxx b/Kernel/Sources/HalPageAlloc.cxx index 0339745b..75e31e86 100644 --- a/Kernel/Sources/HalPageAlloc.cxx +++ b/Kernel/Sources/HalPageAlloc.cxx @@ -1,15 +1,15 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif #include <NewKit/Defines.hpp> @@ -29,7 +29,7 @@ namespace Kernel Boolean Present; Boolean ReadWrite; Boolean User; - SizeT PageSize; + SizeT Size; }; struct VirtualMemoryHeaderTraits @@ -39,7 +39,7 @@ namespace Kernel /// @return VirtualMemoryHeader* Next(VirtualMemoryHeader* current) { - return current + sizeof(PTE) + current->PageSize; + return current + sizeof(VirtualMemoryHeader) + current->Size; } /// @brief Get previous header. @@ -47,7 +47,7 @@ namespace Kernel /// @return VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) { - return current - sizeof(PTE) - current->PageSize; + return current - sizeof(VirtualMemoryHeader) - current->Size; } }; } // namespace Detail @@ -80,7 +80,7 @@ namespace Kernel vmHeader->Present = true; vmHeader->ReadWrite = rw; vmHeader->User = user; - vmHeader->PageSize = size; + vmHeader->Size = size; kAllocationInProgress = false; diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/Heap.cxx index 7bfd9c07..6ac91448 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/Heap.cxx @@ -1,17 +1,17 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/HError.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/Crc32.hpp> #include <NewKit/PageManager.hpp> //! @file KernelHeap.cxx -//! @brief Kernel allocator. +//! @brief Kernel heap allocator. #define kKernelHeapMagic (0xD4D7D5) #define kKernelHeapHeaderPaddingSz (16U) @@ -47,23 +47,47 @@ namespace Kernel typedef HeapInformationBlock* HeapInformationBlockPtr; } // namespace Detail + /// @brief Declare a new size for allocatedPtr. + /// @param allocatedPtr the pointer. + /// @return + voidPtr ke_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz) + { + if (!allocatedPtr || newSz < 1) + return nullptr; + + Detail::HeapInformationBlockPtr heapInfoBlk = + reinterpret_cast<Detail::HeapInformationBlockPtr>( + (UIntPtr)allocatedPtr - sizeof(Detail::HeapInformationBlock)); + + heapInfoBlk->fTargetPtrSize = newSz; + + if (heapInfoBlk->fCRC32 > 0) + { + MUST_PASS(ke_protect_ke_heap(allocatedPtr)); + } + + return allocatedPtr; + } + /// @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? /// @return the pointer - VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) + VoidPtr ke_new_ke_heap(const SizeT sz, const bool rw, const bool user) { - if (sz == 0) - ++sz; + auto szFix = sz; + + if (szFix == 0) + ++szFix; - auto wrapper = kHeapPageManager.Request(rw, user, false, sz); + auto wrapper = kHeapPageManager.Request(rw, user, false, szFix); Detail::HeapInformationBlockPtr heapInfo = reinterpret_cast<Detail::HeapInformationBlockPtr>( wrapper.VirtualAddress()); - heapInfo->fTargetPtrSize = sz; + heapInfo->fTargetPtrSize = szFix; heapInfo->fMagic = kKernelHeapMagic; heapInfo->fCRC32 = 0; // dont fill it for now. heapInfo->fTargetPtr = wrapper.VirtualAddress(); @@ -130,10 +154,10 @@ namespace Kernel } heapInfoBlk->fTargetPtrSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fTargetPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heapInfoBlk->fPresent = false; + heapInfoBlk->fTargetPtr = 0; + heapInfoBlk->fCRC32 = 0; + heapInfoBlk->fMagic = 0; PTEWrapper pageWrapper(false, false, false, reinterpret_cast<UIntPtr>(heapInfoBlk)); Ref<PTEWrapper*> pteAddress{&pageWrapper}; diff --git a/Kernel/Sources/IndexableProperty.cxx b/Kernel/Sources/IndexableProperty.cxx index 5cb1d54a..940a7d7a 100644 --- a/Kernel/Sources/IndexableProperty.cxx +++ b/Kernel/Sources/IndexableProperty.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Json.cxx b/Kernel/Sources/Json.cxx index 16a74765..ffec19ce 100644 --- a/Kernel/Sources/Json.cxx +++ b/Kernel/Sources/Json.cxx @@ -1,12 +1,12 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <NewKit/Json.hpp> +#include <NewKit/Json.hxx> using namespace Kernel; /// @brief Undefined object, is null in length. -INIT(Kernel::JsonType::kUndefined, Kernel::JsonType); +cInitObject(Kernel::JsonType::kNull, Kernel::JsonType); diff --git a/Kernel/Sources/KernelCheck.cxx b/Kernel/Sources/KernelCheck.cxx index 6eb5429c..690c8e8f 100644 --- a/Kernel/Sources/KernelCheck.cxx +++ b/Kernel/Sources/KernelCheck.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,10 +8,12 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/KernelCheck.hpp> #include <NewKit/String.hpp> +#include <FirmwareKit/Handover.hxx> +#include <Modules/ACPI/ACPIFactoryInterface.hxx> -EXTERN_C [[noreturn]] void ke_wait_for_debugger() +EXTERN_C [[noreturn]] Kernel::Void ke_wait_for_debugger() { - while (true) + while (Yes) { #ifdef __NEWOS_AMD64__ Kernel::HAL::rt_cli(); @@ -88,12 +90,20 @@ namespace Kernel } }; - DumpManager::Dump(); + RecoveryFactory::Recover(); + } + + Void RecoveryFactory::Recover() noexcept + { #ifdef __DEBUG__ ke_wait_for_debugger(); #endif // ifdef __DEBUG__ + + PowerFactoryInterface powerInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); + powerInterface.Shutdown(); } + void ke_runtime_check(bool expr, const char* file, const char* line) { @@ -105,7 +115,7 @@ namespace Kernel #endif // __DEBUG__ - Kernel::ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed + ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed } } } // namespace Kernel diff --git a/Kernel/Sources/LockDelegate.cxx b/Kernel/Sources/LockDelegate.cxx index 6f0aa1d4..df9eb3e4 100644 --- a/Kernel/Sources/LockDelegate.cxx +++ b/Kernel/Sources/LockDelegate.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/Main.cxx index 7ec96539..0f835adc 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/Main.cxx @@ -1,9 +1,9 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies - File: KeMain.cxx - Purpose: Kernel main loop. + File: Main.cxx + Purpose: Main entrypoint of kernel. ------------------------------------------- */ @@ -13,20 +13,24 @@ #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> -#include <KernelKit/KernelHeap.hpp> -#include <KernelKit/PEF.hpp> +#include <KernelKit/Heap.hxx> +#include <KernelKit/PEF.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> -#include <KernelKit/UserHeap.hpp> -#include <NewKit/Json.hpp> +#include <KernelKit/ProcessHeap.hxx> +#include <NewKit/Json.hxx> #include <NewKit/KernelCheck.hpp> #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> #include <KernelKit/CodeManager.hpp> +#include <CFKit/Property.hpp> + +EXTERN Kernel::Property cKernelVersion; +EXTERN Kernel::Property cAutoFormatDisk; namespace Kernel::Detail { - /// @brief Filesystem auto installer, additional checks are also done by the class. + /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { Kernel::NewFilesystemManager* fNewFS{nullptr}; @@ -35,16 +39,20 @@ namespace Kernel::Detail /// @brief wizard constructor. explicit FilesystemInstaller() { + if (cAutoFormatDisk.GetValue() == No) + { + return; + } + if (Kernel::FilesystemManagerInterface::GetMounted()) { - /// Mounted partition, cool! + // Partition is mounted, cool! Kernel::kcout - << "newoskrnl: No need to create for a NewFS partition here...\r"; + << "newoskrnl: No need to create for a new NewFS (EPM) partition here...\r"; } else { - /// Not mounted partition, auto-mount. - ///! Mounts a NewFS block. + // Mounts a NewFS from main drive. fNewFS = new Kernel::NewFilesystemManager(); Kernel::FilesystemManagerInterface::Mount(fNewFS); @@ -54,8 +62,8 @@ namespace Kernel::Detail constexpr auto cFolderInfo = "META-INF"; const auto cDirCount = 9; const char* cDirStr[cDirCount] = { - "C:\\Boot\\", "C:\\System\\", "C:\\Support\\", "C:\\Applications\\", - "C:\\Users\\", "C:\\Library\\", "C:\\Mount\\", "C:\\DCIM\\", "C:\\Storage\\"}; + "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", + "\\Users\\", "\\Library\\", "\\Mounted\\", "\\DCIM\\", "\\Applications\\Store\\"}; for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { @@ -63,7 +71,7 @@ namespace Kernel::Detail if (catalogDir) { - Kernel::kcout << "newoskrnl: Already here\r"; + Kernel::kcout << "newoskrnl: already exists.\r"; delete catalogDir; continue; @@ -72,16 +80,16 @@ namespace Kernel::Detail catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, kNewFSCatalogKindDir); - NewFork theFork{0}; + NFS_FORK_STRUCT theFork{0}; const Kernel::Char* cSrcName = cFolderInfo; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDir->Name), - theFork.CatalogName, - Kernel::rt_string_len(catalogDir->Name)); + theFork.CatalogName, + Kernel::rt_string_len(catalogDir->Name)); delete catalogDir; @@ -93,7 +101,7 @@ namespace Kernel::Detail Kernel::StringView metadataFolder(kNewFSSectorSz); metadataFolder += - "<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " + "<!properties/>\r<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " "system</p>\r<p>Volume Type: Zeta</p>\r"; metadataFolder += "<p>Path: "; @@ -114,28 +122,24 @@ namespace Kernel::Detail } } - NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("C:\\Mount\\SIM:"); + NFS_CATALOG_STRUCT* catalogDisk = + this->fNewFS->GetParser()->GetCatalog("\\Mount\\SIM:"); const Kernel::Char* cSrcName = "DISK-INF"; if (catalogDisk) { - auto bufferInfoDisk = (Kernel::Char*)this->fNewFS->GetParser()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); - Kernel::kcout << bufferInfoDisk << Kernel::end_line(); - - delete bufferInfoDisk; delete catalogDisk; } else { catalogDisk = - (NewCatalog*)this->Leak()->CreateAlias("C:\\Mount\\SIM:"); + (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\SIM:"); Kernel::StringView diskFolder(kNewFSSectorSz); diskFolder += - "<p>Kind: alias to SIM Card</p>\r<p>Created by: system</p>\r<p>Edited " + "<!properties/><p>Kind: alias to SIM Card</p>\r<p>Created by: system</p>\r<p>Edited " "by: " "system</p>\r<p>Volume Type: SIM Card</p>\r"; @@ -143,14 +147,14 @@ namespace Kernel::Detail diskFolder += Kernel::NewFilesystemHelper::Root(); diskFolder += "</p>\r"; - NewFork theDiskFork{0}; + NFS_FORK_STRUCT theDiskFork{0}; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); + theDiskFork.CatalogName, + Kernel::rt_string_len(catalogDisk->Name)); theDiskFork.DataSize = kNewFSForkSize; theDiskFork.ResourceId = 0; @@ -162,8 +166,6 @@ namespace Kernel::Detail (Kernel::VoidPtr)diskFolder.CData(), kNewFSSectorSz, cSrcName); - Kernel::kcout << diskFolder.CData() << Kernel::end_line(); - delete catalogDisk; } } @@ -184,29 +186,15 @@ namespace Kernel::Detail /// @brief Loads necessary servers for the kernel -> user mode switch. /// @param void no args. /// @return void no return value. - STATIC Kernel::Void ke_launch_srv(Kernel::Void) + STATIC Kernel::Void ke_user_switch(Kernel::Void) { - // load security server. - Kernel::PEFLoader launchDevil("C:\\System\\launchd"); - if (!launchDevil.IsLoaded()) - { - Kernel::ke_stop(RUNTIME_CHECK_FAILED); - } - - Kernel::Utils::execute_from_image(launchDevil, - Kernel::ProcessHeader::kAppKind); + Kernel::UserView::The()->fRootUser = new User(RingKind::kRingSuperUser, kSuperUser); + Kernel::kcout << "newoskrnl: logged in as: " << Kernel::UserView::The()->fRootUser->Name().CData() << Kernel::endl; - /// load middleware service. - Kernel::PEFLoader stageBoard("C:\\System\\stageboard"); - - if (!stageBoard.IsLoaded()) - { - Kernel::ke_stop(RUNTIME_CHECK_FAILED); - } + Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser); - Kernel::Utils::execute_from_image(stageBoard, - Kernel::ProcessHeader::kAppKind); + Kernel::kcout << "newoskrnl: " << cKernelVersion.GetKey().CData() << ": " << Kernel::number(cKernelVersion.GetValue()) << Kernel::endl; } } // namespace Kernel::Detail @@ -217,5 +205,5 @@ EXTERN_C Kernel::Void KeMain(Kernel::Void) { /// Now run kernel loop, until no process are running. Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. - Kernel::Detail::ke_launch_srv(); + Kernel::Detail::ke_user_switch(); } diff --git a/Kernel/Sources/MutableArray.cxx b/Kernel/Sources/MutableArray.cxx index 2099c01a..2bc62fcb 100644 --- a/Kernel/Sources/MutableArray.cxx +++ b/Kernel/Sources/MutableArray.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Network/IP.cxx b/Kernel/Sources/Network/IP.cxx index 676e12a8..64da3448 100644 --- a/Kernel/Sources/Network/IP.cxx +++ b/Kernel/Sources/Network/IP.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -90,13 +90,13 @@ namespace Kernel return true; } - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6) + ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6>& ipv6) { auto str = StringBuilder::Construct(ipv6.Leak().Address()); return str; } - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) + ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress>& ipv4) { auto str = StringBuilder::Construct(ipv4.Leak().Address()); return str; diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index 1869035b..54d94b18 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,46 +12,39 @@ using namespace Kernel; /// @internal /// @brief The internal sanitize function. -Bool __ipc_sanitize_packet(IPCEPMessageHeader* pckt) +Bool ipc_int_sanitize_packet(IPCEPMessageHeader* pckt) { - if (!pckt) return false; - auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); switch (endian) { - case Endian::kEndianBig: - { + case Endian::kEndianBig: { if (pckt->IpcEndianess == eIPCEPLittleEndian) - goto _Fail; + goto ipc_check_failed; break; } - case Endian::kEndianLittle: - { + case Endian::kEndianLittle: { if (pckt->IpcEndianess == eIPCEPBigEndian) - goto _Fail; + goto ipc_check_failed; break; } case Endian::kEndianMixed: break; default: - goto _Fail; + goto ipc_check_failed; } - if (pckt->IpcFrom == pckt->IpcTo) + if (pckt->IpcFrom == pckt->IpcTo || + pckt->IpcPacketSize > cIPCEPMsgSize) { - goto _Fail; - } - if (pckt->IpcPacketSize > cIPCEPMsgSize) - { - goto _Fail; + goto ipc_check_failed; } return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; -_Fail: +ipc_check_failed: ErrLocal() = kErrorIPC; return false; } @@ -63,7 +56,8 @@ namespace Kernel /// @retval false packet is incorrect and process has crashed. Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) { - if (!__ipc_sanitize_packet(pckt)) + if (!pckt || + !ipc_int_sanitize_packet(pckt)) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return false; @@ -71,4 +65,4 @@ namespace Kernel return true; } -} +} // namespace Kernel diff --git a/Kernel/Sources/Network/NetworkDevice.cxx b/Kernel/Sources/Network/NetworkDevice.cxx index 4ee633e8..7c61460e 100644 --- a/Kernel/Sources/Network/NetworkDevice.cxx +++ b/Kernel/Sources/Network/NetworkDevice.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/New+Delete.cxx b/Kernel/Sources/New+Delete.cxx index d87df3e6..2921e079 100644 --- a/Kernel/Sources/New+Delete.cxx +++ b/Kernel/Sources/New+Delete.cxx @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/New.hpp> void* operator new[](size_t sz) diff --git a/Kernel/Sources/NewFS+FileManager.cxx b/Kernel/Sources/NewFS+FileManager.cxx index 2658d784..146f721d 100644 --- a/Kernel/Sources/NewFS+FileManager.cxx +++ b/Kernel/Sources/NewFS+FileManager.cxx @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/FileManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ /// @brief NewFS File manager. /// BUGS: 0 @@ -86,4 +86,4 @@ namespace Kernel } } // namespace Kernel -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/NewFS+IO.cxx b/Kernel/Sources/NewFS+IO.cxx index 884f8c11..314d309a 100644 --- a/Kernel/Sources/NewFS+IO.cxx +++ b/Kernel/Sources/NewFS+IO.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -13,11 +13,11 @@ * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * *************************************************************/ -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ #include <FirmwareKit/EPM.hxx> @@ -98,4 +98,4 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn return DrvTrait.fPacket.fPacketGood; } -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/NewFS+Journal.cxx b/Kernel/Sources/NewFS+Journal.cxx index f69744cc..8685f6ee 100644 --- a/Kernel/Sources/NewFS+Journal.cxx +++ b/Kernel/Sources/NewFS+Journal.cxx @@ -1,13 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/FileManager.hpp> -#ifdef __FSKIT_NEWFS__ +#ifdef __FSKIT_USE_NEWFS__ ///! BUGS: 0 ///! @file NewFS+Journal.cxx @@ -19,4 +19,4 @@ namespace Kernel::Journal using namespace Kernel; -#endif // ifdef __FSKIT_NEWFS__ +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/OwnPtr.cxx b/Kernel/Sources/OwnPtr.cxx index ca129740..cfb51b86 100644 --- a/Kernel/Sources/OwnPtr.cxx +++ b/Kernel/Sources/OwnPtr.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/PEFCodeManager.cxx b/Kernel/Sources/PEFCodeManager.cxx index 6f06ac37..8b1918ef 100644 --- a/Kernel/Sources/PEFCodeManager.cxx +++ b/Kernel/Sources/PEFCodeManager.cxx @@ -1,11 +1,11 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> #include <NewKit/Defines.hpp> diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx index 3e7ec9eb..dccb9d12 100644 --- a/Kernel/Sources/PEFSharedObject.cxx +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -2,13 +2,13 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/PEF.hpp> +#include <KernelKit/PEF.hxx> #include <KernelKit/PEFSharedObject.hxx> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> @@ -18,66 +18,69 @@ Revision History: - 01/02/24: Rework shared library ABI, except a rt_library_init and - rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the + 01/02/24: Rework shared sharedObj ABI, except a rt_library_init and + rt_library_fini (amlel) 15/02/24: Breaking changes, changed the name of the routines. (amlel) + 07/28/24: Replace rt_library_free with rt_library_fini + ------------------------------------------- */ using namespace Kernel; /***********************************************************************************/ -/// @file SharedObjectRT.cxx -/// @brief Shared Object runtime. +/// @file PEFSharedObjectRT.cxx +/// @brief PEF's shared object runtime. /***********************************************************************************/ /***********************************************************************************/ -/* @brief Library runtime initializer. */ +/** @brief Library initializer. */ /***********************************************************************************/ EXTERN_C SharedObjectPtr rt_library_init(void) { - SharedObjectPtr library = tls_new_class<SharedObject>(); + SharedObjectPtr sharedObj = tls_new_class<SharedObject>(); - if (!library) + if (!sharedObj) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); + sharedObj->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); - if (!library->Get()) + if (!sharedObj->Get()) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Get()->fImageObject = + sharedObj->Get()->fImageObject = ProcessScheduler::The().Leak().TheCurrent().Leak().Image; - if (!library->Get()->fImageObject) + if (!sharedObj->Get()->fImageObject) { ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } - library->Get()->fImageEntrypointOffset = - library->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + sharedObj->Get()->fImageEntrypointOffset = + sharedObj->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - return library; + return sharedObj; } /***********************************************************************************/ -/* @brief Ends the library. */ -/* @note Please check if the lib got freed! */ -/* @param SharedObjectPtr the library to free. */ +/** @brief Frees the sharedObj. */ +/** @note Please check if the lib got freed! */ +/** @param lib The sharedObj to free. */ +/** @param successful Reports if successful or not. */ /***********************************************************************************/ -EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) +EXTERN_C Void rt_library_fini(SharedObjectPtr lib, bool* successful) { MUST_PASS(successful); @@ -97,9 +100,10 @@ EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) } /***********************************************************************************/ - /// @brief Unimplemented function (crashes by default) /// @param +/***********************************************************************************/ + EXTERN_C void __mh_purecall(void) { kcout << "newoskrnl: unimplemented symbol!\r"; diff --git a/Kernel/Sources/PRDT.cxx b/Kernel/Sources/PRDT.cxx index 73dadbab..372df03f 100644 --- a/Kernel/Sources/PRDT.cxx +++ b/Kernel/Sources/PRDT.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/PageAllocator.cxx b/Kernel/Sources/PageAllocator.cxx index 27006885..5adf1de3 100644 --- a/Kernel/Sources/PageAllocator.cxx +++ b/Kernel/Sources/PageAllocator.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -26,11 +26,14 @@ namespace Kernel::Detail void exec_disable(UIntPtr VirtualAddr) { +#ifdef __NEWOS_SUPPORT_NX__ PTE* VirtualAddrTable = reinterpret_cast<PTE*>(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); + + MUST_PASS(!VirtualAddrTable->ExecDisable == false); VirtualAddrTable->ExecDisable = true; hal_flush_tlb(); +#endif // ifdef __NEWOS_SUPPORT_NX__ } bool page_disable(UIntPtr VirtualAddr) @@ -38,8 +41,8 @@ namespace Kernel::Detail if (VirtualAddr) { auto VirtualAddrTable = (PTE*)(VirtualAddr); - MUST_PASS(!VirtualAddrTable->Accessed); + MUST_PASS(!VirtualAddrTable->Present == true); VirtualAddrTable->Present = false; hal_flush_tlb(); diff --git a/Kernel/Sources/PageManager.cxx b/Kernel/Sources/PageManager.cxx index 35693310..a9672b3b 100644 --- a/Kernel/Sources/PageManager.cxx +++ b/Kernel/Sources/PageManager.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,9 +8,9 @@ #include <NewKit/PageManager.hpp> #ifdef __NEWOS_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> +#include <HALKit/AMD64/HalPageAlloc.hxx> #elif defined(__NEWOS_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hpp> +#include <HALKit/ARM64/HalPageAlloc.hxx> #endif // ifdef __NEWOS_AMD64__ || defined(__NEWOS_ARM64__) //! null deref will throw (Page Zero detected, aborting app!) diff --git a/Kernel/Sources/PermissionSelector.cxx b/Kernel/Sources/PermissionSelector.cxx deleted file mode 100644 index e5cfd409..00000000 --- a/Kernel/Sources/PermissionSelector.cxx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. - * - * File: PermissionSelector.cpp - * Purpose: Permission selectors. - * - * ======================================================== - */ - -#include <KernelKit/PermissionSelector.hxx> -#include <NewKit/KernelCheck.hpp> - -/// bugs 0 - -namespace Kernel -{ - PermissionSelector::PermissionSelector(const Int32& sel) - : fRing((RingKind)sel) - { - MUST_PASS(sel > 0); - } - - PermissionSelector::PermissionSelector(const RingKind& ringKind) - : fRing(ringKind) - { - } - - PermissionSelector::~PermissionSelector() = default; - - bool PermissionSelector::operator==(const PermissionSelector& lhs) - { - return lhs.fRing == this->fRing; - } - - bool PermissionSelector::operator!=(const PermissionSelector& lhs) - { - return lhs.fRing != this->fRing; - } - - const RingKind& PermissionSelector::Ring() noexcept - { - return this->fRing; - } -} // namespace Kernel diff --git a/Kernel/Sources/Pmm.cxx b/Kernel/Sources/Pmm.cxx index 22813206..f3425c5a 100644 --- a/Kernel/Sources/Pmm.cxx +++ b/Kernel/Sources/Pmm.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,7 +12,7 @@ #endif #if defined(__NEWOS_AMD64__) -#include <HALKit/AMD64/Processor.hpp> +#include <HALKit/AMD64/Processor.hxx> #endif namespace Kernel diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/ProcessHeap.cxx index 453d1f30..86ac1554 100644 --- a/Kernel/Sources/UserHeap.cxx +++ b/Kernel/Sources/ProcessHeap.cxx @@ -1,16 +1,16 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <KernelKit/ProcessScheduler.hxx> -#include <KernelKit/UserHeap.hpp> +#include <KernelKit/ProcessHeap.hxx> #include <NewKit/PageManager.hpp> #define kHeapHeaderPaddingSz (16U) -/// @file UserHeap.cxx +/// @file ProcessHeap.cxx /// @brief User Heap Manager, Process heap allocator. /// @note if you want to look at the kernel allocator, please look for /// KernelHeap.cxx @@ -22,7 +22,7 @@ namespace Kernel * @brief Process Heap Header * @note Allocated per process, it denotes the user's heap. */ - struct UserHeapHeader final + struct PROCESS_HEAP_HEADER final { UInt32 fMagic; Int32 fFlags; @@ -30,35 +30,38 @@ namespace Kernel UInt8 fPadding[kHeapHeaderPaddingSz]; }; + /// @brief PROCESS_HEAP_HEADER as pointer type. + typedef PROCESS_HEAP_HEADER* PROCESS_HEAP_HEADER_PTR; + /** - * @brief User Heap Manager class, takes care of allocating the process pools. + * @brief Process heap class, takes care of allocating the process pools. * @note This rely on Virtual Memory! Consider adding good vmem support when * @note porting to a new arch. */ - class UserHeapManager final + class ProcessHeapHelper final { - UserHeapManager() = delete; + ProcessHeapHelper() = delete; public: - ~UserHeapManager() = default; + ~ProcessHeapHelper() = default; public: - STATIC SizeT& Count() + STATIC SizeT& Count() noexcept { return s_NumPools; } - STATIC Ref<Pmm>& Leak() + STATIC Ref<Pmm>& Leak() noexcept { return s_Pmm; } - STATIC Boolean& IsEnabled() + STATIC Boolean& IsEnabled() noexcept { return s_PoolsAreEnabled; } - STATIC MutableArray<Ref<PTEWrapper>>& The() + STATIC MutableArray<Ref<PTEWrapper>>& The() noexcept { return s_Pool; } @@ -74,10 +77,10 @@ namespace Kernel //! declare fields - SizeT UserHeapManager::s_NumPools = 0UL; - Ref<Pmm> UserHeapManager::s_Pmm; - Boolean UserHeapManager::s_PoolsAreEnabled = true; - MutableArray<Ref<PTEWrapper>> UserHeapManager::s_Pool; + SizeT ProcessHeapHelper::s_NumPools = 0UL; + Ref<Pmm> ProcessHeapHelper::s_Pmm; + Boolean ProcessHeapHelper::s_PoolsAreEnabled = true; + MutableArray<Ref<PTEWrapper>> ProcessHeapHelper::s_Pool; STATIC VoidPtr ke_find_unused_heap(Int32 flags); STATIC Void ke_free_heap_internal(VoidPtr vaddr); @@ -91,15 +94,15 @@ namespace Kernel { for (SizeT index = 0; index < kUserHeapMaxSz; ++index) { - if (UserHeapManager::The()[index] && - !UserHeapManager::The()[index].Leak().Leak().Present()) + if (ProcessHeapHelper::The()[index] && + !ProcessHeapHelper::The()[index].Leak().Leak().Present()) { - UserHeapManager::Leak().Leak().TogglePresent( - UserHeapManager::The()[index].Leak().Leak(), true); + ProcessHeapHelper::Leak().Leak().TogglePresent( + ProcessHeapHelper::The()[index].Leak().Leak(), true); kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r"; return ke_make_heap_internal( - (VoidPtr)UserHeapManager::The()[index].Leak().Leak().VirtualAddress(), + (VoidPtr)ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress(), flags); } } @@ -115,7 +118,7 @@ namespace Kernel { if (virtualAddress) { - UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>(virtualAddress); + PROCESS_HEAP_HEADER* poolHdr = reinterpret_cast<PROCESS_HEAP_HEADER*>(virtualAddress); if (!poolHdr->fFree) { @@ -130,7 +133,7 @@ namespace Kernel kcout << "[ke_make_heap_internal] New allocation has been done.\n"; return reinterpret_cast<VoidPtr>( - (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(UserHeapHeader))); + (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(PROCESS_HEAP_HEADER))); } kcout << "[ke_make_heap_internal] Address is invalid"; @@ -143,8 +146,8 @@ namespace Kernel /// @return STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) { - UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>( - reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(UserHeapHeader)); + PROCESS_HEAP_HEADER* poolHdr = reinterpret_cast<PROCESS_HEAP_HEADER*>( + reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(PROCESS_HEAP_HEADER)); if (poolHdr->fMagic == kUserHeapMag) { @@ -170,18 +173,18 @@ namespace Kernel */ STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr) { - if (UserHeapManager::The()[index]) + if (ProcessHeapHelper::The()[index]) { // ErrorOr<>::operator Boolean /// if (address matches) /// -> Free heap. - if (UserHeapManager::The()[index].Leak().Leak().VirtualAddress() == + if (ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress() == (UIntPtr)ptr) { - UserHeapManager::Leak().Leak().FreePage( - UserHeapManager::The()[index].Leak().Leak()); + ProcessHeapHelper::Leak().Leak().FreePage( + ProcessHeapHelper::The()[index].Leak().Leak()); - --UserHeapManager::Count(); + --ProcessHeapHelper::Count(); ke_free_heap_internal(ptr); ptr = nullptr; @@ -198,24 +201,24 @@ namespace Kernel /// @return a pool pointer with selected permissions. VoidPtr rt_new_heap(Int32 flags) { - if (!UserHeapManager::IsEnabled()) + if (!ProcessHeapHelper::IsEnabled()) return nullptr; - if (UserHeapManager::Count() > kUserHeapMaxSz) + if (ProcessHeapHelper::Count() > kUserHeapMaxSz) return nullptr; if (VoidPtr ret = ke_find_unused_heap(flags)) return ret; // this wasn't set to true - auto ref_page = UserHeapManager::Leak().Leak().RequestPage( + auto ref_page = ProcessHeapHelper::Leak().Leak().RequestPage( ((flags & kUserHeapUser)), (flags & kUserHeapRw)); if (ref_page) { ///! reserve page. - UserHeapManager::The()[UserHeapManager::Count()].Leak() = ref_page; - auto& ref = UserHeapManager::Count(); + ProcessHeapHelper::The()[ProcessHeapHelper::Count()].Leak() = ref_page; + auto& ref = ProcessHeapHelper::Count(); ++ref; // increment the number of addresses we have now. @@ -232,12 +235,12 @@ namespace Kernel /// @return status code Int32 rt_free_heap(VoidPtr ptr) { - if (!UserHeapManager::IsEnabled()) + if (!ProcessHeapHelper::IsEnabled()) return -1; if (ptr) { - SizeT base = UserHeapManager::Count(); + SizeT base = ProcessHeapHelper::Count(); if (ke_check_and_free_heap(base, ptr)) return 0; diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 316a9362..bfa6fddf 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -11,7 +11,7 @@ #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/SMPManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/String.hpp> #include <KernelKit/HError.hpp> @@ -29,14 +29,9 @@ namespace Kernel STATIC Int32 cLastExitCode = 0U; - /// @brief Gets the latest exit code. + /// @brief Gets the last exit code. /// @note Not thread-safe. /// @return Int32 the last exit code. - const Int32& ProcessHeader::GetExitCode() noexcept - { - return fLastExitCode; - } - const Int32& rt_get_exit_code() noexcept { return cLastExitCode; @@ -48,14 +43,31 @@ namespace Kernel void ProcessHeader::Crash() { - kcout << (*this->Name == 0 ? "Unknown" : this->Name) << ": crashed. (id = "; + kcout << (*this->Name == 0 ? "Kernel" : this->Name) << ": crashed. (id = "; kcout.Number(kErrorProcessFault); kcout << ")\r"; + if (Kernel::ProcessScheduler::The().Leak().CurrentTeam().AsArray().Count() < 1) + { + kcout << "*** BAD PROCESS ***\rTerminating as we are the only process...\r"; + ke_stop(RUNTIME_CHECK_PROCESS); + } + this->Exit(kErrorProcessFault); } - Int32& ProcessHeader::GetLocalCode() noexcept { return fLocalCode; } + /// @brief Gets the local last exit code. + /// @note Not thread-safe. + /// @return Int32 the last exit code. + const Int32& ProcessHeader::GetExitCode() noexcept + { + return this->fLastExitCode; + } + + Int32& ProcessHeader::GetLocalCode() noexcept + { + return fLocalCode; + } void ProcessHeader::Wake(const bool should_wakeup) { @@ -73,13 +85,13 @@ namespace Kernel { ErrLocal() = kErrorHeapOutOfMemory; - /* we're going out of memory */ + /* We're going out of memory! crash... */ this->Crash(); return nullptr; } - this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); + this->HeapCursor = reinterpret_cast<VoidPtr>((UIntPtr)this->HeapCursor + (sizeof(sz))); VoidPtr ptr = this->HeapCursor; ++this->UsedMemory; @@ -94,21 +106,17 @@ namespace Kernel /***********************************************************************************/ /* @brief checks if runtime pointer is in region. */ - bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& sz) + bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz) { - UIntPtr* _pool_ptr = (UIntPtr*)pool_ptr; - UIntPtr* _pool = (UIntPtr*)pool; - - for (SizeT index = sz; _pool[sz] != kUserHeapMag; --index) - { - if (&_pool[index] > &_pool_ptr[sz]) - continue; + if (pool == nullptr || + pool_ptr == nullptr) + return false; - if (_pool[index] == _pool_ptr[index]) - return true; - } + UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr; + UIntPtr* uint_pool = (UIntPtr*)pool; - return false; + return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr && + pool_ptr_cur_sz > pool_ptr_used_sz; } /* @brief free pointer from usage. */ @@ -121,7 +129,7 @@ namespace Kernel if (this->UsedMemory < 1) return false; - if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory)) + if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory)) { this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); rt_zero_memory(ptr, sz); @@ -136,7 +144,7 @@ namespace Kernel } /// @brief process name getter. - const Char* ProcessHeader::GetName() noexcept + const Char* ProcessHeader::GetProcessName() noexcept { return this->Name; } @@ -166,7 +174,7 @@ namespace Kernel /** @brief Standard exit proc. */ - void ProcessHeader::Exit(Int32 exit_code) + void ProcessHeader::Exit(const Int32& exit_code) { if (this->ProcessId != ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) @@ -178,6 +186,7 @@ namespace Kernel //! Delete image if not done already. if (this->Image) ke_delete_ke_heap(this->Image); + if (this->StackFrame) ke_delete_ke_heap((VoidPtr)this->StackFrame); @@ -203,15 +212,23 @@ namespace Kernel if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; - kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r"; + kcout << "ProcessScheduler:: adding process to team...\r"; /// Create heap according to type of process. if (process.Leak().Kind == ProcessHeader::kAppKind) + { process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); + } else if (process.Leak().Kind == ProcessHeader::kShLibKind) + { process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared); + } else - process.Leak().HeapPtr = rt_new_heap(kUserHeapDriver | kUserHeapRw); + { + // something went wrong, do not continue, process kind is incorrect. + process.Leak().Crash(); + return -kErrorProcessFault; + } process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame*>( ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); @@ -223,22 +240,28 @@ namespace Kernel process.Leak().ProcessId = (mTeam.AsArray().Count() - 1); process.Leak().HeapCursor = process.Leak().HeapPtr; - mTeam.AsArray().Add(process); + MUST_PASS(mTeam.AsArray().Add(process)); - return mTeam.AsArray().Count() - 1; + return (mTeam.AsArray().Count() - 1); } /// @brief Remove process from list. - /// @param process - /// @return - bool ProcessScheduler::Remove(SizeT process) + /// @param processSlot process slot inside team. + /// @retval true process was removed. + /// @retval false process doesn't exist in team. + Bool ProcessScheduler::Remove(SizeT processSlot) { - if (process > mTeam.AsArray().Count()) + // check if process is within range. + if (processSlot > mTeam.AsArray().Count()) return false; - kcout << "ProcessScheduler::Remove(SizeT process)\r"; + // also check if the process isn't a dummy one. + if (mTeam.AsArray()[processSlot].Leak().Leak().Image == nullptr) + return false; - return mTeam.AsArray().Remove(process); + kcout << "ProcessScheduler: removing process\r"; + + return mTeam.AsArray().Remove(processSlot); } /// @brief Run scheduler. @@ -257,21 +280,21 @@ namespace Kernel { auto unwrapped_process = *process.Leak(); - unwrapped_process.PTime = 0; - // set the current process. mTeam.AsRef() = unwrapped_process; // tell helper to find a core to schedule on. - ProcessHelper::Switch(mTeam.AsRef().Leak().StackFrame, - mTeam.AsRef().Leak().ProcessId); + ProcessHelper::Switch(unwrapped_process.StackFrame, + unwrapped_process.ProcessId); - kcout << unwrapped_process.Name << ": process switched.\r"; + unwrapped_process.PTime = static_cast<Int32>(unwrapped_process.Affinity); + + kcout << unwrapped_process.Name << ": has been switched to process core.\r"; } else { // otherwise increment the P-time. - ++mTeam.AsRef().Leak().PTime; + --mTeam.AsRef().Leak().PTime; } } @@ -285,12 +308,14 @@ namespace Kernel return mTeam; } + /// @internal + STATIC Ref<ProcessScheduler> cSchedulerRef; + /// @brief Shared instance of the process scheduler. /// @return - Ref<ProcessScheduler&> ProcessScheduler::The() + Ref<ProcessScheduler>& ProcessScheduler::The() { - static ProcessScheduler ref; - return {ref}; + return cSchedulerRef; } /// @brief Gets current running process. @@ -320,10 +345,10 @@ namespace Kernel if (process.Leak().GetStatus() == ProcessStatus::kStarting) { - if (process.Leak().PTime < static_cast<Int>(kSchedMinMicroTime)) + if (process.Leak().PTime <= 0) { process.Leak().Status = ProcessStatus::kRunning; - process.Leak().Affinity = AffinityKind::kHartStandard; + process.Leak().Affinity = AffinityKind::kStandard; return true; } @@ -331,7 +356,7 @@ namespace Kernel ++process.Leak().PTime; } - return process.Leak().PTime > static_cast<Int>(kSchedMinMicroTime); + return process.Leak().PTime > 0; } /** diff --git a/Kernel/Sources/ProcessTeam.cxx b/Kernel/Sources/ProcessTeam.cxx index b55ae855..7f3fbcf8 100644 --- a/Kernel/Sources/ProcessTeam.cxx +++ b/Kernel/Sources/ProcessTeam.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Property.cxx b/Kernel/Sources/Property.cxx index db1e0579..60bd03da 100644 --- a/Kernel/Sources/Property.cxx +++ b/Kernel/Sources/Property.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -8,20 +8,19 @@ namespace Kernel { - Property::Property(const StringView& sw) - : fName(sw) - { - kcout << "Property: created: " << sw.CData() << endl; - } - Property::~Property() = default; bool Property::StringEquals(StringView& name) { - return fName && this->fName == name; + return this->fName && this->fName == name; + } + + StringView& Property::GetKey() + { + return this->fName; } - const PropertyId& Property::GetPropertyById() + PropertyId& Property::GetValue() { return fAction; } diff --git a/Kernel/Sources/Ref.cxx b/Kernel/Sources/Ref.cxx index 7661104e..b92ceac4 100644 --- a/Kernel/Sources/Ref.cxx +++ b/Kernel/Sources/Ref.cxx @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <NewKit/Ref.hpp> +#include <NewKit/Ref.hxx> diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 8b0aca9b..f5424525 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -1,12 +1,13 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/SMPManager.hpp> +#include <CFKit/Property.hpp> ///! BUGS: 0 @@ -16,6 +17,8 @@ namespace Kernel { + STATIC Property cSMPCoreName; + ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -120,7 +123,16 @@ namespace Kernel //! @brief Constructor and destructor ///! @brief Default constructor. - SMPManager::SMPManager() = default; + SMPManager::SMPManager() + { + StringView strCoreName(512); + strCoreName += "\\Properties\\Smp\\SchedulerClass"; + + cSMPCoreName.GetKey() = strCoreName; + cSMPCoreName.GetValue() = (UIntPtr)this; + + kcout << "newoskrnl: initializing " << strCoreName.CData() << endl; + } ///! @brief Default destructor. SMPManager::~SMPManager() = default; @@ -160,9 +172,9 @@ namespace Kernel // to avoid any null deref. if (!fThreadList[idx].Leak().Leak()->fStack) continue; - if (fThreadList[idx].Leak().Leak()->fStack->Rsp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->SP == 0) continue; - if (fThreadList[idx].Leak().Leak()->fStack->Rbp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->BP == 0) continue; fThreadList[idx].Leak().Leak()->Busy(true); diff --git a/Kernel/Sources/Semaphore.cxx b/Kernel/Sources/Semaphore.cxx index bef37fa8..ee89f482 100644 --- a/Kernel/Sources/Semaphore.cxx +++ b/Kernel/Sources/Semaphore.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/AHCIDeviceInterface.cxx b/Kernel/Sources/Storage/AHCIDeviceInterface.cxx index 0366efe9..4b0aa23d 100644 --- a/Kernel/Sources/Storage/AHCIDeviceInterface.cxx +++ b/Kernel/Sources/Storage/AHCIDeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/ATADeviceInterface.cxx b/Kernel/Sources/Storage/ATADeviceInterface.cxx index 8c45f31b..cc87491e 100644 --- a/Kernel/Sources/Storage/ATADeviceInterface.cxx +++ b/Kernel/Sources/Storage/ATADeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Storage/NVMEDeviceInterface.cxx b/Kernel/Sources/Storage/NVMEDeviceInterface.cxx index 9b2da7c2..f4f0f667 100644 --- a/Kernel/Sources/Storage/NVMEDeviceInterface.cxx +++ b/Kernel/Sources/Storage/NVMEDeviceInterface.cxx @@ -1,13 +1,26 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ -#include <StorageKit/NVME.hpp> +#include <StorageKit/NVME.hxx> namespace Kernel { + NVMEDeviceInterface::NVMEDeviceInterface(void (*Out)(MountpointInterface* outpacket), + void (*In)(MountpointInterface* inpacket), + void (*Cleanup)(void)) + : DeviceInterface(Out, In), fCleanup(Cleanup) + { + } + + NVMEDeviceInterface::~NVMEDeviceInterface() + { + if (fCleanup) + fCleanup(); + } + const char* NVMEDeviceInterface::Name() const { return ("NVMEDeviceInterface"); diff --git a/Kernel/Sources/Storage/SCSIDeviceInterface.cxx b/Kernel/Sources/Storage/SCSIDeviceInterface.cxx index 9ec5e4c9..14f58794 100644 --- a/Kernel/Sources/Storage/SCSIDeviceInterface.cxx +++ b/Kernel/Sources/Storage/SCSIDeviceInterface.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/Stream.cxx b/Kernel/Sources/Stream.cxx index c83b6184..c2839cae 100644 --- a/Kernel/Sources/Stream.cxx +++ b/Kernel/Sources/Stream.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies File: Stream.cxx Purpose: Stream object diff --git a/Kernel/Sources/String.cxx b/Kernel/Sources/String.cxx index 8dd4b7bf..2ed52029 100644 --- a/Kernel/Sources/String.cxx +++ b/Kernel/Sources/String.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -22,7 +22,7 @@ namespace Kernel Size StringView::Length() const { - return rt_string_len(fData); + return fSz; } bool StringView::operator==(const StringView& rhs) const @@ -98,7 +98,7 @@ namespace Kernel if (!fmt) return ("-1"); - char* ret = (char*)Alloca(sizeof(char) * 8 + rt_string_len(fmt)); + char* ret = (char*)ALLOCA(sizeof(char) * 8 + rt_string_len(fmt)); if (!ret) return ("-1"); @@ -131,7 +131,7 @@ namespace Kernel ret[idx] = fmt[idx]; } - return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */ + return ret; /* Copy that ret into a buffer, 'ALLOCA' allocates to the stack */ } const char* StringBuilder::FromBool(const char* fmt, bool i) @@ -140,7 +140,7 @@ namespace Kernel return ("?"); const char* boolean_expr = i ? "true" : "false"; - char* ret = (char*)Alloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); + char* ret = (char*)ALLOCA((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); if (!ret) return ("?"); @@ -189,7 +189,7 @@ namespace Kernel return ("?"); char* ret = - (char*)Alloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2)); + (char*)ALLOCA(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2)); if (!ret) return ("?"); @@ -214,22 +214,25 @@ namespace Kernel return ret; } - static void string_append(char* lhs, char* rhs, int cur) + STATIC void rt_string_append(Char* lhs, Char* rhs, Int cur) { - if (lhs && rhs) - { - SizeT sz_rhs = rt_string_len(rhs); - - if (sz_rhs == 0) - return; + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; - rt_copy_memory(rhs, lhs + cur, sz_rhs); + for (; rhs_i < sz_rhs; ++rhs_i) + { + lhs[rhs_i + cur] = rhs[rhs_i]; } + + lhs[rhs_i + cur] = 0; } StringView& StringView::operator+=(const Char* rhs) { - string_append(this->fData, const_cast<char*>(rhs), this->fCur); + if (rt_string_len(rhs) > this->Length()) + return *this; + + rt_string_append(this->fData, const_cast<Char*>(rhs), this->fCur); this->fCur += rt_string_len(rhs); return *this; @@ -237,11 +240,11 @@ namespace Kernel StringView& StringView::operator+=(const StringView& rhs) { - if (rt_string_len(rhs.fData) > rt_string_len(this->fData)) + if (rt_string_len(rhs.fData) > this->Length()) return *this; - string_append(this->fData, const_cast<char*>(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast<char*>(rhs.fData)); + rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); return *this; } diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 40a7a75f..245ffa1c 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -2,11 +2,13 @@ * ======================================================== * * Kernel - * Copyright Zeta Electronics Corporation, all rights reserved. + * Copyright ZKA Technologies, all rights reserved. * * ======================================================== */ +#include <NewKit/String.hpp> +#include <CFKit/Property.hpp> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> @@ -14,11 +16,13 @@ /***********************************************************************************/ /// @file ThreadLocalStorage.cxx -/// @brief TLS implementation in kernel. +/// @brief TLS inside the kernel. /***********************************************************************************/ using namespace Kernel; +Kernel::Property cTLSEnforceCheck; + /** * @brief Check for cookie inside TIB. * @param tib the TIB to check. @@ -33,7 +37,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "newoskrnl: Checking for a valid cookie...\r"; + kcout << "newoskrnl: checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -44,18 +48,28 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept +EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { - if (!TIB) - return; + if (!tib_ptr) + { + if (cTLSEnforceCheck.GetValue() == No) + { + return; + } + else + { + kcout << "newoskrnl: crashing because of an invalid TIB...\r"; + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } + } - ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB; + ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr; - if (!tls_check_tib(tib)) + if (!tls_check_tib(tib_struct)) { kcout << "newoskrnl: crashing because of an invalid TIB...\r"; ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } - kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! staying alive...\r"; } diff --git a/Kernel/Sources/Timer.cxx b/Kernel/Sources/Timer.cxx index 38e58b70..ad43310d 100644 --- a/Kernel/Sources/Timer.cxx +++ b/Kernel/Sources/Timer.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ diff --git a/Kernel/Sources/URL.cxx b/Kernel/Sources/URL.cxx index 8d31da7c..88328ea6 100644 --- a/Kernel/Sources/URL.cxx +++ b/Kernel/Sources/URL.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -20,17 +20,17 @@ namespace Kernel URL::~URL() = default; /// @brief internal and reserved protocols by kernel. - constexpr const char* kURLProtocols[] = { - "file", // Filesystem protocol - "mup", // Mahrouss update protocol - "param", // Mahrouss parameter protocol. + constexpr const Char* kURLProtocols[] = { + "file", // Filesystem protocol + "zup", // Zeta update protocol + "oscc", // Open System Configuration Connectivity. }; constexpr const int kUrlOutSz = 1; //! such as: :// constexpr const int kProtosCount = 3; constexpr const int kRangeSz = 4096; - ErrorOr<StringView> url_extract_location(const char* url) + ErrorOr<StringView> url_extract_location(const Char* url) { if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) return ErrorOr<StringView>{-1}; @@ -62,7 +62,7 @@ namespace Kernel return ErrorOr<StringView>(view); } - ErrorOr<StringView> url_extract_protocol(const char* url) + ErrorOr<StringView> url_extract_protocol(const Char* url) { if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) return ErrorOr<StringView>{-1}; @@ -74,7 +74,7 @@ namespace Kernel Ref<ErrorOr<StringView>> URL::Location() noexcept { - const char* src = fUrlView.Leak().CData(); + const Char* src = fUrlView.Leak().CData(); auto loc = url_extract_location(src); if (!loc) @@ -85,7 +85,7 @@ namespace Kernel Ref<ErrorOr<StringView>> URL::Protocol() noexcept { - const char* src = fUrlView.Leak().CData(); + const Char* src = fUrlView.Leak().CData(); auto loc = url_extract_protocol(src); if (!loc) diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx new file mode 100644 index 00000000..68d0d5be --- /dev/null +++ b/Kernel/Sources/User.cxx @@ -0,0 +1,64 @@ +/* + * ======================================================== + * + * Kernel + * Copyright ZKA Technologies, all rights reserved. + * + * File: User.cpp + * Purpose: Permission selectors. + * + * ======================================================== + */ + +#include <KernelKit/User.hxx> +#include <NewKit/KernelCheck.hpp> + +/// bugs 0 + +namespace Kernel +{ + User::User(const Int32& sel, const Char* userName) + : fRing((RingKind)sel) + { + MUST_PASS(sel >= 0); + this->fUserName += userName; + } + + User::User(const RingKind& ringKind, const Char* userName) + : fRing(ringKind) + { + this->fUserName += userName; + } + + User::~User() = default; + + bool User::operator==(const User& lhs) + { + return lhs.fRing == this->fRing; + } + + bool User::operator!=(const User& lhs) + { + return lhs.fRing != this->fRing; + } + + const StringView User::Name() noexcept + { + return this->fUserName; + } + + const RingKind& User::Ring() noexcept + { + return this->fRing; + } + + Bool User::IsStdUser() noexcept + { + return this->Ring() == RingKind::kRingStdUser; + } + + Bool User::IsSuperUser() noexcept + { + return this->Ring() == RingKind::kRingSuperUser; + } +} // namespace Kernel diff --git a/Kernel/Sources/Utils.cxx b/Kernel/Sources/Utils.cxx index 37269ca1..eeac3f93 100644 --- a/Kernel/Sources/Utils.cxx +++ b/Kernel/Sources/Utils.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -37,7 +37,7 @@ namespace Kernel { if (len > _len) { - break; + return 0; } ++len; @@ -48,15 +48,14 @@ namespace Kernel Size rt_string_len(const Char* ptr) { - if (!ptr) + if (*ptr == 0) return 0; SizeT cnt = 0; - while (*ptr != (Char)0) + while (ptr[cnt] != (Char)0) { - ++ptr; - ++cnt; + cnt++; } return cnt; diff --git a/Kernel/Sources/Variant.cxx b/Kernel/Sources/Variant.cxx index 7630f5db..7dc71df5 100644 --- a/Kernel/Sources/Variant.cxx +++ b/Kernel/Sources/Variant.cxx @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Zeta Electronics Corporation + Copyright ZKA Technologies ------------------------------------------- */ @@ -12,13 +12,17 @@ namespace Kernel { switch (fKind) { + case VariantKind::kJson: + return ("Class:{Json}"); case VariantKind::kString: return ("Class:{String}"); - case VariantKind::kPointer: - return ("Memory:{Pointer}"); + case VariantKind::kBlob: + return ("Class:{Blob}"); default: - return ("Memory:{Undefined}"); + return ("Class:{Null}"); } } + /// @brief Leak variant's instance. + VoidPtr Variant::Leak() { return fPtr; } } // namespace Kernel diff --git a/Kernel/Sources/compile_flags.txt b/Kernel/Sources/compile_flags.txt index 1f54e6fb..b02c5e3d 100644 --- a/Kernel/Sources/compile_flags.txt +++ b/Kernel/Sources/compile_flags.txt @@ -3,5 +3,5 @@ -std=c++20 -I../ -I$(HOME)/ --D__FSKIT_NEWFS__ +-D__FSKIT_USE_NEWFS__ -D__NEWOS_AMD64__ |
