Skip to contentSkip to conversation

target/nios2: Rewrite interrupt handling

PATCH In review Richard Henderson 3 participants 20 messages Feb 27, 2022 – Mar 2, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover target/nios2: Rewrite interrupt handling

This fixes the problems that I pointed out with respect to the existing Internal Interrupt Controller, and a few cleanups on the way. It passes check-avocado, which is the only nios2 test I know of, so more testing would be appreciated.

r~

Richard Henderson (7):
target/nios2: Remove mmu_read_debug target/nios2: Replace MMU_LOG with tracepoints target/nios2: Only build mmu.c for system mode target/nios2: Hoist R_ZERO check in rdctl target/nios2: Split mmu_write
target/nios2: Special case ipending in rdctl and wrctl target/nios2: Rewrite interrupt handling

 meson.build               |   1 +
 target/nios2/cpu.h        |   1 -
 target/nios2/helper.h     |   6 +-
 target/nios2/mmu.h        |   1 -
 target/nios2/cpu.c        |  10 +-
 target/nios2/mmu.c        | 265 ++++++++++++++------------------------
 target/nios2/op_helper.c  |  29 -----
 target/nios2/translate.c  |  71 +++++-----
 target/nios2/meson.build  |   3 +-
 target/nios2/trace-events |  10 ++
 10 files changed, 150 insertions(+), 247 deletions(-)
 create mode 100644 target/nios2/trace-events
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/7 target/nios2: Remove mmu_read_debug

This functionality can be had via plugins, if desired. In the meantime, it is unused code.

---
 target/nios2/helper.h    |  1 -
 target/nios2/mmu.h       |  1 -
 target/nios2/mmu.c       | 20 --------------------
 target/nios2/op_helper.c |  5 -----
 target/nios2/translate.c | 17 -----------------
 5 files changed, 44 deletions(-)
target/nios2/helper.h +0 -1
index 6c8f0b5b35..6d8eec1814 100644
@@ -21,7 +21,6 @@
 DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
 
 #if !defined(CONFIG_USER_ONLY)
-DEF_HELPER_2(mmu_read_debug, void, env, i32)
 DEF_HELPER_3(mmu_write, void, env, i32, i32)
 DEF_HELPER_1(check_interrupts, void, env)
 #endif
target/nios2/mmu.h +0 -1
index 4f46fbb82e..b7785b46c0 100644
@@ -44,7 +44,6 @@ void mmu_flip_um(CPUNios2State *env, unsigned int um);
 unsigned int mmu_translate(CPUNios2State *env,
                            Nios2MMULookup *lu,
                            target_ulong vaddr, int rw, int mmu_idx);
-void mmu_read_debug(CPUNios2State *env, uint32_t rn);
 void mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v);
 void mmu_init(CPUNios2State *env);
 
target/nios2/mmu.c +0 -20
index 2545c06761..5616c39d54 100644
@@ -35,26 +35,6 @@
 #define MMU_LOG(x)
 #endif
 
-void mmu_read_debug(CPUNios2State *env, uint32_t rn)
-{
-    switch (rn) {
-    case CR_TLBACC:
-        MMU_LOG(qemu_log("TLBACC READ %08X\n", env->regs[rn]));
-        break;
-
-    case CR_TLBMISC:
-        MMU_LOG(qemu_log("TLBMISC READ %08X\n", env->regs[rn]));
-        break;
-
-    case CR_PTEADDR:
-        MMU_LOG(qemu_log("PTEADDR READ %08X\n", env->regs[rn]));
-        break;
-
-    default:
-        break;
-    }
-}
-
 /* rw - 0 = read, 1 = write, 2 = fetch.  */
 unsigned int mmu_translate(CPUNios2State *env,
                            Nios2MMULookup *lu,
target/nios2/op_helper.c +0 -5
index a59003855a..61fc4dc903 100644
@@ -26,11 +26,6 @@
 #include "qemu/main-loop.h"
 
 #if !defined(CONFIG_USER_ONLY)
-void helper_mmu_read_debug(CPUNios2State *env, uint32_t rn)
-{
-    mmu_read_debug(env, rn);
-}
-
 void helper_mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v)
 {
     mmu_write(env, rn, v);
target/nios2/translate.c +0 -17
index f9abc2fdd2..194c8ebafd 100644
@@ -448,23 +448,6 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
     gen_check_supervisor(dc);
 
     switch (instr.imm5 + CR_BASE) {
-    case CR_PTEADDR:
-    case CR_TLBACC:
-    case CR_TLBMISC:
-    {
-#if !defined(CONFIG_USER_ONLY)
-        if (likely(instr.c != R_ZERO)) {
-            tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
-#ifdef DEBUG_MMU
-            TCGv_i32 tmp = tcg_const_i32(instr.imm5 + CR_BASE);
-            gen_helper_mmu_read_debug(cpu_R[instr.c], cpu_env, tmp);
-            tcg_temp_free_i32(tmp);
-#endif
-        }
-#endif
-        break;
-    }
-
     default:
         if (likely(instr.c != R_ZERO)) {
             tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] target/nios2: Remove mmu_read_debug

Quoted 26 lines · Richard Henderson

This functionality can be had via plugins, if desired. In the meantime, it is unused code.

---
 target/nios2/helper.h    |  1 -
 target/nios2/mmu.h       |  1 -
 target/nios2/mmu.c       | 20 --------------------
 target/nios2/op_helper.c |  5 -----
 target/nios2/translate.c | 17 -----------------
 5 files changed, 44 deletions(-)
target/nios2/translate.c +0 -7
@@ -448,23 +448,6 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
     gen_check_supervisor(dc);
 
     switch (instr.imm5 + CR_BASE) {
-    case CR_PTEADDR:
-    case CR_TLBACC:
-    case CR_TLBMISC:
-    {
-#if !defined(CONFIG_USER_ONLY)
-        if (likely(instr.c != R_ZERO)) {
-            tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);

target/nios2/translate.c static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags) · line 467

Quoted 10 lines
target/nios2/translate.c +0 -10
-#ifdef DEBUG_MMU
-            TCGv_i32 tmp = tcg_const_i32(instr.imm5 + CR_BASE);
-            gen_helper_mmu_read_debug(cpu_R[instr.c], cpu_env, tmp);
-            tcg_temp_free_i32(tmp);
-#endif
-        }
-#endif
-        break;
-    }
-

For a moment I thought this was changing the behaviour of these registers for linux-user, but gen_check_supervisor() means we never execute the code generated here. (Side note: it would be more sensible to stop generating code rather than generating the "throw an exception" code and then the "write/read reg" code as known-dead-code after it. But that's a different issue.)

thanks
-- PMM

#3 lore raw

PATCH 2/7 target/nios2: Replace MMU_LOG with tracepoints

In reply to Richard Henderson
---
 meson.build               |  1 +
 target/nios2/mmu.c        | 96 ++++++++++++---------------------------
 target/nios2/trace-events | 10 ++++
 3 files changed, 39 insertions(+), 68 deletions(-)
 create mode 100644 target/nios2/trace-events
meson.build +1 -0
index 8df40bfac4..98f167d782 100644
@@ -2692,6 +2692,7 @@ if have_system or have_user
     'target/i386',
     'target/i386/kvm',
     'target/mips/tcg',
+    'target/nios2',
     'target/ppc',
     'target/riscv',
     'target/s390x',
target/nios2/mmu.c +28 -68

181 lines not on this page · raw message

target/nios2/trace-events new file +10 -0
new file mode 100644
index 0000000000..07f1f0a5e7
@@ -0,0 +1,10 @@
+# mmu.c
+nios2_mmu_translate_miss(uint32_t vaddr, uint32_t pid, uint32_t index, uint32_t tag) "mmu_translate: MISS vaddr=0x%08x pid=%u TLB[%u] tag=0x%08x"
+nios2_mmu_translate_hit(uint32_t vaddr, uint32_t pid, uint32_t index, uint32_t paddr, uint32_t prot) "mmu_translate: HIT vaddr=0x%08x pid=%u TLB[%u] paddr=0x%08x prot=0x%x"
+
+nios2_mmu_flush_pid_miss(uint32_t pid, uint32_t index, uint32_t vaddr) "mmu_flush: MISS pid=%u TLB[%u] tag=0x%08x"
+nios2_mmu_flush_pid_hit(uint32_t pid, uint32_t index, uint32_t vaddr) "mmu_flush: HIT pid=%u TLB[%u] vaddr=0x%08x"
+
+nios2_mmu_write_tlbacc(uint32_t ig, char c, char r, char w, char x, char g, uint32_t pfn) "mmu_write_tlbacc: ig=0x%02x flags=%c%c%c%c%c pfn=0x%08x"
+nios2_mmu_write_tlbmisc(uint32_t way, char r, char w, char t, char b, char p, char d, uint32_t pid) "mmu_write_tlbmisc: way=0x%x flags=%c%c%c%c%c%c pid=%u"
+nios2_mmu_write_pteaddr(uint32_t ptb, uint32_t vpn) "mmu_write_pteaddr: ptbase=0x%03x vpn=0x%05x"
Signature · 1 line
2.25.1
Reviewed-by on v1 2/7
#4 lore raw

Re: [PATCH 2/7] target/nios2: Replace MMU_LOG with tracepoints

Quoted 7 lines · Richard Henderson
---
  meson.build               |  1 +
  target/nios2/mmu.c        | 96 ++++++++++++---------------------------
  target/nios2/trace-events | 10 ++++
  3 files changed, 39 insertions(+), 68 deletions(-)

create mode 100644 target/nios2/trace-events

Reviewed-by on v1 2/7
#5 lore raw

Re: [PATCH 2/7] target/nios2: Replace MMU_LOG with tracepoints

In reply to Richard Henderson
Quoted 8 lines · Richard Henderson
---
 meson.build               |  1 +
 target/nios2/mmu.c        | 96 ++++++++++++---------------------------
 target/nios2/trace-events | 10 ++++
 3 files changed, 39 insertions(+), 68 deletions(-)
 create mode 100644 target/nios2/trace-events

thanks
-- PMM

#6 lore raw

PATCH 3/7 target/nios2: Only build mmu.c for system mode

In reply to Richard Henderson

We can thus remove an ifdef covering the entire file.

---
 target/nios2/mmu.c       | 3 ---
 target/nios2/meson.build | 3 +--
 2 files changed, 1 insertion(+), 5 deletions(-)
target/nios2/mmu.c +0 -3
index 306370f675..437fad09b7 100644
@@ -25,7 +25,6 @@
 #include "mmu.h"
 #include "trace/trace-target_nios2.h"
 
-#if !defined(CONFIG_USER_ONLY)
 
 /* rw - 0 = read, 1 = write, 2 = fetch.  */
 unsigned int mmu_translate(CPUNios2State *env,
@@ -217,5 +216,3 @@ void dump_mmu(CPUNios2State *env)
                     (entry->data & CR_TLBACC_X) ? 'X' : '-');
     }
 }
-
-#endif /* !CONFIG_USER_ONLY */
target/nios2/meson.build +1 -2
index e643917db1..62b384702d 100644
@@ -2,14 +2,13 @@ nios2_ss = ss.source_set()
 nios2_ss.add(files(
   'cpu.c',
   'helper.c',
-  'mmu.c',
   'nios2-semi.c',
   'op_helper.c',
   'translate.c',
 ))
 
 nios2_softmmu_ss = ss.source_set()
-nios2_softmmu_ss.add(files('monitor.c'))
+nios2_softmmu_ss.add(files('monitor.c', 'mmu.c'))
 
 target_arch += {'nios2': nios2_ss}
 target_softmmu_arch += {'nios2': nios2_softmmu_ss}
Signature · 1 line
2.25.1
#9 lore raw

PATCH 4/7 target/nios2: Hoist R_ZERO check in rdctl

In reply to Richard Henderson

This will avoid having to replicate the check to additional cases.

---
 target/nios2/translate.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
target/nios2/translate.c +5 -3
index 194c8ebafd..fa355308a9 100644
@@ -447,11 +447,13 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
 
     gen_check_supervisor(dc);
 
+    if (unlikely(instr.c == R_ZERO)) {
+        return;
+    }
+
     switch (instr.imm5 + CR_BASE) {
     default:
-        if (likely(instr.c != R_ZERO)) {
-            tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
-        }
+        tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
         break;
     }
 }
Signature · 1 line
2.25.1
#12 lore raw

PATCH 5/7 target/nios2: Split mmu_write

In reply to Richard Henderson

Create three separate functions for the three separate registers. Avoid extra dispatch through op_helper.c.
Dispatch to the correct function in translation.
Clean up the ifdefs in wrctl.

---
 target/nios2/helper.h    |   4 +-
 target/nios2/mmu.c       | 180 +++++++++++++++++++--------------------
 target/nios2/op_helper.c |   5 --
 target/nios2/translate.c |  26 +++---
 4 files changed, 104 insertions(+), 111 deletions(-)
target/nios2/helper.h +3 -1
index 6d8eec1814..21ef7f0791 100644
@@ -21,6 +21,8 @@
 DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
 
 #if !defined(CONFIG_USER_ONLY)
-DEF_HELPER_3(mmu_write, void, env, i32, i32)
+DEF_HELPER_2(mmu_write_tlbacc, void, env, i32)
+DEF_HELPER_2(mmu_write_tlbmisc, void, env, i32)
+DEF_HELPER_2(mmu_write_pteaddr, void, env, i32)
 DEF_HELPER_1(check_interrupts, void, env)
 #endif
target/nios2/mmu.c +89 -91

201 lines not on this page · raw message

target/nios2/op_helper.c +0 -5
index 61fc4dc903..d729379e4d 100644
@@ -26,11 +26,6 @@
 #include "qemu/main-loop.h"
 
 #if !defined(CONFIG_USER_ONLY)
-void helper_mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v)
-{
-    mmu_write(env, rn, v);
-}
-
 static void nios2_check_interrupts(CPUNios2State *env)
 {
     if (env->irq_pending &&
target/nios2/translate.c +12 -14
index fa355308a9..52965ba17e 100644
@@ -461,30 +461,28 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
 /* ctlN <- rA */
 static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
 {
-    R_TYPE(instr, code);
-
     gen_check_supervisor(dc);
 
+#ifndef CONFIG_USER_ONLY
+    R_TYPE(instr, code);
+    TCGv v = load_gpr(dc, instr.a);
+
     switch (instr.imm5 + CR_BASE) {
     case CR_PTEADDR:
-    case CR_TLBACC:
-    case CR_TLBMISC:
-    {
-#if !defined(CONFIG_USER_ONLY)
-        TCGv_i32 tmp = tcg_const_i32(instr.imm5 + CR_BASE);
-        gen_helper_mmu_write(cpu_env, tmp, load_gpr(dc, instr.a));
-        tcg_temp_free_i32(tmp);
-#endif
+        gen_helper_mmu_write_pteaddr(cpu_env, v);
+        break;
+    case CR_TLBACC:
+        gen_helper_mmu_write_tlbacc(cpu_env, v);
+        break;
+    case CR_TLBMISC:
+        gen_helper_mmu_write_tlbmisc(cpu_env, v);
         break;
-    }
-
     default:
-        tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], load_gpr(dc, instr.a));
+        tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], v);
         break;
     }
 
     /* If interrupts were enabled using WRCTL, trigger them. */
-#if !defined(CONFIG_USER_ONLY)
     if ((instr.imm5 + CR_BASE) == CR_STATUS) {
         if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) {
             gen_io_start();
Signature · 1 line
2.25.1
Reviewed-by on v1 5/7
#13 lore raw

Re: [PATCH 5/7] target/nios2: Split mmu_write

Quoted 6 lines · Richard Henderson

Create three separate functions for the three separate registers. Avoid extra dispatch through op_helper.c.
Dispatch to the correct function in translation.
Clean up the ifdefs in wrctl.

Quoted 7 lines
---
 target/nios2/helper.h    |   4 +-
 target/nios2/mmu.c       | 180 +++++++++++++++++++--------------------
 target/nios2/op_helper.c |   5 --
 target/nios2/translate.c |  26 +++---
 4 files changed, 104 insertions(+), 111 deletions(-)

You forgot to delete the prototype for mmu_write() in mmu.h. Otherwise

thanks
-- PMM

#14 lore raw

PATCH 6/7 target/nios2: Special case ipending in rdctl and wrctl

In reply to Richard Henderson

It was never correct to be able to write to ipending. Until the rest of the irq code is tidied, the read of ipending will generate an "unnecessary" mask.

---
 target/nios2/translate.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/nios2/translate.c +12 -0
index 52965ba17e..b17ce25a36 100644
@@ -452,6 +452,15 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
     }
 
     switch (instr.imm5 + CR_BASE) {
+    case CR_IPENDING:
+        /*
+         * The value of the ipending register is synthetic.
+         * In hw, this is the AND of a set of hardware irq lines
+         * with the ienable register.  In qemu, we re-use the space
+         * of CR_IPENDING to store the set of irq lines.
+         */
+        tcg_gen_and_tl(cpu_R[instr.c], cpu_R[CR_IPENDING], cpu_R[CR_IENABLE]);
+        break;
     default:
         tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
         break;
@@ -477,6 +486,9 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
     case CR_TLBMISC:
         gen_helper_mmu_write_tlbmisc(cpu_env, v);
         break;
+    case CR_IPENDING:
+        /* ipending is read only, writes ignored. */
+        break;
     default:
         tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], v);
         break;
Signature · 1 line
2.25.1
Reviewed-by on v1 6/7
#15 lore raw

Re: [PATCH 6/7] target/nios2: Special case ipending in rdctl and wrctl

Quoted 8 lines · Richard Henderson

It was never correct to be able to write to ipending. Until the rest of the irq code is tidied, the read of ipending will generate an "unnecessary" mask.

---
  target/nios2/translate.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
Reviewed-by on v1 6/7
#16 lore raw

Re: [PATCH 6/7] target/nios2: Special case ipending in rdctl and wrctl

In reply to Richard Henderson
Quoted 15 lines · Richard Henderson

It was never correct to be able to write to ipending. Until the rest of the irq code is tidied, the read of ipending will generate an "unnecessary" mask.

---
 target/nios2/translate.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/nios2/translate.c +0 -0
index 52965ba17e..b17ce25a36 100644

target/nios2/translate.c static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags) · line 460

Quoted 9 lines
target/nios2/translate.c +6 -0
@@ -452,6 +452,15 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
     }
 
     switch (instr.imm5 + CR_BASE) {
+    case CR_IPENDING:
+        /*
+         * The value of the ipending register is synthetic.
+         * In hw, this is the AND of a set of hardware irq lines
+         * with the ienable register.  In qemu, we re-use the space
+         * of CR_IPENDING to store the set of irq lines.

maybe add
"and so we must perform the AND here, and anywhere else we need the guest value of CR_IPENDING" ?

target/nios2/translate.c static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags) · line 463

Quoted 3 lines
target/nios2/translate.c +3 -0
+         */
+        tcg_gen_and_tl(cpu_R[instr.c], cpu_R[CR_IPENDING], cpu_R[CR_IENABLE]);
+        break;

thanks
-- PMM

#17 lore raw

PATCH 7/7 target/nios2: Rewrite interrupt handling

In reply to Richard Henderson

Drop irq_pending boolean.
Drop helper_check_interrupts.
Move checks for irq disabled into nios2_cpu_exec_interrupt. End the TB on writes to ienable, just like to status.

---
 target/nios2/cpu.h       |  1 -
 target/nios2/helper.h    |  1 -
 target/nios2/cpu.c       | 10 ++++------
 target/nios2/op_helper.c | 19 -------------------
 target/nios2/translate.c | 14 +++++---------
 5 files changed, 9 insertions(+), 36 deletions(-)
target/nios2/cpu.h +0 -1
index d2ba0c5bbd..a00e4229ce 100644
@@ -160,7 +160,6 @@ struct CPUNios2State {
 
 #if !defined(CONFIG_USER_ONLY)
     Nios2MMU mmu;
-    uint32_t irq_pending;
 #endif
     int error_code;
 };
target/nios2/helper.h +0 -1
index 21ef7f0791..a44ecfdf7a 100644
@@ -24,5 +24,4 @@ DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
 DEF_HELPER_2(mmu_write_tlbacc, void, env, i32)
 DEF_HELPER_2(mmu_write_tlbmisc, void, env, i32)
 DEF_HELPER_2(mmu_write_pteaddr, void, env, i32)
-DEF_HELPER_1(check_interrupts, void, env)
 #endif
target/nios2/cpu.c +4 -6
index 4cade61e93..6975ae4bdb 100644
@@ -73,12 +73,9 @@ static void nios2_cpu_set_irq(void *opaque, int irq, int level)
 
     env->regs[CR_IPENDING] = deposit32(env->regs[CR_IPENDING], irq, 1, !!level);
 
-    env->irq_pending = env->regs[CR_IPENDING] & env->regs[CR_IENABLE];
-
-    if (env->irq_pending && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
-        env->irq_pending = 0;
+    if (env->regs[CR_IPENDING]) {
         cpu_interrupt(cs, CPU_INTERRUPT_HARD);
-    } else if (!env->irq_pending) {
+    } else {
         cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
     }
 }
@@ -134,7 +131,8 @@ static bool nios2_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
     CPUNios2State *env = &cpu->env;
 
     if ((interrupt_request & CPU_INTERRUPT_HARD) &&
-        (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
+        (env->regs[CR_STATUS] & CR_STATUS_PIE) &&
+        (env->regs[CR_IPENDING] & env->regs[CR_IENABLE])) {
         cs->exception_index = EXCP_IRQ;
         nios2_cpu_do_interrupt(cs);
         return true;
target/nios2/op_helper.c +0 -19
index d729379e4d..caa885f7b4 100644
@@ -21,28 +21,9 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
-#include "exec/cpu_ldst.h"
 #include "exec/exec-all.h"
 #include "qemu/main-loop.h"
 
-#if !defined(CONFIG_USER_ONLY)
-static void nios2_check_interrupts(CPUNios2State *env)
-{
-    if (env->irq_pending &&
-        (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
-        env->irq_pending = 0;
-        cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD);
-    }
-}
-
-void helper_check_interrupts(CPUNios2State *env)
-{
-    qemu_mutex_lock_iothread();
-    nios2_check_interrupts(env);
-    qemu_mutex_unlock_iothread();
-}
-#endif /* !CONFIG_USER_ONLY */
-
 void helper_raise_exception(CPUNios2State *env, uint32_t index)
 {
     CPUState *cs = env_cpu(env);
target/nios2/translate.c +5 -9
index b17ce25a36..ce3aacf59d 100644
@@ -489,19 +489,15 @@ static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
     case CR_IPENDING:
         /* ipending is read only, writes ignored. */
         break;
+    case CR_STATUS:
+    case CR_IENABLE:
+        /* If interrupts were enabled using WRCTL, trigger them. */
+        dc->base.is_jmp = DISAS_UPDATE;
+        /* fall through */
     default:
         tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], v);
         break;
     }
-
-    /* If interrupts were enabled using WRCTL, trigger them. */
-    if ((instr.imm5 + CR_BASE) == CR_STATUS) {
-        if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) {
-            gen_io_start();
-        }
-        gen_helper_check_interrupts(cpu_env);
-        dc->base.is_jmp = DISAS_UPDATE;
-    }
 #endif
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 7/7
#18 lore raw
Quoted 5 lines · Richard Henderson

Drop irq_pending boolean.
Drop helper_check_interrupts.
Move checks for irq disabled into nios2_cpu_exec_interrupt. End the TB on writes to ienable, just like to status.

Quoted 8 lines
---
  target/nios2/cpu.h       |  1 -
  target/nios2/helper.h    |  1 -
  target/nios2/cpu.c       | 10 ++++------
  target/nios2/op_helper.c | 19 -------------------
  target/nios2/translate.c | 14 +++++---------
  5 files changed, 9 insertions(+), 36 deletions(-)

LGTM but better have another review...

Reviewed-by on v1 7/7
#19 lore raw
In reply to Richard Henderson
Quoted 2 lines · Richard Henderson

Drop irq_pending boolean.

It wasn't a boolean, it was a uint32_t.

Quoted 5 lines

Drop helper_check_interrupts.
Move checks for irq disabled into nios2_cpu_exec_interrupt. End the TB on writes to ienable, just like to status.

The code changes look good to me, but I think it would be useful to have the commit message include a brief sketch of how the new interrupt-handling design works and mention that this means nios2 now works like the other targets. At the moment the commit message is all "what" (which you can get by looking at the patch) and no "why".

thanks
-- PMM