From 85b34e1c9dc03585ec4f13f6241cd8f0ecaf9cd9 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sat, 8 Oct 2022 00:39:15 -0700 Subject: Trivial support for running the checker on an image. --- isa/checker.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'isa/checker.h') 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 @@ #pragma once #include +#include #include "isa/isa.h" struct funcmem { - unsigned int fetch(unsigned int address); - void store(unsigned int address, unsigned int value); + 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 page; + + std::map 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 checker { unsigned int acc = 0; unsigned int link = 0; - unsigned int pc = 0; + unsigned int pc = 00200; std::array ctlregs; + instruction_context inst; bool halted = false; funcmem mem; void execute(); -- cgit v1.2.3