1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-09 05:25:01 +00:00

Unify reads.

This commit is contained in:
Thomas Harte
2024-03-02 23:15:17 -05:00
parent 1663d3d9d1
commit 62da0dee7f
3 changed files with 17 additions and 11 deletions

View File

@@ -554,6 +554,10 @@ struct Executor {
return registers_.pc(0); return registers_.pc(0);
} }
Mode mode() const {
return registers_.mode();
}
private: private:
Registers registers_; Registers registers_;
}; };

View File

@@ -95,7 +95,7 @@ struct Registers {
} }
} }
Mode mode() { Mode mode() const {
return mode_; return mode_;
} }

View File

@@ -16,6 +16,8 @@ using namespace InstructionSet::ARM;
namespace { namespace {
struct Memory { struct Memory {
std::vector<uint8_t> rom;
template <typename IntT> template <typename IntT>
bool write(uint32_t address, IntT source, Mode mode, bool trans) { bool write(uint32_t address, IntT source, Mode mode, bool trans) {
(void)address; (void)address;
@@ -27,8 +29,13 @@ struct Memory {
template <typename IntT> template <typename IntT>
bool read(uint32_t address, IntT &source, Mode mode, bool trans) { bool read(uint32_t address, IntT &source, Mode mode, bool trans) {
(void)address; if(address > 0x3800000) {
(void)source; source = *reinterpret_cast<const IntT *>(&rom[address - 0x3800000]);
} else {
// TODO: this is true only very transiently.
source = *reinterpret_cast<const IntT *>(&rom[address]);
}
(void)mode; (void)mode;
(void)trans; (void)trans;
return true; return true;
@@ -192,18 +199,13 @@ struct Memory {
ROM::Request request(rom_name); ROM::Request request(rom_name);
const auto roms = CSROMFetcher()(request); const auto roms = CSROMFetcher()(request);
const auto rom = roms.find(rom_name)->second; Executor<Model::ARMv2, Memory> executor;
executor.bus_.rom = roms.find(rom_name)->second;
uint32_t pc = 0; uint32_t pc = 0;
Executor<Model::ARMv2, Memory> executor;
for(int c = 0; c < 100; c++) { for(int c = 0; c < 100; c++) {
uint32_t instruction; uint32_t instruction;
executor.bus_.read(pc, instruction, executor.mode(), false);
if(pc > 0x3800000) {
instruction = *reinterpret_cast<const uint32_t *>(&rom[pc - 0x3800000]);
} else {
instruction = *reinterpret_cast<const uint32_t *>(&rom[pc]);
}
printf("%08x: %08x\n", pc, instruction); printf("%08x: %08x\n", pc, instruction);
dispatch<Model::ARMv2>(pc, instruction, executor); dispatch<Model::ARMv2>(pc, instruction, executor);