From a0a90c80e5dd17df8f609aebc253b4bf9147f90f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Sep 2024 12:56:23 +0200 Subject: Created a new branch for the overhaul project. Signed-off-by: Amlal El Mahrouss --- dev/HPFS/X64/EBS.asm | 2 +- dev/INST/.keepme | 0 dev/INST/ReadMe.txt | 1 + dev/INST/X64/InstallAPI.asm | 34 +++++ dev/INSTALL/.keepme | 0 dev/INSTALL/ReadMe.txt | 1 - dev/INSTALL/X64/InstallAPI.asm | 34 ----- dev/ZBA/Modules/NetBoot/build.json | 2 +- dev/ZBA/Modules/SysChk/Module.cxx | 2 +- dev/ZBA/Modules/SysChk/build.json | 2 +- dev/ZBA/Sources/HEL/AMD64/BootAPI.S | 47 +++++++ dev/ZBA/Sources/HEL/AMD64/BootJump.S | 41 ------ dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 77 ++++++----- dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx | 8 +- dev/ZBA/Sources/Thread.cxx | 2 +- dev/ZBA/amd64-efi.make | 2 +- dev/ZKA/FirmwareKit/Handover.hxx | 3 +- dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx | 99 ++++++++++++++ .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx | 9 ++ dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx | 4 +- dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx | 4 - dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 9 +- dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 9 +- dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx | 149 --------------------- dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 4 +- dev/ZKA/HALKit/AMD64/HalProcessor.cxx | 31 +++-- dev/ZKA/HALKit/AMD64/Processor.hxx | 12 +- dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx | 2 +- dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 4 +- dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx | 2 +- dev/ZKA/HALKit/ARM64/Processor.hxx | 1 - dev/ZKA/HALKit/POWER/HalHardware.cxx | 2 +- dev/ZKA/KernelKit/Heap.hxx | 8 +- dev/ZKA/NewKit/KernelCheck.hxx | 3 +- dev/ZKA/NewKit/Macros.hxx | 16 +-- dev/ZKA/NewKit/PageAllocator.hxx | 1 - dev/ZKA/NewKit/PageManager.hxx | 4 +- dev/ZKA/NewKit/Ref.hxx | 2 +- dev/ZKA/Sources/DLLMain.cxx | 16 +-- dev/ZKA/Sources/FS/NewFS.cxx | 4 +- dev/ZKA/Sources/Framebuffer.cxx | 2 +- dev/ZKA/Sources/Heap.cxx | 43 +++--- dev/ZKA/Sources/KernelCheck.cxx | 13 +- dev/ZKA/Sources/MP.cxx | 4 +- dev/ZKA/Sources/NewFS+FileManager.cxx | 1 + dev/ZKA/Sources/PageAllocator.cxx | 13 -- dev/ZKA/Sources/PageManager.cxx | 30 ++--- dev/ZKA/Sources/ThreadLocalStorage.cxx | 2 +- dev/ZKA/Sources/User.cxx | 1 - dev/ZKA/Sources/UserProcessScheduler.cxx | 29 ++-- dev/ZKA/amd64-efi.make | 4 +- 51 files changed, 356 insertions(+), 439 deletions(-) create mode 100644 dev/INST/.keepme create mode 100644 dev/INST/ReadMe.txt create mode 100644 dev/INST/X64/InstallAPI.asm delete mode 100644 dev/INSTALL/.keepme delete mode 100644 dev/INSTALL/ReadMe.txt delete mode 100644 dev/INSTALL/X64/InstallAPI.asm create mode 100644 dev/ZBA/Sources/HEL/AMD64/BootAPI.S delete mode 100644 dev/ZBA/Sources/HEL/AMD64/BootJump.S create mode 100644 dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx delete mode 100644 dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx (limited to 'dev') diff --git a/dev/HPFS/X64/EBS.asm b/dev/HPFS/X64/EBS.asm index c1d87ab5..f42098a2 100644 --- a/dev/HPFS/X64/EBS.asm +++ b/dev/HPFS/X64/EBS.asm @@ -9,7 +9,7 @@ HPFS_EBS_HEADER: db " HPFS", 0 ;; MAGIC NUMBER OF FILESYSTEM - db 1 ;; VERSION + dw 1 ;; VERSION dw 0 ;; PARTITION TYPE dw 0 ;; DISK TYPE (INVALID = 0, CDROM = 1, SSD = 2, USB = 3) dw 0 ;; CHECKSUM OF PARTITION diff --git a/dev/INST/.keepme b/dev/INST/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/dev/INST/ReadMe.txt b/dev/INST/ReadMe.txt new file mode 100644 index 00000000..d1a3953b --- /dev/null +++ b/dev/INST/ReadMe.txt @@ -0,0 +1 @@ +This installs ZKA onto a EPM compliant drive. \ No newline at end of file diff --git a/dev/INST/X64/InstallAPI.asm b/dev/INST/X64/InstallAPI.asm new file mode 100644 index 00000000..61c712d0 --- /dev/null +++ b/dev/INST/X64/InstallAPI.asm @@ -0,0 +1,34 @@ +;; /* +;; * --------------------------------------------------- +;; * +;; * Copyright ZKA Technologies., all rights reserved. +;; * +;; * File: Install.asm +;; * Purpose: ZKA installer program, runs at ring-0. +;; * +;; * --------------------------------------------------- +;; */ + +[bits 64] + +[global kInstallTitle] +[global InstInstallToDir] + +section .data + +kInstallTitle: db "ZKA Installer", 0 + +section .text + +;; @param r8 arg 1 +;; @param r9 arg 2 +;; @return rax, return status of syscall. +;; @note MS-ABI procedure. +InstInstallToDir: + mov r8, rcx ; FILE_INFO_STRUCT (SRC) + mov r9, rdx ; FILE_INFO_STRUCT (DST) + syscall ;; 0 = GOOD, 1 = BAD FIS (SRC), 2 = BAD FIS (DST) + ret + + + diff --git a/dev/INSTALL/.keepme b/dev/INSTALL/.keepme deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/INSTALL/ReadMe.txt b/dev/INSTALL/ReadMe.txt deleted file mode 100644 index d1a3953b..00000000 --- a/dev/INSTALL/ReadMe.txt +++ /dev/null @@ -1 +0,0 @@ -This installs ZKA onto a EPM compliant drive. \ No newline at end of file diff --git a/dev/INSTALL/X64/InstallAPI.asm b/dev/INSTALL/X64/InstallAPI.asm deleted file mode 100644 index 61c712d0..00000000 --- a/dev/INSTALL/X64/InstallAPI.asm +++ /dev/null @@ -1,34 +0,0 @@ -;; /* -;; * --------------------------------------------------- -;; * -;; * Copyright ZKA Technologies., all rights reserved. -;; * -;; * File: Install.asm -;; * Purpose: ZKA installer program, runs at ring-0. -;; * -;; * --------------------------------------------------- -;; */ - -[bits 64] - -[global kInstallTitle] -[global InstInstallToDir] - -section .data - -kInstallTitle: db "ZKA Installer", 0 - -section .text - -;; @param r8 arg 1 -;; @param r9 arg 2 -;; @return rax, return status of syscall. -;; @note MS-ABI procedure. -InstInstallToDir: - mov r8, rcx ; FILE_INFO_STRUCT (SRC) - mov r9, rdx ; FILE_INFO_STRUCT (DST) - syscall ;; 0 = GOOD, 1 = BAD FIS (SRC), 2 = BAD FIS (DST) - ret - - - diff --git a/dev/ZBA/Modules/NetBoot/build.json b/dev/ZBA/Modules/NetBoot/build.json index 78336241..c24966d9 100644 --- a/dev/ZBA/Modules/NetBoot/build.json +++ b/dev/ZBA/Modules/NetBoot/build.json @@ -11,7 +11,7 @@ "-fPIC", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base 0x10000000" + "-Wl,--subsystem=17,--image-base,0x1000000" ], "cpp_macros": [ "__NEWOSKRNL__", diff --git a/dev/ZBA/Modules/SysChk/Module.cxx b/dev/ZBA/Modules/SysChk/Module.cxx index 9bc3425c..7bf7fb62 100644 --- a/dev/ZBA/Modules/SysChk/Module.cxx +++ b/dev/ZBA/Modules/SysChk/Module.cxx @@ -15,7 +15,7 @@ EXTERN_C Int32 ModuleMain(Kernel::HEL::HandoverInformationHeader* Handover) cST->ConOut->ClearScreen(cST->ConOut); - cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: CHECKING FOR VALID NEWFS OR EXT4 PARTITIONS...\r\n"); + cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: CHECKING FOR VALID NEWFS OR HPFS PARTITIONS...\r\n"); cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: GOOD TO GO!\r\n"); return kEfiOk; diff --git a/dev/ZBA/Modules/SysChk/build.json b/dev/ZBA/Modules/SysChk/build.json index 67e22955..dac413e0 100644 --- a/dev/ZBA/Modules/SysChk/build.json +++ b/dev/ZBA/Modules/SysChk/build.json @@ -11,7 +11,7 @@ "-fPIC", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,ModuleMain" + "-Wl,--subsystem=17,--image-base,0x1000000,-e,ModuleMain" ], "cpp_macros": [ "__NEWOSKRNL__", diff --git a/dev/ZBA/Sources/HEL/AMD64/BootAPI.S b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S new file mode 100644 index 00000000..e391351d --- /dev/null +++ b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S @@ -0,0 +1,47 @@ +.global rt_jump_to_address +.global rt_reset_hardware + +.text + +.intel_syntax noprefix + +/** + @brief this function setups a stack and then jumps to + a function */ +rt_jump_to_address: + mov rbx, rcx + mov rcx, rdx + jmp rbx + + ret + +rt_reset_hardware: + /* dont raise any interrupts. (except ofc NMIs.) */ + cli +wait_gate1: + /* wait for gate 1 to be ready? */ + in al,0x64 + and al,2 + jnz wait_gate1 + mov al,0x0D1 + out 0x64,al +wait_gate2: + /* wait for gate 2 to be ready? */ + in al,0x64 + and al,2 + jnz wait_gate2 + mov al,0x0FE + out 0x60,al + + /* trigger triple fault, by writing to cr4 */ + + xor rax,rax + mov cr4,rax +reset_wait: + jmp reset_wait + +.global write_cr3 + +write_cr3: + mov cr3, rcx + ret \ No newline at end of file diff --git a/dev/ZBA/Sources/HEL/AMD64/BootJump.S b/dev/ZBA/Sources/HEL/AMD64/BootJump.S deleted file mode 100644 index d8e09d4e..00000000 --- a/dev/ZBA/Sources/HEL/AMD64/BootJump.S +++ /dev/null @@ -1,41 +0,0 @@ -.global rt_jump_to_address -.global rt_reset_hardware - -.text - -.intel_syntax noprefix - -/** - @brief this function setups a stack and then jumps to - a function */ -rt_jump_to_address: - mov rbx, rcx - mov rcx, rdx - jmp rbx - - ret - -rt_reset_hardware: - /* dont raise any interrupts. (except ofc NMIs.) */ - cli -wait_gate1: - /* wait for gate 1 to be ready? */ - in al,0x64 - and al,2 - jnz wait_gate1 - mov al,0x0D1 - out 0x64,al -wait_gate2: - /* wait for gate 2 to be ready? */ - in al,0x64 - and al,2 - jnz wait_gate2 - mov al,0x0FE - out 0x60,al - - /* trigger triple fault, by writing to cr4 */ - - xor rax,rax - mov cr4,rax -reset_wait: - jmp reset_wait diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 576ada08..55f10ea2 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -79,6 +79,8 @@ STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) return true; } +EXTERN_C Void write_cr3(VoidPtr new_cr3); + /// @brief Main EFI entrypoint. /// @param ImageHandle Handle of this image. /// @param SystemTable The system table of it. @@ -186,17 +188,45 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] = (UIntPtr)Descriptor; - handoverHdrPtr->f_VirtualStart = - (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; + handoverHdrPtr->f_BitMapStart = 0; - handoverHdrPtr->f_HeapStart = 0; + while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk) + ; - while (BS->AllocatePool(EfiLoaderData, kHandoverHeapSz, &handoverHdrPtr->f_HeapStart) != kEfiOk) + auto extended_heap = (VoidPtr)((UIntPtr)handoverHdrPtr->f_BitMapStart + kHandoverHeapSz); + + while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &extended_heap) != kEfiOk) ; handoverHdrPtr->f_VirtualSize = Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ + + handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS; + handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST; + + BFileReader readerSysChk(L"syschk.sys", ImageHandle); + readerSysChk.ReadAll(0); + + Boot::BThread* loaderSysChk = nullptr; + + // ------------------------------------------ // + // If we succeed in reading the blob, then execute it. + // ------------------------------------------ // + + if (readerSysChk.Blob()) + { + loaderSysChk = new Boot::BThread(readerSysChk.Blob()); + loaderSysChk->SetName("System Check SYS."); + } + + loaderSysChk->Start(handoverHdrPtr); + + // nullify these fields, to avoid being reused later. + + handoverHdrPtr->f_FirmwareCustomTables[0] = nullptr; + handoverHdrPtr->f_FirmwareCustomTables[1] = nullptr; + handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); handoverHdrPtr->f_Magic = kHandoverMagic; @@ -213,6 +243,12 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, BDiskFormatFactory checkPart; + // ---------------------------------------------------- // + // The following checks for an exisiting partition + // inside the disk, if it doesn't have one, + // format the disk. + // ---------------------------------------------------- // + if (!checkPart.IsPartitionValid()) { BDiskFormatFactory::BFileDescriptor root; @@ -226,37 +262,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, rt_reset_hardware(); } - // ---------------------------------------------------- // - // The following checks for an exisiting partition - // inside the disk, if it doesn't have one, - // format the disk. - // ---------------------------------------------------- // - - handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS; - handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST; - - BFileReader readerSysChk(L"syschk.sys", ImageHandle); - readerSysChk.ReadAll(0); - - Boot::BThread* loaderSysChk = nullptr; - - // ------------------------------------------ // - // If we succeed in reading the blob, then execute it. - // ------------------------------------------ // - - if (readerSysChk.Blob()) - { - loaderSysChk = new Boot::BThread(readerSysChk.Blob()); - loaderSysChk->SetName("64-bit System Check DLL."); - } - - loaderSysChk->Start(handoverHdrPtr); - - // nullify these fields, to avoid being reused later. - - handoverHdrPtr->f_FirmwareCustomTables[0] = nullptr; - handoverHdrPtr->f_FirmwareCustomTables[1] = nullptr; - BFileReader readerKernel(L"newoskrnl.exe", ImageHandle); readerKernel.ReadAll(0); @@ -270,7 +275,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, if (readerKernel.Blob()) { loader = new Boot::BThread(readerKernel.Blob()); - loader->SetName("64-bit Kernel DLL."); + loader->SetName("64-Bit Kernel EXE."); handoverHdrPtr->f_KernelImage = readerKernel.Blob(); } diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx index 467f4303..65ea3d89 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx @@ -25,7 +25,7 @@ */ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) { -#ifdef __DEBUG__ +#ifdef __DEBUG_OUTPUT__ if (!str || *str == 0) return *this; @@ -57,7 +57,7 @@ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) /// @param str the input string. BTextWriter& BTextWriter::Write(const Char* str) { -#ifdef __DEBUG__ +#ifdef __DEBUG_OUTPUT__ if (!str || *str == 0) return *this; @@ -87,7 +87,7 @@ BTextWriter& BTextWriter::Write(const Char* str) BTextWriter& BTextWriter::Write(const UChar* str) { -#ifdef __DEBUG__ +#ifdef __DEBUG_OUTPUT__ if (!str || *str == 0) return *this; @@ -120,7 +120,7 @@ BTextWriter& BTextWriter::Write(const UChar* str) */ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { -#ifdef __DEBUG__ +#ifdef __DEBUG_OUTPUT__ EfiCharType str[2]; str[0] = c; diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx index 1ea83618..13b02b92 100644 --- a/dev/ZBA/Sources/Thread.cxx +++ b/dev/ZBA/Sources/Thread.cxx @@ -165,7 +165,7 @@ namespace Boot err_fn(handover); } - rt_jump_to_address(fStartAddress, handover); + reinterpret_cast(fStartAddress)(handover); } const Char* BThread::GetName() diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index d75f2aaf..55ce3f1c 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -36,7 +36,7 @@ EMU_FLAGS=-net none -m 8G -M q35 -cpu qemu64 \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -d int + -device ide-hd,drive=disk_2,bus=ahci.0 -d int -no-reboot -no-shutdown LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 46fca139..80d68afa 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -62,10 +62,9 @@ namespace Kernel::HEL UInt64 f_Magic; UInt64 f_Version; - VoidPtr f_VirtualStart; + VoidPtr f_BitMapStart; SizeT f_VirtualSize; VoidPtr f_PhysicalStart; - VoidPtr f_HeapStart; VoidPtr f_KernelImage; VoidPtr f_StartupChime; diff --git a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx new file mode 100644 index 00000000..677b1219 --- /dev/null +++ b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx @@ -0,0 +1,99 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include + +#define cVMHMagic ((Kernel::UIntPtr)0x10210) + +#ifdef __ZKA_AMD64__ +#include +#elif defined(__ZKA_ARM64__) +#include +#endif + +#include +#include + +namespace Kernel +{ + namespace HAL + { + namespace Detail + { + struct AllocatorTraits final + { + /// @brief Iterate over availables pages for a free one. + /// @return The new address which was found. + VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept + { + while (base_ptr && size) + { + UIntPtr* ptr_bit_set = reinterpret_cast(base_ptr); + + if (ptr_bit_set[0] != cVMHMagic) + { + ptr_bit_set[0] = cVMHMagic; + ptr_bit_set[1] = size; + + kcout << "BBP: STATUS\r"; + kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "BBP: ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + + if (rw) + mm_update_pte(base_ptr, eFlagsRw); + + if (user) + mm_update_pte(base_ptr, eFlagsUser); + + return (VoidPtr)(ptr_bit_set + 2); + } + + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + size); + } + + return nullptr; + } + }; + } // namespace Detail + + /// @brief Allocate a new page to be used by the OS. + /// @param rw read/write bit. + /// @param user user bit. + /// @return + auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr + { + VoidPtr ptr_new = nullptr; + Detail::AllocatorTraits traits; + + ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + + return ptr_new; + } + + auto mm_free_bitmap(VoidPtr page_ptr) -> Bool + { + if (!page_ptr) + return false; + + UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 2; + + if (!ptr_bit_set[0] || + ptr_bit_set[0] != cVMHMagic) + return false; + + kcout << "BBP: FREE STATUS\r"; + kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "BBP: ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + + ptr_bit_set[0] = 0UL; + ptr_bit_set[1] = 0UL; + + return true; + } + } // namespace HAL +} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index 611ec596..1bb54588 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -13,6 +13,9 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); + Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } /// @brief Handle page fault. @@ -20,6 +23,8 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } @@ -28,6 +33,8 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } @@ -44,6 +51,8 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx index 2e76d73a..b524b04c 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx @@ -160,10 +160,10 @@ namespace Kernel::HAL { fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak(); - return true; + return Yes; } - return false; + return No; } /***********************************************************************************/ diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx index 4474295f..19d62965 100644 --- a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx +++ b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx @@ -47,8 +47,6 @@ namespace Kernel::HAL for (UInt16 idt_indx = 0; idt_indx < 12; ++idt_indx) { - MUST_PASS(ptr_ivt[idt_indx]); - Detail::kInterruptVectorTable[idt_indx].Selector = kGdtKernelCodeSelector; Detail::kInterruptVectorTable[idt_indx].Ist = 0; Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kTrapGate; @@ -62,8 +60,6 @@ namespace Kernel::HAL for (UInt16 idt_indx = 13; idt_indx < kKernelIdtSize; ++idt_indx) { - MUST_PASS(ptr_ivt[idt_indx]); - Detail::kInterruptVectorTable[idt_indx].Selector = kGdtKernelCodeSelector; Detail::kInterruptVectorTable[idt_indx].Ist = 0; Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kInterruptGate; diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 34398871..33c3f689 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -56,7 +56,6 @@ namespace Kernel::HAL Kernel::Property cKernelVersion; Kernel::User cUserSuper{Kernel::RingKind::kRingSuperUser, kSuperUser}; -EXTERN Kernel::Boolean kAllocationInProgress; EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; Kernel::Void hal_real_init(Kernel::Void) noexcept; @@ -93,17 +92,12 @@ EXTERN_C void hal_init_platform( Kernel::Void hal_real_init(Kernel::Void) noexcept { - // reset kAllocationInProgress field to zero. - kAllocationInProgress = false; - - kKernelVMHStart = kHandoverHeader->f_HeapStart; - // get page size. kKernelVirtualSize = kHandoverHeader->f_VirtualSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast( - reinterpret_cast(kHandoverHeader->f_VirtualStart)); + reinterpret_cast(kHandoverHeader->f_BitMapStart)); // get physical address start. kKernelPhysicalStart = reinterpret_cast( @@ -136,7 +130,6 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept auto fs = new Kernel::NewFilesystemManager(); MUST_PASS(fs); - MUST_PASS(fs->GetParser()); Kernel::NewFilesystemManager::Mount(fs); diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index dc534589..39a80922 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -67,20 +67,15 @@ mp_system_call_handler: o64 sysret mp_do_context_switch_pre: + mov rcx, 0xc0000082 + wrmsr mov rcx, 0xc0000080 rdmsr or eax, 1 wrmsr - mov rcx, 0xc0000081 rdmsr - mov rax, 0x00000000 mov edx, 0x00180008 wrmsr - mov rcx, 0xc0000082 - mov rax, mp_system_call_handler - mov rdx, 0x0 - wrmsr - ret diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx deleted file mode 100644 index 28b5f9be..00000000 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ /dev/null @@ -1,149 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include - -#define cVMHMagic (0xDEEFD00D) -#define cPaddingVMH (16) - -#ifdef __ZKA_AMD64__ -#include -#elif defined(__ZKA_ARM64__) -#include -#endif - -#include -#include - -Kernel::Boolean kAllocationInProgress = false; - -namespace Kernel -{ - namespace HAL - { - namespace Detail - { - struct VIRTUAL_MEMORY_HEADER - { - UInt32 Magic; - Boolean Present : 1; - Boolean ReadWrite : 1; - Boolean User : 1; - SizeT Size; - }; - - struct VirtualMemoryHeaderTraits final - { - /// @brief Get next header. - /// @param current - /// @return - VIRTUAL_MEMORY_HEADER* Next(VIRTUAL_MEMORY_HEADER* current) - { - if (current->Magic != cVMHMagic) - return current; - - return current + sizeof(VIRTUAL_MEMORY_HEADER) + current->Size; - } - - /// @brief Get previous header. - /// @param current - /// @return - VIRTUAL_MEMORY_HEADER* Prev(VIRTUAL_MEMORY_HEADER* current) - { - if (current->Magic != cVMHMagic) - return current; - - return current - sizeof(VIRTUAL_MEMORY_HEADER) - current->Size; - } - }; - } // namespace Detail - - /// @brief Allocates a new page of memory. - /// @param sz the size of it. - /// @param rw read/write flag. - /// @param user user flag. - /// @return the page table of it. - STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - if (kAllocationInProgress) - return nullptr; - - kAllocationInProgress = true; - - //! fetch from the start. - Detail::VIRTUAL_MEMORY_HEADER* vmh_header = reinterpret_cast(kKernelVMHStart); - Detail::VirtualMemoryHeaderTraits traits; - - while (vmh_header->Present && - vmh_header->Magic == cVMHMagic) - { - vmh_header = traits.Next(vmh_header); - - if (vmh_header == reinterpret_cast(kBadPtr)) - { - ke_stop(RUNTIME_CHECK_POINTER); - return nullptr; - } - } - - vmh_header->Magic = cVMHMagic; - vmh_header->Present = true; - vmh_header->ReadWrite = rw; - vmh_header->User = user; - vmh_header->Size = size; - - kAllocationInProgress = false; - - VoidPtr result = reinterpret_cast(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER)); - - mm_update_pte(result, (rw ? eFlagsRw : 0)); - mm_update_pte(result, (user ? eFlagsUser : 0)); - - return result; - } - - /// @brief Allocate a new page to be used by the OS. - /// @param rw read/write bit. - /// @param user user bit. - /// @return - auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - kcout << "PageAlloc: Waiting now..."; - - // Wait for a ongoing allocation to complete. - while (kAllocationInProgress) - { - (Void)0; - } - - kcout << ", done waiting, allocating...\r"; - - if (size == 0) - ++size; - - // Now allocate the page. - return hal_try_alloc_new_page(rw, user, size); - } - - auto hal_free_page(VoidPtr page_ptr) -> Bool - { - if (!page_ptr) - return false; - - Detail::VIRTUAL_MEMORY_HEADER* result = reinterpret_cast((UIntPtr)page_ptr - sizeof(Detail::VIRTUAL_MEMORY_HEADER)); - - if (result->Magic != cVMHMagic) - return false; - - if (result->Present != true) - return true; - - result->Present = false; - - return true; - } - } // namespace HAL -} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index aadabd9c..8eb85e78 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -87,8 +87,8 @@ namespace Kernel::HAL ZKA_PTE ALIGN(kPTEAlign) Pte[kPTEMax]; }; - auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr; - auto hal_free_page(VoidPtr page_ptr) -> Bool; + auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr; + auto mm_free_bitmap(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index 407b7e51..3c34ab68 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -27,32 +27,37 @@ namespace Kernel::HAL // Access PML4 entry volatile UInt64* pml4_entry = (volatile UInt64*)(((UInt64)pml4_base) + pml4_idx * sizeof(UIntPtr)); - UInt64 pdpt_base = *pml4_entry & ~0xFFF; // Remove flags (assuming 4KB pages) + UInt64 pdpt_base = *pml4_entry & ~0xFFF; // Remove flags (assuming 4KB pages) // Access PDPT entry volatile UInt64* pdpt_entry = (volatile UInt64*)(((UInt64)pdpt_base) + pdpt_idx * sizeof(UIntPtr)); - UInt64 pd_base = *pdpt_entry & ~0xFFF; // Remove flags + UInt64 pd_base = *pdpt_entry & ~0xFFF; // Remove flags + // Now PD volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pd_base) + pd_idx * sizeof(UIntPtr)); UInt64 pt_base = *pd_entry & ~0xFFF; // Remove flags + // And then PTE volatile UInt64* page_addr = (volatile UInt64*)(((UInt64)pt_base) + (pte_idx * sizeof(UIntPtr))); - if (page_addr) - { - if (flags & eFlagsPresent) - *page_addr |= 0x01; // present bit + if (flags & eFlagsPresent) + *page_addr |= 0x01; // present bit + else if (flags & ~eFlagsPresent) + *page_addr &= 0x01; // present bit - if (flags & eFlagsRw) - *page_addr |= 0x02; + if (flags & eFlagsRw) + *page_addr |= 0x02; + else if (flags & ~eFlagsRw) + *page_addr &= 0x02; // present bit - if (flags & eFlagsUser) - *page_addr |= 0x02; + if (flags & eFlagsUser) + *page_addr |= 0x04; + else if (flags & ~eFlagsUser) + *page_addr &= 0x04; // present bit - return Yes; - } + hal_write_cr3((UIntPtr)pml4_base); - return No; + return 0; } Void Out8(UInt16 port, UInt8 value) diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index a80e13cb..b7fa080c 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -56,11 +56,10 @@ namespace Kernel::HAL /// @brief Virtual memory flags. enum { - eFlagsPresent, - eFlagsUser, - eFlagsRw, - eFlagsExecDisable, - eFlagsCount, + eFlagsPresent = 0x01, + eFlagsRw = 0x02, + eFlagsUser = 0x04, + eFlagsCount = 0x3, }; /// @brief Updates a PTE from pd_base. @@ -100,7 +99,7 @@ namespace Kernel::HAL using InterruptId = UInt16; /* For each element in the IVT */ /// @brief Stack frame (as retrieved from assembly.) - struct PACKED StackFrame final + struct StackFrame final { UIntPtr R8{0}; UIntPtr R9{0}; @@ -293,7 +292,6 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); #define kKernelIdtSize 0x100 #define kKernelInterruptId 0x32 -inline Kernel::VoidPtr kKernelVMHStart = nullptr; inline Kernel::VoidPtr kKernelVirtualStart = nullptr; inline Kernel::UIntPtr kKernelVirtualSize = 0UL; diff --git a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx index 996b93ee..052f8c64 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -107,7 +107,7 @@ ATAInit_Retry: OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - Kernel::kcout << "newoskrnl.exe: Create ATA module.\r"; + Kernel::kcout << "newoskrnl.exe: Created IDE module.\r"; return true; } diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index 52e4f1ee..d51f0421 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -76,14 +76,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept // reset kAllocationInProgress field to zero. kAllocationInProgress = false; - kKernelVMHStart = kHandoverHeader->f_HeapStart; - // get page size. kKernelVirtualSize = kHandoverHeader->f_VirtualSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast( - reinterpret_cast(kHandoverHeader->f_VirtualStart)); + reinterpret_cast(kHandoverHeader->f_BitMapStart)); // get physical address start. kKernelPhysicalStart = reinterpret_cast( diff --git a/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx b/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx index ef3b6db1..ab77f1d0 100644 --- a/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx @@ -96,7 +96,7 @@ namespace Kernel::HAL LongDescLevel3 ALIGN(kPTEAlign) Pte[kPTEMax]; }; - VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size); + VoidPtr mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size); } // namespace Kernel::HAL namespace Kernel diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx index 1880d36c..ad2bdc7b 100644 --- a/dev/ZKA/HALKit/ARM64/Processor.hxx +++ b/dev/ZKA/HALKit/ARM64/Processor.hxx @@ -42,7 +42,6 @@ namespace Kernel::HAL typedef StackFrame* StackFramePtr; } // namespace Kernel::HAL -inline Kernel::VoidPtr kKernelVMHStart = nullptr; inline Kernel::VoidPtr kKernelVirtualStart = nullptr; inline Kernel::UIntPtr kKernelVirtualSize = 0UL; diff --git a/dev/ZKA/HALKit/POWER/HalHardware.cxx b/dev/ZKA/HALKit/POWER/HalHardware.cxx index 9fb841c8..eb335d70 100644 --- a/dev/ZKA/HALKit/POWER/HalHardware.cxx +++ b/dev/ZKA/HALKit/POWER/HalHardware.cxx @@ -11,7 +11,7 @@ namespace Kernel { namespace HAL { - UIntPtr hal_alloc_page(bool rw, bool user) + UIntPtr mm_alloc_bitmap(bool rw, bool user) { return 0; } diff --git a/dev/ZKA/KernelKit/Heap.hxx b/dev/ZKA/KernelKit/Heap.hxx index 65b71774..27c79c83 100644 --- a/dev/ZKA/KernelKit/Heap.hxx +++ b/dev/ZKA/KernelKit/Heap.hxx @@ -30,10 +30,10 @@ namespace Kernel /// @return if it exists. Boolean mm_is_valid_heap(VoidPtr heap_ptr); - /// @brief allocate chunk of memory. - /// @param sz size of pointer - /// @param rw read write (true to enable it) - /// @param user is it accesible by user processes? + /// @brief Allocate chunk of memory. + /// @param sz Size of pointer + /// @param rw Read Write bit. + /// @param user User enable bit. /// @return The newly allocated pointer. VoidPtr mm_new_ke_heap(const SizeT sz, const Bool rw, const Bool user); diff --git a/dev/ZKA/NewKit/KernelCheck.hxx b/dev/ZKA/NewKit/KernelCheck.hxx index 58a76acb..8797ff86 100644 --- a/dev/ZKA/NewKit/KernelCheck.hxx +++ b/dev/ZKA/NewKit/KernelCheck.hxx @@ -20,7 +20,7 @@ namespace Kernel Kernel::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE)) #ifdef __DEBUG__ -#define MUST_PASS(EXPR) __MUST_PASS(EXPR, __FILE__, __LINE__) +#define MUST_PASS(EXPR) __MUST_PASS((EXPR), __FILE__, __LINE__) #define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION) #else #define MUST_PASS(EXPR) (Kernel::Void)(EXPR) @@ -43,6 +43,7 @@ enum RUNTIME_CHECK RUNTIME_CHECK_BOOTSTRAP, RUNTIME_CHECK_UNEXCPECTED, RUNTIME_CHECK_FILESYSTEM, + RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM, RUNTIME_CHECK_COUNT, }; diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index 153b8c45..b9242e79 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -7,31 +7,31 @@ #pragma once #ifndef KIB -#define KIB(X) ((X) / 1024) +#define KIB(X) (Kernel::UInt64)((X) / 1024) #endif #ifndef kib_cast -#define kib_cast(X) ((X)*1024) +#define kib_cast(X) (Kernel::UInt64)((X)*1024) #endif #ifndef MIB -#define MIB(X) ((Kernel::UInt64)KIB(X) / 1024) +#define MIB(X) (Kernel::UInt64)((Kernel::UInt64)KIB(X) / 1024) #endif #ifndef mib_cast -#define mib_cast(X) ((Kernel::UInt64)kib_cast(X) * 1024) +#define mib_cast(X) (Kernel::UInt64)((Kernel::UInt64)kib_cast(X) * 1024) #endif #ifndef GIB -#define GIB(X) ((Kernel::UInt64)MIB(X) / 1024) +#define GIB(X) (Kernel::UInt64)((Kernel::UInt64)MIB(X) / 1024) #endif #ifndef gib_cast -#define gib_cast(X) ((Kernel::UInt64)mib_cast(X) * 1024) +#define gib_cast(X) (Kernel::UInt64)((Kernel::UInt64)mib_cast(X) * 1024) #endif #ifndef TIB -#define TIB(X) ((Kernel::UInt64)GIB(X) / 1024) +#define TIB(X) (Kernel::UInt64)((Kernel::UInt64)GIB(X) / 1024) #endif #ifndef tib_cast @@ -94,7 +94,7 @@ #define CANT_REACH() __builtin_unreachable() #endif -#define kBadPtr 0xFBFBFBFBFBFBFBFB +#define kInvalidAddress 0xFBFBFBFBFBFBFBFB #define kBadAddress 0x00000000000000 #define kMaxAddr 0xFFFFFFFFFFFFFFFF #define kPathLen 255 diff --git a/dev/ZKA/NewKit/PageAllocator.hxx b/dev/ZKA/NewKit/PageAllocator.hxx index b485e722..a6d84aa0 100644 --- a/dev/ZKA/NewKit/PageAllocator.hxx +++ b/dev/ZKA/NewKit/PageAllocator.hxx @@ -13,7 +13,6 @@ namespace Kernel { namespace Detail { - VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz); void exec_disable(UIntPtr addr); bool page_disable(UIntPtr addr); } // namespace Detail diff --git a/dev/ZKA/NewKit/PageManager.hxx b/dev/ZKA/NewKit/PageManager.hxx index 249c0cc9..0de37803 100644 --- a/dev/ZKA/NewKit/PageManager.hxx +++ b/dev/ZKA/NewKit/PageManager.hxx @@ -33,6 +33,8 @@ namespace Kernel void NoExecute(const bool enable = false); const bool& NoExecute(); + operator bool() { return fVirtAddr; } + bool Reclaim(); bool Shareable(); bool Present(); @@ -68,7 +70,7 @@ namespace Kernel bool Free(Ref& wrapper); private: - void FlushTLB(UIntPtr VirtAddr); + void FlushTLB(); private: friend PTEWrapper; diff --git a/dev/ZKA/NewKit/Ref.hxx b/dev/ZKA/NewKit/Ref.hxx index 977c353a..7f5167c2 100644 --- a/dev/ZKA/NewKit/Ref.hxx +++ b/dev/ZKA/NewKit/Ref.hxx @@ -84,7 +84,7 @@ namespace Kernel NonNullRef(T* ref) : fRef(ref, true) { - MUST_PASS(ref != nullptr); + MUST_PASS(ref); } Ref& operator->() diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 934f418c..84c58b3a 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -150,14 +150,12 @@ namespace Kernel::Detail }; } // namespace Kernel::Detail -namespace Kernel +EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void) { - EXTERN UserProcessScheduler* cProcessScheduler; -} // namespace Kernel + while (Yes) + { -EXTERN_C Kernel::Void HangCPU(Kernel::Void) -{ - while (1); + } } /// @brief Application entrypoint. @@ -189,10 +187,6 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Running System Component: ", 10, 10, RGB(0, 0, 0)); CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("newoskrnl.exe: Running System Component: ")), RGB(0, 0, 0)); - /// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. - Kernel::cProcessScheduler = nullptr; - Kernel::UserProcessHelper::StartScheduling(); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Starting ZKA System...", 20, 10, RGB(0, 0, 0)); Kernel::sched_execute_thread(HangCPU, "HANG TEST"); @@ -201,6 +195,4 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { Kernel::UserProcessHelper::StartScheduling(); } - - Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx index bf55a56f..e3ec6184 100644 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ b/dev/ZKA/Sources/FS/NewFS.cxx @@ -1035,11 +1035,11 @@ namespace Kernel::Detail sMountpointInterface.C() = io_construct_drive(); sMountpointInterface.D() = io_construct_drive(); - kcout << "newoskrnl.exe: Testing main drive...\r"; + kcout << "newoskrnl.exe: Testing A:\r"; sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - kcout << "newoskrnl.exe: Testing main drive [ OK ]...\r"; + kcout << "newoskrnl.exe: Testing A: [ OK ]\r"; return true; } diff --git a/dev/ZKA/Sources/Framebuffer.cxx b/dev/ZKA/Sources/Framebuffer.cxx index 76fe7172..3794e458 100644 --- a/dev/ZKA/Sources/Framebuffer.cxx +++ b/dev/ZKA/Sources/Framebuffer.cxx @@ -44,7 +44,7 @@ namespace Kernel { return fFrameBufferAddr.Leak()->fBase != 0 && fColour != FramebufferColorKind::INVALID && - fFrameBufferAddr.Leak()->fBase != kBadPtr; + fFrameBufferAddr.Leak()->fBase != kInvalidAddress; } /// @brief Set color kind of framebuffer. diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index bd7e299b..e036badb 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -85,10 +85,10 @@ namespace Kernel 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? + /// @brief Allocate chunk of memory. + /// @param sz Size of pointer + /// @param rw Read Write bit. + /// @param user User enable bit. /// @return The newly allocated pointer. VoidPtr mm_new_ke_heap(const SizeT sz, const bool rw, const bool user) { @@ -99,28 +99,29 @@ namespace Kernel if (szFix == 0) ++szFix; - auto wrapper = kHeapPageManager.Request(rw, user, false, szFix); + auto wrapper = kHeapPageManager.Request(rw, user, No, szFix); Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr = reinterpret_cast( - wrapper.VirtualAddress()); + wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK)); heap_info_ptr->fHeapSize = szFix; - heap_info_ptr->fMagic = kKernelHeapMagic; - heap_info_ptr->fCRC32 = 0U; // dont fill it for now. - heap_info_ptr->fHeapPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); - heap_info_ptr->fPage = 0UL; - heap_info_ptr->fUser = user; - heap_info_ptr->fPresent = true; + heap_info_ptr->fMagic = kKernelHeapMagic; + heap_info_ptr->fCRC32 = 0U; // dont fill it for now. + heap_info_ptr->fHeapPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); + heap_info_ptr->fPage = 0UL; + heap_info_ptr->fUser = user; + heap_info_ptr->fPresent = true; ++kHeapCount; + auto result = reinterpret_cast(heap_info_ptr->fHeapPtr); + kLatestAllocation = heap_info_ptr; Detail::mm_alloc_fini_timeout(); - return reinterpret_cast(heap_info_ptr + - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + return result; } /// @brief Makes a page heap. @@ -132,7 +133,7 @@ namespace Kernel return -kErrorInternal; if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) return -kErrorInternal; - if (((IntPtr)heap_ptr - kBadPtr) < 0) + if (((IntPtr)heap_ptr - kInvalidAddress) < 0) return -kErrorInternal; Detail::mm_alloc_init_timeout(); @@ -157,7 +158,7 @@ namespace Kernel return -kErrorInternal; if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) return -kErrorInternal; - if (((IntPtr)heap_ptr - kBadPtr) < 0) + if (((IntPtr)heap_ptr - kInvalidAddress) < 0) return -kErrorInternal; Detail::mm_alloc_init_timeout(); @@ -188,12 +189,12 @@ namespace Kernel } heapInfoBlk->fHeapSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fHeapPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heapInfoBlk->fPresent = false; + heapInfoBlk->fHeapPtr = 0; + heapInfoBlk->fCRC32 = 0; + heapInfoBlk->fMagic = 0; - PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heapInfoBlk)); + PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heapInfoBlk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); Ref pteAddress{&pageWrapper}; kHeapPageManager.Free(pteAddress); diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index a05c265a..0ed96593 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -56,6 +56,7 @@ namespace Kernel { case RUNTIME_CHECK_PROCESS: { CGDrawString("0x00000008 No more processes to run, this is because that ZKA ran out of processes.", start_y, x, panicTxt); + RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_ACPI: { @@ -102,7 +103,7 @@ namespace Kernel break; } case RUNTIME_CHECK_FAILED: { - CGDrawString("0x10000001 Assertion failed.", start_y, x, panicTxt); + CGDrawString("0x10000001 Kernel bug-check failure.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } @@ -120,13 +121,6 @@ namespace Kernel Void RecoveryFactory::Recover() noexcept { - const auto cMaxSeconds = Seconds(4); - - HardwareTimer timer(cMaxSeconds); - timer.Wait(); - - kcout << "newoskrnl.exe: Shutting down computer...\r"; - PowerFactoryInterface power(nullptr); power.Shutdown(); } @@ -135,6 +129,9 @@ namespace Kernel { if (!expr) { + kcout << "ASSERTION FAILED: FILE: " << file << endl; + kcout << "ASSERTION FAILED: LINE: " << line << endl; + ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed } } diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx index b3b62609..7429751f 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/MP.cxx @@ -125,12 +125,12 @@ namespace Kernel ///! @brief Default constructor. HardwareThreadScheduler::HardwareThreadScheduler() { - kcout << "newoskrnl.exe: initializing HardwareThreadScheduler." << endl; + kcout << "newoskrnl.exe: Initializing HardwareThreadScheduler." << endl; cSMPCoreName.GetKey() += "Property\\MPClass"; cSMPCoreName.GetValue() = (PropertyId)this; - kcout << "newoskrnl.exe: initialized HardwareThreadScheduler." << endl; + kcout << "newoskrnl.exe: Initialized HardwareThreadScheduler." << endl; } ///! @brief Default destructor. diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NewFS+FileManager.cxx index 98e0e3af..20fb623d 100644 --- a/dev/ZKA/Sources/NewFS+FileManager.cxx +++ b/dev/ZKA/Sources/NewFS+FileManager.cxx @@ -19,6 +19,7 @@ namespace Kernel { MUST_PASS(Detail::fs_init_newfs()); fImpl = new NewFSParser(); + MUST_PASS(fImpl); kcout << "newoskrnl.exe: We are done here... (NewFilesystemManager).\r"; } diff --git a/dev/ZKA/Sources/PageAllocator.cxx b/dev/ZKA/Sources/PageAllocator.cxx index dec6c470..e68d0659 100644 --- a/dev/ZKA/Sources/PageAllocator.cxx +++ b/dev/ZKA/Sources/PageAllocator.cxx @@ -11,19 +11,6 @@ /// @brief Internal namespace, used internally by Kernel. namespace Kernel::Detail { - VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz) - { - auto addr = HAL::hal_alloc_page(rw, user, pageSz); - - if (addr == kBadAddress) - { - kcout << "[create_page_wrapper] kBadAddress returned\n"; - ke_stop(RUNTIME_CHECK_POINTER); - } - - return addr; - } - void exec_disable(UIntPtr VirtualAddr) { #ifdef __ZKA_SUPPORT_NX__ diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageManager.cxx index d14130ff..dd18709f 100644 --- a/dev/ZKA/Sources/PageManager.cxx +++ b/dev/ZKA/Sources/PageManager.cxx @@ -35,11 +35,8 @@ namespace Kernel /// @brief Flush virtual address. /// @param VirtAddr - Void PageManager::FlushTLB(UIntPtr VirtAddr) + Void PageManager::FlushTLB() { - if (VirtAddr == kBadAddress) - return; - hal_flush_tlb(); } @@ -64,31 +61,20 @@ namespace Kernel PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) { // Store PTE wrapper right after PTE. - VoidPtr ptr = Kernel::HAL::hal_alloc_page(Rw, User, Sz); - - if (ptr == kBadAddress) - { - kcout << "[create_page_wrapper] kBadAddress returned\n"; - ke_stop(RUNTIME_CHECK_POINTER); - } + VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast(ptr)}; } - /// @brief Disable PTE. + /// @brief Disable BitMap. /// @param wrapper the wrapper. - /// @return - bool PageManager::Free(Ref& wrapper) + /// @return If the page bitmap was cleared or not. + Bool PageManager::Free(Ref& wrapper) { - if (wrapper) - { - if (!Kernel::HAL::hal_free_page((VoidPtr)wrapper->VirtualAddress())) - return false; + if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper->VirtualAddress())) + return false; - return true; - } - - return false; + return true; } /// @brief Virtual PTE address. diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index f4794bdd..e68593f6 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -21,7 +21,7 @@ using namespace Kernel; -namespace Detail +namespace Kernel::Detail { /// \brief UserProcess thread information header. struct THREAD_HEADER_BLOCK final diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 5a4c2335..871d011f 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -77,7 +77,6 @@ namespace Kernel SizeT len = rt_string_len(password_to_fill); Char* password = new Char[len]; - MUST_PASS(password); // fill data first, generate hash. diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index dc142b18..26d8be79 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -28,13 +28,13 @@ namespace Kernel /// @brief Exit Code global variable. /***********************************************************************************/ - UInt32 cLastExitCode = 0U; + STATIC UInt32 cLastExitCode = 0U; /***********************************************************************************/ /// @brief UserProcess scheduler instance. /***********************************************************************************/ - UserProcessScheduler* cProcessScheduler = nullptr; + STATIC UserProcessScheduler* cProcessScheduler; /// @brief Gets the last exit code. /// @note Not thread-safe. @@ -53,11 +53,9 @@ namespace Kernel if (this->Name == 0) return; - kcout << this->Name << ": crashed. (id = " << number(kErrorProcessFault) << endl; + kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl; this->Exit(kErrorProcessFault); - - UserProcessHelper::StartScheduling(); } /// @brief Gets the local last exit code. @@ -246,8 +244,12 @@ namespace Kernel } process.StackFrame = new HAL::StackFrame(); - - MUST_PASS(process.StackFrame); + + if (!process.StackFrame) + { + process.Crash(); + return -kErrorProcessFault; + } if (process.Image) { @@ -291,6 +293,11 @@ namespace Kernel UserProcessScheduler& UserProcessScheduler::The() { + if (!cProcessScheduler) + { + cProcessScheduler = new UserProcessScheduler(); + } + MUST_PASS(cProcessScheduler); return *cProcessScheduler; } @@ -414,14 +421,6 @@ namespace Kernel SizeT UserProcessHelper::StartScheduling() { - if (!cProcessScheduler) - { - cProcessScheduler = new UserProcessScheduler(); - MUST_PASS(cProcessScheduler); - - kcout << "newoskrnl.exe: Team capacity: " << number(cProcessScheduler->CurrentTeam().AsArray().Capacity()) << endl; - } - SizeT ret = cProcessScheduler->Run(); return ret; } diff --git a/dev/ZKA/amd64-efi.make b/dev/ZKA/amd64-efi.make index 02224e93..0e8cbad4 100644 --- a/dev/ZKA/amd64-efi.make +++ b/dev/ZKA/amd64-efi.make @@ -35,10 +35,10 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is __ImageStart -LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 +LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000 LDOBJ = Objects/*.obj -# This file is the Kernel, responsible of task management and memory. +# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. KERNEL = newoskrnl.exe .PHONY: error -- cgit v1.2.3 From 8b1114ea205ef6560fb7bf5713577d1ab7deb5be Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Sep 2024 17:29:07 +0200 Subject: [ MR ] BUMP commit. Signed-off-by: Amlal El Mahrouss --- dev/ZBA/amd64-efi.make | 4 +- dev/ZKA/ArchKit/ArchKit.hxx | 2 +- dev/ZKA/FSKit/IndexableProperty.hxx | 2 +- dev/ZKA/FSKit/NewFS.hxx | 2 +- dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx | 8 +- dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx | 16 +- dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm | 18 +- dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 18 +- dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 48 ++- dev/ZKA/HALKit/AMD64/Processor.hxx | 20 +- dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 10 +- dev/ZKA/KernelKit/CodeManager.hxx | 31 -- dev/ZKA/KernelKit/CodeMgr.hxx | 31 ++ dev/ZKA/KernelKit/DLLInterface.hxx | 11 +- dev/ZKA/KernelKit/DebugOutput.hxx | 2 +- dev/ZKA/KernelKit/DeviceManager.hxx | 130 -------- dev/ZKA/KernelKit/DeviceMgr.hxx | 132 ++++++++ dev/ZKA/KernelKit/DriveManager.hxx | 151 --------- dev/ZKA/KernelKit/DriveMgr.hxx | 151 +++++++++ dev/ZKA/KernelKit/FileManager.hxx | 420 ------------------------- dev/ZKA/KernelKit/FileMgr.hxx | 420 +++++++++++++++++++++++++ dev/ZKA/KernelKit/MP.hxx | 2 +- dev/ZKA/KernelKit/PCI/Dma.hxx | 2 +- dev/ZKA/KernelKit/PECodeManager.hxx | 24 -- dev/ZKA/KernelKit/PECodeMgr.hxx | 24 ++ dev/ZKA/KernelKit/PEFCodeManager.hxx | 67 ---- dev/ZKA/KernelKit/PEFCodeMgr.hxx | 67 ++++ dev/ZKA/KernelKit/PEFDLLInterface.hxx | 4 +- dev/ZKA/KernelKit/UserProcessScheduler.hxx | 5 +- dev/ZKA/NetworkKit/NetworkDevice.hxx | 2 +- dev/ZKA/NewKit/PageAllocator.hxx | 2 +- dev/ZKA/NewKit/PageManager.hxx | 79 ----- dev/ZKA/NewKit/PageMgr.hxx | 79 +++++ dev/ZKA/NewKit/Pmm.hxx | 8 +- dev/ZKA/Sources/CodeManager.cxx | 32 -- dev/ZKA/Sources/CodeMgr.cxx | 32 ++ dev/ZKA/Sources/DLLMain.cxx | 22 +- dev/ZKA/Sources/DeviceManager.cxx | 7 - dev/ZKA/Sources/DeviceMgr.cxx | 7 + dev/ZKA/Sources/DriveManager.cxx | 146 --------- dev/ZKA/Sources/DriveMgr.cxx | 146 +++++++++ dev/ZKA/Sources/FileManager.cxx | 190 ----------- dev/ZKA/Sources/FileMgr.cxx | 190 +++++++++++ dev/ZKA/Sources/Heap.cxx | 73 +++-- dev/ZKA/Sources/MP.cxx | 30 +- dev/ZKA/Sources/NewFS+FileManager.cxx | 109 ------- dev/ZKA/Sources/NewFS+FileMgr.cxx | 109 +++++++ dev/ZKA/Sources/NewFS+IO.cxx | 4 +- dev/ZKA/Sources/NewFS+Journal.cxx | 2 +- dev/ZKA/Sources/PEFCodeManager.cxx | 252 --------------- dev/ZKA/Sources/PEFCodeMgr.cxx | 252 +++++++++++++++ dev/ZKA/Sources/PageManager.cxx | 111 ------- dev/ZKA/Sources/PageMgr.cxx | 111 +++++++ dev/ZKA/Sources/Pmm.cxx | 14 +- dev/ZKA/Sources/Storage/ATADeviceInterface.cxx | 4 +- dev/ZKA/Sources/User.cxx | 2 +- dev/ZKA/Sources/UserProcessScheduler.cxx | 2 +- dev/ZKA/StorageKit/AHCI.hxx | 4 +- dev/ZKA/StorageKit/ATA.hxx | 4 +- dev/ZKA/StorageKit/NVME.hxx | 4 +- dev/ZKA/amd64-efi.make | 2 +- 61 files changed, 1932 insertions(+), 1921 deletions(-) delete mode 100644 dev/ZKA/KernelKit/CodeManager.hxx create mode 100644 dev/ZKA/KernelKit/CodeMgr.hxx delete mode 100644 dev/ZKA/KernelKit/DeviceManager.hxx create mode 100644 dev/ZKA/KernelKit/DeviceMgr.hxx delete mode 100644 dev/ZKA/KernelKit/DriveManager.hxx create mode 100644 dev/ZKA/KernelKit/DriveMgr.hxx delete mode 100644 dev/ZKA/KernelKit/FileManager.hxx create mode 100644 dev/ZKA/KernelKit/FileMgr.hxx delete mode 100644 dev/ZKA/KernelKit/PECodeManager.hxx create mode 100644 dev/ZKA/KernelKit/PECodeMgr.hxx delete mode 100644 dev/ZKA/KernelKit/PEFCodeManager.hxx create mode 100644 dev/ZKA/KernelKit/PEFCodeMgr.hxx delete mode 100644 dev/ZKA/NewKit/PageManager.hxx create mode 100644 dev/ZKA/NewKit/PageMgr.hxx delete mode 100644 dev/ZKA/Sources/CodeManager.cxx create mode 100644 dev/ZKA/Sources/CodeMgr.cxx delete mode 100644 dev/ZKA/Sources/DeviceManager.cxx create mode 100644 dev/ZKA/Sources/DeviceMgr.cxx delete mode 100644 dev/ZKA/Sources/DriveManager.cxx create mode 100644 dev/ZKA/Sources/DriveMgr.cxx delete mode 100644 dev/ZKA/Sources/FileManager.cxx create mode 100644 dev/ZKA/Sources/FileMgr.cxx delete mode 100644 dev/ZKA/Sources/NewFS+FileManager.cxx create mode 100644 dev/ZKA/Sources/NewFS+FileMgr.cxx delete mode 100644 dev/ZKA/Sources/PEFCodeManager.cxx create mode 100644 dev/ZKA/Sources/PEFCodeMgr.cxx delete mode 100644 dev/ZKA/Sources/PageManager.cxx create mode 100644 dev/ZKA/Sources/PageMgr.cxx (limited to 'dev') diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 55ce3f1c..497dc8e9 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -29,14 +29,14 @@ IMG=epm-master-1.img IMG_2=epm-slave.img IMG_3=epm-master-2.img -EMU_FLAGS=-net none -m 8G -M q35 -cpu qemu64 \ +EMU_FLAGS=-net none -m 12G -M q35 \ -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -d int -no-reboot -no-shutdown + -device ide-hd,drive=disk_2,bus=ahci.0 -d int LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/ArchKit/ArchKit.hxx b/dev/ZKA/ArchKit/ArchKit.hxx index 60a2b2ec..fc2d7d33 100644 --- a/dev/ZKA/ArchKit/ArchKit.hxx +++ b/dev/ZKA/ArchKit/ArchKit.hxx @@ -109,4 +109,4 @@ inline Kernel::Array #include -#include +#include #define kIndexerNodeNameLength 255 #define kIndexerClaimed 0xCF diff --git a/dev/ZKA/FSKit/NewFS.hxx b/dev/ZKA/FSKit/NewFS.hxx index c5ada14b..4587b70f 100644 --- a/dev/ZKA/FSKit/NewFS.hxx +++ b/dev/ZKA/FSKit/NewFS.hxx @@ -18,7 +18,7 @@ default. #include #include -#include +#include #include /** diff --git a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx index 677b1219..7bafd075 100644 --- a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx @@ -49,10 +49,10 @@ namespace Kernel if (user) mm_update_pte(base_ptr, eFlagsUser); - return (VoidPtr)(ptr_bit_set + 2); + return (VoidPtr)(&ptr_bit_set[2]); } - base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + size); + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + 1 + ptr_bit_set[1]); } return nullptr; @@ -71,7 +71,7 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); - return ptr_new; + return &((UIntPtr*)ptr_new)[1]; } auto mm_free_bitmap(VoidPtr page_ptr) -> Bool @@ -79,7 +79,7 @@ namespace Kernel if (!page_ptr) return false; - UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 2; + UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 3; if (!ptr_bit_set[0] || ptr_bit_set[0] != cVMHMagic) diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx index 19d62965..54b62b80 100644 --- a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx +++ b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx @@ -15,12 +15,15 @@ namespace Kernel::HAL STATIC Void hal_remap_intel_pic_ctrl(Void) noexcept { - // Remap PIC. + auto a1 = HAL::In8(0xa1); // save masks + auto a2 = HAL::In8(0xa2); + HAL::Out8(0x20, 0x11); + HAL::Out8(0xA0, 0x11); - HAL::Out8(0x21, 40); - HAL::Out8(0xA1, 32); + HAL::Out8(0x21, 32); + HAL::Out8(0xA1, 40); HAL::Out8(0x21, 4); HAL::Out8(0xA1, 2); @@ -28,8 +31,8 @@ namespace Kernel::HAL HAL::Out8(0x21, 0x01); HAL::Out8(0xA1, 0x01); - HAL::Out8(0x21, 0xFD); - HAL::Out8(0xA1, 0xFF); + HAL::Out8(0x21, a2); + HAL::Out8(0xA1, a1); } } // namespace Detail @@ -73,7 +76,8 @@ namespace Kernel::HAL hal_load_idt(idt); - Detail::hal_remap_intel_pic_ctrl(); + HAL::Out8(0xA1, 0xFF); + HAL::Out8(0x21, 0xFF); } void GDTLoader::Load(Ref& gdt) diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm index d59cc197..6abd28c9 100644 --- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm @@ -141,12 +141,7 @@ IntNormal 38 IntNormal 39 IntNormal 40 -extern mp_system_call_handler - -__ZKA_INT_41: - cmp rcx, 0 - jne mp_system_call_handler - iretq +IntNormal 41 IntNormal 42 IntNormal 43 @@ -222,17 +217,18 @@ section .text hal_load_gdt: lgdt [rcx] - push 0x08 - lea rax, [rel rt_reload_segments] - push rax + cli + push 8 + push hal_reload_segments o64 retf -rt_reload_segments: - mov ax, 0x10 +hal_reload_segments: + mov ax, 16 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax + sti ret global hal_load_idt diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 33c3f689..10916b06 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -64,14 +64,14 @@ EXTERN_C void hal_user_code_start(void); EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void); /* GDT, mostly descriptors for user and kernel segments. */ -STATIC Kernel::HAL::Detail::ZKA_GDT_ENTRY cGdt[6] = { +STATIC Kernel::HAL::Detail::ZKA_GDT_ENTRY ALIGN(0x1000) cGdt[6] = { {.fLimitLow = 0, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x00, .fFlags = 0x00, .fBaseHigh = 0}, // Null entry {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x9A, .fFlags = 0xA0, .fBaseHigh = 0}, // Kernel code {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x92, .fFlags = 0xA0, .fBaseHigh = 0}, // Kernel data - {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xFA, .fFlags = 0xA0, .fBaseHigh = 0}, // User code - {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xF2, .fFlags = 0xA0, .fBaseHigh = 0}, // User data - // reserve them for later. {.fLimitLow = 0, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x00, .fFlags = 0x00, .fBaseHigh = 0}, + {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x9A, .fFlags = 0xA0, .fBaseHigh = 0}, // User code + {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x92, .fFlags = 0xA0, .fBaseHigh = 0}, // User data + // reserve them for later. }; EXTERN_C void hal_init_platform( @@ -127,11 +127,11 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemManager(); + auto fs = new Kernel::NewFilesystemMgr(); MUST_PASS(fs); - Kernel::NewFilesystemManager::Mount(fs); + Kernel::NewFilesystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index 39a80922..1f31c880 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -21,23 +21,42 @@ section .text ;; rcx: code ptr. ;; rdx: stack ptr. mp_do_context_switch: - mov rsp, rdx - mov rbp, rsp + swapgs + + mov fs, rcx + mov gs, rdx mov r9, [r8 + (8 * 2)] mov r10, [r8 + (8 * 3)] - mov fs, [r8 + (8 * 4)] + mov r12, [r8 + (8 * 5)] mov r13, [r8 + (8 * 6)] mov r14, [r8 + (8 * 7)] mov r15, [r8 + (8 * 8)] - mov gs, [r8 + (8 * 9)] - mov r8, [r8] + mov r11, gs + mov r12, fs - mov rax, rcx + ; Enable SCE that enables sysret and syscall + mov rcx, 0xc0000082 + wrmsr + mov rcx, 0xc0000080 + rdmsr + or eax, 1 + wrmsr + mov rcx, 0xc0000081 + rdmsr + mov edx, 0x00180008 + wrmsr mov r11, 0x202 + mov fs, [r8 + (8 * 4)] + mov gs, [r8 + (8 * 9)] + mov r8, [r8] + + swapgs + sti + o64 sysret ;; @brief Gets the current stack frame. @@ -67,15 +86,14 @@ mp_system_call_handler: o64 sysret mp_do_context_switch_pre: - mov rcx, 0xc0000082 - wrmsr - mov rcx, 0xc0000080 - rdmsr - or eax, 1 - wrmsr - mov rcx, 0xc0000081 - rdmsr - mov edx, 0x00180008 + xor rdx, rdx + mov rax, 0x202 + mov rcx, 0xc0000084 wrmsr + mov rdx, mp_system_call_handler + shr rdx, 32 + mov rcx, 0xc0000082 + wrmsr + ret diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index b7fa080c..0636c291 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -99,17 +99,17 @@ namespace Kernel::HAL using InterruptId = UInt16; /* For each element in the IVT */ /// @brief Stack frame (as retrieved from assembly.) - struct StackFrame final + struct PACKED StackFrame final { - UIntPtr R8{0}; - UIntPtr R9{0}; - UIntPtr R10{0}; - UIntPtr FS{0}; - UIntPtr R12{0}; - UIntPtr R13{0}; - UIntPtr R14{0}; - UIntPtr R15{0}; - UIntPtr GS{0}; + RawRegister R8{0}; + RawRegister R9{0}; + RawRegister R10{0}; + RawRegister FS{0}; + RawRegister R12{0}; + RawRegister R13{0}; + RawRegister R14{0}; + RawRegister R15{0}; + RawRegister GS{0}; }; typedef StackFrame* StackFramePtr; diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index d51f0421..ee06c305 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -94,12 +94,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemManager(); + auto fs = new Kernel::NewFilesystemMgr(); MUST_PASS(fs); MUST_PASS(fs->GetParser()); - Kernel::NewFilesystemManager::Mount(fs); + Kernel::NewFilesystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/KernelKit/CodeManager.hxx b/dev/ZKA/KernelKit/CodeManager.hxx deleted file mode 100644 index ef9d18f4..00000000 --- a/dev/ZKA/KernelKit/CodeManager.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: CodeManager.hpp - Purpose: Code Manager and Shared Objects. - - Revision History: - - 30/01/24: Added file (amlel) - 3/8/24: Add UPP struct. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel -{ - /// @brief Main process entrypoint. - typedef void (*MainKind)(void); - - /// @brief Executes a new process from a function. Kernel code only. - /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. - /// @param main the start of the process. - /// @return if the process was started or not. - bool sched_execute_thread(MainKind main, const Char* process_name) noexcept; -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/CodeMgr.hxx b/dev/ZKA/KernelKit/CodeMgr.hxx new file mode 100644 index 00000000..8c4f090f --- /dev/null +++ b/dev/ZKA/KernelKit/CodeMgr.hxx @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: CodeMgr.hpp + Purpose: Code Mgr and Shared Objects. + + Revision History: + + 30/01/24: Added file (amlel) + 3/8/24: Add UPP struct. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel +{ + /// @brief Main process entrypoint. + typedef void (*MainKind)(void); + + /// @brief Executes a new process from a function. Kernel code only. + /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. + /// @param main the start of the process. + /// @return if the process was started or not. + bool sched_execute_thread(MainKind main, const Char* process_name) noexcept; +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DLLInterface.hxx b/dev/ZKA/KernelKit/DLLInterface.hxx index 370363b7..13f36b82 100644 --- a/dev/ZKA/KernelKit/DLLInterface.hxx +++ b/dev/ZKA/KernelKit/DLLInterface.hxx @@ -35,8 +35,15 @@ namespace Kernel virtual DLL_TRAITS** GetAddressOf() = 0; virtual DLL_TRAITS* Get() = 0; - virtual void Mount(DLL_TRAITS* to_mount) = 0; - virtual void Unmount() = 0; + virtual Void Mount(DLL_TRAITS* to_mount) = 0; + virtual Void Unmount() = 0; + + + template + SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) + { + return nullptr; + } }; /// @brief Pure implementation, missing method/function handler. diff --git a/dev/ZKA/KernelKit/DebugOutput.hxx b/dev/ZKA/KernelKit/DebugOutput.hxx index fcf18bff..66105aa1 100644 --- a/dev/ZKA/KernelKit/DebugOutput.hxx +++ b/dev/ZKA/KernelKit/DebugOutput.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include diff --git a/dev/ZKA/KernelKit/DeviceManager.hxx b/dev/ZKA/KernelKit/DeviceManager.hxx deleted file mode 100644 index 5164ae28..00000000 --- a/dev/ZKA/KernelKit/DeviceManager.hxx +++ /dev/null @@ -1,130 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -/* ------------------------------------------- - - Revision History: - - 31/01/24: Add kDeviceCnt (amlel) - - ------------------------------------------- */ - -#pragma once - -/* Kernel device interface manager. */ -/* @file KernelKit/DeviceManager.hpp */ -/* @brief Device abstraction and I/O buffer. */ - -#include -#include - -// Last Rev -// Wed, Apr 3, 2024 9:09:41 AM - -namespace Kernel -{ - template - class DeviceInterface; - - template - class DeviceInterface - { - public: - explicit DeviceInterface(void (*Out)(T), void (*In)(T)) - : fOut(Out), fIn(In) - { - } - - virtual ~DeviceInterface() = default; - - public: - DeviceInterface& operator=(const DeviceInterface&) = default; - DeviceInterface(const DeviceInterface&) = default; - - public: - virtual DeviceInterface& operator<<(T Data) - { - fOut(Data); - return *this; - } - - virtual DeviceInterface& operator>>(T Data) - { - fIn(Data); - return *this; - } - - virtual const char* Name() const - { - return "DeviceInterface"; - } - - operator bool() - { - return fOut && fIn; - } - - Bool operator!() - { - return !fOut || !fIn; - } - - private: - Void (*fOut)(T Data) = {nullptr}; - Void (*fIn)(T Data) = {nullptr}; - }; - - /// - /// @brief Input Output Buffer - /// Used mainly to communicate between hardware. - /// - template - class IOBuf final - { - public: - explicit IOBuf(T Dat) - : fData(Dat) - { - // at least pass something valid when instancating this struct. - MUST_PASS(Dat); - } - - IOBuf& operator=(const IOBuf&) = default; - IOBuf(const IOBuf&) = default; - - ~IOBuf() = default; - - public: - template - R operator->() const - { - return fData; - } - - template - R& operator[](Size index) const - { - return fData[index]; - } - - private: - T fData; - }; - - ///! @brief Device enum types. - enum - { - kDeviceTypeIDE, - kDeviceTypeEthernet, - kDeviceTypeWiFi, - kDeviceTypeRS232, - kDeviceTypeSCSI, - kDeviceTypeSHCI, - kDeviceTypeUSB, - kDeviceTypeMedia, - kDeviceTypeCount, - }; -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DeviceMgr.hxx b/dev/ZKA/KernelKit/DeviceMgr.hxx new file mode 100644 index 00000000..473af601 --- /dev/null +++ b/dev/ZKA/KernelKit/DeviceMgr.hxx @@ -0,0 +1,132 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* Device manager. */ +/* @file KernelKit/DeviceMgr.hpp */ +/* @brief Device abstraction and I/O buffer. */ + +#include +#include + +#define cDevicePath "\\Mount\\" + +// Last Rev +// Wed, Apr 3, 2024 9:09:41 AM + +namespace Kernel +{ + template + class DeviceInterface; + + template + class DeviceInterface + { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : fOut(Out), fIn(In) + { + } + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; + + public: + virtual DeviceInterface& operator<<(T Data) + { + fOut(Data); + return *this; + } + + virtual DeviceInterface& operator>>(T Data) + { + fIn(Data); + return *this; + } + + virtual const char* Name() const + { + return "DeviceInterface"; + } + + operator bool() + { + return fOut && fIn; + } + + Bool operator!() + { + return !fOut || !fIn; + } + + private: + Void (*fOut)(T Data) = {nullptr}; + Void (*fIn)(T Data) = {nullptr}; + }; + + /// + /// @brief Input Output Buffer + /// Used mainly to communicate between hardware. + /// + template + class IOBuf final + { + public: + explicit IOBuf(T Dat) + : fData(Dat) + { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } + + IOBuf& operator=(const IOBuf&) = default; + IOBuf(const IOBuf&) = default; + + ~IOBuf() = default; + + public: + template + R operator->() const + { + return fData; + } + + template + R& operator[](Size index) const + { + return fData[index]; + } + + private: + T fData; + }; + + ///! @brief Device enum types. + enum + { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeMedia, + kDeviceTypeCount, + }; +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DriveManager.hxx b/dev/ZKA/KernelKit/DriveManager.hxx deleted file mode 100644 index 96fbd95d..00000000 --- a/dev/ZKA/KernelKit/DriveManager.hxx +++ /dev/null @@ -1,151 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef __INC_DRIVE_MANAGER_HXX__ -#define __INC_DRIVE_MANAGER_HXX__ - -#include -#include -#include -#include -#include -#include -#include - -#define kDriveManagerCount (4U) - -#define kDriveInvalidID (-1) -#define kDriveNameLen (32) - -#define drv_get_sector_count(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) - -namespace Kernel -{ - enum - { - kInvalidDrive = -1, - kBlockDevice = 0xAD, - kMassStorage = 0xDA, - kFloppyDisc = 0xCD, - kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray - /// combine with below. - kReadOnly = 0x10, // Read only drive - kEPMDrive = 0x11, // Explicit Partition Map. - kEPTDrive = 0x12, // ESP w/ EPM partition. - kMBRDrive = 0x13, // IBM PC classic partition scheme - kDriveCnt = 9, - }; - - typedef Int64 rt_drive_id_type; - - /// @brief Media drive trait type. - struct DriveTrait final - { - Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... - Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. - rt_drive_id_type fId; // Drive id. - Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive - - /// @brief Packet drive (StorageKit compilant.) - struct DrivePacket final - { - VoidPtr fPacketContent; //! packet body. - Char fPacketMime[kDriveNameLen]; //! identify what we're sending. - SizeT fPacketSize; //! packet size - UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false - Boolean fPacketGood; - Lba fLba; - } fPacket; - - Void (*fInput)(DrivePacket* packetPtr); - Void (*fOutput)(DrivePacket* packetPtr); - Void (*fVerify)(DrivePacket* packetPtr); - const Char* (*fDriveKind)(Void); - }; - - ///! drive as a device. - typedef DriveTrait* DriveTraitPtr; - - /** - * @brief Mounted drives interface. - * @note This class has all of it's drive set to nullptr, allocate them using - * GetAddressOf(index). - */ - class MountpointInterface final - { - public: - explicit MountpointInterface() = default; - ~MountpointInterface() = default; - - ZKA_COPY_DEFAULT(MountpointInterface); - - public: - DriveTrait& A() - { - return mA; - } - DriveTrait& B() - { - return mB; - } - DriveTrait& C() - { - return mC; - } - DriveTrait& D() - { - return mD; - } - - DriveTraitPtr GetAddressOf(Int32 index) - { - ErrLocal() = kErrorSuccess; - - switch (index) - { - case 0: - return &mA; - case 1: - return &mB; - case 2: - return &mC; - case 3: - return &mD; - default: { - ErrLocal() = kErrorNoSuchDisk; - kcout << "newoskrnl.exe: No such disk.\n"; - - break; - } - } - - return nullptr; - } - - private: - DriveTrait mA, mB, mC, mD; - }; - - /// @brief Unimplemented drive. - /// @param pckt - /// @return - Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt); - - /// @brief Gets the drive kind (ATA, SCSI, AHCI...) - /// @param - /// @return the drive kind (ATA, Flash, NVM) - const Char* io_drive_kind(Void); - - /// @brief Makes a new drive. - /// @return the new drive as a trait. - DriveTrait io_construct_drive(void) noexcept; - - /// @brief Fetches the main drive. - /// @return the new drive as a trait. - DriveTrait io_construct_main_drive(void) noexcept; -} // namespace Kernel - -#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */ diff --git a/dev/ZKA/KernelKit/DriveMgr.hxx b/dev/ZKA/KernelKit/DriveMgr.hxx new file mode 100644 index 00000000..4b2cdc73 --- /dev/null +++ b/dev/ZKA/KernelKit/DriveMgr.hxx @@ -0,0 +1,151 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __INC_DRIVE_MANAGER_HXX__ +#define __INC_DRIVE_MANAGER_HXX__ + +#include +#include +#include +#include +#include +#include +#include + +#define kDriveMgrCount (4U) + +#define kDriveInvalidID (-1) +#define kDriveNameLen (32) + +#define drv_get_sector_count(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) + +namespace Kernel +{ + enum + { + kInvalidDrive = -1, + kBlockDevice = 0xAD, + kMassStorage = 0xDA, + kFloppyDisc = 0xCD, + kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray + /// combine with below. + kReadOnly = 0x10, // Read only drive + kEPMDrive = 0x11, // Explicit Partition Map. + kEPTDrive = 0x12, // ESP w/ EPM partition. + kMBRDrive = 0x13, // IBM PC classic partition scheme + kDriveCnt = 9, + }; + + typedef Int64 rt_drive_id_type; + + /// @brief Media drive trait type. + struct DriveTrait final + { + Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... + Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. + rt_drive_id_type fId; // Drive id. + Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive + + /// @brief Packet drive (StorageKit compilant.) + struct DrivePacket final + { + VoidPtr fPacketContent; //! packet body. + Char fPacketMime[kDriveNameLen]; //! identify what we're sending. + SizeT fPacketSize; //! packet size + UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false + Boolean fPacketGood; + Lba fLba; + } fPacket; + + Void (*fInput)(DrivePacket* packetPtr); + Void (*fOutput)(DrivePacket* packetPtr); + Void (*fVerify)(DrivePacket* packetPtr); + const Char* (*fDriveKind)(Void); + }; + + ///! drive as a device. + typedef DriveTrait* DriveTraitPtr; + + /** + * @brief Mounted drives interface. + * @note This class has all of it's drive set to nullptr, allocate them using + * GetAddressOf(index). + */ + class MountpointInterface final + { + public: + explicit MountpointInterface() = default; + ~MountpointInterface() = default; + + ZKA_COPY_DEFAULT(MountpointInterface); + + public: + DriveTrait& A() + { + return mA; + } + DriveTrait& B() + { + return mB; + } + DriveTrait& C() + { + return mC; + } + DriveTrait& D() + { + return mD; + } + + DriveTraitPtr GetAddressOf(Int32 index) + { + ErrLocal() = kErrorSuccess; + + switch (index) + { + case 0: + return &mA; + case 1: + return &mB; + case 2: + return &mC; + case 3: + return &mD; + default: { + ErrLocal() = kErrorNoSuchDisk; + kcout << "newoskrnl.exe: No such disk.\n"; + + break; + } + } + + return nullptr; + } + + private: + DriveTrait mA, mB, mC, mD; + }; + + /// @brief Unimplemented drive. + /// @param pckt + /// @return + Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt); + + /// @brief Gets the drive kind (ATA, SCSI, AHCI...) + /// @param + /// @return the drive kind (ATA, Flash, NVM) + const Char* io_drive_kind(Void); + + /// @brief Makes a new drive. + /// @return the new drive as a trait. + DriveTrait io_construct_drive(void) noexcept; + + /// @brief Fetches the main drive. + /// @return the new drive as a trait. + DriveTrait io_construct_main_drive(void) noexcept; +} // namespace Kernel + +#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */ diff --git a/dev/ZKA/KernelKit/FileManager.hxx b/dev/ZKA/KernelKit/FileManager.hxx deleted file mode 100644 index 05f74a63..00000000 --- a/dev/ZKA/KernelKit/FileManager.hxx +++ /dev/null @@ -1,420 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: FileManager.hxx - Purpose: Kernel file manager. - -------------------------------------------- */ - -/* ------------------------------------------- - - Revision History: - - 31/01/24: Update documentation (amlel) - 05/07/24: NewFS support, and fork support, updated constants and specs - as well. - - ------------------------------------------- */ - -#pragma once - -#ifdef __FSKIT_USE_NEWFS__ -#include -#endif // __FSKIT_USE_NEWFS__ - -#include -#include -#include -#include -#include -#include -#include -#include - -/// @brief Filesystem manager, abstraction over mounted filesystem. -/// Works like the VFS or IFS. - -#define cRestrictR "r" -#define cRestrictRB "rb" -#define cRestrictW "w" -#define cRestrictWB "rw" -#define cRestrictRWB "rwb" - -#define cRestrictMax 5 - -#define node_cast(PTR) reinterpret_cast(PTR) - -/** - @note Refer to first enum. -*/ -#define cFileOpsCount 4 -#define cFileMimeGeneric "n-application-kind/all" - -/** @brief invalid position. (n-pos) */ -#define kNPos (SizeT)(-1); - -namespace Kernel -{ - enum - { - cFileWriteAll = 100, - cFileReadAll = 101, - cFileReadChunk = 102, - cFileWriteChunk = 103, - cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1, - // file flags - cFileFlagRsrc = 104, - cFileFlagData = 105, - }; - - typedef VoidPtr NodePtr; - - /** - @brief Filesystem Manager Interface class - @brief Used to provide common I/O for a specific filesystem. -*/ - class FilesystemManagerInterface - { - public: - explicit FilesystemManagerInterface() = default; - virtual ~FilesystemManagerInterface() = default; - - public: - ZKA_COPY_DEFAULT(FilesystemManagerInterface); - - public: - /// @brief Mounts a new filesystem into an active state. - /// @param interface the filesystem interface - /// @return - static bool Mount(FilesystemManagerInterface* interface); - - /// @brief Unmounts the active filesystem - /// @return - static FilesystemManagerInterface* Unmount(); - - /// @brief Getter, gets the active filesystem. - /// @return - static FilesystemManagerInterface* GetMounted(); - - public: - virtual NodePtr Create(_Input const Char* path) = 0; - virtual NodePtr CreateAlias(_Input const Char* path) = 0; - virtual NodePtr CreateDirectory(_Input const Char* path) = 0; - virtual NodePtr CreateSwapFile(const Char* path) = 0; - - public: - virtual bool Remove(_Input const Char* path) = 0; - - public: - virtual NodePtr Open(_Input const Char* path, _Input const Char* r) = 0; - - public: - virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; - - virtual _Output VoidPtr Read(_Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) = 0; - - virtual Void Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) = 0; - - virtual _Output VoidPtr Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) = 0; - - public: - virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; - - public: - virtual SizeT Tell(_Input NodePtr node) = 0; - virtual bool Rewind(_Input NodePtr node) = 0; - }; - -#ifdef __FSKIT_USE_NEWFS__ - /** - * @brief Based of FilesystemManagerInterface, takes care of managing NewFS - * disks. - */ - class NewFilesystemManager final : public FilesystemManagerInterface - { - public: - explicit NewFilesystemManager(); - ~NewFilesystemManager() override; - - public: - ZKA_COPY_DEFAULT(NewFilesystemManager); - - public: - NodePtr Create(const Char* path) override; - NodePtr CreateAlias(const Char* path) override; - NodePtr CreateDirectory(const Char* path) override; - NodePtr CreateSwapFile(const Char* path) override; - - public: - bool Remove(const Char* path) override; - NodePtr Open(const Char* path, const Char* r) override; - Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; - VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; - bool Seek(NodePtr node, SizeT off) override; - SizeT Tell(NodePtr node) override; - bool Rewind(NodePtr node) override; - - Void Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) override; - - _Output VoidPtr Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) override; - - public: - /// @brief Get NewFS parser class. - /// @return The filesystem parser class. - NewFSParser* GetParser() noexcept; - - private: - NewFSParser* fImpl{nullptr}; - }; - -#endif // ifdef __FSKIT_USE_NEWFS__ - - /** - * Usable FileStream - * @tparam Encoding file encoding (char, wchar_t...) - * @tparam FSClass Filesystem contract who takes care of it. - */ - template - class FileStream final - { - public: - explicit FileStream(const Encoding* path, const Encoding* restrict_type); - ~FileStream(); - - public: - FileStream& operator=(const FileStream&); - FileStream(const FileStream&); - - public: - ErrorOr WriteAll(const VoidPtr data) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return ErrorOr(kErrorInvalidData); - - if (data == nullptr) - return ErrorOr(kErrorInvalidData); - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Write(fFile, data, cFileWriteAll); - return ErrorOr(0); - } - - return ErrorOr(kErrorInvalidData); - } - - VoidPtr ReadAll() noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - VoidPtr ret = man->Read(fFile, cFileReadAll, 0); - return ret; - } - - return nullptr; - } - - ErrorOr WriteAll(const Char* fName, const VoidPtr data) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return ErrorOr(kErrorInvalidData); - - if (data == nullptr) - return ErrorOr(kErrorInvalidData); - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Write(fName, fFile, data, cFileWriteAll); - return ErrorOr(0); - } - - return ErrorOr(kErrorInvalidData); - } - - VoidPtr Read(const Char* fName) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0); - return ret; - } - - return nullptr; - } - - VoidPtr Read(SizeT offset, SizeT sz) - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Seek(fFile, offset); - auto ret = man->Read(fFile, cFileReadChunk, sz); - - return ret; - } - - return nullptr; - } - - Void Write(SizeT offset, voidPtr data, SizeT sz) - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return; - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Seek(fFile, offset); - man->Write(fFile, data, sz, cFileReadChunk); - } - } - - public: - /// @brief Leak node pointer. - /// @return The node pointer. - NodePtr Leak() - { - return fFile; - } - - /// @brief Leak MIME. - /// @return The MIME. - Char* MIME() noexcept - { - return const_cast(fMime); - } - - enum - { - eRestrictRead, - eRestrictReadBinary, - eRestrictWrite, - eRestrictWriteBinary, - eRestrictReadWrite, - eRestrictReadWriteBinary, - }; - - private: - NodePtr fFile{nullptr}; - Int32 fFileRestrict{}; - const Char* fMime{cFileMimeGeneric}; - }; - - using FileStreamUTF8 = FileStream; - using FileStreamUTF16 = FileStream; - - typedef UInt64 CursorType; - - /// @brief constructor - template - FileStream::FileStream(const Encoding* path, - const Encoding* restrict_type) - : fFile(Class::GetMounted()->Open(path, restrict_type)) - { - static const auto cLength = 255; - - /// @brief restrict information about the file descriptor. - struct RESTRICT_MAP final - { - Char fRestrict[cLength]; - Int32 fMappedTo; - }; - - const SizeT cRestrictCount = cRestrictMax; - const RESTRICT_MAP cRestrictList[] = { - { - .fRestrict = cRestrictR, - .fMappedTo = eRestrictRead, - }, - { - .fRestrict = cRestrictRB, - .fMappedTo = eRestrictReadBinary, - }, - { - .fRestrict = cRestrictRWB, - .fMappedTo = eRestrictReadWriteBinary, - }, - { - .fRestrict = cRestrictW, - .fMappedTo = eRestrictWrite, - }, - { - .fRestrict = cRestrictWB, - .fMappedTo = eRestrictReadWrite, - }}; - - for (SizeT index = 0; index < cRestrictCount; ++index) - { - if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict, - rt_string_len(cRestrictList[index].fRestrict)) == 0) - { - fFileRestrict = cRestrictList[index].fMappedTo; - break; - } - } - - kcout << "newoskrnl.exe: new file: " << path << ".\r"; - } - - /// @brief destructor - template - FileStream::~FileStream() - { - mm_delete_ke_heap(fFile); - } -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx new file mode 100644 index 00000000..7a97f821 --- /dev/null +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -0,0 +1,420 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: FileMgr.hxx + Purpose: Kernel file manager. + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Update documentation (amlel) + 05/07/24: NewFS support, and fork support, updated constants and specs + as well. + + ------------------------------------------- */ + +#pragma once + +#ifdef __FSKIT_USE_NEWFS__ +#include +#endif // __FSKIT_USE_NEWFS__ + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @brief Filesystem manager, abstraction over mounted filesystem. +/// Works like the VFS or IFS. + +#define cRestrictR "r" +#define cRestrictRB "rb" +#define cRestrictW "w" +#define cRestrictWB "rw" +#define cRestrictRWB "rwb" + +#define cRestrictMax 5 + +#define node_cast(PTR) reinterpret_cast(PTR) + +/** + @note Refer to first enum. +*/ +#define cFileOpsCount 4 +#define cFileMimeGeneric "n-application-kind/all" + +/** @brief invalid position. (n-pos) */ +#define kNPos (SizeT)(-1); + +namespace Kernel +{ + enum + { + cFileWriteAll = 100, + cFileReadAll = 101, + cFileReadChunk = 102, + cFileWriteChunk = 103, + cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1, + // file flags + cFileFlagRsrc = 104, + cFileFlagData = 105, + }; + + typedef VoidPtr NodePtr; + + /** + @brief Filesystem Mgr Interface class + @brief Used to provide common I/O for a specific filesystem. +*/ + class FilesystemMgrInterface + { + public: + explicit FilesystemMgrInterface() = default; + virtual ~FilesystemMgrInterface() = default; + + public: + ZKA_COPY_DEFAULT(FilesystemMgrInterface); + + public: + /// @brief Mounts a new filesystem into an active state. + /// @param interface the filesystem interface + /// @return + static bool Mount(FilesystemMgrInterface* interface); + + /// @brief Unmounts the active filesystem + /// @return + static FilesystemMgrInterface* Unmount(); + + /// @brief Getter, gets the active filesystem. + /// @return + static FilesystemMgrInterface* GetMounted(); + + public: + virtual NodePtr Create(_Input const Char* path) = 0; + virtual NodePtr CreateAlias(_Input const Char* path) = 0; + virtual NodePtr CreateDirectory(_Input const Char* path) = 0; + virtual NodePtr CreateSwapFile(const Char* path) = 0; + + public: + virtual bool Remove(_Input const Char* path) = 0; + + public: + virtual NodePtr Open(_Input const Char* path, _Input const Char* r) = 0; + + public: + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) = 0; + + virtual Void Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) = 0; + + public: + virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; + + public: + virtual SizeT Tell(_Input NodePtr node) = 0; + virtual bool Rewind(_Input NodePtr node) = 0; + }; + +#ifdef __FSKIT_USE_NEWFS__ + /** + * @brief Based of FilesystemMgrInterface, takes care of managing NewFS + * disks. + */ + class NewFilesystemMgr final : public FilesystemMgrInterface + { + public: + explicit NewFilesystemMgr(); + ~NewFilesystemMgr() override; + + public: + ZKA_COPY_DEFAULT(NewFilesystemMgr); + + public: + NodePtr Create(const Char* path) override; + NodePtr CreateAlias(const Char* path) override; + NodePtr CreateDirectory(const Char* path) override; + NodePtr CreateSwapFile(const Char* path) override; + + public: + bool Remove(const Char* path) override; + NodePtr Open(const Char* path, const Char* r) override; + Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; + VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; + bool Seek(NodePtr node, SizeT off) override; + SizeT Tell(NodePtr node) override; + bool Rewind(NodePtr node) override; + + Void Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) override; + + _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) override; + + public: + /// @brief Get NewFS parser class. + /// @return The filesystem parser class. + NewFSParser* GetParser() noexcept; + + private: + NewFSParser* fImpl{nullptr}; + }; + +#endif // ifdef __FSKIT_USE_NEWFS__ + + /** + * Usable FileStream + * @tparam Encoding file encoding (char, wchar_t...) + * @tparam FSClass Filesystem contract who takes care of it. + */ + template + class FileStream final + { + public: + explicit FileStream(const Encoding* path, const Encoding* restrict_type); + ~FileStream(); + + public: + FileStream& operator=(const FileStream&); + FileStream(const FileStream&); + + public: + ErrorOr WriteAll(const VoidPtr data) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr(kErrorInvalidData); + + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fFile, data, cFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr ReadAll() noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fFile, cFileReadAll, 0); + return ret; + } + + return nullptr; + } + + ErrorOr WriteAll(const Char* fName, const VoidPtr data) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr(kErrorInvalidData); + + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fName, fFile, data, cFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr Read(const Char* fName) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0); + return ret; + } + + return nullptr; + } + + VoidPtr Read(SizeT offset, SizeT sz) + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + auto ret = man->Read(fFile, cFileReadChunk, sz); + + return ret; + } + + return nullptr; + } + + Void Write(SizeT offset, voidPtr data, SizeT sz) + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return; + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + man->Write(fFile, data, sz, cFileReadChunk); + } + } + + public: + /// @brief Leak node pointer. + /// @return The node pointer. + NodePtr Leak() + { + return fFile; + } + + /// @brief Leak MIME. + /// @return The MIME. + Char* MIME() noexcept + { + return const_cast(fMime); + } + + enum + { + eRestrictRead, + eRestrictReadBinary, + eRestrictWrite, + eRestrictWriteBinary, + eRestrictReadWrite, + eRestrictReadWriteBinary, + }; + + private: + NodePtr fFile{nullptr}; + Int32 fFileRestrict{}; + const Char* fMime{cFileMimeGeneric}; + }; + + using FileStreamUTF8 = FileStream; + using FileStreamUTF16 = FileStream; + + typedef UInt64 CursorType; + + /// @brief constructor + template + FileStream::FileStream(const Encoding* path, + const Encoding* restrict_type) + : fFile(Class::GetMounted()->Open(path, restrict_type)) + { + static const auto cLength = 255; + + /// @brief restrict information about the file descriptor. + struct RESTRICT_MAP final + { + Char fRestrict[cLength]; + Int32 fMappedTo; + }; + + const SizeT cRestrictCount = cRestrictMax; + const RESTRICT_MAP cRestrictList[] = { + { + .fRestrict = cRestrictR, + .fMappedTo = eRestrictRead, + }, + { + .fRestrict = cRestrictRB, + .fMappedTo = eRestrictReadBinary, + }, + { + .fRestrict = cRestrictRWB, + .fMappedTo = eRestrictReadWriteBinary, + }, + { + .fRestrict = cRestrictW, + .fMappedTo = eRestrictWrite, + }, + { + .fRestrict = cRestrictWB, + .fMappedTo = eRestrictReadWrite, + }}; + + for (SizeT index = 0; index < cRestrictCount; ++index) + { + if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict, + rt_string_len(cRestrictList[index].fRestrict)) == 0) + { + fFileRestrict = cRestrictList[index].fMappedTo; + break; + } + } + + kcout << "newoskrnl.exe: new file: " << path << ".\r"; + } + + /// @brief destructor + template + FileStream::~FileStream() + { + mm_delete_ke_heap(fFile); + } +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/MP.hxx b/dev/ZKA/KernelKit/MP.hxx index 51f3472a..cf5d6754 100644 --- a/dev/ZKA/KernelKit/MP.hxx +++ b/dev/ZKA/KernelKit/MP.hxx @@ -103,7 +103,7 @@ namespace Kernel operator bool() noexcept; public: - /// @brief Shared instance of the MP Manager. + /// @brief Shared instance of the MP Mgr. /// @return the reference to the mp manager class. STATIC HardwareThreadScheduler& The(); diff --git a/dev/ZKA/KernelKit/PCI/Dma.hxx b/dev/ZKA/KernelKit/PCI/Dma.hxx index 43df13f0..8e51bc45 100644 --- a/dev/ZKA/KernelKit/PCI/Dma.hxx +++ b/dev/ZKA/KernelKit/PCI/Dma.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include diff --git a/dev/ZKA/KernelKit/PECodeManager.hxx b/dev/ZKA/KernelKit/PECodeManager.hxx deleted file mode 100644 index f42c7c21..00000000 --- a/dev/ZKA/KernelKit/PECodeManager.hxx +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: PECodeManager.hxx - Purpose: PE32+ Code Manager and Shared Objects. - - Revision History: - - 12/02/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -//////////////////////////////////////////////////// - -// LAST REV: Mon Feb 12 13:52:01 CET 2024 - -//////////////////////////////////////////////////// - -#include -#include -#include diff --git a/dev/ZKA/KernelKit/PECodeMgr.hxx b/dev/ZKA/KernelKit/PECodeMgr.hxx new file mode 100644 index 00000000..7b84fbc1 --- /dev/null +++ b/dev/ZKA/KernelKit/PECodeMgr.hxx @@ -0,0 +1,24 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: PECodeMgr.hxx + Purpose: PE32+ Code Mgr and Shared Objects. + + Revision History: + + 12/02/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +//////////////////////////////////////////////////// + +// LAST REV: Mon Feb 12 13:52:01 CET 2024 + +//////////////////////////////////////////////////// + +#include +#include +#include diff --git a/dev/ZKA/KernelKit/PEFCodeManager.hxx b/dev/ZKA/KernelKit/PEFCodeManager.hxx deleted file mode 100644 index dd6daca5..00000000 --- a/dev/ZKA/KernelKit/PEFCodeManager.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef _INC_CODE_MANAGER_PEF_HXX_ -#define _INC_CODE_MANAGER_PEF_HXX_ - -#include -#include -#include -#include - -#define kPefApplicationMime "application/x-newos-exec" - -namespace Kernel -{ - /// - /// \name PEFLoader - /// \brief PEF loader class. - /// - class PEFLoader : public LoaderInterface - { - private: - explicit PEFLoader() = delete; - - public: - explicit PEFLoader(const VoidPtr blob); - explicit PEFLoader(const Char* path); - ~PEFLoader() override; - - public: - ZKA_COPY_DEFAULT(PEFLoader); - - public: - const Char* Path() override; - const Char* AsString() override; - const Char* MIME() override; - - public: - ErrorOr FindStart() override; - VoidPtr FindSymbol(const Char* name, Int32 kind) override; - - public: - bool IsLoaded() noexcept; - - private: -#ifdef __FSKIT_USE_NEWFS__ - OwnPtr> fFile; -#else - OwnPtr> fFile; -#endif // __FSKIT_USE_NEWFS__ - - Ref fPath; - VoidPtr fCachedBlob; - bool fFatBinary; - bool fBad; - }; - - namespace Utils - { - bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept; - } // namespace Utils -} // namespace Kernel - -#endif // ifndef _INC_CODE_MANAGER_PEF_HXX_ diff --git a/dev/ZKA/KernelKit/PEFCodeMgr.hxx b/dev/ZKA/KernelKit/PEFCodeMgr.hxx new file mode 100644 index 00000000..74cc8eb0 --- /dev/null +++ b/dev/ZKA/KernelKit/PEFCodeMgr.hxx @@ -0,0 +1,67 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef _INC_CODE_MANAGER_PEF_HXX_ +#define _INC_CODE_MANAGER_PEF_HXX_ + +#include +#include +#include +#include + +#define kPefApplicationMime "application/x-newos-exec" + +namespace Kernel +{ + /// + /// \name PEFLoader + /// \brief PEF loader class. + /// + class PEFLoader : public LoaderInterface + { + private: + explicit PEFLoader() = delete; + + public: + explicit PEFLoader(const VoidPtr blob); + explicit PEFLoader(const Char* path); + ~PEFLoader() override; + + public: + ZKA_COPY_DEFAULT(PEFLoader); + + public: + const Char* Path() override; + const Char* AsString() override; + const Char* MIME() override; + + public: + ErrorOr FindStart() override; + VoidPtr FindSymbol(const Char* name, Int32 kind) override; + + public: + bool IsLoaded() noexcept; + + private: +#ifdef __FSKIT_USE_NEWFS__ + OwnPtr> fFile; +#else + OwnPtr> fFile; +#endif // __FSKIT_USE_NEWFS__ + + Ref fPath; + VoidPtr fCachedBlob; + bool fFatBinary; + bool fBad; + }; + + namespace Utils + { + bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept; + } // namespace Utils +} // namespace Kernel + +#endif // ifndef _INC_CODE_MANAGER_PEF_HXX_ diff --git a/dev/ZKA/KernelKit/PEFDLLInterface.hxx b/dev/ZKA/KernelKit/PEFDLLInterface.hxx index ef1a844f..d664bfd8 100644 --- a/dev/ZKA/KernelKit/PEFDLLInterface.hxx +++ b/dev/ZKA/KernelKit/PEFDLLInterface.hxx @@ -11,7 +11,7 @@ #define __KERNELKIT_SHARED_OBJECT_HXX__ #include -#include +#include #include #include @@ -96,7 +96,7 @@ namespace Kernel PEFLoader* fLoader{nullptr}; }; - typedef PEFDLLInterface* DLLInterfacePtr; + typedef DLLInterface* DLLInterfacePtr; EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header); EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful); diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index 809dbb7f..78d75af6 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -10,6 +10,7 @@ #include #include #include +#include #include #define kSchedMinMicroTime (AffinityKind::kStandard) @@ -158,13 +159,13 @@ namespace Kernel SizeT StackSize{mib_cast(8)}; // shared library handle, reserved for kDLLKind types of executables only. - PEFDLLInterface* DLLPtr{nullptr}; + DLLInterface* DLLPtr{nullptr}; UserProcess* Parent{nullptr}; // Memory usage. SizeT UsedMemory{0}; SizeT FreeMemory{0}; - SizeT SizeMemory{gib_cast(4)}; + SizeT SizeMemory{mib_cast(64)}; enum { diff --git a/dev/ZKA/NetworkKit/NetworkDevice.hxx b/dev/ZKA/NetworkKit/NetworkDevice.hxx index c307a433..ed575e3e 100644 --- a/dev/ZKA/NetworkKit/NetworkDevice.hxx +++ b/dev/ZKA/NetworkKit/NetworkDevice.hxx @@ -7,7 +7,7 @@ #ifndef __INC_NETWORK_DEVICE_HPP__ #define __INC_NETWORK_DEVICE_HPP__ -#include +#include #include /// @note Can either work with: Ethernet, GPRS, WiFi diff --git a/dev/ZKA/NewKit/PageAllocator.hxx b/dev/ZKA/NewKit/PageAllocator.hxx index a6d84aa0..5b19c0c2 100644 --- a/dev/ZKA/NewKit/PageAllocator.hxx +++ b/dev/ZKA/NewKit/PageAllocator.hxx @@ -7,7 +7,7 @@ #pragma once #include -#include +#include namespace Kernel { diff --git a/dev/ZKA/NewKit/PageManager.hxx b/dev/ZKA/NewKit/PageManager.hxx deleted file mode 100644 index 0de37803..00000000 --- a/dev/ZKA/NewKit/PageManager.hxx +++ /dev/null @@ -1,79 +0,0 @@ -// a way to create and find our pages. -// I'm thinking about a separate way of getting a paged area. - -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel -{ - class PageManager; - - class PTEWrapper final - { - public: - explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0); - - ~PTEWrapper(); - - PTEWrapper& operator=(const PTEWrapper&) = default; - PTEWrapper(const PTEWrapper&) = default; - - public: - const UIntPtr VirtualAddress(); - - void NoExecute(const bool enable = false); - const bool& NoExecute(); - - operator bool() { return fVirtAddr; } - - bool Reclaim(); - bool Shareable(); - bool Present(); - bool Access(); - - private: - Boolean fRw; - Boolean fUser; - Boolean fExecDisable; - UIntPtr fVirtAddr; - Boolean fCache; - Boolean fShareable; - Boolean fWt; - Boolean fPresent; - Boolean fAccessed; - - private: - friend class PageManager; - friend class Pmm; - }; - - struct PageManager final - { - public: - PageManager() = default; - ~PageManager() = default; - - PageManager& operator=(const PageManager&) = default; - PageManager(const PageManager&) = default; - - public: - PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz); - bool Free(Ref& wrapper); - - private: - void FlushTLB(); - - private: - friend PTEWrapper; - friend class Pmm; - }; -} // namespace Kernel diff --git a/dev/ZKA/NewKit/PageMgr.hxx b/dev/ZKA/NewKit/PageMgr.hxx new file mode 100644 index 00000000..1f6b5021 --- /dev/null +++ b/dev/ZKA/NewKit/PageMgr.hxx @@ -0,0 +1,79 @@ +// a way to create and find our pages. +// I'm thinking about a separate way of getting a paged area. + +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel +{ + class PageMgr; + + class PTEWrapper final + { + public: + explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0); + + ~PTEWrapper(); + + PTEWrapper& operator=(const PTEWrapper&) = default; + PTEWrapper(const PTEWrapper&) = default; + + public: + const UIntPtr VirtualAddress(); + + void NoExecute(const bool enable = false); + const Bool& NoExecute(); + + operator bool() { return fVirtAddr; } + + bool Reclaim(); + bool Shareable(); + bool Present(); + bool Access(); + + private: + Boolean fRw; + Boolean fUser; + Boolean fExecDisable; + UIntPtr fVirtAddr; + Boolean fCache; + Boolean fShareable; + Boolean fWt; + Boolean fPresent; + Boolean fAccessed; + + private: + friend class PageMgr; + friend class Pmm; + }; + + struct PageMgr final + { + public: + PageMgr() = default; + ~PageMgr() = default; + + PageMgr& operator=(const PageMgr&) = default; + PageMgr(const PageMgr&) = default; + + public: + PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz); + bool Free(Ref& wrapper); + + private: + void FlushTLB(); + + private: + friend PTEWrapper; + friend class Pmm; + }; +} // namespace Kernel diff --git a/dev/ZKA/NewKit/Pmm.hxx b/dev/ZKA/NewKit/Pmm.hxx index 111b3044..cdf498d9 100644 --- a/dev/ZKA/NewKit/Pmm.hxx +++ b/dev/ZKA/NewKit/Pmm.hxx @@ -7,7 +7,7 @@ #pragma once -#include +#include #include namespace Kernel @@ -33,12 +33,12 @@ namespace Kernel Boolean ToggleShare(Ref refPage, Boolean enable = true); /// @brief Get the page manager of this. - Ref& Leak() + Ref& Leak() { - return fPageManager; + return fPageMgr; } private: - Ref fPageManager; + Ref fPageMgr; }; } // namespace Kernel diff --git a/dev/ZKA/Sources/CodeManager.cxx b/dev/ZKA/Sources/CodeManager.cxx deleted file mode 100644 index 7e180ac0..00000000 --- a/dev/ZKA/Sources/CodeManager.cxx +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include - -namespace Kernel -{ - /// @brief Executes a new process from a function. Kernel code only. - /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. - /// @param main the start of the process. - /// @return if the process was started or not. - bool sched_execute_thread(MainKind main, const Char* processName) noexcept - { - if (!main) - return false; - - UserProcess proc; - proc.SetImageStart(reinterpret_cast(main)); - - proc.Kind = UserProcess::kExeKind; - proc.StackSize = kib_cast(8); - - rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); - - return UserProcessScheduler::The().Add(proc) == kErrorSuccess; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx new file mode 100644 index 00000000..df5b0917 --- /dev/null +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include + +namespace Kernel +{ + /// @brief Executes a new process from a function. Kernel code only. + /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. + /// @param main the start of the process. + /// @return if the process was started or not. + bool sched_execute_thread(MainKind main, const Char* processName) noexcept + { + if (!main) + return false; + + UserProcess proc; + proc.SetImageStart(reinterpret_cast(main)); + + proc.Kind = UserProcess::kExeKind; + proc.StackSize = kib_cast(8); + + rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); + + return UserProcessScheduler::The().Add(proc) == kErrorSuccess; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 84c58b3a..88887ec3 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -11,18 +11,18 @@ #include #include #include -#include +#include #include #include #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include #include #include #include @@ -44,23 +44,23 @@ namespace Kernel::Detail /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { - Kernel::NewFilesystemManager* fNewFS{nullptr}; + Kernel::NewFilesystemMgr* fNewFS{nullptr}; public: /// @brief wizard constructor. explicit FilesystemInstaller() { - if (Kernel::FilesystemManagerInterface::GetMounted()) + if (Kernel::FilesystemMgrInterface::GetMounted()) { CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNewFS = reinterpret_cast(Kernel::FilesystemManagerInterface::GetMounted()); + fNewFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); } else { // Mounts a NewFS from main drive. - fNewFS = new Kernel::NewFilesystemManager(); + fNewFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemManagerInterface::Mount(fNewFS); + Kernel::FilesystemMgrInterface::Mount(fNewFS); CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } @@ -142,8 +142,8 @@ namespace Kernel::Detail ZKA_COPY_DEFAULT(FilesystemInstaller); /// @brief Grab the disk's NewFS reference. - /// @return NewFilesystemManager the filesystem interface - Kernel::NewFilesystemManager* Leak() + /// @return NewFilesystemMgr the filesystem interface + Kernel::NewFilesystemMgr* Leak() { return fNewFS; } diff --git a/dev/ZKA/Sources/DeviceManager.cxx b/dev/ZKA/Sources/DeviceManager.cxx deleted file mode 100644 index 229e0fb7..00000000 --- a/dev/ZKA/Sources/DeviceManager.cxx +++ /dev/null @@ -1,7 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include diff --git a/dev/ZKA/Sources/DeviceMgr.cxx b/dev/ZKA/Sources/DeviceMgr.cxx new file mode 100644 index 00000000..70d01984 --- /dev/null +++ b/dev/ZKA/Sources/DeviceMgr.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include diff --git a/dev/ZKA/Sources/DriveManager.cxx b/dev/ZKA/Sources/DriveManager.cxx deleted file mode 100644 index 84c9870f..00000000 --- a/dev/ZKA/Sources/DriveManager.cxx +++ /dev/null @@ -1,146 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include -#include - -/// @file DriveManager.cxx -/// @brief Kernel drive manager. - -namespace Kernel -{ - static UInt16 kATAIO = 0U; - static UInt8 kATAMaster = 0U; - - /// @brief reads from an ATA drive. - /// @param pckt - /// @return - Void ke_drv_input(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - -#ifdef __AHCI__ - drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); -#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); -#endif - } - - /// @brief Writes to an ATA drive. - /// @param pckt - /// @return - Void ke_drv_output(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - -#ifdef __AHCI__ - drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); -#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); -#endif - } - - /// @brief Executes a disk check on the ATA drive. - /// @param pckt - /// @return - Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - - pckt->fPacketGood = false; - -#if defined(__ATA_PIO__) || defined(__ATA_DMA__) - kATAMaster = true; - kATAIO = ATA_PRIMARY_IO; - - MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster)); -#elif defined(__AHCI__) - UInt16 pi = 0; - MUST_PASS(drv_std_init(pi)); -#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) - - pckt->fPacketGood = true; - } - -/// @brief Gets the drive kind (ATA, SCSI, AHCI...) -/// @param -/// @return -#ifdef __ATA_PIO__ - const Char* io_drive_kind(Void) - { - return "ATA-PIO"; - } -#endif - -#ifdef __ATA_DMA__ - const Char* io_drive_kind(Void) - { - return "ATA-DMA"; - } -#endif - -#ifdef __AHCI__ - const Char* io_drive_kind(Void) - { - return "AHCI"; - } -#endif - - /// @brief Unimplemented drive. - /// @param pckt - /// @return - Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) - { - } - - /// @brief Makes a new drive. - /// @return the new drive. - DriveTrait io_construct_drive() noexcept - { - DriveTrait trait; - - rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); - trait.fKind = kInvalidDrive; - - trait.fInput = io_drv_unimplemented; - trait.fOutput = io_drv_unimplemented; - trait.fVerify = io_drv_unimplemented; - trait.fDriveKind = io_drive_kind; - - return trait; - } - - /// @brief Fetches the main drive. - /// @return the new drive. - DriveTrait io_construct_main_drive() noexcept - { - DriveTrait trait; - - rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); - trait.fKind = kMassStorage; - - trait.fInput = ke_drv_input; - trait.fOutput = ke_drv_output; - trait.fVerify = ke_drv_check_disk; - trait.fDriveKind = io_drive_kind; - - kcout << "newoskrnl.exe: Construct drive with success.\r"; - - return trait; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx new file mode 100644 index 00000000..376eb158 --- /dev/null +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -0,0 +1,146 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include + +/// @file DriveMgr.cxx +/// @brief Kernel drive manager. + +namespace Kernel +{ + static UInt16 kATAIO = 0U; + static UInt8 kATAMaster = 0U; + + /// @brief reads from an ATA drive. + /// @param pckt + /// @return + Void ke_drv_input(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + +#ifdef __AHCI__ + drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); +#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) + drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); +#endif + } + + /// @brief Writes to an ATA drive. + /// @param pckt + /// @return + Void ke_drv_output(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + +#ifdef __AHCI__ + drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); +#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) + drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); +#endif + } + + /// @brief Executes a disk check on the ATA drive. + /// @param pckt + /// @return + Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + + pckt->fPacketGood = false; + +#if defined(__ATA_PIO__) || defined(__ATA_DMA__) + kATAMaster = true; + kATAIO = ATA_PRIMARY_IO; + + MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster)); +#elif defined(__AHCI__) + UInt16 pi = 0; + MUST_PASS(drv_std_init(pi)); +#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) + + pckt->fPacketGood = true; + } + +/// @brief Gets the drive kind (ATA, SCSI, AHCI...) +/// @param +/// @return +#ifdef __ATA_PIO__ + const Char* io_drive_kind(Void) + { + return "ATA-PIO"; + } +#endif + +#ifdef __ATA_DMA__ + const Char* io_drive_kind(Void) + { + return "ATA-DMA"; + } +#endif + +#ifdef __AHCI__ + const Char* io_drive_kind(Void) + { + return "AHCI"; + } +#endif + + /// @brief Unimplemented drive. + /// @param pckt + /// @return + Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) + { + } + + /// @brief Makes a new drive. + /// @return the new drive. + DriveTrait io_construct_drive() noexcept + { + DriveTrait trait; + + rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); + trait.fKind = kInvalidDrive; + + trait.fInput = io_drv_unimplemented; + trait.fOutput = io_drv_unimplemented; + trait.fVerify = io_drv_unimplemented; + trait.fDriveKind = io_drive_kind; + + return trait; + } + + /// @brief Fetches the main drive. + /// @return the new drive. + DriveTrait io_construct_main_drive() noexcept + { + DriveTrait trait; + + rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); + trait.fKind = kMassStorage; + + trait.fInput = ke_drv_input; + trait.fOutput = ke_drv_output; + trait.fVerify = ke_drv_check_disk; + trait.fDriveKind = io_drive_kind; + + kcout << "newoskrnl.exe: Construct drive with success.\r"; + + return trait; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/FileManager.cxx b/dev/ZKA/Sources/FileManager.cxx deleted file mode 100644 index 8c8fb83a..00000000 --- a/dev/ZKA/Sources/FileManager.cxx +++ /dev/null @@ -1,190 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -/// BUGS: 0 -//! @brief File manager for Kernel. - -namespace Kernel -{ - STATIC FilesystemManagerInterface* kMounted = nullptr; - - /// @brief FilesystemManager getter. - /// @return The mounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() - { - return kMounted; - } - - /// @brief Unmount filesystem. - /// @return The unmounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::Unmount() - { - if (kMounted) - { - auto mount = kMounted; - kMounted = nullptr; - - return mount; - } - - return nullptr; - } - - /// @brief Mount filesystem. - /// @param mount_ptr The filesystem to mount. - /// @return if it succeeded true, otherwise false. - bool FilesystemManagerInterface::Mount(_Input FilesystemManagerInterface* mount_ptr) - { - if (mount_ptr != nullptr) - { - kMounted = mount_ptr; - return true; - } - - return false; - } - -#ifdef __FSKIT_USE_NEWFS__ - /// @brief Opens a new file. - /// @param path - /// @param r - /// @return - _Output NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) - { - if (!path || *path == 0) - return nullptr; - - if (!r || *r == 0) - return nullptr; - - auto catalog = fImpl->GetCatalog(path); - - return node_cast(catalog); - } - - /// @brief Writes to a catalog's fork. - /// @param node the node ptr. - /// @param data the data. - /// @param flags the size. - /// @return - Void NewFilesystemManager::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return; - if (!size) - return; - - constexpr auto cDataForkName = kNewFSDataFork; - this->Write(cDataForkName, node, data, flags, size); - } - - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - _Output VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return nullptr; - if (!size) - return nullptr; - - constexpr auto cDataForkName = kNewFSDataFork; - return this->Read(cDataForkName, node, flags, size); - } - - Void NewFilesystemManager::Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) - { - if (!size || - size > kNewFSForkSize) - return; - - if (!data) - return; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, - name); - } - - _Output VoidPtr NewFilesystemManager::Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) - { - if (sz > kNewFSForkSize) - return nullptr; - - if (!sz) - return nullptr; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, - name); - - return nullptr; - } - - /// @brief Seek from Catalog. - /// @param node - /// @param off - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NewFilesystemManager::Seek(NodePtr node, SizeT off) - { - if (!node || off == 0) - return false; - - return fImpl->Seek(reinterpret_cast(node), off); - } - - /// @brief Tell where the catalog is. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output SizeT NewFilesystemManager::Tell(NodePtr node) - { - if (!node) - return kNPos; - - return fImpl->Tell(reinterpret_cast(node)); - } - - /// @brief Rewinds the catalog. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NewFilesystemManager::Rewind(NodePtr node) - { - if (!node) - return false; - - return this->Seek(node, 0); - } - - /// @brief Returns the filesystem parser. - /// @return the Filesystem parser class. - _Output NewFSParser* NewFilesystemManager::GetParser() noexcept - { - return fImpl; - } -#endif // __FSKIT_USE_NEWFS__ -} // namespace Kernel diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx new file mode 100644 index 00000000..270c13f2 --- /dev/null +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -0,0 +1,190 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +/// BUGS: 0 +//! @brief File manager for Kernel. + +namespace Kernel +{ + STATIC FilesystemMgrInterface* kMounted = nullptr; + + /// @brief FilesystemMgr getter. + /// @return The mounted filesystem. + _Output FilesystemMgrInterface* FilesystemMgrInterface::GetMounted() + { + return kMounted; + } + + /// @brief Unmount filesystem. + /// @return The unmounted filesystem. + _Output FilesystemMgrInterface* FilesystemMgrInterface::Unmount() + { + if (kMounted) + { + auto mount = kMounted; + kMounted = nullptr; + + return mount; + } + + return nullptr; + } + + /// @brief Mount filesystem. + /// @param mount_ptr The filesystem to mount. + /// @return if it succeeded true, otherwise false. + bool FilesystemMgrInterface::Mount(_Input FilesystemMgrInterface* mount_ptr) + { + if (mount_ptr != nullptr) + { + kMounted = mount_ptr; + return true; + } + + return false; + } + +#ifdef __FSKIT_USE_NEWFS__ + /// @brief Opens a new file. + /// @param path + /// @param r + /// @return + _Output NodePtr NewFilesystemMgr::Open(_Input const Char* path, _Input const Char* r) + { + if (!path || *path == 0) + return nullptr; + + if (!r || *r == 0) + return nullptr; + + auto catalog = fImpl->GetCatalog(path); + + return node_cast(catalog); + } + + /// @brief Writes to a catalog's fork. + /// @param node the node ptr. + /// @param data the data. + /// @param flags the size. + /// @return + Void NewFilesystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return; + if (!size) + return; + + constexpr auto cDataForkName = kNewFSDataFork; + this->Write(cDataForkName, node, data, flags, size); + } + + /// @brief Read from filesystem fork. + /// @param node the catalog node. + /// @param flags the flags with it. + /// @param sz the size to read. + /// @return + _Output VoidPtr NewFilesystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return nullptr; + if (!size) + return nullptr; + + constexpr auto cDataForkName = kNewFSDataFork; + return this->Read(cDataForkName, node, flags, size); + } + + Void NewFilesystemMgr::Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) + { + if (!size || + size > kNewFSForkSize) + return; + + if (!data) + return; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, + name); + } + + _Output VoidPtr NewFilesystemMgr::Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) + { + if (sz > kNewFSForkSize) + return nullptr; + + if (!sz) + return nullptr; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, + name); + + return nullptr; + } + + /// @brief Seek from Catalog. + /// @param node + /// @param off + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NewFilesystemMgr::Seek(NodePtr node, SizeT off) + { + if (!node || off == 0) + return false; + + return fImpl->Seek(reinterpret_cast(node), off); + } + + /// @brief Tell where the catalog is. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output SizeT NewFilesystemMgr::Tell(NodePtr node) + { + if (!node) + return kNPos; + + return fImpl->Tell(reinterpret_cast(node)); + } + + /// @brief Rewinds the catalog. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NewFilesystemMgr::Rewind(NodePtr node) + { + if (!node) + return false; + + return this->Seek(node, 0); + } + + /// @brief Returns the filesystem parser. + /// @return the Filesystem parser class. + _Output NewFSParser* NewFilesystemMgr::GetParser() noexcept + { + return fImpl; + } +#endif // __FSKIT_USE_NEWFS__ +} // namespace Kernel diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index e036badb..615f5664 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -8,7 +8,7 @@ #include #include #include -#include +#include //! @file KernelHeap.cxx //! @brief Kernel heap allocator. @@ -19,7 +19,7 @@ namespace Kernel { SizeT kHeapCount = 0UL; - PageManager kHeapPageManager; + PageMgr kHeapPageMgr; Bool kOperationInProgress = No; /// @brief Contains data structures and algorithms for the heap. @@ -71,13 +71,13 @@ namespace Kernel if (!allocatedPtr || newSz < 1) return nullptr; - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)allocatedPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fHeapSize = newSz; + heap_blk->fHeapSize = newSz; - if (heapInfoBlk->fCRC32 > 0) + if (heap_blk->fCRC32 > 0) { MUST_PASS(mm_protect_ke_heap(allocatedPtr)); } @@ -97,9 +97,9 @@ namespace Kernel auto szFix = sz; if (szFix == 0) - ++szFix; + return nullptr; - auto wrapper = kHeapPageManager.Request(rw, user, No, szFix); + auto wrapper = kHeapPageMgr.Request(rw, user, No, szFix); Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr = reinterpret_cast( @@ -107,11 +107,11 @@ namespace Kernel heap_info_ptr->fHeapSize = szFix; heap_info_ptr->fMagic = kKernelHeapMagic; - heap_info_ptr->fCRC32 = 0U; // dont fill it for now. - heap_info_ptr->fHeapPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); - heap_info_ptr->fPage = 0UL; + heap_info_ptr->fCRC32 = No; // dont fill it for now. + heap_info_ptr->fHeapPtr = reinterpret_cast(heap_info_ptr) + sizeof(Detail::HEAP_INFORMATION_BLOCK); + heap_info_ptr->fPage = No; heap_info_ptr->fUser = user; - heap_info_ptr->fPresent = true; + heap_info_ptr->fPresent = No; ++kHeapCount; @@ -138,11 +138,11 @@ namespace Kernel Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fPage = true; + heap_blk->fPage = true; Detail::mm_alloc_fini_timeout(); @@ -156,48 +156,47 @@ namespace Kernel { if (kHeapCount < 1) return -kErrorInternal; - if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) - return -kErrorInternal; - if (((IntPtr)heap_ptr - kInvalidAddress) < 0) - return -kErrorInternal; + + if (!heap_ptr) + return -kErrorInvalidData; Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk && heapInfoBlk->fMagic == kKernelHeapMagic) + if (heap_blk && heap_blk->fMagic == kKernelHeapMagic) { - if (!heapInfoBlk->fPresent) + if (!heap_blk->fPresent) { Detail::mm_alloc_fini_timeout(); return -kErrorHeapNotPresent; } - if (heapInfoBlk->fCRC32 != 0) + if (heap_blk->fCRC32 != 0) { - if (heapInfoBlk->fCRC32 != - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, - heapInfoBlk->fHeapSize)) + if (heap_blk->fCRC32 != + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, + heap_blk->fHeapSize)) { - if (!heapInfoBlk->fUser) + if (!heap_blk->fUser) { ke_stop(RUNTIME_CHECK_POINTER); } } } - heapInfoBlk->fHeapSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fHeapPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heap_blk->fHeapSize = 0UL; + heap_blk->fPresent = No; + heap_blk->fHeapPtr = 0; + heap_blk->fCRC32 = 0; + heap_blk->fMagic = 0; - PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heapInfoBlk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - Ref pteAddress{&pageWrapper}; + PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + Ref pteAddress{pageWrapper}; - kHeapPageManager.Free(pteAddress); + kHeapPageMgr.Free(pteAddress); --kHeapCount; @@ -239,14 +238,14 @@ namespace Kernel { if (heap_ptr) { - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk->fPresent && kKernelHeapMagic == heapInfoBlk->fMagic) + if (heap_blk->fPresent && kKernelHeapMagic == heap_blk->fMagic) { - heapInfoBlk->fCRC32 = - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, heapInfoBlk->fHeapSize); + heap_blk->fCRC32 = + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, heap_blk->fHeapSize); return true; } diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx index 7429751f..c5cab5dc 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/MP.cxx @@ -17,12 +17,6 @@ namespace Kernel { - /***********************************************************************************/ - /// @brief MP object container property. - /***********************************************************************************/ - - Property cSMPCoreName; - ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -102,13 +96,13 @@ namespace Kernel { return mp_register_process(fStack); } - - //! SMP is disabled here. - - mp_do_context_switch_pre(); - mp_do_context_switch(image, stack_ptr, fStack); - - return true; + else + { + mp_do_context_switch_pre(); + mp_do_context_switch(image, stack_ptr, fStack); + + return false; + } } ///! @brief Tells if processor is waked up. @@ -123,15 +117,7 @@ namespace Kernel ///! @brief Constructor and destructors. ///! @brief Default constructor. - HardwareThreadScheduler::HardwareThreadScheduler() - { - kcout << "newoskrnl.exe: Initializing HardwareThreadScheduler." << endl; - - cSMPCoreName.GetKey() += "Property\\MPClass"; - cSMPCoreName.GetValue() = (PropertyId)this; - - kcout << "newoskrnl.exe: Initialized HardwareThreadScheduler." << endl; - } + HardwareThreadScheduler::HardwareThreadScheduler() = default; ///! @brief Default destructor. HardwareThreadScheduler::~HardwareThreadScheduler() = default; diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NewFS+FileManager.cxx deleted file mode 100644 index 20fb623d..00000000 --- a/dev/ZKA/Sources/NewFS+FileManager.cxx +++ /dev/null @@ -1,109 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __FSKIT_USE_NEWFS__ - -/// @brief NewFS File manager. -/// BUGS: 0 - -namespace Kernel -{ - /// @brief C++ constructor - NewFilesystemManager::NewFilesystemManager() - { - MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NewFSParser(); - MUST_PASS(fImpl); - - kcout << "newoskrnl.exe: We are done here... (NewFilesystemManager).\r"; - } - - NewFilesystemManager::~NewFilesystemManager() - { - kcout << "newoskrnl.exe: Destroying it...\r"; - - if (fImpl) - { - delete fImpl; - } - } - - /// @brief Removes a node from the filesystem. - /// @param fileName The filename - /// @return If it was deleted or not. - bool NewFilesystemManager::Remove(const Char* fileName) - { - if (fileName == nullptr || *fileName == 0) - return false; - - return fImpl->RemoveCatalog(fileName); - } - - /// @brief Creates a node with the specified. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::Create(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path)); - } - - /// @brief Creates a node with is a directory. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateDirectory(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); - } - - /// @brief Creates a node with is a alias. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateAlias(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); - } - - /// @brief Creates a node with is a page file. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateSwapFile(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); - } - - /// @brief Gets the root directory. - /// @return - const Char* NewFilesystemHelper::Root() - { - return kNewFSRoot; - } - - /// @brief Gets the up-dir directory. - /// @return - const Char* NewFilesystemHelper::UpDir() - { - return kNewFSUpDir; - } - - /// @brief Gets the separator character. - /// @return - const Char NewFilesystemHelper::Separator() - { - return kNewFSSeparator; - } - - /// @brief Gets the metafile character. - /// @return - const Char NewFilesystemHelper::MetaFile() - { - return kNewFSMetaFilePrefix; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx new file mode 100644 index 00000000..dd0d4a21 --- /dev/null +++ b/dev/ZKA/Sources/NewFS+FileMgr.cxx @@ -0,0 +1,109 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +#ifdef __FSKIT_USE_NEWFS__ + +/// @brief NewFS File manager. +/// BUGS: 0 + +namespace Kernel +{ + /// @brief C++ constructor + NewFilesystemMgr::NewFilesystemMgr() + { + MUST_PASS(Detail::fs_init_newfs()); + fImpl = new NewFSParser(); + MUST_PASS(fImpl); + + kcout << "newoskrnl.exe: We are done here... (NewFilesystemMgr).\r"; + } + + NewFilesystemMgr::~NewFilesystemMgr() + { + kcout << "newoskrnl.exe: Destroying it...\r"; + + if (fImpl) + { + delete fImpl; + } + } + + /// @brief Removes a node from the filesystem. + /// @param fileName The filename + /// @return If it was deleted or not. + bool NewFilesystemMgr::Remove(const Char* fileName) + { + if (fileName == nullptr || *fileName == 0) + return false; + + return fImpl->RemoveCatalog(fileName); + } + + /// @brief Creates a node with the specified. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::Create(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path)); + } + + /// @brief Creates a node with is a directory. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); + } + + /// @brief Creates a node with is a alias. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateAlias(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); + } + + /// @brief Creates a node with is a page file. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); + } + + /// @brief Gets the root directory. + /// @return + const Char* NewFilesystemHelper::Root() + { + return kNewFSRoot; + } + + /// @brief Gets the up-dir directory. + /// @return + const Char* NewFilesystemHelper::UpDir() + { + return kNewFSUpDir; + } + + /// @brief Gets the separator character. + /// @return + const Char NewFilesystemHelper::Separator() + { + return kNewFSSeparator; + } + + /// @brief Gets the metafile character. + /// @return + const Char NewFilesystemHelper::MetaFile() + { + return kNewFSMetaFilePrefix; + } +} // namespace Kernel + +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NewFS+IO.cxx index ddcecde4..e1a6ac95 100644 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ b/dev/ZKA/Sources/NewFS+IO.cxx @@ -4,8 +4,8 @@ ------------------------------------------- */ -#include -#include +#include +#include /************************************************************* * diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx index 6504b2bc..2f63cc9a 100644 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ b/dev/ZKA/Sources/NewFS+Journal.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/PEFCodeManager.cxx b/dev/ZKA/Sources/PEFCodeManager.cxx deleted file mode 100644 index 526312e0..00000000 --- a/dev/ZKA/Sources/PEFCodeManager.cxx +++ /dev/null @@ -1,252 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/// @brief PEF stack size symbol. -#define cPefStackSizeSymbol "SizeOfReserveStack" - -namespace Kernel -{ - namespace Detail - { - /// @brief Get the PEF platform signature according to the compiled backebnd - UInt32 rt_get_pef_platform(void) noexcept - { -#ifdef __ZKA_32X0__ - return kPefArch32x0; -#elif defined(__ZKA_64X0__) - return kPefArch64x0; -#elif defined(__ZKA_AMD64__) - return kPefArchAMD64; -#elif defined(__ZKA_PPC64__) - return kPefArchPowerPC; -#elif defined(__ZKA_ARM64__) - return kPefArchARM64; -#else - return kPefArchInvalid; -#endif // __32x0__ || __64x0__ || __x86_64__ - } - } // namespace Detail - - /// @brief PEF loader constructor w/ blob. - /// @param blob - PEFLoader::PEFLoader(const VoidPtr blob) - : fCachedBlob(blob) - { - MUST_PASS(fCachedBlob); - fBad = false; - } - - /// @brief PEF loader constructor. - /// @param path the filesystem path. - PEFLoader::PEFLoader(const Char* path) - : fCachedBlob(nullptr), fBad(false), fFatBinary(false) - { - fFile.New(const_cast(path), cRestrictRB); - fPath = StringBuilder::Construct(path).Leak(); - - auto cPefHeader = "PEF_CONTAINER"; - - fCachedBlob = fFile->Read(cPefHeader); - - PEFContainer* container = reinterpret_cast(fCachedBlob); - - if (container->Cpu == Detail::rt_get_pef_platform() && - container->Magic[0] == kPefMagic[0] && - container->Magic[1] == kPefMagic[1] && - container->Magic[2] == kPefMagic[2] && - container->Magic[3] == kPefMagic[3] && - container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi) - { - return; - } - else if (container->Magic[4] == kPefMagic[0] && - container->Magic[3] == kPefMagic[1] && - container->Magic[2] == kPefMagic[2] && - container->Magic[1] == kPefMagic[3] && - container->Magic[0] == kPefMagic[0] && container->Abi == kPefAbi) - { - /// This is a fat binary. - this->fFatBinary = true; - return; - } - - fBad = true; - - if (fCachedBlob) - mm_delete_ke_heap(fCachedBlob); - - kcout << "CodeManagerPEF: Warning: Executable format error!\r"; - fCachedBlob = nullptr; - } - - /// @brief PEF destructor. - PEFLoader::~PEFLoader() - { - if (fCachedBlob) - mm_delete_ke_heap(fCachedBlob); - - fFile.Delete(); - } - - VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind) - { - if (!fCachedBlob || fBad || !name) - return nullptr; - - PEFContainer* container = reinterpret_cast(fCachedBlob); - - auto blob = fFile->Read(name); - - PEFCommandHeader* container_header = reinterpret_cast(blob); - - constexpr auto cMangleCharacter = '$'; - const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; - - ErrorOr errOrSym; - - switch (kind) - { - case kPefCode: { - errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol. - break; - } - case kPefData: { - errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol. - break; - } - case kPefZero: { - errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol. - break; - } - default: - return nullptr; - } - - char* unconstSymbol = const_cast(name); - - for (SizeT i = 0UL; i < rt_string_len(unconstSymbol, kPefNameLen); ++i) - { - if (unconstSymbol[i] == ' ') - { - unconstSymbol[i] = cMangleCharacter; - } - } - - errOrSym.Leak().Leak() += name; - - for (SizeT index = 0; index < container->Count; ++index) - { - if (StringBuilder::Equals(container_header->Name, - errOrSym.Leak().Leak().CData())) - { - if (container_header->Kind == kind) - { - if (container_header->Cpu != Detail::rt_get_pef_platform()) - { - if (!this->fFatBinary) - { - mm_delete_ke_heap(blob); - return nullptr; - } - } - - Char* blobRet = new Char[container_header->Size]; - - HAL::mm_update_pte(blobRet, HAL::eFlagsPresent); - HAL::mm_update_pte(blobRet, HAL::eFlagsUser); - - if (container_header->Kind != kPefCode) - HAL::mm_update_pte(blobRet, HAL::eFlagsRw); - - rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size); - - mm_delete_ke_heap(blob); - return blobRet; - } - } - } - - mm_delete_ke_heap(blob); - return nullptr; - } - - /// @brief Finds the executable entrypoint. - /// @return - ErrorOr PEFLoader::FindStart() - { - if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym) - return ErrorOr(sym); - - return ErrorOr(kErrorExecutable); - } - - /// @brief Tells if the executable is loaded or not. - /// @return - bool PEFLoader::IsLoaded() noexcept - { - return !fBad && fCachedBlob; - } - - namespace Utils - { - Bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept - { - auto errOrStart = exec.FindStart(); - - if (errOrStart.Error() != kErrorSuccess) - return false; - - UserProcess proc; - - proc.SetImageStart(errOrStart.Leak().Leak()); - proc.Kind = procKind; - proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData); - - if (!proc.StackSize) - { - const auto cDefaultStackSizeMib = 8; - - proc.StackSize = mib_cast(cDefaultStackSizeMib); - } - - return UserProcessScheduler::The().Add(proc); - } - } // namespace Utils - - const Char* PEFLoader::Path() - { - return fPath.Leak().CData(); - } - - const Char* PEFLoader::AsString() - { -#ifdef __32x0__ - return "32x0 PEF format."; -#elif defined(__64x0__) - return "64x0 PEF format."; -#elif defined(__x86_64__) - return "x86_64 PEF format."; -#elif defined(__powerpc64__) - return "POWER PEF format."; -#else - return "Unknown PEF format."; -#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__ - } - - const Char* PEFLoader::MIME() - { - return kPefApplicationMime; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/PEFCodeMgr.cxx b/dev/ZKA/Sources/PEFCodeMgr.cxx new file mode 100644 index 00000000..feafc35c --- /dev/null +++ b/dev/ZKA/Sources/PEFCodeMgr.cxx @@ -0,0 +1,252 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @brief PEF stack size symbol. +#define cPefStackSizeSymbol "SizeOfReserveStack" + +namespace Kernel +{ + namespace Detail + { + /// @brief Get the PEF platform signature according to the compiled backebnd + UInt32 rt_get_pef_platform(void) noexcept + { +#ifdef __ZKA_32X0__ + return kPefArch32x0; +#elif defined(__ZKA_64X0__) + return kPefArch64x0; +#elif defined(__ZKA_AMD64__) + return kPefArchAMD64; +#elif defined(__ZKA_PPC64__) + return kPefArchPowerPC; +#elif defined(__ZKA_ARM64__) + return kPefArchARM64; +#else + return kPefArchInvalid; +#endif // __32x0__ || __64x0__ || __x86_64__ + } + } // namespace Detail + + /// @brief PEF loader constructor w/ blob. + /// @param blob + PEFLoader::PEFLoader(const VoidPtr blob) + : fCachedBlob(blob) + { + MUST_PASS(fCachedBlob); + fBad = false; + } + + /// @brief PEF loader constructor. + /// @param path the filesystem path. + PEFLoader::PEFLoader(const Char* path) + : fCachedBlob(nullptr), fBad(false), fFatBinary(false) + { + fFile.New(const_cast(path), cRestrictRB); + fPath = StringBuilder::Construct(path).Leak(); + + auto cPefHeader = "PEF_CONTAINER"; + + fCachedBlob = fFile->Read(cPefHeader); + + PEFContainer* container = reinterpret_cast(fCachedBlob); + + if (container->Cpu == Detail::rt_get_pef_platform() && + container->Magic[0] == kPefMagic[0] && + container->Magic[1] == kPefMagic[1] && + container->Magic[2] == kPefMagic[2] && + container->Magic[3] == kPefMagic[3] && + container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi) + { + return; + } + else if (container->Magic[4] == kPefMagic[0] && + container->Magic[3] == kPefMagic[1] && + container->Magic[2] == kPefMagic[2] && + container->Magic[1] == kPefMagic[3] && + container->Magic[0] == kPefMagic[0] && container->Abi == kPefAbi) + { + /// This is a fat binary. + this->fFatBinary = true; + return; + } + + fBad = true; + + if (fCachedBlob) + mm_delete_ke_heap(fCachedBlob); + + kcout << "CodeMgrPEF: Warning: Executable format error!\r"; + fCachedBlob = nullptr; + } + + /// @brief PEF destructor. + PEFLoader::~PEFLoader() + { + if (fCachedBlob) + mm_delete_ke_heap(fCachedBlob); + + fFile.Delete(); + } + + VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind) + { + if (!fCachedBlob || fBad || !name) + return nullptr; + + PEFContainer* container = reinterpret_cast(fCachedBlob); + + auto blob = fFile->Read(name); + + PEFCommandHeader* container_header = reinterpret_cast(blob); + + constexpr auto cMangleCharacter = '$'; + const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; + + ErrorOr errOrSym; + + switch (kind) + { + case kPefCode: { + errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol. + break; + } + case kPefData: { + errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol. + break; + } + case kPefZero: { + errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol. + break; + } + default: + return nullptr; + } + + char* unconstSymbol = const_cast(name); + + for (SizeT i = 0UL; i < rt_string_len(unconstSymbol, kPefNameLen); ++i) + { + if (unconstSymbol[i] == ' ') + { + unconstSymbol[i] = cMangleCharacter; + } + } + + errOrSym.Leak().Leak() += name; + + for (SizeT index = 0; index < container->Count; ++index) + { + if (StringBuilder::Equals(container_header->Name, + errOrSym.Leak().Leak().CData())) + { + if (container_header->Kind == kind) + { + if (container_header->Cpu != Detail::rt_get_pef_platform()) + { + if (!this->fFatBinary) + { + mm_delete_ke_heap(blob); + return nullptr; + } + } + + Char* blobRet = new Char[container_header->Size]; + + HAL::mm_update_pte(blobRet, HAL::eFlagsPresent); + HAL::mm_update_pte(blobRet, HAL::eFlagsUser); + + if (container_header->Kind != kPefCode) + HAL::mm_update_pte(blobRet, HAL::eFlagsRw); + + rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size); + + mm_delete_ke_heap(blob); + return blobRet; + } + } + } + + mm_delete_ke_heap(blob); + return nullptr; + } + + /// @brief Finds the executable entrypoint. + /// @return + ErrorOr PEFLoader::FindStart() + { + if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym) + return ErrorOr(sym); + + return ErrorOr(kErrorExecutable); + } + + /// @brief Tells if the executable is loaded or not. + /// @return + bool PEFLoader::IsLoaded() noexcept + { + return !fBad && fCachedBlob; + } + + namespace Utils + { + Bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept + { + auto errOrStart = exec.FindStart(); + + if (errOrStart.Error() != kErrorSuccess) + return false; + + UserProcess proc; + + proc.SetImageStart(errOrStart.Leak().Leak()); + proc.Kind = procKind; + proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData); + + if (!proc.StackSize) + { + const auto cDefaultStackSizeMib = 8; + + proc.StackSize = mib_cast(cDefaultStackSizeMib); + } + + return UserProcessScheduler::The().Add(proc); + } + } // namespace Utils + + const Char* PEFLoader::Path() + { + return fPath.Leak().CData(); + } + + const Char* PEFLoader::AsString() + { +#ifdef __32x0__ + return "32x0 PEF format."; +#elif defined(__64x0__) + return "64x0 PEF format."; +#elif defined(__x86_64__) + return "x86_64 PEF format."; +#elif defined(__powerpc64__) + return "POWER PEF format."; +#else + return "Unknown PEF format."; +#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__ + } + + const Char* PEFLoader::MIME() + { + return kPefApplicationMime; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageManager.cxx deleted file mode 100644 index dd18709f..00000000 --- a/dev/ZKA/Sources/PageManager.cxx +++ /dev/null @@ -1,111 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __ZKA_AMD64__ -#include -#elif defined(__ZKA_ARM64__) -#include -#endif // ifdef __ZKA_AMD64__ || defined(__ZKA_ARM64__) - -//! null deref will throw (Page Zero detected, aborting app!) -#define kProtectedRegionEnd (512) - -namespace Kernel -{ - PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) - : fRw(Rw), - fUser(User), - fExecDisable(ExecDisable), - fVirtAddr(VirtAddr), - fCache(false), - fShareable(false), - fWt(false), - fPresent(true), - fAccessed(false) - { - } - - PTEWrapper::~PTEWrapper() = default; - - /// @brief Flush virtual address. - /// @param VirtAddr - Void PageManager::FlushTLB() - { - hal_flush_tlb(); - } - - /// @brief Reclaim freed page. - /// @return - Bool PTEWrapper::Reclaim() - { - if (!this->fPresent) - { - this->fPresent = true; - return true; - } - - return false; - } - - /// @brief Request a PTE. - /// @param Rw r/w? - /// @param User user mode? - /// @param ExecDisable disable execution on page? - /// @return - PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) - { - // Store PTE wrapper right after PTE. - VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); - - return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast(ptr)}; - } - - /// @brief Disable BitMap. - /// @param wrapper the wrapper. - /// @return If the page bitmap was cleared or not. - Bool PageManager::Free(Ref& wrapper) - { - if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper->VirtualAddress())) - return false; - - return true; - } - - /// @brief Virtual PTE address. - /// @return The virtual address of the page. - const UIntPtr PTEWrapper::VirtualAddress() - { - return (fVirtAddr); - } - - bool PTEWrapper::Shareable() - { - return fShareable; - } - - bool PTEWrapper::Present() - { - return fPresent; - } - - bool PTEWrapper::Access() - { - return fAccessed; - } - - void PTEWrapper::NoExecute(const bool enable) - { - this->fExecDisable = enable; - } - - const bool& PTEWrapper::NoExecute() - { - return this->fExecDisable; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/PageMgr.cxx b/dev/ZKA/Sources/PageMgr.cxx new file mode 100644 index 00000000..78b279f3 --- /dev/null +++ b/dev/ZKA/Sources/PageMgr.cxx @@ -0,0 +1,111 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +#ifdef __ZKA_AMD64__ +#include +#elif defined(__ZKA_ARM64__) +#include +#endif // ifdef __ZKA_AMD64__ || defined(__ZKA_ARM64__) + +//! null deref will throw (Page Zero detected, aborting app!) +#define kProtectedRegionEnd (512) + +namespace Kernel +{ + PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) + : fRw(Rw), + fUser(User), + fExecDisable(ExecDisable), + fVirtAddr(VirtAddr), + fCache(false), + fShareable(false), + fWt(false), + fPresent(true), + fAccessed(false) + { + } + + PTEWrapper::~PTEWrapper() = default; + + /// @brief Flush virtual address. + /// @param VirtAddr + Void PageMgr::FlushTLB() + { + hal_flush_tlb(); + } + + /// @brief Reclaim freed page. + /// @return + Bool PTEWrapper::Reclaim() + { + if (!this->fPresent) + { + this->fPresent = true; + return true; + } + + return false; + } + + /// @brief Request a PTE. + /// @param Rw r/w? + /// @param User user mode? + /// @param ExecDisable disable execution on page? + /// @return + PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) + { + // Store PTE wrapper right after PTE. + VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); + + return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast(ptr)}; + } + + /// @brief Disable BitMap. + /// @param wrapper the wrapper. + /// @return If the page bitmap was cleared or not. + Bool PageMgr::Free(Ref& wrapper) + { + if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper.Leak().VirtualAddress())) + return false; + + return true; + } + + /// @brief Virtual PTE address. + /// @return The virtual address of the page. + const UIntPtr PTEWrapper::VirtualAddress() + { + return (fVirtAddr); + } + + bool PTEWrapper::Shareable() + { + return fShareable; + } + + bool PTEWrapper::Present() + { + return fPresent; + } + + bool PTEWrapper::Access() + { + return fAccessed; + } + + void PTEWrapper::NoExecute(const bool enable) + { + this->fExecDisable = enable; + } + + const bool& PTEWrapper::NoExecute() + { + return this->fExecDisable; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/Pmm.cxx b/dev/ZKA/Sources/Pmm.cxx index b0855281..58335a2b 100644 --- a/dev/ZKA/Sources/Pmm.cxx +++ b/dev/ZKA/Sources/Pmm.cxx @@ -19,9 +19,9 @@ namespace Kernel { /// @brief Pmm constructor. Pmm::Pmm() - : fPageManager() + : fPageMgr() { - kcout << "[PMM] Allocate PageMemoryManager"; + kcout << "[PMM] Allocate PageMemoryMgr"; } Pmm::~Pmm() = default; @@ -31,17 +31,15 @@ namespace Kernel /// @param readWrite is it r/w? Ref Pmm::RequestPage(Boolean user, Boolean readWrite) { - PTEWrapper pt = fPageManager.Leak().Request(user, readWrite, false, kPTESize); + PTEWrapper pt = fPageMgr.Leak().Request(user, readWrite, false, kPTESize); if (pt.fPresent) { - kcout << "[PMM]: Allocation was successful.\r"; - return Ref(pt); + kcout << "[PMM]: Allocation failed.\r"; + return {}; } - kcout << "[PMM]: Allocation failed.\r"; - - return {}; + return Ref(pt); } Boolean Pmm::FreePage(Ref PageRef) diff --git a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx index 183481e1..97d2e2e4 100644 --- a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx +++ b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) @@ -69,7 +69,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 871d011f..5aa688be 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 26d8be79..48988e57 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -34,7 +34,7 @@ namespace Kernel /// @brief UserProcess scheduler instance. /***********************************************************************************/ - STATIC UserProcessScheduler* cProcessScheduler; + STATIC UserProcessScheduler* cProcessScheduler = nullptr; /// @brief Gets the last exit code. /// @note Not thread-safe. diff --git a/dev/ZKA/StorageKit/AHCI.hxx b/dev/ZKA/StorageKit/AHCI.hxx index 3e9567a5..f3d771c9 100644 --- a/dev/ZKA/StorageKit/AHCI.hxx +++ b/dev/ZKA/StorageKit/AHCI.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include namespace Kernel diff --git a/dev/ZKA/StorageKit/ATA.hxx b/dev/ZKA/StorageKit/ATA.hxx index be3e4a21..e954b0e7 100644 --- a/dev/ZKA/StorageKit/ATA.hxx +++ b/dev/ZKA/StorageKit/ATA.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/dev/ZKA/StorageKit/NVME.hxx b/dev/ZKA/StorageKit/NVME.hxx index c0231f57..45d00c0c 100644 --- a/dev/ZKA/StorageKit/NVME.hxx +++ b/dev/ZKA/StorageKit/NVME.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include namespace Kernel diff --git a/dev/ZKA/amd64-efi.make b/dev/ZKA/amd64-efi.make index 0e8cbad4..4d1f9403 100644 --- a/dev/ZKA/amd64-efi.make +++ b/dev/ZKA/amd64-efi.make @@ -35,7 +35,7 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is __ImageStart -LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000 +LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 LDOBJ = Objects/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. -- cgit v1.2.3 From e4517a114b460f55452b2968270c019db14cf42a Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 4 Sep 2024 16:45:27 +0000 Subject: dev/ZKA/Sources/ProcessTeam.cxx edited online with Bitbucket --- dev/ZKA/Sources/ProcessTeam.cxx | 38 ------------------------------------- dev/ZKA/Sources/UserProcessTeam.cxx | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) delete mode 100644 dev/ZKA/Sources/ProcessTeam.cxx create mode 100644 dev/ZKA/Sources/UserProcessTeam.cxx (limited to 'dev') diff --git a/dev/ZKA/Sources/ProcessTeam.cxx b/dev/ZKA/Sources/ProcessTeam.cxx deleted file mode 100644 index bb5726f7..00000000 --- a/dev/ZKA/Sources/ProcessTeam.cxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -/***********************************************************************************/ -/// @file UserProcessTeam.cxx -/// @brief UserProcess teams implementation. -/***********************************************************************************/ - -#include - -namespace Kernel -{ - /// @brief UserProcess list array getter. - /// @return The list of process to schedule. - Array& UserProcessTeam::AsArray() - { - return mProcessList; - } - - /// @brief Get team ID. - /// @return The team's ID. - ProcessID& UserProcessTeam::Id() noexcept - { - return mTeamId; - } - - /// @brief Current process getter. - /// @return The current process header. - Ref& UserProcessTeam::AsRef() - { - return mCurrentProcess; - } -} // namespace Kernel - -// last rev 05-03-24 diff --git a/dev/ZKA/Sources/UserProcessTeam.cxx b/dev/ZKA/Sources/UserProcessTeam.cxx new file mode 100644 index 00000000..bb5726f7 --- /dev/null +++ b/dev/ZKA/Sources/UserProcessTeam.cxx @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +/***********************************************************************************/ +/// @file UserProcessTeam.cxx +/// @brief UserProcess teams implementation. +/***********************************************************************************/ + +#include + +namespace Kernel +{ + /// @brief UserProcess list array getter. + /// @return The list of process to schedule. + Array& UserProcessTeam::AsArray() + { + return mProcessList; + } + + /// @brief Get team ID. + /// @return The team's ID. + ProcessID& UserProcessTeam::Id() noexcept + { + return mTeamId; + } + + /// @brief Current process getter. + /// @return The current process header. + Ref& UserProcessTeam::AsRef() + { + return mCurrentProcess; + } +} // namespace Kernel + +// last rev 05-03-24 -- cgit v1.2.3 From 0aaf98a4875893914b3c75cb0eb1eb0971412377 Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 4 Sep 2024 16:47:41 +0000 Subject: dev/ZKA/HALKit/AMD64/HalAPIC.cxx edited online with Bitbucket --- dev/ZKA/HALKit/AMD64/HalAPIC.cxx | 36 ------------------------------------ dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 dev/ZKA/HALKit/AMD64/HalAPIC.cxx create mode 100644 dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx (limited to 'dev') diff --git a/dev/ZKA/HALKit/AMD64/HalAPIC.cxx b/dev/ZKA/HALKit/AMD64/HalAPIC.cxx deleted file mode 100644 index caa2ce0b..00000000 --- a/dev/ZKA/HALKit/AMD64/HalAPIC.cxx +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -namespace Kernel::HAL -{ - /// @brief Read from APIC controller. - /// @param reg register. - UInt32 APICController::Read(UInt32 reg) noexcept - { - MUST_PASS(this->fApic); - - UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; - ioapic[0] = (reg & 0xff); - - return ioapic[4]; - } - - /// @brief Write to APIC controller. - /// @param reg register. - /// @param value value. - Void APICController::Write(UInt32 reg, UInt32 value) noexcept - { - MUST_PASS(this->fApic); - - UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; - - ioapic[0] = (reg & 0xFF); - ioapic[4] = value; - } -} // namespace Kernel::HAL diff --git a/dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx b/dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx new file mode 100644 index 00000000..caa2ce0b --- /dev/null +++ b/dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +namespace Kernel::HAL +{ + /// @brief Read from APIC controller. + /// @param reg register. + UInt32 APICController::Read(UInt32 reg) noexcept + { + MUST_PASS(this->fApic); + + UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; + ioapic[0] = (reg & 0xff); + + return ioapic[4]; + } + + /// @brief Write to APIC controller. + /// @param reg register. + /// @param value value. + Void APICController::Write(UInt32 reg, UInt32 value) noexcept + { + MUST_PASS(this->fApic); + + UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic; + + ioapic[0] = (reg & 0xFF); + ioapic[4] = value; + } +} // namespace Kernel::HAL -- cgit v1.2.3 From 1069f411d413e2185f6536b01b8993187056fcd8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Sep 2024 22:20:17 +0200 Subject: [ IMP ] BMP allocator needs more tweaking and fixes, to be usable. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 99 ++++++++++++++++ dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx | 99 ---------------- dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 34 ++---- dev/ZKA/HALKit/POWER/HalHardware.cxx | 19 ---- dev/ZKA/KernelKit/CodeMgr.hxx | 2 +- dev/ZKA/KernelKit/DLLInterface.hxx | 51 --------- dev/ZKA/KernelKit/IDLLObject.hxx | 45 ++++++++ dev/ZKA/KernelKit/IPEFDLLObject.hxx | 105 +++++++++++++++++ dev/ZKA/KernelKit/PEFDLLInterface.hxx | 105 ----------------- dev/ZKA/KernelKit/UserProcessScheduler.hxx | 36 +++--- dev/ZKA/Sources/CodeMgr.cxx | 2 +- dev/ZKA/Sources/DLLInterface.cxx | 15 --- dev/ZKA/Sources/DLLMain.cxx | 2 + dev/ZKA/Sources/Heap.cxx | 16 +-- dev/ZKA/Sources/IDLLObject.cxx | 15 +++ dev/ZKA/Sources/IPEFDLLObject.cxx | 100 ++++++++++++++++ dev/ZKA/Sources/PEFDLLInterface.cxx | 100 ---------------- dev/ZKA/Sources/UserProcessScheduler.cxx | 169 +++++++++++++--------------- 18 files changed, 490 insertions(+), 524 deletions(-) create mode 100644 dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx delete mode 100644 dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx delete mode 100644 dev/ZKA/HALKit/POWER/HalHardware.cxx delete mode 100644 dev/ZKA/KernelKit/DLLInterface.hxx create mode 100644 dev/ZKA/KernelKit/IDLLObject.hxx create mode 100644 dev/ZKA/KernelKit/IPEFDLLObject.hxx delete mode 100644 dev/ZKA/KernelKit/PEFDLLInterface.hxx delete mode 100644 dev/ZKA/Sources/DLLInterface.cxx create mode 100644 dev/ZKA/Sources/IDLLObject.cxx create mode 100644 dev/ZKA/Sources/IPEFDLLObject.cxx delete mode 100644 dev/ZKA/Sources/PEFDLLInterface.cxx (limited to 'dev') diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx new file mode 100644 index 00000000..7bafd075 --- /dev/null +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -0,0 +1,99 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include + +#define cVMHMagic ((Kernel::UIntPtr)0x10210) + +#ifdef __ZKA_AMD64__ +#include +#elif defined(__ZKA_ARM64__) +#include +#endif + +#include +#include + +namespace Kernel +{ + namespace HAL + { + namespace Detail + { + struct AllocatorTraits final + { + /// @brief Iterate over availables pages for a free one. + /// @return The new address which was found. + VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept + { + while (base_ptr && size) + { + UIntPtr* ptr_bit_set = reinterpret_cast(base_ptr); + + if (ptr_bit_set[0] != cVMHMagic) + { + ptr_bit_set[0] = cVMHMagic; + ptr_bit_set[1] = size; + + kcout << "BBP: STATUS\r"; + kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "BBP: ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + + if (rw) + mm_update_pte(base_ptr, eFlagsRw); + + if (user) + mm_update_pte(base_ptr, eFlagsUser); + + return (VoidPtr)(&ptr_bit_set[2]); + } + + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + 1 + ptr_bit_set[1]); + } + + return nullptr; + } + }; + } // namespace Detail + + /// @brief Allocate a new page to be used by the OS. + /// @param rw read/write bit. + /// @param user user bit. + /// @return + auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr + { + VoidPtr ptr_new = nullptr; + Detail::AllocatorTraits traits; + + ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + + return &((UIntPtr*)ptr_new)[1]; + } + + auto mm_free_bitmap(VoidPtr page_ptr) -> Bool + { + if (!page_ptr) + return false; + + UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 3; + + if (!ptr_bit_set[0] || + ptr_bit_set[0] != cVMHMagic) + return false; + + kcout << "BBP: FREE STATUS\r"; + kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "BBP: ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + + ptr_bit_set[0] = 0UL; + ptr_bit_set[1] = 0UL; + + return true; + } + } // namespace HAL +} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx deleted file mode 100644 index 7bafd075..00000000 --- a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx +++ /dev/null @@ -1,99 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include - -#define cVMHMagic ((Kernel::UIntPtr)0x10210) - -#ifdef __ZKA_AMD64__ -#include -#elif defined(__ZKA_ARM64__) -#include -#endif - -#include -#include - -namespace Kernel -{ - namespace HAL - { - namespace Detail - { - struct AllocatorTraits final - { - /// @brief Iterate over availables pages for a free one. - /// @return The new address which was found. - VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept - { - while (base_ptr && size) - { - UIntPtr* ptr_bit_set = reinterpret_cast(base_ptr); - - if (ptr_bit_set[0] != cVMHMagic) - { - ptr_bit_set[0] = cVMHMagic; - ptr_bit_set[1] = size; - - kcout << "BBP: STATUS\r"; - kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "BBP: ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; - - if (rw) - mm_update_pte(base_ptr, eFlagsRw); - - if (user) - mm_update_pte(base_ptr, eFlagsUser); - - return (VoidPtr)(&ptr_bit_set[2]); - } - - base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + 1 + ptr_bit_set[1]); - } - - return nullptr; - } - }; - } // namespace Detail - - /// @brief Allocate a new page to be used by the OS. - /// @param rw read/write bit. - /// @param user user bit. - /// @return - auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - VoidPtr ptr_new = nullptr; - Detail::AllocatorTraits traits; - - ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); - - return &((UIntPtr*)ptr_new)[1]; - } - - auto mm_free_bitmap(VoidPtr page_ptr) -> Bool - { - if (!page_ptr) - return false; - - UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 3; - - if (!ptr_bit_set[0] || - ptr_bit_set[0] != cVMHMagic) - return false; - - kcout << "BBP: FREE STATUS\r"; - kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "BBP: ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; - - ptr_bit_set[0] = 0UL; - ptr_bit_set[1] = 0UL; - - return true; - } - } // namespace HAL -} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index 1f31c880..c26a346f 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -21,8 +21,6 @@ section .text ;; rcx: code ptr. ;; rdx: stack ptr. mp_do_context_switch: - swapgs - mov fs, rcx mov gs, rdx @@ -36,27 +34,12 @@ mp_do_context_switch: mov r11, gs mov r12, fs - ; Enable SCE that enables sysret and syscall - mov rcx, 0xc0000082 - wrmsr - mov rcx, 0xc0000080 - rdmsr - or eax, 1 - wrmsr - mov rcx, 0xc0000081 - rdmsr - mov edx, 0x00180008 - wrmsr - mov r11, 0x202 mov fs, [r8 + (8 * 4)] mov gs, [r8 + (8 * 9)] mov r8, [r8] - swapgs - sti - o64 sysret ;; @brief Gets the current stack frame. @@ -68,8 +51,6 @@ extern hal_system_call_enter global mp_system_call_handler mp_system_call_handler: - swapgs - push r8 push r9 push r10 @@ -80,9 +61,6 @@ mp_system_call_handler: pop r9 pop r8 - swapgs - sti - o64 sysret mp_do_context_switch_pre: @@ -96,4 +74,16 @@ mp_do_context_switch_pre: mov rcx, 0xc0000082 wrmsr + ; Enable SCE that enables sysret and syscall + mov rcx, 0xc0000082 + wrmsr + mov rcx, 0xc0000080 + rdmsr + or eax, 1 + wrmsr + mov rcx, 0xc0000081 + rdmsr + mov edx, 0x00180008 + wrmsr + ret diff --git a/dev/ZKA/HALKit/POWER/HalHardware.cxx b/dev/ZKA/HALKit/POWER/HalHardware.cxx deleted file mode 100644 index eb335d70..00000000 --- a/dev/ZKA/HALKit/POWER/HalHardware.cxx +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -namespace Kernel -{ - namespace HAL - { - UIntPtr mm_alloc_bitmap(bool rw, bool user) - { - return 0; - } - } // namespace HAL -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/CodeMgr.hxx b/dev/ZKA/KernelKit/CodeMgr.hxx index 8c4f090f..c8f9cca9 100644 --- a/dev/ZKA/KernelKit/CodeMgr.hxx +++ b/dev/ZKA/KernelKit/CodeMgr.hxx @@ -16,7 +16,7 @@ #include #include -#include +#include namespace Kernel { diff --git a/dev/ZKA/KernelKit/DLLInterface.hxx b/dev/ZKA/KernelKit/DLLInterface.hxx deleted file mode 100644 index 13f36b82..00000000 --- a/dev/ZKA/KernelKit/DLLInterface.hxx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright ZKA Technologies., all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include - -namespace Kernel -{ - class DLLInterface - { - public: - explicit DLLInterface() = default; - virtual ~DLLInterface() = default; - - struct DLL_TRAITS final - { - VoidPtr fImageObject{nullptr}; - VoidPtr fImageEntrypointOffset{nullptr}; - - Bool IsValid() - { - return fImageObject && fImageEntrypointOffset; - } - }; - - ZKA_COPY_DEFAULT(DLLInterface); - - virtual DLL_TRAITS** GetAddressOf() = 0; - virtual DLL_TRAITS* Get() = 0; - - virtual Void Mount(DLL_TRAITS* to_mount) = 0; - virtual Void Unmount() = 0; - - - template - SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) - { - return nullptr; - } - }; - - /// @brief Pure implementation, missing method/function handler. - EXTERN_C void __zka_pure_call(void); -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/IDLLObject.hxx b/dev/ZKA/KernelKit/IDLLObject.hxx new file mode 100644 index 00000000..39580307 --- /dev/null +++ b/dev/ZKA/KernelKit/IDLLObject.hxx @@ -0,0 +1,45 @@ +/* + * ======================================================== + * + * Kernel + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include + +namespace Kernel +{ + class IDLLObject + { + public: + explicit IDLLObject() = default; + virtual ~IDLLObject() = default; + + struct DLL_TRAITS final + { + VoidPtr fImageObject{nullptr}; + VoidPtr fImageEntrypointOffset{nullptr}; + + Bool IsValid() + { + return fImageObject && fImageEntrypointOffset; + } + }; + + ZKA_COPY_DEFAULT(IDLLObject); + + virtual DLL_TRAITS** GetAddressOf() = 0; + virtual DLL_TRAITS* Get() = 0; + + virtual Void Mount(DLL_TRAITS* to_mount) = 0; + virtual Void Unmount() = 0; + + }; + + /// @brief Pure implementation, missing method/function handler. + EXTERN_C void __zka_pure_call(void); +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/IPEFDLLObject.hxx b/dev/ZKA/KernelKit/IPEFDLLObject.hxx new file mode 100644 index 00000000..013173d1 --- /dev/null +++ b/dev/ZKA/KernelKit/IPEFDLLObject.hxx @@ -0,0 +1,105 @@ +/* + * ======================================================== + * + * Kernel + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#ifndef __KERNELKIT_SHARED_OBJECT_HXX__ +#define __KERNELKIT_SHARED_OBJECT_HXX__ + +#include +#include +#include +#include + +namespace Kernel +{ + /** + * @brief Shared Library class + * Load library from this class + */ + class IPEFDLLObject final : public IDLLObject + { + public: + explicit IPEFDLLObject() = default; + ~IPEFDLLObject() = default; + + public: + ZKA_COPY_DEFAULT(IPEFDLLObject); + + private: + DLL_TRAITS* fMounted{nullptr}; + + public: + DLL_TRAITS** GetAddressOf() + { + return &fMounted; + } + + DLL_TRAITS* Get() + { + return fMounted; + } + + public: + void Mount(DLL_TRAITS* to_mount) + { + if (!to_mount || !to_mount->fImageObject) + return; + + fMounted = to_mount; + + if (fLoader && to_mount) + { + delete fLoader; + fLoader = nullptr; + } + + if (!fLoader) + { + fLoader = new PEFLoader(fMounted->fImageObject); + } + } + + void Unmount() + { + if (fMounted) + fMounted = nullptr; + }; + + template + SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) + { + if (symbol_name == nullptr || *symbol_name == 0) + return nullptr; + if (len > kPathLen || len < 1) + return nullptr; + + auto ret = + reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); + + if (!ret) + { + if (kind == kPefCode) + return (VoidPtr)&__zka_pure_call; + + return nullptr; + } + + return ret; + } + + private: + PEFLoader* fLoader{nullptr}; + }; + + typedef IPEFDLLObject* IDLL; + + EXTERN_C IDLL rtl_init_shared_object(UserProcess* header); + EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful); +} // namespace Kernel + +#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */ diff --git a/dev/ZKA/KernelKit/PEFDLLInterface.hxx b/dev/ZKA/KernelKit/PEFDLLInterface.hxx deleted file mode 100644 index d664bfd8..00000000 --- a/dev/ZKA/KernelKit/PEFDLLInterface.hxx +++ /dev/null @@ -1,105 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright ZKA Technologies., all rights reserved. - * - * ======================================================== - */ - -#ifndef __KERNELKIT_SHARED_OBJECT_HXX__ -#define __KERNELKIT_SHARED_OBJECT_HXX__ - -#include -#include -#include -#include - -namespace Kernel -{ - /** - * @brief Shared Library class - * Load library from this class - */ - class PEFDLLInterface final : public DLLInterface - { - public: - explicit PEFDLLInterface() = default; - ~PEFDLLInterface() = default; - - public: - ZKA_COPY_DEFAULT(PEFDLLInterface); - - private: - DLL_TRAITS* fMounted{nullptr}; - - public: - DLL_TRAITS** GetAddressOf() - { - return &fMounted; - } - - DLL_TRAITS* Get() - { - return fMounted; - } - - public: - void Mount(DLL_TRAITS* to_mount) - { - if (!to_mount || !to_mount->fImageObject) - return; - - fMounted = to_mount; - - if (fLoader && to_mount) - { - delete fLoader; - fLoader = nullptr; - } - - if (!fLoader) - { - fLoader = new PEFLoader(fMounted->fImageObject); - } - } - - void Unmount() - { - if (fMounted) - fMounted = nullptr; - }; - - template - SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) - { - if (symbol_name == nullptr || *symbol_name == 0) - return nullptr; - if (len > kPathLen || len < 1) - return nullptr; - - auto ret = - reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); - - if (!ret) - { - if (kind == kPefCode) - return (VoidPtr)&__zka_pure_call; - - return nullptr; - } - - return ret; - } - - private: - PEFLoader* fLoader{nullptr}; - }; - - typedef DLLInterface* DLLInterfacePtr; - - EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header); - EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful); -} // namespace Kernel - -#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */ diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index 78d75af6..d5172fe9 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -10,12 +10,10 @@ #include #include #include -#include #include #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) -#define kSchedMaxStackSz (4096) /* Max stack sz */ #define kSchedProcessLimitPerTeam (16U) //////////////////////////////////////////////////// @@ -29,7 +27,7 @@ namespace Kernel //! @note Forward declarations. class UserProcess; - class PEFDLLInterface; + class IPEFDLLObject; class UserProcessTeam; class UserProcessScheduler; class UserProcessHelper; @@ -148,24 +146,33 @@ namespace Kernel User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; AffinityKind Affinity{AffinityKind::kStandard}; - ProcessStatusKind Status{ProcessStatusKind::kDead}; + ProcessStatusKind Status{ProcessStatusKind::kDead}; UInt8* StackReserve{nullptr}; // Memory, images pointers. - HeapPtrKind HeapCursor{nullptr}; ImagePtr Image{nullptr}; - HeapPtrKind HeapPtr{nullptr}; SizeT StackSize{mib_cast(8)}; - // shared library handle, reserved for kDLLKind types of executables only. - DLLInterface* DLLPtr{nullptr}; - UserProcess* Parent{nullptr}; + //! @brief Shared library handle, reserved for kDLLKind types of executables only. + IPEFDLLObject* DLLPtr{nullptr}; + + /// @brief Parent process, reserved for threads only. + UserProcess* Parent{nullptr}; // Memory usage. - SizeT UsedMemory{0}; - SizeT FreeMemory{0}; - SizeT SizeMemory{mib_cast(64)}; + SizeT MemoryCursor{0}; + SizeT MemoryLimit{gib_cast(128)}; + + struct PROCESS_MEMORY_ENTRY + { + VoidPtr MemoryEntry; + + struct PROCESS_MEMORY_ENTRY *MemoryPrev; + struct PROCESS_MEMORY_ENTRY *MemoryNext; + } * MemoryEntryList{nullptr}; + + SizeT MemoryPD{0}; enum { @@ -213,9 +220,9 @@ namespace Kernel //! @return Int32 local error code. Int32& GetLocalCode() noexcept; - const User* GetOwner() noexcept; + const User* GetOwner() noexcept; const ProcessStatusKind& GetStatus() noexcept; - const AffinityKind& GetAffinity() noexcept; + const AffinityKind& GetAffinity() noexcept; private: UInt32 fLastExitCode{0}; @@ -291,6 +298,7 @@ namespace Kernel STATIC bool CanBeScheduled(UserProcess& process); STATIC PID& TheCurrentPID(); STATIC SizeT StartScheduling(); + STATIC Void Init(); }; const UInt32& sched_get_exit_code(void) noexcept; diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx index df5b0917..c4ff2ee3 100644 --- a/dev/ZKA/Sources/CodeMgr.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -23,7 +23,7 @@ namespace Kernel proc.SetImageStart(reinterpret_cast(main)); proc.Kind = UserProcess::kExeKind; - proc.StackSize = kib_cast(8); + proc.StackSize = kib_cast(4); rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); diff --git a/dev/ZKA/Sources/DLLInterface.cxx b/dev/ZKA/Sources/DLLInterface.cxx deleted file mode 100644 index c18f2f00..00000000 --- a/dev/ZKA/Sources/DLLInterface.cxx +++ /dev/null @@ -1,15 +0,0 @@ -/* - * ======================================================== - * - * newoskrnl - * Copyright ZKA Technologies., all rights reserved. - * - * ======================================================== - */ - -#include -#include - -#include - -using namespace Kernel; diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 88887ec3..75fb24ff 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -189,6 +189,8 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Starting ZKA System...", 20, 10, RGB(0, 0, 0)); + Kernel::UserProcessHelper::Init(); + Kernel::sched_execute_thread(HangCPU, "HANG TEST"); while (Yes) diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index 615f5664..0b54cbcd 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -63,26 +63,26 @@ namespace Kernel Detail::HEAP_INFORMATION_BLOCK_PTR kLatestAllocation = nullptr; - /// @brief Declare a new size for allocatedPtr. - /// @param allocatedPtr the pointer. + /// @brief Declare a new size for ptr_heap. + /// @param ptr_heap the pointer. /// @return - voidPtr mm_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz) + voidPtr mm_realloc_ke_heap(voidPtr ptr_heap, SizeT new_sz) { - if (!allocatedPtr || newSz < 1) + if (!ptr_heap || new_sz < 1) return nullptr; Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( - (UIntPtr)allocatedPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + (UIntPtr)ptr_heap - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heap_blk->fHeapSize = newSz; + heap_blk->fHeapSize = new_sz; if (heap_blk->fCRC32 > 0) { - MUST_PASS(mm_protect_ke_heap(allocatedPtr)); + MUST_PASS(mm_protect_ke_heap(ptr_heap)); } - return allocatedPtr; + return ptr_heap; } /// @brief Allocate chunk of memory. diff --git a/dev/ZKA/Sources/IDLLObject.cxx b/dev/ZKA/Sources/IDLLObject.cxx new file mode 100644 index 00000000..b6b6a348 --- /dev/null +++ b/dev/ZKA/Sources/IDLLObject.cxx @@ -0,0 +1,15 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include +#include + +#include + +using namespace Kernel; diff --git a/dev/ZKA/Sources/IPEFDLLObject.cxx b/dev/ZKA/Sources/IPEFDLLObject.cxx new file mode 100644 index 00000000..913912a4 --- /dev/null +++ b/dev/ZKA/Sources/IPEFDLLObject.cxx @@ -0,0 +1,100 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include +#include + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared sharedObj ABI, except a rtl_init_shared_object and + rtl_fini_shared_object (amlel) 15/02/24: Breaking changes, changed the name of the + routines. (amlel) + + 07/28/24: Replace rt_library_free with rtl_fini_shared_object + + ------------------------------------------- */ + +using namespace Kernel; + +/***********************************************************************************/ +/// @file PEFSharedObjectRT.cxx +/// @brief PEF's shared object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/** @brief Library initializer. */ +/***********************************************************************************/ + +EXTERN_C IDLL rtl_init_shared_object(UserProcess* header) +{ + IDLL sharedObj = tls_new_class(); + + if (!sharedObj) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Mount(tls_new_class()); + + if (!sharedObj->Get()) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Get()->fImageObject = + header->Image; + + if (!sharedObj->Get()->fImageObject) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Get()->fImageEntrypointOffset = + sharedObj->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + + return sharedObj; +} + +/***********************************************************************************/ +/** @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 rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful) +{ + MUST_PASS(successful); + + // sanity check (will also trigger a bug check if this fails) + if (lib == nullptr) + { + *successful = false; + header->Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} diff --git a/dev/ZKA/Sources/PEFDLLInterface.cxx b/dev/ZKA/Sources/PEFDLLInterface.cxx deleted file mode 100644 index 70c68783..00000000 --- a/dev/ZKA/Sources/PEFDLLInterface.cxx +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ======================================================== - * - * newoskrnl - * Copyright ZKA Technologies., all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------- - - Revision History: - - 01/02/24: Rework shared sharedObj ABI, except a rtl_init_shared_object and - rtl_fini_shared_object (amlel) 15/02/24: Breaking changes, changed the name of the - routines. (amlel) - - 07/28/24: Replace rt_library_free with rtl_fini_shared_object - - ------------------------------------------- */ - -using namespace Kernel; - -/***********************************************************************************/ -/// @file PEFSharedObjectRT.cxx -/// @brief PEF's shared object runtime. -/***********************************************************************************/ - -/***********************************************************************************/ -/** @brief Library initializer. */ -/***********************************************************************************/ - -EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header) -{ - DLLInterfacePtr sharedObj = tls_new_class(); - - if (!sharedObj) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Mount(tls_new_class()); - - if (!sharedObj->Get()) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Get()->fImageObject = - header->Image; - - if (!sharedObj->Get()->fImageObject) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Get()->fImageEntrypointOffset = - sharedObj->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - - return sharedObj; -} - -/***********************************************************************************/ -/** @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 rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful) -{ - MUST_PASS(successful); - - // sanity check (will also trigger a bug check if this fails) - if (lib == nullptr) - { - *successful = false; - header->Crash(); - } - - delete lib->Get(); - delete lib; - - lib = nullptr; - - *successful = true; -} diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 48988e57..7c576226 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -6,11 +6,11 @@ /***********************************************************************************/ /// @file UserProcessScheduler.cxx -/// @brief User UserProcess scheduler. +/// @brief User Process scheduler. /***********************************************************************************/ #include -#include +#include #include #include #include @@ -19,7 +19,7 @@ ///! BUGS: 0 /***********************************************************************************/ -/* TODO: Document more the Kernel, sdk and kits. */ +/* TODO: Document the Kernel, SDK and kits. */ /***********************************************************************************/ namespace Kernel @@ -53,7 +53,7 @@ namespace Kernel if (this->Name == 0) return; - kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl; + kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl; this->Exit(kErrorProcessFault); } @@ -83,27 +83,45 @@ namespace Kernel /***********************************************************************************/ + /** @brief Add pointer to entry. */ VoidPtr UserProcess::New(const SizeT& sz) { - if (this->HeapCursor) +#ifdef __ZKA_AMD64__ + auto pd = hal_read_cr3(); + hal_write_cr3(this->MemoryPD); + + auto ptr = mm_new_ke_heap(sz, Yes, Yes); + + hal_write_cr3(reinterpret_cast(pd)); +#else + auto ptr = mm_new_ke_heap(sz, Yes, Yes); +#endif + + if (!this->MemoryEntryList) { - if (this->FreeMemory < 1) - { - ErrLocal() = kErrorHeapOutOfMemory; + this->MemoryEntryList = new UserProcess::PROCESS_MEMORY_ENTRY(); + this->MemoryEntryList->MemoryEntry = ptr; - /* We're going out of memory! crash... */ - this->Crash(); + this->MemoryEntryList->MemoryPrev = nullptr; + this->MemoryEntryList->MemoryNext = nullptr; - return nullptr; - } + return ptr; + } + else + { + auto entry = this->MemoryEntryList; - this->HeapCursor = reinterpret_cast((UIntPtr)this->HeapCursor + (sizeof(sz))); - VoidPtr cursor = this->HeapCursor; + while (entry->MemoryNext) + { + if (entry->MemoryNext) + entry = entry->MemoryNext; + } - ++this->UsedMemory; - --this->FreeMemory; + entry->MemoryNext = new UserProcess::PROCESS_MEMORY_ENTRY(); + entry->MemoryNext->MemoryEntry = ptr; - return cursor; + entry->MemoryNext->MemoryPrev = entry; + entry->MemoryNext->MemoryNext = nullptr; } return nullptr; @@ -111,39 +129,31 @@ namespace Kernel /***********************************************************************************/ - /* @brief checks if runtime pointer is in region. */ - bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz) - { - if (pool == nullptr || - pool_ptr == nullptr) - return false; - - UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr; - UIntPtr* uint_pool = (UIntPtr*)pool; - - return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr && - pool_ptr_cur_sz > pool_ptr_used_sz; - } - - /* @brief free pointer from usage. */ + /** @brief Free pointer from usage. */ Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz) { - if (sz < 1 || this->HeapCursor == this->HeapPtr) - return false; - - // also check for the amount of allocations we've done so far. - if (this->UsedMemory < 1) - return false; + auto entry = this->MemoryEntryList; - if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory)) + while (entry->MemoryNext) { - this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); - rt_zero_memory(ptr, sz); + if (entry->MemoryEntry == ptr) + { +#ifdef __ZKA_AMD64__ + auto pd = hal_read_cr3(); + hal_write_cr3(this->MemoryPD); - ++this->FreeMemory; - --this->UsedMemory; + bool ret = mm_delete_ke_heap(ptr); + hal_write_cr3(reinterpret_cast(pd)); - return true; + return ret; +#else + bool ret = mm_delete_ke_heap(ptr); + return ret; +#endif + } + + if (entry->MemoryNext) + entry = entry->MemoryNext; } return false; @@ -183,7 +193,7 @@ namespace Kernel void UserProcess::Exit(const Int32& exit_code) { this->Status = ProcessStatusKind::kDead; - + fLastExitCode = exit_code; cLastExitCode = exit_code; @@ -211,7 +221,8 @@ namespace Kernel if (this->StackReserve) delete[] this->StackReserve; - cProcessScheduler->Remove(this->ProcessId); + if (this->ProcessId > 0) + UserProcessScheduler::The().Remove(this->ProcessId); } /// @brief Add process to list. @@ -219,73 +230,50 @@ namespace Kernel /// @return the process index inside the team. SizeT UserProcessScheduler::Add(UserProcess& process) { - if (!process.Image) - { - return -kErrorInvalidData; - } +#ifdef __ZKA_AMD64__ + process.MemoryPD = reinterpret_cast(hal_read_cr3()); +#endif // __ZKA_AMD64__ - kcout << "UserProcessScheduler: Adding process to team...\r"; + process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame)); - // Create heap according to type of process. - if (process.Kind == UserProcess::kExeKind) - { - process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true); - } - else if (process.Kind == UserProcess::kDLLKind) - { - process.DLLPtr = rtl_init_shared_object(&process); - process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true); - } - else + if (!process.StackFrame) { - // Something went wrong, do not continue, process may be incorrect. - process.Crash(); return -kErrorProcessFault; } - process.StackFrame = new HAL::StackFrame(); - - if (!process.StackFrame) + // Create heap according to type of process. + if (process.Kind == UserProcess::kDLLKind) { - process.Crash(); - return -kErrorProcessFault; + process.DLLPtr = rtl_init_shared_object(&process); } - + if (process.Image) { // get preferred stack size by app. const auto cMaxStackSize = process.StackSize; - - process.StackReserve = (UInt8*)mm_new_ke_heap(cMaxStackSize, Yes, Yes); + process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize); // if stack pointer isn't valid. if (!process.StackReserve) { - process.StackReserve = (UInt8*)mm_new_ke_heap(kSchedMaxStackSz, Yes, Yes); - kcout << "newoskrnl.exe: Use fallback reserve size.\r"; + return -kErrorProcessFault; } } else { if (process.Kind != UserProcess::kDLLKind) { - process.Crash(); return -kErrorProcessFault; } } - process.Status = ProcessStatusKind::kStarting; - + process.Status = ProcessStatusKind::kStarting; process.ProcessId = mTeam.mProcessAmount; ++mTeam.mProcessAmount; - process.HeapCursor = process.HeapPtr; - mTeam.AsArray()[process.ProcessId] = process; - kcout << "UserProcessScheduler: Adding process to team [ OK ]...\r"; - return process.ProcessId; } @@ -293,11 +281,6 @@ namespace Kernel UserProcessScheduler& UserProcessScheduler::The() { - if (!cProcessScheduler) - { - cProcessScheduler = new UserProcessScheduler(); - } - MUST_PASS(cProcessScheduler); return *cProcessScheduler; } @@ -341,7 +324,7 @@ namespace Kernel if (UserProcessHelper::CanBeScheduled(process)) { // set the current process. - mTeam.AsRef() = process; + mTeam.AsRef() = mTeam.AsArray()[process.ProcessId]; process.PTime = static_cast(process.Affinity); @@ -349,7 +332,7 @@ namespace Kernel // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize], process.StackFrame, - process.ProcessId)) + process.ProcessId)) { process.Crash(); continue; @@ -393,6 +376,14 @@ namespace Kernel return cProcessScheduler->CurrentProcess().Leak().ProcessId; } + Void UserProcessHelper::Init() + { + if (!cProcessScheduler) + { + cProcessScheduler = new UserProcessScheduler(); + } + } + /// @brief Check if process can be schedulded. /// @param process the process reference. /// @retval true can be schedulded. @@ -408,7 +399,7 @@ namespace Kernel if (auto start = process.DLLPtr->Load(kPefStart, rt_string_len(kPefStart), kPefCode); start) { - process.Image = start; + process.Image = start; } } -- cgit v1.2.3 From 518e2ce29513b8d49adf73e76aaf94c4f722dfae Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 09:26:46 +0200 Subject: [ FIX ] Fixed KRNL BMP allocator, which was not working because of badly formatted heap block. [ IMP ] Improve logger routines [ FILE ] LINE : . Signed-off-by: Amlal El Mahrouss --- dev/ZBA/amd64-efi.make | 2 +- dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 30 ++++++---- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx | 8 +-- dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx | 8 +-- dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 2 +- dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx | 6 +- dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx | 6 +- dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 2 +- dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx | 4 +- dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 4 +- dev/ZKA/KernelKit/DebugOutput.hxx | 22 ++++--- dev/ZKA/KernelKit/DriveMgr.hxx | 2 +- dev/ZKA/KernelKit/FileMgr.hxx | 2 +- dev/ZKA/NetworkKit/NetworkDevice.inl | 4 +- dev/ZKA/Sources/CodeMgr.cxx | 2 +- dev/ZKA/Sources/CxxAbi-AMD64.cxx | 2 +- dev/ZKA/Sources/CxxAbi-ARM64.cxx | 2 +- dev/ZKA/Sources/DLLMain.cxx | 26 ++++---- dev/ZKA/Sources/DriveMgr.cxx | 2 +- dev/ZKA/Sources/FS/NewFS.cxx | 70 +++++++++++----------- dev/ZKA/Sources/Heap.cxx | 11 ++-- dev/ZKA/Sources/IndexableProperty.cxx | 2 +- dev/ZKA/Sources/KernelCheck.cxx | 13 ++-- dev/ZKA/Sources/NewFS+FileMgr.cxx | 4 +- dev/ZKA/Sources/ThreadLocalStorage.cxx | 8 +-- dev/ZKA/Sources/User.cxx | 2 +- dev/ZKA/Sources/UserProcessScheduler.cxx | 19 +++--- 27 files changed, 139 insertions(+), 126 deletions(-) (limited to 'dev') diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 497dc8e9..5d5071e0 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -29,7 +29,7 @@ IMG=epm-master-1.img IMG_2=epm-slave.img IMG_3=epm-master-2.img -EMU_FLAGS=-net none -m 12G -M q35 \ +EMU_FLAGS=-net none -m 8G -M q35 \ -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 7bafd075..221cb044 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -37,11 +37,13 @@ namespace Kernel { ptr_bit_set[0] = cVMHMagic; ptr_bit_set[1] = size; + ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; - kcout << "BBP: STATUS\r"; - kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "BBP: ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "ALLOC STATUS\r"; + kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "ALLOC STATUS\r"; if (rw) mm_update_pte(base_ptr, eFlagsRw); @@ -49,10 +51,10 @@ namespace Kernel if (user) mm_update_pte(base_ptr, eFlagsUser); - return (VoidPtr)(&ptr_bit_set[2]); + return (VoidPtr)ptr_bit_set; } - base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + 1 + ptr_bit_set[1]); + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + __BIGGEST_ALIGNMENT__ + ptr_bit_set[1]); } return nullptr; @@ -71,7 +73,7 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); - return &((UIntPtr*)ptr_new)[1]; + return ((UIntPtr*)ptr_new); } auto mm_free_bitmap(VoidPtr page_ptr) -> Bool @@ -79,19 +81,21 @@ namespace Kernel if (!page_ptr) return false; - UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 3; + UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr); if (!ptr_bit_set[0] || ptr_bit_set[0] != cVMHMagic) - return false; + return false; - kcout << "BBP: FREE STATUS\r"; - kcout << "BBP: MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "BBP: ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "BBP: SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "FREE STATUS\r"; + kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "FREE STATUS\r"; ptr_bit_set[0] = 0UL; ptr_bit_set[1] = 0UL; + ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; return true; } diff --git a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index 1bb54588..1be22e7d 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -63,12 +63,12 @@ EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr { if (rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: syscall: enter.\r"; + kcout << "syscall: enter.\r"; if (kSyscalls[rcx].fHooked) (kSyscalls[rcx].fProc)((Kernel::VoidPtr)rdx); - Kernel::kcout << "newoskrnl.exe: syscall: exit.\r"; + kcout << "syscall: exit.\r"; } } @@ -79,11 +79,11 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr { if (rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: kerncall: enter.\r"; + kcout << "kerncall: enter.\r"; if (kKerncalls[rcx].fHooked) (kKerncalls[rcx].fProc)((Kernel::VoidPtr)rdx); - Kernel::kcout << "newoskrnl.exe: kerncall: exit.\r"; + kcout << "kerncall: exit.\r"; } } diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx index b524b04c..f985deb7 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx @@ -191,7 +191,7 @@ namespace Kernel::HAL cSMPInterrupt = 0; kSMPCount = 0; - kcout << "newoskrnl.exe: Probing MADT cores...\r"; + kcout << "Probing MADT cores...\r"; UIntPtr madt_address = kMADTBlock->Address; @@ -205,13 +205,13 @@ namespace Kernel::HAL { case 0x00: { cSMPCores[index] = kMADTBlock->List[index].LAPIC.ProcessorID; - kcout << "newoskrnl.exe: Core ID: " << number(cSMPCores[index]) << endl; + kcout << "Core ID: " << number(cSMPCores[index]) << endl; ++kSMPCount; break; } case 0x05: { madt_address = kMADTBlock->List[index].LAPIC_ADDRESS_OVERRIDE.Address; - kcout << "newoskrnl.exe: Address: " << number(madt_address) << endl; + kcout << "Address: " << number(madt_address) << endl; break; } } @@ -219,7 +219,7 @@ namespace Kernel::HAL ++index; } - kcout << "newoskrnl.exe: # of cores: " << number(kSMPCount) << endl; + kcout << "# of cores: " << number(kSMPCount) << endl; // Kernel is now SMP aware. // That means that the scheduler is now available (on MP Kernels) diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 10916b06..79d9c097 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -125,7 +125,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; + kcout << "Creating filesystem and such.\r"; auto fs = new Kernel::NewFilesystemMgr(); diff --git a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx index 889b8c39..7eaa5bbb 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx @@ -63,7 +63,7 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) { if (ports_implemented) { - kcout << "newoskrnl.exe: Port is implemented by host.\r"; + kcout << "Port is implemented by host.\r"; UInt8 ipm = (mem_ahci->Ports[ahci_index].Ssts >> 8) & 0x0F; UInt8 det = mem_ahci->Ports[ahci_index].Ssts & 0x0F; @@ -72,8 +72,8 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) det == cAhciPresent && ipm == cAhciIPMActive) { - kcout << "newoskrnl.exe: Found AHCI controller.\r"; - kcout << "newoskrnl.exe: Device is of SATA type.\r"; + kcout << "Found AHCI controller.\r"; + kcout << "Device is of SATA type.\r"; detected = true; diff --git a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx index 052f8c64..bc1a1f22 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -68,7 +68,7 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) drv_std_select(IO); - Kernel::kcout << "newoskrnl.exe: Initializing drive...\r"; + kcout << "Initializing drive...\r"; ATAInit_Retry: // Bus init, NEIN bit. @@ -80,7 +80,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { - Kernel::kcout << "newoskrnl.exe: Failing drive...\r"; + kcout << "Failing drive...\r"; return false; } @@ -107,7 +107,7 @@ ATAInit_Retry: OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - Kernel::kcout << "newoskrnl.exe: Created IDE module.\r"; + kcout << "Created IDE module.\r"; return true; } diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index ee06c305..140c3370 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -92,7 +92,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept else Kernel::HAL::mp_get_cores(nullptr); - Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; + kcout << "Creating filesystem and such.\r"; auto fs = new Kernel::NewFilesystemMgr(); diff --git a/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx b/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx index 97950a78..f1f6c718 100644 --- a/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx +++ b/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx @@ -53,13 +53,13 @@ namespace Kernel /// @brief Enable flash memory at slot. STATIC Void drv_enable_flash(Int32 arg) { - kcout << "newoskrnl.exe: Enabled FLSH hardware.\r"; + kcout << "Enabled FLSH hardware.\r"; } /// @brief Disable flash memory at slot. STATIC Void drv_disable_flash(Int32 arg) { - kcout << "newoskrnl.exe: Disabled FLSH hardware.\r"; + kcout << "Disabled FLSH hardware.\r"; } } // namespace Kernel diff --git a/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 5f71380d..254e1ab6 100644 --- a/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -14,11 +14,11 @@ EXTERN_C void rt_syscall_handle(Kernel::HAL::StackFrame* stack) { if (stack->Rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: syscall: enter.\r"; + kcout << "syscall: enter.\r"; if (kSyscalls[stack->Rcx].Leak().Leak().fHooked) (kSyscalls[stack->Rcx].Leak().Leak().fProc)(stack); - Kernel::kcout << "newoskrnl.exe: syscall: exit.\r"; + kcout << "syscall: exit.\r"; } } diff --git a/dev/ZKA/KernelKit/DebugOutput.hxx b/dev/ZKA/KernelKit/DebugOutput.hxx index 66105aa1..70f920d1 100644 --- a/dev/ZKA/KernelKit/DebugOutput.hxx +++ b/dev/ZKA/KernelKit/DebugOutput.hxx @@ -59,21 +59,24 @@ namespace Kernel inline TerminalDevice end_line() { TerminalDevice selfTerm = TerminalDevice::The(); - selfTerm << "\r"; + + selfTerm.operator<<("\r"); return selfTerm; } inline TerminalDevice carriage_return() { TerminalDevice selfTerm = TerminalDevice::The(); - selfTerm << "\r"; + + selfTerm.operator<<("\r"); return selfTerm; } inline TerminalDevice tabulate() { TerminalDevice selfTerm = TerminalDevice::The(); - selfTerm << "\t"; + + selfTerm.operator<<("\t"); return selfTerm; } @@ -81,7 +84,8 @@ namespace Kernel inline TerminalDevice bell() { TerminalDevice selfTerm = TerminalDevice::The(); - selfTerm << "\a"; + + selfTerm.operator<<("\a"); return selfTerm; } @@ -111,7 +115,7 @@ namespace Kernel buf[0] = cNumbers[h]; buf[1] = 0; - term << buf; + term.operator<<(buf); return term; } @@ -139,7 +143,7 @@ namespace Kernel buf[0] = cNumbers[h]; buf[1] = 0; - term << buf; + term.operator<<(buf); return term; } } // namespace Detail @@ -148,7 +152,7 @@ namespace Kernel { TerminalDevice selfTerm = TerminalDevice::The(); - selfTerm << "0x"; + selfTerm.operator<<("0x"); Detail::_write_number_hex(x, selfTerm); return selfTerm; @@ -186,5 +190,5 @@ namespace Kernel #undef kcout #endif // ifdef kcout -#define kcout TerminalDevice::The() -#define endl kcout << Kernel::end_line() +#define kcout (Kernel::TerminalDevice::The() << "\e[0;31m [ " << __FILE__ << ": LINE: " << Kernel::number(__LINE__)); (Kernel::TerminalDevice::The() << " ] \e[0m" << ": ") +#define endl Kernel::TerminalDevice::The() << Kernel::end_line() diff --git a/dev/ZKA/KernelKit/DriveMgr.hxx b/dev/ZKA/KernelKit/DriveMgr.hxx index 4b2cdc73..8cec098c 100644 --- a/dev/ZKA/KernelKit/DriveMgr.hxx +++ b/dev/ZKA/KernelKit/DriveMgr.hxx @@ -116,7 +116,7 @@ namespace Kernel return &mD; default: { ErrLocal() = kErrorNoSuchDisk; - kcout << "newoskrnl.exe: No such disk.\n"; + kcout << "No such disk.\n"; break; } diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index 7a97f821..86c40b69 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -408,7 +408,7 @@ namespace Kernel } } - kcout << "newoskrnl.exe: new file: " << path << ".\r"; + kcout << "new file: " << path << ".\r"; } /// @brief destructor diff --git a/dev/ZKA/NetworkKit/NetworkDevice.inl b/dev/ZKA/NetworkKit/NetworkDevice.inl index 0ae5d9c6..4bc2a153 100644 --- a/dev/ZKA/NetworkKit/NetworkDevice.inl +++ b/dev/ZKA/NetworkKit/NetworkDevice.inl @@ -15,7 +15,7 @@ namespace Kernel void (*on_cleanup)(void)) : DeviceInterface(out, in), fCleanup(on_cleanup) { - kcout << "newoskrnl.exe: NetworkDevice initialized.\r"; + kcout << "NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); } @@ -24,7 +24,7 @@ namespace Kernel { MUST_PASS(fCleanup); - kcout << "newoskrnl.exe: NetworkDevice cleanup.\r"; + kcout << "NetworkDevice cleanup.\r"; if (fCleanup) fCleanup(); diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx index c4ff2ee3..1d4f4a6e 100644 --- a/dev/ZKA/Sources/CodeMgr.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -23,7 +23,7 @@ namespace Kernel proc.SetImageStart(reinterpret_cast(main)); proc.Kind = UserProcess::kExeKind; - proc.StackSize = kib_cast(4); + proc.StackSize = mib_cast(4); rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); diff --git a/dev/ZKA/Sources/CxxAbi-AMD64.cxx b/dev/ZKA/Sources/CxxAbi-AMD64.cxx index 0b26e9da..908e26f4 100644 --- a/dev/ZKA/Sources/CxxAbi-AMD64.cxx +++ b/dev/ZKA/Sources/CxxAbi-AMD64.cxx @@ -19,7 +19,7 @@ Kernel::UIntPtr __dso_handle; EXTERN_C void __cxa_pure_virtual() { - Kernel::kcout << "newoskrnl.exe: C++ placeholder method.\n"; + kcout << "C++ placeholder method.\n"; } EXTERN_C void ___chkstk_ms(void) diff --git a/dev/ZKA/Sources/CxxAbi-ARM64.cxx b/dev/ZKA/Sources/CxxAbi-ARM64.cxx index c11baf72..679be041 100644 --- a/dev/ZKA/Sources/CxxAbi-ARM64.cxx +++ b/dev/ZKA/Sources/CxxAbi-ARM64.cxx @@ -68,7 +68,7 @@ EXTERN_C void __cdecl _Init_thread_footer(int* const pOnce) noexcept EXTERN_C void _purecall() { - Kernel::kcout << "newoskrnl.exe: C++ placeholder method.\n"; + kcout << "C++ placeholder method.\n"; } #endif // ifdef __ZKA_ARM64__ diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 75fb24ff..db1a80d1 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -52,7 +52,7 @@ namespace Kernel::Detail { if (Kernel::FilesystemMgrInterface::GetMounted()) { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); fNewFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); } else @@ -62,7 +62,7 @@ namespace Kernel::Detail Kernel::FilesystemMgrInterface::Mount(fNewFS); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } const Kernel::SizeT cDirCount = 7UL; @@ -79,8 +79,8 @@ namespace Kernel::Detail if (catalogDir) { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog directory already exists: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory already exists: ")), RGB(0, 0, 0)); delete catalogDir; continue; @@ -89,8 +89,8 @@ namespace Kernel::Detail catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, kNewFSCatalogKindDir); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog directory has been created: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory has been created: ")), RGB(0, 0, 0)); delete catalogDir; } @@ -102,15 +102,15 @@ namespace Kernel::Detail if (catalogDisk) { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog swap file already exists: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file already exists: ")), RGB(0, 0, 0)); delete catalogDisk; } else { - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("newoskrnl.exe: Catalog swap file created: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file created: ")), RGB(0, 0, 0)); catalogDisk = (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(kSysPage); @@ -184,10 +184,10 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawWindowList(&cKernelWnd, 1); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Running System Component: ", 10, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("newoskrnl.exe: Running System Component: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Running System Component: ", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running System Component: ")), RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Starting ZKA System...", 20, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0)); Kernel::UserProcessHelper::Init(); diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx index 376eb158..e39c9c33 100644 --- a/dev/ZKA/Sources/DriveMgr.cxx +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -139,7 +139,7 @@ namespace Kernel trait.fVerify = ke_drv_check_disk; trait.fDriveKind = io_drive_kind; - kcout << "newoskrnl.exe: Construct drive with success.\r"; + kcout << "Construct drive with success.\r"; return trait; } diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx index e3ec6184..37b2a44c 100644 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ b/dev/ZKA/Sources/FS/NewFS.cxx @@ -67,7 +67,7 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork : catalog->ResourceFork; - kcout << "newoskrnl.exe: fork lba: " << hex_number(lba) << endl; + kcout << "fork lba: " << hex_number(lba) << endl; if (lba <= kNewFSCatalogStartAddress) return nullptr; @@ -96,22 +96,22 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata if (curFork.NextSibling > kBadAddress) { - kcout << "newoskrnl.exe: bad fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; break; } - kcout << "newoskrnl.exe: next fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; if (curFork.Flags == kNewFSFlagCreated) { - kcout << "newoskrnl.exe: fork already exists.\r"; + kcout << "fork already exists.\r"; /// sanity check. if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && StringBuilder::Equals(curFork.CatalogName, catalog->Name)) return nullptr; - kcout << "newoskrnl.exe: next fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; lbaOfPreviousFork = lba; lba = curFork.NextSibling; @@ -153,10 +153,10 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata drv.fOutput(&drv.fPacket); /// log what we have now. - kcout << "newoskrnl.exe: Wrote fork data at: " << hex_number(theFork.DataOffset) + kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) << endl; - kcout << "newoskrnl.exe: Wrote fork at: " << hex_number(lba) << endl; + kcout << "Wrote fork at: " << hex_number(lba) << endl; return &theFork; } @@ -241,11 +241,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { - kcout << "newoskrnl.exe: CreateCatalog(...)\r"; + kcout << "CreateCatalog(...)\r"; Lba out_lba = 0UL; - kcout << "newoskrnl.exe: Checking for extension...\r"; + kcout << "Checking for extension...\r"; /// a directory should have a slash in the end. if (kind == kNewFSCatalogKindDir && @@ -261,7 +261,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (catalog_copy) { - kcout << "newoskrnl.exe: Catalog already exists: " << name << ".\r"; + kcout << "Catalog already exists: " << name << ".\r"; ErrLocal() = kErrorFileExists; return catalog_copy; @@ -276,7 +276,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (*parentName == 0) { - kcout << "newoskrnl.exe: Parent name is NUL.\r"; + kcout << "Parent name is NUL.\r"; ErrLocal() = kErrorFileNotFound; return nullptr; } @@ -308,7 +308,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, if (catalog && catalog->Kind == kNewFSCatalogKindFile) { - kcout << "newoskrnl.exe: Parent name is file.\r"; + kcout << "Parent name is file.\r"; delete catalog; return nullptr; } @@ -433,9 +433,9 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, drive.fOutput(&drive.fPacket); - kcout << "newoskrnl.exe: Create new catalog, status: " + kcout << "Create new catalog, status: " << hex_number(catalogChild->Flags) << endl; - kcout << "newoskrnl.exe: Create new catalog, name: " << catalogChild->Name + kcout << "Create new catalog, name: " << catalogChild->Name << endl; delete catalog; @@ -599,14 +599,14 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL drive->fOutput(&drive->fPacket); - kcout << "newoskrnl.exe: drive kind: " << drive->fDriveKind() << endl; + kcout << "drive kind: " << drive->fDriveKind() << endl; - kcout << "newoskrnl.exe: partition name: " << partBlock->PartitionName << endl; - kcout << "newoskrnl.exe: start: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "newoskrnl.exe: number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "newoskrnl.exe: free catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "newoskrnl.exe: free sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "newoskrnl.exe: sector size: " << hex_number(partBlock->SectorSize) << endl; + kcout << "partition name: " << partBlock->PartitionName << endl; + kcout << "start: " << hex_number(partBlock->StartCatalog) << endl; + kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; + kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl; + kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl; + kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl; // write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); @@ -614,7 +614,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL return true; } - kcout << "newoskrnl.exe: partition block already exists.\r"; + kcout << "partition block already exists.\r"; start += partBlock->DiskSize; @@ -659,7 +659,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool { ErrLocal() = kErrorDiskIsCorrupted; - kcout << "newoskrnl.exe: Invalid fork offset.\r"; + kcout << "Invalid fork offset.\r"; return false; } @@ -688,7 +688,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool drive.fPacket.fPacketSize = sizeOfData; drive.fPacket.fLba = startFork + sizeof(NFS_FORK_STRUCT); - kcout << "newoskrnl.exe: data offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; drive.fOutput(&drive.fPacket); @@ -698,7 +698,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool drive.fOutput(&drive.fPacket); - kcout << "newoskrnl.exe: wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; delete catalog; @@ -721,7 +721,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogName, Lba& out_lba) { - kcout << "newoskrnl.exe: start finding catalog...\r"; + kcout << "start finding catalog...\r"; NFS_ROOT_PARTITION_BLOCK fs_buf{0}; auto drive = sMountpointInterface.A(); @@ -789,7 +789,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogN } } - kcout << "newoskrnl.exe: fetching catalog...\r"; + kcout << "fetching catalog...\r"; NewFSSearchThroughCatalogList: while (drive.fPacket.fPacketGood) @@ -813,8 +813,8 @@ NewFSSearchThroughCatalogList: NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); - kcout << "newoskrnl.exe: found catalog at: " << hex_number(startCatalogList) << endl; - kcout << "newoskrnl.exe: found catalog at: " << catalog->Name << endl; + kcout << "found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "found catalog at: " << catalog->Name << endl; out_lba = startCatalogList; return catalogPtr; @@ -944,7 +944,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; - kcout << "newoskrnl.exe: catalog " << catalog->Name + kcout << "catalog " << catalog->Name << ", fork: " << hex_number(dataForkLba) << endl; NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); @@ -965,8 +965,8 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, fs_fork_data = fs_buf; - kcout << "newoskrnl.exe: ForkName: " << fs_fork_data->ForkName << endl; - kcout << "newoskrnl.exe: CatalogName: " << fs_fork_data->CatalogName << endl; + kcout << "ForkName: " << fs_fork_data->ForkName << endl; + kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) @@ -1028,18 +1028,18 @@ namespace Kernel::Detail /***********************************************************************************/ Boolean fs_init_newfs(Void) noexcept { - kcout << "newoskrnl.exe: Creating drives...\r"; + kcout << "Creating drives...\r"; sMountpointInterface.A() = io_construct_main_drive(); sMountpointInterface.B() = io_construct_drive(); sMountpointInterface.C() = io_construct_drive(); sMountpointInterface.D() = io_construct_drive(); - kcout << "newoskrnl.exe: Testing A:\r"; + kcout << "Testing A:\r"; sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - kcout << "newoskrnl.exe: Testing A: [ OK ]\r"; + kcout << "Testing A: [ OK ]\r"; return true; } diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index 0b54cbcd..1f9af6a2 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -20,7 +20,7 @@ namespace Kernel { SizeT kHeapCount = 0UL; PageMgr kHeapPageMgr; - Bool kOperationInProgress = No; + Bool kHeapLock = No; /// @brief Contains data structures and algorithms for the heap. namespace Detail @@ -52,12 +52,12 @@ namespace Kernel Void mm_alloc_init_timeout(Void) noexcept { - kOperationInProgress = Yes; + kHeapLock = Yes; } Void mm_alloc_fini_timeout(Void) noexcept { - kOperationInProgress = No; + kHeapLock = No; } } // namespace Detail @@ -111,7 +111,7 @@ namespace Kernel heap_info_ptr->fHeapPtr = reinterpret_cast(heap_info_ptr) + sizeof(Detail::HEAP_INFORMATION_BLOCK); heap_info_ptr->fPage = No; heap_info_ptr->fUser = user; - heap_info_ptr->fPresent = No; + heap_info_ptr->fPresent = Yes; ++kHeapCount; @@ -168,6 +168,7 @@ namespace Kernel if (heap_blk && heap_blk->fMagic == kKernelHeapMagic) { + if (!heap_blk->fPresent) { Detail::mm_alloc_fini_timeout(); @@ -196,6 +197,8 @@ namespace Kernel PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); Ref pteAddress{pageWrapper}; + kcout << "Freeing pointer address: " << hex_number(reinterpret_cast(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)) << endl; + kHeapPageMgr.Free(pteAddress); --kHeapCount; diff --git a/dev/ZKA/Sources/IndexableProperty.cxx b/dev/ZKA/Sources/IndexableProperty.cxx index 84aabc6b..a5f1bc0b 100644 --- a/dev/ZKA/Sources/IndexableProperty.cxx +++ b/dev/ZKA/Sources/IndexableProperty.cxx @@ -52,7 +52,7 @@ namespace Kernel indexer.AddFlag(kIndexerClaimed); rt_copy_memory((VoidPtr)indexer.Leak().Path, (VoidPtr)filename, filenameLen); - kcout << "newoskrnl.exe: filesystem: index new file: " << filename << endl; + kcout << "filesystem: index new file: " << filename << endl; } } } // namespace Indexer diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index 0ed96593..acc01dec 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -99,11 +99,16 @@ namespace Kernel RecoveryFactory::Recover(); break; case RUNTIME_CHECK_UNEXCPECTED: { - CGDrawString("0x0000000B Catasrophic Kernel failure.", start_y, x, panicTxt); + CGDrawString("0x0000000B Unexpected Kernel failure.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: { + CGDrawString("0x10000001 Out of Virtual Memory. (Catastrophic Failure)", start_y, x, panicTxt); + RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_FAILED: { - CGDrawString("0x10000001 Kernel bug-check failure.", start_y, x, panicTxt); + CGDrawString("0x10000001 Kernel Check.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } @@ -129,8 +134,8 @@ namespace Kernel { if (!expr) { - kcout << "ASSERTION FAILED: FILE: " << file << endl; - kcout << "ASSERTION FAILED: LINE: " << line << endl; + kcout << "FAILED: FILE: " << file << endl; + kcout << "FAILED: LINE: " << line << endl; ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed } diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx index dd0d4a21..1ffa774a 100644 --- a/dev/ZKA/Sources/NewFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NewFS+FileMgr.cxx @@ -21,12 +21,12 @@ namespace Kernel fImpl = new NewFSParser(); MUST_PASS(fImpl); - kcout << "newoskrnl.exe: We are done here... (NewFilesystemMgr).\r"; + kcout << "We are done here... (NewFilesystemMgr).\r"; } NewFilesystemMgr::~NewFilesystemMgr() { - kcout << "newoskrnl.exe: Destroying it...\r"; + kcout << "Destroying it...\r"; if (fImpl) { diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index e68593f6..35f2dbcd 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -72,7 +72,7 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(the_tib); - kcout << "newoskrnl.exe: checking for a valid cookie inside the TIB...\r"; + kcout << "checking for a valid cookie inside the TIB...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -87,7 +87,7 @@ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { if (!tib_ptr) { - kcout << "newoskrnl.exe: failing because of an invalid TIB...\r"; + kcout << "failing because of an invalid TIB...\r"; return false; } @@ -95,10 +95,10 @@ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept if (!tls_check_tib(tib_struct)) { - kcout << "newoskrnl.exe: crashing because of an invalid TIB...\r"; + kcout << "crashing because of an invalid TIB...\r"; return false; } - kcout << "newoskrnl.exe: Verification succeeded! staying alive...\r"; + kcout << "Verification succeeded! staying alive...\r"; return true; } diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 5aa688be..066a3e06 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -99,7 +99,7 @@ namespace Kernel delete[] password; password = nullptr; - kcout << "newoskrnl.exe: Saved password...\r"; + kcout << "Saved password...\r"; return true; } diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 7c576226..4d74a5b3 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -234,10 +234,11 @@ namespace Kernel process.MemoryPD = reinterpret_cast(hal_read_cr3()); #endif // __ZKA_AMD64__ - process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame)); + process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame)); if (!process.StackFrame) { + process.Crash(); return -kErrorProcessFault; } @@ -246,16 +247,16 @@ namespace Kernel { process.DLLPtr = rtl_init_shared_object(&process); } - + if (process.Image) { // get preferred stack size by app. const auto cMaxStackSize = process.StackSize; process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize); - // if stack pointer isn't valid. - if (!process.StackReserve) + if (process.StackReserve) { + process.Crash(); return -kErrorProcessFault; } } @@ -296,11 +297,7 @@ namespace Kernel // check if process is within range. if (processSlot > mTeam.AsArray().Count()) return false; - - // also check if the process isn't a dummy one. - if (mTeam.AsArray()[processSlot].Image == nullptr) - return false; - + kcout << "UserProcessScheduler: Removing process...\r"; mTeam.AsArray()[processSlot].Status = ProcessStatusKind::kDead; @@ -427,7 +424,7 @@ namespace Kernel if (!stack || !frame_ptr || !image_ptr || new_pid < 0) return false; - kcout << "newoskrnl.exe: Finding hardware thread...\r"; + kcout << "Finding hardware thread...\r"; for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index) { @@ -446,7 +443,7 @@ namespace Kernel UserProcessHelper::TheCurrentPID() = new_pid; - kcout << "newoskrnl.exe: Found hardware thread...\r"; + kcout << "Found hardware thread...\r"; bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); -- cgit v1.2.3 From 270223aea3a48f2d250525869c30fff418356ef3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 10:50:15 +0200 Subject: [ IMP ] Use Busy flag for MP scheduler. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/Sources/MP.cxx | 8 ++++++-- dev/ZKA/Sources/UserProcessScheduler.cxx | 24 +++++++----------------- 2 files changed, 13 insertions(+), 19 deletions(-) (limited to 'dev') diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx index c5cab5dc..0e109b66 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/MP.cxx @@ -94,14 +94,18 @@ namespace Kernel if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) { - return mp_register_process(fStack); + this->Busy(true); + Bool ret = mp_register_process(fStack); + this->Busy(true); + + return ret; } else { mp_do_context_switch_pre(); mp_do_context_switch(image, stack_ptr, fStack); - return false; + return true; } } diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 4d74a5b3..733e19ed 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -19,7 +19,7 @@ ///! BUGS: 0 /***********************************************************************************/ -/* TODO: Document the Kernel, SDK and kits. */ +/** TODO: Document the Kernel, SDK and kits. */ /***********************************************************************************/ namespace Kernel @@ -31,7 +31,7 @@ namespace Kernel STATIC UInt32 cLastExitCode = 0U; /***********************************************************************************/ - /// @brief UserProcess scheduler instance. + /// @brief User Process scheduler global object. /***********************************************************************************/ STATIC UserProcessScheduler* cProcessScheduler = nullptr; @@ -289,18 +289,16 @@ namespace Kernel /***********************************************************************************/ /// @brief Remove process from list. - /// @param processSlot process slot inside team. + /// @param process_id process slot inside team. /// @retval true process was removed. /// @retval false process doesn't exist in team. - Bool UserProcessScheduler::Remove(ProcessID processSlot) + Bool UserProcessScheduler::Remove(ProcessID process_id) { // check if process is within range. - if (processSlot > mTeam.AsArray().Count()) + if (process_id > mTeam.AsArray().Count()) return false; - - kcout << "UserProcessScheduler: Removing process...\r"; - - mTeam.AsArray()[processSlot].Status = ProcessStatusKind::kDead; + + mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead; --mTeam.mProcessAmount; return true; @@ -424,8 +422,6 @@ namespace Kernel if (!stack || !frame_ptr || !image_ptr || new_pid < 0) return false; - kcout << "Finding hardware thread...\r"; - for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index) { if (HardwareThreadScheduler::The()[index].Leak()->Kind() == kInvalidHart) @@ -439,16 +435,10 @@ namespace Kernel HardwareThreadScheduler::The()[index].Leak()->Kind() != ThreadKind::kHartSystemReserved) { - HardwareThreadScheduler::The()[index].Leak()->Busy(true); - UserProcessHelper::TheCurrentPID() = new_pid; - kcout << "Found hardware thread...\r"; - bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); - HardwareThreadScheduler::The()[index].Leak()->Busy(false); - return ret; } } -- cgit v1.2.3 From 3e2b931d65582284e9716c42a902cab6d279c7f0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 11:54:27 +0200 Subject: [ IMP ] Add Interrupt for scheduler (for APIC, maybe PIT?) [ IMP ] Fixed user scheduler context switching. Signed-off-by: Amlal El Mahrouss --- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx | 5 + dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx | 2 +- dev/ZKA/KernelKit/HardwareThreadScheduler.hxx | 129 +++++++++++++ dev/ZKA/KernelKit/MP.hxx | 129 ------------- dev/ZKA/KernelKit/UserProcessScheduler.hxx | 12 +- dev/ZKA/Sources/HardwareThreadScheduler.cxx | 200 +++++++++++++++++++++ dev/ZKA/Sources/MP.cxx | 197 -------------------- dev/ZKA/Sources/UserProcessScheduler.cxx | 9 +- 8 files changed, 348 insertions(+), 335 deletions(-) create mode 100644 dev/ZKA/KernelKit/HardwareThreadScheduler.hxx delete mode 100644 dev/ZKA/KernelKit/MP.hxx create mode 100644 dev/ZKA/Sources/HardwareThreadScheduler.cxx delete mode 100644 dev/ZKA/Sources/MP.cxx (limited to 'dev') diff --git a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index 1be22e7d..b49a688f 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -28,6 +28,11 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } +EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) +{ + Kernel::UserProcessHelper::StartScheduling(); +} + /// @brief Handle math fault. /// @param rsp EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx index f985deb7..5f6c0552 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx @@ -16,7 +16,7 @@ // Needed for SMP. // #include -#include +#include #define kApicSignature "APIC" diff --git a/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx new file mode 100644 index 00000000..cf5d6754 --- /dev/null +++ b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx @@ -0,0 +1,129 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __INC_MP_MANAGER_HPP__ +#define __INC_MP_MANAGER_HPP__ + +#include +#include +#include + +/// @note Last Rev Sun 28 Jul CET 2024 +/// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM + +#define cMaxHWThreads (8U) + +namespace Kernel +{ + class HardwareThread; + class HardwareThreadScheduler; + + using ThreadID = UInt32; + + enum ThreadKind + { + kHartSystemReserved, // System reserved thread, well user can't use it + kHartStandard, // user thread, cannot be used by Kernel + kHartFallback, // fallback thread, cannot be used by user if not clear or + // used by Kernel. + kHartBoot, // The core we booted from, the mama. + kInvalidHart, + kHartCount, + }; + + typedef enum ThreadKind ThreadKind; + typedef ThreadID ThreadID; + + /// + /// \name HardwareThread + /// \brief Abstraction over the CPU's core, used to run processes or threads. + /// + + class HardwareThread final + { + public: + explicit HardwareThread(); + ~HardwareThread(); + + public: + ZKA_COPY_DEFAULT(HardwareThread) + + public: + operator bool(); + + public: + void Wake(const bool wakeup = false) noexcept; + void Busy(const bool busy = false) noexcept; + + public: + bool Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame); + bool IsWakeup() noexcept; + + public: + HAL::StackFramePtr StackFrame() noexcept; + const ThreadKind& Kind() noexcept; + bool IsBusy() noexcept; + const ThreadID& ID() noexcept; + + private: + HAL::StackFramePtr fStack{nullptr}; + ThreadKind fKind{ThreadKind::kHartStandard}; + ThreadID fID{0}; + ProcessID fSourcePID{-1}; + bool fWakeup{false}; + bool fBusy{false}; + + private: + friend class HardwareThreadScheduler; + }; + + /// + /// \name HardwareThreadScheduler + /// \brief Class to manage the thread scheduling. + /// + + class HardwareThreadScheduler final + { + private: + explicit HardwareThreadScheduler(); + + public: + ~HardwareThreadScheduler(); + ZKA_COPY_DEFAULT(HardwareThreadScheduler); + + public: + HAL::StackFramePtr Leak() noexcept; + + public: + Ref operator[](const SizeT& idx); + bool operator!() noexcept; + operator bool() noexcept; + + public: + /// @brief Shared instance of the MP Mgr. + /// @return the reference to the mp manager class. + STATIC HardwareThreadScheduler& The(); + + public: + /// @brief Returns the amount of threads present in the system. + /// @returns SizeT the amount of cores present. + SizeT Count() noexcept; + + private: + Array fThreadList; + ThreadID fCurrentThread{0}; + }; + + /// @brief wakes up thread. + /// wakes up thread from hang. + Void mp_wakeup_thread(HAL::StackFramePtr stack); + + /// @brief makes thread sleep. + /// hooks and hangs thread to prevent code from executing. + Void mp_hang_thread(HAL::StackFramePtr stack); +} // namespace Kernel + +#endif // !__INC_MP_MANAGER_HPP__ diff --git a/dev/ZKA/KernelKit/MP.hxx b/dev/ZKA/KernelKit/MP.hxx deleted file mode 100644 index cf5d6754..00000000 --- a/dev/ZKA/KernelKit/MP.hxx +++ /dev/null @@ -1,129 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef __INC_MP_MANAGER_HPP__ -#define __INC_MP_MANAGER_HPP__ - -#include -#include -#include - -/// @note Last Rev Sun 28 Jul CET 2024 -/// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM - -#define cMaxHWThreads (8U) - -namespace Kernel -{ - class HardwareThread; - class HardwareThreadScheduler; - - using ThreadID = UInt32; - - enum ThreadKind - { - kHartSystemReserved, // System reserved thread, well user can't use it - kHartStandard, // user thread, cannot be used by Kernel - kHartFallback, // fallback thread, cannot be used by user if not clear or - // used by Kernel. - kHartBoot, // The core we booted from, the mama. - kInvalidHart, - kHartCount, - }; - - typedef enum ThreadKind ThreadKind; - typedef ThreadID ThreadID; - - /// - /// \name HardwareThread - /// \brief Abstraction over the CPU's core, used to run processes or threads. - /// - - class HardwareThread final - { - public: - explicit HardwareThread(); - ~HardwareThread(); - - public: - ZKA_COPY_DEFAULT(HardwareThread) - - public: - operator bool(); - - public: - void Wake(const bool wakeup = false) noexcept; - void Busy(const bool busy = false) noexcept; - - public: - bool Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame); - bool IsWakeup() noexcept; - - public: - HAL::StackFramePtr StackFrame() noexcept; - const ThreadKind& Kind() noexcept; - bool IsBusy() noexcept; - const ThreadID& ID() noexcept; - - private: - HAL::StackFramePtr fStack{nullptr}; - ThreadKind fKind{ThreadKind::kHartStandard}; - ThreadID fID{0}; - ProcessID fSourcePID{-1}; - bool fWakeup{false}; - bool fBusy{false}; - - private: - friend class HardwareThreadScheduler; - }; - - /// - /// \name HardwareThreadScheduler - /// \brief Class to manage the thread scheduling. - /// - - class HardwareThreadScheduler final - { - private: - explicit HardwareThreadScheduler(); - - public: - ~HardwareThreadScheduler(); - ZKA_COPY_DEFAULT(HardwareThreadScheduler); - - public: - HAL::StackFramePtr Leak() noexcept; - - public: - Ref operator[](const SizeT& idx); - bool operator!() noexcept; - operator bool() noexcept; - - public: - /// @brief Shared instance of the MP Mgr. - /// @return the reference to the mp manager class. - STATIC HardwareThreadScheduler& The(); - - public: - /// @brief Returns the amount of threads present in the system. - /// @returns SizeT the amount of cores present. - SizeT Count() noexcept; - - private: - Array fThreadList; - ThreadID fCurrentThread{0}; - }; - - /// @brief wakes up thread. - /// wakes up thread from hang. - Void mp_wakeup_thread(HAL::StackFramePtr stack); - - /// @brief makes thread sleep. - /// hooks and hangs thread to prevent code from executing. - Void mp_hang_thread(HAL::StackFramePtr stack); -} // namespace Kernel - -#endif // !__INC_MP_MANAGER_HPP__ diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index d5172fe9..9585da29 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -52,12 +52,12 @@ namespace Kernel //! to run. enum class AffinityKind : Int32 { - kRealTime = 0500, - kVeryHigh = 2500, - kHigh = 2000, - kStandard = 1500, - kLowUsage = 1000, - kVeryLowUsage = 5000, + kRealTime = 500, + kVeryHigh = 250, + kHigh = 200, + kStandard = 1000, + kLowUsage = 1500, + kVeryLowUsage = 2000, }; // operator overloading. diff --git a/dev/ZKA/Sources/HardwareThreadScheduler.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx new file mode 100644 index 00000000..b130ef63 --- /dev/null +++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx @@ -0,0 +1,200 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include + +///! BUGS: 0 + +///! @file MP.cxx +///! @brief This file handles multi processing in the Kernel. +///! @brief Multi processing is needed for multi-tasking operations. + +namespace Kernel +{ + ///! A HardwareThread class takes care of it's owned hardware thread. + ///! It has a stack for it's core. + + ///! @brief C++ constructor. + HardwareThread::HardwareThread() = default; + + ///! @brief C++ destructor. + HardwareThread::~HardwareThread() = default; + + //! @brief returns the id of the thread. + const ThreadID& HardwareThread::ID() noexcept + { + return fID; + } + + //! @brief returns the kind of thread we have. + const ThreadKind& HardwareThread::Kind() noexcept + { + return fKind; + } + + //! @brief is the thread busy? + Bool HardwareThread::IsBusy() noexcept + { + return fBusy; + } + + /// @brief Get processor stack frame. + + HAL::StackFramePtr HardwareThread::StackFrame() noexcept + { + MUST_PASS(fStack); + return fStack; + } + + Void HardwareThread::Busy(const Bool busy) noexcept + { + fBusy = busy; + } + + HardwareThread::operator bool() + { + return fStack; + } + + /// @brief Wakeup the processor. + + Void HardwareThread::Wake(const bool wakeup) noexcept + { + fWakeup = wakeup; + + if (!fWakeup) + mp_hang_thread(fStack); + else + mp_wakeup_thread(fStack); + } + + /// @note Those symbols are needed in order to switch and validate the stack. + + EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr); + EXTERN_C Bool mp_register_process(HAL::StackFramePtr stackPtr); + + /// @brief Switch to hardware thread. + /// @param stack the new hardware thread. + /// @retval true stack was changed, code is running. + /// @retval false stack is invalid, previous code is running. + Bool HardwareThread::Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame) + { + if (!frame || + !image || + !stack_ptr) + return false; + + if (this->IsBusy()) + return false; + + fStack = frame; + + if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) + { + this->Busy(true); + Bool ret = mp_register_process(fStack); + this->Busy(true); + + return ret; + } + else + { + mp_do_context_switch_pre(); + mp_do_context_switch(image, stack_ptr, fStack); + + return true; + } + } + + ///! @brief Tells if processor is waked up. + bool HardwareThread::IsWakeup() noexcept + { + return fWakeup; + } + + ///! @brief Internal Hardware Thread list. + STATIC HardwareThread cThreadList[cMaxHWThreads]; + + ///! @brief Constructor and destructors. + + ///! @brief Default constructor. + HardwareThreadScheduler::HardwareThreadScheduler() = default; + + ///! @brief Default destructor. + HardwareThreadScheduler::~HardwareThreadScheduler() = default; + + /// @brief Shared singleton function + HardwareThreadScheduler& HardwareThreadScheduler::The() + { + STATIC HardwareThreadScheduler sched; + return sched; + } + + /// @brief Get Stack Frame of Core + HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept + { + return fThreadList[fCurrentThread].fStack; + } + + /** + * Get Hardware thread at index. + * @param idx the index + * @return the reference to the hardware thread. + */ + Ref HardwareThreadScheduler::operator[](const SizeT& idx) + { + if (idx == 0) + { + if (fThreadList[idx].Kind() != kHartSystemReserved) + { + fThreadList[idx].fKind = kHartBoot; + } + } + else if (idx >= cMaxHWThreads) + { + static HardwareThread* fakeThread = new HardwareThread(); + + if (!fakeThread) + { + fakeThread = new HardwareThread(); + } + + fakeThread->fKind = kInvalidHart; + + return {fakeThread}; + } + + return &fThreadList[idx]; + } + + /** + * Check if thread pool isn't empty. + * @return + */ + HardwareThreadScheduler::operator bool() noexcept + { + return !fThreadList.Empty(); + } + + /** + * Reverse operator bool + * @return + */ + bool HardwareThreadScheduler::operator!() noexcept + { + return fThreadList.Empty(); + } + + /// @brief Returns the amount of core present. + /// @return the number of cores. + SizeT HardwareThreadScheduler::Count() noexcept + { + return fThreadList.Count(); + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx deleted file mode 100644 index 0e109b66..00000000 --- a/dev/ZKA/Sources/MP.cxx +++ /dev/null @@ -1,197 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include - -///! BUGS: 0 - -///! @file MP.cxx -///! @brief This file handles multi processing in the Kernel. -///! @brief Multi processing is needed for multi-tasking operations. - -namespace Kernel -{ - ///! A HardwareThread class takes care of it's owned hardware thread. - ///! It has a stack for it's core. - - ///! @brief C++ constructor. - HardwareThread::HardwareThread() = default; - - ///! @brief C++ destructor. - HardwareThread::~HardwareThread() = default; - - //! @brief returns the id of the thread. - const ThreadID& HardwareThread::ID() noexcept - { - return fID; - } - - //! @brief returns the kind of thread we have. - const ThreadKind& HardwareThread::Kind() noexcept - { - return fKind; - } - - //! @brief is the thread busy? - Bool HardwareThread::IsBusy() noexcept - { - return fBusy; - } - - /// @brief Get processor stack frame. - - HAL::StackFramePtr HardwareThread::StackFrame() noexcept - { - MUST_PASS(fStack); - return fStack; - } - - Void HardwareThread::Busy(const Bool busy) noexcept - { - fBusy = busy; - } - - HardwareThread::operator bool() - { - return fStack; - } - - /// @brief Wakeup the processor. - - Void HardwareThread::Wake(const bool wakeup) noexcept - { - fWakeup = wakeup; - - if (!fWakeup) - mp_hang_thread(fStack); - else - mp_wakeup_thread(fStack); - } - - /// @note Those symbols are needed in order to switch and validate the stack. - - EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr); - EXTERN_C Bool mp_register_process(HAL::StackFramePtr stackPtr); - - /// @brief Switch to hardware thread. - /// @param stack the new hardware thread. - /// @retval true stack was changed, code is running. - /// @retval false stack is invalid, previous code is running. - Bool HardwareThread::Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame) - { - if (!frame || - !image || - !stack_ptr) - return false; - - fStack = frame; - - if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) - { - this->Busy(true); - Bool ret = mp_register_process(fStack); - this->Busy(true); - - return ret; - } - else - { - mp_do_context_switch_pre(); - mp_do_context_switch(image, stack_ptr, fStack); - - return true; - } - } - - ///! @brief Tells if processor is waked up. - bool HardwareThread::IsWakeup() noexcept - { - return fWakeup; - } - - ///! @brief Internal Hardware Thread list. - STATIC HardwareThread cThreadList[cMaxHWThreads]; - - ///! @brief Constructor and destructors. - - ///! @brief Default constructor. - HardwareThreadScheduler::HardwareThreadScheduler() = default; - - ///! @brief Default destructor. - HardwareThreadScheduler::~HardwareThreadScheduler() = default; - - /// @brief Shared singleton function - HardwareThreadScheduler& HardwareThreadScheduler::The() - { - STATIC HardwareThreadScheduler sched; - return sched; - } - - /// @brief Get Stack Frame of Core - HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept - { - return fThreadList[fCurrentThread].fStack; - } - - /** - * Get Hardware thread at index. - * @param idx the index - * @return the reference to the hardware thread. - */ - Ref HardwareThreadScheduler::operator[](const SizeT& idx) - { - if (idx == 0) - { - if (fThreadList[idx].Kind() != kHartSystemReserved) - { - fThreadList[idx].fKind = kHartBoot; - } - } - else if (idx >= cMaxHWThreads) - { - static HardwareThread* fakeThread = new HardwareThread(); - - if (!fakeThread) - { - fakeThread = new HardwareThread(); - } - - fakeThread->fKind = kInvalidHart; - - return {fakeThread}; - } - - return &fThreadList[idx]; - } - - /** - * Check if thread pool isn't empty. - * @return - */ - HardwareThreadScheduler::operator bool() noexcept - { - return !fThreadList.Empty(); - } - - /** - * Reverse operator bool - * @return - */ - bool HardwareThreadScheduler::operator!() noexcept - { - return fThreadList.Empty(); - } - - /// @brief Returns the amount of core present. - /// @return the number of cores. - SizeT HardwareThreadScheduler::Count() noexcept - { - return fThreadList.Count(); - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 733e19ed..4e0c8902 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -435,11 +435,16 @@ namespace Kernel HardwareThreadScheduler::The()[index].Leak()->Kind() != ThreadKind::kHartSystemReserved) { + PID prev_pid = UserProcessHelper::TheCurrentPID(); UserProcessHelper::TheCurrentPID() = new_pid; bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); - return ret; + if (!ret) + { + UserProcessHelper::TheCurrentPID() = prev_pid; + continue; + } } } -- cgit v1.2.3 From 432e68391357423914547a7b34311258d7598808 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 14:42:03 +0200 Subject: [ FIX ] Fixing shortcomings of scheduler, filesystem and kernel. Signed-off-by: Amlal El Mahrouss --- dev/DLL/EncryptFS/EncryptFS.hxx | 2 +- dev/HPFS/.gitignore | 3 + dev/HPFS/hpfs.json | 11 + dev/HPFS/hpfs_main.rs | 10 + dev/ZBA/BootKit/BootKit.hxx | 77 +- dev/ZBA/Modules/SysChk/build.json | 2 +- dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 58 +- dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx | 8 +- dev/ZKA/Docs/SPECIFICATION.md | 2 +- dev/ZKA/FSKit/NeFS.hxx | 326 ++++++++ dev/ZKA/FSKit/NewFS.hxx | 326 -------- dev/ZKA/FirmwareKit/EPM.hxx | 2 +- dev/ZKA/FirmwareKit/Handover.hxx | 12 +- dev/ZKA/KernelKit/FileMgr.hxx | 12 +- dev/ZKA/NewKit/Macros.hxx | 9 + dev/ZKA/Sources/DLLMain.cxx | 130 +++- dev/ZKA/Sources/FS/NeFS.cxx | 1045 +++++++++++++++++++++++++ dev/ZKA/Sources/FS/NewFS.cxx | 1048 -------------------------- dev/ZKA/Sources/FileMgr.cxx | 14 +- dev/ZKA/Sources/NewFS+FileMgr.cxx | 18 +- dev/ZKA/Sources/NewFS+IO.cxx | 18 +- dev/ZKA/Sources/NewFS+Journal.cxx | 4 +- 22 files changed, 1590 insertions(+), 1547 deletions(-) create mode 100644 dev/HPFS/.gitignore create mode 100644 dev/HPFS/hpfs.json create mode 100644 dev/HPFS/hpfs_main.rs create mode 100644 dev/ZKA/FSKit/NeFS.hxx delete mode 100644 dev/ZKA/FSKit/NewFS.hxx create mode 100644 dev/ZKA/Sources/FS/NeFS.cxx delete mode 100644 dev/ZKA/Sources/FS/NewFS.cxx (limited to 'dev') diff --git a/dev/DLL/EncryptFS/EncryptFS.hxx b/dev/DLL/EncryptFS/EncryptFS.hxx index 4dfafe7c..368df9ae 100644 --- a/dev/DLL/EncryptFS/EncryptFS.hxx +++ b/dev/DLL/EncryptFS/EncryptFS.hxx @@ -13,7 +13,7 @@ #pragma once -#include +#include namespace EncryptFS { diff --git a/dev/HPFS/.gitignore b/dev/HPFS/.gitignore new file mode 100644 index 00000000..6f675898 --- /dev/null +++ b/dev/HPFS/.gitignore @@ -0,0 +1,3 @@ +*.sys +*.exe +*.dll \ No newline at end of file diff --git a/dev/HPFS/hpfs.json b/dev/HPFS/hpfs.json new file mode 100644 index 00000000..1098dfd3 --- /dev/null +++ b/dev/HPFS/hpfs.json @@ -0,0 +1,11 @@ +{ + "compiler_path": "rustc", + "compiler_std": "", + "sources_path": ["*.rs"], + "output_name": "hpfs.sys", + "compiler_flags": [ + ], + "cpp_macros": [ + ] + } + \ No newline at end of file diff --git a/dev/HPFS/hpfs_main.rs b/dev/HPFS/hpfs_main.rs new file mode 100644 index 00000000..ed66d175 --- /dev/null +++ b/dev/HPFS/hpfs_main.rs @@ -0,0 +1,10 @@ +/* + * Created on Thu Sep 05 2024 + * + * Copyright (c) 2024 ZKA Technologies. + */ + +fn main() { + println!("ZKA High Performance File System Driver for ZKA/OS."); + println!("Copyright ZKA technologies, all rights reserved."); +} \ No newline at end of file diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 6ac87b82..3732ea8d 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -15,10 +15,10 @@ #include #include -/// include NewFS header and Support header as well. +/// include NeFS header and Support header as well. #include -#include +#include #include /***********************************************************************************/ @@ -193,7 +193,7 @@ public: /// @brief File entry for **BDiskFormatFactory**. struct BFileDescriptor final { - Char fFileName[kNewFSNodeNameLen]; + Char fFileName[kNeFSNodeNameLen]; Int32 fKind; }; @@ -219,7 +219,7 @@ public: /// @brief check if partition is good. Bool IsPartitionValid() noexcept { - fDiskDev.Leak().mBase = (kNewFSRootCatalogStartAddress); + fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); fDiskDev.Leak().mSize = BootDev::kSectorSize; Char buf[BootDev::kSectorSize] = {0}; @@ -230,9 +230,9 @@ public: BTextWriter writer; - for (SizeT indexMag = 0UL; indexMag < kNewFSIdentLen; ++indexMag) + for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) { - if (blockPart->Ident[indexMag] != kNewFSIdent[indexMag]) + if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) return false; } @@ -241,7 +241,7 @@ public: if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || blockPart->DiskSize < 1 || blockPart->SectorSize != BootDev::kSectorSize || - blockPart->Version != kNewFSVersionInteger || + blockPart->Version != kNeFSVersionInteger || blockPart->StartCatalog == 0) { return false; @@ -260,7 +260,7 @@ private: /// @brief Write all of the requested catalogs into the filesystem. /// @param fileBlobs the blobs. /// @param blobCount the number of blobs to write. - /// @param partBlock the NewFS partition block. + /// @param partBlock the NeFS partition block. Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock) { BFileDescriptor* blob = fileBlobs; @@ -269,14 +269,14 @@ private: NFS_CATALOG_STRUCT catalogKind{0}; - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; catalogKind.PrevSibling = startLba; - catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); + catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); /// Fill catalog kind. catalogKind.Kind = blob->fKind; - catalogKind.Flags = kNewFSFlagCreated; + catalogKind.Flags = kNeFSFlagCreated; --partBlock.FreeCatalog; --partBlock.FreeSectors; @@ -316,7 +316,7 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, /// @note A catalog roughly equal to a sector. - constexpr auto cMinimumDiskSize = 10; // at minimum. + constexpr auto cMinimumDiskSize = 4; // at minimum. /// @note also look at EPM headers, for free part blocks. @@ -325,70 +325,37 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here."); return false; } - - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; - + NFS_ROOT_PARTITION_BLOCK partBlock{0}; - fDiskDev.Read((Char*)&partBlock, sizeof(NFS_ROOT_PARTITION_BLOCK)); - - if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen) == 0 && - partBlock.Version != kNewFSVersionInteger) - { - if (partBlock.Version != 0) - { - BTextWriter writer; - writer.Write(L"newosldr: Disk partition updated.\r"); - - partBlock.Version = kNewFSVersionInteger; - - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; - - fDiskDev.Write((Char*)&partBlock, sectorSz); - - return true; - } - } - else if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen)) - { - BTextWriter writer; - writer.Write(L"newosldr: Disk partition error, not a valid one.\r"); - - // TODO: Find a way to use EFI::Stop. - while (1) - ; - } - - CopyMem(partBlock.Ident, kNewFSIdent, kNewFSIdentLen - 1); + CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1); CopyMem(partBlock.PartitionName, partName, strlen(partName)); - partBlock.Version = kNewFSVersionInteger; + partBlock.Version = kNeFSVersionInteger; partBlock.CatalogCount = blobCount; - partBlock.Kind = kNewFSHardDrive; + partBlock.Kind = kNeFSHardDrive; partBlock.SectorSize = sectorSz; partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); partBlock.SectorCount = fDiskDev.GetSectorsCount(); partBlock.FreeSectors = fDiskDev.GetSectorsCount(); - partBlock.StartCatalog = kNewFSCatalogStartAddress; + partBlock.StartCatalog = kNeFSCatalogStartAddress; partBlock.DiskSize = fDiskDev.GetDiskSize(); - partBlock.Flags = kNewFSPartitionTypeBoot | kNewFSPartitionTypeStandard; + partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; + fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; fDiskDev.Leak().mSize = sectorSz; fDiskDev.Write((Char*)&partBlock, sectorSz); BOOT_BLOCK_STRUCT epmBoot{0}; - constexpr auto cFsName = "NewFS"; + constexpr auto cFsName = "NeFS"; constexpr auto cBlockName = "ZKA:"; CopyMem(epmBoot.Fs, reinterpret_cast(const_cast(cFsName)), StrLen(cFsName)); - epmBoot.FsVersion = kNewFSVersionInteger; - epmBoot.LbaStart = kNewFSRootCatalogStartAddress; + epmBoot.FsVersion = kNeFSVersionInteger; + epmBoot.LbaStart = kNeFSRootCatalogStartAddress; epmBoot.SectorSz = partBlock.SectorSize; epmBoot.NumBlocks = partBlock.CatalogCount; diff --git a/dev/ZBA/Modules/SysChk/build.json b/dev/ZBA/Modules/SysChk/build.json index dac413e0..67e22955 100644 --- a/dev/ZBA/Modules/SysChk/build.json +++ b/dev/ZBA/Modules/SysChk/build.json @@ -11,7 +11,7 @@ "-fPIC", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x1000000,-e,ModuleMain" + "-Wl,--subsystem=17,--image-base,0x10000000,-e,ModuleMain" ], "cpp_macros": [ "__NEWOSKRNL__", diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 55f10ea2..9cccc922 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -154,6 +154,27 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handoverHdrPtr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; // Fill handover header now. + BDiskFormatFactory checkPart; + + // ---------------------------------------------------- // + // The following checks for an exisiting partition + // inside the disk, if it doesn't have one, + // format the disk. + // ---------------------------------------------------- // + + if (!checkPart.IsPartitionValid()) + { + BDiskFormatFactory::BFileDescriptor root; + root.fFileName[0] = kNeFSRoot[0]; + root.fFileName[1] = 0; + + root.fKind = kNeFSCatalogKindDir; + + checkPart.Format("ZKA (A:)", &root, 1); + + rt_reset_hardware(); + } + BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc); Descriptor = new EfiMemoryDescriptor[SzDesc]; @@ -193,15 +214,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk) ; - auto extended_heap = (VoidPtr)((UIntPtr)handoverHdrPtr->f_BitMapStart + kHandoverHeapSz); - - while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &extended_heap) != kEfiOk) - ; - handoverHdrPtr->f_VirtualSize = Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ - handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST; @@ -241,27 +256,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // Assign to global 'kHandoverHeader'. - BDiskFormatFactory checkPart; - - // ---------------------------------------------------- // - // The following checks for an exisiting partition - // inside the disk, if it doesn't have one, - // format the disk. - // ---------------------------------------------------- // - - if (!checkPart.IsPartitionValid()) - { - BDiskFormatFactory::BFileDescriptor root; - root.fFileName[0] = kNewFSRoot[0]; - root.fFileName[1] = 0; - - root.fKind = kNewFSCatalogKindDir; - - checkPart.Format("ZKA (A:)", &root, 1); - - rt_reset_hardware(); - } - BFileReader readerKernel(L"newoskrnl.exe", ImageHandle); readerKernel.ReadAll(0); @@ -293,11 +287,17 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, urbanistTTF.ReadAll(0); if (readerSysDrv.Blob() && - chimeWav.Blob()) + chimeWav.Blob() && + urbanistTTF.Blob()) { handoverHdrPtr->f_StartupChime = chimeWav.Blob(); - handoverHdrPtr->f_StartupImage = readerKernel.Blob(); + handoverHdrPtr->f_ChimeSz = chimeWav.Size(); + handoverHdrPtr->f_StartupImage = readerSysDrv.Blob(); + handoverHdrPtr->f_StartupSz = readerSysDrv.Size(); + handoverHdrPtr->f_KernelImage = readerKernel.Blob(); + handoverHdrPtr->f_KernelSz = readerKernel.Size(); handoverHdrPtr->f_TTFallbackFont = urbanistTTF.Blob(); + handoverHdrPtr->f_FontSz = urbanistTTF.Size(); } else { diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx index 65ea3d89..467f4303 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx @@ -25,7 +25,7 @@ */ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -57,7 +57,7 @@ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) /// @param str the input string. BTextWriter& BTextWriter::Write(const Char* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -87,7 +87,7 @@ BTextWriter& BTextWriter::Write(const Char* str) BTextWriter& BTextWriter::Write(const UChar* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -120,7 +120,7 @@ BTextWriter& BTextWriter::Write(const UChar* str) */ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ EfiCharType str[2]; str[0] = c; diff --git a/dev/ZKA/Docs/SPECIFICATION.md b/dev/ZKA/Docs/SPECIFICATION.md index d39a95d3..c38fa122 100644 --- a/dev/ZKA/Docs/SPECIFICATION.md +++ b/dev/ZKA/Docs/SPECIFICATION.md @@ -19,7 +19,7 @@ - Separation of Files/Devices. - Networking. - Hardware Abstraction Layer. -- Native Filesystem support (NewFS, FAT32 and ffs2). +- Native Filesystem support (NeFS, FAT32 and ffs2). - Program Loaders interfaces. - TLS (Thread Local Storage) support. - Semaphore, Locks, Timers. diff --git a/dev/ZKA/FSKit/NeFS.hxx b/dev/ZKA/FSKit/NeFS.hxx new file mode 100644 index 00000000..d1c0c9c7 --- /dev/null +++ b/dev/ZKA/FSKit/NeFS.hxx @@ -0,0 +1,326 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: NeFS.hxx + PURPOSE: NeFS (New FileSystem) kernel support. + + Revision History: + + ?/?/?: Added file (amlel) + 12/02/24: Add UUID macro for EPM and GPT partition schemes. + 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by +default. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +/** + @brief New File System specification. + @author Amlal EL Mahrouss +*/ + +#define kNeFSInvalidFork (-1) +#define kNeFSInvalidCatalog (-1) +#define kNeFSNodeNameLen (256) + +#define kNeFSSectorSz (512) +#define kNeFSForkDataSz (gib_cast(16)) + +#define kNeFSIdentLen (8) +#define kNeFSIdent " NewFS" +#define kNeFSPadLen (400) + +#define kNeFSMetaFilePrefix '$' + +#define kNeFSVersionInteger (0x0128) +#define kNeFSVerionString "1.28" + +/// @brief Standard fork types. +#define kNeFSDataFork "main_data" +#define kNeFSResourceFork "main_rsrc" + +#define kNeFSCatalogKindFile (1) +#define kNeFSCatalogKindDir (2) +#define kNeFSCatalogKindAlias (3) + +#define kNeFSForkSize (512) + +//! shared between network or +//! other filesystems. Export forks as .zip when copying. +#define kNeFSCatalogKindShared (4) + +#define kNeFSCatalogKindResource (5) +#define kNeFSCatalogKindExecutable (6) + +#define kNeFSCatalogKindPage (8) + +#define kNeFSPartitionTypeStandard (7) +#define kNeFSPartitionTypePage (8) +#define kNeFSPartitionTypeBoot (9) + +#define kNeFSCatalogKindDevice (9) +#define kNeFSCatalogKindLock (10) + +#define kNeFSCatalogKindRLE (11) + +#define kNeFSCatalogKindMetaFile (12) + +#define kNeFSSeparator '\\' +#define kNeFSSeparatorAlt '/' + +#define kNeFSUpDir ".." +#define kNeFSRoot "\\" +#define kNeFSRootAlt "/" + +#define kNeFSLF '\r' +#define kNeFSEOF (-1) + +#define kNeFSBitWidth (sizeof(Kernel::Char)) +#define kNeFSLbaType (Kernel::Lba) + +/// Start After the PM headers, pad 1024 bytes. +#define kNeFSRootCatalogStartAddress (1024) +#define kNeFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK)) + +#define kResourceTypeDialog (10) +#define kResourceTypeString (11) +#define kResourceTypeMenu (12) + +#define kConfigLen (64) +#define kPartLen (32) + +#define kNeFSFlagDeleted (70) +#define kNeFSFlagUnallocated (0) +#define kNeFSFlagCreated (71) + +#define kNeFSMimeNameLen (200) + +#define kNeFSForkNameLen (200U) + +struct NFS_CATALOG_STRUCT; +struct NFS_FORK_STRUCT; +struct NFS_ROOT_PARTITION_BLOCK; + +enum +{ + kNeFSHardDrive = 0xC0, // Hard Drive + kNeFSSolidStateDrive = 0xC1, // Solid State Drive + kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD + kNeFSMassStorageDevice = 0xCC, // USB + kNeFSScsi = 0xC4, // SCSI Hard Drive + kNeFSFlashDrive = 0xC6, + kNeFSUnknown = 0xFF, // Unknown device. + kNeFSDriveCount = 7, +}; + +/// @brief Catalog type. +struct PACKED NFS_CATALOG_STRUCT final +{ + Kernel::Char Name[kNeFSNodeNameLen]; + Kernel::Char Mime[kNeFSMimeNameLen]; + + /// Catalog status flag. + Kernel::UInt16 Flags; + /// Custom catalog flags. + Kernel::UInt16 FileFlags; + /// Catalog kind. + Kernel::Int32 Kind; + + /// Size of the data fork. + Kernel::Lba DataForkSize; + + /// Size of all resource forks. + Kernel::Lba ResourceForkSize; + + Kernel::Lba DataFork; + Kernel::Lba ResourceFork; + + Kernel::Lba NextSibling; + Kernel::Lba PrevSibling; +}; + +/// @brief Fork type, contains a data page. +/// @note The way we store is way different than how other filesystems do, specific chunk of code are +/// written into either the data fork or resource fork, the resource fork is reserved for file metadata. +/// whereas the data fork is reserved for file data. +struct PACKED NFS_FORK_STRUCT final +{ + Kernel::Char ForkName[kNeFSForkNameLen]; + Kernel::Char CatalogName[kNeFSNodeNameLen]; + + Kernel::Int32 Flags; + Kernel::Int32 Kind; + + Kernel::Int64 ResourceId; + Kernel::Int32 ResourceKind; + Kernel::Int32 ResourceFlags; + + Kernel::Lba DataOffset; // 8 Where to look for this data? + Kernel::SizeT DataSize; /// Data size according using sector count. + + Kernel::Lba NextSibling; + Kernel::Lba PreviousSibling; +}; + +/// @brief Partition block type +struct PACKED NFS_ROOT_PARTITION_BLOCK final +{ + Kernel::Char Ident[kNeFSIdentLen]; + Kernel::Char PartitionName[kPartLen]; + + Kernel::Int32 Flags; + Kernel::Int32 Kind; + + Kernel::Lba StartCatalog; + Kernel::SizeT CatalogCount; + + Kernel::SizeT DiskSize; + + Kernel::SizeT FreeCatalog; + Kernel::SizeT FreeSectors; + + Kernel::SizeT SectorCount; + Kernel::SizeT SectorSize; + + Kernel::UInt64 Version; + + Kernel::Lba EpmBlock; + + Kernel::Char Pad[kNeFSPadLen - sizeof(Kernel::Lba)]; +}; + +namespace Kernel +{ + enum + { + kNeFSSubDriveA, + kNeFSSubDriveB, + kNeFSSubDriveC, + kNeFSSubDriveD, + kNeFSSubDriveInvalid, + kNeFSSubDriveCount, + }; + + /// \brief Resource fork kind. + enum + { + kNeFSRsrcForkKind = 0, + kNeFSDataForkKind = 1 + }; + + /// + /// \name NeFSParser + /// \brief NeFS parser class. (catalog creation, remove removal, root, + /// forks...) Designed like the DOM, detects the filesystem automatically. + /// + class NeFSParser final + { + public: + explicit NeFSParser() = default; + ~NeFSParser() = default; + + public: + ZKA_COPY_DEFAULT(NeFSParser); + + public: + /// @brief Creates a new fork inside the New filesystem partition. + /// @param catalog it's catalog + /// @param theFork the fork itself. + /// @return the fork + _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork); + + /// @brief Find fork inside New filesystem. + /// @param catalog the catalog. + /// @param name the fork name. + /// @return the fork. + _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input const Char* name, + Boolean dataOrRsrc); + + _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); + + _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); + + _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba); + + _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); + + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, + _Input const Int32& flags, + _Input const Int32& kind); + + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); + + Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input VoidPtr data, + _Input SizeT sizeOfData, + _Input const Char* forkName); + + VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input SizeT dataSz, + _Input const Char* forkName); + + bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); + + SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog); + + bool RemoveCatalog(_Input const Char* catalog); + + bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog); + + /// @brief Make a EPM+NeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see ErrLocal(). + bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name); + + public: + Int32 fDriveIndex{kNeFSSubDriveA}; + }; + + /// + /// \name NewFilesystemHelper + /// \brief Filesystem helper and utils. + /// + + class NewFilesystemHelper final + { + public: + STATIC const Char* Root(); + STATIC const Char* UpDir(); + STATIC const Char Separator(); + STATIC const Char MetaFile(); + }; + + namespace Detail + { + Boolean fs_init_newfs(Void) noexcept; + } // namespace Detail +} // namespace Kernel + +/// @brief Write to newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); + +/// @brief Read from newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt, + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); diff --git a/dev/ZKA/FSKit/NewFS.hxx b/dev/ZKA/FSKit/NewFS.hxx deleted file mode 100644 index 4587b70f..00000000 --- a/dev/ZKA/FSKit/NewFS.hxx +++ /dev/null @@ -1,326 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: NewFS.hxx - Purpose: - - Revision History: - - ?/?/?: Added file (amlel) - 12/02/24: Add UUID macro for EPM and GPT partition schemes. - 3/16/24: Add mandatory sector size, kNewFSSectorSz is set to 2048 by -default. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include - -/** - @brief New File System specification. - @author Amlal EL Mahrouss -*/ - -#define kNewFSInvalidFork (-1) -#define kNewFSInvalidCatalog (-1) -#define kNewFSNodeNameLen (256) - -#define kNewFSSectorSz (512) -#define kNewFSForkSz (8192) - -#define kNewFSIdentLen (8) -#define kNewFSIdent " NewFS" -#define kNewFSPadLen (400) - -#define kNewFSMetaFilePrefix '$' - -#define kNewFSVersionInteger (0x0128) -#define kNewFSVerionString "1.28" - -/// @brief Standard fork types. -#define kNewFSDataFork "main_data" -#define kNewFSResourceFork "main_rsrc" - -#define kNewFSCatalogKindFile (1) -#define kNewFSCatalogKindDir (2) -#define kNewFSCatalogKindAlias (3) - -#define kNewFSForkSize (512) - -//! shared between network or -//! other filesystems. Export forks as .zip when copying. -#define kNewFSCatalogKindShared (4) - -#define kNewFSCatalogKindResource (5) -#define kNewFSCatalogKindExecutable (6) - -#define kNewFSCatalogKindPage (8) - -#define kNewFSPartitionTypeStandard (7) -#define kNewFSPartitionTypePage (8) -#define kNewFSPartitionTypeBoot (9) - -#define kNewFSCatalogKindDevice (9) -#define kNewFSCatalogKindLock (10) - -#define kNewFSCatalogKindRLE (11) - -#define kNewFSCatalogKindMetaFile (12) - -#define kNewFSSeparator '\\' -#define kNewFSSeparatorAlt '/' - -#define kNewFSUpDir ".." -#define kNewFSRoot "\\" -#define kNewFSRootAlt "/" - -#define kNewFSLF '\r' -#define kNewFSEOF (-1) - -#define kNewFSBitWidth (sizeof(Kernel::Char)) -#define kNewFSLbaType (Kernel::Lba) - -/// Start After the PM headers, pad 1024 bytes. -#define kNewFSRootCatalogStartAddress (1024) -#define kNewFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK)) - -#define kResourceTypeDialog (10) -#define kResourceTypeString (11) -#define kResourceTypeMenu (12) - -#define kConfigLen (64) -#define kPartLen (32) - -#define kNewFSFlagDeleted (70) -#define kNewFSFlagUnallocated (0) -#define kNewFSFlagCreated (71) - -#define kNewFSMimeNameLen (200) - -#define kNewFSForkNameLen (200U) - -struct NFS_CATALOG_STRUCT; -struct NFS_FORK_STRUCT; -struct NFS_ROOT_PARTITION_BLOCK; - -enum -{ - kNewFSHardDrive = 0xC0, // Hard Drive - kNewFSSolidStateDrive = 0xC1, // Solid State Drive - kNewFSOpticalDrive = 0x0C, // Blu-Ray/DVD - kNewFSMassStorageDevice = 0xCC, // USB - kNewFSScsi = 0xC4, // SCSI Hard Drive - kNewFSFlashDrive = 0xC6, - kNewFSUnknown = 0xFF, // Unknown device. - kNewFSDriveCount = 7, -}; - -/// @brief Catalog type. -struct PACKED NFS_CATALOG_STRUCT final -{ - Kernel::Char Name[kNewFSNodeNameLen]; - Kernel::Char Mime[kNewFSMimeNameLen]; - - /// Catalog status flag. - Kernel::UInt16 Flags; - /// Custom catalog flags. - Kernel::UInt16 FileFlags; - /// Catalog kind. - Kernel::Int32 Kind; - - /// Size of the data fork. - Kernel::Lba DataForkSize; - - /// Size of all resource forks. - Kernel::Lba ResourceForkSize; - - Kernel::Lba DataFork; - Kernel::Lba ResourceFork; - - Kernel::Lba NextSibling; - Kernel::Lba PrevSibling; -}; - -/// @brief Fork type, contains a data page. -/// @note The way we store is way different than how other filesystems do, specific chunk of code are -/// written into either the data fork or resource fork, the resource fork is reserved for file metadata. -/// whereas the data fork is reserved for file data. -struct PACKED NFS_FORK_STRUCT final -{ - Kernel::Char ForkName[kNewFSForkNameLen]; - Kernel::Char CatalogName[kNewFSNodeNameLen]; - - Kernel::Int32 Flags; - Kernel::Int32 Kind; - - Kernel::Int64 ResourceId; - Kernel::Int32 ResourceKind; - Kernel::Int32 ResourceFlags; - - Kernel::Lba DataOffset; // 8 Where to look for this data? - Kernel::SizeT DataSize; /// Data size according using sector count. - - Kernel::Lba NextSibling; - Kernel::Lba PreviousSibling; -}; - -/// @brief Partition block type -struct PACKED NFS_ROOT_PARTITION_BLOCK final -{ - Kernel::Char Ident[kNewFSIdentLen]; - Kernel::Char PartitionName[kPartLen]; - - Kernel::Int32 Flags; - Kernel::Int32 Kind; - - Kernel::Lba StartCatalog; - Kernel::SizeT CatalogCount; - - Kernel::SizeT DiskSize; - - Kernel::SizeT FreeCatalog; - Kernel::SizeT FreeSectors; - - Kernel::SizeT SectorCount; - Kernel::SizeT SectorSize; - - Kernel::UInt64 Version; - - Kernel::Lba EpmBlock; - - Kernel::Char Pad[kNewFSPadLen - sizeof(Kernel::Lba)]; -}; - -namespace Kernel -{ - enum - { - kNewFSSubDriveA, - kNewFSSubDriveB, - kNewFSSubDriveC, - kNewFSSubDriveD, - kNewFSSubDriveInvalid, - kNewFSSubDriveCount, - }; - - /// \brief Resource fork kind. - enum - { - kNewFSRsrcForkKind = 0, - kNewFSDataForkKind = 1 - }; - - /// - /// \name NewFSParser - /// \brief NewFS parser class. (catalog creation, remove removal, root, - /// forks...) Designed like the DOM, detects the filesystem automatically. - /// - class NewFSParser final - { - public: - explicit NewFSParser() = default; - ~NewFSParser() = default; - - public: - ZKA_COPY_DEFAULT(NewFSParser); - - public: - /// @brief Creates a new fork inside the New filesystem partition. - /// @param catalog it's catalog - /// @param theFork the fork itself. - /// @return the fork - _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork); - - /// @brief Find fork inside New filesystem. - /// @param catalog the catalog. - /// @param name the fork name. - /// @return the fork. - _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - Boolean dataOrRsrc); - - _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); - - _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); - - _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba); - - _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); - - _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind); - - _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); - - Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input VoidPtr data, - _Input SizeT sizeOfData, - _Input const Char* forkName); - - VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input SizeT dataSz, - _Input const Char* forkName); - - bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); - - SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog); - - bool RemoveCatalog(_Input const Char* catalog); - - bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog); - - /// @brief Make a EPM+NewFS drive out of the disk. - /// @param drive The drive to write on. - /// @return If it was sucessful, see ErrLocal(). - bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name); - - public: - Int32 fDriveIndex{kNewFSSubDriveA}; - }; - - /// - /// \name NewFilesystemHelper - /// \brief Filesystem helper and utils. - /// - - class NewFilesystemHelper final - { - public: - STATIC const Char* Root(); - STATIC const Char* UpDir(); - STATIC const Char Separator(); - STATIC const Char MetaFile(); - }; - - namespace Detail - { - Boolean fs_init_newfs(Void) noexcept; - } // namespace Detail -} // namespace Kernel - -/// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); - -/// @brief Read from newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); diff --git a/dev/ZKA/FirmwareKit/EPM.hxx b/dev/ZKA/FirmwareKit/EPM.hxx index 0de288be..18f8558d 100644 --- a/dev/ZKA/FirmwareKit/EPM.hxx +++ b/dev/ZKA/FirmwareKit/EPM.hxx @@ -102,7 +102,7 @@ struct PACKED _BOOT_BLOCK_STRUCT Kernel::Int64 LbaEnd; // addition of lba_start to get the end of partition. Kernel::Int16 Kind; Kernel::Int32 FsVersion; - Kernel::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */ + Kernel::Char Fs[kEPMFilesystemLength]; /* NeFS, ffs2... */ Kernel::Char Reserved[401]; // to fill a full sector. }; diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 80d68afa..b4558560 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -24,13 +24,7 @@ #define kHandoverMagic 0xBADCC #define kHandoverVersion 0x114 -#define kHandoverMaxCmdLine 8 - -#define kHandoverBetterEFI "ZKA_EFI" -#define kHandoverBetterEFI_U L"ZKA_EFI" - -#define kHandoverHeapSz gib_cast(2) - +#define kHandoverHeapSz gib_cast(3) #define kHandoverStructSz sizeof(HEL::HandoverInformationHeader) namespace Kernel::HEL @@ -67,9 +61,13 @@ namespace Kernel::HEL VoidPtr f_PhysicalStart; VoidPtr f_KernelImage; + SizeT f_KernelSz; VoidPtr f_StartupChime; + SizeT f_ChimeSz; VoidPtr f_StartupImage; + SizeT f_StartupSz; VoidPtr f_TTFallbackFont; + SizeT f_FontSz; WideChar f_FirmwareVendorName[32]; SizeT f_FirmwareVendorLen; diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index 86c40b69..a46216db 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -12,7 +12,7 @@ Revision History: 31/01/24: Update documentation (amlel) - 05/07/24: NewFS support, and fork support, updated constants and specs + 05/07/24: NeFS support, and fork support, updated constants and specs as well. ------------------------------------------- */ @@ -20,7 +20,7 @@ #pragma once #ifdef __FSKIT_USE_NEWFS__ -#include +#include #endif // __FSKIT_USE_NEWFS__ #include @@ -137,7 +137,7 @@ namespace Kernel #ifdef __FSKIT_USE_NEWFS__ /** - * @brief Based of FilesystemMgrInterface, takes care of managing NewFS + * @brief Based of FilesystemMgrInterface, takes care of managing NeFS * disks. */ class NewFilesystemMgr final : public FilesystemMgrInterface @@ -176,12 +176,12 @@ namespace Kernel _Input SizeT sz) override; public: - /// @brief Get NewFS parser class. + /// @brief Get NeFS parser class. /// @return The filesystem parser class. - NewFSParser* GetParser() noexcept; + NeFSParser* GetParser() noexcept; private: - NewFSParser* fImpl{nullptr}; + NeFSParser* fImpl{nullptr}; }; #endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index b9242e79..0de25216 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -119,3 +119,12 @@ /// @brief The main system driver. #define kSysDrv "\\System\\startup.sys" + +/// @brief The main font file. +#define kSysTTF "\\System\\urbanist.ttf" + +/// @brief The main kernel file. +#define kSysChime "\\System\\startup.wav" + +/// @brief The main kernel file. +#define kSysKrnl "\\System\\newoskrnl.exe" diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index db1a80d1..0fa3a181 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -44,7 +44,7 @@ namespace Kernel::Detail /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { - Kernel::NewFilesystemMgr* fNewFS{nullptr}; + Kernel::NewFilesystemMgr* fNeFS{nullptr}; public: /// @brief wizard constructor. @@ -52,17 +52,17 @@ namespace Kernel::Detail { if (Kernel::FilesystemMgrInterface::GetMounted()) { - CG::CGDrawStringToWnd(cKernelWnd, "NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNewFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); + CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); + fNeFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); } else { - // Mounts a NewFS from main drive. - fNewFS = new Kernel::NewFilesystemMgr(); + // Mounts a NeFS from main drive. + fNeFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemMgrInterface::Mount(fNewFS); + Kernel::FilesystemMgrInterface::Mount(fNeFS); - CG::CGDrawStringToWnd(cKernelWnd, "Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } const Kernel::SizeT cDirCount = 7UL; @@ -71,11 +71,11 @@ namespace Kernel::Detail "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", "\\Users\\", "\\Library\\", "\\Mount\\"}; - if (fNewFS->GetParser()) + if (fNeFS->GetParser()) { for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { - auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + auto catalogDir = fNeFS->GetParser()->GetCatalog(cDirStr[dirIndx]); if (catalogDir) { @@ -86,8 +86,8 @@ namespace Kernel::Detail continue; } - catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); + catalogDir = fNeFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, + kNeFSCatalogKindDir); CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory has been created: ")), RGB(0, 0, 0)); @@ -96,44 +96,93 @@ namespace Kernel::Detail } } - NFS_CATALOG_STRUCT* catalogDisk = - this->fNewFS->GetParser()->GetCatalog(kSysPage); - const Kernel::Char* cSrcName = "8K_SYS_PAGE_KERNEL"; + constexpr auto cFileToFormatCnt = 5; - if (catalogDisk) + struct { - CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file already exists: ")), RGB(0, 0, 0)); + VoidPtr fBlob; + Size fBlobSz; + Int32 fFlags; + Char fName[kNeFSNodeNameLen]; + } cFiles[cFileToFormatCnt] = { + { + .fBlob = kHandoverHeader->f_KernelImage, + .fBlobSz = kHandoverHeader->f_KernelSz, + .fFlags = kNeFSCatalogKindExecutable, + .fName = kSysKrnl, + }, + { + .fBlob = kHandoverHeader->f_StartupImage, + .fBlobSz = kHandoverHeader->f_StartupSz, + .fFlags = kNeFSCatalogKindExecutable, + .fName = kSysDrv, + }, + { + .fBlob = 0, + .fBlobSz = mib_cast(32), + .fFlags = kNeFSCatalogKindPage, + .fName = kSysPage, + }, + { + .fBlob = kHandoverHeader->f_TTFallbackFont, + .fBlobSz = kHandoverHeader->f_FontSz, + .fFlags = kNeFSCatalogKindResource, + .fName = kSysTTF, + }, + { + .fBlob = kHandoverHeader->f_StartupChime, + .fBlobSz = kHandoverHeader->f_ChimeSz, + .fFlags = kNeFSCatalogKindResource, + .fName = kSysChime, + } - delete catalogDisk; - } - else + }; + + for (size_t i = 0; i < cFileToFormatCnt; i++) { - CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file created: ")), RGB(0, 0, 0)); + NFS_CATALOG_STRUCT* catalogDisk = + this->fNeFS->GetParser()->GetCatalog(cFiles[i].fName); + + const Kernel::Char* cSrcName = cFiles[i].fName; - catalogDisk = - (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(kSysPage); + if (catalogDisk) + { + CG::CGDrawStringToWnd(cKernelWnd, "File already exists: ", 10 + (10 * (cDirCount + i + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i+ 1)), 10 + (FONT_SIZE_X * rt_string_len("File already exists: ")), RGB(0, 0, 0)); + + delete catalogDisk; + } + else + { + CG::CGDrawStringToWnd(cKernelWnd, "File created: ", 10 + (10 * (cDirCount + i+ 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i + 1)), 10 + (FONT_SIZE_X * rt_string_len("File created: ")), RGB(0, 0, 0)); + + catalogDisk = + (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(cFiles[i].fName); - NFS_FORK_STRUCT theDiskFork{0}; + NFS_FORK_STRUCT theDiskFork{0}; - Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, + Kernel::rt_string_len(cSrcName)); - Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); + Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), + theDiskFork.CatalogName, + Kernel::rt_string_len(catalogDisk->Name)); - Kernel::Size sz_hdr = kNewFSForkSz; + theDiskFork.DataSize = cFiles[i].fBlobSz; + theDiskFork.ResourceId = cFiles[i].fFlags; + theDiskFork.ResourceKind = Kernel::kNeFSDataForkKind; + theDiskFork.Kind = Kernel::kNeFSDataForkKind; - theDiskFork.DataSize = sz_hdr; - theDiskFork.ResourceId = kNewFSCatalogKindExecutable | kNewFSCatalogKindPage; - theDiskFork.ResourceKind = Kernel::kNewFSDataForkKind; - theDiskFork.Kind = Kernel::kNewFSDataForkKind; + fNeFS->GetParser()->CreateFork(catalogDisk, theDiskFork); - fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); + if (theDiskFork.ResourceId != kNeFSCatalogKindPage) + { + fNeFS->GetParser()->WriteCatalog(catalogDisk, false, cFiles[i].fBlob, cFiles[i].fBlobSz, theDiskFork.ForkName); + } - delete catalogDisk; + delete catalogDisk; + } } } @@ -141,11 +190,11 @@ namespace Kernel::Detail ZKA_COPY_DEFAULT(FilesystemInstaller); - /// @brief Grab the disk's NewFS reference. + /// @brief Grab the disk's NeFS reference. /// @return NewFilesystemMgr the filesystem interface Kernel::NewFilesystemMgr* Leak() { - return fNewFS; + return fNeFS; } }; } // namespace Kernel::Detail @@ -154,7 +203,6 @@ EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void) { while (Yes) { - } } @@ -190,7 +238,7 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0)); Kernel::UserProcessHelper::Init(); - + Kernel::sched_execute_thread(HangCPU, "HANG TEST"); while (Yes) diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx new file mode 100644 index 00000000..5bae8d4a --- /dev/null +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -0,0 +1,1045 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifdef __FSKIT_USE_NEWFS__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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. +/// \\ +/// \\Path1\\ \\ath2\\ +/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. +/// \\Path1\\readme.rtf +/***********************************************************************************/ + +STATIC MountpointInterface sMountpointInterface; + +/***********************************************************************************/ +/// @brief Creates a new fork inside the New filesystem partition. +/// @param catalog it's catalog +/// @param theFork the fork itself. +/// @return the fork +/***********************************************************************************/ +_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork) +{ + if (catalog && theFork.ForkName[0] != 0 && + theFork.DataSize <= kNeFSForkDataSz) + { + Lba lba = (theFork.Kind == kNeFSDataForkKind) ? catalog->DataFork + : catalog->ResourceFork; + + kcout << "fork lba: " << hex_number(lba) << endl; + + if (lba <= kNeFSCatalogStartAddress) + return nullptr; + + auto drv = sMountpointInterface.A(); + + /// special treatment. + rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + 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. + while (true) + { + if (lba <= kNeFSCatalogStartAddress) + break; + + drv.fPacket.fLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &curFork; + + drv.fInput(&drv.fPacket); + + if (curFork.NextSibling > kBadAddress) + { + kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; + break; + } + + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; + + if (curFork.Flags == kNeFSFlagCreated) + { + kcout << "fork already exists.\r"; + + /// sanity check. + if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && + StringBuilder::Equals(curFork.CatalogName, catalog->Name)) + return nullptr; + + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; + + lbaOfPreviousFork = lba; + lba = curFork.NextSibling; + + prevFork = curFork; + } + else + { + /// This is a check that we have, in order to link the previous fork + /// entry. + if (lba >= kNeFSCatalogStartAddress) + { + drv.fPacket.fLba = lbaOfPreviousFork; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &prevFork; + + prevFork.NextSibling = lba; + + /// write to disk. + drv.fOutput(&drv.fPacket); + } + + break; + } + } + + constexpr auto cForkPadding = + 4; /// this value gives us space for the data offset. + + theFork.Flags = kNeFSFlagCreated; + 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(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &theFork; + + drv.fOutput(&drv.fPacket); + + /// log what we have now. + kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) + << endl; + + kcout << "Wrote fork at: " << hex_number(lba) << endl; + + return &theFork; + } + + return nullptr; +} + +/***********************************************************************************/ +/// @brief Find fork inside New filesystem. +/// @param catalog the catalog. +/// @param name the fork name. +/// @return the fork. +/***********************************************************************************/ +_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input const Char* name, + Boolean isDataFork) +{ + auto drv = sMountpointInterface.A(); + NFS_FORK_STRUCT* theFork = nullptr; + + Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; + + while (lba != 0) + { + drv.fPacket.fLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = (VoidPtr)theFork; + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16); + + if (auto res = + fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex); + res) + { + switch (res) + { + case 1: + ErrLocal() = kErrorDiskReadOnly; + break; + case 2: + ErrLocal() = kErrorDiskIsFull; + break; + ErrLocal() = kErrorNoSuchDisk; + break; + + default: + break; + } + return nullptr; + } + + if (StringBuilder::Equals(theFork->ForkName, name)) + { + break; + } + + lba = theFork->NextSibling; + } + + return theFork; +} + +/***********************************************************************************/ +/// @brief Simpler factory to create a catalog (assumes you want to create a +/// file.) +/// @param name +/// @return catalog pointer. +/***********************************************************************************/ +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name) +{ + return this->CreateCatalog(name, 0, kNeFSCatalogKindFile); +} + +/***********************************************************************************/ +/// @brief Creates a new catalog into the disk. +/// @param name the catalog name. +/// @param flags the flags of the catalog. +/// @param kind the catalog kind. +/// @return catalog pointer. +/***********************************************************************************/ +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, + _Input const Int32& flags, + _Input const Int32& kind) +{ + kcout << "CreateCatalog(...)\r"; + + Lba out_lba = 0UL; + + kcout << "Checking for extension...\r"; + + /// a directory should have a slash in the end. + if (kind == kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) + return nullptr; + + /// a file shouldn't have a slash in the end. + if (kind != kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) + return nullptr; + + NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); + + if (catalog_copy) + { + kcout << "Catalog already exists: " << name << ".\r"; + ErrLocal() = kErrorFileExists; + + return catalog_copy; + } + + Char parentName[kNeFSNodeNameLen] = {0}; + + for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) + { + parentName[indexName] = name[indexName]; + } + + if (*parentName == 0) + { + kcout << "Parent name is NUL.\r"; + ErrLocal() = kErrorFileNotFound; + return nullptr; + } + + /// Locate parent catalog, to then allocate right after it. + + for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) + { + parentName[indexFill] = name[indexFill]; + } + + SizeT indexReverseCopy = rt_string_len(parentName); + + // zero character it. + parentName[--indexReverseCopy] = 0; + + // mandatory / character, zero it. + parentName[--indexReverseCopy] = 0; + + while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + { + parentName[indexReverseCopy] = 0; + --indexReverseCopy; + } + + NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, out_lba); + + auto drive = sMountpointInterface.A(); + + if (catalog && catalog->Kind == kNeFSCatalogKindFile) + { + kcout << "Parent name is file.\r"; + delete catalog; + return nullptr; + } + else if (!catalog) + { + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + constexpr auto cNeFSCatalogPadding = 4; + + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + out_lba = partBlock->StartCatalog; + } + + constexpr SizeT cDefaultForkSize = kNeFSForkSize; + + NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); + + Int32 flagsList = flags; + + catalogChild->ResourceForkSize = cDefaultForkSize; + catalogChild->DataForkSize = cDefaultForkSize; + + catalogChild->NextSibling = out_lba; + catalogChild->PrevSibling = out_lba; + catalogChild->Kind = kind; + catalogChild->Flags = kNeFSFlagCreated | flagsList; + + rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, + rt_string_len(name)); + + UInt16 catalogBuf[kNeFSSectorSz] = {0}; + + 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.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = start_free; + + drive.fInput(&drive.fPacket); + + NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; + + start_free = nextSibling->NextSibling; + + catalogChild->PrevSibling = out_lba; + + drive.fPacket.fLba = start_free; + drive.fInput(&drive.fPacket); + + while (drive.fPacket.fPacketGood) + { + nextSibling = reinterpret_cast(catalogBuf); + + if (start_free <= kNeFSRootCatalogStartAddress) + { + delete catalogChild; + delete catalog; + + return nullptr; + } + + // ========================== // + // Allocate catalog now... + // ========================== // + if ((nextSibling->Flags & kNeFSFlagCreated) == 0) + { + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + constexpr auto cNeFSCatalogPadding = 4; + + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + + if (partBlock->FreeCatalog < 1) + { + delete catalogChild; + return nullptr; + } + + catalogChild->DataFork = partBlock->DiskSize - start_free; + catalogChild->ResourceFork = catalogChild->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)) + { + catalogChild->NextSibling = + start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + } + + drive.fPacket.fPacketContent = catalogChild; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + drive.fPacket.fLba = start_free; + + drive.fOutput(&drive.fPacket); + + // Get NeFS partition's block. + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + partBlock->FreeSectors -= 1; + partBlock->CatalogCount += 1; + partBlock->FreeCatalog -= 1; + + drive.fOutput(&drive.fPacket); + + kcout << "Create new catalog, status: " + << hex_number(catalogChild->Flags) << endl; + kcout << "Create new catalog, name: " << catalogChild->Name + << endl; + + delete catalog; + return catalogChild; + } + else if ((nextSibling->Flags & kNeFSFlagCreated) && + StringBuilder::Equals(nextSibling->Name, name)) + { + return nextSibling; + } + + constexpr auto cNeFSCatalogPadding = 4; + + //// @note that's how we find the next catalog in the partition block. + start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + + drive.fPacket.fPacketContent = catalogBuf; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = start_free; + + drive.fInput(&drive.fPacket); + } + + delete catalog; + return nullptr; +} + +/// @brief Make a EPM+NeFS drive out of the disk. +/// @param drive The drive to write on. +/// @return If it was sucessful, see ErrLocal(). +bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) +{ + if (*part_name == 0 || + endLba == 0) + return false; + + // verify disk. + drive->fVerify(&drive->fPacket); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + // if disk isn't good, then error out. + if (false == drive->fPacket.fPacketGood) + { + ErrLocal() = kErrorDiskIsCorrupted; + return false; + } + + Char fs_buf[kNeFSSectorSz] = {0}; + + Lba start = kNeFSRootCatalogStartAddress; + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = start; + + drive->fInput(&drive->fPacket); + + if (flags & kNeFSPartitionTypeBoot) + { + // make it bootable when needed. + Char bufEpmHdr[kNeFSSectorSz] = {0}; + + BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; + + // EPM header. + + constexpr auto cFsName = "NeFS"; + constexpr auto cBlockName = "ZKA:"; + + rt_copy_memory(reinterpret_cast(const_cast(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); + + epmBoot->FsVersion = kNeFSVersionInteger; + epmBoot->LbaStart = start; + epmBoot->SectorSz = kNeFSSectorSz; + + rt_copy_memory(reinterpret_cast(const_cast(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); + rt_copy_memory(reinterpret_cast(const_cast(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); + + Lba outEpmLba = kEpmBase; + + Char buf[kNeFSSectorSz]; + + Lba prevStart = 0; + SizeT cnt = 0; + + while (drive->fPacket.fPacketGood) + { + drive->fPacket.fPacketContent = buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = outEpmLba; + + drive->fInput(&drive->fPacket); + + if (buf[0] == 0) + { + epmBoot->LbaStart = prevStart; + + if (epmBoot->LbaStart) + epmBoot->LbaStart = outEpmLba; + + epmBoot->LbaEnd = endLba; + epmBoot->NumBlocks = cnt; + + drive->fPacket.fPacketContent = bufEpmHdr; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = outEpmLba; + + drive->fOutput(&drive->fPacket); + + break; + } + else + { + prevStart = ((BOOT_BLOCK_STRUCT*)buf)->LbaStart + ((BOOT_BLOCK_STRUCT*)buf)->LbaEnd; + } + + outEpmLba += sizeof(BOOT_BLOCK_STRUCT); + ++cnt; + } + } + + // disk isnt faulty and data has been fetched. + while (drive->fPacket.fPacketGood) + { + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; + + // check for an empty partition here. + if (partBlock->PartitionName[0] == 0 && + rt_string_cmp(partBlock->Ident, kNeFSIdent, kNeFSIdentLen)) + { + // partition is free and valid. + + partBlock->Version = kNeFSVersionInteger; + + const auto cUntitledHD = part_name; + + rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)partBlock->Ident, + kNeFSIdentLen); + + rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, + rt_string_len(cUntitledHD)); + + SizeT catalogCount = 0UL; + + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_drv_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); + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive->fOutput(&drive->fPacket); + + 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; + + // write the root catalog. + this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); + + return true; + } + + kcout << "partition block already exists.\r"; + + start += partBlock->DiskSize; + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = start; + + drive->fInput(&drive->fPacket); + } + + return false; +} + +/// @brief Writes the data fork into a specific catalog. +/// @param catalog the catalog itself +/// @param data the data. +/// @return if the catalog w rote the contents successfully. +bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) +{ + if (sizeOfData > kNeFSForkDataSz) + return No; + + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + auto startFork = (!isRsrcFork) ? catalog->DataFork + : catalog->ResourceFork; + + NFS_FORK_STRUCT* forkDataIn = new NFS_FORK_STRUCT(); + NFS_FORK_STRUCT prevFork{}; + + // sanity check of the fork position as the condition to run the loop. + while (startFork >= kNeFSCatalogStartAddress) + { + drive.fPacket.fPacketContent = forkDataIn; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fLba = startFork; + + drive.fInput(&drive.fPacket); + + // check the fork, if it's position is valid. + if (forkDataIn->DataOffset <= kNeFSCatalogStartAddress) + { + ErrLocal() = kErrorDiskIsCorrupted; + + kcout << "Invalid fork offset.\r"; + + return false; + } + + if (forkDataIn->Flags != kNeFSFlagUnallocated && + forkDataIn->Flags != kNeFSFlagDeleted && + StringBuilder::Equals(forkDataIn->ForkName, forkName) && + StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) + { + // ===================================================== // + // Store the blob now. + // ===================================================== // + + forkDataIn->Flags = kNeFSFlagCreated; + forkDataIn->DataOffset = startFork - sizeof(NFS_FORK_STRUCT); + forkDataIn->DataSize = sizeOfData; + + drive.fPacket.fPacketContent = data; + drive.fPacket.fPacketSize = sizeOfData; + drive.fPacket.fLba = forkDataIn->DataOffset; + + kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; + + drive.fOutput(&drive.fPacket); + + drive.fPacket.fPacketContent = &forkDataIn; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fLba = startFork; + + drive.fOutput(&drive.fPacket); + + kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + + delete catalog; + + return true; + } + + // stumble upon a fork, store it. + + prevFork = *forkDataIn; + + startFork = forkDataIn->NextSibling; + } + + return false; +} + +/// @brief +/// @param catalogName the catalog name. +/// @return the newly found catalog. +_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName, + Lba& out_lba) +{ + kcout << "start finding catalog...\r"; + + NFS_ROOT_PARTITION_BLOCK fs_buf{0}; + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + drive.fPacket.fPacketContent = &fs_buf; + drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf; + + auto startCatalogList = part->StartCatalog; + const auto cCtartCatalogList = startCatalogList; + + auto localSearchFirst = false; + + NFS_CATALOG_STRUCT catalogBuf{0}; + + drive.fPacket.fLba = startCatalogList; + drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + + drive.fInput(&drive.fPacket); + + if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + { + Char parentName[kNeFSNodeNameLen] = {0}; + + for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) + { + parentName[indexFill] = catalogName[indexFill]; + } + + SizeT indexReverseCopy = rt_string_len(parentName); + + // zero character. + parentName[--indexReverseCopy] = 0; + + // mandatory '/' character. + parentName[--indexReverseCopy] = 0; + + while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + { + parentName[indexReverseCopy] = 0; + --indexReverseCopy; + } + + NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba); + + if (parentCatalog && + !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) + { + startCatalogList = parentCatalog->NextSibling; + delete parentCatalog; + + localSearchFirst = true; + } + else if (parentCatalog) + { + delete parentCatalog; + } + } + + kcout << "fetching catalog...\r"; + +NeFSSearchThroughCatalogList: + while (drive.fPacket.fPacketGood) + { + drive.fPacket.fLba = startCatalogList; + drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + + drive.fInput(&drive.fPacket); + + NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf; + + if (StringBuilder::Equals(catalogName, catalog->Name)) + { + /// ignore unallocated catalog, break + if (!(catalog->Flags & kNeFSFlagCreated)) + { + goto NeFSContinueSearch; + } + + NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); + rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); + + kcout << "found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "found catalog at: " << catalog->Name << endl; + + out_lba = startCatalogList; + return catalogPtr; + } + + NeFSContinueSearch: + startCatalogList = catalog->NextSibling; + + if (startCatalogList <= kNeFSRootCatalogStartAddress) + break; + } + + if (localSearchFirst) + { + localSearchFirst = false; + startCatalogList = cCtartCatalogList; + + goto NeFSSearchThroughCatalogList; + } + + out_lba = 0UL; + return nullptr; +} + +/// @brief Get catalog from filesystem. +/// @param name the catalog's name/ +/// @return +_Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name) +{ + Lba unused = 0; + return this->FindCatalog(name, unused); +} + +/// @brief Closes a catalog, (frees it). +/// @param catalog the catalog to close. +/// @return +Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) +{ + if (!catalog) + return false; + + delete catalog; + catalog = nullptr; + + return true; +} + +/// @brief Mark catalog as removed. +/// @param catalog The catalog structure. +/// @return if the catalog was removed or not. +Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) +{ + if (!catalogName || + StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + { + ErrLocal() = kErrorInternal; + return false; + } + + Lba out_lba = 0; + auto catalog = this->FindCatalog(catalogName, out_lba); + + if (out_lba >= kNeFSCatalogStartAddress || + catalog->Flags == kNeFSFlagCreated) + { + catalog->Flags = kNeFSFlagDeleted; + + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + drive.fPacket.fLba = out_lba; // the catalog position. + drive.fPacket.fPacketSize = + 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(NFS_ROOT_PARTITION_BLOCK)] = {0}; + + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = partitionBlockBuf; + drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); + + drive.fInput(&drive.fPacket); + + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast(partitionBlockBuf); + + --partBlock->CatalogCount; + ++partBlock->FreeSectors; + + drive.fOutput(&drive.fPacket); + + return true; + } + + delete catalog; + return false; +} + +/// ***************************************************************** /// +/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead. +/// ***************************************************************** /// + +/***********************************************************************************/ +/// @brief Read the catalog data fork. +/// @param catalog +/// @param dataSz +/// @return +/***********************************************************************************/ + +VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input SizeT dataSz, + _Input const Char* forkName) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return nullptr; + } + + constexpr auto cNeFSCatalogPadding = 4; + + Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; + Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; + + kcout << "catalog " << catalog->Name + << ", fork: " << hex_number(dataForkLba) << endl; + + NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + NFS_FORK_STRUCT* fs_fork_data = nullptr; + + while (dataForkLba > kNeFSCatalogStartAddress) + { + drive.fPacket.fLba = dataForkLba; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fPacketContent = fs_buf; + + drive.fInput(&drive.fPacket); + + fs_fork_data = fs_buf; + + kcout << "ForkName: " << fs_fork_data->ForkName << endl; + kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; + + if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && + StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) + break; + + dataForkLba = fs_fork_data->NextSibling; + } + + if (dataForkLba < kNeFSCatalogStartAddress) + { + delete[] fs_buf; + return nullptr; + } + + return fs_fork_data; +} + +/***********************************************************************************/ +/// @brief Seek in the data fork. +/// @param catalog the catalog offset. +/// @param off where to seek. +/// @return if the seeking was successful. +/***********************************************************************************/ + +bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return false; + } + + ErrLocal() = kErrorUnimplemented; + return false; +} + +/***********************************************************************************/ +/// @brief Tell where we are inside the data fork. +/// @param catalog +/// @return The position on the file. +/***********************************************************************************/ + +SizeT NeFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return 0; + } + + ErrLocal() = kErrorUnimplemented; + return 0; +} + +namespace Kernel::Detail +{ + /***********************************************************************************/ + /// @brief Construct NeFS drives. + /***********************************************************************************/ + Boolean fs_init_newfs(Void) noexcept + { + kcout << "Creating drives...\r"; + + sMountpointInterface.A() = io_construct_main_drive(); + sMountpointInterface.B() = io_construct_drive(); + sMountpointInterface.C() = io_construct_drive(); + sMountpointInterface.D() = io_construct_drive(); + + kcout << "Testing A:\r"; + + sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); + + kcout << "Testing A: [ OK ]\r"; + + return true; + } +} // namespace Kernel::Detail + +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx deleted file mode 100644 index 37b2a44c..00000000 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ /dev/null @@ -1,1048 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifdef __FSKIT_USE_NEWFS__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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. -/// \\ -/// \\Path1\\ \\ath2\\ -/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. -/// \\Path1\\readme.rtf -/***********************************************************************************/ - -STATIC MountpointInterface sMountpointInterface; - -/***********************************************************************************/ -/// @brief Creates a new fork inside the New filesystem partition. -/// @param catalog it's catalog -/// @param theFork the fork itself. -/// @return the fork -/***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork) -{ - if (catalog && theFork.ForkName[0] != 0) - { - Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork - : catalog->ResourceFork; - - kcout << "fork lba: " << hex_number(lba) << endl; - - if (lba <= kNewFSCatalogStartAddress) - return nullptr; - - auto drv = sMountpointInterface.A(); - - /// special treatment. - rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - 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. - while (true) - { - if (lba <= kNewFSCatalogStartAddress) - break; - - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &curFork; - - drv.fInput(&drv.fPacket); - - if (curFork.NextSibling > kBadAddress) - { - kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; - break; - } - - kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - - if (curFork.Flags == kNewFSFlagCreated) - { - kcout << "fork already exists.\r"; - - /// sanity check. - if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && - StringBuilder::Equals(curFork.CatalogName, catalog->Name)) - return nullptr; - - kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - - lbaOfPreviousFork = lba; - lba = curFork.NextSibling; - - prevFork = curFork; - } - else - { - /// This is a check that we have, in order to link the previous fork - /// entry. - if (lba >= kNewFSCatalogStartAddress) - { - drv.fPacket.fLba = lbaOfPreviousFork; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &prevFork; - - prevFork.NextSibling = lba; - - /// write to disk. - drv.fOutput(&drv.fPacket); - } - - break; - } - } - - constexpr auto cForkPadding = - 4; /// this value gives us space for the data offset. - - theFork.Flags = kNewFSFlagCreated; - theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; - theFork.PreviousSibling = lbaOfPreviousFork; - theFork.NextSibling = theFork.DataOffset - theFork.DataSize; - - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &theFork; - - drv.fOutput(&drv.fPacket); - - /// log what we have now. - kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) - << endl; - - kcout << "Wrote fork at: " << hex_number(lba) << endl; - - return &theFork; - } - - return nullptr; -} - -/***********************************************************************************/ -/// @brief Find fork inside New filesystem. -/// @param catalog the catalog. -/// @param name the fork name. -/// @return the fork. -/***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - Boolean isDataFork) -{ - auto drv = sMountpointInterface.A(); - NFS_FORK_STRUCT* theFork = nullptr; - - Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; - - while (lba != 0) - { - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = (VoidPtr)theFork; - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16); - - if (auto res = - fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex); - res) - { - switch (res) - { - case 1: - ErrLocal() = kErrorDiskReadOnly; - break; - case 2: - ErrLocal() = kErrorDiskIsFull; - break; - ErrLocal() = kErrorNoSuchDisk; - break; - - default: - break; - } - return nullptr; - } - - if (StringBuilder::Equals(theFork->ForkName, name)) - { - break; - } - - lba = theFork->NextSibling; - } - - return theFork; -} - -/***********************************************************************************/ -/// @brief Simpler factory to create a catalog (assumes you want to create a -/// file.) -/// @param name -/// @return catalog pointer. -/***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name) -{ - return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); -} - -/***********************************************************************************/ -/// @brief Creates a new catalog into the disk. -/// @param name the catalog name. -/// @param flags the flags of the catalog. -/// @param kind the catalog kind. -/// @return catalog pointer. -/***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind) -{ - kcout << "CreateCatalog(...)\r"; - - Lba out_lba = 0UL; - - kcout << "Checking for extension...\r"; - - /// a directory should have a slash in the end. - if (kind == kNewFSCatalogKindDir && - name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) - return nullptr; - - /// a file shouldn't have a slash in the end. - if (kind != kNewFSCatalogKindDir && - name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) - return nullptr; - - NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); - - if (catalog_copy) - { - kcout << "Catalog already exists: " << name << ".\r"; - ErrLocal() = kErrorFileExists; - - return catalog_copy; - } - - Char parentName[kNewFSNodeNameLen] = {0}; - - for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) - { - parentName[indexName] = name[indexName]; - } - - if (*parentName == 0) - { - kcout << "Parent name is NUL.\r"; - ErrLocal() = kErrorFileNotFound; - return nullptr; - } - - /// Locate parent catalog, to then allocate right after it. - - for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) - { - parentName[indexFill] = name[indexFill]; - } - - SizeT indexReverseCopy = rt_string_len(parentName); - - // zero character it. - parentName[--indexReverseCopy] = 0; - - // mandatory / character, zero it. - parentName[--indexReverseCopy] = 0; - - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) - { - parentName[indexReverseCopy] = 0; - --indexReverseCopy; - } - - NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, out_lba); - - auto drive = sMountpointInterface.A(); - - if (catalog && catalog->Kind == kNewFSCatalogKindFile) - { - kcout << "Parent name is file.\r"; - delete catalog; - return nullptr; - } - else if (!catalog) - { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - constexpr auto cNewFSCatalogPadding = 4; - - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - out_lba = partBlock->StartCatalog; - } - - constexpr SizeT cDefaultForkSize = kNewFSForkSize; - - NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); - - Int32 flagsList = flags; - - catalogChild->ResourceForkSize = cDefaultForkSize; - catalogChild->DataForkSize = cDefaultForkSize; - - catalogChild->NextSibling = out_lba; - catalogChild->PrevSibling = out_lba; - catalogChild->Kind = kind; - catalogChild->Flags = kNewFSFlagCreated | flagsList; - - rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, - rt_string_len(name)); - - UInt16 catalogBuf[kNewFSSectorSz] = {0}; - - 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.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = start_free; - - drive.fInput(&drive.fPacket); - - NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; - - start_free = nextSibling->NextSibling; - - catalogChild->PrevSibling = out_lba; - - drive.fPacket.fLba = start_free; - drive.fInput(&drive.fPacket); - - while (drive.fPacket.fPacketGood) - { - nextSibling = reinterpret_cast(catalogBuf); - - if (start_free <= kNewFSRootCatalogStartAddress) - { - delete catalogChild; - delete catalog; - - return nullptr; - } - - // ========================== // - // Allocate catalog now... - // ========================== // - if ((nextSibling->Flags & kNewFSFlagCreated) == 0) - { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - constexpr auto cNewFSCatalogPadding = 4; - - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - - if (partBlock->FreeCatalog < 1) - { - delete catalogChild; - return nullptr; - } - - catalogChild->DataFork = partBlock->DiskSize - start_free; - catalogChild->ResourceFork = catalogChild->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)) - { - catalogChild->NextSibling = - start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); - } - - drive.fPacket.fPacketContent = catalogChild; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - drive.fPacket.fLba = start_free; - - drive.fOutput(&drive.fPacket); - - // Get NewFS partition's block. - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - partBlock->FreeSectors -= 1; - partBlock->CatalogCount += 1; - partBlock->FreeCatalog -= 1; - - drive.fOutput(&drive.fPacket); - - kcout << "Create new catalog, status: " - << hex_number(catalogChild->Flags) << endl; - kcout << "Create new catalog, name: " << catalogChild->Name - << endl; - - delete catalog; - return catalogChild; - } - else if ((nextSibling->Flags & kNewFSFlagCreated) && - StringBuilder::Equals(nextSibling->Name, name)) - { - return nextSibling; - } - - constexpr auto cNewFSCatalogPadding = 4; - - //// @note that's how we find the next catalog in the partition block. - start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); - - drive.fPacket.fPacketContent = catalogBuf; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = start_free; - - drive.fInput(&drive.fPacket); - } - - delete catalog; - return nullptr; -} - -/// @brief Make a EPM+NewFS drive out of the disk. -/// @param drive The drive to write on. -/// @return If it was sucessful, see ErrLocal(). -bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) -{ - if (*part_name == 0 || - endLba == 0) - return false; - - // verify disk. - drive->fVerify(&drive->fPacket); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - // if disk isn't good, then error out. - if (false == drive->fPacket.fPacketGood) - { - ErrLocal() = kErrorDiskIsCorrupted; - return false; - } - - Char fs_buf[kNewFSSectorSz] = {0}; - - Lba start = kNewFSRootCatalogStartAddress; - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = start; - - drive->fInput(&drive->fPacket); - - if (flags & kNewFSPartitionTypeBoot) - { - // make it bootable when needed. - Char bufEpmHdr[kNewFSSectorSz] = {0}; - - BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; - - // EPM header. - - constexpr auto cFsName = "NewFS"; - constexpr auto cBlockName = "ZKA:"; - - rt_copy_memory(reinterpret_cast(const_cast(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); - - epmBoot->FsVersion = kNewFSVersionInteger; - epmBoot->LbaStart = start; - epmBoot->SectorSz = kNewFSSectorSz; - - rt_copy_memory(reinterpret_cast(const_cast(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); - rt_copy_memory(reinterpret_cast(const_cast(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); - - Lba outEpmLba = kEpmBase; - - Char buf[kNewFSSectorSz]; - - Lba prevStart = 0; - SizeT cnt = 0; - - while (drive->fPacket.fPacketGood) - { - drive->fPacket.fPacketContent = buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = outEpmLba; - - drive->fInput(&drive->fPacket); - - if (buf[0] == 0) - { - epmBoot->LbaStart = prevStart; - - if (epmBoot->LbaStart) - epmBoot->LbaStart = outEpmLba; - - epmBoot->LbaEnd = endLba; - epmBoot->NumBlocks = cnt; - - drive->fPacket.fPacketContent = bufEpmHdr; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = outEpmLba; - - drive->fOutput(&drive->fPacket); - - break; - } - else - { - prevStart = ((BOOT_BLOCK_STRUCT*)buf)->LbaStart + ((BOOT_BLOCK_STRUCT*)buf)->LbaEnd; - } - - outEpmLba += sizeof(BOOT_BLOCK_STRUCT); - ++cnt; - } - } - - // disk isnt faulty and data has been fetched. - while (drive->fPacket.fPacketGood) - { - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; - - // check for an empty partition here. - if (partBlock->PartitionName[0] == 0 && - rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) - { - // partition is free and valid. - - partBlock->Version = kNewFSVersionInteger; - - const auto cUntitledHD = part_name; - - rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, - kNewFSIdentLen); - - rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, - rt_string_len(cUntitledHD)); - - 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(NFS_CATALOG_STRUCT); - partBlock->SectorCount = sectorCount; - partBlock->DiskSize = diskSize; - partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive->fOutput(&drive->fPacket); - - 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; - - // write the root catalog. - this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); - - return true; - } - - kcout << "partition block already exists.\r"; - - start += partBlock->DiskSize; - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = start; - - drive->fInput(&drive->fPacket); - } - - return false; -} - -/// @brief Writes the data fork into a specific catalog. -/// @param catalog the catalog itself -/// @param data the data. -/// @return if the catalog w rote the contents successfully. -bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) -{ - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - auto startFork = (!isRsrcFork) ? catalog->DataFork - : catalog->ResourceFork; - - NFS_FORK_STRUCT* forkDataIn = new NFS_FORK_STRUCT(); - NFS_FORK_STRUCT prevFork{}; - - // sanity check of the fork position as the condition to run the loop. - while (startFork >= kNewFSCatalogStartAddress) - { - drive.fPacket.fPacketContent = forkDataIn; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; - - drive.fInput(&drive.fPacket); - - // check the fork, if it's position is valid. - if (forkDataIn->DataOffset <= kNewFSCatalogStartAddress) - { - ErrLocal() = kErrorDiskIsCorrupted; - - kcout << "Invalid fork offset.\r"; - - return false; - } - - if (forkDataIn->Flags != kNewFSFlagUnallocated && - forkDataIn->Flags != kNewFSFlagDeleted && - StringBuilder::Equals(forkDataIn->ForkName, forkName) && - StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) - { - // ===================================================== // - // Store size of blob now. - // ===================================================== // - - if (forkDataIn->DataSize < sizeOfData && - forkDataIn->DataSize < 1) - { - startFork = forkDataIn->NextSibling; - continue; - } - - forkDataIn->Flags = kNewFSFlagCreated; - forkDataIn->DataOffset = startFork + sizeof(NFS_FORK_STRUCT); - forkDataIn->DataSize = sizeOfData; - - drive.fPacket.fPacketContent = data; - drive.fPacket.fPacketSize = sizeOfData; - drive.fPacket.fLba = startFork + sizeof(NFS_FORK_STRUCT); - - kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; - - drive.fOutput(&drive.fPacket); - - drive.fPacket.fPacketContent = &forkDataIn; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; - - drive.fOutput(&drive.fPacket); - - kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; - - delete catalog; - - return true; - } - - // stumble upon a fork, store it. - - prevFork = *forkDataIn; - - startFork = forkDataIn->NextSibling; - } - - return false; -} - -/// @brief -/// @param catalogName the catalog name. -/// @return the newly found catalog. -_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogName, - Lba& out_lba) -{ - kcout << "start finding catalog...\r"; - - NFS_ROOT_PARTITION_BLOCK fs_buf{0}; - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - drive.fPacket.fPacketContent = &fs_buf; - drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf; - - auto startCatalogList = part->StartCatalog; - const auto cCtartCatalogList = startCatalogList; - - auto localSearchFirst = false; - - NFS_CATALOG_STRUCT catalogBuf{0}; - - drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - - drive.fInput(&drive.fPacket); - - if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) - { - Char parentName[kNewFSNodeNameLen] = {0}; - - for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) - { - parentName[indexFill] = catalogName[indexFill]; - } - - SizeT indexReverseCopy = rt_string_len(parentName); - - // zero character. - parentName[--indexReverseCopy] = 0; - - // mandatory '/' character. - parentName[--indexReverseCopy] = 0; - - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) - { - parentName[indexReverseCopy] = 0; - --indexReverseCopy; - } - - NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba); - - if (parentCatalog && - !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) - { - startCatalogList = parentCatalog->NextSibling; - delete parentCatalog; - - localSearchFirst = true; - } - else if (parentCatalog) - { - delete parentCatalog; - } - } - - kcout << "fetching catalog...\r"; - -NewFSSearchThroughCatalogList: - while (drive.fPacket.fPacketGood) - { - drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - - drive.fInput(&drive.fPacket); - - NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf; - - if (StringBuilder::Equals(catalogName, catalog->Name)) - { - /// ignore unallocated catalog, break - if (!(catalog->Flags & kNewFSFlagCreated)) - { - goto NewFSContinueSearch; - } - - NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); - rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); - - kcout << "found catalog at: " << hex_number(startCatalogList) << endl; - kcout << "found catalog at: " << catalog->Name << endl; - - out_lba = startCatalogList; - return catalogPtr; - } - - NewFSContinueSearch: - startCatalogList = catalog->NextSibling; - - if (startCatalogList <= kNewFSRootCatalogStartAddress) - break; - } - - if (localSearchFirst) - { - localSearchFirst = false; - startCatalogList = cCtartCatalogList; - - goto NewFSSearchThroughCatalogList; - } - - out_lba = 0UL; - return nullptr; -} - -/// @brief Get catalog from filesystem. -/// @param name the catalog's name/ -/// @return -_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const Char* name) -{ - Lba unused = 0; - return this->FindCatalog(name, unused); -} - -/// @brief Closes a catalog, (frees it). -/// @param catalog the catalog to close. -/// @return -Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) -{ - if (!catalog) - return false; - - delete catalog; - catalog = nullptr; - - return true; -} - -/// @brief Mark catalog as removed. -/// @param catalog The catalog structure. -/// @return if the catalog was removed or not. -Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) -{ - if (!catalogName || - StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) - { - ErrLocal() = kErrorInternal; - return false; - } - - Lba out_lba = 0; - auto catalog = this->FindCatalog(catalogName, out_lba); - - if (out_lba >= kNewFSCatalogStartAddress || - catalog->Flags == kNewFSFlagCreated) - { - catalog->Flags = kNewFSFlagDeleted; - - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - drive.fPacket.fLba = out_lba; // the catalog position. - drive.fPacket.fPacketSize = - 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(NFS_ROOT_PARTITION_BLOCK)] = {0}; - - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - drive.fPacket.fPacketContent = partitionBlockBuf; - drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - - drive.fInput(&drive.fPacket); - - NFS_ROOT_PARTITION_BLOCK* partBlock = - reinterpret_cast(partitionBlockBuf); - - --partBlock->CatalogCount; - ++partBlock->FreeSectors; - - drive.fOutput(&drive.fPacket); - - return true; - } - - delete catalog; - return false; -} - -/// ***************************************************************** /// -/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead. -/// ***************************************************************** /// - -/***********************************************************************************/ -/// @brief Read the catalog data fork. -/// @param catalog -/// @param dataSz -/// @return -/***********************************************************************************/ - -VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input SizeT dataSz, - _Input const Char* forkName) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return nullptr; - } - - constexpr auto cNewFSCatalogPadding = 4; - - Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; - Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; - - kcout << "catalog " << catalog->Name - << ", fork: " << hex_number(dataForkLba) << endl; - - NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - NFS_FORK_STRUCT* fs_fork_data = nullptr; - - while (dataForkLba > kNewFSCatalogStartAddress) - { - drive.fPacket.fLba = dataForkLba; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fPacketContent = fs_buf; - - drive.fInput(&drive.fPacket); - - fs_fork_data = fs_buf; - - kcout << "ForkName: " << fs_fork_data->ForkName << endl; - kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; - - if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && - StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) - break; - - dataForkLba = fs_fork_data->NextSibling; - } - - if (dataForkLba < kNewFSCatalogStartAddress) - { - delete[] fs_buf; - return nullptr; - } - - return fs_fork_data; -} - -/***********************************************************************************/ -/// @brief Seek in the data fork. -/// @param catalog the catalog offset. -/// @param off where to seek. -/// @return if the seeking was successful. -/***********************************************************************************/ - -bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return false; - } - - ErrLocal() = kErrorUnimplemented; - return false; -} - -/***********************************************************************************/ -/// @brief Tell where we are inside the data fork. -/// @param catalog -/// @return The position on the file. -/***********************************************************************************/ - -SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return 0; - } - - ErrLocal() = kErrorUnimplemented; - return 0; -} - -namespace Kernel::Detail -{ - /***********************************************************************************/ - /// @brief Construct NewFS drives. - /***********************************************************************************/ - Boolean fs_init_newfs(Void) noexcept - { - kcout << "Creating drives...\r"; - - sMountpointInterface.A() = io_construct_main_drive(); - sMountpointInterface.B() = io_construct_drive(); - sMountpointInterface.C() = io_construct_drive(); - sMountpointInterface.D() = io_construct_drive(); - - kcout << "Testing A:\r"; - - sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - - kcout << "Testing A: [ OK ]\r"; - - return true; - } -} // namespace Kernel::Detail - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index 270c13f2..cbd2a4f4 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -80,7 +80,7 @@ namespace Kernel if (!size) return; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; this->Write(cDataForkName, node, data, flags, size); } @@ -96,7 +96,7 @@ namespace Kernel if (!size) return nullptr; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; return this->Read(cDataForkName, node, flags, size); } @@ -107,7 +107,7 @@ namespace Kernel _Input SizeT size) { if (!size || - size > kNewFSForkSize) + size > kNeFSForkSize) return; if (!data) @@ -115,7 +115,7 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, name); } @@ -125,7 +125,7 @@ namespace Kernel _Input Int32 flags, _Input SizeT sz) { - if (sz > kNewFSForkSize) + if (sz > kNeFSForkSize) return nullptr; if (!sz) @@ -133,7 +133,7 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, name); @@ -182,7 +182,7 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - _Output NewFSParser* NewFilesystemMgr::GetParser() noexcept + _Output NeFSParser* NewFilesystemMgr::GetParser() noexcept { return fImpl; } diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx index 1ffa774a..29beda45 100644 --- a/dev/ZKA/Sources/NewFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NewFS+FileMgr.cxx @@ -9,7 +9,7 @@ #ifdef __FSKIT_USE_NEWFS__ -/// @brief NewFS File manager. +/// @brief NeFS File manager. /// BUGS: 0 namespace Kernel @@ -18,7 +18,7 @@ namespace Kernel NewFilesystemMgr::NewFilesystemMgr() { MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NewFSParser(); + fImpl = new NeFSParser(); MUST_PASS(fImpl); kcout << "We are done here... (NewFilesystemMgr).\r"; @@ -58,7 +58,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node with is a alias. @@ -66,7 +66,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateAlias(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } /// @brief Creates a node with is a page file. @@ -74,35 +74,35 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return const Char* NewFilesystemHelper::Root() { - return kNewFSRoot; + return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return const Char* NewFilesystemHelper::UpDir() { - return kNewFSUpDir; + return kNeFSUpDir; } /// @brief Gets the separator character. /// @return const Char NewFilesystemHelper::Separator() { - return kNewFSSeparator; + return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return const Char NewFilesystemHelper::MetaFile() { - return kNewFSMetaFilePrefix; + return kNeFSMetaFilePrefix; } } // namespace Kernel diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NewFS+IO.cxx index e1a6ac95..7917c1bb 100644 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ b/dev/ZKA/Sources/NewFS+IO.cxx @@ -9,7 +9,7 @@ /************************************************************* * - * File: NewFS+IO.cxx + * File: NeFS+IO.cxx * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * @@ -42,19 +42,19 @@ Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvInd switch (DrvIndex) { - case kNewFSSubDriveA: { + case kNeFSSubDriveA: { NEWFS_READ(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { + case kNeFSSubDriveB: { NEWFS_READ(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { + case kNeFSSubDriveC: { NEWFS_READ(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { + case kNeFSSubDriveD: { NEWFS_READ(D, DrvTrait.fPacket, Mnt); break; } @@ -77,19 +77,19 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn switch (DrvIndex) { - case kNewFSSubDriveA: { + case kNeFSSubDriveA: { NEWFS_WRITE(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { + case kNeFSSubDriveB: { NEWFS_WRITE(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { + case kNeFSSubDriveC: { NEWFS_WRITE(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { + case kNeFSSubDriveD: { NEWFS_WRITE(D, DrvTrait.fPacket, Mnt); break; } diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx index 2f63cc9a..f8d82fcd 100644 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ b/dev/ZKA/Sources/NewFS+Journal.cxx @@ -10,8 +10,8 @@ #ifdef __FSKIT_USE_NEWFS__ ///! BUGS: 0 -///! @file NewFS+Journal.cxx -///! @brief Journaling for NewFS. +///! @file NeFS+Journal.cxx +///! @brief Journaling for NeFS. namespace Kernel::Journal { -- cgit v1.2.3 From 3b60a1e87ab02a1b72d8bb9f7392780899d5a0d7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 19:53:08 +0200 Subject: [ IMP ] HPFS EBS and NeFS overhaul. Signed-off-by: Amlal El Mahrouss --- .vscode/c_cpp_properties.json | 4 +- dev/HPFS/Sources/IFSMain.rs | 12 +++ dev/HPFS/X64/EBS.asm | 27 ++++--- dev/HPFS/hpfs.json | 2 +- dev/HPFS/hpfs_main.rs | 10 --- dev/ZBA/BootKit/BootKit.hxx | 4 +- dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx | 9 +-- dev/ZBA/amd64-efi.make | 2 +- dev/ZKA/FSKit/FAT32.hxx | 12 --- dev/ZKA/FSKit/HPFS.hxx | 12 +++ dev/ZKA/FSKit/NeFS.hxx | 13 ++-- dev/ZKA/KernelKit/FileMgr.hxx | 8 +- dev/ZKA/KernelKit/PEFCodeMgr.hxx | 4 +- dev/ZKA/NewKit/Macros.hxx | 2 - dev/ZKA/Sources/DLLMain.cxx | 97 +----------------------- dev/ZKA/Sources/DriveMgr.cxx | 10 ++- dev/ZKA/Sources/FS/FAT32.cxx | 4 +- dev/ZKA/Sources/FS/NeFS.cxx | 28 ++++--- dev/ZKA/Sources/FileMgr.cxx | 4 +- dev/ZKA/Sources/NeFS+FileMgr.cxx | 109 +++++++++++++++++++++++++++ dev/ZKA/Sources/NeFS+IO.cxx | 101 +++++++++++++++++++++++++ dev/ZKA/Sources/NewFS+FileMgr.cxx | 109 --------------------------- dev/ZKA/Sources/NewFS+IO.cxx | 101 ------------------------- dev/ZKA/Sources/NewFS+Journal.cxx | 22 ------ dev/ZKA/Sources/UserProcessScheduler.cxx | 23 ++++-- dev/ZKA/Sources/compile_flags.txt | 2 +- dev/ZKA/amd64-efi.make | 2 +- dev/ZKA/arm64-efi.make | 2 +- doc/NeFS.pdf | Bin 0 -> 13654 bytes doc/NewFS.pdf | Bin 13654 -> 0 bytes 30 files changed, 322 insertions(+), 413 deletions(-) create mode 100644 dev/HPFS/Sources/IFSMain.rs delete mode 100644 dev/HPFS/hpfs_main.rs delete mode 100644 dev/ZKA/FSKit/FAT32.hxx create mode 100644 dev/ZKA/FSKit/HPFS.hxx create mode 100644 dev/ZKA/Sources/NeFS+FileMgr.cxx create mode 100644 dev/ZKA/Sources/NeFS+IO.cxx delete mode 100644 dev/ZKA/Sources/NewFS+FileMgr.cxx delete mode 100644 dev/ZKA/Sources/NewFS+IO.cxx delete mode 100644 dev/ZKA/Sources/NewFS+Journal.cxx create mode 100644 doc/NeFS.pdf delete mode 100644 doc/NewFS.pdf (limited to 'dev') diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 5c0ed4d2..6a8b4dfb 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -12,7 +12,7 @@ "__NEWOSKRNL__", "Z_PREFIX", "__HAVE_ZKA_APIS__", - "__FSKIT_USE_NEWFS__", + "__FSKIT_USE_NEFS__", "__EFI_x86_64__", "__ATA_PIO__", "__ZKA_AMD64__", @@ -35,7 +35,7 @@ "__NEWOSKRNL__", "Z_PREFIX", "__HAVE_ZKA_APIS__", - "__FSKIT_USE_NEWFS__", + "__FSKIT_USE_NEFS__", "__EFI_x86_64__", "__ATA_PIO__", "__ZKA_AMD64__", diff --git a/dev/HPFS/Sources/IFSMain.rs b/dev/HPFS/Sources/IFSMain.rs new file mode 100644 index 00000000..5a49585a --- /dev/null +++ b/dev/HPFS/Sources/IFSMain.rs @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: IFSMain.rs + PURPOSE: HPFS IFS. + +------------------------------------------- */ + +fn IFSStart() { + +} \ No newline at end of file diff --git a/dev/HPFS/X64/EBS.asm b/dev/HPFS/X64/EBS.asm index f42098a2..3c55825b 100644 --- a/dev/HPFS/X64/EBS.asm +++ b/dev/HPFS/X64/EBS.asm @@ -1,25 +1,28 @@ ;; FILE: EBS.asm -;; PURPOSE: EXPLICIT BOOT SECTOR OF HPFS. +;; PURPOSE: EXPLICIT BOOT SECTOR STRUCTURE (HPFS RELATED). ;; AUTHOR: AMLAL EL MAHROUSS -;; THIS IS PART OF THE HPFS FOR AMD64 FILESYSTEM PACKAGE. [bits 64] -;; WRITE THIS A BLOB TO THEN DUMP INTO DISK. +;; DUMP THIS BLOB TO DISK, WHEN FORMATTING THE SSD. HPFS_EBS_HEADER: - db " HPFS", 0 ;; MAGIC NUMBER OF FILESYSTEM + db "HPFS ", 0 ;; MAGIC NUMBER OF FILESYSTEM + dq 0 ;; RESERVED 4 dw 1 ;; VERSION dw 0 ;; PARTITION TYPE + dq 0 ;; RESERVED 3 dw 0 ;; DISK TYPE (INVALID = 0, CDROM = 1, SSD = 2, USB = 3) dw 0 ;; CHECKSUM OF PARTITION dw 0 ;; IS IT LOCKED? (DISK ENCRYPTION ON?) dq 0 ;; SECTOR COUNT - dw 512 ;; SECTOR SZ - dq 0 ;; KERNEL FILE RECORD LBA - dq 0 ;; KERNEL FILE RECORD SIZE -;; READ LAST, WHEN KERNEL LBA IS READ. -HPFS_EBS_JUMP_FIELD: - nop - nop - jmp 0x4000000 ;; OS JUMP FIELD, OS SHOULD BE AT THAT LOCATION \ No newline at end of file + dq 0 ;; RESERVED 2 + dq 512 ;; SECTOR SZ + dq 0 ;; DISK SIZE + dq 0 ;; RESERVED 1 + dq 0 ;; LOCKER ON? + dq 0 ;; PARTITION MAP TYPE (GPT, MBR, EPM) + dq 0 ;; MASTER FILE TABLE + dq 0 ;; MASTER TRACE TABLE + dq 0 ;; MASTER DIRECTORY TABLE + dw 0xFFFF ;; END OF HEADER WORD \ No newline at end of file diff --git a/dev/HPFS/hpfs.json b/dev/HPFS/hpfs.json index 1098dfd3..3a13297b 100644 --- a/dev/HPFS/hpfs.json +++ b/dev/HPFS/hpfs.json @@ -1,7 +1,7 @@ { "compiler_path": "rustc", "compiler_std": "", - "sources_path": ["*.rs"], + "sources_path": ["Sources/*.rs"], "output_name": "hpfs.sys", "compiler_flags": [ ], diff --git a/dev/HPFS/hpfs_main.rs b/dev/HPFS/hpfs_main.rs deleted file mode 100644 index ed66d175..00000000 --- a/dev/HPFS/hpfs_main.rs +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Created on Thu Sep 05 2024 - * - * Copyright (c) 2024 ZKA Technologies. - */ - -fn main() { - println!("ZKA High Performance File System Driver for ZKA/OS."); - println!("Copyright ZKA technologies, all rights reserved."); -} \ No newline at end of file diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 3732ea8d..3f7b0a96 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -236,7 +236,7 @@ public: return false; } - writer.Write(L"newosldr: Disk size: ").Write(this->fDiskDev.GetDiskSize()).Write(L"\r"); + writer.Write(L"newosldr: Disk is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r"); if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || blockPart->DiskSize < 1 || @@ -251,7 +251,7 @@ public: return false; } - writer.Write(L"newosldr: Partition name: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); + writer.Write(L"newosldr: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); return true; } diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx index 467f4303..d43be468 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx @@ -134,7 +134,6 @@ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) BTextWriter& BTextWriter::Write(const Long& x) { #ifdef __DEBUG__ - this->Write(L"0x"); this->_Write(x); #endif // ifdef __DEBUG__ @@ -145,14 +144,14 @@ BTextWriter& BTextWriter::Write(const Long& x) BTextWriter& BTextWriter::_Write(const Long& x) { #ifdef __DEBUG__ - UInt64 y = (x > 0 ? x : -x) / 16; - UInt64 h = (x > 0 ? x : -x) % 16; + UInt64 y = (x > 0 ? x : -x) / 10; + UInt64 h = (x > 0 ? x : -x) % 10; if (y) this->_Write(y); /* fail if the hex number is not base-16 */ - if (h > 15) + if (h > 10) { this->WriteCharacter('?'); return *this; @@ -161,7 +160,7 @@ BTextWriter& BTextWriter::_Write(const Long& x) if (y < 0) y = -y; - const char cNumbers[17] = "0123456789ABCDEF"; + const char cNumbers[] = "0123456789"; this->WriteCharacter(cNumbers[h]); #endif // ifdef __DEBUG__ diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 5d5071e0..1f8bf1b1 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -36,7 +36,7 @@ EMU_FLAGS=-net none -m 8G -M q35 \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -d int + -device ide-hd,drive=disk_2,bus=ahci.0 -serial stdio -no-reboot LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/FSKit/FAT32.hxx b/dev/ZKA/FSKit/FAT32.hxx deleted file mode 100644 index 04fa0c6d..00000000 --- a/dev/ZKA/FSKit/FAT32.hxx +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file FAT32.hxx -/// @brief FAT32 support. \ No newline at end of file diff --git a/dev/ZKA/FSKit/HPFS.hxx b/dev/ZKA/FSKit/HPFS.hxx new file mode 100644 index 00000000..6f5ff3f4 --- /dev/null +++ b/dev/ZKA/FSKit/HPFS.hxx @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file HPFS.hxx +/// @brief HPFS support. \ No newline at end of file diff --git a/dev/ZKA/FSKit/NeFS.hxx b/dev/ZKA/FSKit/NeFS.hxx index d1c0c9c7..2bf17863 100644 --- a/dev/ZKA/FSKit/NeFS.hxx +++ b/dev/ZKA/FSKit/NeFS.hxx @@ -3,7 +3,7 @@ Copyright ZKA Technologies. FILE: NeFS.hxx - PURPOSE: NeFS (New FileSystem) kernel support. + PURPOSE: NeFS (New FileSystem) support, can be used with kernel, HPFS is preferred. Revision History: @@ -31,11 +31,11 @@ default. #define kNeFSNodeNameLen (256) #define kNeFSSectorSz (512) -#define kNeFSForkDataSz (gib_cast(16)) +#define kNeFSForkDataSz (kib_cast(8)) #define kNeFSIdentLen (8) -#define kNeFSIdent " NewFS" -#define kNeFSPadLen (400) +#define kNeFSIdent " NeFS" +#define kNeFSPadLen (392) #define kNeFSMetaFilePrefix '$' @@ -69,8 +69,9 @@ default. #define kNeFSCatalogKindLock (10) #define kNeFSCatalogKindRLE (11) - #define kNeFSCatalogKindMetaFile (12) +#define kNeFSCatalogKindTTF (13) +#define kNeFSCatalogKindRIFF (14) #define kNeFSSeparator '\\' #define kNeFSSeparatorAlt '/' @@ -193,7 +194,7 @@ struct PACKED NFS_ROOT_PARTITION_BLOCK final Kernel::Lba EpmBlock; - Kernel::Char Pad[kNeFSPadLen - sizeof(Kernel::Lba)]; + Kernel::Char Pad[kNeFSPadLen]; }; namespace Kernel diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index a46216db..86eade6a 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -19,9 +19,9 @@ #pragma once -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ #include -#endif // __FSKIT_USE_NEWFS__ +#endif // __FSKIT_USE_NEFS__ #include #include @@ -135,7 +135,7 @@ namespace Kernel virtual bool Rewind(_Input NodePtr node) = 0; }; -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ /** * @brief Based of FilesystemMgrInterface, takes care of managing NeFS * disks. @@ -184,7 +184,7 @@ namespace Kernel NeFSParser* fImpl{nullptr}; }; -#endif // ifdef __FSKIT_USE_NEWFS__ +#endif // ifdef __FSKIT_USE_NEFS__ /** * Usable FileStream diff --git a/dev/ZKA/KernelKit/PEFCodeMgr.hxx b/dev/ZKA/KernelKit/PEFCodeMgr.hxx index 74cc8eb0..c2938fae 100644 --- a/dev/ZKA/KernelKit/PEFCodeMgr.hxx +++ b/dev/ZKA/KernelKit/PEFCodeMgr.hxx @@ -46,11 +46,11 @@ namespace Kernel bool IsLoaded() noexcept; private: -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ OwnPtr> fFile; #else OwnPtr> fFile; -#endif // __FSKIT_USE_NEWFS__ +#endif // __FSKIT_USE_NEFS__ Ref fPath; VoidPtr fCachedBlob; diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index 0de25216..b20ddb8a 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -126,5 +126,3 @@ /// @brief The main kernel file. #define kSysChime "\\System\\startup.wav" -/// @brief The main kernel file. -#define kSysKrnl "\\System\\newoskrnl.exe" diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 0fa3a181..2aed9bf7 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -79,8 +79,8 @@ namespace Kernel::Detail if (catalogDir) { - CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory already exists: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory already exists: ")), RGB(0, 0, 0)); delete catalogDir; continue; @@ -89,101 +89,12 @@ namespace Kernel::Detail catalogDir = fNeFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, kNeFSCatalogKindDir); - CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory has been created: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory has been created: ")), RGB(0, 0, 0)); delete catalogDir; } } - - constexpr auto cFileToFormatCnt = 5; - - struct - { - VoidPtr fBlob; - Size fBlobSz; - Int32 fFlags; - Char fName[kNeFSNodeNameLen]; - } cFiles[cFileToFormatCnt] = { - { - .fBlob = kHandoverHeader->f_KernelImage, - .fBlobSz = kHandoverHeader->f_KernelSz, - .fFlags = kNeFSCatalogKindExecutable, - .fName = kSysKrnl, - }, - { - .fBlob = kHandoverHeader->f_StartupImage, - .fBlobSz = kHandoverHeader->f_StartupSz, - .fFlags = kNeFSCatalogKindExecutable, - .fName = kSysDrv, - }, - { - .fBlob = 0, - .fBlobSz = mib_cast(32), - .fFlags = kNeFSCatalogKindPage, - .fName = kSysPage, - }, - { - .fBlob = kHandoverHeader->f_TTFallbackFont, - .fBlobSz = kHandoverHeader->f_FontSz, - .fFlags = kNeFSCatalogKindResource, - .fName = kSysTTF, - }, - { - .fBlob = kHandoverHeader->f_StartupChime, - .fBlobSz = kHandoverHeader->f_ChimeSz, - .fFlags = kNeFSCatalogKindResource, - .fName = kSysChime, - } - - }; - - for (size_t i = 0; i < cFileToFormatCnt; i++) - { - NFS_CATALOG_STRUCT* catalogDisk = - this->fNeFS->GetParser()->GetCatalog(cFiles[i].fName); - - const Kernel::Char* cSrcName = cFiles[i].fName; - - if (catalogDisk) - { - CG::CGDrawStringToWnd(cKernelWnd, "File already exists: ", 10 + (10 * (cDirCount + i + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i+ 1)), 10 + (FONT_SIZE_X * rt_string_len("File already exists: ")), RGB(0, 0, 0)); - - delete catalogDisk; - } - else - { - CG::CGDrawStringToWnd(cKernelWnd, "File created: ", 10 + (10 * (cDirCount + i+ 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i + 1)), 10 + (FONT_SIZE_X * rt_string_len("File created: ")), RGB(0, 0, 0)); - - catalogDisk = - (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(cFiles[i].fName); - - NFS_FORK_STRUCT theDiskFork{0}; - - Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); - - Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); - - theDiskFork.DataSize = cFiles[i].fBlobSz; - theDiskFork.ResourceId = cFiles[i].fFlags; - theDiskFork.ResourceKind = Kernel::kNeFSDataForkKind; - theDiskFork.Kind = Kernel::kNeFSDataForkKind; - - fNeFS->GetParser()->CreateFork(catalogDisk, theDiskFork); - - if (theDiskFork.ResourceId != kNeFSCatalogKindPage) - { - fNeFS->GetParser()->WriteCatalog(catalogDisk, false, cFiles[i].fBlob, cFiles[i].fBlobSz, theDiskFork.ForkName); - } - - delete catalogDisk; - } - } } ~FilesystemInstaller() = default; diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx index e39c9c33..5d0f7fc3 100644 --- a/dev/ZKA/Sources/DriveMgr.cxx +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -6,17 +6,20 @@ #include #include +#include + + #include #include -#include +#include /// @file DriveMgr.cxx /// @brief Kernel drive manager. namespace Kernel { - static UInt16 kATAIO = 0U; - static UInt8 kATAMaster = 0U; + STATIC UInt16 kATAIO = 0U; + STATIC UInt8 kATAMaster = 0U; /// @brief reads from an ATA drive. /// @param pckt @@ -106,6 +109,7 @@ namespace Kernel /// @return Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) { + ZKA_UNUSED(pckt); } /// @brief Makes a new drive. diff --git a/dev/ZKA/Sources/FS/FAT32.cxx b/dev/ZKA/Sources/FS/FAT32.cxx index 1f5e194b..9e22e2a8 100644 --- a/dev/ZKA/Sources/FS/FAT32.cxx +++ b/dev/ZKA/Sources/FS/FAT32.cxx @@ -4,9 +4,9 @@ ------------------------------------------- */ -#ifdef __FSKIT_INCLUDES_FAT32__ +#ifdef __FSKIT_INCLUDES_HPFS__ #include #include -#endif // ifdef __FSKIT_INCLUDES_FAT32__ +#endif // ifdef __FSKIT_INCLUDES_HPFS__ diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx index 5bae8d4a..68078ec3 100644 --- a/dev/ZKA/Sources/FS/NeFS.cxx +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ #include #include @@ -143,9 +143,9 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal 4; /// this value gives us space for the data offset. theFork.Flags = kNeFSFlagCreated; - theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; + theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) - theFork.DataSize; theFork.PreviousSibling = lbaOfPreviousFork; - theFork.NextSibling = theFork.DataOffset - theFork.DataSize; + theFork.NextSibling = theFork.DataOffset + sizeof(NFS_FORK_STRUCT) + theFork.DataSize; drv.fPacket.fLba = lba; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); @@ -635,9 +635,13 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb /// @return if the catalog w rote the contents successfully. bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) { - if (sizeOfData > kNeFSForkDataSz) + if (sizeOfData > kNeFSForkDataSz || + sizeOfData == 0) return No; + auto buf = new UInt8[kNeFSForkDataSz]; + rt_copy_memory(data, buf, sizeOfData); + auto drive = sMountpointInterface.A(); rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, @@ -671,31 +675,31 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i if (forkDataIn->Flags != kNeFSFlagUnallocated && forkDataIn->Flags != kNeFSFlagDeleted && StringBuilder::Equals(forkDataIn->ForkName, forkName) && - StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) + StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name) && + forkDataIn->DataSize == sizeOfData) { // ===================================================== // // Store the blob now. // ===================================================== // forkDataIn->Flags = kNeFSFlagCreated; - forkDataIn->DataOffset = startFork - sizeof(NFS_FORK_STRUCT); - forkDataIn->DataSize = sizeOfData; - drive.fPacket.fPacketContent = data; - drive.fPacket.fPacketSize = sizeOfData; + drive.fPacket.fPacketContent = buf; + drive.fPacket.fPacketSize = kNeFSForkDataSz; drive.fPacket.fLba = forkDataIn->DataOffset; kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; drive.fOutput(&drive.fPacket); - drive.fPacket.fPacketContent = &forkDataIn; + drive.fPacket.fPacketContent = forkDataIn; drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; + drive.fPacket.fLba = startFork - sizeof(NFS_FORK_STRUCT); drive.fOutput(&drive.fPacket); kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + kcout << "wrote fork at offset: " << hex_number(startFork - sizeof(NFS_FORK_STRUCT)) << endl; delete catalog; @@ -1042,4 +1046,4 @@ namespace Kernel::Detail } } // namespace Kernel::Detail -#endif // ifdef __FSKIT_USE_NEWFS__ +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index cbd2a4f4..3e3977ab 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -50,7 +50,7 @@ namespace Kernel return false; } -#ifdef __FSKIT_USE_NEWFS__ +#ifdef __FSKIT_USE_NEFS__ /// @brief Opens a new file. /// @param path /// @param r @@ -186,5 +186,5 @@ namespace Kernel { return fImpl; } -#endif // __FSKIT_USE_NEWFS__ +#endif // __FSKIT_USE_NEFS__ } // namespace Kernel diff --git a/dev/ZKA/Sources/NeFS+FileMgr.cxx b/dev/ZKA/Sources/NeFS+FileMgr.cxx new file mode 100644 index 00000000..b3ad381f --- /dev/null +++ b/dev/ZKA/Sources/NeFS+FileMgr.cxx @@ -0,0 +1,109 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +#ifdef __FSKIT_USE_NEFS__ + +/// @brief NeFS File manager. +/// BUGS: 0 + +namespace Kernel +{ + /// @brief C++ constructor + NewFilesystemMgr::NewFilesystemMgr() + { + MUST_PASS(Detail::fs_init_newfs()); + fImpl = new NeFSParser(); + MUST_PASS(fImpl); + + kcout << "We are done here... (NewFilesystemMgr).\r"; + } + + NewFilesystemMgr::~NewFilesystemMgr() + { + kcout << "Destroying it...\r"; + + if (fImpl) + { + delete fImpl; + } + } + + /// @brief Removes a node from the filesystem. + /// @param fileName The filename + /// @return If it was deleted or not. + bool NewFilesystemMgr::Remove(const Char* fileName) + { + if (fileName == nullptr || *fileName == 0) + return false; + + return fImpl->RemoveCatalog(fileName); + } + + /// @brief Creates a node with the specified. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::Create(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path)); + } + + /// @brief Creates a node with is a directory. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + } + + /// @brief Creates a node with is a alias. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateAlias(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + } + + /// @brief Creates a node with is a page file. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + } + + /// @brief Gets the root directory. + /// @return + const Char* NewFilesystemHelper::Root() + { + return kNeFSRoot; + } + + /// @brief Gets the up-dir directory. + /// @return + const Char* NewFilesystemHelper::UpDir() + { + return kNeFSUpDir; + } + + /// @brief Gets the separator character. + /// @return + const Char NewFilesystemHelper::Separator() + { + return kNeFSSeparator; + } + + /// @brief Gets the metafile character. + /// @return + const Char NewFilesystemHelper::MetaFile() + { + return kNeFSMetaFilePrefix; + } +} // namespace Kernel + +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/NeFS+IO.cxx b/dev/ZKA/Sources/NeFS+IO.cxx new file mode 100644 index 00000000..a86e9c29 --- /dev/null +++ b/dev/ZKA/Sources/NeFS+IO.cxx @@ -0,0 +1,101 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +/************************************************************* + * + * File: NeFS+IO.cxx + * Purpose: Filesystem to mountpoint interface. + * Date: 3/26/24 + * + * Copyright ZKA Technologies., all rights reserved. + * + *************************************************************/ + +#ifdef __FSKIT_USE_NEFS__ + +#include + +/// Useful macros. + +#define NEFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) +#define NEFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) + +using namespace Kernel; + +/// @brief Read from newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) +{ + if (!Mnt) + return -1; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) + { + case kNeFSSubDriveA: { + NEFS_READ(A, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveB: { + NEFS_READ(B, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveC: { + NEFS_READ(C, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveD: { + NEFS_READ(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood; +} + +/// @brief Write to newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) +{ + if (!Mnt) + return -1; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) + { + case kNeFSSubDriveA: { + NEFS_WRITE(A, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveB: { + NEFS_WRITE(B, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveC: { + NEFS_WRITE(C, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveD: { + NEFS_WRITE(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood; +} + +#endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx deleted file mode 100644 index 29beda45..00000000 --- a/dev/ZKA/Sources/NewFS+FileMgr.cxx +++ /dev/null @@ -1,109 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __FSKIT_USE_NEWFS__ - -/// @brief NeFS File manager. -/// BUGS: 0 - -namespace Kernel -{ - /// @brief C++ constructor - NewFilesystemMgr::NewFilesystemMgr() - { - MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NeFSParser(); - MUST_PASS(fImpl); - - kcout << "We are done here... (NewFilesystemMgr).\r"; - } - - NewFilesystemMgr::~NewFilesystemMgr() - { - kcout << "Destroying it...\r"; - - if (fImpl) - { - delete fImpl; - } - } - - /// @brief Removes a node from the filesystem. - /// @param fileName The filename - /// @return If it was deleted or not. - bool NewFilesystemMgr::Remove(const Char* fileName) - { - if (fileName == nullptr || *fileName == 0) - return false; - - return fImpl->RemoveCatalog(fileName); - } - - /// @brief Creates a node with the specified. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemMgr::Create(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path)); - } - - /// @brief Creates a node with is a directory. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); - } - - /// @brief Creates a node with is a alias. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateAlias(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); - } - - /// @brief Creates a node with is a page file. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); - } - - /// @brief Gets the root directory. - /// @return - const Char* NewFilesystemHelper::Root() - { - return kNeFSRoot; - } - - /// @brief Gets the up-dir directory. - /// @return - const Char* NewFilesystemHelper::UpDir() - { - return kNeFSUpDir; - } - - /// @brief Gets the separator character. - /// @return - const Char NewFilesystemHelper::Separator() - { - return kNeFSSeparator; - } - - /// @brief Gets the metafile character. - /// @return - const Char NewFilesystemHelper::MetaFile() - { - return kNeFSMetaFilePrefix; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NewFS+IO.cxx deleted file mode 100644 index 7917c1bb..00000000 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ /dev/null @@ -1,101 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -/************************************************************* - * - * File: NeFS+IO.cxx - * Purpose: Filesystem to mountpoint interface. - * Date: 3/26/24 - * - * Copyright ZKA Technologies., all rights reserved. - * - *************************************************************/ - -#ifdef __FSKIT_USE_NEWFS__ - -#include - -/// Useful macros. - -#define NEWFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) -#define NEWFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) - -using namespace Kernel; - -/// @brief Read from newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) -{ - if (!Mnt) - return -1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) - { - case kNeFSSubDriveA: { - NEWFS_READ(A, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveB: { - NEWFS_READ(B, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveC: { - NEWFS_READ(C, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveD: { - NEWFS_READ(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} - -/// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) -{ - if (!Mnt) - return -1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) - { - case kNeFSSubDriveA: { - NEWFS_WRITE(A, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveB: { - NEWFS_WRITE(B, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveC: { - NEWFS_WRITE(C, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveD: { - NEWFS_WRITE(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx deleted file mode 100644 index f8d82fcd..00000000 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ /dev/null @@ -1,22 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __FSKIT_USE_NEWFS__ - -///! BUGS: 0 -///! @file NeFS+Journal.cxx -///! @brief Journaling for NeFS. - -namespace Kernel::Journal -{ -} // namespace Kernel::Journal - -using namespace Kernel; - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 4e0c8902..8c46b1cf 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -2,6 +2,9 @@ Copyright ZKA Technologies. + FILE: UserProcessScheduler.cxx + PURPOSE: User sided process scheduler. + ------------------------------------------- */ /***********************************************************************************/ @@ -34,7 +37,7 @@ namespace Kernel /// @brief User Process scheduler global object. /***********************************************************************************/ - STATIC UserProcessScheduler* cProcessScheduler = nullptr; + UserProcessScheduler* cProcessScheduler = nullptr; /// @brief Gets the last exit code. /// @note Not thread-safe. @@ -264,6 +267,7 @@ namespace Kernel { if (process.Kind != UserProcess::kDLLKind) { + process.Crash(); return -kErrorProcessFault; } } @@ -273,6 +277,9 @@ namespace Kernel ++mTeam.mProcessAmount; + while (1) + ; + mTeam.AsArray()[process.ProcessId] = process; return process.ProcessId; @@ -297,7 +304,7 @@ namespace Kernel // check if process is within range. if (process_id > mTeam.AsArray().Count()) return false; - + mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead; --mTeam.mProcessAmount; @@ -373,10 +380,12 @@ namespace Kernel Void UserProcessHelper::Init() { - if (!cProcessScheduler) - { - cProcessScheduler = new UserProcessScheduler(); - } + if (mm_is_valid_heap(cProcessScheduler)) + delete cProcessScheduler; + + cProcessScheduler = nullptr; + cProcessScheduler = new UserProcessScheduler(); + MUST_PASS(cProcessScheduler); } /// @brief Check if process can be schedulded. @@ -435,7 +444,7 @@ namespace Kernel HardwareThreadScheduler::The()[index].Leak()->Kind() != ThreadKind::kHartSystemReserved) { - PID prev_pid = UserProcessHelper::TheCurrentPID(); + PID prev_pid = UserProcessHelper::TheCurrentPID(); UserProcessHelper::TheCurrentPID() = new_pid; bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); diff --git a/dev/ZKA/Sources/compile_flags.txt b/dev/ZKA/Sources/compile_flags.txt index 33aadad4..a22ed881 100644 --- a/dev/ZKA/Sources/compile_flags.txt +++ b/dev/ZKA/Sources/compile_flags.txt @@ -3,5 +3,5 @@ -std=c++20 -I../ -I$(HOME)/ --D__FSKIT_USE_NEWFS__ +-D__FSKIT_USE_NEFS__ -D__ZKA_AMD64__ diff --git a/dev/ZKA/amd64-efi.make b/dev/ZKA/amd64-efi.make index 4d1f9403..00c2664e 100644 --- a/dev/ZKA/amd64-efi.make +++ b/dev/ZKA/amd64-efi.make @@ -6,7 +6,7 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld CCFLAGS = -fshort-wchar -c -D__ZKA_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ - -std=c++20 -D__ZKA_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEWFS__ \ + -std=c++20 -D__ZKA_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEFS__ \ -D__NEWOSKRNL__ -D__HAVE_ZKA_APIS__ -D__FREESTANDING__ -D__ZKA__ -I./ -I../ -I../ZBA ASM = nasm diff --git a/dev/ZKA/arm64-efi.make b/dev/ZKA/arm64-efi.make index 65f3a0ae..a801ed3e 100644 --- a/dev/ZKA/arm64-efi.make +++ b/dev/ZKA/arm64-efi.make @@ -7,7 +7,7 @@ CC = clang++ LD = lld-link CCFLAGS = -fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__ZKA_ARM64__ -fno-rtti -fno-exceptions -I./ \ -target aarch64-unknown-windows \ - -std=c++20 -D__FSKIT_USE_NEWFS__ -D__ZETA_MACHINE__ -D__NEWOSKRNL__ -D__HAVE_ZKA_APIS__ -D__ZKA__ -I../ + -std=c++20 -D__FSKIT_USE_NEFS__ -D__ZETA_MACHINE__ -D__NEWOSKRNL__ -D__HAVE_ZKA_APIS__ -D__ZKA__ -I../ ASM = clang++ diff --git a/doc/NeFS.pdf b/doc/NeFS.pdf new file mode 100644 index 00000000..a2193504 Binary files /dev/null and b/doc/NeFS.pdf differ diff --git a/doc/NewFS.pdf b/doc/NewFS.pdf deleted file mode 100644 index a2193504..00000000 Binary files a/doc/NewFS.pdf and /dev/null differ -- cgit v1.2.3