From f95d8bf159d10b5a9521dcaa0bc37aa0e9dfc02b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 5 May 2024 21:10:18 +0200 Subject: MHR-23: Add run_format.sh, kernel patches. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx | 1 - Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 261 ++++++++------- .../NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 213 ++++++------ Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 369 +++++++++++---------- Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx | 89 +++-- Private/NewBoot/Source/HEL/AMD64/BootString.cxx | 91 ++--- .../NewBoot/Source/HEL/AMD64/BootTextWriter.cxx | 154 +++++---- Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx | 16 +- Private/NewBoot/Source/HEL/AMD64/Support.cxx | 51 +-- Private/NewBoot/Source/makefile | 5 +- 10 files changed, 697 insertions(+), 553 deletions(-) (limited to 'Private/NewBoot/Source') diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx index d04a94d3..a99b8a56 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx @@ -15,7 +15,6 @@ * */ - #include #include #include diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index edfbaed8..a5bd9809 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -23,138 +23,153 @@ #define kATADataLen 256 -static Boolean kATADetected = false; -static Int32 kATADeviceType = kATADeviceCount; -static UInt16 kATAData[kATADataLen] = {0}; +static Boolean kATADetected = false; +static Int32 kATADeviceType = kATADeviceCount; +static UInt16 kATAData[kATADataLen] = {0}; Boolean boot_ata_detected(Void); -STATIC Boolean boot_ata_wait_io(UInt16 IO) { - for (int i = 0; i < 4; i++) In8(IO + ATA_REG_STATUS); +STATIC Boolean boot_ata_wait_io(UInt16 IO) +{ + for (int i = 0; i < 4; i++) + In8(IO + ATA_REG_STATUS); ATAWaitForIO_Retry: - auto statRdy = In8(IO + ATA_REG_STATUS); + auto statRdy = In8(IO + ATA_REG_STATUS); - if ((statRdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; + if ((statRdy & ATA_SR_BSY)) + goto ATAWaitForIO_Retry; ATAWaitForIO_Retry2: - statRdy = In8(IO + ATA_REG_STATUS); + statRdy = In8(IO + ATA_REG_STATUS); - if (statRdy & ATA_SR_ERR) return false; + if (statRdy & ATA_SR_ERR) + return false; - if (!(statRdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; + if (!(statRdy & ATA_SR_DRDY)) + goto ATAWaitForIO_Retry2; - return true; + return true; } -Void boot_ata_select(UInt16 Bus) { - if (Bus == ATA_PRIMARY_IO) - Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); - else - Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); +Void boot_ata_select(UInt16 Bus) +{ + if (Bus == ATA_PRIMARY_IO) + Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); + else + Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); } -Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, - UInt8& OutMaster) { - if (boot_ata_detected()) return true; +Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) +{ + if (boot_ata_detected()) + return true; - BTextWriter writer; + BTextWriter writer; - UInt16 IO = Bus; + UInt16 IO = Bus; - boot_ata_select(IO); + boot_ata_select(IO); - // Bus init, NEIN bit. - Out8(IO + ATA_REG_NEIN, 1); + // Bus init, NEIN bit. + Out8(IO + ATA_REG_NEIN, 1); - // identify until it's good. + // identify until it's good. ATAInit_Retry: - auto statRdy = In8(IO + ATA_REG_STATUS); + auto statRdy = In8(IO + ATA_REG_STATUS); - if (statRdy & ATA_SR_ERR) { - writer.Write( - L"New Boot: ATA: Select error, not an IDE based hard-drive.\r"); + if (statRdy & ATA_SR_ERR) + { + writer.Write( + L"New Boot: ATA: Select error, not an IDE based hard-drive.\r"); - return false; - } + return false; + } - if ((statRdy & ATA_SR_BSY)) goto ATAInit_Retry; + if ((statRdy & ATA_SR_BSY)) + goto ATAInit_Retry; - Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - /// fetch serial info - /// model, speed, number of sectors... + /// fetch serial info + /// model, speed, number of sectors... - boot_ata_wait_io(IO); + boot_ata_wait_io(IO); - for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = In16(IO + ATA_REG_DATA); - } + for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) + { + kATAData[indexData] = In16(IO + ATA_REG_DATA); + } - OutBus = - (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; + OutBus = + (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - return true; + return true; } -Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, - SizeT SectorSz, SizeT Size) { - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); +Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) +{ + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - boot_ata_wait_io(IO); - boot_ata_select(IO); + boot_ata_wait_io(IO); + boot_ata_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 2); + Out8(IO + ATA_REG_SEC_COUNT0, 2); - Out8(IO + ATA_REG_LBA0, (Lba)); - Out8(IO + ATA_REG_LBA1, (Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); + Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA1, (Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (Lba) >> 16); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); - Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - boot_ata_wait_io(IO); + boot_ata_wait_io(IO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { - boot_ata_wait_io(IO); - Buf[IndexOff] = In16(IO + ATA_REG_DATA); - boot_ata_wait_io(IO); - } + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) + { + boot_ata_wait_io(IO); + Buf[IndexOff] = In16(IO + ATA_REG_DATA); + boot_ata_wait_io(IO); + } } -Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, - SizeT SectorSz, SizeT Size) { - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); +Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) +{ + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - boot_ata_wait_io(IO); - boot_ata_select(IO); + boot_ata_wait_io(IO); + boot_ata_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 2); + Out8(IO + ATA_REG_SEC_COUNT0, 2); - Out8(IO + ATA_REG_LBA0, (Lba)); - Out8(IO + ATA_REG_LBA1, (Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); + Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA1, (Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (Lba) >> 16); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); - Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - boot_ata_wait_io(IO); + boot_ata_wait_io(IO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { - boot_ata_wait_io(IO); - Out16(IO + ATA_REG_DATA, Buf[IndexOff]); - boot_ata_wait_io(IO); - } + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) + { + boot_ata_wait_io(IO); + Out16(IO + ATA_REG_DATA, Buf[IndexOff]); + boot_ata_wait_io(IO); + } } /// @check is ATA detected? -Boolean boot_ata_detected(Void) { return kATADetected; } +Boolean boot_ata_detected(Void) +{ + return kATADetected; +} /*** * @@ -168,40 +183,48 @@ Boolean boot_ata_detected(Void) { return kATADetected; } * @brief ATA Device constructor. * @param void none. */ -BootDeviceATA::BootDeviceATA() noexcept { - if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, - this->Leak().mMaster) || - boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, - this->Leak().mMaster)) { - kATADetected = true; - } +BootDeviceATA::BootDeviceATA() noexcept +{ + if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, + this->Leak().mMaster) || + boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, + this->Leak().mMaster)) + { + kATADetected = true; + } } /** * @brief Is ATA detected? */ -BootDeviceATA::operator bool() { return boot_ata_detected(); } +BootDeviceATA::operator bool() +{ + return boot_ata_detected(); +} /** @brief Read Buf from disk @param Sz Sector size @param Buf buffer */ -BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } +BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz) +{ + if (!boot_ata_detected()) + { + Leak().mErr = true; + return *this; + } - this->Leak().mErr = false; + this->Leak().mErr = false; - if (!Buf || SectorSz < 1) return *this; + if (!Buf || SectorSz < 1) + return *this; - auto lba = this->Leak().mBase / SectorSz; + auto lba = this->Leak().mBase / SectorSz; - boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster, - Buf, SectorSz, this->Leak().mSize); + boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster, + Buf, SectorSz, this->Leak().mSize); - return *this; + return *this; } /** @@ -209,37 +232,45 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz @param Sz Sector size @param Buf buffer */ -BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } +BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorSz) +{ + if (!boot_ata_detected()) + { + Leak().mErr = true; + return *this; + } - Leak().mErr = false; + Leak().mErr = false; - if (!Buf || SectorSz < 1) return *this; + if (!Buf || SectorSz < 1) + return *this; - auto lba = this->Leak().mBase / SectorSz; + auto lba = this->Leak().mBase / SectorSz; - boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster, - Buf, SectorSz, this->Leak().mSize); + boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster, + Buf, SectorSz, this->Leak().mSize); - return *this; + return *this; } /** * @brief ATA trait getter. * @return BootDeviceATA::ATATrait& the drive config. */ -BootDeviceATA::ATATrait& BootDeviceATA::Leak() { return mTrait; } +BootDeviceATA::ATATrait& BootDeviceATA::Leak() +{ + return mTrait; +} /*** @brief Getter, gets the number of sectors inside the drive. */ -SizeT BootDeviceATA::GetSectorsCount() noexcept { - return (kATAData[61] << 16)| kATAData[60]; +SizeT BootDeviceATA::GetSectorsCount() noexcept +{ + return (kATAData[61] << 16) | kATAData[60]; } -SizeT BootDeviceATA::GetDiskSize() noexcept { - return this->GetSectorsCount() * BootDeviceATA::kSectorSize; +SizeT BootDeviceATA::GetDiskSize() noexcept +{ + return this->GetSectorsCount() * BootDeviceATA::kSectorSize; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index 85b90e57..39c18821 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -32,117 +32,142 @@ @brief File Reader constructor. */ BFileReader::BFileReader(const CharacterTypeUTF16* path, - EfiHandlePtr ImageHandle) { - if (path != nullptr) { - SizeT index = 0UL; - for (; path[index] != L'\0'; ++index) { - mPath[index] = path[index]; - } - - mPath[index] = 0; - } - - /// Load protocols with their GUIDs. - - EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID); - - EfiSimpleFilesystemProtocol* efp = nullptr; - EfiFileProtocol* rootFs = nullptr; - - EfiLoadImageProtocol* img = nullptr; - EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); - - if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); - this->mErrorCode = kNotSupported; - } - - if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); - this->mErrorCode = kNotSupported; - return; - } - - /// Start doing disk I/O - - if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r"); - this->mErrorCode = kNotSupported; - return; - } - - EfiFileProtocol* kernelFile = nullptr; - - if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) != - kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ") - .Write(mPath) - .Write(L"\r"); - this->mErrorCode = kNotSupported; - return; - } - - rootFs->Close(rootFs); - - mSizeFile = 0; - mFile = kernelFile; - mErrorCode = kOperationOkay; + EfiHandlePtr ImageHandle) +{ + if (path != nullptr) + { + SizeT index = 0UL; + for (; path[index] != L'\0'; ++index) + { + mPath[index] = path[index]; + } + + mPath[index] = 0; + } + + /// Load protocols with their GUIDs. + + EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID); + + EfiSimpleFilesystemProtocol* efp = nullptr; + EfiFileProtocol* rootFs = nullptr; + + EfiLoadImageProtocol* img = nullptr; + EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); + + if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) + { + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); + this->mErrorCode = kNotSupported; + } + + if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) + { + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); + this->mErrorCode = kNotSupported; + return; + } + + /// Start doing disk I/O + + if (efp->OpenVolume(efp, &rootFs) != kEfiOk) + { + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r"); + this->mErrorCode = kNotSupported; + return; + } + + EfiFileProtocol* kernelFile = nullptr; + + if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) != + kEfiOk) + { + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ") + .Write(mPath) + .Write(L"\r"); + this->mErrorCode = kNotSupported; + return; + } + + rootFs->Close(rootFs); + + mSizeFile = 0; + mFile = kernelFile; + mErrorCode = kOperationOkay; } -BFileReader::~BFileReader() { - if (this->mFile) { - this->mFile->Close(this->mFile); - this->mFile = nullptr; - } +BFileReader::~BFileReader() +{ + if (this->mFile) + { + this->mFile->Close(this->mFile); + this->mFile = nullptr; + } - if (this->mBlob) BS->FreePool(mBlob); + if (this->mBlob) + BS->FreePool(mBlob); - BSetMem(this->mPath, 0, kPathLen); + BSetMem(this->mPath, 0, kPathLen); } /** @brief this reads all of the buffer. @param until read until size is reached. */ -Void BFileReader::ReadAll(SizeT until, SizeT chunk) { - if (mBlob == nullptr) { - if (auto err = BS->AllocatePool(EfiLoaderCode, until, (VoidPtr*)&mBlob) != - kEfiOk) { - mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r"); - EFI::ThrowError(L"OutOfMemory", L"Out of memory."); - } - } - - mErrorCode = kNotSupported; - - UInt64 bufSize = chunk; - UInt64 szCnt = 0; - UInt64 curSz = 0; - - while (szCnt < until) { - if (mFile->Read(mFile, &bufSize, (VoidPtr)((UIntPtr)mBlob + curSz)) != - kEfiOk) { - break; - } - - szCnt += bufSize; - curSz += bufSize; - - if (bufSize == 0) break; - } - - mSizeFile = curSz; - mErrorCode = kOperationOkay; +Void BFileReader::ReadAll(SizeT until, SizeT chunk) +{ + if (mBlob == nullptr) + { + if (auto err = BS->AllocatePool(EfiLoaderCode, until, (VoidPtr*)&mBlob) != + kEfiOk) + { + mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r"); + EFI::ThrowError(L"OutOfMemory", L"Out of memory."); + } + } + + mErrorCode = kNotSupported; + + UInt64 bufSize = chunk; + UInt64 szCnt = 0; + UInt64 curSz = 0; + + while (szCnt < until) + { + if (mFile->Read(mFile, &bufSize, (VoidPtr)((UIntPtr)mBlob + curSz)) != + kEfiOk) + { + break; + } + + szCnt += bufSize; + curSz += bufSize; + + if (bufSize == 0) + break; + } + + mSizeFile = curSz; + mErrorCode = kOperationOkay; } /// @brief error code getter. /// @return the error code. -Int32& BFileReader::Error() { return mErrorCode; } +Int32& BFileReader::Error() +{ + return mErrorCode; +} /// @brief blob getter. /// @return the blob. -VoidPtr BFileReader::Blob() { return mBlob; } +VoidPtr BFileReader::Blob() +{ + return mBlob; +} /// @breif Size getter. /// @return the size of the file. -UInt64& BFileReader::Size() { return mSizeFile; } +UInt64& BFileReader::Size() +{ + return mSizeFile; +} diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 844179da..ebde06e8 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -20,13 +20,13 @@ /// make the compiler shut up. #ifndef kMachineModel #define kMachineModel "NeWS HD" -#endif // !kMachineModel +#endif // !kMachineModel /** Graphics related. */ -STATIC EfiGraphicsOutputProtocol* kGop = nullptr; -STATIC UInt16 kStride = 0U; -STATIC EfiGUID kGopGuid; +STATIC EfiGraphicsOutputProtocol* kGop = nullptr; +STATIC UInt16 kStride = 0U; +STATIC EfiGUID kGopGuid; EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH); @@ -34,196 +34,211 @@ EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH); @brief Finds and stores the GOP. */ -STATIC Void CheckAndFindFramebuffer() noexcept { - kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); - kGop = nullptr; +STATIC Void CheckAndFindFramebuffer() noexcept +{ + kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); + kGop = nullptr; - extern EfiBootServices* BS; + extern EfiBootServices* BS; - BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop); + BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop); - kStride = 4; + kStride = 4; } /// @brief check the BootDevice if suitable. -STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) { - if (ataDev.Leak().mErr) return false; - return true; +STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) +{ + if (ataDev.Leak().mErr) + return false; + return true; } /// @brief Main EFI entrypoint. /// @param ImageHandle Handle of this image. /// @param SystemTable The system table of it. /// @return -EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, - EfiSystemTable* SystemTable) { - InitEFI(SystemTable); ///! Init the EFI library. - CheckAndFindFramebuffer(); ///! Init the GOP. +EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, + EfiSystemTable* SystemTable) +{ + InitEFI(SystemTable); ///! Init the EFI library. + CheckAndFindFramebuffer(); ///! Init the GOP. - BTextWriter writer; + BTextWriter writer; - /// Splash screen stuff + /// Splash screen stuff - writer.Write(L"Mahrouss-Logic (R) New Boot: ") - .Write(BVersionString::Shared()); + writer.Write(L"Mahrouss-Logic (R) New Boot: ") + .Write(BVersionString::Shared()); - writer.Write(L"\rNew Boot: Firmware Vendor: ") - .Write(SystemTable->FirmwareVendor) - .Write(L"\r"); + writer.Write(L"\rNew Boot: Firmware Vendor: ") + .Write(SystemTable->FirmwareVendor) + .Write(L"\r"); - UInt32* MapKey = new UInt32(); - UInt32* SizePtr = new UInt32(); - EfiMemoryDescriptor* Descriptor = nullptr; - UInt32* SzDesc = new UInt32(); - UInt32* RevDesc = new UInt32(); + UInt32* MapKey = new UInt32(); + UInt32* SizePtr = new UInt32(); + EfiMemoryDescriptor* Descriptor = nullptr; + UInt32* SzDesc = new UInt32(); + UInt32* RevDesc = new UInt32(); - *MapKey = 0; - *SizePtr = 0; + *MapKey = 0; + *SizePtr = 0; + + HEL::HandoverInformationHeader* handoverHdrPtr = + new HEL::HandoverInformationHeader(); + + for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries; + ++indexVT) + { + volatile Char* vendorTable = reinterpret_cast( + SystemTable->ConfigurationTable[indexVT].VendorTable); - HEL::HandoverInformationHeader* handoverHdrPtr = - new HEL::HandoverInformationHeader(); - - for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries; - ++indexVT) { - volatile Char* vendorTable = reinterpret_cast( - SystemTable->ConfigurationTable[indexVT].VendorTable); - - /// ACPI's 'RSD PTR', which contains hardware tables (MADT, FACP...) - if (vendorTable[0] == 'R' && vendorTable[1] == 'S' && - vendorTable[2] == 'D' && vendorTable[3] == ' ' && - vendorTable[4] == 'P' && vendorTable[5] == 'T' && - vendorTable[6] == 'R' && vendorTable[7] == ' ') { - handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable; - - break; - } - } - - handoverHdrPtr->f_Magic = kHandoverMagic; - handoverHdrPtr->f_Version = kHandoverVersion; - - BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor, - handoverHdrPtr->f_FirmwareVendorLen); - - 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; - - ///! Finally draw bootloader screen. - - kHandoverHeader = handoverHdrPtr; - - ToolboxInitRsrc(); - - ToolboxDrawZone(RGB(9d, 9d, 9d), handoverHdrPtr->f_GOP.f_Height, - handoverHdrPtr->f_GOP.f_Width, 0, 0); - - ToolboxClearRsrc(); - - ToolboxDrawRsrc(NewBoot, NEWBOOT_HEIGHT, NEWBOOT_WIDTH, - (handoverHdrPtr->f_GOP.f_Width - NEWBOOT_WIDTH) / 2, - (handoverHdrPtr->f_GOP.f_Height - NEWBOOT_HEIGHT) / 2); - - ToolboxClearRsrc(); - - BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc); - - Descriptor = new EfiMemoryDescriptor[*SzDesc]; - BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc); - - writer.Write(L"Kernel-Desc-Count: "); - writer.Write(*SzDesc); - writer.Write(L"\r"); - - auto cDefaultMemoryMap = 0; /// The sixth entry. - - /// A simple loop which finds a usable memory region for us. - SizeT i = 0UL; - for (; Descriptor[i].Kind != EfiMemoryType::EfiConventionalMemory; ++i) { - ; - } - - cDefaultMemoryMap = i; - - writer.Write(L"Number-Of-Pages: ") - .Write(Descriptor[cDefaultMemoryMap].NumberOfPages) - .Write(L"\r"); - writer.Write(L"Virtual-Address: ") - .Write(Descriptor[cDefaultMemoryMap].VirtualStart) - .Write(L"\r"); - writer.Write(L"Phyiscal-Address: ") - .Write(Descriptor[cDefaultMemoryMap].PhysicalStart) - .Write(L"\r"); - writer.Write(L"Page-Kind: ") - .Write(Descriptor[cDefaultMemoryMap].Kind) - .Write(L"\r"); - writer.Write(L"Page-Attribute: ") - .Write(Descriptor[cDefaultMemoryMap].Attribute) - .Write(L"\r"); - - handoverHdrPtr->f_PhysicalStart = - (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart; - - handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] = - Descriptor[cDefaultMemoryMap].Attribute; - handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] = - Descriptor[cDefaultMemoryMap].Kind; - handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] = - (UIntPtr)Descriptor; - - handoverHdrPtr->f_VirtualStart = - (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; - handoverHdrPtr->f_VirtualSize = - Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ - - handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); - - BFileReader reader(L"SplashScreen.fmt", ImageHandle); - reader.ReadAll(512, 16); - - if (reader.Blob()) { - Char* buf = (Char*)reader.Blob(); - - for (SizeT i = 0; i < reader.Size(); ++i) { - if (buf[i] != '\n' && buf[i] != '\r') { - if (buf[i] == '*') { - writer.WriteCharacter('\t'); - } else { - writer.WriteCharacter(buf[i]); - } - } else - writer.Write(L"\r"); - } - } - - /// - /// The following checks for an exisiting partition - /// inside the disk, if it doesn't have one, - /// format the disk. - // - - BDiskFormatFactory diskFormatter; - - /// if not formated yet, then format it with the following folders: - /// /, /Boot, /Applications. - if (!diskFormatter.IsPartitionValid()) { - BDiskFormatFactory::BFileDescriptor rootDesc{0}; - - CopyMem(rootDesc.fFileName, kNewFSRoot, StrLen(kNewFSRoot)); - rootDesc.fKind = kNewFSCatalogKindDir; - - diskFormatter.Format(kMachineModel, &rootDesc, 1); - } - - EFI::ExitBootServices(*MapKey, ImageHandle); - - /// Fallback to builtin kernel. - hal_init_platform(handoverHdrPtr); - - EFI::Stop(); - - CANT_REACH(); + /// ACPI's 'RSD PTR', which contains hardware tables (MADT, FACP...) + if (vendorTable[0] == 'R' && vendorTable[1] == 'S' && + vendorTable[2] == 'D' && vendorTable[3] == ' ' && + vendorTable[4] == 'P' && vendorTable[5] == 'T' && + vendorTable[6] == 'R' && vendorTable[7] == ' ') + { + handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable; + + break; + } + } + + handoverHdrPtr->f_Magic = kHandoverMagic; + handoverHdrPtr->f_Version = kHandoverVersion; + + BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor, + handoverHdrPtr->f_FirmwareVendorLen); + + 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; + + ///! Finally draw bootloader screen. + + kHandoverHeader = handoverHdrPtr; + + ToolboxInitRsrc(); + + ToolboxDrawZone(RGB(9d, 9d, 9d), handoverHdrPtr->f_GOP.f_Height, + handoverHdrPtr->f_GOP.f_Width, 0, 0); + + ToolboxClearRsrc(); + + ToolboxDrawRsrc(NewBoot, NEWBOOT_HEIGHT, NEWBOOT_WIDTH, + (handoverHdrPtr->f_GOP.f_Width - NEWBOOT_WIDTH) / 2, + (handoverHdrPtr->f_GOP.f_Height - NEWBOOT_HEIGHT) / 2); + + ToolboxClearRsrc(); + + BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc); + + Descriptor = new EfiMemoryDescriptor[*SzDesc]; + BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc); + + writer.Write(L"Kernel-Desc-Count: "); + writer.Write(*SzDesc); + writer.Write(L"\r"); + + auto cDefaultMemoryMap = 0; /// The sixth entry. + + /// A simple loop which finds a usable memory region for us. + SizeT i = 0UL; + for (; Descriptor[i].Kind != EfiMemoryType::EfiConventionalMemory; ++i) + { + ; + } + + cDefaultMemoryMap = i; + + writer.Write(L"Number-Of-Pages: ") + .Write(Descriptor[cDefaultMemoryMap].NumberOfPages) + .Write(L"\r"); + writer.Write(L"Virtual-Address: ") + .Write(Descriptor[cDefaultMemoryMap].VirtualStart) + .Write(L"\r"); + writer.Write(L"Phyiscal-Address: ") + .Write(Descriptor[cDefaultMemoryMap].PhysicalStart) + .Write(L"\r"); + writer.Write(L"Page-Kind: ") + .Write(Descriptor[cDefaultMemoryMap].Kind) + .Write(L"\r"); + writer.Write(L"Page-Attribute: ") + .Write(Descriptor[cDefaultMemoryMap].Attribute) + .Write(L"\r"); + + handoverHdrPtr->f_PhysicalStart = + (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart; + + handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] = + Descriptor[cDefaultMemoryMap].Attribute; + handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] = + Descriptor[cDefaultMemoryMap].Kind; + handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] = + (UIntPtr)Descriptor; + + handoverHdrPtr->f_VirtualStart = + (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; + handoverHdrPtr->f_VirtualSize = + Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ + + handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); + + BFileReader reader(L"SplashScreen.fmt", ImageHandle); + reader.ReadAll(512, 16); + + if (reader.Blob()) + { + Char* buf = (Char*)reader.Blob(); + + for (SizeT i = 0; i < reader.Size(); ++i) + { + if (buf[i] != '\n' && buf[i] != '\r') + { + if (buf[i] == '*') + { + writer.WriteCharacter('\t'); + } + else + { + writer.WriteCharacter(buf[i]); + } + } + else + writer.Write(L"\r"); + } + } + + /// + /// The following checks for an exisiting partition + /// inside the disk, if it doesn't have one, + /// format the disk. + // + + BDiskFormatFactory diskFormatter; + + /// if not formated yet, then format it with the following folders: + /// /, /Boot, /Applications. + if (!diskFormatter.IsPartitionValid()) + { + BDiskFormatFactory::BFileDescriptor rootDesc{0}; + + CopyMem(rootDesc.fFileName, kNewFSRoot, StrLen(kNewFSRoot)); + rootDesc.fKind = kNewFSCatalogKindDir; + + diskFormatter.Format(kMachineModel, &rootDesc, 1); + } + + EFI::ExitBootServices(*MapKey, ImageHandle); + + /// Fallback to builtin kernel. + hal_init_platform(handoverHdrPtr); + + EFI::Stop(); + + CANT_REACH(); } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx index fa735142..1b8576a9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx @@ -11,51 +11,92 @@ #ifdef __STANDALONE__ -EXTERN_C void rt_hlt() { asm volatile("hlt"); } +EXTERN_C void rt_hlt() +{ + asm volatile("hlt"); +} -EXTERN_C void rt_cli() { asm volatile("cli"); } +EXTERN_C void rt_cli() +{ + asm volatile("cli"); +} -EXTERN_C void rt_sti() { asm volatile("sti"); } +EXTERN_C void rt_sti() +{ + asm volatile("sti"); +} -EXTERN_C void rt_cld() { asm volatile("cld"); } +EXTERN_C void rt_cld() +{ + asm volatile("cld"); +} -EXTERN_C void rt_std() { asm volatile("std"); } +EXTERN_C void rt_std() +{ + asm volatile("std"); +} -EXTERN_C void Out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +EXTERN_C void Out8(UInt16 port, UInt8 value) +{ + asm volatile("outb %%al, %1" + : + : "a"(value), "Nd"(port) + : "memory"); } -EXTERN_C void Out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +EXTERN_C void Out16(UInt16 port, UInt16 value) +{ + asm volatile("outw %%ax, %1" + : + : "a"(value), "Nd"(port) + : "memory"); } -EXTERN_C void Out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +EXTERN_C void Out32(UInt16 port, UInt32 value) +{ + asm volatile("outl %%eax, %1" + : + : "a"(value), "Nd"(port) + : "memory"); } -EXTERN_C UInt8 In8(UInt16 port) { - UInt8 value; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); +EXTERN_C UInt8 In8(UInt16 port) +{ + UInt8 value; + asm volatile("inb %1, %%al" + : "=a"(value) + : "Nd"(port) + : "memory"); - return value; + return value; } -EXTERN_C UInt16 In16(UInt16 port) { - UInt16 value; - asm volatile("inw %%dx, %%ax" : "=a"(value) : "d"(port)); +EXTERN_C UInt16 In16(UInt16 port) +{ + UInt16 value; + asm volatile("inw %%dx, %%ax" + : "=a"(value) + : "d"(port)); - return value; + return value; } -EXTERN_C UInt32 In32(UInt16 port) { - UInt32 value; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); +EXTERN_C UInt32 In32(UInt16 port) +{ + UInt32 value; + asm volatile("inl %1, %%eax" + : "=a"(value) + : "Nd"(port) + : "memory"); - return value; + return value; } #else -void rt_hlt() { NewOS::HAL::rt_halt(); } +void rt_hlt() +{ + NewOS::HAL::rt_halt(); +} #endif // 0 diff --git a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx index ef0e4744..34e16737 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx @@ -19,63 +19,74 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////// -NewOS::SizeT BCopyMem(CharacterTypeUTF16 *dest, CharacterTypeUTF16 *src, - const NewOS::SizeT len) { - if (!dest || !src) return 0; - - SizeT index = 0UL; - for (; index < len; ++index) { - dest[index] = src[index]; - } - - return index; +NewOS::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const NewOS::SizeT len) +{ + if (!dest || !src) + return 0; + + SizeT index = 0UL; + for (; index < len; ++index) + { + dest[index] = src[index]; + } + + return index; } -NewOS::SizeT BStrLen(const CharacterTypeUTF16 *ptr) { - if (!ptr) return 0; +NewOS::SizeT BStrLen(const CharacterTypeUTF16* ptr) +{ + if (!ptr) + return 0; - NewOS::SizeT cnt = 0; + NewOS::SizeT cnt = 0; - while (*ptr != (CharacterTypeUTF16)0) { - ++ptr; - ++cnt; - } + while (*ptr != (CharacterTypeUTF16)0) + { + ++ptr; + ++cnt; + } - return cnt; + return cnt; } -NewOS::SizeT BSetMem(CharacterTypeUTF16 *src, const CharacterTypeUTF16 byte, - const NewOS::SizeT len) { - if (!src) return 0; +NewOS::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const NewOS::SizeT len) +{ + if (!src) + return 0; - NewOS::SizeT cnt = 0UL; + NewOS::SizeT cnt = 0UL; - while (*src != 0) { - if (cnt > len) break; + while (*src != 0) + { + if (cnt > len) + break; - *src = byte; - ++src; + *src = byte; + ++src; - ++cnt; - } + ++cnt; + } - return cnt; + return cnt; } -NewOS::SizeT BSetMem(CharacterTypeUTF8 *src, const CharacterTypeUTF8 byte, - const NewOS::SizeT len) { - if (!src) return 0; +NewOS::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const NewOS::SizeT len) +{ + if (!src) + return 0; - NewOS::SizeT cnt = 0UL; + NewOS::SizeT cnt = 0UL; - while (*src != 0) { - if (cnt > len) break; + while (*src != 0) + { + if (cnt > len) + break; - *src = byte; - ++src; + *src = byte; + ++src; - ++cnt; - } + ++cnt; + } - return cnt; + return cnt; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx index 13ef35c8..fcb2154f 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx @@ -23,100 +23,118 @@ /** @brief puts wrapper over EFI ConOut. */ -BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) { +BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) +{ #ifdef __DEBUG__ - if (!str || *str == 0) return *this; - - CharacterTypeUTF16 strTmp[2]; - strTmp[1] = 0; - - for (size_t i = 0; str[i] != 0; i++) { - if (str[i] == '\r') { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - - strTmp[0] = '\n'; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } else { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - } -#endif // ifdef __DEBUG__ - - return *this; + if (!str || *str == 0) + return *this; + + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) + { + if (str[i] == '\r') + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + else + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } +#endif // ifdef __DEBUG__ + + return *this; } /// @brief UTF-8 equivalent of Write (UTF-16). /// @param str the input string. -BTextWriter &BTextWriter::Write(const Char *str) { +BTextWriter& BTextWriter::Write(const Char* str) +{ #ifdef __DEBUG__ - if (!str || *str == 0) return *this; - - CharacterTypeUTF16 strTmp[2]; - strTmp[1] = 0; - - for (size_t i = 0; str[i] != 0; i++) { - if (str[i] == '\r') { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - - strTmp[0] = '\n'; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } else { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - } -#endif // ifdef __DEBUG__ - - return *this; + if (!str || *str == 0) + return *this; + + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) + { + if (str[i] == '\r') + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + else + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } +#endif // ifdef __DEBUG__ + + return *this; } /** @brief putc wrapper over EFI ConOut. */ -BTextWriter &BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { +BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) +{ #ifdef __DEBUG__ - EfiCharType str[2]; + EfiCharType str[2]; - str[0] = c; - str[1] = 0; - ST->ConOut->OutputString(ST->ConOut, str); -#endif // ifdef __DEBUG__ + str[0] = c; + str[1] = 0; + ST->ConOut->OutputString(ST->ConOut, str); +#endif // ifdef __DEBUG__ - return *this; + return *this; } -BTextWriter &BTextWriter::Write(const Long &x) { +BTextWriter& BTextWriter::Write(const Long& x) +{ #ifdef __DEBUG__ - this->Write(L"0x"); - this->_Write(x); + this->Write(L"0x"); + this->_Write(x); -#endif // ifdef __DEBUG__ +#endif // ifdef __DEBUG__ - return *this; + return *this; } -BTextWriter &BTextWriter::_Write(const Long &x) { +BTextWriter& BTextWriter::_Write(const Long& x) +{ #ifdef __DEBUG__ - UInt64 y = (x > 0 ? x : -x) / 16; - UInt64 h = (x > 0 ? x : -x) % 16; + UInt64 y = (x > 0 ? x : -x) / 16; + UInt64 h = (x > 0 ? x : -x) % 16; - if (y) this->_Write(y); + if (y) + this->_Write(y); - /* fail if the hex number is not base-16 */ - if (h > 15) { - this->WriteCharacter('?'); - return *this; - } + /* fail if the hex number is not base-16 */ + if (h > 15) + { + this->WriteCharacter('?'); + return *this; + } - if (y < 0) y = -y; + if (y < 0) + y = -y; - const char NUMBERS[17] = "0123456789ABCDEF"; + const char NUMBERS[17] = "0123456789ABCDEF"; - this->WriteCharacter(NUMBERS[h]); -#endif // ifdef __DEBUG__ + this->WriteCharacter(NUMBERS[h]); +#endif // ifdef __DEBUG__ - return *this; + return *this; } diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx index 8d811bd9..25aaec1c 100644 --- a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx @@ -16,10 +16,10 @@ /// @return void* operator new(size_t sz) { - void* buf = nullptr; - BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); + void* buf = nullptr; + BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); - return buf; + return buf; } /// @brief Allocates a new object. @@ -27,17 +27,17 @@ void* operator new(size_t sz) /// @return void* operator new[](size_t sz) { - void* buf = nullptr; - BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); + void* buf = nullptr; + BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); - return buf; + return buf; } /// @brief Deletes the object. /// @param buf the object. void operator delete(void* buf) { - BS->FreePool(buf); + BS->FreePool(buf); } /// @brief Deletes the object (array specific). @@ -45,7 +45,7 @@ void operator delete(void* buf) /// @param size it's size. void operator delete(void* buf, size_t size) { - BS->FreePool(buf); + BS->FreePool(buf); } #endif // Inactive diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx index 3a6974bb..65fb6b48 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Support.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx @@ -14,42 +14,49 @@ /// @param dst destination pointer. /// @param byte value to fill in. /// @param len length of of src. -EXTERN_C VoidPtr memset(void *dst, int byte, - long long unsigned int len) { - for (size_t i = 0UL; i < len; ++i) { - ((int*)dst)[i] = byte; - } - - return dst; +EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = byte; + } + + return dst; } /// @brief memcpy definition in C++. /// @param dst destination pointer. /// @param src source pointer. /// @param len length of of src. -EXTERN_C VoidPtr memcpy(void *dst, const void *src, - long long unsigned int len) { - for (size_t i = 0UL; i < len; ++i){ - ((int*)dst)[i] = ((int*)src)[i]; - } - - return dst; +EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = ((int*)src)[i]; + } + + return dst; } /// @brief strlen definition in C++. -EXTERN_C size_t strlen(const char *whatToCheck) { - if (!whatToCheck || *whatToCheck == 0) return 0; +EXTERN_C size_t strlen(const char* whatToCheck) +{ + if (!whatToCheck || *whatToCheck == 0) + return 0; - SizeT len = 0; + SizeT len = 0; - while (whatToCheck[len] != 0) { - ++len; - } + while (whatToCheck[len] != 0) + { + ++len; + } - return len; + return len; } /// @brief somthing specific to the microsoft ABI, regarding checking the stack. -EXTERN_C void ___chkstk_ms(void) {} +EXTERN_C void ___chkstk_ms(void) +{ +} #endif diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 9a03b312..a04531da 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -25,7 +25,7 @@ endif IMG=epm.img IMG_2=epm-slave.img -EMU_FLAGS=-net none -smp 4 -m 4G -M q35 \ +EMU_FLAGS=-net none -smp 4 -m 8G -M q35 \ -bios OVMF.fd -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ @@ -49,9 +49,6 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -nostdlib -fno-rtti -fno-exceptions \ -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ -DD=dd -IMG_CREATE=qemu-img -MAX_KERNEL_SIZE=1024K BOOT_LOADER=NewBoot.exe KERNEL=NewKernel.exe -- cgit v1.2.3