From faed1c2a23373e5b6a77c9b2c6e2a01160ea5c30 Mon Sep 17 00:00:00 2001 From: "Edgar E. Iglesias" Date: Thu, 3 Sep 2009 13:25:09 +0200 Subject: [PATCH] microblaze: Trap on bus accesses to unmapped areas. Signed-off-by: Edgar E. Iglesias --- exec.c | 12 ++++++------ target-microblaze/cpu.h | 3 +++ target-microblaze/op_helper.c | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 6c8d9ef..c5bc13a 100644 --- a/exec.c +++ b/exec.c @@ -2492,7 +2492,7 @@ static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr) #ifdef DEBUG_UNASSIGNED printf("Unassigned mem read " TARGET_FMT_plx "\n", addr); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 0, 0, 0, 1); #endif return 0; @@ -2503,7 +2503,7 @@ static uint32_t unassigned_mem_readw(void *opaque, target_phys_addr_t addr) #ifdef DEBUG_UNASSIGNED printf("Unassigned mem read " TARGET_FMT_plx "\n", addr); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 0, 0, 0, 2); #endif return 0; @@ -2514,7 +2514,7 @@ static uint32_t unassigned_mem_readl(void *opaque, target_phys_addr_t addr) #ifdef DEBUG_UNASSIGNED printf("Unassigned mem read " TARGET_FMT_plx "\n", addr); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 0, 0, 0, 4); #endif return 0; @@ -2525,7 +2525,7 @@ static void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_ #ifdef DEBUG_UNASSIGNED printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 1, 0, 0, 1); #endif } @@ -2535,7 +2535,7 @@ static void unassigned_mem_writew(void *opaque, target_phys_addr_t addr, uint32_ #ifdef DEBUG_UNASSIGNED printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 1, 0, 0, 2); #endif } @@ -2545,7 +2545,7 @@ static void unassigned_mem_writel(void *opaque, target_phys_addr_t addr, uint32_ #ifdef DEBUG_UNASSIGNED printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val); #endif -#if defined(TARGET_SPARC) +#if defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE) do_unassigned_access(addr, 1, 0, 0, 4); #endif } diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h index 5dc2b7d..1bf4875 100644 --- a/target-microblaze/cpu.h +++ b/target-microblaze/cpu.h @@ -323,4 +323,7 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc, env->iflags |= env->sregs[SR_MSR] & MSR_EE; *flags = env->iflags & IFLAGS_TB_MASK; } + +void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec, + int is_asi, int size); #endif diff --git a/target-microblaze/op_helper.c b/target-microblaze/op_helper.c index a5b3827..2cc4ced 100644 --- a/target-microblaze/op_helper.c +++ b/target-microblaze/op_helper.c @@ -245,3 +245,30 @@ void helper_mmu_write(uint32_t rn, uint32_t v) mmu_write(env, rn, v); } #endif + +void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec, + int is_asi, int size) +{ + CPUState *saved_env; + /* XXX: hack to restore env in all cases, even if not called from + generated code */ + saved_env = env; + env = cpu_single_env; + qemu_log("Unassigned " TARGET_FMT_plx " wr=%d exe=%d\n", + addr, is_write, is_exec); + if (!(env->sregs[SR_MSR] & MSR_EE)) { + return; + } + + if (is_exec) { + if (!(env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) { + env->sregs[SR_ESR] = ESR_EC_INSN_BUS; + helper_raise_exception(EXCP_HW_EXCP); + } + } else { + if (!(env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) { + env->sregs[SR_ESR] = ESR_EC_DATA_BUS; + helper_raise_exception(EXCP_HW_EXCP); + } + } +} -- 2.7.4