allow bus to trap for an invalid address

This commit is contained in:
folkert van heusden 2022-03-26 12:20:18 +01:00
parent a86c093b33
commit ebaf6393c3
3 changed files with 23 additions and 0 deletions

10
bus.cpp
View file

@ -312,6 +312,11 @@ uint16_t bus::read(const uint16_t a, const bool word_mode, const bool use_prev)
m_offset += a & 8191;
if (m_offset >= n_pages * 8192) {
D(fprintf(stderr, "bus::read %o >= %o\n", m_offset, n_pages * 8192);)
c->schedule_trap(04); // invalid address
}
if (word_mode)
temp = m -> readByte(m_offset);
else
@ -575,6 +580,11 @@ uint16_t bus::write(const uint16_t a, const bool word_mode, uint16_t value, cons
m_offset += a & 8191;
if (m_offset >= n_pages * 8192) {
D(fprintf(stderr, "bus::write %o >= %o\n", m_offset, n_pages * 8192);)
c->schedule_trap(04); // invalid address
}
if (word_mode)
m->writeByte(m_offset, value);
else

11
cpu.cpp
View file

@ -1187,6 +1187,11 @@ void cpu::busError()
trap(4);
}
void cpu::schedule_trap(const uint16_t vector)
{
scheduled_trap = vector;
}
void cpu::trap(const uint16_t vector, const int new_ipl)
{
uint16_t before_psw = getPSW();
@ -1605,6 +1610,12 @@ void cpu::step()
{
check_queued_interrupts();
if (scheduled_trap) {
trap(scheduled_trap, 7);
scheduled_trap = 0;
}
uint16_t temp_pc = getPC();
if (temp_pc & 1)

2
cpu.h
View file

@ -19,6 +19,7 @@ private:
uint16_t psw { 0 };
uint16_t fpsr { 0 };
uint16_t stackLimitRegister { 0 };
uint8_t scheduled_trap { 0 };
bool runMode { false };
bool emulateMFPT { false };
@ -68,6 +69,7 @@ public:
void busError();
void trap(const uint16_t vector, const int new_ipl = -1);
void schedule_trap(const uint16_t vector);
void setEmulateMFPT(const bool v) { emulateMFPT = v; }