From 95f2fc6a9ba93d98a81a817c489de5946dc3f13b Mon Sep 17 00:00:00 2001 From: Amlal Date: Thu, 12 Sep 2024 05:32:09 +0200 Subject: Kernel and Bootloader improvements. - The Allocator works, we have to find a free memory region for the kernel though. - Add Init procedure to DriveMgr. - Refactor CG for cgwm.sys Signed-off-by: Amlal --- dev/ZBA/BootKit/BootKit.hxx | 533 ++++++++++++++------------- dev/ZBA/Sources/HEL/AMD64/BootATA.cxx | 2 + dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx | 12 +- dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 35 +- dev/ZBA/Sources/HEL/AMD64/BootPlatform.cxx | 2 + dev/ZBA/Sources/HEL/AMD64/BootString.cxx | 10 +- dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx | 12 +- dev/ZBA/Sources/Thread.cxx | 2 +- dev/ZKA/FirmwareKit/Handover.hxx | 3 +- dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 4 +- dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 6 +- dev/ZKA/KernelKit/DriveMgr.hxx | 1 + dev/ZKA/Modules/CoreCG/WindowRenderer.hxx | 8 +- dev/ZKA/Sources/DriveMgr.cxx | 16 +- dev/ZKA/Sources/FS/NeFS.cxx | 14 +- dev/ZKA/Sources/KernelCheck.cxx | 6 - 16 files changed, 343 insertions(+), 323 deletions(-) (limited to 'dev') diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 590e50f4..96ded41c 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -34,352 +34,353 @@ /// Framebuffer helpers. /***********************************************************************************/ -class BTextWriter; -class BFileReader; -class BThread; -class BVersionString; - -typedef Char* PEFImagePtr; -typedef Char* PEImagePtr; - -typedef WideChar CharacterTypeUTF16; -typedef Char CharacterTypeUTF8; - -using namespace Kernel; - namespace EFI { - extern void ThrowError(const CharacterTypeUTF16* errorCode, - const CharacterTypeUTF16* reason) noexcept; + extern void ThrowError(const WideChar* errorCode, + const WideChar* reason) noexcept; } // namespace EFI -/** - * @brief BootKit Text Writer class - * Writes to UEFI StdOut. - */ -class BTextWriter final +namespace Boot { - BTextWriter& _Write(const Long& num); - -public: - BTextWriter& Write(const Long& num); - BTextWriter& Write(const Char* str); - BTextWriter& Write(const CharacterTypeUTF16* str); - BTextWriter& WriteCharacter(CharacterTypeUTF16 c); - BTextWriter& Write(const UChar* str); + class BTextWriter; + class BFileReader; + class BThread; + class BVersionString; -public: - explicit BTextWriter() = default; - ~BTextWriter() = default; + typedef Char* PEFImagePtr; + typedef Char* PEImagePtr; -public: - BTextWriter& operator=(const BTextWriter&) = default; - BTextWriter(const BTextWriter&) = default; -}; + typedef WideChar CharacterTypeUTF16; + typedef Char CharacterTypeUTF8; -Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len); + using namespace Kernel; -Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len); + /** + * @brief BootKit Text Writer class + * Writes to UEFI StdOut. + */ + class BTextWriter final + { + BTextWriter& _Write(const Long& num); + + public: + BTextWriter& Write(const Long& num); + BTextWriter& Write(const Char* str); + BTextWriter& Write(const CharacterTypeUTF16* str); + BTextWriter& WriteCharacter(CharacterTypeUTF16 c); + BTextWriter& Write(const UChar* str); + + public: + explicit BTextWriter() = default; + ~BTextWriter() = default; + + public: + BTextWriter& operator=(const BTextWriter&) = default; + BTextWriter(const BTextWriter&) = default; + }; -/// String length functions. + Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len); -/// @brief get string length. -Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr); + Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len); -/// @brief set memory with custom value. -Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len); + /// String length functions. -/** - * @brief BootKit File Reader class - * Reads the Firmware Boot partition and filesystem. - */ -class BFileReader final -{ -public: - explicit BFileReader(const CharacterTypeUTF16* path, - EfiHandlePtr ImageHandle); - ~BFileReader(); + /// @brief get string length. + Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr); -public: - Void ReadAll(SizeT until, SizeT chunk = kib_cast(4), UIntPtr outAddress = 0UL); + /// @brief set memory with custom value. + Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len); - enum + /** + * @brief BootKit File Reader class + * Reads the Firmware Boot partition and filesystem. + */ + class BFileReader final { - kOperationOkay, - kNotSupported, - kEmptyDirectory, - kNoSuchEntry, - kIsDirectory, - kTooSmall, - kCount, - }; - - /// @brief error code getter. - /// @return the error code. - Int32& Error(); + public: + explicit BFileReader(const CharacterTypeUTF16* path, + EfiHandlePtr ImageHandle); + ~BFileReader(); - /// @brief blob getter. - /// @return the blob. - VoidPtr Blob(); + public: + Void ReadAll(SizeT until, SizeT chunk = kib_cast(4), UIntPtr outAddress = 0UL); - /// @breif Size getter. - /// @return the size of the file. - UInt64& Size(); - -public: - BFileReader& operator=(const BFileReader&) = default; - BFileReader(const BFileReader&) = default; - -private: - Int32 mErrorCode{kOperationOkay}; - VoidPtr mBlob{nullptr}; - CharacterTypeUTF16 mPath[kPathLen]; - BTextWriter mWriter; - EfiFileProtocol* mFile{nullptr}; - UInt64 mSizeFile{0}; - EfiFileProtocol* mRootFs; -}; + enum + { + kOperationOkay, + kNotSupported, + kEmptyDirectory, + kNoSuchEntry, + kIsDirectory, + kTooSmall, + kCount, + }; + + /// @brief error code getter. + /// @return the error code. + Int32& Error(); + + /// @brief blob getter. + /// @return the blob. + VoidPtr Blob(); + + /// @breif Size getter. + /// @return the size of the file. + UInt64& Size(); + + public: + BFileReader& operator=(const BFileReader&) = default; + BFileReader(const BFileReader&) = default; + + private: + Int32 mErrorCode{kOperationOkay}; + VoidPtr mBlob{nullptr}; + CharacterTypeUTF16 mPath[kPathLen]; + BTextWriter mWriter; + EfiFileProtocol* mFile{nullptr}; + UInt64 mSizeFile{0}; + EfiFileProtocol* mRootFs; + }; -typedef UInt8* BlobType; + typedef UInt8* BlobType; -class BVersionString final -{ -public: - static const CharacterTypeUTF8* The() + class BVersionString final { - return BOOTLOADER_VERSION; - } -}; + public: + static const CharacterTypeUTF8* The() + { + return BOOTLOADER_VERSION; + } + }; -/***********************************************************************************/ -/// Provide some useful processor features. -/***********************************************************************************/ + /***********************************************************************************/ + /// Provide some useful processor features. + /***********************************************************************************/ #ifdef __EFI_x86_64__ -/*** - * Common processor instructions. - */ + /*** + * Common processor instructions. + */ -EXTERN_C void Out8(UInt16 port, UInt8 value); -EXTERN_C void Out16(UInt16 port, UInt16 value); -EXTERN_C void Out32(UInt16 port, UInt32 value); -EXTERN_C UInt8 In8(UInt16 port); -EXTERN_C UInt16 In16(UInt16 port); -EXTERN_C UInt32 In32(UInt16 port); + EXTERN_C void Out8(UInt16 port, UInt8 value); + EXTERN_C void Out16(UInt16 port, UInt16 value); + EXTERN_C void Out32(UInt16 port, UInt32 value); + EXTERN_C UInt8 In8(UInt16 port); + EXTERN_C UInt16 In16(UInt16 port); + EXTERN_C UInt32 In32(UInt16 port); -EXTERN_C void rt_hlt(); -EXTERN_C void rt_cli(); -EXTERN_C void rt_sti(); -EXTERN_C void rt_cld(); -EXTERN_C void rt_std(); + EXTERN_C void rt_hlt(); + EXTERN_C void rt_cli(); + EXTERN_C void rt_sti(); + EXTERN_C void rt_cld(); + EXTERN_C void rt_std(); #endif // __EFI_x86_64__ -static inline const UInt32 kRgbRed = 0x000000FF; -static inline const UInt32 kRgbGreen = 0x0000FF00; -static inline const UInt32 kRgbBlue = 0x00FF0000; -static inline const UInt32 kRgbBlack = 0x00000000; -static inline const UInt32 kRgbWhite = 0x00FFFFFF; + static inline const UInt32 kRgbRed = 0x000000FF; + static inline const UInt32 kRgbGreen = 0x0000FF00; + static inline const UInt32 kRgbBlue = 0x00FF0000; + static inline const UInt32 kRgbBlack = 0x00000000; + static inline const UInt32 kRgbWhite = 0x00FFFFFF; #define kBKBootFileMime "boot-x/file" #define kBKBootDirMime "boot-x/dir" -/// @brief BootKit Drive Formatter. -template -class BDiskFormatFactory final -{ -public: - /// @brief File entry for **BDiskFormatFactory**. - struct BFileDescriptor final + /// @brief BootKit Drive Formatter. + template + class BDiskFormatFactory final { - Char fFileName[kNeFSNodeNameLen]; - Int32 fKind; - }; + public: + /// @brief File entry for **BDiskFormatFactory**. + struct BFileDescriptor final + { + Char fFileName[kNeFSNodeNameLen]; + Int32 fKind; + }; + + public: + explicit BDiskFormatFactory() = default; + explicit BDiskFormatFactory(BootDev dev) + : fDiskDev(dev) + { + } -public: - explicit BDiskFormatFactory() = default; - explicit BDiskFormatFactory(BootDev dev) - : fDiskDev(dev) - { - } + ~BDiskFormatFactory() = default; - ~BDiskFormatFactory() = default; + ZKA_COPY_DELETE(BDiskFormatFactory); - ZKA_COPY_DELETE(BDiskFormatFactory); + /// @brief Format disk. + /// @param Partition Name + /// @param Blobs. + /// @param Number of blobs. + /// @retval True disk has been formatted. + /// @retval False failed to format. + Boolean Format(const Char* partName, BFileDescriptor* fileBlobs, SizeT blobCount); - /// @brief Format disk. - /// @param Partition Name - /// @param Blobs. - /// @param Number of blobs. - /// @retval True disk has been formatted. - /// @retval False failed to format. - Boolean Format(const Char* partName, BFileDescriptor* fileBlobs, SizeT blobCount); + /// @brief check if partition is good. + Bool IsPartitionValid() noexcept + { + fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); + fDiskDev.Leak().mSize = BootDev::kSectorSize; - /// @brief check if partition is good. - Bool IsPartitionValid() noexcept - { - fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); - fDiskDev.Leak().mSize = BootDev::kSectorSize; + Char buf[BootDev::kSectorSize] = {0}; - Char buf[BootDev::kSectorSize] = {0}; + fDiskDev.Read(buf, BootDev::kSectorSize); - fDiskDev.Read(buf, BootDev::kSectorSize); + NFS_ROOT_PARTITION_BLOCK* blockPart = reinterpret_cast(buf); - NFS_ROOT_PARTITION_BLOCK* blockPart = reinterpret_cast(buf); + BTextWriter writer; - BTextWriter writer; + for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) + { + if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) + return false; + } - for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) - { - if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) + if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || + blockPart->DiskSize < 1 || + blockPart->SectorSize != BootDev::kSectorSize || + blockPart->Version != kNeFSVersionInteger || + blockPart->StartCatalog == 0) + { return false; - } + } + else if (blockPart->PartitionName[0] == 0) + { + return false; + } - writer.Write(L"NEWOSLDR: Drive is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r"); + writer.Write(L"NEWOSLDR: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); - if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || - blockPart->DiskSize < 1 || - blockPart->SectorSize != BootDev::kSectorSize || - blockPart->Version != kNeFSVersionInteger || - blockPart->StartCatalog == 0) - { - return false; - } - else if (blockPart->PartitionName[0] == 0) - { - return false; + return true; } - writer.Write(L"NEWOSLDR: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); + 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 NeFS partition block. + Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock) + { + BFileDescriptor* blob = fileBlobs; + Lba startLba = partBlock.StartCatalog; + BTextWriter writer; - return true; - } + NFS_CATALOG_STRUCT catalogKind{0}; -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 NeFS partition block. - Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock) - { - BFileDescriptor* blob = fileBlobs; - Lba startLba = partBlock.StartCatalog; - BTextWriter writer; + constexpr auto cNeFSCatalogPadding = 4; - NFS_CATALOG_STRUCT catalogKind{0}; + catalogKind.PrevSibling = startLba; + catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); - constexpr auto cNeFSCatalogPadding = 4; + /// Fill catalog kind. + catalogKind.Kind = blob->fKind; + catalogKind.Flags = kNeFSFlagCreated; - catalogKind.PrevSibling = startLba; - catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + --partBlock.FreeCatalog; + --partBlock.FreeSectors; - /// Fill catalog kind. - catalogKind.Kind = blob->fKind; - catalogKind.Flags = kNeFSFlagCreated; + CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); - --partBlock.FreeCatalog; - --partBlock.FreeSectors; + fDiskDev.Leak().mBase = startLba; + fDiskDev.Leak().mSize = sizeof(NFS_CATALOG_STRUCT); - CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); + fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT)); - fDiskDev.Leak().mBase = startLba; - fDiskDev.Leak().mSize = sizeof(NFS_CATALOG_STRUCT); + writer.Write(L"NEWOSLDR: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); - fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT)); + return true; + } - writer.Write(L"NEWOSLDR: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); + private: + BootDev fDiskDev; + }; - return true; - } + /// @brief Format disk. + /// @param Partition Name + /// @param Blobs. + /// @param Number of blobs. + /// @retval True disk has been formatted. + /// @retval False failed to format. + template + inline Boolean BDiskFormatFactory::Format(const Char* partName, + BDiskFormatFactory::BFileDescriptor* fileBlobs, + SizeT blobCount) + { + if (!fileBlobs || !blobCount) + return false; /// sanity check -private: - BootDev fDiskDev; -}; - -/// @brief Format disk. -/// @param Partition Name -/// @param Blobs. -/// @param Number of blobs. -/// @retval True disk has been formatted. -/// @retval False failed to format. -template -inline Boolean BDiskFormatFactory::Format(const Char* partName, - BDiskFormatFactory::BFileDescriptor* fileBlobs, - SizeT blobCount) -{ - if (!fileBlobs || !blobCount) - return false; /// sanity check + /// convert the sector into something that the disk understands. + SizeT sectorSz = BootDev::kSectorSize; - /// convert the sector into something that the disk understands. - SizeT sectorSz = BootDev::kSectorSize; + /// @note A catalog roughly equal to a sector. - /// @note A catalog roughly equal to a sector. + constexpr auto cMinimumDiskSize = 4; // at minimum. - constexpr auto cMinimumDiskSize = 4; // at minimum. + /// @note also look at EPM headers, for free part blocks. - /// @note also look at EPM headers, for free part blocks. + if (GIB(fDiskDev.GetDiskSize()) < cMinimumDiskSize) + { + EFI::ThrowError(L"Drive-Too-Tiny", L"Can't format a New Filesystem partition here."); + return false; + } - if (GIB(fDiskDev.GetDiskSize()) < cMinimumDiskSize) - { - EFI::ThrowError(L"Drive-Too-Tiny", L"Can't format a New Filesystem partition here."); - return false; - } + NFS_ROOT_PARTITION_BLOCK partBlock{0}; - NFS_ROOT_PARTITION_BLOCK partBlock{0}; + CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1); + CopyMem(partBlock.PartitionName, partName, strlen(partName)); - CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1); - CopyMem(partBlock.PartitionName, partName, strlen(partName)); + partBlock.Version = kNeFSVersionInteger; + partBlock.CatalogCount = blobCount; + partBlock.Kind = kNeFSHardDrive; + partBlock.SectorSize = sectorSz; + partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); + partBlock.SectorCount = fDiskDev.GetSectorsCount(); + partBlock.FreeSectors = fDiskDev.GetSectorsCount(); + partBlock.StartCatalog = kNeFSCatalogStartAddress; + partBlock.DiskSize = fDiskDev.GetDiskSize(); + partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; - partBlock.Version = kNeFSVersionInteger; - partBlock.CatalogCount = blobCount; - partBlock.Kind = kNeFSHardDrive; - partBlock.SectorSize = sectorSz; - partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); - partBlock.SectorCount = fDiskDev.GetSectorsCount(); - partBlock.FreeSectors = fDiskDev.GetSectorsCount(); - partBlock.StartCatalog = kNeFSCatalogStartAddress; - partBlock.DiskSize = fDiskDev.GetDiskSize(); - partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; + fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; + fDiskDev.Leak().mSize = sectorSz; - fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; + fDiskDev.Write((Char*)&partBlock, sectorSz); - fDiskDev.Write((Char*)&partBlock, sectorSz); + BOOT_BLOCK_STRUCT epmBoot{0}; - BOOT_BLOCK_STRUCT epmBoot{0}; + constexpr auto cFsName = "NeFS"; + constexpr auto cBlockName = "ZKA:"; - constexpr auto cFsName = "NeFS"; - constexpr auto cBlockName = "ZKA:"; + CopyMem(epmBoot.Fs, reinterpret_cast(const_cast(cFsName)), StrLen(cFsName)); - CopyMem(epmBoot.Fs, reinterpret_cast(const_cast(cFsName)), StrLen(cFsName)); + epmBoot.FsVersion = kNeFSVersionInteger; + epmBoot.LbaStart = kNeFSRootCatalogStartAddress; + epmBoot.SectorSz = partBlock.SectorSize; + epmBoot.Kind = kEPMNewOS; + epmBoot.NumBlocks = partBlock.CatalogCount; - epmBoot.FsVersion = kNeFSVersionInteger; - epmBoot.LbaStart = kNeFSRootCatalogStartAddress; - epmBoot.SectorSz = partBlock.SectorSize; - epmBoot.Kind = kEPMNewOS; - epmBoot.NumBlocks = partBlock.CatalogCount; + CopyMem(epmBoot.Name, reinterpret_cast(const_cast(cBlockName)), StrLen(cBlockName)); + CopyMem(epmBoot.Magic, reinterpret_cast(const_cast(kEPMMagic)), StrLen(kEPMMagic)); - CopyMem(epmBoot.Name, reinterpret_cast(const_cast(cBlockName)), StrLen(cBlockName)); - CopyMem(epmBoot.Magic, reinterpret_cast(const_cast(kEPMMagic)), StrLen(kEPMMagic)); + fDiskDev.Leak().mBase = 1; // always always resies at zero block. + fDiskDev.Leak().mSize = BootDev::kSectorSize; - fDiskDev.Leak().mBase = 1; // always always resies at zero block. - fDiskDev.Leak().mSize = BootDev::kSectorSize; + fDiskDev.Write((Char*)&epmBoot, sectorSz); - fDiskDev.Write((Char*)&epmBoot, sectorSz); + /// if we can write a root catalog, then write the partition block. + if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock)) + { + BTextWriter writer; + writer.Write(L"NEWOSLDR: Drive formatted.\r"); - /// if we can write a root catalog, then write the partition block. - if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock)) - { - BTextWriter writer; - writer.Write(L"NEWOSLDR: Drive formatted.\r"); + return true; + } + else + { + EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned."); + } - return true; - } - else - { - EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned."); + return false; } - - return false; -} +} // namespace Boot diff --git a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx index 2f802cc0..171fe371 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx @@ -21,6 +21,8 @@ /// bugs: 0 +using namespace Boot; + #define kATADataLen 256 static Boolean kATADetected = false; diff --git a/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx b/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx index 7c9fd042..3c71eaab 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx @@ -31,7 +31,7 @@ /*** @brief File Reader constructor. */ -BFileReader::BFileReader(const CharacterTypeUTF16* path, +Boot::BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandle) { if (path != nullptr) @@ -98,7 +98,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, mErrorCode = kOperationOkay; } -BFileReader::~BFileReader() +Boot::BFileReader::~BFileReader() { if (this->mFile) { @@ -126,7 +126,7 @@ BFileReader::~BFileReader() @param **readUntil** size of file @param **chunkToRead** chunk to read each time. */ -Void BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress) +Void Boot::BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress) { if (mBlob == nullptr) { @@ -183,21 +183,21 @@ Void BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress /// @brief error code getter. /// @return the error code. -Int32& BFileReader::Error() +Int32& Boot::BFileReader::Error() { return mErrorCode; } /// @brief blob getter. /// @return the blob. -VoidPtr BFileReader::Blob() +VoidPtr Boot::BFileReader::Blob() { return mBlob; } /// @breif Size getter. /// @return the size of the file. -UInt64& BFileReader::Size() +UInt64& Boot::BFileReader::Size() { return mSizeFile; } diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 55d93c29..0e7a9171 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -80,7 +80,7 @@ STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) } EXTERN_C VoidPtr boot_read_cr3(); -EXTERN_C Void boot_write_cr3(VoidPtr new_cr3); +EXTERN_C Void boot_write_cr3(VoidPtr new_cr3); EXTERN EfiBootServices* BS; @@ -159,7 +159,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; // Fill handover header now. - BDiskFormatFactory checkPart; + Boot::BDiskFormatFactory checkPart; // ---------------------------------------------------- // // The following checks for an exisiting partition @@ -169,7 +169,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, if (!checkPart.IsPartitionValid()) { - BDiskFormatFactory::BFileDescriptor root; + Boot::BDiskFormatFactory::BFileDescriptor root; root.fFileName[0] = kNeFSRoot[0]; root.fFileName[1] = 0; @@ -204,13 +204,22 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // Update handover file specific table and phyiscal start field. //-----------------------------------------------------------// - handover_hdr->f_BitMapStart = reinterpret_cast(kHandoverBitMapStart); /* # of pages */ - handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* # of pages */ + handover_hdr->f_BitMapStart = nullptr; /* # of pages */ + handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* # of pages */ + + while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) + { + if (handover_hdr->f_BitMapStart) + { + BS->FreePool(handover_hdr->f_BitMapStart); + handover_hdr->f_BitMapStart = nullptr; + } + } handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handover_hdr->f_FirmwareCustomTables[1] = (VoidPtr)ST; - BFileReader readerSysChk(L"syschk.sys", ImageHandle); + Boot::BFileReader readerSysChk(L"syschk.sys", ImageHandle); readerSysChk.ReadAll(0); Boot::BThread* loaderSysChk = nullptr; @@ -232,21 +241,21 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handover_hdr->f_FirmwareCustomTables[0] = nullptr; handover_hdr->f_FirmwareCustomTables[1] = nullptr; - handover_hdr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); + handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(SystemTable->FirmwareVendor); handover_hdr->f_Magic = kHandoverMagic; handover_hdr->f_Version = kHandoverVersion; // Provide fimware vendor name. - BCopyMem(handover_hdr->f_FirmwareVendorName, SystemTable->FirmwareVendor, + Boot::BCopyMem(handover_hdr->f_FirmwareVendorName, SystemTable->FirmwareVendor, handover_hdr->f_FirmwareVendorLen); - handover_hdr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); + handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(SystemTable->FirmwareVendor); // Assign to global 'kHandoverHeader'. - BFileReader readerKernel(L"newoskrnl.exe", ImageHandle); + Boot::BFileReader readerKernel(L"newoskrnl.exe", ImageHandle); readerKernel.ReadAll(0); @@ -268,9 +277,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, CGDrawString("NEWOSLDR: PLEASE RECOVER YOUR NEWOSKRNL KERNEL DLL.", 30, 10, RGB(0xFF, 0xFF, 0xFF)); } - BFileReader chimeWav(L"ZKA\\startup.wav", ImageHandle); - BFileReader readerSysDrv(L"ZKA\\startup.sys", ImageHandle); - BFileReader urbanistTTF(L"ZKA\\urbanist.ttf", ImageHandle); + Boot::BFileReader chimeWav(L"ZKA\\startup.wav", ImageHandle); + Boot::BFileReader readerSysDrv(L"ZKA\\startup.sys", ImageHandle); + Boot::BFileReader urbanistTTF(L"ZKA\\urbanist.ttf", ImageHandle); readerSysDrv.ReadAll(0); chimeWav.ReadAll(0); diff --git a/dev/ZBA/Sources/HEL/AMD64/BootPlatform.cxx b/dev/ZBA/Sources/HEL/AMD64/BootPlatform.cxx index c5218fe1..31566a95 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootPlatform.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootPlatform.cxx @@ -10,6 +10,8 @@ #ifdef __STANDALONE__ +using namespace Boot; + EXTERN_C void rt_hlt() { asm volatile("hlt"); diff --git a/dev/ZBA/Sources/HEL/AMD64/BootString.cxx b/dev/ZBA/Sources/HEL/AMD64/BootString.cxx index ad87bce2..1c109b80 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootString.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootString.cxx @@ -15,11 +15,11 @@ #include #include -/// bugs 0 +/// BUGS: 0 ///////////////////////////////////////////////////////////////////////////////////////////////////////// -Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len) +Kernel::SizeT Boot::BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len) { if (!dest || !src) return 0; @@ -33,7 +33,7 @@ Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const return index; } -Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr) +Kernel::SizeT Boot::BStrLen(const CharacterTypeUTF16* ptr) { if (!ptr) return 0; @@ -49,7 +49,7 @@ Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr) return cnt; } -Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len) +Kernel::SizeT Boot::BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len) { if (!src) return 0; @@ -70,7 +70,7 @@ Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, co return cnt; } -Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len) +Kernel::SizeT Boot::BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len) { if (!src) return 0; diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx index fdd9eba1..b0679715 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx @@ -23,7 +23,7 @@ /** @brief puts wrapper over EFI ConOut. */ -BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) +Boot::BTextWriter& Boot::BTextWriter::Write(const CharacterTypeUTF16* str) { #ifdef __DEBUG__ if (!str || *str == 0) @@ -55,7 +55,7 @@ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) /// @brief UTF-8 equivalent of Write (UTF-16). /// @param str the input string. -BTextWriter& BTextWriter::Write(const Char* str) +Boot::BTextWriter& Boot::BTextWriter::Write(const Char* str) { #ifdef __DEBUG__ if (!str || *str == 0) @@ -85,7 +85,7 @@ BTextWriter& BTextWriter::Write(const Char* str) return *this; } -BTextWriter& BTextWriter::Write(const UChar* str) +Boot::BTextWriter& Boot::BTextWriter::Write(const UChar* str) { #ifdef __DEBUG__ if (!str || *str == 0) @@ -118,7 +118,7 @@ BTextWriter& BTextWriter::Write(const UChar* str) /** @brief putc wrapper over EFI ConOut. */ -BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) +Boot::BTextWriter& Boot::BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { #ifdef __DEBUG__ EfiCharType str[2]; @@ -131,7 +131,7 @@ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) return *this; } -BTextWriter& BTextWriter::Write(const Long& x) +Boot::BTextWriter& Boot::BTextWriter::Write(const Long& x) { #ifdef __DEBUG__ this->_Write(x); @@ -141,7 +141,7 @@ BTextWriter& BTextWriter::Write(const Long& x) return *this; } -BTextWriter& BTextWriter::_Write(const Long& x) +Boot::BTextWriter& Boot::BTextWriter::_Write(const Long& x) { #ifdef __DEBUG__ UInt64 y = (x > 0 ? x : -x) / 16; diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx index c811e620..1f780fa2 100644 --- a/dev/ZBA/Sources/Thread.cxx +++ b/dev/ZBA/Sources/Thread.cxx @@ -153,7 +153,7 @@ namespace Boot HEL::HandoverProc err_fn = [](HEL::HANDOVER_INFO_HEADER* rcx) -> void { CGDrawString("NEWOSLDR: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); - EFI::Stop(); + ::EFI::Stop(); }; if (!fStartAddress) diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 41c038ae..a08ff725 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -23,8 +23,7 @@ #define kHandoverVersion 0x0117 /* Initial bitmap pointer location and size. */ -#define kHandoverBitMapStart (0x100000000) -#define kHandoverBitMapSz (gib_cast(4)) +#define kHandoverBitMapSz (gib_cast(3)) /* Executable base */ #define kHandoverExecBase (0x4000000) diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 4549021f..b38fb5ef 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -126,7 +126,9 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelBitMpStart, size, rw, user); if (!ptr_new) - return nullptr; + { + ke_stop(RUNTIME_CHECK_PAGE); + } if (rw) mm_map_page(ptr_new, eFlagsRw | eFlagsPresent); diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index b7dfee8a..ef743c20 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -86,7 +86,11 @@ EXTERN_C 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::NeFileSystemMgr::Mount(Kernel::mm_new_class()); + Kernel::NeFileSystemMgr* mgr = (Kernel::mm_new_class()); + Kernel::NeFileSystemMgr::Mount(mgr); + + delete (NFS_CATALOG_STRUCT*)mgr->CreateDirectory("\\Boot\\"); + delete (NFS_CATALOG_STRUCT*)mgr->CreateDirectory("\\Support\\"); mp_do_user_switch(); diff --git a/dev/ZKA/KernelKit/DriveMgr.hxx b/dev/ZKA/KernelKit/DriveMgr.hxx index 55c4912d..e2e0bc3a 100644 --- a/dev/ZKA/KernelKit/DriveMgr.hxx +++ b/dev/ZKA/KernelKit/DriveMgr.hxx @@ -63,6 +63,7 @@ namespace Kernel Void (*fInput)(DrivePacket* packetPtr); Void (*fOutput)(DrivePacket* packetPtr); Void (*fVerify)(DrivePacket* packetPtr); + Void (*fInit)(DrivePacket* packetPtr); const Char* (*fDriveKind)(Void); }; diff --git a/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx b/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx index ebd47ac9..153cb64f 100644 --- a/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx +++ b/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx @@ -47,7 +47,7 @@ namespace CG Size w_child_count{0}; struct UI_WINDOW_STRUCT* w_child_elements[cChildElementCount]{0}; struct UI_WINDOW_STRUCT* w_parent{nullptr}; - UInt32* display_ptr{nullptr}; + UInt32* w_display_ptr{nullptr}; Bool w_needs_repaint{false}; }; @@ -92,8 +92,8 @@ namespace CG wnd->w_w = width; wnd->w_h = height; - wnd->display_ptr = new UInt32[width * height]; - rt_set_memory(wnd->display_ptr, CGColor(0xF5, 0xF5, 0xF5), width * height); + wnd->w_display_ptr = new UInt32[width * height]; + rt_set_memory(wnd->w_display_ptr, CGColor(0xF5, 0xF5, 0xF5), width * height); return wnd; } @@ -182,7 +182,7 @@ namespace CG // Draw fake controls, just for the looks of it (WINDOW ONLY) if (wnd[index]->w_type == cWndFlagWindow) { - CGDrawBitMapInRegion(wnd[index]->display_ptr, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); + CGDrawBitMapInRegion(wnd[index]->w_display_ptr, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w, FLATCONTROLS_HEIGHT, wnd[index]->w_y, wnd[index]->w_x); if (wnd[index]->w_sub_type != cWndFlagHideCloseControl) diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx index 5d0f7fc3..82291ada 100644 --- a/dev/ZKA/Sources/DriveMgr.cxx +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -58,7 +58,7 @@ namespace Kernel /// @brief Executes a disk check on the ATA drive. /// @param pckt /// @return - Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) + Void ke_drv_init(DriveTrait::DrivePacket* pckt) { if (!pckt) { @@ -84,21 +84,21 @@ namespace Kernel /// @param /// @return #ifdef __ATA_PIO__ - const Char* io_drive_kind(Void) + const Char* ke_drv_kind(Void) { return "ATA-PIO"; } #endif #ifdef __ATA_DMA__ - const Char* io_drive_kind(Void) + const Char* ke_drv_kind(Void) { return "ATA-DMA"; } #endif #ifdef __AHCI__ - const Char* io_drive_kind(Void) + const Char* ke_drv_kind(Void) { return "AHCI"; } @@ -124,7 +124,8 @@ namespace Kernel trait.fInput = io_drv_unimplemented; trait.fOutput = io_drv_unimplemented; trait.fVerify = io_drv_unimplemented; - trait.fDriveKind = io_drive_kind; + trait.fInit = io_drv_unimplemented; + trait.fDriveKind = ke_drv_kind; return trait; } @@ -140,8 +141,9 @@ namespace Kernel trait.fInput = ke_drv_input; trait.fOutput = ke_drv_output; - trait.fVerify = ke_drv_check_disk; - trait.fDriveKind = io_drive_kind; + trait.fVerify = io_drv_unimplemented; + trait.fInit = ke_drv_init; + trait.fDriveKind = ke_drv_kind; kcout << "Construct drive with success.\r"; diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx index 9c33b78c..8bd467c6 100644 --- a/dev/ZKA/Sources/FS/NeFS.cxx +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -790,9 +790,13 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa { delete parentCatalog; } + else + { + return nullptr; + } } - kcout << "fetching catalog...\r"; + kcout << "Fetching catalog...\r"; NeFSSearchThroughCatalogList: while (drive.fPacket.fPacketGood) @@ -980,7 +984,7 @@ VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, if (dataForkLba < kNeFSCatalogStartAddress) { - delete[] fs_buf; + delete fs_buf; return nullptr; } @@ -1038,11 +1042,11 @@ namespace Kernel::Detail sMountpointInterface.C() = io_construct_drive(); sMountpointInterface.D() = io_construct_drive(); - kcout << "Testing A:\r"; + kcout << "Constructing A:\r"; - sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); + sMountpointInterface.A().fInit(&sMountpointInterface.A().fPacket); - kcout << "Testing A: [ OK ]\r"; + kcout << "Constructing A: [ OK ]\r"; return true; } diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index 833ac6de..4c316c0b 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -138,12 +138,6 @@ namespace Kernel Void RecoveryFactory::Recover() noexcept { - if (NeFileSystemMgr::GetMounted()) - { - NeFileSystemMgr::GetMounted()->CreateSwapFile("\\Boot\\$DUMP"); - NeFileSystemMgr::GetMounted()->CreateSwapFile("\\Support\\$CHKDSK"); - } - PowerFactoryInterface power(nullptr); power.Reboot(); } -- cgit v1.2.3