diff options
| author | Amlal El Mahrouss <zka-holder@mahrouss-logic.com> | 2024-10-14 05:58:38 +0000 |
|---|---|---|
| committer | Amlal El Mahrouss <zka-holder@mahrouss-logic.com> | 2024-10-14 05:58:38 +0000 |
| commit | d9d82713326069478e6dd212763d1fac15e65370 (patch) | |
| tree | 37775f4299281598b0f5121df4c188392daebd04 /dev/zka/src | |
| parent | 7477a0f942c374b652da4f80cdb36d4661aac3c8 (diff) | |
IMP: Basic ARM64 port.
Diffstat (limited to 'dev/zka/src')
| -rw-r--r-- | dev/zka/src/ACPIFactoryInterface.cxx | 95 | ||||
| -rw-r--r-- | dev/zka/src/BitMapMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/CRuntime.cxx | 69 | ||||
| -rw-r--r-- | dev/zka/src/CodeMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/CxxAbi-AMD64.cxx | 9 | ||||
| -rw-r--r-- | dev/zka/src/CxxAbi-ARM64.cxx | 94 | ||||
| -rw-r--r-- | dev/zka/src/DriveMgr.cxx | 12 | ||||
| -rw-r--r-- | dev/zka/src/FS/NeFS.cxx | 130 | ||||
| -rw-r--r-- | dev/zka/src/GUIDWizard.cxx | 40 | ||||
| -rw-r--r-- | dev/zka/src/HardwareThreadScheduler.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/NeFS+FileMgr.cxx | 4 | ||||
| -rw-r--r-- | dev/zka/src/PageMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/Stop.cxx | 75 | ||||
| -rw-r--r-- | dev/zka/src/String.cxx | 48 | ||||
| -rw-r--r-- | dev/zka/src/URL.cxx | 98 | ||||
| -rw-r--r-- | dev/zka/src/UserProcessScheduler.cxx | 60 |
16 files changed, 398 insertions, 344 deletions
diff --git a/dev/zka/src/ACPIFactoryInterface.cxx b/dev/zka/src/ACPIFactoryInterface.cxx new file mode 100644 index 00000000..e5c0b514 --- /dev/null +++ b/dev/zka/src/ACPIFactoryInterface.cxx @@ -0,0 +1,95 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <modules/ACPI/ACPIFactoryInterface.hxx> +#include <NewKit/String.hxx> +#include <ArchKit/ArchKit.hxx> +#include <KernelKit/Heap.hxx> + +namespace Kernel +{ + /// @brief Finds a descriptor table inside ACPI XSDT. + ErrorOr<voidPtr> ACPIFactoryInterface::Find(const Char* signature) + { + MUST_PASS(fRsdp); + + if (!signature) + return ErrorOr<voidPtr>{-1}; + + if (*signature == 0) + return ErrorOr<voidPtr>{-1}; + + RSDP* rsp_ptr = reinterpret_cast<RSDP*>(this->fRsdp); + + if (rsp_ptr->Revision <= 1) + return ErrorOr<voidPtr>{-1}; + + RSDT* xsdt = reinterpret_cast<RSDT*>(rsp_ptr->RsdtAddress); + + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32); + + /*** + crucial to avoid - overflows. + */ + if (num < 1) + { + /// stop here, we should have entries... + ke_stop(RUNTIME_CHECK_ACPI); + return ErrorOr<voidPtr>{-1}; + } + + this->fEntries = num; + + kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; + kcout << "ACPI: Revision: " << number(xsdt->Revision) << endl; + kcout << "ACPI: Signature: " << xsdt->Signature << endl; + kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; + + const short cAcpiSignatureLength = 4; + + for (Size index = 0; index < this->fEntries; ++index) + { + SDT* sdt = reinterpret_cast<SDT*>(xsdt->AddressArr[index]); + + kcout << "ACPI: Checksum: " << number(sdt->Checksum) << endl; + kcout << "ACPI: Revision: " << number(sdt->Revision) << endl; + + for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) + { + if (sdt->Signature[signature_index] != signature[signature_index]) + break; + + if (signature_index == (cAcpiSignatureLength - 1)) + { + kcout << "ACPI: Found the SDT. " << endl; + return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>(xsdt->AddressArr[index])); + } + } + } + + return ErrorOr<voidPtr>{-1}; + } + + /*** + @brief check SDT header + @param checksum the header to checksum + @param len the length of it. +*/ + bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) + { + if (len == 0) + return -1; + + char chr = 0; + + for (int index = 0; index < len; ++index) + { + chr += checksum[index]; + } + + return chr == 0; + } +} // namespace Kernel diff --git a/dev/zka/src/BitMapMgr.cxx b/dev/zka/src/BitMapMgr.cxx index 8e8a2208..a3d403d3 100644 --- a/dev/zka/src/BitMapMgr.cxx +++ b/dev/zka/src/BitMapMgr.cxx @@ -168,7 +168,7 @@ namespace Kernel if (!ptr_new) { - ke_stop(RUNTIME_CHECK_PAGE); + return nullptr; } if (wr) diff --git a/dev/zka/src/CRuntime.cxx b/dev/zka/src/CRuntime.cxx new file mode 100644 index 00000000..832c39f6 --- /dev/null +++ b/dev/zka/src/CRuntime.cxx @@ -0,0 +1,69 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <KernelKit/DebugOutput.hxx> + +using namespace Kernel; + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. +EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = byte; + } + + return dst; +} + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = ((int*)src)[i]; + } + + return dst; +} + +/// @brief strlen definition in C++. +EXTERN_C size_t strlen(const char* whatToCheck) +{ + SizeT len = 0; + + while (whatToCheck[len] != 0) + { + ++len; + } + + return len; +} + +/// @brief strcmp definition in C++. +EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) +{ + if (!whatToCheck || *whatToCheck == 0) + return 0; + + SizeT len = 0; + + while (whatToCheck[len] == whatToCheckRight[len]) + { + if (whatToCheck[len] == 0) + return 0; + + ++len; + } + + return len; +} diff --git a/dev/zka/src/CodeMgr.cxx b/dev/zka/src/CodeMgr.cxx index cc1d2059..c3f06096 100644 --- a/dev/zka/src/CodeMgr.cxx +++ b/dev/zka/src/CodeMgr.cxx @@ -22,7 +22,7 @@ namespace Kernel UserProcess proc; proc.SetImageStart(reinterpret_cast<VoidPtr>(main)); - proc.Kind = UserProcess::eExecutableKind; + proc.Kind = UserProcess::kExectuableKind; proc.StackSize = kib_cast(32); rt_set_memory(proc.Name, 0, kProcessLen); diff --git a/dev/zka/src/CxxAbi-AMD64.cxx b/dev/zka/src/CxxAbi-AMD64.cxx index 908e26f4..1f3c5495 100644 --- a/dev/zka/src/CxxAbi-AMD64.cxx +++ b/dev/zka/src/CxxAbi-AMD64.cxx @@ -17,15 +17,16 @@ uarch_t __atexit_func_count; /// @brief Dynamic Shared Object Handle. Kernel::UIntPtr __dso_handle; -EXTERN_C void __cxa_pure_virtual() +EXTERN_C Kernel::Void __cxa_pure_virtual(void* self) { - kcout << "C++ placeholder method.\n"; + kcout << "object: " << Kernel::number(reinterpret_cast<Kernel::UIntPtr>(self)); + kcout << ", has unimplemented virtual functions.\r"; } EXTERN_C void ___chkstk_ms(void) { - Kernel::err_bug_check_raise(); - Kernel::err_bug_check(); + kcout << "Stack pointer has grown too much.\r"; + Kernel::ke_stop(RUNTIME_CHECK_FAILED); } EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso) diff --git a/dev/zka/src/CxxAbi-ARM64.cxx b/dev/zka/src/CxxAbi-ARM64.cxx index f6f7e763..b1e3ec1b 100644 --- a/dev/zka/src/CxxAbi-ARM64.cxx +++ b/dev/zka/src/CxxAbi-ARM64.cxx @@ -10,65 +10,79 @@ #include <NewKit/CxxAbi.hxx> #include <KernelKit/LPC.hxx> -EXTERN_C -{ -#include <limits.h> -} +atexit_func_entry_t __atexit_funcs[kDSOMaxObjects]; -int const cUninitialized = 0; -int const cBeingInitialized = -1; -int const cEpochStart = INT_MIN; +uarch_t __atexit_func_count; -EXTERN_C -{ - int _Init_global_epoch = cEpochStart; - __thread int _Init_thread_epoch = cEpochStart; -} +/// @brief Dynamic Shared Object Handle. +Kernel::UIntPtr __dso_handle; -Kernel::UInt32 const cNKTimeout = 100; // ms +EXTERN_C void __chkstk(void) {} -EXTERN_C void __cdecl _Init_thread_wait(Kernel::UInt32 const timeout) +EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso) { - MUST_PASS(timeout != INT_MAX); + if (__atexit_func_count >= kDSOMaxObjects) + return -1; + + __atexit_funcs[__atexit_func_count].destructor_func = f; + __atexit_funcs[__atexit_func_count].obj_ptr = arg; + __atexit_funcs[__atexit_func_count].dso_handle = dso; + + __atexit_func_count++; + + return 0; } -EXTERN_C void __cdecl _Init_thread_header(int* const pOnce) noexcept +EXTERN_C void __cxa_finalize(void* f) { - if (*pOnce == cUninitialized) + uarch_t i = __atexit_func_count; + if (!f) { - *pOnce = cBeingInitialized; - } - else - { - while (*pOnce == cBeingInitialized) + while (i--) { - _Init_thread_wait(cNKTimeout); - - if (*pOnce == cUninitialized) + if (__atexit_funcs[i].destructor_func) { - *pOnce = cBeingInitialized; - return; - } + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + }; } - _Init_thread_epoch = _Init_global_epoch; + + return; } -} -EXTERN_C void __cdecl _Init_thread_abort(int* const pOnce) noexcept -{ - *pOnce = cUninitialized; + while (i--) + { + if (__atexit_funcs[i].destructor_func) + { + (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + __atexit_funcs[i].destructor_func = 0; + }; + } } -EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept +namespace cxxabiv1 { - ++_Init_global_epoch; - *pOnce = _Init_global_epoch; - _Init_thread_epoch = _Init_global_epoch; -} + EXTERN_C int __cxa_guard_acquire(__guard* g) + { + (void)g; + return 0; + } + + EXTERN_C int __cxa_guard_release(__guard* g) + { + *(char*)g = 1; + return 0; + } + + EXTERN_C void __cxa_guard_abort(__guard* g) + { + (void)g; + } +} // namespace cxxabiv1 -EXTERN_C void _purecall() +EXTERN_C Kernel::Void _purecall(void* self) { - ZKA_UNUSED(0); + kcout << "object: " << Kernel::number(reinterpret_cast<Kernel::UIntPtr>(self)); + kcout << ", has unimplemented virtual functions.\r"; } #endif // ifdef __ZKA_ARM64__ diff --git a/dev/zka/src/DriveMgr.cxx b/dev/zka/src/DriveMgr.cxx index 77412d12..b5edb2b1 100644 --- a/dev/zka/src/DriveMgr.cxx +++ b/dev/zka/src/DriveMgr.cxx @@ -88,20 +88,24 @@ namespace Kernel return "ATA-PIO"; } #endif - #ifdef __ATA_DMA__ const Char* io_drv_kind(Void) { return "ATA-DMA"; } #endif - #ifdef __AHCI__ const Char* io_drv_kind(Void) { return "AHCI"; } #endif +#ifdef __ZKA_MINIMAL_OS__ + const Char* io_drv_kind(Void) + { + return "Unknown"; + } +#endif /// @brief Unimplemented drive. /// @param pckt @@ -118,7 +122,7 @@ namespace Kernel DriveTrait trait; rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); - trait.fKind = kInvalidDrive; + trait.fKind = kInvalidStorage; trait.fInput = io_drv_unimplemented; trait.fOutput = io_drv_unimplemented; @@ -136,7 +140,7 @@ namespace Kernel DriveTrait trait; rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); - trait.fKind = kMassStorage; + trait.fKind = kMassStorage | kEPMDrive; trait.fVerify = io_drv_unimplemented; trait.fOutput = io_drv_output; diff --git a/dev/zka/src/FS/NeFS.cxx b/dev/zka/src/FS/NeFS.cxx index ee1e32c6..455f894d 100644 --- a/dev/zka/src/FS/NeFS.cxx +++ b/dev/zka/src/FS/NeFS.cxx @@ -19,9 +19,10 @@ #include <KernelKit/UserProcessScheduler.hxx> #include <KernelKit/User.hxx> +#ifndef __ZKA_MINIMAL_OS__ using namespace Kernel; -#ifdef __ZKA_IN_EDITOR__ +#ifdef __ZKA_NO_BUILTIN__ /***********************************************************************************/ /** Define those external symbols, to make the editor shutup @@ -325,56 +326,56 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, constexpr auto cNeFSCatalogPadding = 4; - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - out_lba = partBlock->StartCatalog; + NFS_ROOT_PARTITION_BLOCK* part_block = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + out_lba = part_block->StartCatalog; } constexpr SizeT cDefaultForkSize = kNeFSForkSize; - NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); + NFS_CATALOG_STRUCT* child_catalog = new NFS_CATALOG_STRUCT(); Int32 flagsList = flags; - catalogChild->ResourceForkSize = cDefaultForkSize; - catalogChild->DataForkSize = cDefaultForkSize; + child_catalog->ResourceForkSize = cDefaultForkSize; + child_catalog->DataForkSize = cDefaultForkSize; - catalogChild->NextSibling = out_lba; - catalogChild->PrevSibling = out_lba; - catalogChild->Kind = kind; - catalogChild->Flags = kNeFSFlagCreated | flagsList; + child_catalog->NextSibling = out_lba; + child_catalog->PrevSibling = out_lba; + child_catalog->Kind = kind; + child_catalog->Flags = kNeFSFlagCreated | flagsList; - rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, + rt_copy_memory((VoidPtr)name, (VoidPtr)child_catalog->Name, rt_string_len(name)); - UInt16 catalogBuf[kNeFSSectorSz] = {0}; + NFS_CATALOG_STRUCT temporary_catalog; Lba start_free = out_lba; rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, rt_string_len("fs/newfs-packet")); - drive.fPacket.fPacketContent = catalogBuf; + drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = kNeFSSectorSz; drive.fPacket.fLba = start_free; drive.fInput(&drive.fPacket); - NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; + NFS_CATALOG_STRUCT* next_sibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(&temporary_catalog); - start_free = nextSibling->NextSibling; + start_free = next_sibling->NextSibling; - catalogChild->PrevSibling = out_lba; + child_catalog->PrevSibling = out_lba; drive.fPacket.fLba = start_free; drive.fInput(&drive.fPacket); while (drive.fPacket.fPacketGood) { - nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf); + next_sibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(&temporary_catalog); if (start_free <= kNeFSRootCatalogStartAddress) { - delete catalogChild; + delete child_catalog; delete catalog; return nullptr; @@ -383,7 +384,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, // ========================== // // Allocate catalog now... // ========================== // - if ((nextSibling->Flags & kNeFSFlagCreated) == 0) + if ((next_sibling->Flags & kNeFSFlagCreated) == 0) { Char sectorBufPartBlock[kNeFSSectorSz] = {0}; @@ -395,26 +396,26 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, constexpr auto cNeFSCatalogPadding = 4; - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + NFS_ROOT_PARTITION_BLOCK* part_block = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - if (partBlock->FreeCatalog < 1) + if (part_block->FreeCatalog < 1) { - delete catalogChild; + delete child_catalog; return nullptr; } - catalogChild->DataFork = partBlock->DiskSize - start_free; - catalogChild->ResourceFork = catalogChild->DataFork; + child_catalog->DataFork = part_block->DiskSize - start_free; + child_catalog->ResourceFork = child_catalog->DataFork; // Write the new catalog next sibling, if we don't know this parent. // // This is necessary, so that we don't have to get another lba to allocate. // - if (!StringBuilder::Equals(parentName, nextSibling->Name)) + if (!StringBuilder::Equals(parentName, next_sibling->Name)) { - catalogChild->NextSibling = + child_catalog->NextSibling = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); } - drive.fPacket.fPacketContent = catalogChild; + drive.fPacket.fPacketContent = child_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive.fPacket.fLba = start_free; @@ -428,24 +429,24 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, drive.fInput(&drive.fPacket); - partBlock->FreeSectors -= 1; - partBlock->CatalogCount += 1; - partBlock->FreeCatalog -= 1; + part_block->FreeSectors -= 1; + part_block->CatalogCount += 1; + part_block->FreeCatalog -= 1; drive.fOutput(&drive.fPacket); kcout << "Create new catalog, status: " - << hex_number(catalogChild->Flags) << endl; - kcout << "Create new catalog, name: " << catalogChild->Name + << hex_number(child_catalog->Flags) << endl; + kcout << "Create new catalog, name: " << child_catalog->Name << endl; delete catalog; - return catalogChild; + return child_catalog; } - else if ((nextSibling->Flags & kNeFSFlagCreated) && - StringBuilder::Equals(nextSibling->Name, name)) + else if ((next_sibling->Flags & kNeFSFlagCreated) && + StringBuilder::Equals(next_sibling->Name, name)) { - return nextSibling; + return next_sibling; } constexpr auto cNeFSCatalogPadding = 4; @@ -453,7 +454,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, //// @note that's how we find the next catalog in the partition block. start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); - drive.fPacket.fPacketContent = catalogBuf; + drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = kNeFSSectorSz; drive.fPacket.fLba = start_free; @@ -563,22 +564,22 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb // disk isnt faulty and data has been fetched. while (drive->fPacket.fPacketGood) { - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; + NFS_ROOT_PARTITION_BLOCK* part_block = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; // check for an empty partition here. - if (partBlock->PartitionName[0] == 0 && - rt_string_cmp(partBlock->Ident, kNeFSIdent, kNeFSIdentLen)) + if (part_block->PartitionName[0] == 0 && + rt_string_cmp(part_block->Ident, kNeFSIdent, kNeFSIdentLen)) { // partition is free and valid. - partBlock->Version = kNeFSVersionInteger; + part_block->Version = kNeFSVersionInteger; const auto cUntitledHD = part_name; - rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)partBlock->Ident, + rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)part_block->Ident, kNeFSIdentLen); - rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, + rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)part_block->PartitionName, rt_string_len(cUntitledHD)); SizeT catalogCount = 0UL; @@ -586,13 +587,13 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb SizeT sectorCount = drv_get_sector_count(); SizeT diskSize = drv_get_size(); - partBlock->Kind = kNeFSPartitionTypeStandard; - partBlock->StartCatalog = kNeFSCatalogStartAddress; - partBlock->Flags = kNeFSPartitionTypeStandard; - partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); - partBlock->SectorCount = sectorCount; - partBlock->DiskSize = diskSize; - partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); + part_block->Kind = kNeFSPartitionTypeStandard; + part_block->StartCatalog = kNeFSCatalogStartAddress; + part_block->Flags = kNeFSPartitionTypeStandard; + part_block->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); + part_block->SectorCount = sectorCount; + part_block->DiskSize = diskSize; + part_block->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); drive->fPacket.fPacketContent = fs_buf; drive->fPacket.fPacketSize = kNeFSSectorSz; @@ -602,12 +603,12 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb kcout << "drive kind: " << drive->fDriveKind() << endl; - kcout << "partition name: " << partBlock->PartitionName << endl; - kcout << "start: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl; + kcout << "partition name: " << part_block->PartitionName << endl; + kcout << "start: " << hex_number(part_block->StartCatalog) << endl; + kcout << "number of catalogs: " << hex_number(part_block->CatalogCount) << endl; + kcout << "free catalog: " << hex_number(part_block->FreeCatalog) << endl; + kcout << "free sectors: " << hex_number(part_block->FreeSectors) << endl; + kcout << "sector size: " << hex_number(part_block->SectorSize) << endl; // write the root catalog. this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); @@ -617,7 +618,7 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb kcout << "partition block already exists.\r"; - start += partBlock->DiskSize; + start += part_block->DiskSize; drive->fPacket.fPacketContent = fs_buf; drive->fPacket.fPacketSize = kNeFSSectorSz; @@ -745,10 +746,10 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa auto localSearchFirst = false; - NFS_CATALOG_STRUCT catalogBuf{0}; + NFS_CATALOG_STRUCT temporary_catalog{0}; drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive.fInput(&drive.fPacket); @@ -802,12 +803,12 @@ NeFSSearchThroughCatalogList: while (drive.fPacket.fPacketGood) { drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive.fInput(&drive.fPacket); - NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf; + NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&temporary_catalog; if (StringBuilder::Equals(catalogName, catalog->Name)) { @@ -909,11 +910,11 @@ Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) drive.fInput(&drive.fPacket); - NFS_ROOT_PARTITION_BLOCK* partBlock = + NFS_ROOT_PARTITION_BLOCK* part_block = reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); - --partBlock->CatalogCount; - ++partBlock->FreeSectors; + --part_block->CatalogCount; + ++part_block->FreeSectors; drive.fOutput(&drive.fPacket); @@ -1051,5 +1052,6 @@ namespace Kernel::Detail return true; } } // namespace Kernel::Detail +#endif // !__ZKA_MINIMAL_OS__ #endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/zka/src/GUIDWizard.cxx b/dev/zka/src/GUIDWizard.cxx index aede3a19..c1aa23f5 100644 --- a/dev/zka/src/GUIDWizard.cxx +++ b/dev/zka/src/GUIDWizard.cxx @@ -19,47 +19,47 @@ namespace Kernel::XRN::Version1 { - auto cf_make_sequence(const ArrayList<UInt32>& 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->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; + Ref<GUIDSequence> seq_ref{*seq}; + + seq_ref.Leak().fMs1 = uuidSeq[0]; + seq_ref.Leak().fMs2 = uuidSeq[1]; + seq_ref.Leak().fMs3 = uuidSeq[2]; + seq_ref.Leak().fMs4[0] = uuidSeq[3]; + seq_ref.Leak().fMs4[1] = uuidSeq[4]; + seq_ref.Leak().fMs4[2] = uuidSeq[5]; + seq_ref.Leak().fMs4[3] = uuidSeq[6]; + seq_ref.Leak().fMs4[4] = uuidSeq[7]; + seq_ref.Leak().fMs4[5] = uuidSeq[8]; + seq_ref.Leak().fMs4[6] = uuidSeq[9]; + seq_ref.Leak().fMs4[7] = uuidSeq[10]; + + return seq_ref; } // @brief Tries to make a guid out of a string. // This function is not complete for now - auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> + auto cf_try_guid_to_string(Ref<GUIDSequence>& seq) -> ErrorOr<Ref<StringView>> { Char buf[kUUIDSize]; for (SizeT index = 0; index < 16; ++index) { - buf[index] = seq->u8[index] + kAsciiBegin; + buf[index] = seq.Leak().u8[index] + kAsciiBegin; } for (SizeT index = 16; index < 24; ++index) { - buf[index] = seq->u16[index] + kAsciiBegin; + buf[index] = seq.Leak().u16[index] + kAsciiBegin; } for (SizeT index = 24; index < 28; ++index) { - buf[index] = seq->u32[index] + kAsciiBegin; + buf[index] = seq.Leak().u32[index] + kAsciiBegin; } auto view = StringBuilder::Construct(buf); diff --git a/dev/zka/src/HardwareThreadScheduler.cxx b/dev/zka/src/HardwareThreadScheduler.cxx index ef04907d..cc32dd0d 100644 --- a/dev/zka/src/HardwareThreadScheduler.cxx +++ b/dev/zka/src/HardwareThreadScheduler.cxx @@ -108,8 +108,6 @@ namespace Kernel fStack = frame; - kcout << "Trying to register progress...\r"; - Bool ret = mp_register_process(image, stack_ptr, fStack); if (ret) diff --git a/dev/zka/src/NeFS+FileMgr.cxx b/dev/zka/src/NeFS+FileMgr.cxx index cee80531..bd9c260b 100644 --- a/dev/zka/src/NeFS+FileMgr.cxx +++ b/dev/zka/src/NeFS+FileMgr.cxx @@ -7,6 +7,7 @@ #include <KernelKit/FileMgr.hxx> #include <KernelKit/Heap.hxx> +#ifndef __ZKA_MINIMAL_OS__ #ifdef __FSKIT_USE_NEFS__ /// @brief NeFS File manager. @@ -14,7 +15,6 @@ namespace Kernel { -#ifdef __FSKIT_USE_NEFS__ /// @brief C++ constructor NeFileSystemMgr::NeFileSystemMgr() { @@ -242,7 +242,7 @@ namespace Kernel { return fImpl; } -#endif // __FSKIT_USE_NEFS__ } // namespace Kernel #endif // ifdef __FSKIT_USE_NEFS__ +#endif // ifndef __ZKA_MINIMAL_OS__ diff --git a/dev/zka/src/PageMgr.cxx b/dev/zka/src/PageMgr.cxx index 3a4a743c..df8e85b4 100644 --- a/dev/zka/src/PageMgr.cxx +++ b/dev/zka/src/PageMgr.cxx @@ -34,7 +34,9 @@ namespace Kernel /// @param VirtAddr Void PageMgr::FlushTLB() { +#ifndef __ZKA_MINIMAL_OS__ hal_flush_tlb(); +#endif // !__ZKA_MINIMAL_OS__ } /// @brief Reclaim freed page. diff --git a/dev/zka/src/Stop.cxx b/dev/zka/src/Stop.cxx index a02ea099..9c25f374 100644 --- a/dev/zka/src/Stop.cxx +++ b/dev/zka/src/Stop.cxx @@ -11,7 +11,6 @@ #include <KernelKit/DebugOutput.hxx> #include <NewKit/String.hxx> #include <FirmwareKit/Handover.hxx> -#include <modules/ACPI/ACPIFactoryInterface.hxx> #include <KernelKit/FileMgr.hxx> #include <modules/FB/FB.hxx> #include <modules/FB/Text.hxx> @@ -27,17 +26,17 @@ namespace Kernel { CGInit(); - auto panicTxt = RGB(0xff, 0xff, 0xff); + auto panic_text = RGB(0xff, 0xff, 0xff); auto start_y = 10; auto x = 10; - CGDrawString("minoskrnl.exe stopped working properly so it had to stop.", start_y, x, panicTxt); + CGDrawString("minoskrnl.exe stopped working properly so it had to stop.", start_y, x, panic_text); start_y += 10; // simply offset from previous string and then write the website. - CGDrawString("Please visit: ", start_y, x, panicTxt); - CGDrawString(cWebsiteMacro, start_y, x + (FONT_SIZE_X * rt_string_len("Please visit: ")), panicTxt); + CGDrawString("Please visit: ", start_y, x, panic_text); + CGDrawString(cWebsiteMacro, start_y, x + (FONT_SIZE_X * rt_string_len("Please visit: ")), panic_text); CGFini(); @@ -48,91 +47,77 @@ namespace Kernel switch (id) { case RUNTIME_CHECK_PROCESS: { - CGDrawString("0x00000008 Scheduler error.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000008 Scheduler error.", start_y, x, panic_text); + break; } case RUNTIME_CHECK_ACPI: { - CGDrawString("0x00000006 ACPI configuration error.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000006 ACPI configuration error.", start_y, x, panic_text); + break; } case RUNTIME_CHECK_PAGE: { - CGDrawString("0x0000000B Write/Read in non paged area.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x0000000B Write/Read in non paged area.", start_y, x, panic_text); + } case RUNTIME_CHECK_FILESYSTEM: { - CGDrawString("0x0000000A Filesystem error.", start_y, x, panicTxt); - - PowerFactoryInterface power(nullptr); - power.Shutdown(); + CGDrawString("0x0000000A Filesystem error.", start_y, x, panic_text); break; } case RUNTIME_CHECK_POINTER: { - CGDrawString("0x00000000 Heap is corrupted.", start_y, x, panicTxt); - - PowerFactoryInterface power(nullptr); - power.Shutdown(); + CGDrawString("0x00000000 Heap is corrupted.", start_y, x, panic_text); break; } case RUNTIME_CHECK_BAD_BEHAVIOR: { - CGDrawString("0x00000009 Bad behavior error.", start_y, x, panicTxt); - - PowerFactoryInterface power(nullptr); - power.Shutdown(); + CGDrawString("0x00000009 Bad Behavior.", start_y, x, panic_text); break; } case RUNTIME_CHECK_BOOTSTRAP: { - CGDrawString("0x0000000A OS finished executing.", start_y, x, panicTxt); - - PowerFactoryInterface power(nullptr); - power.Shutdown(); - break; + CGDrawString("0x0000000A Boot code has finished executing, waiting for scheduler and other cores.", start_y, x, panic_text); + return; } case RUNTIME_CHECK_HANDSHAKE: { - CGDrawString("0x00000005 Handshake fault.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000005 Handshake fault.", start_y, x, panic_text); + break; } case RUNTIME_CHECK_IPC: { - CGDrawString("0x00000003 Bad IPC/XPCOM message.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000003 Bad IPC/XPCOM message.", start_y, x, panic_text); + break; } case RUNTIME_CHECK_INVALID_PRIVILEGE: { - CGDrawString("0x00000007 Privilege access violation.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000007 Privilege access violation.", start_y, x, panic_text); + break; case RUNTIME_CHECK_UNEXCPECTED: { - CGDrawString("0x0000000B Kernel access violation.", start_y, x, panicTxt); + CGDrawString("0x0000000B Unexpected violation.", start_y, x, panic_text); break; } case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: { - CGDrawString("0x10000001 Out of virtual memory.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x10000001 Out of virtual memory.", start_y, x, panic_text); + break; } case RUNTIME_CHECK_FAILED: { - CGDrawString("0x10000001 Kernel Bug check appears to have failed, a dump has been written to the storage.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x10000001 Kernel Bug check appears to have failed, a dump has been written to the storage.", start_y, x, panic_text); + break; } default: { - RecoveryFactory::Recover(); - CGDrawString("0xFFFFFFFC Unknown Kernel Error.", start_y, x, panicTxt); + + CGDrawString("0xFFFFFFFC Unknown Kernel Error.", start_y, x, panic_text); break; } } }; - PowerFactoryInterface power(nullptr); - power.Reboot(); + RecoveryFactory::Recover(); } Void RecoveryFactory::Recover() noexcept { - PowerFactoryInterface power(nullptr); - power.Reboot(); + HAL::rt_halt(); } void ke_runtime_check(bool expr, const Char* file, const Char* line) diff --git a/dev/zka/src/String.cxx b/dev/zka/src/String.cxx index bb0f80e3..520e42f3 100644 --- a/dev/zka/src/String.cxx +++ b/dev/zka/src/String.cxx @@ -86,52 +86,10 @@ namespace Kernel if (!data || *data == 0) return {}; - StringView view(rt_string_len(data)); + StringView* view = new StringView(rt_string_len(data)); + (*view) += data; - view += data; - - return ErrorOr<StringView>(view); - } - - const Char* StringBuilder::FromInt(const Char* fmt, int i) - { - if (!fmt) - return ("-1"); - - char* ret = (char*)ALLOCA(sizeof(char) * 8 + rt_string_len(fmt)); - - if (!ret) - return ("-1"); - - Char result[8]; - - if (!rt_to_string(result, sizeof(int), i)) - { - return ("-1"); - } - - const auto fmt_len = rt_string_len(fmt); - const auto res_len = rt_string_len(result); - - for (Size idx = 0; idx < fmt_len; ++idx) - { - if (fmt[idx] == '%') - { - SizeT result_cnt = idx; - - for (auto y_idx = idx; y_idx < res_len; ++y_idx) - { - ret[result_cnt] = result[y_idx]; - ++result_cnt; - } - - break; - } - - ret[idx] = fmt[idx]; - } - - return ret; /* Copy that ret into a buffer, 'ALLOCA' allocates to the stack */ + return ErrorOr<StringView>(*view); } const Char* StringBuilder::FromBool(const Char* fmt, bool i) diff --git a/dev/zka/src/URL.cxx b/dev/zka/src/URL.cxx deleted file mode 100644 index 9748ba32..00000000 --- a/dev/zka/src/URL.cxx +++ /dev/null @@ -1,98 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <CFKit/URL.hxx> -#include <KernelKit/DebugOutput.hxx> -#include <NewKit/Utils.hxx> - -/// BUGS: 0 - -namespace Kernel -{ - URL::URL(StringView& strUrl) - : fUrlView(strUrl, false) - { - } - - URL::~URL() = default; - - /// @brief internal and reserved protocols by Kernel. - constexpr const Char* kURLProtocols[] = { - "file", // Filesystem protocol - "zup", // ZKA update protocol - "oscc", // Open System Configuration Connectivity. - "odbc", // ODBC connectivity. - "https", // HTTPS layer driver (HTTPS.sys). - }; - - constexpr const int kUrlOutSz = 1; //! such as: :// - constexpr const int kProtosCount = 5; //! Number of protocols registered as of right now. - constexpr const int kRangeSz = 4096; - - ErrorOr<StringView> url_extract_location(const Char* url) - { - if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; - - StringView view(rt_string_len(url)); - - SizeT i = 0; - bool scheme_found = false; - - for (; i < rt_string_len(url); ++i) - { - if (!scheme_found) - { - for (int y = 0; kProtosCount; ++y) - { - if (rt_string_in_string(view.CData(), kURLProtocols[y])) - { - i += rt_string_len(kURLProtocols[y]) + kUrlOutSz; - scheme_found = true; - - break; - } - } - } - - view.Data()[i] = url[i]; - } - - return ErrorOr<StringView>(view); - } - - ErrorOr<StringView> url_extract_protocol(const Char* url) - { - if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; - - ErrorOr<StringView> view{-1}; - - return view; - } - - Ref<ErrorOr<StringView>> URL::Location() noexcept - { - const Char* src = fUrlView.Leak().CData(); - auto loc = url_extract_location(src); - - if (!loc) - return {}; - - return Ref<ErrorOr<StringView>>(loc); - } - - Ref<ErrorOr<StringView>> URL::Protocol() noexcept - { - const Char* src = fUrlView.Leak().CData(); - auto loc = url_extract_protocol(src); - - if (!loc) - return {}; - - return Ref<ErrorOr<StringView>>(loc); - } -} // namespace Kernel diff --git a/dev/zka/src/UserProcessScheduler.cxx b/dev/zka/src/UserProcessScheduler.cxx index 0819e638..b5a2a998 100644 --- a/dev/zka/src/UserProcessScheduler.cxx +++ b/dev/zka/src/UserProcessScheduler.cxx @@ -242,12 +242,16 @@ namespace Kernel { if (memory_list->MemoryEntry) { +#ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); +#endif MUST_PASS(mm_delete_heap(memory_list->MemoryEntry)); +#ifdef __ZKA_AMD64__ hal_write_cr3(pd); +#endif } auto next = memory_list->MemoryNext; @@ -271,7 +275,7 @@ namespace Kernel this->Image = nullptr; this->StackFrame = nullptr; - if (this->Kind == eExecutableDLLKind) + if (this->Kind == kExectuableDLLKind) { Bool success = false; rtl_fini_dll(this, this->PefDLLDelegate, &success); @@ -317,14 +321,14 @@ namespace Kernel } // Create heap according to type of process. - if (process.Kind == UserProcess::eExecutableDLLKind) + if (process.Kind == UserProcess::kExectuableDLLKind) { process.PefDLLDelegate = rtl_init_dll(&process); } if (!process.Image) { - if (process.Kind != UserProcess::eExecutableDLLKind) + if (process.Kind != UserProcess::kExectuableDLLKind) { process.Crash(); return -kErrorProcessFault; @@ -378,12 +382,27 @@ namespace Kernel { // check if process is within range. if (process_id > mTeam.AsArray().Count()) - return false; + return No; mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead; --mTeam.mProcessAmount; - return true; + return Yes; + } + + const Bool UserProcessScheduler::IsUser() + { + return Yes; + } + + const Bool UserProcessScheduler::IsKernel() + { + return No; + } + + const Bool UserProcessScheduler::HasMP() + { + return kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled; } /***********************************************************************************/ @@ -466,7 +485,7 @@ namespace Kernel return No; if (!process.Image && - process.Kind == UserProcess::eExecutableKind) + process.Kind == UserProcess::kExectuableKind) return No; return Yes; @@ -474,27 +493,32 @@ namespace Kernel /***********************************************************************************/ /** - * @brief Scheduler helper class. + * @brief Allocate a scheduler. */ /***********************************************************************************/ - EXTERN - HardwareThreadScheduler* cHardwareThreadScheduler; //! @brief Ask linker for the hardware thread scheduler. - - SizeT UserProcessHelper::StartScheduling() + Bool UserProcessHelper::InitializeScheduling() { - if (!cHardwareThreadScheduler) - { - cHardwareThreadScheduler = mm_new_class<HardwareThreadScheduler>(); - MUST_PASS(cHardwareThreadScheduler); - } - if (!cProcessScheduler) { cProcessScheduler = mm_new_class<UserProcessScheduler>(); - MUST_PASS(cProcessScheduler); + return cProcessScheduler; } + return No; + } + + /***********************************************************************************/ + /** + * @brief Start the scheduler. + */ + /***********************************************************************************/ + + SizeT UserProcessHelper::StartScheduling() + { + if (!cProcessScheduler) + return 0; + SizeT ret = cProcessScheduler->Run(); return ret; } |
