From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/zba/BootKit/BitManip.h | 20 +++ dev/zba/BootKit/BitManip.hxx | 20 --- dev/zba/BootKit/BootKit.h | 385 +++++++++++++++++++++++++++++++++++++++++++ dev/zba/BootKit/BootKit.hxx | 385 ------------------------------------------- dev/zba/BootKit/Device.h | 36 ++++ dev/zba/BootKit/Device.hxx | 36 ---- dev/zba/BootKit/EPM.h | 9 + dev/zba/BootKit/EPM.hxx | 9 - dev/zba/BootKit/HW/ATA.h | 58 +++++++ dev/zba/BootKit/HW/ATA.hxx | 58 ------- dev/zba/BootKit/HW/SATA.h | 46 ++++++ dev/zba/BootKit/HW/SATA.hxx | 46 ------ dev/zba/BootKit/Platform.h | 32 ++++ dev/zba/BootKit/Platform.hxx | 32 ---- dev/zba/BootKit/Protocol.h | 10 ++ dev/zba/BootKit/Protocol.hxx | 10 -- dev/zba/BootKit/STB.h | 27 +++ dev/zba/BootKit/STB.hxx | 27 --- dev/zba/BootKit/Support.h | 165 +++++++++++++++++++ dev/zba/BootKit/Support.hxx | 165 ------------------- dev/zba/BootKit/Thread.h | 42 +++++ dev/zba/BootKit/Thread.hxx | 42 ----- 22 files changed, 830 insertions(+), 830 deletions(-) create mode 100644 dev/zba/BootKit/BitManip.h delete mode 100644 dev/zba/BootKit/BitManip.hxx create mode 100644 dev/zba/BootKit/BootKit.h delete mode 100644 dev/zba/BootKit/BootKit.hxx create mode 100644 dev/zba/BootKit/Device.h delete mode 100644 dev/zba/BootKit/Device.hxx create mode 100644 dev/zba/BootKit/EPM.h delete mode 100644 dev/zba/BootKit/EPM.hxx create mode 100644 dev/zba/BootKit/HW/ATA.h delete mode 100644 dev/zba/BootKit/HW/ATA.hxx create mode 100644 dev/zba/BootKit/HW/SATA.h delete mode 100644 dev/zba/BootKit/HW/SATA.hxx create mode 100644 dev/zba/BootKit/Platform.h delete mode 100644 dev/zba/BootKit/Platform.hxx create mode 100644 dev/zba/BootKit/Protocol.h delete mode 100644 dev/zba/BootKit/Protocol.hxx create mode 100644 dev/zba/BootKit/STB.h delete mode 100644 dev/zba/BootKit/STB.hxx create mode 100644 dev/zba/BootKit/Support.h delete mode 100644 dev/zba/BootKit/Support.hxx create mode 100644 dev/zba/BootKit/Thread.h delete mode 100644 dev/zba/BootKit/Thread.hxx (limited to 'dev/zba/BootKit') diff --git a/dev/zba/BootKit/BitManip.h b/dev/zba/BootKit/BitManip.h new file mode 100644 index 00000000..ad893b02 --- /dev/null +++ b/dev/zba/BootKit/BitManip.h @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __BITMANIP_H__ +#define __BITMANIP_H__ + +/// Name: Bits API. +/// Purpose: Bit manip helpers, based on CoreBoot header. + +#define bk_set_bit(X, O) X = (1 << O) | X +#define bk_clear_bit(X, O) X = ~(1 << O) & X +#define bk_toogle(X, O) X = (1 << O) ^ X +#define bk_lsb(X) X = X & -X +#define bk_msb(X) X = -(mp_lsb(X)) & X +#define bk_look_for_bit(X, O) (1 << O) | X + +#endif // ifndef __BITMANIP_H__ diff --git a/dev/zba/BootKit/BitManip.hxx b/dev/zba/BootKit/BitManip.hxx deleted file mode 100644 index ad893b02..00000000 --- a/dev/zba/BootKit/BitManip.hxx +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#ifndef __BITMANIP_H__ -#define __BITMANIP_H__ - -/// Name: Bits API. -/// Purpose: Bit manip helpers, based on CoreBoot header. - -#define bk_set_bit(X, O) X = (1 << O) | X -#define bk_clear_bit(X, O) X = ~(1 << O) & X -#define bk_toogle(X, O) X = (1 << O) ^ X -#define bk_lsb(X) X = X & -X -#define bk_msb(X) X = -(mp_lsb(X)) & X -#define bk_look_for_bit(X, O) (1 << O) | X - -#endif // ifndef __BITMANIP_H__ diff --git a/dev/zba/BootKit/BootKit.h b/dev/zba/BootKit/BootKit.h new file mode 100644 index 00000000..dfba9728 --- /dev/null +++ b/dev/zba/BootKit/BootKit.h @@ -0,0 +1,385 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +/***********************************************************************************/ +/// @file Boot.h +/// @brief Bootloader Programming Interface. +/***********************************************************************************/ + +#pragma once + +#include +#include +#include + +/// include NeFS header and Support header as well. + +#include +#include + +/***********************************************************************************/ +/// Include other APIs. +/***********************************************************************************/ + +#include +#include + +#include + +/***********************************************************************************/ +/// Framebuffer helpers. +/***********************************************************************************/ + +namespace EFI +{ + extern void ThrowError(const WideChar* errorCode, + const WideChar* reason) noexcept; +} // namespace EFI + +namespace Boot +{ + class BTextWriter; + class BFileReader; + class BThread; + class BVersionString; + + typedef Char* PEFImagePtr; + typedef Char* PEImagePtr; + + typedef WideChar CharacterTypeUTF16; + typedef Char CharacterTypeUTF8; + + using namespace Kernel; + + /** + * @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; + }; + + Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len); + + Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len); + + /// String length functions. + + /// @brief get string length. + Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr); + + /// @brief set memory with custom value. + Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len); + + /** + * @brief BootKit File Reader class + * Reads the Firmware Boot partition and filesystem. + */ + class BFileReader final + { + public: + explicit BFileReader(const CharacterTypeUTF16* path, + EfiHandlePtr ImageHandle); + ~BFileReader(); + + public: + Void ReadAll(SizeT until, SizeT chunk = kib_cast(4), UIntPtr out_address = 0UL); + + 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; + + class BVersionString final + { + public: + static const CharacterTypeUTF8* The() + { + return BOOTLOADER_VERSION; + } + }; + + /***********************************************************************************/ + /// Provide some useful processor features. + /***********************************************************************************/ + +#ifdef __EFI_x86_64__ + + /*** + * 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 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; + +#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 + { + Char fFileName[kNeFSNodeNameLen]; + Int32 fKind; + }; + + public: + explicit BDiskFormatFactory() = default; + explicit BDiskFormatFactory(BootDev dev) + : fDiskDev(dev) + { + } + + ~BDiskFormatFactory() = default; + + 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 check if partition is good. + Bool IsPartitionValid() noexcept + { + fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); + fDiskDev.Leak().mSize = BootDev::kSectorSize; + + Char buf[BootDev::kSectorSize] = {0}; + + fDiskDev.Read(buf, BootDev::kSectorSize); + + NFS_ROOT_PARTITION_BLOCK* blockPart = reinterpret_cast(buf); + + BTextWriter writer; + + for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) + { + if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) + return false; + } + + 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: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); + + return true; + } + + 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; + + NFS_CATALOG_STRUCT catalogKind{0}; + + constexpr auto cNeFSCatalogPadding = 4; + + catalogKind.PrevSibling = startLba; + catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + + /// Fill catalog kind. + catalogKind.Kind = blob->fKind; + catalogKind.Flags = kNeFSFlagCreated; + + --partBlock.FreeCatalog; + --partBlock.FreeSectors; + + CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); + + fDiskDev.Leak().mBase = startLba; + fDiskDev.Leak().mSize = sizeof(NFS_CATALOG_STRUCT); + + fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT)); + + writer.Write(L"NEWOSLDR: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); + + return true; + } + + 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; + + /// @note A catalog roughly equal to a sector. + + constexpr auto cMinimumDiskSize = kNeFSMinimumDiskSize; // at minimum. + + /// @note also look at EPM headers, for free part blocks. + + if (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}; + + 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; + + fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; + fDiskDev.Leak().mSize = sectorSz; + + fDiskDev.Write((Char*)&partBlock, sectorSz); + + BOOT_BLOCK_STRUCT epmBoot{0}; + + constexpr auto cFsName = "NeFS"; + constexpr auto cBlockName = "ZKA:"; + + 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; + + 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.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"); + + return true; + } + else + { + EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned."); + } + + return false; + } +} // namespace Boot diff --git a/dev/zba/BootKit/BootKit.hxx b/dev/zba/BootKit/BootKit.hxx deleted file mode 100644 index f9a94c6e..00000000 --- a/dev/zba/BootKit/BootKit.hxx +++ /dev/null @@ -1,385 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -/***********************************************************************************/ -/// @file Boot.hxx -/// @brief Bootloader Programming Interface. -/***********************************************************************************/ - -#pragma once - -#include -#include -#include - -/// include NeFS header and Support header as well. - -#include -#include - -/***********************************************************************************/ -/// Include other APIs. -/***********************************************************************************/ - -#include -#include - -#include - -/***********************************************************************************/ -/// Framebuffer helpers. -/***********************************************************************************/ - -namespace EFI -{ - extern void ThrowError(const WideChar* errorCode, - const WideChar* reason) noexcept; -} // namespace EFI - -namespace Boot -{ - class BTextWriter; - class BFileReader; - class BThread; - class BVersionString; - - typedef Char* PEFImagePtr; - typedef Char* PEImagePtr; - - typedef WideChar CharacterTypeUTF16; - typedef Char CharacterTypeUTF8; - - using namespace Kernel; - - /** - * @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; - }; - - Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len); - - Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len); - - /// String length functions. - - /// @brief get string length. - Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr); - - /// @brief set memory with custom value. - Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len); - - /** - * @brief BootKit File Reader class - * Reads the Firmware Boot partition and filesystem. - */ - class BFileReader final - { - public: - explicit BFileReader(const CharacterTypeUTF16* path, - EfiHandlePtr ImageHandle); - ~BFileReader(); - - public: - Void ReadAll(SizeT until, SizeT chunk = kib_cast(4), UIntPtr out_address = 0UL); - - 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; - - class BVersionString final - { - public: - static const CharacterTypeUTF8* The() - { - return BOOTLOADER_VERSION; - } - }; - - /***********************************************************************************/ - /// Provide some useful processor features. - /***********************************************************************************/ - -#ifdef __EFI_x86_64__ - - /*** - * 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 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; - -#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 - { - Char fFileName[kNeFSNodeNameLen]; - Int32 fKind; - }; - - public: - explicit BDiskFormatFactory() = default; - explicit BDiskFormatFactory(BootDev dev) - : fDiskDev(dev) - { - } - - ~BDiskFormatFactory() = default; - - 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 check if partition is good. - Bool IsPartitionValid() noexcept - { - fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); - fDiskDev.Leak().mSize = BootDev::kSectorSize; - - Char buf[BootDev::kSectorSize] = {0}; - - fDiskDev.Read(buf, BootDev::kSectorSize); - - NFS_ROOT_PARTITION_BLOCK* blockPart = reinterpret_cast(buf); - - BTextWriter writer; - - for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) - { - if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) - return false; - } - - 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: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); - - return true; - } - - 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; - - NFS_CATALOG_STRUCT catalogKind{0}; - - constexpr auto cNeFSCatalogPadding = 4; - - catalogKind.PrevSibling = startLba; - catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); - - /// Fill catalog kind. - catalogKind.Kind = blob->fKind; - catalogKind.Flags = kNeFSFlagCreated; - - --partBlock.FreeCatalog; - --partBlock.FreeSectors; - - CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); - - fDiskDev.Leak().mBase = startLba; - fDiskDev.Leak().mSize = sizeof(NFS_CATALOG_STRUCT); - - fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT)); - - writer.Write(L"NEWOSLDR: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); - - return true; - } - - 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; - - /// @note A catalog roughly equal to a sector. - - constexpr auto cMinimumDiskSize = kNeFSMinimumDiskSize; // at minimum. - - /// @note also look at EPM headers, for free part blocks. - - if (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}; - - 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; - - fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; - - fDiskDev.Write((Char*)&partBlock, sectorSz); - - BOOT_BLOCK_STRUCT epmBoot{0}; - - constexpr auto cFsName = "NeFS"; - constexpr auto cBlockName = "ZKA:"; - - 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; - - 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.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"); - - return true; - } - else - { - EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned."); - } - - return false; - } -} // namespace Boot diff --git a/dev/zba/BootKit/Device.h b/dev/zba/BootKit/Device.h new file mode 100644 index 00000000..f6352b7b --- /dev/null +++ b/dev/zba/BootKit/Device.h @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include + +using namespace Kernel; + +/// @brief Device type. +class Device +{ +public: + explicit Device() = default; + virtual ~Device() = default; + + ZKA_MOVE_DEFAULT(Device); + + struct Trait + { + SizeT mBase{1024}; + SizeT mSize{1024}; + }; + + virtual Trait& Leak() = 0; + + virtual Device& Read(Char* Buf, const SizeT& SecCount) = 0; + virtual Device& Write(Char* Buf, const SizeT& SecCount) = 0; +}; + +typedef Device BootDevice; +typedef Device NetworkDevice; +typedef Device DiskDevice; diff --git a/dev/zba/BootKit/Device.hxx b/dev/zba/BootKit/Device.hxx deleted file mode 100644 index 7c6d9c4e..00000000 --- a/dev/zba/BootKit/Device.hxx +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include - -using namespace Kernel; - -/// @brief Device type. -class Device -{ -public: - explicit Device() = default; - virtual ~Device() = default; - - ZKA_MOVE_DEFAULT(Device); - - struct Trait - { - SizeT mBase{1024}; - SizeT mSize{1024}; - }; - - virtual Trait& Leak() = 0; - - virtual Device& Read(Char* Buf, const SizeT& SecCount) = 0; - virtual Device& Write(Char* Buf, const SizeT& SecCount) = 0; -}; - -typedef Device BootDevice; -typedef Device NetworkDevice; -typedef Device DiskDevice; diff --git a/dev/zba/BootKit/EPM.h b/dev/zba/BootKit/EPM.h new file mode 100644 index 00000000..df9754f1 --- /dev/null +++ b/dev/zba/BootKit/EPM.h @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include diff --git a/dev/zba/BootKit/EPM.hxx b/dev/zba/BootKit/EPM.hxx deleted file mode 100644 index 0dacba8b..00000000 --- a/dev/zba/BootKit/EPM.hxx +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include diff --git a/dev/zba/BootKit/HW/ATA.h b/dev/zba/BootKit/HW/ATA.h new file mode 100644 index 00000000..0bed397f --- /dev/null +++ b/dev/zba/BootKit/HW/ATA.h @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include + +using namespace Kernel; + +class BootDeviceATA final : public Device +{ +public: + enum + { + kPrimary = ATA_PRIMARY_IO, + kSecondary = ATA_SECONDARY_IO, + }; + + explicit BootDeviceATA() noexcept; + ~BootDeviceATA() = default; + + ZKA_COPY_DELETE(BootDeviceATA); + + enum + { + kSectorSize = kATASectorSize + }; + + struct ATATrait final : public Device::Trait + { + UInt16 mBus{kPrimary}; + UInt8 mMaster{0}; + Boolean mErr{false}; + + operator bool() + { + return !mErr; + } + }; + +public: + operator bool(); + + SizeT GetSectorsCount() noexcept; + SizeT GetDiskSize() noexcept; + + BootDeviceATA& Read(Char* Buf, const SizeT& SecCount) override; + BootDeviceATA& Write(Char* Buf, const SizeT& SecCount) override; + + ATATrait& Leak() override; + +private: + ATATrait mTrait; +}; diff --git a/dev/zba/BootKit/HW/ATA.hxx b/dev/zba/BootKit/HW/ATA.hxx deleted file mode 100644 index 84d03835..00000000 --- a/dev/zba/BootKit/HW/ATA.hxx +++ /dev/null @@ -1,58 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include - -using namespace Kernel; - -class BootDeviceATA final : public Device -{ -public: - enum - { - kPrimary = ATA_PRIMARY_IO, - kSecondary = ATA_SECONDARY_IO, - }; - - explicit BootDeviceATA() noexcept; - ~BootDeviceATA() = default; - - ZKA_COPY_DELETE(BootDeviceATA); - - enum - { - kSectorSize = kATASectorSize - }; - - struct ATATrait final : public Device::Trait - { - UInt16 mBus{kPrimary}; - UInt8 mMaster{0}; - Boolean mErr{false}; - - operator bool() - { - return !mErr; - } - }; - -public: - operator bool(); - - SizeT GetSectorsCount() noexcept; - SizeT GetDiskSize() noexcept; - - BootDeviceATA& Read(Char* Buf, const SizeT& SecCount) override; - BootDeviceATA& Write(Char* Buf, const SizeT& SecCount) override; - - ATATrait& Leak() override; - -private: - ATATrait mTrait; -}; diff --git a/dev/zba/BootKit/HW/SATA.h b/dev/zba/BootKit/HW/SATA.h new file mode 100644 index 00000000..3154e99b --- /dev/null +++ b/dev/zba/BootKit/HW/SATA.h @@ -0,0 +1,46 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include + +class BootDeviceSATA final +{ +public: + explicit BootDeviceSATA() noexcept; + ~BootDeviceSATA() = default; + + ZKA_COPY_DEFAULT(BootDeviceSATA); + + struct SATATrait final + { + Kernel::SizeT mBase{1024}; + Kernel::Boolean mErr{false}; + Kernel::Boolean mDetected{false}; + + operator bool() + { + return !this->mErr; + } + }; + + operator bool() + { + return this->Leak().mDetected; + } + + BootDeviceSATA& Read(Kernel::WideChar* Buf, const Kernel::SizeT& SecCount); + BootDeviceSATA& Write(Kernel::WideChar* Buf, const Kernel::SizeT& SecCount); + + SATATrait& Leak(); + +private: + SATATrait mTrait; +}; + +#define kAHCISectorSz 4096 diff --git a/dev/zba/BootKit/HW/SATA.hxx b/dev/zba/BootKit/HW/SATA.hxx deleted file mode 100644 index d0f7a3b5..00000000 --- a/dev/zba/BootKit/HW/SATA.hxx +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include - -class BootDeviceSATA final -{ -public: - explicit BootDeviceSATA() noexcept; - ~BootDeviceSATA() = default; - - ZKA_COPY_DEFAULT(BootDeviceSATA); - - struct SATATrait final - { - Kernel::SizeT mBase{1024}; - Kernel::Boolean mErr{false}; - Kernel::Boolean mDetected{false}; - - operator bool() - { - return !this->mErr; - } - }; - - operator bool() - { - return this->Leak().mDetected; - } - - BootDeviceSATA& Read(Kernel::WideChar* Buf, const Kernel::SizeT& SecCount); - BootDeviceSATA& Write(Kernel::WideChar* Buf, const Kernel::SizeT& SecCount); - - SATATrait& Leak(); - -private: - SATATrait mTrait; -}; - -#define kAHCISectorSz 4096 diff --git a/dev/zba/BootKit/Platform.h b/dev/zba/BootKit/Platform.h new file mode 100644 index 00000000..e778223b --- /dev/null +++ b/dev/zba/BootKit/Platform.h @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +/** + @file Platform.h + @brief Platform specific code. +*/ + +#ifdef __x86_64__ + +#ifdef __cplusplus +#ifndef EXTERN_C +#define EXTERN_C extern "C" +#endif +#else +#ifndef EXTERN_C +#define EXTERN_C extern +#endif +#endif // __cplusplus + +EXTERN_C void rt_halt(); +EXTERN_C void rt_cli(); +EXTERN_C void rt_sti(); +EXTERN_C void rt_cld(); +EXTERN_C void rt_std(); + +#endif /* ifdef __x86_64__ */ diff --git a/dev/zba/BootKit/Platform.hxx b/dev/zba/BootKit/Platform.hxx deleted file mode 100644 index 0ed6d047..00000000 --- a/dev/zba/BootKit/Platform.hxx +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -/** - @file Platform.hxx - @brief Platform specific code. -*/ - -#ifdef __x86_64__ - -#ifdef __cplusplus -#ifndef EXTERN_C -#define EXTERN_C extern "C" -#endif -#else -#ifndef EXTERN_C -#define EXTERN_C extern -#endif -#endif // __cplusplus - -EXTERN_C void rt_halt(); -EXTERN_C void rt_cli(); -EXTERN_C void rt_sti(); -EXTERN_C void rt_cld(); -EXTERN_C void rt_std(); - -#endif /* ifdef __x86_64__ */ diff --git a/dev/zba/BootKit/Protocol.h b/dev/zba/BootKit/Protocol.h new file mode 100644 index 00000000..82ef1140 --- /dev/null +++ b/dev/zba/BootKit/Protocol.h @@ -0,0 +1,10 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include diff --git a/dev/zba/BootKit/Protocol.hxx b/dev/zba/BootKit/Protocol.hxx deleted file mode 100644 index 537fea94..00000000 --- a/dev/zba/BootKit/Protocol.hxx +++ /dev/null @@ -1,10 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include diff --git a/dev/zba/BootKit/STB.h b/dev/zba/BootKit/STB.h new file mode 100644 index 00000000..7b8d6f3d --- /dev/null +++ b/dev/zba/BootKit/STB.h @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#define STBI_NO_STDIO 1 +#define STBI_NO_SIMD 1 +#define STBI_NO_THREAD_LOCALS 1 +#define STBI_NO_LINEAR 1 + +#define STBI_ONLY_PNG 1 +#define STBI_ONLY_JPEG 1 +#define STBI_ONLY_BMP 1 +#define STBI_ONLY_GIF 1 + +#define STBI_ASSERT(x) MUST_PASS(x) +#define STBI_MALLOC(x) Kernel::mm_new_heap(x, true, true) +#define STBI_REALLOC(p, x) Kernel::mm_realloc_heap(p, x); +#define STBI_FREE(x) Kernel::mm_delete_heap(x) +#define STB_IMAGE_IMPLEMENTATION 1 + +#include + +#include diff --git a/dev/zba/BootKit/STB.hxx b/dev/zba/BootKit/STB.hxx deleted file mode 100644 index 1f47fdfb..00000000 --- a/dev/zba/BootKit/STB.hxx +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#define STBI_NO_STDIO 1 -#define STBI_NO_SIMD 1 -#define STBI_NO_THREAD_LOCALS 1 -#define STBI_NO_LINEAR 1 - -#define STBI_ONLY_PNG 1 -#define STBI_ONLY_JPEG 1 -#define STBI_ONLY_BMP 1 -#define STBI_ONLY_GIF 1 - -#define STBI_ASSERT(x) MUST_PASS(x) -#define STBI_MALLOC(x) Kernel::mm_new_heap(x, true, true) -#define STBI_REALLOC(p, x) Kernel::mm_realloc_heap(p, x); -#define STBI_FREE(x) Kernel::mm_delete_heap(x) -#define STB_IMAGE_IMPLEMENTATION 1 - -#include - -#include diff --git a/dev/zba/BootKit/Support.h b/dev/zba/BootKit/Support.h new file mode 100644 index 00000000..99fe0cb0 --- /dev/null +++ b/dev/zba/BootKit/Support.h @@ -0,0 +1,165 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +/// @file Support.h +/// @brief Purpose of this file is to help port libs into the bootloader. + +#define cLongMax ((long)(~0UL >> 1)) +#define cLongMin (~cLongMax) + +#ifdef __NEWOSLDR__ + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. +EXTERN_C void* memset(void* dst, int byte, long long unsigned int len); + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len); + +/// @brief strlen definition in C++. +EXTERN_C size_t strlen(const char* whatToCheck); + +/// @brief strcmp definition in C++. +EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight); + +#define SetMem(dst, c, sz) memset(dst, c, sz) +#define MoveMem(dst, src, sz) memcpy(dst, src, sz) +#define CopyMem(dst, src, sz) memcpy(dst, src, sz) +#define StrLen(src) strlen(src) +#define StrCmp(dst, src) strcmp(dst, src) + +#endif // __NEWOSLDR__ + +inline int IsSpace(int c) +{ + return c == ' '; +} + +inline int StringNCompare(const char* destination, const char* source, long length) +{ + long err = 0; + + for (long i = 0UL; i < length; ++i) + { + if (source[i] != destination[i]) + ++err; + } + + return err; +} + +inline long StringToLong(const char* nptr, char** endptr, int base) +{ + const char *p = nptr, *endp; + bool is_neg = 0, overflow = 0; + + /* Need unsigned so (-cLongMin) can fit in these: */ + unsigned long n = 0UL, cutoff; + int cutlim; + + if (base < 0 || base == 1 || base > 36) + { + return 0L; + } + + endp = nptr; + + while (IsSpace(*p)) + p++; + + if (*p == '+') + { + p++; + } + else if (*p == '-') + { + is_neg = 1, p++; + } + if (*p == '0') + { + p++; + /* For strtol(" 0xZ", &endptr, 16), endptr should point to 'x'; + * pointing to ' ' or '0' is non-compliant. + * (Many implementations do this wrong.) */ + endp = p; + if (base == 16 && (*p == 'X' || *p == 'x')) + { + p++; + } + else if (base == 2 && (*p == 'B' || *p == 'b')) + { + /* C23 standard supports "0B" and "0b" prefixes. */ + p++; + } + else if (base == 0) + { + if (*p == 'X' || *p == 'x') + { + base = 16, p++; + } + else if (*p == 'B' || *p == 'b') + { + base = 2, p++; + } + else + { + base = 8; + } + } + } + else if (base == 0) + { + base = 10; + } + + cutoff = (is_neg) ? -(cLongMin / base) : cLongMax / base; + cutlim = (is_neg) ? -(cLongMin % base) : cLongMax % base; + + while (1) + { + int c; + if (*p >= 'A') + c = ((*p - 'A') & (~('a' ^ 'A'))) + 10; + else if (*p <= '9') + c = *p - '0'; + else + break; + if (c < 0 || c >= base) + break; + endp = ++p; + if (overflow) + { + /* endptr should go forward and point to the non-digit character + * (of the given base); required by ANSI standard. */ + if (endptr) + continue; + break; + } + if (n > cutoff || (n == cutoff && c > cutlim)) + { + overflow = 1; + continue; + } + n = n * base + c; + } + + if (endptr) + *endptr = (char*)endp; + + if (overflow) + { + return ((is_neg) ? cLongMin : cLongMax); + } + + return (long)((is_neg) ? -n : n); +} diff --git a/dev/zba/BootKit/Support.hxx b/dev/zba/BootKit/Support.hxx deleted file mode 100644 index 44ba5299..00000000 --- a/dev/zba/BootKit/Support.hxx +++ /dev/null @@ -1,165 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -/// @file Support.hxx -/// @brief Purpose of this file is to help port libs into the bootloader. - -#define cLongMax ((long)(~0UL >> 1)) -#define cLongMin (~cLongMax) - -#ifdef __NEWOSLDR__ - -/// @brief memset definition in C++. -/// @param dst destination pointer. -/// @param byte value to fill in. -/// @param len length of of src. -EXTERN_C void* memset(void* dst, int byte, long long unsigned int len); - -/// @brief memcpy definition in C++. -/// @param dst destination pointer. -/// @param src source pointer. -/// @param len length of of src. -EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len); - -/// @brief strlen definition in C++. -EXTERN_C size_t strlen(const char* whatToCheck); - -/// @brief strcmp definition in C++. -EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight); - -#define SetMem(dst, c, sz) memset(dst, c, sz) -#define MoveMem(dst, src, sz) memcpy(dst, src, sz) -#define CopyMem(dst, src, sz) memcpy(dst, src, sz) -#define StrLen(src) strlen(src) -#define StrCmp(dst, src) strcmp(dst, src) - -#endif // __NEWOSLDR__ - -inline int IsSpace(int c) -{ - return c == ' '; -} - -inline int StringNCompare(const char* destination, const char* source, long length) -{ - long err = 0; - - for (long i = 0UL; i < length; ++i) - { - if (source[i] != destination[i]) - ++err; - } - - return err; -} - -inline long StringToLong(const char* nptr, char** endptr, int base) -{ - const char *p = nptr, *endp; - bool is_neg = 0, overflow = 0; - - /* Need unsigned so (-cLongMin) can fit in these: */ - unsigned long n = 0UL, cutoff; - int cutlim; - - if (base < 0 || base == 1 || base > 36) - { - return 0L; - } - - endp = nptr; - - while (IsSpace(*p)) - p++; - - if (*p == '+') - { - p++; - } - else if (*p == '-') - { - is_neg = 1, p++; - } - if (*p == '0') - { - p++; - /* For strtol(" 0xZ", &endptr, 16), endptr should point to 'x'; - * pointing to ' ' or '0' is non-compliant. - * (Many implementations do this wrong.) */ - endp = p; - if (base == 16 && (*p == 'X' || *p == 'x')) - { - p++; - } - else if (base == 2 && (*p == 'B' || *p == 'b')) - { - /* C23 standard supports "0B" and "0b" prefixes. */ - p++; - } - else if (base == 0) - { - if (*p == 'X' || *p == 'x') - { - base = 16, p++; - } - else if (*p == 'B' || *p == 'b') - { - base = 2, p++; - } - else - { - base = 8; - } - } - } - else if (base == 0) - { - base = 10; - } - - cutoff = (is_neg) ? -(cLongMin / base) : cLongMax / base; - cutlim = (is_neg) ? -(cLongMin % base) : cLongMax % base; - - while (1) - { - int c; - if (*p >= 'A') - c = ((*p - 'A') & (~('a' ^ 'A'))) + 10; - else if (*p <= '9') - c = *p - '0'; - else - break; - if (c < 0 || c >= base) - break; - endp = ++p; - if (overflow) - { - /* endptr should go forward and point to the non-digit character - * (of the given base); required by ANSI standard. */ - if (endptr) - continue; - break; - } - if (n > cutoff || (n == cutoff && c > cutlim)) - { - overflow = 1; - continue; - } - n = n * base + c; - } - - if (endptr) - *endptr = (char*)endp; - - if (overflow) - { - return ((is_neg) ? cLongMin : cLongMax); - } - - return (long)((is_neg) ? -n : n); -} diff --git a/dev/zba/BootKit/Thread.h b/dev/zba/BootKit/Thread.h new file mode 100644 index 00000000..6923854b --- /dev/null +++ b/dev/zba/BootKit/Thread.h @@ -0,0 +1,42 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Boot +{ + using namespace Kernel; + + class BThread; + + /// @brief Program loader class + /// @package nl.zeta.boot.api + class BThread final + { + public: + explicit BThread() = delete; + ~BThread() = default; + + explicit BThread(Kernel::VoidPtr blob); + + BThread& operator=(const BThread&) = default; + BThread(const BThread&) = default; + + void Start(HEL::HANDOVER_INFO_HEADER* handover); + const char* GetName(); + void SetName(const char* name); + bool IsValid(); + + private: + Char fBlobName[255] = {"BootThread"}; + VoidPtr fStartAddress{nullptr}; + VoidPtr fBlob{nullptr}; + }; +} // namespace Boot diff --git a/dev/zba/BootKit/Thread.hxx b/dev/zba/BootKit/Thread.hxx deleted file mode 100644 index 25a3b544..00000000 --- a/dev/zba/BootKit/Thread.hxx +++ /dev/null @@ -1,42 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Boot -{ - using namespace Kernel; - - class BThread; - - /// @brief Program loader class - /// @package nl.zeta.boot.api - class BThread final - { - public: - explicit BThread() = delete; - ~BThread() = default; - - explicit BThread(Kernel::VoidPtr blob); - - BThread& operator=(const BThread&) = default; - BThread(const BThread&) = default; - - void Start(HEL::HANDOVER_INFO_HEADER* handover); - const char* GetName(); - void SetName(const char* name); - bool IsValid(); - - private: - Char fBlobName[255] = {"BootThread"}; - VoidPtr fStartAddress{nullptr}; - VoidPtr fBlob{nullptr}; - }; -} // namespace Boot -- cgit v1.2.3