Methods for run-mode retrieval

This commit is contained in:
folkert van heusden 2023-03-25 15:45:07 +01:00
parent d66650b5b2
commit b5f9d62f55
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 26 additions and 15 deletions

13
bus.cpp
View file

@ -394,7 +394,7 @@ uint16_t bus::read(const uint16_t a, const word_mode_t word_mode, const rm_selec
return 0; 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); 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; uint32_t m_offset = a;
if (a == 0100000)
DOLOG(info, true, "0100000: MMR0=%d", MMR0);
if ((MMR0 & 1) || (is_write && (MMR0 & (1 << 8)))) { if ((MMR0 & 1) || (is_write && (MMR0 & (1 << 8)))) {
const uint8_t apf = a >> 13; // active page field const uint8_t apf = a >> 13; // active page field
bool d = (space == d_space) & ((!!(MMR3 & di_ena_mask[run_mode])) ? space == d_space : false); bool d = (space == d_space) & ((!!(MMR3 & di_ena_mask[run_mode])) ? space == d_space : false);
uint16_t p_offset = a & 8191; // page offset 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 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; do_trap = true;
} }
if (a == 0100000)
DOLOG(info, true, "0100000: access_control=%d, do_trap=%d", access_control, do_trap);
if (do_trap) { if (do_trap) {
bool do_trap_250 = false; 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) 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) { if ((MMR0 & 1) == 1 && (a & 1) == 0 && a != ADDR_MMR0) {
const uint8_t apf = a >> 13; // active page field const uint8_t apf = a >> 13; // active page field

26
cpu.cpp
View file

@ -103,9 +103,9 @@ uint16_t cpu::getRegister(const int nr, const rm_selection_t mode_selection) con
if (nr == 6) { if (nr == 6) {
if (mode_selection == rm_prev) 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; 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) { else if (nr == 6) {
if (mode_selection == rm_prev) if (mode_selection == rm_prev)
sp[(getPSW() >> 12) & 3] = value; sp[getPSW_prev_runmode()] = value;
else else
sp[getPSW() >> 14] = value; sp[getPSW_runmode()] = value;
} }
else { else {
pc = value; pc = value;
@ -166,9 +166,9 @@ uint16_t cpu::addRegister(const int nr, const rm_selection_t mode_selection, con
if (nr == 6) { if (nr == 6) {
if (mode_selection == rm_prev) 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; 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, { }, { }, { } }; 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 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ always d_space here? TODO
g.space = isR7_space; 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); v = b->read(a.addr.value(), wm_word, rm_prev);
} }
else { else {
int run_mode = (getPSW() >> 12) & 3; int run_mode = getPSW_prev_runmode();
auto phys = b->calculate_physical_address(run_mode, a.addr.value()); auto phys = b->calculate_physical_address(run_mode, a.addr.value());
uint32_t a = word_mode == wm_byte ? phys.physical_data : phys.physical_instruction; 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) if (a.addr.value() >= 0160000)
b->write(a.addr.value(), wm_word, v, rm_prev); // put in '13/12' address space b->write(a.addr.value(), wm_word, v, rm_prev); // put in '13/12' address space
else { else {
int run_mode = (getPSW() >> 12) & 3; int run_mode = getPSW_prev_runmode();
auto phys = b->calculate_physical_address(run_mode, a.addr.value()); 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); 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 case 0b0000000000000010: // RTI
setPC(popStack()); setPC(popStack());
setPSW(popStack(), !!((getPSW() >> 12) & 3)); setPSW(popStack(), !!getPSW_prev_runmode());
return true; return true;
case 0b0000000000000011: // BPT case 0b0000000000000011: // BPT
@ -1510,7 +1510,7 @@ bool cpu::misc_operations(const uint16_t instr)
case 0b0000000000000110: // RTT case 0b0000000000000110: // RTT
setPC(popStack()); setPC(popStack());
setPSW(popStack(), !!((getPSW() >> 12) & 3)); setPSW(popStack(), !!getPSW_prev_runmode());
return true; return true;
case 0b0000000000000111: // MFPT case 0b0000000000000111: // MFPT
@ -1603,7 +1603,7 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)
try { try {
processing_trap_depth++; processing_trap_depth++;
bool kernel_mode = psw >> 14; bool kernel_mode = psw >> 14; // TODO wrong?
if (processing_trap_depth >= 2) { if (processing_trap_depth >= 2) {
DOLOG(debug, true, "Trap depth %d", processing_trap_depth); DOLOG(debug, true, "Trap depth %d", processing_trap_depth);

2
cpu.h
View file

@ -111,6 +111,8 @@ public:
bool getPSW_n() const; bool getPSW_n() const;
int getPSW_spl() const; int getPSW_spl() const;
bool getBitPSW(const int bit) 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_c(const bool v);
void setPSW_v(const bool v); void setPSW_v(const bool v);