diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 10:59:24 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 10:59:24 +0100 |
| commit | e2bbec91d70847cc5a2ff67eb84ca4a3c2d03e85 (patch) | |
| tree | 1e7fec7c232b0c750157007113ce8f86d43b7e76 /Private/NewBoot/Source | |
| parent | aff54fd3dc6855b62c047f126c6fe20ca717ee0f (diff) | |
Kernel: Depend less on NewFS, add support for FileSystem protocol in
NewBoot.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/Entrypoint.cxx | 19 | ||||
| -rw-r--r-- | Private/NewBoot/Source/FileReader.cxx | 118 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx | 1 | ||||
| -rw-r--r-- | Private/NewBoot/Source/String.cxx | 1 | ||||
| -rw-r--r-- | Private/NewBoot/Source/TextWriter.cxx | 1 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 3 |
6 files changed, 120 insertions, 23 deletions
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx index 39769b87..4839ee1f 100644 --- a/Private/NewBoot/Source/Entrypoint.cxx +++ b/Private/NewBoot/Source/Entrypoint.cxx @@ -7,7 +7,6 @@ * ======================================================== */ -#include "BootKit/Arch/ATA.hxx" #define __BOOTLOADER__ 1 #include <BootKit/BootKit.hxx> @@ -43,26 +42,18 @@ EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle, UInt64 mapKey = 0; - BFileReader img(L"HCoreKrnl.exe"); + BFileReader img(L"\\EFI\\BOOT\\HCoreKrnl.exe"); - SizeT sz = 0UL; - PEImagePtr blob = (PEImagePtr)img.Fetch(sz); + PEImagePtr blob = (PEImagePtr)img.Fetch(ImageHandle); - if (!blob || sz < 1) + if (!blob) EFI::RaiseHardError(L"HCoreLdr_NoSuchKernel", L"Couldn't find HCoreKrnl.exe!"); - ExecHeaderPtr headerPtr = (ExecHeaderPtr)blob; + writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n"); - if (blob[0] == kMagMz0 && blob[1] == kMagMz1) { - writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n"); - /// Load Image here - } else { - EFI::RaiseHardError(L"HCoreLdr_NotPE", L"Not a PE file! Aborting..."); - } - - EFI::Stop(); EFI::ExitBootServices(mapKey, ImageHandle); + EFI::Stop(); return kEfiOk; } diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index 39884f9f..3edacb5a 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -14,7 +14,8 @@ #include <BootKit/BootKit.hxx> #include <EFIKit/Api.hxx> -#include <FSKit/NewFS.hxx> + +#include "EFIKit/EFI.hxx" //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -27,7 +28,7 @@ /*** @brief File Reader constructor. */ -BFileReader::BFileReader(const CharacterType *path) { +BFileReader::BFileReader(const CharacterType* path) { if (path != nullptr) { SizeT index = 0UL; for (; path[index] != L'\0'; ++index) { @@ -38,17 +39,122 @@ BFileReader::BFileReader(const CharacterType *path) { } } +BFileReader::~BFileReader() { + if (this->mBlob) { + BS->FreePool(this->mBlob); + } +} + /** @brief this reads all of the buffer. - @param size, new buffer size. + @param ImageHandle used internally. */ -HCore::VoidPtr BFileReader::Fetch(SizeT &size) { +HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle) { mWriter.WriteString(L"HCoreLdr: Fetch-File: ") .WriteString(mPath) .WriteString(L"\r\n"); + /// 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->OpenProtocol(ImageHandle, &guidImg, (void**)&img, ImageHandle, + nullptr, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL) != kEfiOk) { + mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol") + .WriteString(L"\r\n"); + this->mErrorCode = kNotSupported; + } + + if (BS->OpenProtocol(img->DeviceHandle, &guidEfp, (void**)&efp, ImageHandle, + nullptr, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL) != kEfiOk) { + mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol") + .WriteString(L"\r\n"); + this->mErrorCode = kNotSupported; + return nullptr; + } + + /// Start doing disk I/O + + if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { + mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Volume") + .WriteString(L"\r\n"); + this->mErrorCode = kNotSupported; + return nullptr; + } + + /// Open kernel. + + EfiFileProtocol* kernelFile; + + if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, + kEFIReadOnly | kEFIHidden | kEFISystem) != kEfiOk) { + mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ") + .WriteString(mPath) + .WriteString(L"\r\n"); + this->mErrorCode = kNotSupported; + return nullptr; + } + + /// File FAT info. + + UInt32 szInfo = sizeof(EfiFileInfo); + EfiFileInfo info{0}; + + guidEfp = EfiGUID(EFI_FILE_INFO_GUID); + + if (kernelFile->GetInfo(kernelFile, &guidEfp, &szInfo, (void*)&info) != + kEfiOk) { + mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ") + .WriteString(mPath) + .WriteString(L"\r\n"); + this->mErrorCode = kNotSupported; + return nullptr; + } + + mWriter.WriteString(L"HCoreLdr: Fetch-Info: In-Progress...") + .WriteString(L"\r\n"); + + UInt8* blob = nullptr; + + mWriter.WriteString(L"HCoreLdr: Fetch-Info: OK...").WriteString(L"\r\n"); + + UInt64 sz = info.FileSize; + + if (BS->AllocatePool(EfiBootServicesData, sz, (VoidPtr*)&blob) != kEfiOk) { + mWriter + .WriteString( + L"HCoreLdr: Fetch: Failed to call AllocatePool " + L"correctly!") + .WriteString(L"\r\n"); + + kernelFile->Close(kernelFile); + + return nullptr; + } + + BSetMem((CharacterType*)blob, 0, sz); + + mWriter.WriteString(L"HCoreLdr: Fetch-File: In-Progress...") + .WriteString(L"\r\n"); + + kernelFile->Read(kernelFile, &sz, blob); + + mWriter.WriteString(L"HCoreLdr: Fetch-File: OK").WriteString(L"\r\n"); + + kernelFile->Close(kernelFile); + this->mCached = true; - this->mErrorCode = kNotSupported; + this->mErrorCode = kOperationOkay; + + this->mBlob = blob; - return nullptr; + return blob; } diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx index 20af043d..46bec94c 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx @@ -71,6 +71,7 @@ ATAInit_Retry: auto statRdy = In8(IO + ATA_REG_STATUS); if (statRdy & ATA_SR_ERR) { + writer.WriteString(L"HCoreLdr: Probe error.\r\n"); return false; } if ((statRdy & ATA_SR_BSY)) goto ATAInit_Retry; diff --git a/Private/NewBoot/Source/String.cxx b/Private/NewBoot/Source/String.cxx index e080a01d..c59e2bba 100644 --- a/Private/NewBoot/Source/String.cxx +++ b/Private/NewBoot/Source/String.cxx @@ -13,7 +13,6 @@ #include <BootKit/BootKit.hxx> #include <EFIKit/Api.hxx> -#include <FSKit/NewFS.hxx> /// bugs 0 diff --git a/Private/NewBoot/Source/TextWriter.cxx b/Private/NewBoot/Source/TextWriter.cxx index 77baa067..b6a8e3b8 100644 --- a/Private/NewBoot/Source/TextWriter.cxx +++ b/Private/NewBoot/Source/TextWriter.cxx @@ -13,7 +13,6 @@ #include <BootKit/BootKit.hxx> #include <EFIKit/Api.hxx> -#include <FSKit/NewFS.hxx> /// bugs 0 diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 460b5dc1..3deef8f4 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -19,6 +19,7 @@ bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI + cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCoreKrnl.exe .PHONY: make-disk make-disk: @@ -27,7 +28,7 @@ make-disk: .PHONY: run-efi-debug run-efi-debug: wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - qemu-system-x86_64 -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -d int + qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -d int .PHONY: clean clean: |
