From f319439314946ca5b8d38bfaa33bad92f2f6e4b6 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Fri, 3 May 2024 19:42:28 +0200 Subject: [PATCH] get_trap_action is an mmu action --- bus.cpp | 34 +--------------------------------- bus.h | 3 --- debugger.cpp | 4 ++-- mmu.cpp | 32 ++++++++++++++++++++++++++++++++ mmu.h | 6 +++++- 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/bus.cpp b/bus.cpp index de41cb1..783d250 100644 --- a/bus.cpp +++ b/bus.cpp @@ -544,38 +544,6 @@ void bus::mmudebug(const uint16_t a) } } -std::pair bus::get_trap_action(const int run_mode, const bool d, const int apf, const bool is_write) -{ - const int access_control = mmu_->get_access_control(run_mode, d, apf); - - trap_action_t trap_action = T_PROCEED; - - if (access_control == 0) - trap_action = T_ABORT_4; - else if (access_control == 1) - trap_action = is_write ? T_ABORT_4 : T_TRAP_250; - else if (access_control == 2) { - if (is_write) - trap_action = T_ABORT_4; - } - else if (access_control == 3) - trap_action = T_ABORT_4; - else if (access_control == 4) - trap_action = T_TRAP_250; - else if (access_control == 5) { - if (is_write) - trap_action = T_TRAP_250; - } - else if (access_control == 6) { - // proceed - } - else if (access_control == 7) { - trap_action = T_ABORT_4; - } - - return { trap_action, access_control }; -} - uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, const bool trap_on_failure, const bool is_write, const bool peek_only, const d_i_space_t space) { uint32_t m_offset = a; @@ -599,7 +567,7 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c if (trap_on_failure) [[unlikely]] { { - auto rc = get_trap_action(run_mode, d, apf, is_write); + auto rc = mmu_->get_trap_action(run_mode, d, apf, is_write); auto trap_action = rc.first; int access_control = rc.second; diff --git a/bus.h b/bus.h index 44461dd..119789c 100644 --- a/bus.h +++ b/bus.h @@ -52,8 +52,6 @@ class memory; class tm_11; class tty; -typedef enum { T_PROCEED, T_ABORT_4, T_TRAP_250 } trap_action_t; - typedef struct { bool is_psw; } write_rc_t; @@ -134,7 +132,6 @@ public: bool is_psw(const uint16_t addr, const int run_mode, const d_i_space_t space) const; - std::pair get_trap_action(const int run_mode, const bool d, const int apf, const bool is_write); uint32_t calculate_physical_address(const int run_mode, const uint16_t a, const bool trap_on_failure, const bool is_write, const bool peek_only, const d_i_space_t space); void check_address(const bool trap_on_failure, const bool is_write, const memory_addresses_t & addr, const word_mode_t word_mode, const bool is_data, const int run_mode); diff --git a/debugger.cpp b/debugger.cpp index 3c60733..046babc 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -521,8 +521,8 @@ void mmu_resolve(console *const cnsl, bus *const b, const uint16_t va) } for(int i=0; i<2; i++) { - auto ta_i = b->get_trap_action(run_mode, false, data.apf, i); - auto ta_d = b->get_trap_action(run_mode, true, data.apf, i); + auto ta_i = b->getMMU()->get_trap_action(run_mode, false, data.apf, i); + auto ta_d = b->getMMU()->get_trap_action(run_mode, true, data.apf, i); cnsl->put_string_lf(format("Instruction action: %s (%s)", trap_action_to_str(ta_i.first), i ? "write" : "read")); cnsl->put_string_lf(format("Data action : %s (%s)", trap_action_to_str(ta_d.first), i ? "write" : "read")); diff --git a/mmu.cpp b/mmu.cpp index e995d2c..3f28fe2 100644 --- a/mmu.cpp +++ b/mmu.cpp @@ -257,6 +257,38 @@ memory_addresses_t mmu::calculate_physical_address(const int run_mode, const uin return { a, apf, physical_instruction, physical_instruction_is_psw, physical_data, physical_data_is_psw }; } +std::pair mmu::get_trap_action(const int run_mode, const bool d, const int apf, const bool is_write) +{ + const int access_control = get_access_control(run_mode, d, apf); + + trap_action_t trap_action = T_PROCEED; + + if (access_control == 0) + trap_action = T_ABORT_4; + else if (access_control == 1) + trap_action = is_write ? T_ABORT_4 : T_TRAP_250; + else if (access_control == 2) { + if (is_write) + trap_action = T_ABORT_4; + } + else if (access_control == 3) + trap_action = T_ABORT_4; + else if (access_control == 4) + trap_action = T_TRAP_250; + else if (access_control == 5) { + if (is_write) + trap_action = T_TRAP_250; + } + else if (access_control == 6) { + // proceed + } + else if (access_control == 7) { + trap_action = T_ABORT_4; + } + + return { trap_action, access_control }; +} + #if IS_POSIX void mmu::add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) const { diff --git a/mmu.h b/mmu.h index 1dd5ef0..47f43d0 100644 --- a/mmu.h +++ b/mmu.h @@ -22,6 +22,8 @@ #define ADDR_PAR_U_END 0177700 +typedef enum { T_PROCEED, T_ABORT_4, T_TRAP_250 } trap_action_t; + typedef struct { uint16_t virtual_address; uint8_t apf; // active page field @@ -78,9 +80,11 @@ public: int get_pdr_direction (const int run_mode, const bool d, const int apf) { return pages[run_mode][d][apf].pdr & 8; } uint32_t get_physical_memory_offset(const int run_mode, const bool d, const int apf) const { return pages[run_mode][d][apf].par * 64; } bool get_use_data_space(const int run_mode) const; - memory_addresses_t calculate_physical_address(const int run_mode, const uint16_t a) const; uint32_t get_io_base() const { return getMMR0() & 1 ? (getMMR3() & 16 ? 017760000 : 0760000) : 0160000; } + memory_addresses_t calculate_physical_address(const int run_mode, const uint16_t a) const; + std::pair get_trap_action(const int run_mode, const bool d, const int apf, const bool is_write); + uint16_t getMMR0() const { return MMR0; } uint16_t getMMR1() const { return MMR1; } uint16_t getMMR2() const { return MMR2; }