summaryrefslogtreecommitdiffhomepage
path: root/Boot/Sources/ProgramLoader.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Boot/Sources/ProgramLoader.cxx')
-rw-r--r--Boot/Sources/ProgramLoader.cxx48
1 files changed, 27 insertions, 21 deletions
diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx
index 90e4b624..2103414a 100644
--- a/Boot/Sources/ProgramLoader.cxx
+++ b/Boot/Sources/ProgramLoader.cxx
@@ -18,6 +18,8 @@ EXTERN_C
#include <string.h>
}
+extern EfiBootServices* BS;
+
namespace Boot
{
EXTERN_C Int32 rt_jump_to_address(HEL::HandoverProc baseCode, HEL::HandoverInformationHeader* handover, Char* stackPointer);
@@ -63,14 +65,22 @@ namespace Boot
{
ExecSectionHeaderPtr sect = &sectPtr[sectIndex];
- // if this is a code header.
- if (sect->mCharacteristics & 0x00000020)
+ EfiPhysicalAddress address_to_alloc = sect->mVirtualAddress;
+
+ // if this is a code header, then we can look for the entrypoint.
+ if (sect->mCharacteristics & eUserSection)
{
- fStartAddress = (VoidPtr)(optHdr->mAddressOfEntryPoint + sect->mPointerToRawData +
- sect->mVirtualAddress);
- writer.Write("newosldr: Start Address: ").Write((UIntPtr)fStartAddress).Write("\r");
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderCode, 1, &address_to_alloc);
- break;
+ if (!fStartAddress)
+ {
+ fStartAddress = (VoidPtr)((UIntPtr)firstBytes + optHdr->mAddressOfEntryPoint);
+ writer.Write("newosldr: Start Address set: ").Write((UIntPtr)fStartAddress).Write("\r");
+ }
+ }
+ else
+ {
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderData, 1, &address_to_alloc);
}
}
}
@@ -97,32 +107,28 @@ namespace Boot
{
BTextWriter writer;
- if (!handover ||
- ((Char*)fStartAddress)[0] == 0x0)
+ if (!handover)
{
writer.Write("newosldr: Exec format error.\r");
return;
}
- writer.Write("newosldr: Trying to run: ").Write(fBlobName).Write("\r");
+ HEL::HandoverProc err_fn = [](HEL::HandoverInformationHeader* rcx) -> void {
+ BTextWriter writer;
+ writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
+
+ EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
+ };
if (!fStartAddress)
{
- HEL::HandoverProc fn = [](HEL::HandoverInformationHeader* rcx) -> void {
- BTextWriter writer;
- writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
-
- EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
- };
-
- rt_jump_to_address(fn, handover, fStackPtr);
-
- return;
+ err_fn(handover);
}
- HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
+ volatile HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
- rt_jump_to_address(start, handover, fStackPtr);
+ start(handover);
+ err_fn(handover);
}
const Char* ProgramLoader::GetName()