diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-18 12:35:19 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-18 12:39:24 +0100 |
| commit | 4c714f2c24c5df78bae2f35c42c73107de4c8c71 (patch) | |
| tree | b36d2498b8387909dac45c98097b8169636ad25a /Private | |
| parent | a4bfc396a78ddd553de519ab927d8479d0c3c45d (diff) | |
unstable, unrelated: See below.
- :boom: Breaking changes in System.Core.dll
- Framebuffer, moved operator bool into c++ source file.
- Remove zlib in favor of our own Zip API.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private')
29 files changed, 295 insertions, 312 deletions
diff --git a/Private/FSKit/HCFS.hxx b/Private/FSKit/HCFS.hxx index 90285bd9..2d7e5627 100644 --- a/Private/FSKit/HCFS.hxx +++ b/Private/FSKit/HCFS.hxx @@ -8,6 +8,11 @@ #pragma once +/** + @brief HCore File System. + @author Amlal EL Mahrouss +*/ + #include <NewKit/Defines.hpp> #include <FirmwareKit/EPM.hxx> diff --git a/Private/FSKit/IndexableProperty.hxx b/Private/FSKit/IndexableProperty.hxx index 36416c82..86bacfdf 100644 --- a/Private/FSKit/IndexableProperty.hxx +++ b/Private/FSKit/IndexableProperty.hxx @@ -8,7 +8,7 @@ #include <CFKit/Property.hpp> #include <CompilerKit/CompilerKit.hxx> -#include <KernelKit/DriveManager.hpp> +#include <KernelKit/DriveManager.hxx> namespace HCore { namespace Indexer { diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 8632e650..b82bde9e 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -17,11 +17,12 @@ #include <CompilerKit/CompilerKit.hxx> #include <HintKit/CompilerHint.hxx> -#include <KernelKit/DriveManager.hpp> +#include <KernelKit/DriveManager.hxx> #include <NewKit/Defines.hpp> /** - @brief HCore File System implementation. + @brief New File System. + @author Amlal EL Mahrouss */ #define kNewFSInvalidFork -1 @@ -111,6 +112,7 @@ struct PACKED NewBootBlock final { NewCharType Pad[kNewFSPadLen]; }; +/// @brief File catalog type. struct PACKED NewCatalog final { NewCharType Name[kNewFSNodeNameLen]; @@ -124,6 +126,7 @@ struct PACKED NewCatalog final { HCore::Lba PrevSibling; }; +/// @brief File fork type. struct PACKED NewFork final { NewCharType Name[kNewFSNodeNameLen]; @@ -141,6 +144,7 @@ struct PACKED NewFork final { HCore::Lba PreviousSibling; }; +/// @brief Partition block type struct PACKED NewPartitionBlock final { NewCharType Ident[kNewFSIdentLen]; NewCharType PartitionName[kPartLen]; @@ -198,12 +202,13 @@ class NewFSParser { virtual bool WriteCatalog(_Input _Output NewCatalog& catalog, voidPtr data) = 0; + virtual bool RemoveCatalog(_Input _Output NewCatalog& catalog) = 0; /// @brief Make a EPM+NewFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see DbgLastError(). - virtual bool Format(_Input _Output DriveTraits& drive) = 0; + virtual bool Format(_Input _Output DriveTrait& drive) = 0; }; /// diff --git a/Private/HALKit/AMD64/HalDebugPort.cxx b/Private/HALKit/AMD64/HalDebugPort.cxx index b8127b1a..df3fc6e9 100644 --- a/Private/HALKit/AMD64/HalDebugPort.cxx +++ b/Private/HALKit/AMD64/HalDebugPort.cxx @@ -13,7 +13,7 @@ // after that we have start of additional data. namespace HCore { -void rt_debug_listen(DebuggerPorts* theHook) noexcept { +void rt_debug_listen(DebuggerPortHeader* theHook) noexcept { if (theHook == nullptr) return; for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) { diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index a2355cd8..88ed2448 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -96,7 +96,7 @@ inline TerminalDevice get_console_in(Char* buf) { typedef Char rt_debug_type[255]; -class DebuggerPorts final { +class DebuggerPortHeader final { public: Int16 fPort[kDebugMaxPorts]; Int16 fBoundCnt; diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hxx index 027c9391..abca0ad3 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hxx @@ -33,30 +33,34 @@ enum { typedef Int64 rt_drive_id_type; -/// @brief Mounted drive traits. -struct DriveTraits final { +/// @brief Media drive trait type. +struct DriveTrait final { Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. rt_drive_id_type fId; // Drive id. Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive - //! for StorageKit. + /// @brief Packet drive (StorageKit compilant.) struct DrivePacket final { - voidPtr fPacketContent; // packet body. - Char fPacketMime[32]; //! identify what we're sending. + VoidPtr fPacketContent; // packet body. + Char fPacketMime[kDriveNameLen]; //! identify what we're sending. SizeT fPacketSize; // packet size UInt32 fPacketCRC32; // sanity crc, in case if good is set to false Boolean fPacketGood; } fPacket; + + Void (*fInput)(DrivePacket* packetPtr); + Void (*fOutput)(DrivePacket* packetPtr); + Void (*fVerify)(DrivePacket* packetPtr); }; -#define kPacketBinary "file/x-binary" -#define kPacketSource "file/x-source" -#define kPacketASCII "file/x-ascii" -#define kPacketZip "file/x-zip" +#define kDrivePacketBinary "file/x-binary" +#define kDrivePacketSource "file/x-source" +#define kDrivePacketASCII "file/x-ascii" +#define kDrivePacketZip "file/x-zip" //! drive as a device. -typedef DeviceInterface<DriveTraits> DriveDevice; +typedef DeviceInterface<DriveTrait> DriveDevice; typedef DriveDevice* DriveDevicePtr; /** diff --git a/Private/KernelKit/Framebuffer.hpp b/Private/KernelKit/Framebuffer.hpp index 2847efb0..daf95ed0 100644 --- a/Private/KernelKit/Framebuffer.hpp +++ b/Private/KernelKit/Framebuffer.hpp @@ -28,7 +28,7 @@ class FramebufferContext final { class Framebuffer final { public: - Framebuffer(Ref<FramebufferContext *> &addr) : m_FrameBufferAddr(addr) {} + explicit Framebuffer(Ref<FramebufferContext *> &addr) : m_FrameBufferAddr(addr) {} ~Framebuffer() {} Framebuffer &operator=(const Framebuffer &) = delete; @@ -36,10 +36,8 @@ class Framebuffer final { volatile UIntPtr *operator[](const UIntPtr &pos); - operator bool() { - return m_FrameBufferAddr && m_Colour != FramebufferColorKind::INVALID; - } - + operator bool(); + const FramebufferColorKind &Color( const FramebufferColorKind &colour = FramebufferColorKind::INVALID); diff --git a/Private/KernelKit/PEFSharedObject.hxx b/Private/KernelKit/PEFSharedObject.hxx index becac43e..0684b2a7 100644 --- a/Private/KernelKit/PEFSharedObject.hxx +++ b/Private/KernelKit/PEFSharedObject.hxx @@ -25,7 +25,7 @@ extern "C" void __mh_purecall(void); */ class SharedObject final { public: - struct SharedObjectTraits final { + struct SharedObjectTrait final { VoidPtr fImageObject; VoidPtr fImageEntrypointOffset; }; @@ -38,15 +38,15 @@ class SharedObject final { HCORE_COPY_DEFAULT(SharedObject); private: - SharedObjectTraits *fMounted{nullptr}; + SharedObjectTrait *fMounted{nullptr}; public: - SharedObjectTraits **GetAddressOf() { return &fMounted; } + SharedObjectTrait **GetAddressOf() { return &fMounted; } - SharedObjectTraits *Get() { return fMounted; } + SharedObjectTrait *Get() { return fMounted; } public: - void Mount(SharedObjectTraits *to_mount) { + void Mount(SharedObjectTrait *to_mount) { if (!to_mount || !to_mount->fImageObject) return; fMounted = to_mount; diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/Arch/ATA.hxx index 74bdc630..5493b29f 100644 --- a/Private/NewBoot/BootKit/Arch/ATA.hxx +++ b/Private/NewBoot/BootKit/Arch/ATA.hxx @@ -20,7 +20,7 @@ class BDeviceATA final { HCORE_COPY_DEFAULT(BDeviceATA); - struct ATATraits final { + struct ATATrait final { SizeT mBase{1024}; UInt16 mBus{kPrimary}; UInt8 mMaster{0}; @@ -34,10 +34,10 @@ class BDeviceATA final { BDeviceATA& Read(WideChar* Buf, const SizeT& SecCount); BDeviceATA& Write(WideChar* Buf, const SizeT& SecCount); - ATATraits& Leak(); + ATATrait& Leak(); private: - ATATraits mTraits; + ATATrait mTrait; }; enum { diff --git a/Private/NewBoot/BootKit/Arch/SATA.hxx b/Private/NewBoot/BootKit/Arch/SATA.hxx index 409601ec..dc48c3ea 100644 --- a/Private/NewBoot/BootKit/Arch/SATA.hxx +++ b/Private/NewBoot/BootKit/Arch/SATA.hxx @@ -16,7 +16,7 @@ class BDeviceSATA final { HCORE_COPY_DEFAULT(BDeviceSATA); - struct AHCITraits final { + struct SATATrait final { HCore::SizeT mBase{1024}; HCore::Boolean mErr{false}; HCore::Boolean mDetected{false}; @@ -29,10 +29,10 @@ class BDeviceSATA final { BDeviceSATA& Read(HCore::WideChar* Buf, const HCore::SizeT& SecCount); BDeviceSATA& Write(HCore::WideChar* Buf, const HCore::SizeT& SecCount); - AHCITraits& Leak(); + SATATrait& Leak(); private: - AHCITraits mTraits; + SATATrait mTrait; }; #define kAHCISectorSz 4096 diff --git a/Private/NewBoot/CxxRuntime/UnwindCxxKit.cxx b/Private/NewBoot/CxxRuntime/UnwindCxxKit.cxx index 551cb599..c6e09fe2 100644 --- a/Private/NewBoot/CxxRuntime/UnwindCxxKit.cxx +++ b/Private/NewBoot/CxxRuntime/UnwindCxxKit.cxx @@ -23,7 +23,7 @@ EXTERN_C void __unwind(void (**finis)(void), int cnt) EXTERN_C Int32 EfiMain(EfiHandlePtr handle, EfiSystemTable* SystemTable) { - SystemTable->ConOut->OutputString(SystemTable->ConOut, L"HCoreLdr: C++ Runtime Add-in\r\n"); + SystemTable->ConOut->OutputString(SystemTable->ConOut, L"NewBoot: C++ Runtime Add-in\r\n"); return kEfiOk; }
\ No newline at end of file diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx deleted file mode 100644 index c0412797..00000000 --- a/Private/NewBoot/Source/BootMain.cxx +++ /dev/null @@ -1,220 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include <BootKit/BootKit.hxx> -#include <KernelKit/MSDOS.hpp> -#include <KernelKit/PE.hpp> -#include <NewKit/Ref.hpp> - -#ifdef __x86_64__ -#include <HALKit/AMD64/HalPageAlloc.hpp> -#else -#error This CPU is unknown. -#endif // ifdef __x86_64__ - -#ifndef kBootKrnlSections -#error [NewBoot/HCoreLdr] Please provide the amount of sections the kernel has. -#endif // !kBootKrnlSections - -#define kBootReadSize \ - (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader)) - -EXTERN_C void Main(HEL::HandoverInformationHeader* HIH); - -typedef void (*bt_main_type)(HEL::HandoverInformationHeader* HIH); - -EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, - EfiSystemTable* SystemTable) { - InitEFI(SystemTable); // Init the efi library. - InitGOP(); // Quick Toolkit for UI - - BTextWriter writer; - - /// Splash screen stuff - - writer.Write(L"MahroussLogic (R) HCoreLdr: ") - .Write(BVersionString::Shared()).Write(L"\r\n"); - - const char strDate[] = __DATE__; - - writer.Write(L"HCoreLdr: Build: "); - - for (auto& ch : strDate) writer.WriteCharacter(ch); - - writer.Write(L"\r\nHCoreLdr: Firmware Vendor: ") - .Write(SystemTable->FirmwareVendor) - .Write(L"\r\n"); - - /// Read Kernel blob. - - BFileReader kernelImg(L"HCOREKRNL.EXE", ImageHandle); - - kernelImg.Size(kBootReadSize); - kernelImg.ReadAll(); - - if (kernelImg.Error() == BFileReader::kOperationOkay) { - BlobType blob = (BlobType)kernelImg.Blob(); - - ExecHeaderPtr ptrHdr = reinterpret_cast<ExecHeaderPtr>( - HCore::rt_find_exec_header(reinterpret_cast<DosHeaderPtr>(blob))); - - if (ptrHdr && ptrHdr->mMachine == EFI::Platform() && - ptrHdr->mMagic == kPeMagic) { - /// sections must be at least 3. - if (ptrHdr->mNumberOfSections == kBootKrnlSections) { - ExecOptionalHeaderPtr optHdr = reinterpret_cast<ExecOptionalHeaderPtr>( - (UIntPtr)&ptrHdr->mCharacteristics + 1); - - // first check for kernel.cfg inside ESP/EPM. - BFileReader systemIni(L"KERNEL.CFG", ImageHandle); - - systemIni.Size(1); - systemIni.ReadAll(); - - bt_main_type kernelMain = - (bt_main_type)(UIntPtr)optHdr->mAddressOfEntryPoint; - - SizeT heapSize = optHdr->mSizeOfHeapReserve; - SizeT stackSize = optHdr->mSizeOfStackReserve; - - UInt64 posSeek = 0; - - // load sections here - - kernelImg.File()->SetPosition(kernelImg.File(), &posSeek); - kernelImg.Size(kBootReadSize + - ptrHdr->mNumberOfSections * sizeof(ExecSectionHeader)); - - kernelImg.ReadAll(); - - writer.Write(L"HCoreLdr: Number of sections: ") - .Write(ptrHdr->mNumberOfSections) - .Write(L"\r\n"); - writer.Write(L"HCoreLdr: Size of sections: ") - .Write(ptrHdr->mNumberOfSections * sizeof(ExecSectionHeader)) - .Write(L"\r\n"); - - ExecSectionHeader* blobKrnl = - (ExecSectionHeader*)(&optHdr + sizeof(ExecOptionalHeader) + sizeof(UInt32)); - - for (size_t i = 0; i < ptrHdr->mNumberOfSections; i++) { - // TODO: parse PE information here. - } - - UInt32 MapKey = 0; - UInt32* Size; - EfiMemoryDescriptor* Descriptor; - UInt32 SzDesc = 0; - UInt32 RevDesc = 0; - - if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&Size) != - kEfiOk) { - EFI::RaiseHardError( - L"HCoreLdr-BadAlloc", - L"The bootloader ran out of memory! Please check your specs."); - } - - /**** - * - * Load kernel into memory. - * - */ - - *Size = sizeof(EfiMemoryDescriptor); - - if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor), - (VoidPtr*)&Descriptor) != kEfiOk) { - EFI::RaiseHardError( - L"HCoreLdr-BadAlloc", - L"The bootloader ran out of memory! Please check your specs."); - } - - /**** - * - * Get machine memory map. - * - */ - - if (BS->GetMemoryMap(Size, Descriptor, &MapKey, &SzDesc, &RevDesc) != - kEfiOk) { - EFI::RaiseHardError( - L"HCoreLdr-GetMemoryMap", - L"GetMemoryMap returned a value which isn't kEfiOk!"); - } - -#ifndef __DEBUG__ - ST->ConOut->ClearScreen(ST->ConOut); -#endif - - HEL::HandoverInformationHeader* handoverHdrPtr = nullptr; - - BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader), - (VoidPtr*)&handoverHdrPtr); - - handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase; - handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; - handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; - handoverHdrPtr->f_GOP.f_PixelPerLine = - kGop->Mode->Info->PixelsPerScanLine; - handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; - handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; - - handoverHdrPtr->f_PhysicalStart = - reinterpret_cast<voidPtr>(Descriptor->PhysicalStart); - handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages; - - handoverHdrPtr->f_VirtualStart = - reinterpret_cast<voidPtr>(Descriptor->VirtualStart); - - handoverHdrPtr->f_VirtualSize = - Descriptor->NumberOfPages; /* # of pages */ - - handoverHdrPtr->f_FirmwareVendorLen = - BStrLen(SystemTable->FirmwareVendor); - - BCopyMem(handoverHdrPtr->f_FirmwareVendorName, - SystemTable->FirmwareVendor, - handoverHdrPtr->f_FirmwareVendorLen); - - handoverHdrPtr->f_HardwareTables.f_VendorTables = ST->ConfigurationTable->VendorTable; - - EFI::ExitBootServices(MapKey, ImageHandle); - - bool isIniNotFound = (systemIni.Blob() == nullptr); - - if (isIniNotFound) { - handoverHdrPtr->f_Magic = kHandoverMagic; - handoverHdrPtr->f_Version = 0x1011; - handoverHdrPtr->f_Bootloader = 0x11; // Installer - - Main(handoverHdrPtr); - } else { - handoverHdrPtr->f_Magic = kHandoverMagic; - handoverHdrPtr->f_Version = 0x1011; - handoverHdrPtr->f_Bootloader = 0xDD; // System present - - MUST_PASS(kernelMain); - - kernelMain(handoverHdrPtr); - } - - EFI::Stop(); - - return kEfiOk; - } else { - writer.Write(L"HCoreLdr: Error-Code: HLDR-0001\r\n"); - } - } else { - writer.Write(L"HCoreLdr: Error-Code: HLDR-0002\r\n"); - } - } else { - writer.Write(L"HCoreLdr: Error-Code: HLDR-0003\r\n"); - } - - EFI::Stop(); - - return kEfiFail; -} diff --git a/Private/NewBoot/Source/String.cxx b/Private/NewBoot/Source/BootString.cxx index 9fbe1a11..9fbe1a11 100644 --- a/Private/NewBoot/Source/String.cxx +++ b/Private/NewBoot/Source/BootString.cxx diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx index be7010a8..be7010a8 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index fc09a3a7..21f3f256 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -72,7 +72,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { writer.Write( - L"HCoreLdr: ATA: Select error, not an IDE based hard-drive.\r\n"); + L"NewBoot: ATA: Select error, not an IDE based hard-drive.\r\n"); return false; } @@ -90,7 +90,7 @@ ATAInit_Retry: kATAData[indexData] = In16(IO + ATA_REG_DATA); } - writer.Write(L"HCoreLdr: Model: "); + writer.Write(L"NewBoot: Model: "); for (SizeT indexData = 0; indexData < kATADataLen; indexData += 1) { writer.WriteCharacter(kATAData[indexData + ATA_IDENT_MODEL + 1]) @@ -114,21 +114,21 @@ ATAInit_Retry: /* differentiate ATA, ATAPI, SATA and SATAPI */ if (cl == 0x14 && ch == 0xEB) { - writer.Write(L"HCoreLdr: PATAPI drive detected.\r\n"); + writer.Write(L"NewBoot: PATAPI drive detected.\r\n"); kATADeviceType = kATADevicePATA_PI; } if (cl == 0x69 && ch == 0x96) { - writer.Write(L"HCoreLdr: SATAPI drive detected.\r\n"); + writer.Write(L"NewBoot: SATAPI drive detected.\r\n"); kATADeviceType = kATADeviceSATA_PI; } if (cl == 0 && ch == 0) { - writer.Write(L"HCoreLdr: PATA drive detected.\r\n"); + writer.Write(L"NewBoot: PATA drive detected.\r\n"); kATADeviceType = kATADevicePATA; } if (cl == 0x3c && ch == 0xc3) { - writer.Write(L"HCoreLdr: SATA drive detected.\r\n"); + writer.Write(L"NewBoot: SATA drive detected.\r\n"); kATADeviceType = kATADeviceSATA; } @@ -206,7 +206,7 @@ BDeviceATA::BDeviceATA() noexcept { kATADetected = true; BTextWriter writer; - writer.Write(L"HCoreLdr: Driver: OnLine.\r\n"); + writer.Write(L"NewBoot: Driver: OnLine.\r\n"); } } /** @@ -271,6 +271,6 @@ BDeviceATA& BDeviceATA::Write(CharacterType* Buf, const SizeT& SectorSz) { /** * @brief ATA Config getter. - * @return BDeviceATA::ATATraits& the drive config. + * @return BDeviceATA::ATATrait& the drive config. */ -BDeviceATA::ATATraits& BDeviceATA::Leak() { return mTraits; } +BDeviceATA::ATATrait& BDeviceATA::Leak() { return mTrait; } diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index f24329e8..8418fd4c 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -6,10 +6,6 @@ Purpose: NewBoot FileReader, Read complete file and store it in a buffer. - Revision History: - - Fix stupid implementation for a more smarter one. - ------------------------------------------- */ #include <BootKit/BootKit.hxx> @@ -50,12 +46,12 @@ BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) { EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) { - mWriter.Write(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); + mWriter.Write(L"NewBoot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); this->mErrorCode = kNotSupported; } if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) { - mWriter.Write(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); + mWriter.Write(L"NewBoot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); this->mErrorCode = kNotSupported; return; } @@ -63,7 +59,7 @@ BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) { /// Start doing disk I/O if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { - mWriter.Write(L"HCoreLdr: Fetch-Protocol: No-Such-Volume").Write(L"\r\n"); + mWriter.Write(L"NewBoot: Fetch-Protocol: No-Such-Volume").Write(L"\r\n"); this->mErrorCode = kNotSupported; return; } @@ -72,7 +68,7 @@ BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) { if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) != kEfiOk) { - mWriter.Write(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ") + mWriter.Write(L"NewBoot: Fetch-Protocol: No-Such-Path: ") .Write(mPath) .Write(L"\r\n"); this->mErrorCode = kNotSupported; diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx new file mode 100644 index 00000000..cfd58516 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -0,0 +1,167 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <BootKit/BootKit.hxx> +#include <KernelKit/MSDOS.hpp> +#include <KernelKit/PE.hpp> +#include <NewKit/Ref.hpp> + +#ifdef __x86_64__ +#include <HALKit/AMD64/HalPageAlloc.hpp> +#else +#error This CPU is unknown. +#endif // ifdef __x86_64__ + +#ifndef kBootKrnlSections +#error[NewBoot/NewBoot] Please provide the amount of sections the kernel has. +#endif // !kBootKrnlSections + +#define kBootReadSize \ + (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader)) + +EXTERN_C void Main(HEL::HandoverInformationHeader* HIH); + +typedef void (*bt_main_type)(HEL::HandoverInformationHeader* HIH); + +EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, + EfiSystemTable* SystemTable) { + InitEFI(SystemTable); // Init the efi library. + InitGOP(); // Quick Toolkit for UI + + BTextWriter writer; + + /// Splash screen stuff + + writer.Write(L"MahroussLogic (R) NewBoot: ") + .Write(BVersionString::Shared()) + .Write(L"\r\n"); + + const char strDate[] = __DATE__; + + writer.Write(L"NewBoot: Build: "); + + for (auto& ch : strDate) writer.WriteCharacter(ch); + + writer.Write(L"\r\nHCoreLdr: Firmware Vendor: ") + .Write(SystemTable->FirmwareVendor) + .Write(L"\r\n"); + + /// Read Kernel blob. + + BFileReader kernelImg(L".HCORE", ImageHandle); + + kernelImg.Size(kBootReadSize + sizeof(ExecSectionHeader) * kBootKrnlSections); + kernelImg.ReadAll(); + + if (kernelImg.Error() == BFileReader::kOperationOkay) { + // first check for kernel.cfg inside ESP/EPM. + BFileReader systemManifest(L".MANIFEST", ImageHandle); + + systemManifest.Size(1); + systemManifest.ReadAll(); + + UInt32 MapKey = 0; + UInt32* Size; + EfiMemoryDescriptor* Descriptor; + UInt32 SzDesc = 0; + UInt32 RevDesc = 0; + + if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&Size) != + kEfiOk) { + EFI::RaiseHardError( + L"NewBoot-BadAlloc", + L"NewBoot ran out of memory! Please check your specs."); + } + + /**** + * + * Load kernel into memory. + * + */ + + *Size = sizeof(EfiMemoryDescriptor); + + if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor), + (VoidPtr*)&Descriptor) != kEfiOk) { + EFI::RaiseHardError( + L"NewBoot-BadAlloc", + L"NewBoot ran out of memory! Please check your specs."); + } + + /**** + * + * Get machine memory map. + * + */ + + if (BS->GetMemoryMap(Size, Descriptor, &MapKey, &SzDesc, &RevDesc) != + kEfiOk) { + EFI::RaiseHardError(L"NewBoot-GetMemoryMap", + L"GetMemoryMap returned a value which isn't kEfiOk!"); + } + +#ifndef __DEBUG__ + ST->ConOut->ClearScreen(ST->ConOut); +#endif + + HEL::HandoverInformationHeader* handoverHdrPtr = nullptr; + + BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader), + (VoidPtr*)&handoverHdrPtr); + + handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase; + handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; + handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; + handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine; + handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; + handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; + + handoverHdrPtr->f_PhysicalStart = + reinterpret_cast<voidPtr>(Descriptor->PhysicalStart); + handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages; + + handoverHdrPtr->f_VirtualStart = + reinterpret_cast<voidPtr>(Descriptor->VirtualStart); + + handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */ + + handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); + + BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor, + handoverHdrPtr->f_FirmwareVendorLen); + + handoverHdrPtr->f_HardwareTables.f_VendorTables = + ST->ConfigurationTable->VendorTable; + + EFI::ExitBootServices(MapKey, ImageHandle); + + bool isIniNotFound = (systemManifest.Blob() == nullptr); + + if (isIniNotFound) { + handoverHdrPtr->f_Magic = kHandoverMagic; + handoverHdrPtr->f_Version = 0x1011; + handoverHdrPtr->f_Bootloader = 0x11; // Installer + + Main(handoverHdrPtr); + } else { + handoverHdrPtr->f_Magic = kHandoverMagic; + handoverHdrPtr->f_Version = 0x1011; + handoverHdrPtr->f_Bootloader = 0xDD; // System present + + Main(handoverHdrPtr); + } + + EFI::Stop(); + + return kEfiOk; + } else { + writer.Write(L"NewBoot: Error-Code: HLDR-0003\r\n"); + } + + EFI::Stop(); + + return kEfiFail; +} diff --git a/Private/NewBoot/Source/TextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx index b363d80b..b363d80b 100644 --- a/Private/NewBoot/Source/TextWriter.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index eaaac592..801e7699 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -6,6 +6,10 @@ CC_GNU=x86_64-w64-mingw32-g++ LD_GNU=x86_64-w64-mingw32-ld +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + ifeq ($(shell uname), Darwin) EMU=qemu-system-x86_64 else @@ -26,12 +30,15 @@ invalid-recipe: @echo "invalid-recipe: Use make bootloader-<arch> all instead." .PHONY: bootloader-amd64 -bootloader-amd64: - $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreLdr.exe - cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI - cp HCoreLdr.exe CDROM/EFI/BOOT/HCORELDR.EFI - cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE +bootloader-amd64: compile-amd64 + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe + $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI + $(COPY) NewBoot.exe CDROM/EFI/BOOT/HCORELDR.EFI + $(ADD_FILE) CDROM/.HCORE + +.PHONY: compile-amd64 +compile-amd64: + $(CC_GNU) $(FLAG_GNU) $(wildcard HEL/AMD64/*.cxx) $(wildcard *.cxx) .PHONY: run-efi-amd64 run-efi-amd64: @@ -39,8 +46,8 @@ run-efi-amd64: .PHONY: download-edk download-edk: - wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd + $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd .PHONY: clean clean: - $(REM) $(REM_FLAG) $(OBJ) HCoreLdr.exe HCoreKrnl.exe OVMF.fd + $(REM) $(REM_FLAG) $(OBJ) NewBoot.exe HCoreKrnl.exe OVMF.fd diff --git a/Private/NewKit/Json.hpp b/Private/NewKit/Json.hpp index 3a7aa7cb..115e893f 100644 --- a/Private/NewKit/Json.hpp +++ b/Private/NewKit/Json.hpp @@ -39,7 +39,7 @@ class JsonType final { static JsonType kUndefined; }; -struct JsonStreamTraits final { +struct JsonStreamTrait final { JsonType In(const char *full_array) { SizeT len = rt_string_len(full_array); @@ -82,5 +82,5 @@ struct JsonStreamTraits final { JsonType Out(JsonType &out) { return out; } }; -using JsonStream = Stream<JsonStreamTraits, JsonType>; +using JsonStream = Stream<JsonStreamTrait, JsonType>; } // namespace HCore diff --git a/Private/NewKit/Stream.hpp b/Private/NewKit/Stream.hpp index 60c6e7ff..c344808f 100644 --- a/Private/NewKit/Stream.hpp +++ b/Private/NewKit/Stream.hpp @@ -12,7 +12,7 @@ namespace HCore { - template <typename StreamTraits, typename Kind> + template <typename StreamTrait, typename Kind> class Stream final { public: @@ -26,21 +26,21 @@ namespace HCore Stream(const Stream &) = default; template <typename Data> - friend Stream<StreamTraits, Kind> &operator>>(Stream<StreamTraits, Kind> &Ks, Ref<Data>& Buf) + friend Stream<StreamTrait, Kind> &operator>>(Stream<StreamTrait, Kind> &Ks, Ref<Data>& Buf) { Ks.m_Kind = Ks.m_Stream->In(Buf); return *Ks; } template <typename Data> - friend Stream<StreamTraits, Kind> &operator<<(Stream<StreamTraits, Kind> &Ks, Ref<Data>& Buf) + friend Stream<StreamTrait, Kind> &operator<<(Stream<StreamTrait, Kind> &Ks, Ref<Data>& Buf) { Ks.m_Kind = Buf; Ks.m_Stream->Out(Buf.Leak()); return *Ks; } - Ref<StreamTraits> &AsStreamTraits() + Ref<StreamTrait> &AsStreamTrait() { return m_Stream; } @@ -51,7 +51,7 @@ namespace HCore } private: - Ref<StreamTraits> m_Stream; + Ref<StreamTrait> m_Stream; Ref<Kind> m_Kind; }; diff --git a/Private/NewKit/UserHeap.hpp b/Private/NewKit/UserHeap.hpp index d27963e9..09a7d31e 100644 --- a/Private/NewKit/UserHeap.hpp +++ b/Private/NewKit/UserHeap.hpp @@ -13,12 +13,12 @@ #include <NewKit/Pmm.hpp> #include <NewKit/Ref.hpp> -// last-rev 5/11/23 -// file: UserHeap.hpp -// description: memory heap for user programs. +/// last-rev 5/11/23 +/// @file UserHeap.hpp +/// @brief memory heap for user programs. #define kPoolMaxSz (4096) -#define kPoolMag 0x5500A1 +#define kPoolMag (0x5500A1) namespace HCore { typedef enum { diff --git a/Private/ObjectKit/Object.hxx b/Private/ObjectKit/Object.hxx index 9840a52e..dbb7944d 100644 --- a/Private/ObjectKit/Object.hxx +++ b/Private/ObjectKit/Object.hxx @@ -12,15 +12,25 @@ #define kObjectGlobalNamespaceSystem "HCORE_ROOT\\" #define kObjectGlobalNamespaceUser "HCORE_USER_ROOT\\" +enum { + kObjectTypeProcess, + kObjectTypeFile, + kObjectTypeDevice, + kObjectTypeNetwork, + kObjectTypeInvalid, + kObjectTypeCount, +}; + /// \brief Object handle. +/// \author Amlal El Mahrouss typedef struct Object final { - HCore::WideChar ObjectName[255]; + HCore::Char ObjectName[255]; HCore::Int32 ObjectType; - HCore::WideChar ObjectNamespace[255]; + HCore::Char ObjectNamespace[255]; HCore::Void(*Release)(struct Object* Self); HCore::IntPtr(*Invoke)(struct Object* Self, HCore::Int32 Sel, ...); - HCore::Void(*QueryInterface)(HCore::VoidPtr* Dst, HCore::SizeT SzDst, HCore::XRN::GUIDSequence GuidOf); + HCore::Void(*Query)(struct Object* Self, HCore::VoidPtr* Dst, HCore::SizeT SzDst, HCore::XRN::GUIDSequence GuidOf); } Object, *ObjectPtr; #define object_cast reinterpret_cast diff --git a/Private/Source/DriveManager.cxx b/Private/Source/DriveManager.cxx index 2a5ea394..00e1d94d 100644 --- a/Private/Source/DriveManager.cxx +++ b/Private/Source/DriveManager.cxx @@ -5,6 +5,6 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/DriveManager.hpp> +#include <KernelKit/DriveManager.hxx> namespace HCore {} // namespace HCore diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx index 7a09e5cf..4d3c9417 100644 --- a/Private/Source/FileManager.cxx +++ b/Private/Source/FileManager.cxx @@ -32,11 +32,11 @@ FilesystemManagerInterface* FilesystemManagerInterface::Unmount() { } /// @brief Mount filesystem. -/// @param pMount the filesystem to mount. +/// @param mountPtr the filesystem to mount. /// @return if it succeeded true, otherwise false. -bool FilesystemManagerInterface::Mount(FilesystemManagerInterface* pMount) { +bool FilesystemManagerInterface::Mount(FilesystemManagerInterface* mountPtr) { if (kMounted == nullptr) { - kMounted = pMount; + kMounted = mountPtr; return true; } diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx index f31bd6dc..6ea2fa5b 100644 --- a/Private/Source/Framebuffer.cxx +++ b/Private/Source/Framebuffer.cxx @@ -31,6 +31,15 @@ volatile UIntPtr *Framebuffer::operator[](const UIntPtr &pos) { return (UIntPtr *)(m_FrameBufferAddr->m_Base * pos); } +/// @brief Boolean operator. +Framebuffer::operator bool() { + return m_FrameBufferAddr.Leak()->m_Base != 0 && m_Colour != FramebufferColorKind::INVALID && + m_FrameBufferAddr.Leak()->m_Base != kBadPtr; +} + +/// @brief Set color kind of framebuffer. +/// @param colour +/// @return const FramebufferColorKind &Framebuffer::Color( const FramebufferColorKind &colour) { if (m_Colour != FramebufferColorKind::INVALID && @@ -41,6 +50,8 @@ const FramebufferColorKind &Framebuffer::Color( return m_Colour; } +/// @brief Leak fraembuffer context. +/// @return The reference of the framebuffer context. Ref<FramebufferContext *> &Framebuffer::Leak() { return this->m_FrameBufferAddr; } diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx index 7e5d4f50..9d03e3ae 100644 --- a/Private/Source/NewFS+IO.cxx +++ b/Private/Source/NewFS+IO.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <KernelKit/DriveManager.hpp> +#include <KernelKit/DriveManager.hxx> #include <KernelKit/FileManager.hpp> /** --------------------------------------------------- @@ -33,54 +33,54 @@ enum { kHCFSSubDriveCount, }; -Int32 KeHCFSRead(Mountpoint* Mnt, DriveTraits& DrvTraits, Int32 DrvIndex) { +Int32 ke_newfs_read(Mountpoint* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { if (!Mnt) return -1; switch (DrvIndex) { case 0: { - NEWFS_READ(A, DrvTraits, Mnt); + NEWFS_READ(A, DrvTrait, Mnt); break; } case 1: { - NEWFS_READ(B, DrvTraits, Mnt); + NEWFS_READ(B, DrvTrait, Mnt); break; } case 2: { - NEWFS_READ(C, DrvTraits, Mnt); + NEWFS_READ(C, DrvTrait, Mnt); break; } case 3: { - NEWFS_READ(D, DrvTraits, Mnt); + NEWFS_READ(D, DrvTrait, Mnt); break; } } - return DrvTraits.fPacket.fPacketGood; + return DrvTrait.fPacket.fPacketGood; } -Int32 KeHCFSWrite(Mountpoint* Mnt, DriveTraits& DrvTraits, Int32 DrvIndex) { +Int32 ke_newfs_write(Mountpoint* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { if (!Mnt) return -1; switch (DrvIndex) { case 0: { - NEWFS_WRITE(A, DrvTraits, Mnt); + NEWFS_WRITE(A, DrvTrait, Mnt); break; } case 1: { - NEWFS_WRITE(B, DrvTraits, Mnt); + NEWFS_WRITE(B, DrvTrait, Mnt); break; } case 2: { - NEWFS_WRITE(C, DrvTraits, Mnt); + NEWFS_WRITE(C, DrvTrait, Mnt); break; } case 3: { - NEWFS_WRITE(D, DrvTraits, Mnt); + NEWFS_WRITE(D, DrvTrait, Mnt); break; } } - return DrvTraits.fPacket.fPacketGood; + return DrvTrait.fPacket.fPacketGood; } #endif // ifdef __FSKIT_NEWFS__ diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx index d404819f..06c5813c 100644 --- a/Private/Source/PEFSharedObjectRT.cxx +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -18,7 +18,7 @@ Revision History: - 01/02/24: Rework shared library ABI, except a __LibInit and __LibFini + 01/02/24: Rework shared library ABI, except a rt_library_init and rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the routines. (amlel) @@ -44,7 +44,7 @@ EXTERN_C SharedObjectPtr rt_library_init(void) { return nullptr; } - library->Mount(tls_new_class<SharedObject::SharedObjectTraits>()); + library->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); if (!library->Get()) { ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); diff --git a/Private/makefile b/Private/makefile index 1088e9b5..d64889a3 100644 --- a/Private/makefile +++ b/Private/makefile @@ -26,7 +26,7 @@ invalid-recipe: MOVEALL=./MoveAll.sh .PHONY: h-core-amd64 -h-core-amd64: +h-core-amd64: clean $(CC) $(CCFLAGS) $(DEBUG) Source/*.cxx HALKit/AMD64/PCI/*.cxx Source/Network/*.cxx\ Source/Storage/*.cxx HALKit/AMD64/*.cxx HALKit/AMD64/*.cpp HALKit/AMD64/*.s $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptRouting.asm |
