diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 20:32:18 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 20:32:18 +0100 |
| commit | b76f26d281c77e3fa028d4217a1456c43ab68d06 (patch) | |
| tree | 66cebff0951c52fbf0b5289ca4c1ee3584e33776 /Private/NewBoot/Source | |
| parent | 9fe3b6e1e2447a11644307e83df2b109b24fe0d1 (diff) | |
HCR-11 : Found the reason why it doesn't work, fixing it tomorrow.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/Entrypoint.cxx | 6 | ||||
| -rw-r--r-- | Private/NewBoot/Source/FileReader.cxx | 42 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 8 |
3 files changed, 32 insertions, 24 deletions
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx index bdcfab4d..c6ae4572 100644 --- a/Private/NewBoot/Source/Entrypoint.cxx +++ b/Private/NewBoot/Source/Entrypoint.cxx @@ -14,8 +14,8 @@ #include <KernelKit/PE.hpp> #include <NewKit/Ref.hpp> -EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle, - EfiSystemTable* SystemTable) { +EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, + EfiSystemTable* SystemTable) { InitEFI(SystemTable); InitQT(); @@ -29,7 +29,7 @@ EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle, .WriteString(SystemTable->FirmwareVendor) .WriteString(L"\r\n"); - BFileReader img(L"\\EFI\\BOOT\\HCOREKRNL.EXE"); + BFileReader img(L"HCOREKRNL.EXE"); img.Fetch(ImageHandle); VoidPtr blob = img.Blob(); diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index a66f2c71..be0e7746 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -16,6 +16,10 @@ #include <EFIKit/Api.hxx> #include <EFIKit/Handover.hxx> +#include "EFIKit/EFI.hxx" +#include "KernelKit/PE.hpp" +#include "NewKit/Defines.hpp" + //////////////////////////////////////////////////////////////////////////////////////////////////// // // @@ -85,12 +89,10 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { return; } - /// Open kernel. - - EfiFileProtocol* kernelFile; + EfiFileProtocol* kernelFile = nullptr; - if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, - kEFIReadOnly | kEFIHidden | kEFISystem) != kEfiOk) { + if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) != + kEfiOk) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ") .WriteString(mPath) .WriteString(L"\r\n"); @@ -98,6 +100,8 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { return; } + rootFs->Close(rootFs); + if (kernelFile->Revision < EFI_FILE_PROTOCOL_REVISION2) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: Invalid-Revision: ") .WriteString(mPath) @@ -108,12 +112,13 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { /// File FAT info. UInt32 szInfo = sizeof(EfiFileInfo); - EfiFileInfo info{0}; + EfiFileInfo* info = nullptr; + + BS->AllocatePool(EfiLoaderData, szInfo, (void**)&info); guidEfp = EfiGUID(EFI_FILE_INFO_GUID); - if (kernelFile->GetInfo(kernelFile, &guidEfp, &szInfo, (void*)&info) != - kEfiOk) { + if (kernelFile->GetInfo(kernelFile, &guidEfp, &szInfo, info) != kEfiOk) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ") .WriteString(mPath) .WriteString(L"\r\n"); @@ -126,23 +131,26 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { VoidPtr blob = (VoidPtr)kHandoverStartKernel; - mWriter.WriteString(L"HCoreLdr: Fetch-Info: OK...").WriteString(L"\r\n"); + if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1, + (EfiPhysicalAddress*)&blob) != kEfiOk) { + EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error."); + } + + UInt32* sz = nullptr; + + BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&sz); - UInt32 sz = info.FileSize; + *sz = info->FileSize; - BSetMem((CharacterType*)blob, 0, sz); + mWriter.WriteString(L"HCoreLdr: Fetch-Info: Read...").WriteString(L"\r\n"); - auto resultEfiRead = kernelFile->Read(kernelFile, &sz, blob); - kernelFile->Close(kernelFile); + kernelFile->Read(kernelFile, sz, blob); - if (resultEfiRead != kEfiOk) return; + mWriter.WriteString(L"HCoreLdr: Fetch-Info: Success...").WriteString(L"\r\n"); mCached = true; mErrorCode = kOperationOkay; - mBlob = blob; // We are done! - - mWriter.WriteString(L"HCoreLdr: Fetch: OK.").WriteString(L"\r\n"); } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index cf6bb579..2c08426e 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -8,7 +8,7 @@ LD_GNU=x86_64-w64-mingw32-ld ASM=nasm FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -fPIC -D__DEBUG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I../../efiSDK/inc -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ +FLAG_GNU=-fshort-wchar -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ .PHONY: invalid-recipe invalid-recipe: @@ -18,9 +18,9 @@ invalid-recipe: bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm - $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe + $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI - cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCOREKRNL.EXE + cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE .PHONY: make-disk make-disk: @@ -29,7 +29,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 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 -serial stdio + qemu-system-x86_64 -smp 8,maxcpus=16 -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 -serial stdio .PHONY: clean clean: |
