diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-05 10:53:58 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-05 10:53:58 +0100 |
| commit | f8c9b81ff120160af60af6e9d44cba338aceb65a (patch) | |
| tree | cb4683589aab4d50470628f189dc366814fd80ad /Private/NewBoot/Source | |
| parent | e03903b98aa0b4d2dc3ed4637863124f28c4e1fe (diff) | |
Kernel: Improved kernel design and Bootloader runs on real hardware!
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/Entrypoint.cxx | 13 | ||||
| -rw-r--r-- | Private/NewBoot/Source/FileReader.cxx | 45 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx | 20 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 10 |
4 files changed, 44 insertions, 44 deletions
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx index c6ae4572..2ef057ba 100644 --- a/Private/NewBoot/Source/Entrypoint.cxx +++ b/Private/NewBoot/Source/Entrypoint.cxx @@ -21,19 +21,20 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, BTextWriter writer; - writer.WriteString(L"HCoreLdr: ") - .WriteString(L"Copyright Mahrouss-Logic Corporation.") - .WriteString(L"\r\n"); - - writer.WriteString(L"HCoreLdr: Firmware: ") + writer.WriteString(L"HCoreLdr: Firmware Vendor: ") .WriteString(SystemTable->FirmwareVendor) .WriteString(L"\r\n"); BFileReader img(L"HCOREKRNL.EXE"); - img.Fetch(ImageHandle); + img.ReadAll(ImageHandle); VoidPtr blob = img.Blob(); + if (!blob) { + EFI::RaiseHardError(L"HCoreLdr_NoBlob", L"No Such blob."); + return kEfiFail; + } + UInt64 MapKey = 0; EFI::ExitBootServices(MapKey, ImageHandle); diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index be0e7746..a18c5093 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -17,8 +17,7 @@ #include <EFIKit/Handover.hxx> #include "EFIKit/EFI.hxx" -#include "KernelKit/PE.hpp" -#include "NewKit/Defines.hpp" +#include "NewKit/Macros.hpp" //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -46,14 +45,21 @@ BFileReader::~BFileReader() { if (this->mBlob) { BS->FreePool(this->mBlob); } + + if (this->mFile) { + this->mFile->Close(this->mFile); + this->mFile = nullptr; + } + + BSetMem(this->mPath, 0, kPathLen); } /** @brief this reads all of the buffer. @param ImageHandle used internally. */ -Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { - mWriter.WriteString(L"HCoreLdr: Fetch-File: ") +Void BFileReader::ReadAll(EfiHandlePtr ImageHandle) { + mWriter.WriteString(L"HCoreLdr: ReadAll: ") .WriteString(mPath) .WriteString(L"\r\n"); @@ -102,13 +108,6 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { rootFs->Close(rootFs); - if (kernelFile->Revision < EFI_FILE_PROTOCOL_REVISION2) { - mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: Invalid-Revision: ") - .WriteString(mPath) - .WriteString(L"\r\n"); - return; - } - /// File FAT info. UInt32 szInfo = sizeof(EfiFileInfo); @@ -126,8 +125,7 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { return; } - mWriter.WriteString(L"HCoreLdr: Fetch-Info: In-Progress...") - .WriteString(L"\r\n"); + /// Allocate Handover page. VoidPtr blob = (VoidPtr)kHandoverStartKernel; @@ -136,21 +134,14 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error."); } - UInt32* sz = nullptr; - - BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&sz); - - *sz = info->FileSize; - - mWriter.WriteString(L"HCoreLdr: Fetch-Info: Read...").WriteString(L"\r\n"); - - kernelFile->Read(kernelFile, sz, blob); - - mWriter.WriteString(L"HCoreLdr: Fetch-Info: Success...").WriteString(L"\r\n"); - - mCached = true; + mSizeFile = info->FileSize; + mFile = kernelFile; mErrorCode = kOperationOkay; mBlob = blob; - // We are done! + this->File()->Read(this->File(), &mSizeFile, this->Blob()); + + mWriter.WriteString(L"HCoreLdr: ReadAll: OK: ") + .WriteString(mPath) + .WriteString(L"\r\n"); } diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx index 2ef2189c..757c294d 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx @@ -57,39 +57,45 @@ Void ATASelect(UInt16 Bus) { Boolean ATAInitDriver(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { + if (IsATADetected()) return false; + BTextWriter writer; UInt16 IO = Bus; - // Bus init, NEIN bit. - Out8(IO + 1, 1); - ATASelect(IO); + // Bus init, NEIN bit. + Out8(IO + ATA_REG_NEIN, 1); + // identify until it's good. ATAInit_Retry: auto statRdy = In8(IO + ATA_REG_STATUS); if (statRdy & ATA_SR_ERR) { writer.WriteString( - L"HCoreLdr: ATA: Hard-drive error, not an IDE drive.\r\n"); + L"HCoreLdr: ATA: Select error, not an IDE based hard-drive.\r\n"); + return false; } + if ((statRdy & ATA_SR_BSY)) goto ATAInit_Retry; Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + BSetMem(kATAData, 0, kATADataLen); + for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = In16(IO + ATA_REG_DATA); } - writer.WriteString(L"HCoreLdr: Drive: "); + writer.WriteString(L"HCoreLdr: Model: "); /// fetch drive info for (SizeT indexData = 0; indexData < kATADataLen; indexData += 1) { - writer.WriteCharacter(kATAData[indexData + 1]) - .WriteCharacter(kATAData[indexData]); + writer.WriteCharacter(kATAData[indexData + ATA_IDENT_MODEL + 1]) + .WriteCharacter(kATAData[indexData + ATA_IDENT_MODEL]); } writer.WriteString(L"\r\n"); diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 2c08426e..02990084 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -5,10 +5,12 @@ CC_GNU=x86_64-w64-mingw32-g++ LD_GNU=x86_64-w64-mingw32-ld +LD_FLAGS=-e efi_main -shared --subsystem=10 -ffreestanding ASM=nasm +OBJ=$(wildcard *.obj) $(wildcard *.o) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o) FLAG_ASM=-f win64 -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)/ +FLAG_GNU=-fshort-wchar -O0 -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,7 +20,7 @@ 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 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE @@ -29,8 +31,8 @@ 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 -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 + qemu-system-x86_64 -smp 2 -m 4G -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: - rm -f *.o HCoreLdr.exe OVMF.fd + rm -f $(OBJ) HCoreLdr.exe OVMF.fd |
