[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 08/15] target/m68k: Fix address argument for EXCP_TRACE
From: |
Richard Henderson |
Subject: |
[PATCH v2 08/15] target/m68k: Fix address argument for EXCP_TRACE |
Date: |
Thu, 2 Dec 2021 12:48:53 -0800 |
According to the M68040 Users Manual, section 8.4.3,
Six word stack frame (format 2), Trace (and others) is
supposed to record the next insn in PC and the address
of the trapping instruction in ADDRESS.
Create gen_raise_exception_format2 to record the trapping
pc in env->mmu.ar. Update m68k_interrupt_all to pass the
value to do_stack_frame. Update cpu_loop to handle EXCP_TRACE.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/m68k/cpu_loop.c | 3 +++
target/m68k/op_helper.c | 2 +-
target/m68k/translate.c | 27 ++++++++++++++++++---------
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index 267df05372..8e2b79550d 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -54,6 +54,9 @@ void cpu_loop(CPUM68KState *env)
case EXCP_DIV0:
force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, env->mmu.ar);
break;
+ case EXCP_TRACE:
+ force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_TRACE, env->mmu.ar);
+ break;
case EXCP_TRAP0:
{
abi_long ret;
diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index a6e4f5719f..c9ea28bf68 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -396,13 +396,13 @@ static void m68k_interrupt_all(CPUM68KState *env, int
is_hw)
case EXCP_ILLEGAL:
case EXCP_TRAPCC:
- case EXCP_TRACE:
/* FIXME: addr is not only env->pc */
do_stack_frame(env, &sp, 2, oldsr, env->pc, env->pc);
break;
case EXCP_CHK:
case EXCP_DIV0:
+ case EXCP_TRACE:
do_stack_frame(env, &sp, 2, oldsr, env->mmu.ar, env->pc);
break;
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index ae9f5a5222..fc2b6a3085 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -298,6 +298,20 @@ static void gen_raise_exception(int nr)
tcg_temp_free_i32(tmp);
}
+static void gen_raise_exception_format2(DisasContext *s, int nr)
+{
+ /*
+ * Pass the address of the insn to the exception handler,
+ * for recording in the Format $2 (6-word) stack frame.
+ * Re-use mmu.ar for the purpose, since that's only valid
+ * after tlb_fill.
+ */
+ tcg_gen_st_i32(tcg_constant_i32(s->base.pc_next), cpu_env,
+ offsetof(CPUM68KState, mmu.ar));
+ gen_raise_exception(nr);
+ s->base.is_jmp = DISAS_NORETURN;
+}
+
static void gen_exception(DisasContext *s, uint32_t dest, int nr)
{
update_cc_op(s);
@@ -1499,7 +1513,7 @@ static void gen_jmp_tb(DisasContext *s, int n, uint32_t
dest)
if (unlikely(s->ss_active)) {
update_cc_op(s);
tcg_gen_movi_i32(QREG_PC, dest);
- gen_raise_exception(EXCP_TRACE);
+ gen_raise_exception_format2(s, EXCP_TRACE);
} else if (translator_use_goto_tb(&s->base, dest)) {
tcg_gen_goto_tb(n);
tcg_gen_movi_i32(QREG_PC, dest);
@@ -6225,17 +6239,12 @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase,
CPUState *cpu)
break;
case DISAS_TOO_MANY:
update_cc_op(dc);
- if (dc->ss_active) {
- tcg_gen_movi_i32(QREG_PC, dc->pc);
- gen_raise_exception(EXCP_TRACE);
- } else {
- gen_jmp_tb(dc, 0, dc->pc);
- }
+ gen_jmp_tb(dc, 0, dc->pc);
break;
case DISAS_JUMP:
/* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
if (dc->ss_active) {
- gen_raise_exception(EXCP_TRACE);
+ gen_raise_exception_format2(dc, EXCP_TRACE);
} else {
tcg_gen_lookup_and_goto_ptr();
}
@@ -6246,7 +6255,7 @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase,
CPUState *cpu)
* other state that may require returning to the main loop.
*/
if (dc->ss_active) {
- gen_raise_exception(EXCP_TRACE);
+ gen_raise_exception_format2(dc, EXCP_TRACE);
} else {
tcg_gen_exit_tb(NULL, 0);
}
--
2.25.1
- Re: [PATCH v2 01/15] target/m68k: Raise the TRAPn exception with the correct pc, (continued)
- [PATCH v2 04/15] linux-user/m68k: Handle EXCP_TRAP1 through EXCP_TRAP15, Richard Henderson, 2021/12/02
- [PATCH v2 02/15] target/m68k: Switch over exception type in m68k_interrupt_all, Richard Henderson, 2021/12/02
- [PATCH v2 09/15] target/m68k: Implement TRAPcc, Richard Henderson, 2021/12/02
- [PATCH v2 12/15] target/m68k: Fix stack frame for EXCP_ILLEGAL, Richard Henderson, 2021/12/02
- [PATCH v2 14/15] linux-user/strace: Fix print_syscall_err, Richard Henderson, 2021/12/02
- [PATCH v2 13/15] tests/tcg/m68k: Add trap.c, Richard Henderson, 2021/12/02
- [PATCH v2 08/15] target/m68k: Fix address argument for EXCP_TRACE,
Richard Henderson <=
- [PATCH v2 05/15] target/m68k: Remove retaddr in m68k_interrupt_all, Richard Henderson, 2021/12/02
- [PATCH v2 06/15] target/m68k: Fix address argument for EXCP_CHK, Richard Henderson, 2021/12/02
- [PATCH v2 10/15] target/m68k: Implement TRAPV, Richard Henderson, 2021/12/02
- [PATCH v2 15/15] linux-user/strace: Adjust get_thread_area for m68k, Richard Henderson, 2021/12/02