From 9d55740a0f84b090b3e62368e99733f85400c051 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 18 Jun 2022 08:48:29 +0200 Subject: [PATCH] SR0 errors by KKTBD0 fixed --- bus.cpp | 19 ++++++++++++++++++- bus.h | 1 + cpu.cpp | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bus.cpp b/bus.cpp index 446b244..e3cb197 100644 --- a/bus.cpp +++ b/bus.cpp @@ -326,6 +326,14 @@ void bus::setMMR0Bit(const int bit) MMR0 |= 1 << bit; } +void bus::clearMMR0Bit(const int bit) +{ + assert(bit != 10 && bit != 11); + assert(bit < 16 && bit >= 0); + + MMR0 &= ~(1 << bit); +} + void bus::setMMR2(const uint16_t value) { MMR2 = value; @@ -359,6 +367,7 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c pages[run_mode][0][apf].pdr |= 1 << 7; // TODO: D/I + MMR0 &= 017777; MMR0 |= 1 << 13; // read-only MMR0 &= ~(3 << 5); @@ -367,6 +376,8 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c MMR0 &= ~14; // add current page MMR0 |= apf << 1; + DOLOG(info, true, "MMR0: %06o", MMR0); + throw 1; } else if (!is_write) { // read @@ -377,7 +388,11 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c pages[run_mode][0][apf].pdr |= 1 << 7; // TODO: D/I - MMR0 |= 1 << 13; // read-only + MMR0 &= 017777; + if (access_control == 0 || access_control == 4) + MMR0 |= 1 << 15; // not resident + else + MMR0 |= 1 << 13; // read-only MMR0 &= ~(3 << 5); MMR0 |= run_mode << 5; @@ -398,6 +413,7 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c DOLOG(debug, !peek_only, "bus::calculate_physical_address %o >= %o", m_offset, n_pages * 8192); DOLOG(info, true, "TRAP(04) (throw 3) on address %06o", a); + MMR0 &= 017777; MMR0 |= 1 << 15; // non-resident MMR0 &= ~14; // add current page @@ -415,6 +431,7 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c DOLOG(info, true, "TRAP(0250) (throw 4) on address %06o", a); c->schedule_trap(0250); // invalid access + MMR0 &= 017777; MMR0 |= 1 << 14; // length MMR0 &= ~14; // add current page diff --git a/bus.h b/bus.h index ba06211..b4c92d5 100644 --- a/bus.h +++ b/bus.h @@ -85,6 +85,7 @@ public: void addToMMR1(const int8_t delta, const uint8_t reg); void setMMR0(int value); void setMMR0Bit(const int bit); + void clearMMR0Bit(const int bit); void setMMR2(const uint16_t value); uint16_t get_switch_register() const { return switch_register; } diff --git a/cpu.cpp b/cpu.cpp index a8243b8..44b79a6 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1647,6 +1647,7 @@ void cpu::schedule_trap(const uint16_t vector) scheduled_trap = vector; } +// 'is_interrupt' is not correct naming; it is true for mmu faults and interrupts void cpu::trap(const uint16_t vector, const int new_ipl, const bool is_interrupt) { uint16_t before_psw = getPSW(); @@ -1661,7 +1662,9 @@ void cpu::trap(const uint16_t vector, const int new_ipl, const bool is_interrupt b->addToMMR1(-2, 6); } - if (!is_interrupt) + if (is_interrupt) + b->clearMMR0Bit(12); + else b->setMMR0Bit(12); // it's a trap setPC(b->readWord(vector + 0)); @@ -2156,7 +2159,7 @@ void cpu::step_a() b->clearMMR1(); if (scheduled_trap) { - trap(scheduled_trap, 7); + trap(scheduled_trap, 7, true); scheduled_trap = 0;