summaryrefslogtreecommitdiff
path: root/isa/checker.h
diff options
context:
space:
mode:
Diffstat (limited to 'isa/checker.h')
-rw-r--r--isa/checker.h33
1 files changed, 30 insertions, 3 deletions
diff --git a/isa/checker.h b/isa/checker.h
index 6aae3ff..70393b6 100644
--- a/isa/checker.h
+++ b/isa/checker.h
@@ -1,19 +1,46 @@
1#pragma once 1#pragma once
2 2
3#include <array> 3#include <array>
4#include <map>
4 5
5#include "isa/isa.h" 6#include "isa/isa.h"
6 7
7struct funcmem { 8struct funcmem {
8 unsigned int fetch(unsigned int address); 9 static constexpr unsigned int PAGE_BYTES_LOG2 = 20;
9 void store(unsigned int address, unsigned int value); 10 static constexpr unsigned int PAGE_BYTES = 1 << PAGE_BYTES_LOG2;
11 static constexpr unsigned int PAGE_BYTE_OFFSET_MASK = PAGE_BYTES - 1;
12
13 typedef std::array<unsigned int, PAGE_BYTES> page;
14
15 std::map<unsigned int, page> image;
16
17 unsigned int fetch(unsigned int address) const {
18 auto page_address = address >> PAGE_BYTES_LOG2;
19 auto page_offset = address & PAGE_BYTE_OFFSET_MASK;
20 if (auto p = image.find(page_address); p != image.end()) {
21 const auto &page = p->second;
22 return page[page_offset];
23 }
24 return 0;
25 }
26
27 void store(unsigned int address, unsigned int value) {
28 auto page_address = address >> PAGE_BYTES_LOG2;
29 auto page_offset = address & PAGE_BYTE_OFFSET_MASK;
30 auto [p, emplaced] = image.try_emplace(page_address);
31 auto &page = p->second;
32 if (emplaced)
33 page.fill(0);
34 page[page_offset] = value;
35 }
10}; 36};
11 37
12struct checker { 38struct checker {
13 unsigned int acc = 0; 39 unsigned int acc = 0;
14 unsigned int link = 0; 40 unsigned int link = 0;
15 unsigned int pc = 0; 41 unsigned int pc = 00200;
16 std::array<unsigned int, NUM_CTLREGS> ctlregs; 42 std::array<unsigned int, NUM_CTLREGS> ctlregs;
43 instruction_context inst;
17 bool halted = false; 44 bool halted = false;
18 funcmem mem; 45 funcmem mem;
19 void execute(); 46 void execute();