-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory.cc
39 lines (32 loc) · 819 Bytes
/
Memory.cc
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
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "Memory.h"
#include <fstream>
using namespace llvm;
ArrayRef<uint8_t> Memory::getMemDataRef(uint32_t Start, uint32_t Len)
{
assert(Start + Len < MemorySize());
return {getPointer(Start), Len};
}
void Memory::setRom(StringRef RomName)
{
set(RomName, 0x8000000);
}
void Memory::setBios(StringRef RomName)
{
set(RomName, 0);
}
void Memory::set(StringRef RomName, int32_t Start)
{
auto Buffer = MemoryBuffer::getFile(RomName);
if (Buffer.getError()) {
errs() << "BIOS loading failed\n";
exit(-1);
}
const char *I = (*Buffer)->getBufferStart();
const char *End = (*Buffer)->getBufferEnd();
for (int j = Start; I != End; ++I, j++) {
InternalMem[j] = (uint8_t)*I;
}
}