From 6c7529971d10287f0468e80093980d65a7fe6c92 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 25 Apr 2024 17:00:04 +0200 Subject: [PATCH] mmu ser/deser --- bus.cpp | 17 ++++++++++++- bus.h | 1 + mmu.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mmu.h | 10 ++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/bus.cpp b/bus.cpp index d9a6e56..c69d1dd 100644 --- a/bus.cpp +++ b/bus.cpp @@ -56,7 +56,10 @@ json_t *bus::serialize() if (tty_) json_object_set(j_out, "tty", tty_->serialize()); - // TODO: mmu, cpu, rl02, rk05, tm11 + if (mmu_) + json_object_set(j_out, "mmu", mmu_->serialize()); + + // TODO: cpu, rl02, rk05, tm11 return j_out; } @@ -85,6 +88,12 @@ bus *bus::deserialize(const json_t *const j, console *const cnsl) b->add_tty(tty_); } + temp = json_object_get(j, "mmu"); + if (temp) { + mmu *mmu_ = mmu::deserialize(temp); + b->add_mmu(mmu_); + } + // TODO: mmu, cpu, rl02, rk05, tm11 return b; @@ -135,6 +144,12 @@ void bus::add_ram(memory *const m) this->m = m; } +void bus::add_mmu(mmu *const mmu_) +{ + delete this->mmu_; + this->mmu_ = mmu_; +} + void bus::add_cpu(cpu *const c) { delete this->c; diff --git a/bus.h b/bus.h index af1ed6b..d1312ba 100644 --- a/bus.h +++ b/bus.h @@ -111,6 +111,7 @@ public: void add_ram (memory *const m ); void add_cpu (cpu *const c ); + void add_mmu (mmu *const mmu_ ); void add_tm11 (tm_11 *const tm11 ); void add_rk05 (rk05 *const rk05_ ); void add_rl02 (rl02 *const rl02_ ); diff --git a/mmu.cpp b/mmu.cpp index b0083ab..f3eaa7e 100644 --- a/mmu.cpp +++ b/mmu.cpp @@ -220,3 +220,80 @@ void mmu::writeByte(const uint16_t a, const uint8_t value) else if (a >= ADDR_PAR_U_START && a < ADDR_PAR_U_END) write_par(a, 3, value, wm_byte); } + +#if IS_POSIX +void mmu::add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) +{ + json_t *j = json_object(); + + json_t *ja_par = json_array(); + for(int i=0; i<8; i++) + json_array_append(ja_par, json_integer(pages[run_mode][is_d][i].par)); + json_object_set(j, "par", ja_par); + + json_t *ja_pdr = json_array(); + for(int i=0; i<8; i++) + json_array_append(ja_pdr, json_integer(pages[run_mode][is_d][i].pdr)); + json_object_set(j, "pdr", ja_pdr); + + json_object_set(target, name.c_str(), j); +} + +json_t *mmu::serialize() +{ + json_t *j = json_object(); + + for(int run_mode=0; run_mode<4; run_mode++) { + if (run_mode == 2) + continue; + + for(int is_d=0; is_d<2; is_d++) + add_par_pdr(j, run_mode, is_d, format("runmode_%d_d_%d", run_mode, is_d)); + } + + json_object_set(j, "MMR0", json_integer(MMR0)); + json_object_set(j, "MMR1", json_integer(MMR1)); + json_object_set(j, "MMR2", json_integer(MMR2)); + json_object_set(j, "MMR3", json_integer(MMR3)); + json_object_set(j, "CPUERR", json_integer(CPUERR)); + json_object_set(j, "PIR", json_integer(PIR)); + json_object_set(j, "CSR", json_integer(CSR)); + + return j; +} + +void mmu::set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name) +{ + json_t *j = json_object_get(j_in, name.c_str()); + + json_t *j_par = json_object_get(j, "par"); + for(int i=0; i<8; i++) + pages[run_mode][is_d][i].par = json_integer_value(json_array_get(j_par, i)); + json_t *j_pdr = json_object_get(j, "pdr"); + for(int i=0; i<8; i++) + pages[run_mode][is_d][i].pdr = json_integer_value(json_array_get(j_pdr, i)); +} + +mmu *mmu::deserialize(const json_t *const j) +{ + mmu *m = new mmu(); + + for(int run_mode=0; run_mode<4; run_mode++) { + if (run_mode == 2) + continue; + + for(int is_d=0; is_d<2; is_d++) + m->set_par_pdr(j, run_mode, is_d, format("runmode_%d_d_%d", run_mode, is_d)); + } + + m->MMR0 = json_integer_value(json_object_get(j, "MMR0")); + m->MMR1 = json_integer_value(json_object_get(j, "MMR1")); + m->MMR2 = json_integer_value(json_object_get(j, "MMR2")); + m->MMR3 = json_integer_value(json_object_get(j, "MMR3")); + m->CPUERR = json_integer_value(json_object_get(j, "CPUERR")); + m->PIR = json_integer_value(json_object_get(j, "PIR")); + m->CSR = json_integer_value(json_object_get(j, "CSR")); + + return m; +} +#endif diff --git a/mmu.h b/mmu.h index 22ed44e..3a80c0b 100644 --- a/mmu.h +++ b/mmu.h @@ -1,8 +1,10 @@ #pragma once #include +#include #include "device.h" +#include "gen.h" #define ADDR_PDR_SV_START 0172200 #define ADDR_PDR_SV_END 0172240 @@ -39,10 +41,18 @@ private: uint16_t PIR { 0 }; uint16_t CSR { 0 }; + void add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name); + void set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name); + public: mmu(); virtual ~mmu(); +#if IS_POSIX + json_t *serialize(); + static mmu *deserialize(const json_t *const j); +#endif + void reset() override; bool is_enabled() const { return MMR0 & 1; }