-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
67 lines (50 loc) · 1.4 KB
/
main.cpp
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
#include <cstdio>
#include <iostream>
#include <memory>
#include "hyperscan/cpu.h"
#include "hyperscan/debugger.h"
#include "hyperscan/io/io.h"
#include "hyperscan/memory/arraymemoryregion.h"
using namespace hyperscan;
/**
* TODO: make better
*/
auto createFileMemoryRegion(const char* fileName, uint32_t offset = 0) {
auto result = std::make_shared<memory::ArrayMemoryRegion<24>>();
FILE* f = fopen(fileName, "rb");
if(!f) {
fprintf(stderr, "bad file: %s", fileName);
exit(1);
}
fseek(f, 0, SEEK_END);
size_t fileSize = ftell(f);
fseek(f, 0, SEEK_SET);
if(fread(result->memory.data() + offset, 1, fileSize, f) != fileSize)
fprintf(stderr, "WARNING: Bad firmware\n");
fclose(f);
return result;
}
int main() {
CPU cpu;
cpu.miu = std::make_shared<memory::SegmentedMemoryRegion<8, 24>>();
auto firmware = createFileMemoryRegion("roms/hsfirmware.bin");
auto dram = std::make_shared<memory::ArrayMemoryRegion<24>>();
auto mmio = std::make_shared<io::IOMemoryRegion>();
cpu.miu->setRegion(0x9E, firmware);
cpu.miu->setRegion(0x9F, firmware);
cpu.miu->setRegion(0x80, dram);
cpu.miu->setRegion(0xA0, dram);
cpu.miu->setRegion(0x08, mmio);
cpu.miu->setRegion(0x88, mmio);
// XXX: Debug control register
cpu.cr29 = 0x20000000;
// Firmware entry point
cpu.pc = 0x9F000000;
// // ISO "entry point"
// cpu.pc = 0xA0091000;
debugger_enable();
while (true) {
debugger_loop(cpu);
cpu.step();
}
}