diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-07-07 09:39:07 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-07-07 09:39:07 +0200 |
| commit | eb076dbf3754f44efdda926e1cc55a5c86136f5c (patch) | |
| tree | 6391d97d885dcf6d85f8824aec29c60c4dea2d78 /Boot/Sources/ProgramLoader.cxx | |
| parent | e477d85ffea45a92aea7a2942bdfb9240fed80bc (diff) | |
MHR-36: IMP: Add ProgramLoader class, *_cast macros and patching capability.
FIX: Device constructor marked as explicit.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Boot/Sources/ProgramLoader.cxx')
| -rw-r--r-- | Boot/Sources/ProgramLoader.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
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 <BootKit/ProgramLoader.hxx> +#include <BootKit/Vendor/Support.hxx> +#include <BootKit/BootKit.hxx> +#include <string.h> + +namespace Boot +{ + ProgramLoader::ProgramLoader(VoidPtr blob) + : fBlob(blob), fStartAddress(nullptr) + { + // detect the format. + const char* firstBytes = reinterpret_cast<char*>(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 |
