From d027ffafd6c25e07e6c222f7ec511bdbfabdd8dd Mon Sep 17 00:00:00 2001 From: Sven Schnelle Date: Sun, 7 Oct 2018 11:04:10 +0200 Subject: m68k: throw mmu configuration exception if SRP/CRP is invalid --- src/devices/cpu/m68000/m68kcpu.h | 1 + src/devices/cpu/m68000/m68kmmu.h | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/devices/cpu/m68000/m68kcpu.h b/src/devices/cpu/m68000/m68kcpu.h index adb45a04c78..9759294f8f6 100644 --- a/src/devices/cpu/m68000/m68kcpu.h +++ b/src/devices/cpu/m68000/m68kcpu.h @@ -55,6 +55,7 @@ static constexpr int EXCEPTION_UNINITIALIZED_INTERRUPT = 15; static constexpr int EXCEPTION_SPURIOUS_INTERRUPT = 24; static constexpr int EXCEPTION_INTERRUPT_AUTOVECTOR = 24; static constexpr int EXCEPTION_TRAP_BASE = 32; +static constexpr int EXCEPTION_MMU_CONFIGURATION = 56; // only on 020/030 /* Function codes set by CPU during data/address bus activity */ static constexpr int FUNCTION_CODE_USER_DATA = 1; diff --git a/src/devices/cpu/m68000/m68kmmu.h b/src/devices/cpu/m68000/m68kmmu.h index 24601755e6d..ab9d6396673 100644 --- a/src/devices/cpu/m68000/m68kmmu.h +++ b/src/devices/cpu/m68000/m68kmmu.h @@ -1016,7 +1016,18 @@ void m68881_mmu_ops() if (m_mmu_tc & 0x80000000) { - m_pmmu_enabled = 1; + int bits = 0; + for(int shift = 20; shift >= 0; shift -= 4) { + bits += (m_mmu_tc >> shift) & 0x0f; + } + + if (bits != 32 || !((m_mmu_tc >> 23) & 1)) { + logerror("MMU: TC invalid!\n"); + m_mmu_tc &= ~0x80000000; + m68ki_exception_trap(EXCEPTION_MMU_CONFIGURATION); + } else { + m_pmmu_enabled = 1; + } // printf("PMMU enabled\n"); } else @@ -1036,6 +1047,12 @@ void m68881_mmu_ops() m_mmu_srp_limit = (temp64>>32) & 0xffffffff; m_mmu_srp_aptr = temp64 & 0xffffffff; // printf("PMMU: SRP limit = %08x aptr = %08x\n", m_mmu_srp_limit, m_mmu_srp_aptr); + // CRP type 0 is not allowed + if ((m_mmu_crp_limit & 3) == 0) { + m68ki_exception_trap(EXCEPTION_MMU_CONFIGURATION); + return; + } + if (!(modes & 0x100)) { pmmu_atc_flush(); @@ -1047,6 +1064,13 @@ void m68881_mmu_ops() m_mmu_crp_limit = (temp64>>32) & 0xffffffff; m_mmu_crp_aptr = temp64 & 0xffffffff; // printf("PMMU: CRP limit = %08x aptr = %08x\n", m_mmu_crp_limit, m_mmu_crp_aptr); + // CRP type 0 is not allowed + if ((m_mmu_crp_limit & 3) == 0) { + m68ki_exception_trap(EXCEPTION_MMU_CONFIGURATION); + return; + } + + if (!(modes & 0x100)) { pmmu_atc_flush(); -- cgit v1.2.3