summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-14 13:06:07 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-14 13:06:07 +0100
commit41b1d0483dead754bb054bb4139cbc69fec84f36 (patch)
tree1f69c6a616935406c251438dc391b0f56ca1fc05 /Private
parentc49a4199373d546703ea2016f188131648a39a68 (diff)
HCR-18: NewBoot: Getting more work done...
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/HALKit/AMD64/HalStartSequence.asm4
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx54
-rw-r--r--Private/NewBoot/Source/makefile2
3 files changed, 27 insertions, 33 deletions
diff --git a/Private/HALKit/AMD64/HalStartSequence.asm b/Private/HALKit/AMD64/HalStartSequence.asm
index c8e0a4e2..1db3b218 100644
--- a/Private/HALKit/AMD64/HalStartSequence.asm
+++ b/Private/HALKit/AMD64/HalStartSequence.asm
@@ -31,10 +31,6 @@ section .text
;; Just a simple setup, we'd also need to tell some before
Main:
- push rcx
- jmp RuntimeMain
- pop rcx
-L0:
cli
hlt
jmp $
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 4c9d3b8f..afca21eb 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -7,6 +7,7 @@
* ========================================================
*/
+#include "EFIKit/EFI.hxx"
#define __BOOTLOADER__ 1
#include <BootKit/BootKit.hxx>
@@ -25,7 +26,7 @@
#endif
-#define kBufferReadSz 2048
+#define kBufferReadSz 4096
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
@@ -73,42 +74,35 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
ExecOptionalHeaderPtr optHdr = reinterpret_cast<ExecOptionalHeaderPtr>(
ptrHdr + sizeof(ExecHeader));
- UInt64 baseCode = optHdr->mBaseOfCode;
- UInt64 codeSz = optHdr->mSizeOfCode;
- VoidPtr codePtr = nullptr;
+ UInt64 baseSec = ptrHdr->mNumberOfSections;
+ img.File()->SetPosition(img.File(), &baseSec);
- img.File()->SetPosition(img.File(), &baseCode);
+ baseSec = ptrHdr->mNumberOfSections;
+ ExecSectionHeaderPtr headers =
+ (ExecSectionHeaderPtr)(&ptrHdr->mCharacteristics + 1);
- BS->AllocatePool(EfiLoaderCode, codeSz, &codePtr);
+ for (int i = 0u; i < ptrHdr->mNumberOfSections; ++i) {
+ auto& hdr = headers[i];
- writer.WriteString(L"HCoreLdr: Init [0/2]...\r\n");
+ if (hdr.mName[0] != '.') continue;
- if (!codePtr) {
- EFI::RaiseHardError(L"HCoreLdr-BadAlloc",
- L"Bad Alloc! (AllocatePool)");
- }
+ writer.WriteString(L"HCoreLdr: Mapping: ");
+ for (auto ch : hdr.mName) writer.WriteCharacter(ch);
- img.File()->Read(img.File(), &codeSz, codePtr);
+ writer.WriteString(L"\r\n");
- /// GET DATA
+ UInt64 addr = hdr.mVirtualAddress;
- UInt64 baseData = optHdr->mBaseOfData;
- UInt64 sizeofData =
- optHdr->mSizeOfInitializedData + optHdr->mSizeOfUninitializedData;
- VoidPtr dataPtr = nullptr;
+ BS->AllocatePages(AllocateAnyPages, EfiLoaderCode, 1, &addr);
- BS->AllocatePool(EfiLoaderCode, sizeofData, &dataPtr);
+ UInt64 pos = (optHdr->mImageBase + optHdr->mBaseOfData) +
+ hdr.mPointerToRawData;
- if (!dataPtr) {
- EFI::RaiseHardError(L"HCoreLdr: BadAlloc", L"(AllocatePool)");
+ img.File()->SetPosition(img.File(), &pos);
+ img.Size(hdr.mSizeOfRawData);
+ img.File()->Read(img.File(), &img.Size(), (VoidPtr)addr);
}
- writer.WriteString(L"HCoreLdr: Init [1/2]...\r\n");
-
- img.File()->SetPosition(img.File(), &baseData);
-
- img.File()->Read(img.File(), &sizeofData, dataPtr);
-
UInt32 MapKey = 0;
UInt32* Size = 0;
EfiMemoryDescriptor* Descriptor = nullptr;
@@ -135,8 +129,6 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
L"Bad Alloc! (GetMemoryMap)");
}
- writer.WriteString(L"HCoreLdr: Init [2/2]...\r\n");
-
HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
@@ -167,6 +159,12 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EFI::ExitBootServices(MapKey, ImageHandle);
+ HCore::HEL::HandoverProc proc =
+ reinterpret_cast<HCore::HEL::HandoverProc>(
+ optHdr->mAddressOfEntryPoint);
+
+ proc(handoverHdrPtr);
+
EFI::Stop();
return kEfiOk;
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index d17f9671..fab7453d 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -27,7 +27,7 @@ bootloader-amd64:
.PHONY: run-efi-amd64
run-efi-amd64:
wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
- qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -d int
+ qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
.PHONY: clean
clean: