[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/4] target/avr: Disable interrupts when env->skip set
From: |
Richard Henderson |
Subject: |
[PULL 4/4] target/avr: Disable interrupts when env->skip set |
Date: |
Thu, 1 Sep 2022 07:51:54 +0100 |
This bit is not saved across interrupts, so we must
delay delivering the interrupt until the skip has
been processed.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1118
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/avr/helper.c | 9 +++++++++
target/avr/translate.c | 26 ++++++++++++++++++++++----
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/target/avr/helper.c b/target/avr/helper.c
index 34f1cbffb2..156dde4e92 100644
--- a/target/avr/helper.c
+++ b/target/avr/helper.c
@@ -31,6 +31,15 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int
interrupt_request)
AVRCPU *cpu = AVR_CPU(cs);
CPUAVRState *env = &cpu->env;
+ /*
+ * We cannot separate a skip from the next instruction,
+ * as the skip would not be preserved across the interrupt.
+ * Separating the two insn normally only happens at page boundaries.
+ */
+ if (env->skip) {
+ return false;
+ }
+
if (interrupt_request & CPU_INTERRUPT_RESET) {
if (cpu_interrupts_enabled(env)) {
cs->exception_index = EXCP_RESET;
diff --git a/target/avr/translate.c b/target/avr/translate.c
index dc9c3d6bcc..026753c963 100644
--- a/target/avr/translate.c
+++ b/target/avr/translate.c
@@ -2971,8 +2971,18 @@ static void avr_tr_translate_insn(DisasContextBase
*dcbase, CPUState *cs)
if (skip_label) {
canonicalize_skip(ctx);
gen_set_label(skip_label);
- if (ctx->base.is_jmp == DISAS_NORETURN) {
+
+ switch (ctx->base.is_jmp) {
+ case DISAS_NORETURN:
ctx->base.is_jmp = DISAS_CHAIN;
+ break;
+ case DISAS_NEXT:
+ if (ctx->base.tb->flags & TB_FLAGS_SKIP) {
+ ctx->base.is_jmp = DISAS_TOO_MANY;
+ }
+ break;
+ default:
+ break;
}
}
@@ -2989,6 +2999,11 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase,
CPUState *cs)
{
DisasContext *ctx = container_of(dcbase, DisasContext, base);
bool nonconst_skip = canonicalize_skip(ctx);
+ /*
+ * Because we disable interrupts while env->skip is set,
+ * we must return to the main loop to re-evaluate afterward.
+ */
+ bool force_exit = ctx->base.tb->flags & TB_FLAGS_SKIP;
switch (ctx->base.is_jmp) {
case DISAS_NORETURN:
@@ -2997,7 +3012,7 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase,
CPUState *cs)
case DISAS_NEXT:
case DISAS_TOO_MANY:
case DISAS_CHAIN:
- if (!nonconst_skip) {
+ if (!nonconst_skip && !force_exit) {
/* Note gen_goto_tb checks singlestep. */
gen_goto_tb(ctx, 1, ctx->npc);
break;
@@ -3005,8 +3020,11 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase,
CPUState *cs)
tcg_gen_movi_tl(cpu_pc, ctx->npc);
/* fall through */
case DISAS_LOOKUP:
- tcg_gen_lookup_and_goto_ptr();
- break;
+ if (!force_exit) {
+ tcg_gen_lookup_and_goto_ptr();
+ break;
+ }
+ /* fall through */
case DISAS_EXIT:
tcg_gen_exit_tb(NULL, 0);
break;
--
2.34.1
- [PULL 00/20] tcg patch queue, Richard Henderson, 2022/09/01
- [PULL 01/20] linux-user/arm: Mark the commpage executable, Richard Henderson, 2022/09/01
- [PULL 1/4] target/avr: Support probe argument to tlb_fill, Richard Henderson, 2022/09/01
- [PULL 02/20] linux-user/hppa: Allocate page zero as a commpage, Richard Henderson, 2022/09/01
- [PULL 2/4] target/avr: Call avr_cpu_do_interrupt directly, Richard Henderson, 2022/09/01
- [PULL 06/20] tests/tcg/i386: Move smc_code2 to an executable section, Richard Henderson, 2022/09/01
- [PULL 10/20] accel/tcg: Make tb_htable_lookup static, Richard Henderson, 2022/09/01
- [PULL 05/20] linux-user: Clear translations on mprotect(), Richard Henderson, 2022/09/01
- [PULL 07/20] accel/tcg: Introduce is_same_page(), Richard Henderson, 2022/09/01
- [PULL 12/20] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp, Richard Henderson, 2022/09/01
- [PULL 4/4] target/avr: Disable interrupts when env->skip set,
Richard Henderson <=
- [PULL 11/20] accel/tcg: Move qemu_ram_addr_from_host_nofail to physmem.c, Richard Henderson, 2022/09/01
- [PULL 03/20] linux-user/x86_64: Allocate vsyscall page as a commpage, Richard Henderson, 2022/09/01
- [PULL 3/4] target/avr: Only execute one interrupt at a time, Richard Henderson, 2022/09/01
- [PULL 04/20] linux-user: Honor PT_GNU_STACK, Richard Henderson, 2022/09/01
- [PULL 14/20] accel/tcg: Remove translator_ldsw, Richard Henderson, 2022/09/01
- [PULL 09/20] accel/tcg: Unlock mmap_lock after longjmp, Richard Henderson, 2022/09/01
- [PULL 08/20] accel/tcg: Properly implement get_page_addr_code for user-only, Richard Henderson, 2022/09/01
- [PULL 13/20] accel/tcg: Document the faulting lookup in tb_lookup_cmp, Richard Henderson, 2022/09/01
- [PULL 15/20] accel/tcg: Add pc and host_pc params to gen_intermediate_code, Richard Henderson, 2022/09/01
- [PULL 16/20] accel/tcg: Add fast path for translator_ld*, Richard Henderson, 2022/09/01