From eb076dbf3754f44efdda926e1cc55a5c86136f5c Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 7 Jul 2024 09:39:07 +0200 Subject: MHR-36: IMP: Add ProgramLoader class, *_cast macros and patching capability. FIX: Device constructor marked as explicit. Signed-off-by: Amlal EL Mahrouss --- Boot/Sources/ProgramLoader.cxx | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Boot/Sources/ProgramLoader.cxx (limited to 'Boot/Sources/ProgramLoader.cxx') diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx new file mode 100644 index 00000000..90175bef --- /dev/null +++ b/Boot/Sources/ProgramLoader.cxx @@ -0,0 +1,66 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include +#include +#include +#include + +namespace Boot +{ + ProgramLoader::ProgramLoader(VoidPtr blob) + : fBlob(blob), fStartAddress(nullptr) + { + // detect the format. + const char* firstBytes = reinterpret_cast(fBlob); + + BTextWriter writer; + writer.WriteCharacter(firstBytes[0]).WriteCharacter(firstBytes[1]).WriteCharacter('\r').WriteCharacter('\n'); + + if (!firstBytes) + { + // failed to provide a valid pointer. + return; + } + + if (firstBytes[0] == 'M' && + firstBytes[1] == 'Z') + { + // Parse PE32+ + fStartAddress = nullptr; + } + else if (firstBytes[0] == 'J' && + firstBytes[1] == 'o' && + firstBytes[2] == 'y' && + firstBytes[3] == '!') + { + // Parse Non FAT PEF. + fStartAddress = nullptr; + } + else + { + // probably a binary blob. + fStartAddress = fBlob; + } + } + + Void ProgramLoader::Start(HEL::HandoverInformationHeader* handover) + { + if (!fStartAddress) return; + + ((HEL::HandoverProc)fStartAddress)(handover); + } + + const Char* ProgramLoader::GetName() + { + return fBlobName; + } + + Void ProgramLoader::SetName(const Char* name) + { + CopyMem(fBlobName, name, StrLen(name)); + } +} // namespace Boot \ No newline at end of file -- cgit v1.2.3