blob: 30a8356b8b2ab2f4c70c7fdc989c6ba606a0f890 (
plain) (
blame)
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
|
#pragma once
#include <array>
#include <cstdint>
#include <map>
#include "io/model.h"
#include "isa/isa.h"
struct funcmem {
static constexpr unsigned int PAGE_BYTES_LOG2 = 20;
static constexpr unsigned int PAGE_BYTES = 1 << PAGE_BYTES_LOG2;
static constexpr unsigned int PAGE_BYTE_OFFSET_MASK = PAGE_BYTES - 1;
typedef std::array<unsigned int, PAGE_BYTES> page;
std::map<unsigned int, page> image;
unsigned int fetch(unsigned int address) const {
auto page_address = address >> PAGE_BYTES_LOG2;
auto page_offset = address & PAGE_BYTE_OFFSET_MASK;
if (auto p = image.find(page_address); p != image.end()) {
const auto &page = p->second;
return page[page_offset];
}
return 0;
}
void store(unsigned int address, unsigned int value) {
auto page_address = address >> PAGE_BYTES_LOG2;
auto page_offset = address & PAGE_BYTE_OFFSET_MASK;
auto [p, emplaced] = image.try_emplace(page_address);
auto &page = p->second;
if (emplaced)
page.fill(0);
page[page_offset] = value;
}
};
struct funcchecker {
unsigned int acc = 0;
unsigned int link = 0;
unsigned int mq = 0;
unsigned int pc = 000200;
std::array<std::uint_fast32_t, NUM_CTLREGS> ctlregs;
std::uint64_t icount = 0;
bool interrupt = false;
iomodel &system;
instruction_context inst;
funcmem mem;
funcchecker(iomodel &system)
: system(system)
{
ctlregs.fill(0);
ctlregs[TT_FLAGS] = TTF_INT_ENABLE;
}
void execute();
bool done() {
return ctlregs[HALTED] && system.done(icount);
}
};
|