diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-10 10:33:39 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-10 10:34:53 +0200 |
| commit | 5aef44da0ce752e7ac6bd9c95489942b1a0319ae (patch) | |
| tree | f3c6f613048ab091def7afc726f0227f552df519 /dev/ZKA | |
| parent | b11bf31c59d447e62e6ba9b3d8455f9b2828703f (diff) | |
Fix: See below.
- Fixing PML4 mapping and getting it to work.
- Don't update cr4, instead do lidt to triple fault.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA')
| -rw-r--r-- | dev/ZKA/FSKit/NeFS.hxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/FirmwareKit/Handover.hxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx | 25 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 7 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 16 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalProcessor.cxx | 12 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/Processor.hxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/ARM64/Processor.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/FileMgr.hxx | 8 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/PEFCodeMgr.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/NewKit/PageAllocator.hxx | 19 | ||||
| -rw-r--r-- | dev/ZKA/NewKit/PageMgr.hxx | 1 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ExeMain.cxx | 26 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FS/NeFS.cxx | 58 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FileMgr.cxx | 18 | ||||
| -rw-r--r-- | dev/ZKA/Sources/KernelCheck.cxx | 46 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NeFS+FileMgr.cxx | 24 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PageAllocator.cxx | 42 |
20 files changed, 160 insertions, 174 deletions
diff --git a/dev/ZKA/FSKit/NeFS.hxx b/dev/ZKA/FSKit/NeFS.hxx index 7bec2a4b..1818eab2 100644 --- a/dev/ZKA/FSKit/NeFS.hxx +++ b/dev/ZKA/FSKit/NeFS.hxx @@ -31,7 +31,7 @@ default. #define kNeFSNodeNameLen (256) #define kNeFSSectorSz (512) -#define kNeFSForkDataSz (kib_cast(8)) +#define kNeFSForkDataSz (mib_cast(16)) #define kNeFSIdentLen (8) #define kNeFSIdent " NeFS" @@ -292,11 +292,11 @@ namespace Kernel }; /// - /// \name NewFilesystemHelper + /// \name NeFileSystemHelper /// \brief Filesystem helper and utils. /// - class NewFilesystemHelper final + class NeFileSystemHelper final { public: STATIC const Char* Root(); diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 8d25ec6d..457c0982 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -22,7 +22,7 @@ /* useful macros */ #define kHandoverMagic 0xBADCC -#define kHandoverVersion 0x114 +#define kHandoverVersion 0x0115 #define kHandoverBitMapSz gib_cast(3) #define kHandoverStructSz sizeof(HEL::HandoverInformationHeader) @@ -58,7 +58,8 @@ namespace Kernel::HEL VoidPtr f_BitMapStart; SizeT f_BitMapSize; - VoidPtr f_PhysicalStart; + + VoidPtr f_PageStart; VoidPtr f_KernelImage; SizeT f_KernelSz; diff --git a/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx b/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx index 37b1375f..1cb8ce07 100644 --- a/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -102,11 +102,26 @@ namespace Kernel Void ACPIFactoryInterface::Reboot() { failed_to_reboot: - // in case no acpi mode, or it's not available. - while (Yes) - { - asm volatile("cli; hlt"); - } + asm volatile(".intel_syntax noprefix; " + "rt_reset_hardware:; " + "cli; " + "wait_gate1: ; " + "in al,0x64 ; " + "and al,2 ; " + "jnz wait_gate1 ; " + "mov al,0x0D1 ; " + "out 0x64,al ; " + "wait_gate2: ; " + "in al,0x64 ; " + "and al,2 ; " + "jnz wait_gate2 ; " + "mov al,0x0FE ; " + "out 0x60,al ; " + "xor rax,rax ; " + "lidt [rax] ; " + "reset_wait: ; " + "jmp reset_wait ; " + ".att_syntax; "); } /// @brief Finds a descriptor table inside ACPI XSDT. diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 3d9cc90f..7cb891b6 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -54,10 +54,13 @@ namespace Kernel kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl; if (rw) - mm_map_page(base_ptr, eFlagsRw | eFlagsPresent); + mm_map_page(base_ptr, eFlagsRw); + + if (user && rw) + mm_map_page(base_ptr, eFlagsUser | eFlagsRw); if (user) - mm_map_page(base_ptr, eFlagsUser | eFlagsPresent); + mm_map_page(base_ptr, eFlagsUser); return (VoidPtr)ptr_bit_set; } diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 7f77824e..bc2a94ce 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -64,11 +64,10 @@ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept; EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void); +/// @brief Kernel init procedure. EXTERN_C void hal_init_platform( Kernel::HEL::HandoverInformationHeader* HandoverHeader) { - /* Setup globals. */ - kHandoverHeader = HandoverHeader; if (kHandoverHeader->f_Magic != kHandoverMagic && @@ -78,15 +77,15 @@ EXTERN_C void hal_init_platform( } // get page size. - kKernelVirtualSize = kHandoverHeader->f_BitMapSize; + kKernelBitMpSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart)); // get physical address start. - kKernelPhysicalStart = reinterpret_cast<Kernel::VoidPtr>( - reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_PhysicalStart)); + kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>( + reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_PageStart)); STATIC CONST auto cEntriesCount = 6; @@ -126,14 +125,11 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept kcout << "Creating filesystem and such.\r"; - auto fs = Kernel::mm_new_class<Kernel::NewFilesystemMgr>(); + auto fs = Kernel::mm_new_class<Kernel::NeFileSystemMgr>(); MUST_PASS(fs); - Kernel::HAL::mm_map_page((Kernel::VoidPtr)mp_user_switch_proc, Kernel::HAL::eFlagsUser | Kernel::HAL::eFlagsRw | Kernel::HAL::eFlagsPresent); - Kernel::HAL::mm_map_page((Kernel::VoidPtr)mp_user_switch_proc_stack_end, Kernel::HAL::eFlagsUser | Kernel::HAL::eFlagsRw | Kernel::HAL::eFlagsPresent); - - Kernel::NewFilesystemMgr::Mount(fs); + Kernel::NeFileSystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index c5bede49..ecf739a3 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -53,7 +53,7 @@ namespace Kernel::HAL UInt8 PageSize : 1; UInt8 Global : 1; UInt8 Available : 3; - UInt64 PhysicalAddress : 39; + UInt32 PhysicalAddress : 20; UInt8 Reserved : 6; UInt8 ProtectionKey : 1; UInt8 ExecDisable : 1; diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index e2ef1902..0d20d0b7 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -116,14 +116,14 @@ namespace Kernel::HAL volatile UIntPtr* pt_entry = (volatile UIntPtr*)(pd_entry[pt_index + cIndexAlign]); - if (!(*pt_entry & eFlagsPresent)) + if (!(pt_entry[offset] & eFlagsPresent)) { - PTE* frame = (PTE*)pt_entry; + PTE* frame = (PTE*)pt_entry[offset]; MM::pg_delete((VoidPtr)frame->PhysicalAddress); auto pt_addr = MM::pg_allocate(); - *pt_entry = (UIntPtr)pt_addr | eFlagsPresent | flags; + pt_entry[offset] = (UIntPtr)pt_addr | eFlagsPresent | flags; kcout << (frame->Present ? "Page Present." : "Page Not Present.") << endl; kcout << (frame->Rw ? "Page RW." : "Page Not RW.") << endl; @@ -133,9 +133,9 @@ namespace Kernel::HAL } else { - PTE* frame = (PTE*)pt_entry; + PTE* frame = (PTE*)pt_entry[offset]; - *pt_entry = (UIntPtr)(frame->PhysicalAddress / cPageSz) | flags; + pt_entry[offset] = (UIntPtr)(frame->PhysicalAddress / cPageSz) | flags; kcout << (frame->Present ? "Page Present." : "Page Not Present.") << endl; kcout << (frame->Rw ? "Page RW." : "Page Not RW.") << endl; @@ -144,8 +144,6 @@ namespace Kernel::HAL kcout << "Physical Address: " << number(frame->PhysicalAddress) << endl; } - hal_invl_tlb(p_virt_addr); - rt_sti(); return 0; } diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index 8463550c..7da1adea 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -27,6 +27,11 @@ EXTERN_C #define IsActiveLow(FLG) (FLG & 2) #define IsLevelTriggered(FLG) (FLG & 8) +#define cPageSz kPageSize // 4KB pages +#define cTotalPgMem mib_cast(16) // 16MB total memory +#define cTotalPages (cTotalPgMem / cPageSz) // Total number of pages +#define cBmpPgSz (cTotalPages / 8) // 1 bit per page in the bitmap + #define kInterruptGate (0x8E) #define kTrapGate (0xEF) #define kTaskGate (0b10001100) @@ -294,6 +299,6 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); #define kKernelInterruptId 0x32 inline Kernel::VoidPtr kKernelVirtualStart = nullptr; -inline Kernel::UIntPtr kKernelVirtualSize = 0UL; +inline Kernel::UIntPtr kKernelBitMpSize = 0UL; -inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; +inline Kernel::VoidPtr kKernelBitMpStart = nullptr; diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index d6bed3ba..c617c45d 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -77,7 +77,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kAllocationInProgress = false; // get page size. - kKernelVirtualSize = kHandoverHeader->f_BitMapSize; + kKernelBitMpSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( @@ -94,12 +94,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kcout << "Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemMgr(); + auto fs = new Kernel::NeFileSystemMgr(); MUST_PASS(fs); MUST_PASS(fs->GetParser()); - Kernel::NewFilesystemMgr::Mount(fs); + Kernel::NeFileSystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx index ab864577..dfba0293 100644 --- a/dev/ZKA/HALKit/ARM64/Processor.hxx +++ b/dev/ZKA/HALKit/ARM64/Processor.hxx @@ -43,7 +43,7 @@ namespace Kernel::HAL } // namespace Kernel::HAL inline Kernel::VoidPtr kKernelVirtualStart = nullptr; -inline Kernel::UIntPtr kKernelVirtualSize = 0UL; +inline Kernel::UIntPtr kKernelBitMpSize = 0UL; inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index 5b2b8fa8..b569ce36 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -140,14 +140,14 @@ namespace Kernel * @brief Based of IFilesystemMgr, takes care of managing NeFS * disks. */ - class NewFilesystemMgr final : public IFilesystemMgr + class NeFileSystemMgr final : public IFilesystemMgr { public: - explicit NewFilesystemMgr(); - ~NewFilesystemMgr() override; + explicit NeFileSystemMgr(); + ~NeFileSystemMgr() override; public: - ZKA_COPY_DEFAULT(NewFilesystemMgr); + ZKA_COPY_DEFAULT(NeFileSystemMgr); public: NodePtr Create(const Char* path) override; diff --git a/dev/ZKA/KernelKit/PEFCodeMgr.hxx b/dev/ZKA/KernelKit/PEFCodeMgr.hxx index c2938fae..c6748ba0 100644 --- a/dev/ZKA/KernelKit/PEFCodeMgr.hxx +++ b/dev/ZKA/KernelKit/PEFCodeMgr.hxx @@ -47,7 +47,7 @@ namespace Kernel private: #ifdef __FSKIT_USE_NEFS__ - OwnPtr<FileStream<Char, NewFilesystemMgr>> fFile; + OwnPtr<FileStream<Char, NeFileSystemMgr>> fFile; #else OwnPtr<FileStream<Char>> fFile; #endif // __FSKIT_USE_NEFS__ diff --git a/dev/ZKA/NewKit/PageAllocator.hxx b/dev/ZKA/NewKit/PageAllocator.hxx deleted file mode 100644 index 5b19c0c2..00000000 --- a/dev/ZKA/NewKit/PageAllocator.hxx +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hxx> -#include <NewKit/PageMgr.hxx> - -namespace Kernel -{ - namespace Detail - { - void exec_disable(UIntPtr addr); - bool page_disable(UIntPtr addr); - } // namespace Detail -} // namespace Kernel diff --git a/dev/ZKA/NewKit/PageMgr.hxx b/dev/ZKA/NewKit/PageMgr.hxx index 1f6b5021..1f470382 100644 --- a/dev/ZKA/NewKit/PageMgr.hxx +++ b/dev/ZKA/NewKit/PageMgr.hxx @@ -10,7 +10,6 @@ #pragma once #include <NewKit/Defines.hxx> -#include <NewKit/PageAllocator.hxx> #include <NewKit/Ref.hxx> namespace Kernel diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx index 93bbb3e5..44dedfd7 100644 --- a/dev/ZKA/Sources/ExeMain.cxx +++ b/dev/ZKA/Sources/ExeMain.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* fNeFS{nullptr}; + Kernel::NeFileSystemMgr* fNeFS{nullptr}; public: /// @brief wizard constructor. @@ -53,12 +53,12 @@ namespace Kernel::Detail if (Kernel::IFilesystemMgr::GetMounted()) { CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::IFilesystemMgr::GetMounted()); + fNeFS = reinterpret_cast<Kernel::NeFileSystemMgr*>(Kernel::IFilesystemMgr::GetMounted()); } else { // Mounts a NeFS from main drive. - fNeFS = new Kernel::NewFilesystemMgr(); + fNeFS = new Kernel::NeFileSystemMgr(); Kernel::IFilesystemMgr::Mount(fNeFS); @@ -92,6 +92,22 @@ namespace Kernel::Detail 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)); + NFS_FORK_STRUCT theFork{ 0 }; + + rt_copy_memory(catalogDir->Name, theFork.CatalogName, rt_string_len(catalogDir->Name)); + rt_copy_memory(catalogDir->Name, theFork.ForkName, rt_string_len(catalogDir->Name)); + + theFork.DataSize = kNeFSForkDataSz; + theFork.Kind = kNeFSDataForkKind; + theFork.ResourceId = 0; + + fNeFS->GetParser()->CreateFork(catalogDir, theFork); + + auto data_len = 4096; + Char data[4096] = R"({ "FolderKind": "System", "Owner": "ZKA USER\\SUPER", "Important": true })"; + + fNeFS->GetParser()->WriteCatalog(catalogDir, false, data, data_len, theFork.ForkName); + delete catalogDir; } } @@ -102,8 +118,8 @@ namespace Kernel::Detail ZKA_COPY_DEFAULT(FilesystemInstaller); /// @brief Grab the disk's NeFS reference. - /// @return NewFilesystemMgr the filesystem interface - Kernel::NewFilesystemMgr* Leak() + /// @return NeFileSystemMgr the filesystem interface + Kernel::NeFileSystemMgr* Leak() { return fNeFS; } diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx index 1a9b89f7..ad4dd031 100644 --- a/dev/ZKA/Sources/FS/NeFS.cxx +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -56,16 +56,16 @@ STATIC MountpointInterface sMountpointInterface; /***********************************************************************************/ /// @brief Creates a new fork inside the New filesystem partition. /// @param catalog it's catalog -/// @param theFork the fork itself. +/// @param the_fork the fork itself. /// @return the fork /***********************************************************************************/ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork) + _Input NFS_FORK_STRUCT& the_fork) { - if (catalog && theFork.ForkName[0] != 0 && - theFork.DataSize <= kNeFSForkDataSz) + if (catalog && the_fork.ForkName[0] != 0 && + the_fork.DataSize <= kNeFSForkDataSz) { - Lba lba = (theFork.Kind == kNeFSDataForkKind) ? catalog->DataFork + Lba lba = (the_fork.Kind == kNeFSDataForkKind) ? catalog->DataFork : catalog->ResourceFork; kcout << "fork lba: " << hex_number(lba) << endl; @@ -103,12 +103,12 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - if (curFork.Flags == kNeFSFlagCreated) + if (curFork.Flags & kNeFSFlagCreated) { kcout << "fork already exists.\r"; /// sanity check. - if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && + if (StringBuilder::Equals(curFork.ForkName, the_fork.ForkName) && StringBuilder::Equals(curFork.CatalogName, catalog->Name)) return nullptr; @@ -142,24 +142,24 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal constexpr auto cForkPadding = 4; /// this value gives us space for the data offset. - theFork.Flags = kNeFSFlagCreated; - theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) - theFork.DataSize; - theFork.PreviousSibling = lbaOfPreviousFork; - theFork.NextSibling = theFork.DataOffset + sizeof(NFS_FORK_STRUCT) + theFork.DataSize; + the_fork.Flags |= kNeFSFlagCreated; + the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT); + the_fork.PreviousSibling = lbaOfPreviousFork; + the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT); drv.fPacket.fLba = lba; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &theFork; + drv.fPacket.fPacketContent = &the_fork; drv.fOutput(&drv.fPacket); /// log what we have now. - kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) + kcout << "Wrote fork data at: " << hex_number(the_fork.DataOffset) << endl; kcout << "Wrote fork at: " << hex_number(lba) << endl; - return &theFork; + return &the_fork; } return nullptr; @@ -176,7 +176,7 @@ _Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog Boolean isDataFork) { auto drv = sMountpointInterface.A(); - NFS_FORK_STRUCT* theFork = nullptr; + NFS_FORK_STRUCT* the_fork = nullptr; Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; @@ -184,7 +184,7 @@ _Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog { drv.fPacket.fLba = lba; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = (VoidPtr)theFork; + drv.fPacket.fPacketContent = (VoidPtr)the_fork; rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16); @@ -209,15 +209,15 @@ _Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog return nullptr; } - if (StringBuilder::Equals(theFork->ForkName, name)) + if (StringBuilder::Equals(the_fork->ForkName, name)) { break; } - lba = theFork->NextSibling; + lba = the_fork->NextSibling; } - return theFork; + return the_fork; } /***********************************************************************************/ @@ -250,12 +250,12 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, /// a directory should have a slash in the end. if (kind == kNeFSCatalogKindDir && - name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) + name[rt_string_len(name) - 1] != NeFileSystemHelper::Separator()) return nullptr; /// a file shouldn't have a slash in the end. if (kind != kNeFSCatalogKindDir && - name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) + name[rt_string_len(name) - 1] == NeFileSystemHelper::Separator()) return nullptr; NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); @@ -297,7 +297,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, // mandatory / character, zero it. parentName[--indexReverseCopy] = 0; - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + while (parentName[indexReverseCopy] != NeFileSystemHelper::Separator()) { parentName[indexReverseCopy] = 0; --indexReverseCopy; @@ -684,7 +684,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i // Store the blob now. // ===================================================== // - fork_data_input->Flags = kNeFSFlagCreated; + fork_data_input->Flags |= kNeFSFlagCreated; drive.fPacket.fPacketContent = buf; drive.fPacket.fPacketSize = kNeFSForkDataSz; @@ -753,7 +753,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa drive.fInput(&drive.fPacket); - if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + if (!StringBuilder::Equals(catalogName, NeFileSystemHelper::Root())) { Char parentName[kNeFSNodeNameLen] = {0}; @@ -770,7 +770,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa // mandatory '/' character. parentName[--indexReverseCopy] = 0; - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + while (parentName[indexReverseCopy] != NeFileSystemHelper::Separator()) { parentName[indexReverseCopy] = 0; --indexReverseCopy; @@ -779,7 +779,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba); if (parentCatalog && - !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) + !StringBuilder::Equals(parentName, NeFileSystemHelper::Root())) { startCatalogList = parentCatalog->NextSibling; delete parentCatalog; @@ -871,7 +871,7 @@ Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) { if (!catalogName || - StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + StringBuilder::Equals(catalogName, NeFileSystemHelper::Root())) { ErrLocal() = kErrorInternal; return false; @@ -881,9 +881,9 @@ Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) auto catalog = this->FindCatalog(catalogName, out_lba); if (out_lba >= kNeFSCatalogStartAddress || - catalog->Flags == kNeFSFlagCreated) + catalog->Flags & kNeFSFlagCreated) { - catalog->Flags = kNeFSFlagDeleted; + catalog->Flags |= kNeFSFlagDeleted; auto drive = sMountpointInterface.A(); diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index eff3c334..88e8c433 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -55,7 +55,7 @@ namespace Kernel /// @param path /// @param r /// @return - _Output NodePtr NewFilesystemMgr::Open(_Input const Char* path, _Input const Char* r) + _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) { if (!path || *path == 0) return nullptr; @@ -73,7 +73,7 @@ namespace Kernel /// @param data the data. /// @param flags the size. /// @return - Void NewFilesystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { if (!node) return; @@ -89,7 +89,7 @@ namespace Kernel /// @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) + _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { if (!node) return nullptr; @@ -100,7 +100,7 @@ namespace Kernel return this->Read(cDataForkName, node, flags, size); } - Void NewFilesystemMgr::Write(_Input const Char* name, + Void NeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, @@ -120,7 +120,7 @@ namespace Kernel name); } - _Output VoidPtr NewFilesystemMgr::Read(_Input const Char* name, + _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, _Input SizeT sz) @@ -146,7 +146,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output Bool NewFilesystemMgr::Seek(NodePtr node, SizeT off) + _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) { if (!node || off == 0) return false; @@ -159,7 +159,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output SizeT NewFilesystemMgr::Tell(NodePtr node) + _Output SizeT NeFileSystemMgr::Tell(NodePtr node) { if (!node) return kNPos; @@ -172,7 +172,7 @@ namespace Kernel /// @retval true always returns false, this is unimplemented. /// @retval false always returns this, it is unimplemented. - _Output Bool NewFilesystemMgr::Rewind(NodePtr node) + _Output Bool NeFileSystemMgr::Rewind(NodePtr node) { if (!node) return false; @@ -182,7 +182,7 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - _Output NeFSParser* NewFilesystemMgr::GetParser() noexcept + _Output NeFSParser* NeFileSystemMgr::GetParser() noexcept { return fImpl; } diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index ff71950a..833ac6de 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -11,7 +11,7 @@ #include <NewKit/String.hxx> #include <FirmwareKit/Handover.hxx> #include <Modules/ACPI/ACPIFactoryInterface.hxx> - +#include <KernelKit/FileMgr.hxx> #include <Modules/CoreCG/Accessibility.hxx> #include <Modules/CoreCG/FbRenderer.hxx> #include <Modules/CoreCG/TextRenderer.hxx> @@ -69,50 +69,58 @@ namespace Kernel RecoveryFactory::Recover(); } case RUNTIME_CHECK_FILESYSTEM: { - CGDrawString("0x0000000A Filesystem corruption error.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x0000000A Filesystem error.", start_y, x, panicTxt); + + PowerFactoryInterface power(nullptr); + power.Shutdown(); break; } case RUNTIME_CHECK_POINTER: { - CGDrawString("0x00000000 Kernel heap pointer error, surely corrupted.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000000 Heap error, the heap is corrupted.", start_y, x, panicTxt); + + PowerFactoryInterface power(nullptr); + power.Shutdown(); break; } case RUNTIME_CHECK_BAD_BEHAVIOR: { - CGDrawString("0x00000009 Undefined behavior error, image had to stop.", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x00000009 CPU access error.", start_y, x, panicTxt); + + PowerFactoryInterface power(nullptr); + power.Shutdown(); break; } case RUNTIME_CHECK_BOOTSTRAP: { - CGDrawString("0x0000000A End of boot code...", start_y, x, panicTxt); - RecoveryFactory::Recover(); + CGDrawString("0x0000000A Boot Processor finished executing.", start_y, x, panicTxt); + + PowerFactoryInterface power(nullptr); + power.Shutdown(); break; } case RUNTIME_CHECK_HANDSHAKE: { - CGDrawString("0x00000005 Bad handshake error.", start_y, x, panicTxt); + CGDrawString("0x00000005 Handshake fault.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_IPC: { - CGDrawString("0x00000003 Bad Kernel IPC error.", start_y, x, panicTxt); + CGDrawString("0x00000003 Bad IPC/XPCOM message.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_INVALID_PRIVILEGE: { - CGDrawString("0x00000007 Kernel privilege violation.", start_y, x, panicTxt); + CGDrawString("0x00000007 Privilege access violation.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; case RUNTIME_CHECK_UNEXCPECTED: { - CGDrawString("0x0000000B Unexpected Kernel failure.", start_y, x, panicTxt); + CGDrawString("0x0000000B Kernel access violation.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: { - CGDrawString("0x10000001 Out of Virtual Memory. (Catastrophic Failure)", start_y, x, panicTxt); + CGDrawString("0x10000001 Out of virtual memory.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } case RUNTIME_CHECK_FAILED: { - CGDrawString("0x10000001 Kernel Check.", start_y, x, panicTxt); + CGDrawString("0x10000001 Kernel Bug check failed.", start_y, x, panicTxt); RecoveryFactory::Recover(); break; } @@ -130,8 +138,14 @@ namespace Kernel Void RecoveryFactory::Recover() noexcept { + if (NeFileSystemMgr::GetMounted()) + { + NeFileSystemMgr::GetMounted()->CreateSwapFile("\\Boot\\$DUMP"); + NeFileSystemMgr::GetMounted()->CreateSwapFile("\\Support\\$CHKDSK"); + } + PowerFactoryInterface power(nullptr); - power.Shutdown(); + power.Reboot(); } void ke_runtime_check(bool expr, const Char* file, const Char* line) diff --git a/dev/ZKA/Sources/NeFS+FileMgr.cxx b/dev/ZKA/Sources/NeFS+FileMgr.cxx index 609f2ece..85630018 100644 --- a/dev/ZKA/Sources/NeFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NeFS+FileMgr.cxx @@ -15,16 +15,16 @@ namespace Kernel { /// @brief C++ constructor - NewFilesystemMgr::NewFilesystemMgr() + NeFileSystemMgr::NeFileSystemMgr() { MUST_PASS(Detail::fs_init_newfs()); fImpl = mm_new_class<NeFSParser>(); MUST_PASS(fImpl); - kcout << "We are done here... (NewFilesystemMgr).\r"; + kcout << "We are done here... (NeFileSystemMgr).\r"; } - NewFilesystemMgr::~NewFilesystemMgr() + NeFileSystemMgr::~NeFileSystemMgr() { kcout << "Destroying it...\r"; @@ -37,7 +37,7 @@ namespace Kernel /// @brief Removes a node from the filesystem. /// @param fileName The filename /// @return If it was deleted or not. - bool NewFilesystemMgr::Remove(const Char* fileName) + bool NeFileSystemMgr::Remove(const Char* fileName) { if (fileName == nullptr || *fileName == 0) return false; @@ -48,7 +48,7 @@ namespace Kernel /// @brief Creates a node with the specified. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemMgr::Create(const Char* path) + NodePtr NeFileSystemMgr::Create(const Char* path) { return node_cast(fImpl->CreateCatalog(path)); } @@ -56,7 +56,7 @@ namespace Kernel /// @brief Creates a node with is a directory. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) + NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } @@ -64,7 +64,7 @@ namespace Kernel /// @brief Creates a node with is a alias. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateAlias(const Char* path) + NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } @@ -72,35 +72,35 @@ namespace Kernel /// @brief Creates a node with is a page file. /// @param path The filename path. /// @return The Node pointer. - NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) + NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return - const Char* NewFilesystemHelper::Root() + const Char* NeFileSystemHelper::Root() { return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return - const Char* NewFilesystemHelper::UpDir() + const Char* NeFileSystemHelper::UpDir() { return kNeFSUpDir; } /// @brief Gets the separator character. /// @return - const Char NewFilesystemHelper::Separator() + const Char NeFileSystemHelper::Separator() { return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return - const Char NewFilesystemHelper::MetaFile() + const Char NeFileSystemHelper::MetaFile() { return kNeFSMetaFilePrefix; } diff --git a/dev/ZKA/Sources/PageAllocator.cxx b/dev/ZKA/Sources/PageAllocator.cxx deleted file mode 100644 index e68d0659..00000000 --- a/dev/ZKA/Sources/PageAllocator.cxx +++ /dev/null @@ -1,42 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <ArchKit/ArchKit.hxx> -#include <KernelKit/DebugOutput.hxx> -#include <NewKit/PageAllocator.hxx> - -/// @brief Internal namespace, used internally by Kernel. -namespace Kernel::Detail -{ - void exec_disable(UIntPtr VirtualAddr) - { -#ifdef __ZKA_SUPPORT_NX__ - PTE* VirtualAddrTable = reinterpret_cast<PTE*>(VirtualAddr); - - MUST_PASS(!VirtualAddrTable->ExecDisable == false); - VirtualAddrTable->ExecDisable = true; - - hal_flush_tlb(); -#endif // ifdef __ZKA_SUPPORT_NX__ - } - - bool page_disable(UIntPtr VirtualAddr) - { - if (VirtualAddr) - { - auto VirtualAddrTable = (PTE*)(VirtualAddr); - - MUST_PASS(!VirtualAddrTable->Present == true); - VirtualAddrTable->Present = false; - - hal_flush_tlb(); - - return true; - } - - return false; - } -} // namespace Kernel::Detail |
