blob: 0603fb9c213138541fd23bba973a044be184f76a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* -------------------------------------------
Copyright Zeta Electronics Corporation
------------------------------------------- */
#include <BootKit/ProgramLoader.hxx>
#include <BootKit/Vendor/Support.hxx>
#include <BootKit/BootKit.hxx>
EXTERN_C
{
#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;
if (!firstBytes)
{
// failed to provide a valid pointer.
return;
}
if (firstBytes[0] == 'M' &&
firstBytes[1] == 'Z')
{
// Parse PE32+
fStartAddress = nullptr;
writer.Write("newosldr: MZ executable detected.\r");
}
else if (firstBytes[0] == 'J' &&
firstBytes[1] == 'o' &&
firstBytes[2] == 'y' &&
firstBytes[3] == '!')
{
// Parse Non FAT PEF.
fStartAddress = nullptr;
writer.Write("newosldr: PEF executable detected.\r");
}
else
{
// probably a binary blob.
fStartAddress = fBlob;
}
}
Void ProgramLoader::Start(HEL::HandoverInformationHeader* handover)
{
BTextWriter writer;
writer.Write("newosldr: running: ").Write(fBlobName).Write("\r");
if (!fStartAddress)
{
writer.Write("newosldr: exec error.\r");
return;
}
((HEL::HandoverProc)fStartAddress)(handover);
}
const Char* ProgramLoader::GetName()
{
return fBlobName;
}
Void ProgramLoader::SetName(const Char* name)
{
CopyMem(fBlobName, name, StrLen(name));
}
} // namespace Boot
|