diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-24 08:51:21 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-24 08:54:22 +0200 |
| commit | 4185fcc698e237225902646736c6b23f6b5e54be (patch) | |
| tree | 7b0fc0bb58cb20c61e676b13e3e0f7fd52c73a56 /dev | |
| parent | b31d81cd939ed3e8bb5fade029b32876e71ed54c (diff) | |
[IMP+REFACTORS] See below.
+ Add SysChk driver instead of BootScr.
+ Working on AHCI driver, did progress on detection, need to find out
why the signature are set to zero.
+ Refactor PE loader structures.
Add BecomeBusMaster call when probing AHCI disk.
+ Alongside some other modifications.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
18 files changed, 312 insertions, 79 deletions
diff --git a/dev/SIGG/Drv.hxx b/dev/SIGG/Drv.hxx new file mode 100644 index 00000000..e7d9f60b --- /dev/null +++ b/dev/SIGG/Drv.hxx @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hxx> +#include <KernelKit/PEF.hxx> +#include <KernelKit/PE.hxx> +#include <KernelKit/MSDOS.hxx> + +#define kDriverSignedExt ".sigg" +#define kDriverExt ".sys" +#define kSignedDriverMagic "SIGG" + +/// @brief SIGG format, takes care of signed drivers. + +namespace Kernel +{ + namespace Detail + { + /// @brief Instablle Secure Driver record. + struct SIGNED_DRIVER_HEADER final + { + // doesn't change. + char d_binary_magic[5]; + int d_binary_version; + // can change. + char d_binary_name[4096]; + UInt64 d_binary_checksum; + UInt64 d_binary_size; + char d_binary_padding[512]; + }; + } // namespace Detail +} // namespace Kernel diff --git a/dev/ZBA/Modules/BootScr/.hgkeep b/dev/ZBA/Modules/SysChk/.hgkeep index e69de29b..e69de29b 100644 --- a/dev/ZBA/Modules/BootScr/.hgkeep +++ b/dev/ZBA/Modules/SysChk/.hgkeep diff --git a/dev/ZBA/Modules/BootScr/Boot.S b/dev/ZBA/Modules/SysChk/Boot.S index ce9f36b1..ce9f36b1 100644 --- a/dev/ZBA/Modules/BootScr/Boot.S +++ b/dev/ZBA/Modules/SysChk/Boot.S diff --git a/dev/ZBA/Modules/BootScr/Module.cxx b/dev/ZBA/Modules/SysChk/Module.cxx index 15758599..15758599 100644 --- a/dev/ZBA/Modules/BootScr/Module.cxx +++ b/dev/ZBA/Modules/SysChk/Module.cxx diff --git a/dev/ZBA/Modules/BootScr/build.json b/dev/ZBA/Modules/SysChk/build.json index c53c6faa..aff1e78a 100644 --- a/dev/ZBA/Modules/BootScr/build.json +++ b/dev/ZBA/Modules/SysChk/build.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "../../", "../../../ZKA", "../../../", "./"], "sources_path": ["*.cxx", "*.S"], - "output_name": "bootscr.sys", + "output_name": "syschk.sys", "compiler_flags": [ "-ffreestanding", "-nostdlib", diff --git a/dev/ZBA/Modules/BootScr/compile_flags.txt b/dev/ZBA/Modules/SysChk/compile_flags.txt index 6ab76da0..6ab76da0 100644 --- a/dev/ZBA/Modules/BootScr/compile_flags.txt +++ b/dev/ZBA/Modules/SysChk/compile_flags.txt diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index c5ee3fb3..c98f700c 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -226,8 +226,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // format the disk. // ---------------------------------------------------- // - BFileReader readerBootScr(L"bootscr.sys", ImageHandle); - readerBootScr.ReadAll(0); + BFileReader readerSysChk(L"syschk.sys", ImageHandle); + readerSysChk.ReadAll(0); Boot::BThread* loaderBootScr = nullptr; @@ -235,10 +235,10 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // If we succeed in reading the blob, then execute it. // ------------------------------------------ // - if (readerBootScr.Blob()) + if (readerSysChk.Blob()) { - loaderBootScr = new Boot::BThread(readerBootScr.Blob()); - loaderBootScr->SetName("64-bit Boot Screen DLL."); + loaderBootScr = new Boot::BThread(readerSysChk.Blob()); + loaderBootScr->SetName("64-bit System Check DLL."); } loaderBootScr->Start(handoverHdrPtr); diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx index 58937213..610d45b8 100644 --- a/dev/ZBA/Sources/Thread.cxx +++ b/dev/ZBA/Sources/Thread.cxx @@ -12,34 +12,20 @@ #include <KernelKit/PEF.hxx> #include <KernelKit/PE.hxx> #include <KernelKit/MSDOS.hxx> -#include <Modules/CoreCG/TextRenderer.hxx> #include <CFKit/LoaderUtils.hxx> +#include <Modules/CoreCG/TextRenderer.hxx> + +#include <SIGG/Drv.hxx> EXTERN_C{ #include <string.h> } -// External boot services record. +// External boot services symbol. EXTERN EfiBootServices* BS; namespace Boot { - namespace Detail - { - /// @brief Instablle Secure Driver record. - struct SIGNED_DRIVER_HEADER final - { - // doesn't change. - char d_binary_magic[5]; - int d_binary_version; - // can change. - char d_binary_name[4096]; - UInt64 d_binary_checksum; - UInt64 d_binary_size; - char d_binary_padding[512]; - }; - } // namespace Detail - BThread::BThread(VoidPtr blob) : fBlob(blob), fStartAddress(nullptr) { @@ -57,8 +43,8 @@ namespace Boot if (firstBytes[0] == kMagMz0 && firstBytes[1] == kMagMz1) { - ExecHeaderPtr hdrPtr = ldr_find_exec_header(firstBytes); - ExecOptionalHeaderPtr optHdr = ldr_find_opt_exec_header(firstBytes); + LDR_EXEC_HEADER_PTR hdrPtr = ldr_find_exec_header(firstBytes); + LDR_OPTIONAL_HEADER_PTR optHdr = ldr_find_opt_exec_header(firstBytes); if (hdrPtr->mMachine != kPeMachineAMD64 || hdrPtr->mSignature != kPeMagic) @@ -93,7 +79,7 @@ namespace Boot auto numPages = optHdr->mSizeOfImage / cPageSize; BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress); - ExecSectionHeaderPtr sectPtr = (ExecSectionHeaderPtr)(((Char*)optHdr) + hdrPtr->mSizeOfOptionalHeader); + LDR_SECTION_HEADER_PTR sectPtr = (LDR_SECTION_HEADER_PTR)(((Char*)optHdr) + hdrPtr->mSizeOfOptionalHeader); constexpr auto sectionForCode = ".text"; constexpr auto sectionForNewLdr = ".ldr"; @@ -101,7 +87,7 @@ namespace Boot for (SizeT sectIndex = 0; sectIndex < numSecs; ++sectIndex) { - ExecSectionHeaderPtr sect = §Ptr[sectIndex]; + LDR_SECTION_HEADER_PTR sect = §Ptr[sectIndex]; if (StrCmp(sectionForCode, sect->mName) == 0) { diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index ef54c12c..f5c19801 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -32,8 +32,11 @@ IMG_3=epm-master-2.img EMU_FLAGS=-net none -smp 4 -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 -hdd $(IMG_2) -drive \ - file=fat:rw:Sources/Root/,index=2,format=raw -d int + -device ide-hd,drive=disk,bus=ide.0 -drive \ + file=fat:rw:Sources/Root/,index=2,format=raw -d int \ + -drive id=disk_2,file=$(IMG_2),if=none \ + -device ahci,id=ahci \ + -device ide-hd,drive=disk_2,bus=ahci.0 LD_FLAGS=-e Main --subsystem=10 @@ -53,7 +56,7 @@ KERNEL=newoskrnl.dll DDK=ddk.dll SCI=sci.dll CRT=ndkcrt.dll -BOOT_SCR=bootscr.sys +SYS_CHK=syschk.sys .PHONY: invalid-recipe invalid-recipe: @@ -68,7 +71,7 @@ all: compile-amd64 $(COPY) ../ZKA/$(KERNEL) Sources/Root/$(KERNEL) $(COPY) ../SCI/$(SCI) Sources/Root/$(SCI) $(COPY) ../DDK/$(DDK) Sources/Root/$(DDK) - $(COPY) ./Modules/BootScr/$(BOOT_SCR) Sources/Root/$(BOOT_SCR) + $(COPY) ./Modules/SysChk/$(SYS_CHK) Sources/Root/$(SYS_CHK) $(COPY) ../CRT/$(CRT) Sources/Root/$(CRT) $(COPY) Sources/$(BOOT_LOADER) Sources/Root/$(BOOT_LOADER) diff --git a/dev/ZKA/CFKit/LoaderUtils.hxx b/dev/ZKA/CFKit/LoaderUtils.hxx index 3edacc67..248b18b8 100644 --- a/dev/ZKA/CFKit/LoaderUtils.hxx +++ b/dev/ZKA/CFKit/LoaderUtils.hxx @@ -7,7 +7,7 @@ namespace Kernel { /// @brief Find the PE header inside the blob. - inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> ExecHeaderPtr + inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> LDR_EXEC_HEADER_PTR { if (!ptrDos) return nullptr; @@ -18,11 +18,11 @@ namespace Kernel if (ptrDos->eMagic[1] != kMagMz1) return nullptr; - return (ExecHeaderPtr)(VoidPtr)(&ptrDos->eLfanew + 1); + return (LDR_EXEC_HEADER_PTR)(VoidPtr)(&ptrDos->eLfanew + 1); } /// @brief Find the PE optional header inside the blob. - inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> ExecOptionalHeaderPtr + inline auto ldr_find_opt_exec_header(DosHeaderPtr ptrDos) -> LDR_OPTIONAL_HEADER_PTR { if (!ptrDos) return nullptr; @@ -32,12 +32,12 @@ namespace Kernel if (!exec) return nullptr; - return (ExecOptionalHeaderPtr)(VoidPtr)(&exec->mCharacteristics + 1); + return (LDR_OPTIONAL_HEADER_PTR)(VoidPtr)(&exec->mCharacteristics + 1); } /// @brief Find the PE header inside the blob. /// @note overloaded function. - inline auto ldr_find_exec_header(const Char* ptrDos) -> ExecHeaderPtr + inline auto ldr_find_exec_header(const Char* ptrDos) -> LDR_EXEC_HEADER_PTR { return ldr_find_exec_header((DosHeaderPtr)ptrDos); } @@ -45,7 +45,7 @@ namespace Kernel /// @brief Find the PE header inside the blob. /// @note overloaded function. - inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> ExecOptionalHeaderPtr + inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> LDR_OPTIONAL_HEADER_PTR { return ldr_find_opt_exec_header((DosHeaderPtr)ptrDos); } diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 1c3d4187..0845dc39 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -22,7 +22,6 @@ #include <Modules/CoreCG/TextRenderer.hxx> Kernel::Property cKernelVersion; -Kernel::Property cAutoFormatDisk; EXTERN Kernel::Boolean kAllocationInProgress; @@ -66,6 +65,7 @@ STATIC Kernel::HAL::Detail::NewOSGDT cGdt = { }; Kernel::Void hal_real_init(Kernel::Void) noexcept; +EXTERN_C Kernel::Void KeMain(Kernel::Void); EXTERN_C void hal_init_platform( Kernel::HEL::HandoverInformationHeader* HandoverHeader) @@ -232,5 +232,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::User user_debug{Kernel::RingKind::kRingSuperUser, kSuperUser}; Kernel::UserManager::The()->TryLogIn(user_debug, cPassword, cPassword); + KeMain(); + Kernel::ke_stop(RUNTIME_CHECK_FAILED); } diff --git a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx index e8742cdc..c37bc01a 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx @@ -11,7 +11,7 @@ * @version 0.1 * @date 2024-02-02 * - * @copyright Copyright (c) ZKA Technologies + * @copyright ZKA Technologies. * */ @@ -25,8 +25,8 @@ enum kSATASubClass = 0x06 }; -static Kernel::PCI::Device kAhciDevice; -static HbaPort* kAhciPort = nullptr; +STATIC Kernel::PCI::Device kAhciDevice; +STATIC HbaPort* kAhciPort = nullptr; /// @brief Initializes an AHCI disk. /// @param PortsImplemented the amount of port that have been detected. @@ -42,39 +42,53 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) if (iterator[devIndex].Leak().Subclass() == kSATASubClass && iterator[devIndex].Leak().ProgIf() == kSATAProgIfAHCI) { - iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device. + iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device. + iterator[devIndex].Leak().BecomeBusMaster(); /// become bus master for this ahci device, so that we can control it. + kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference. HbaMem* mem_ahci = (HbaMem*)kAhciDevice.Bar(); - UInt32 pi = mem_ahci->Pi; - Int32 i = 0; + UInt32 ports_implemented = mem_ahci->Pi; + Int32 ahci_index = 0; const auto cMaxAhciDevices = 32; const auto cAhciSig = 0x00000101; const auto cAhciPresent = 0x03; + const auto cAhciIPMActive = 0x01; + + auto detected = false; - while (i < cMaxAhciDevices) + while (ahci_index < cMaxAhciDevices) { - if (pi & 1 && - (mem_ahci->Ports[i].Ssts & 0x0F) == cAhciPresent && - ((mem_ahci->Ports[i].Ssts >> 8) & 0x0F) == 1) + if (ports_implemented) { - kcout << "newoskrnl: Port is implemented.\r"; + kcout << "newoskrnl: Port is implemented by host.\r"; - if (mem_ahci->Ports[i].Sig == cAhciSig) + UInt8 ipm = (mem_ahci->Ports[ahci_index].Ssts >> 8) & 0x0F; + UInt8 det = mem_ahci->Ports[ahci_index].Ssts & 0x0F; + + if (mem_ahci->Ports[ahci_index].Sig == cAhciSig && + det == cAhciPresent && + ipm == cAhciIPMActive) { - kcout << "newoskrnl: device is SATA.\r"; + kcout << "newoskrnl: Found AHCI controller.\r"; + kcout << "newoskrnl: Device is of SATA type.\r"; + + detected = true; + + kAhciPort = &mem_ahci->Ports[ahci_index]; + + // start command engine. + // drv_start_ahci_engine(); } } - pi >>= 1; - i++; + ports_implemented >>= 1; + ahci_index++; } - kcout << "newoskrnl: [PCI] Found AHCI controller.\r"; - - return true; + return detected; } } diff --git a/dev/ZKA/KernelKit/PE.hxx b/dev/ZKA/KernelKit/PE.hxx index 11cc564e..d17bf840 100644 --- a/dev/ZKA/KernelKit/PE.hxx +++ b/dev/ZKA/KernelKit/PE.hxx @@ -24,7 +24,7 @@ #define kPeMachineAMD64 0x8664 #define kPeMachineARM64 0xaa64 -typedef struct ExecHeader final +typedef struct LDR_EXEC_HEADER final { Kernel::UInt32 mSignature; Kernel::UInt16 mMachine; @@ -34,9 +34,9 @@ typedef struct ExecHeader final Kernel::UInt32 mNumberOfSymbols; Kernel::UInt16 mSizeOfOptionalHeader; Kernel::UInt16 mCharacteristics; -} ExecHeader, *ExecHeaderPtr; +} LDR_EXEC_HEADER, *LDR_EXEC_HEADER_PTR; -typedef struct ExecOptionalHeader final +typedef struct LDR_OPTIONAL_HEADER final { Kernel::UInt16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) Kernel::UInt8 mMajorLinkerVersion; @@ -68,9 +68,9 @@ typedef struct ExecOptionalHeader final Kernel::UInt32 mSizeOfHeapCommit; Kernel::UInt32 mLoaderFlags; Kernel::UInt32 mNumberOfRvaAndSizes; -} ExecOptionalHeader, *ExecOptionalHeaderPtr; +} LDR_OPTIONAL_HEADER, *LDR_OPTIONAL_HEADER_PTR; -typedef struct ExecSectionHeader final +typedef struct LDR_SECTION_HEADER final { Kernel::Char mName[8]; Kernel::UInt32 mVirtualSize; @@ -82,7 +82,7 @@ typedef struct ExecSectionHeader final Kernel::UInt16 mNumberOfRelocations; Kernel::UInt16 mNumberOfLinenumbers; Kernel::UInt32 mCharacteristics; -} ExecSectionHeader, *ExecSectionHeaderPtr; +} LDR_SECTION_HEADER, *LDR_SECTION_HEADER_PTR; enum kExecDataDirParams { @@ -92,7 +92,7 @@ enum kExecDataDirParams kExecCount, }; -typedef struct ExecExportDirectory +typedef struct LDR_EXPORT_DIRECTORY { Kernel::UInt32 mCharacteristics; Kernel::UInt32 mTimeDateStamp; @@ -105,9 +105,9 @@ typedef struct ExecExportDirectory Kernel::UInt32 mAddressOfFunctions; // export table rva Kernel::UInt32 mAddressOfNames; Kernel::UInt32 mAddressOfNameOrdinal; // ordinal table rva -} ExecExportDirectory, *ExecExportDirectoryPtr; +} LDR_EXPORT_DIRECTORY, *LDR_EXPORT_DIRECTORY_PTR; -typedef struct ExecImportDirectory +typedef struct LDR_IMPORT_DIRECTORY { union { Kernel::UInt32 mCharacteristics; @@ -117,17 +117,17 @@ typedef struct ExecImportDirectory Kernel::UInt32 mForwarderChain; Kernel::UInt32 mNameRva; Kernel::UInt32 mThunkTableRva; -} ExecImportDirectory, *ExecImportDirectoryPtr; +} LDR_IMPORT_DIRECTORY, *LDR_IMPORT_DIRECTORY_PTR; -typedef struct ExecDataDirectory { +typedef struct LDR_DATA_DIRECTORY { Kernel::UInt32 VirtualAddress; Kernel::UInt32 Size; -} ExecDataDirectory, *ExecDataDirectoryPtr; +} LDR_DATA_DIRECTORY, *LDR_DATA_DIRECTORY_PTR; -typedef struct ExecImageHeader { - ExecHeader mHeader; - ExecOptionalHeader mOptHdr; -} ExecImageHeader, *ExecImageHeaderPtr; +typedef struct LDR_IMAGE_HEADER { + LDR_EXEC_HEADER mHeader; + LDR_OPTIONAL_HEADER mOptHdr; +} LDR_IMAGE_HEADER, *LDR_IMAGE_HEADER_PTR; enum { diff --git a/dev/ZKA/KernelKit/User.hxx b/dev/ZKA/KernelKit/User.hxx index ddc422c3..4686135f 100644 --- a/dev/ZKA/KernelKit/User.hxx +++ b/dev/ZKA/KernelKit/User.hxx @@ -13,10 +13,10 @@ #include <NewKit/Defines.hxx> // user mode users. -#define kSuperUser "\\Local\\Super" -#define kGuestUser "\\Local\\Guest" +#define kSuperUser "ZKA USER\\SYSTEM" +#define kGuestUser "ZKA USER\\GUEST" -#define kUsersFile "\\Users\\UsrRcrd" +#define kUsersFile "\\Users\\$UsrRcrd" #define kUsersDir "\\Users\\" #define kMaxUserNameLen (255) diff --git a/dev/ZKA/Modules/AHCI/AHCI.hxx b/dev/ZKA/Modules/AHCI/AHCI.hxx index 7d8c7cd5..abf31187 100644 --- a/dev/ZKA/Modules/AHCI/AHCI.hxx +++ b/dev/ZKA/Modules/AHCI/AHCI.hxx @@ -264,7 +264,7 @@ typedef struct HbaMem final Kernel::UInt16 Resv0; Kernel::UInt32 Resv2; - HbaPort Ports[32]; // 1 ~ 32, 32 is the max ahci devices per controller. + HbaPort Ports[1]; // 1 ~ 32, 32 is the max ahci devices per controller. } HbaMem; typedef struct HbaCmdHeader final diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx new file mode 100644 index 00000000..edfc804f --- /dev/null +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -0,0 +1,189 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + + File: Main.cxx + Purpose: Main entrypoint of kernel. + +------------------------------------------- */ + +#include <ArchKit/ArchKit.hxx> +#include <CompilerKit/Detail.hxx> +#include <FirmwareKit/Handover.hxx> +#include <KernelKit/FileManager.hxx> +#include <KernelKit/Framebuffer.hxx> +#include <KernelKit/Heap.hxx> +#include <KernelKit/PEF.hxx> +#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/ProcessScheduler.hxx> +#include <KernelKit/ProcessHeap.hxx> +#include <NewKit/Json.hxx> +#include <NewKit/KernelCheck.hxx> +#include <NewKit/String.hxx> +#include <NewKit/Utils.hxx> +#include <KernelKit/CodeManager.hxx> +#include <CFKit/Property.hxx> + +EXTERN Kernel::Property cKernelVersion; + +namespace Kernel::Detail +{ + /// @brief Filesystem auto formatter, additional checks are also done by the class. + class FilesystemInstaller final + { + Kernel::NewFilesystemManager* fNewFS{nullptr}; + + public: + /// @brief wizard constructor. + explicit FilesystemInstaller() + { + if (Kernel::FilesystemManagerInterface::GetMounted()) + { + // Partition is mounted, cool! + Kernel::kcout + << "newoskrnl: No need to create for a new NewFS (EPM) partition here...\r"; + + fNewFS = reinterpret_cast<Kernel::NewFilesystemManager*>(Kernel::FilesystemManagerInterface::GetMounted()); + } + else + { + // Mounts a NewFS from main drive. + fNewFS = new Kernel::NewFilesystemManager(); + + Kernel::FilesystemManagerInterface::Mount(fNewFS); + } + + if (fNewFS->GetParser()) + { + constexpr auto cFolderInfo = "META-INF"; + const auto cDirCount = 7; + const char* cDirStr[cDirCount] = { + "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", + "\\Users\\", "\\Library\\", "\\Mount\\"}; + + for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) + { + auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + + if (catalogDir) + { + Kernel::kcout << "newoskrnl: already exists.\r"; + + delete catalogDir; + continue; + } + + catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, + kNewFSCatalogKindDir); + + NFS_FORK_STRUCT theFork{0}; + + const Kernel::Char* cSrcName = cFolderInfo; + + Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theFork.ForkName, + Kernel::rt_string_len(cSrcName)); + + Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDir->Name), + theFork.CatalogName, + Kernel::rt_string_len(catalogDir->Name)); + + delete catalogDir; + + theFork.DataSize = kNewFSForkSize; + theFork.ResourceId = 0; + theFork.ResourceKind = Kernel::kNewFSRsrcForkKind; + theFork.Kind = Kernel::kNewFSDataForkKind; + + Kernel::StringView metadataFolder(kNewFSSectorSz); + + metadataFolder += + "<!properties/>\r<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " + "system</p>\r<p>Volume Type: Zeta</p>\r"; + + metadataFolder += "<p>Path: "; + metadataFolder += cDirStr[dirIndx]; + metadataFolder += "</p>\r"; + + const Kernel::SizeT metadataSz = kNewFSSectorSz; + + auto catalogSystem = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + + fNewFS->GetParser()->CreateFork(catalogSystem, theFork); + + fNewFS->GetParser()->WriteCatalog( + catalogSystem, true, (Kernel::VoidPtr)(metadataFolder.CData()), + metadataSz, cFolderInfo); + + delete catalogSystem; + } + } + + NFS_CATALOG_STRUCT* catalogDisk = + this->fNewFS->GetParser()->GetCatalog("\\Mount\\NUL:"); + + const Kernel::Char* cSrcName = "DISK-INF"; + + if (catalogDisk) + { + delete catalogDisk; + } + else + { + catalogDisk = + (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\NUL:"); + + Kernel::StringView diskFolder(kNewFSSectorSz); + + diskFolder += + "<!properties/><p>Kind: alias to NULL.</p>\r<p>Created by: system</p>\r<p>Edited " + "by: " + "system</p>\r<p>Volume Type: NULL.</p>\r"; + + diskFolder += "<p>Root: NUL"; + diskFolder += "</p>\r"; + + 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 = kNewFSForkSize; + theDiskFork.ResourceId = 0; + theDiskFork.ResourceKind = Kernel::kNewFSRsrcForkKind; + theDiskFork.Kind = Kernel::kNewFSDataForkKind; + + fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); + fNewFS->GetParser()->WriteCatalog(catalogDisk, + true, + (Kernel::VoidPtr)diskFolder.CData(), + kNewFSSectorSz, cSrcName); + + delete catalogDisk; + } + } + + ~FilesystemInstaller() = default; + + NEWOS_COPY_DEFAULT(FilesystemInstaller); + + /// @brief Grab the disk's NewFS reference. + /// @return NewFilesystemManager the filesystem interface + Kernel::NewFilesystemManager* Leak() + { + return fNewFS; + } + }; +} // namespace Kernel::Detail + +/// @brief Application entrypoint. +/// @param Void +/// @return Void +EXTERN_C Kernel::Void KeMain(Kernel::Void) +{ + /// Now run kernel loop, until no process are running. + Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. +} diff --git a/dev/ZKA/Sources/DriveManager.cxx b/dev/ZKA/Sources/DriveManager.cxx index c4cebc3f..48a61f41 100644 --- a/dev/ZKA/Sources/DriveManager.cxx +++ b/dev/ZKA/Sources/DriveManager.cxx @@ -131,7 +131,7 @@ namespace Kernel { DriveTrait trait; - rt_copy_memory((VoidPtr) "MainDisk", trait.fName, rt_string_len("MainDisk")); + rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); trait.fKind = kMassStorage; trait.fInput = ke_drv_input; diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx index 36e0755e..8f9ef8ef 100644 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ b/dev/ZKA/Sources/FS/NewFS.cxx @@ -486,13 +486,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; + // EPM header. + constexpr auto cFsName = "NewFS"; constexpr auto cBlockName = "ZKA:"; rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); epmBoot->FsVersion = kNewFSVersionInteger; - epmBoot->LbaStart = 0; + epmBoot->LbaStart = start; epmBoot->SectorSz = kNewFSSectorSz; rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); |
