From b5f9d62f55b70ea0ca55de19efed127f90a4ff46 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 25 Mar 2023 15:45:07 +0100 Subject: [PATCH] Methods for run-mode retrieval --- bus.cpp | 13 +++++++++++-- cpu.cpp | 26 +++++++++++++------------- cpu.h | 2 ++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/bus.cpp b/bus.cpp index 2728377..90db999 100644 --- a/bus.cpp +++ b/bus.cpp @@ -394,7 +394,7 @@ uint16_t bus::read(const uint16_t a, const word_mode_t word_mode, const rm_selec return 0; } - int run_mode = (c->getPSW() >> (mode_selection == rm_prev ? 12 : 14)) & 3; + int run_mode = mode_selection == rm_cur ? c->getPSW_runmode() : c->getPSW_prev_runmode(); uint32_t m_offset = calculate_physical_address(run_mode, a, !peek_only, false, peek_only, space); @@ -498,12 +498,18 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c { uint32_t m_offset = a; + if (a == 0100000) + DOLOG(info, true, "0100000: MMR0=%d", MMR0); + if ((MMR0 & 1) || (is_write && (MMR0 & (1 << 8)))) { const uint8_t apf = a >> 13; // active page field bool d = (space == d_space) & ((!!(MMR3 & di_ena_mask[run_mode])) ? space == d_space : false); uint16_t p_offset = a & 8191; // page offset + // + if (a == 0100000) + DOLOG(info, true, "0100000: APF=%d, d=%d, MMR3=%d, run_mode=%d, mask=%d, space=%d", apf, d, MMR3, run_mode, !!(MMR3 & di_ena_mask[run_mode]), space); m_offset = pages[run_mode][d][apf].par * 64; // memory offset TODO: handle 16b int-s @@ -524,6 +530,9 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c do_trap = true; } + if (a == 0100000) + DOLOG(info, true, "0100000: access_control=%d, do_trap=%d", access_control, do_trap); + if (do_trap) { bool do_trap_250 = false; @@ -685,7 +694,7 @@ void bus::write_par(const uint32_t a, const int run_mode, const uint16_t value, void bus::write(const uint16_t a, const word_mode_t word_mode, uint16_t value, const rm_selection_t mode_selection, const d_i_space_t space) { - int run_mode = (c->getPSW() >> (mode_selection == rm_prev ? 12 : 14)) & 3; + int run_mode = mode_selection == rm_cur ? c->getPSW_runmode() : c->getPSW_prev_runmode(); if ((MMR0 & 1) == 1 && (a & 1) == 0 && a != ADDR_MMR0) { const uint8_t apf = a >> 13; // active page field diff --git a/cpu.cpp b/cpu.cpp index aeb5135..e9f96a5 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -103,9 +103,9 @@ uint16_t cpu::getRegister(const int nr, const rm_selection_t mode_selection) con if (nr == 6) { if (mode_selection == rm_prev) - return sp[(getPSW() >> 12) & 3]; + return sp[getPSW_prev_runmode()]; - return sp[getPSW() >> 14]; + return sp[getPSW_runmode()]; } return pc; @@ -120,9 +120,9 @@ void cpu::setRegister(const int nr, const uint16_t value, const rm_selection_t m } else if (nr == 6) { if (mode_selection == rm_prev) - sp[(getPSW() >> 12) & 3] = value; + sp[getPSW_prev_runmode()] = value; else - sp[getPSW() >> 14] = value; + sp[getPSW_runmode()] = value; } else { pc = value; @@ -166,9 +166,9 @@ uint16_t cpu::addRegister(const int nr, const rm_selection_t mode_selection, con if (nr == 6) { if (mode_selection == rm_prev) - return sp[(getPSW() >> 12) & 3] += value; + return sp[getPSW_prev_runmode()] += value; - return sp[getPSW() >> 14] += value; + return sp[getPSW_runmode()] += value; } return pc += value; @@ -315,7 +315,7 @@ gam_rc_t cpu::getGAM(const uint8_t mode, const uint8_t reg, const word_mode_t wo { gam_rc_t g { word_mode, mode_selection, i_space, { }, { }, { } }; - d_i_space_t isR7_space = reg == 7 ? i_space : (b->get_use_data_space(psw >> 14) ? d_space : i_space); + d_i_space_t isR7_space = reg == 7 ? i_space : (b->get_use_data_space(getPSW_runmode()) ? d_space : i_space); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ always d_space here? TODO g.space = isR7_space; @@ -1225,8 +1225,8 @@ bool cpu::single_operand_instructions(const uint16_t instr) v = b->read(a.addr.value(), wm_word, rm_prev); } else { - int run_mode = (getPSW() >> 12) & 3; - auto phys = b->calculate_physical_address(run_mode, a.addr.value()); + int run_mode = getPSW_prev_runmode(); + auto phys = b->calculate_physical_address(run_mode, a.addr.value()); uint32_t a = word_mode == wm_byte ? phys.physical_data : phys.physical_instruction; @@ -1265,7 +1265,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) if (a.addr.value() >= 0160000) b->write(a.addr.value(), wm_word, v, rm_prev); // put in '13/12' address space else { - int run_mode = (getPSW() >> 12) & 3; + int run_mode = getPSW_prev_runmode(); auto phys = b->calculate_physical_address(run_mode, a.addr.value()); DOLOG(debug, true, "%lu %06o MTP%c %06o: %06o", mtpi_count, pc-2, word_mode == wm_byte ? 'D' : 'I', a.addr.value(), v); @@ -1497,7 +1497,7 @@ bool cpu::misc_operations(const uint16_t instr) case 0b0000000000000010: // RTI setPC(popStack()); - setPSW(popStack(), !!((getPSW() >> 12) & 3)); + setPSW(popStack(), !!getPSW_prev_runmode()); return true; case 0b0000000000000011: // BPT @@ -1510,7 +1510,7 @@ bool cpu::misc_operations(const uint16_t instr) case 0b0000000000000110: // RTT setPC(popStack()); - setPSW(popStack(), !!((getPSW() >> 12) & 3)); + setPSW(popStack(), !!getPSW_prev_runmode()); return true; case 0b0000000000000111: // MFPT @@ -1603,7 +1603,7 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt) try { processing_trap_depth++; - bool kernel_mode = psw >> 14; + bool kernel_mode = psw >> 14; // TODO wrong? if (processing_trap_depth >= 2) { DOLOG(debug, true, "Trap depth %d", processing_trap_depth); diff --git a/cpu.h b/cpu.h index 1dba52d..11163ae 100644 --- a/cpu.h +++ b/cpu.h @@ -111,6 +111,8 @@ public: bool getPSW_n() const; int getPSW_spl() const; bool getBitPSW(const int bit) const; + int getPSW_runmode() const { return psw >> 14; }; + int getPSW_prev_runmode() const { return (psw >> 12) & 3; }; void setPSW_c(const bool v); void setPSW_v(const bool v);