diff options
| author | Julian Blake Kongslie | 2022-10-08 00:39:15 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-08 00:39:15 -0700 |
| commit | 85b34e1c9dc03585ec4f13f6241cd8f0ecaf9cd9 (patch) | |
| tree | 0ec9a990fab8c06d0e2c6aa67447f3a8003aaf3d /isa | |
| parent | Minor cleanup and some compilation fixes. (diff) | |
| download | biggolf-85b34e1c9dc03585ec4f13f6241cd8f0ecaf9cd9.tar.xz | |
Trivial support for running the checker on an image.
Diffstat (limited to '')
| -rw-r--r-- | isa/checker.cpp | 2 | ||||
| -rw-r--r-- | isa/checker.h | 33 |
2 files changed, 31 insertions, 4 deletions
diff --git a/isa/checker.cpp b/isa/checker.cpp index 604279a..05b59a9 100644 --- a/isa/checker.cpp +++ b/isa/checker.cpp | |||
| @@ -10,7 +10,7 @@ void checker::execute() { | |||
| 10 | // check for interrupt | 10 | // check for interrupt |
| 11 | } | 11 | } |
| 12 | ctlregs[INT_ENABLE] = (int_enable_delay << 1) | int_enable_delay; | 12 | ctlregs[INT_ENABLE] = (int_enable_delay << 1) | int_enable_delay; |
| 13 | auto inst = decode(ctlregs[DATA_INSTRUCTION_FIELD_BUFFER], | 13 | inst = decode(ctlregs[DATA_INSTRUCTION_FIELD_BUFFER], |
| 14 | pc, | 14 | pc, |
| 15 | mem.fetch(pc)); | 15 | mem.fetch(pc)); |
| 16 | auto next_pc = inst.next_pc; | 16 | auto next_pc = inst.next_pc; |
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 | ||
| 7 | struct funcmem { | 8 | struct 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 | ||
| 12 | struct checker { | 38 | struct 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(); |
