target/nios2: Rewrite interrupt handling
The following changes since commit 36eae3a732a1f2aa81391e871ac0e9bb3233e7d7:
Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-migration-20220302b' into staging (2022-03-02 20:55:48 +0000)
are available in the Git repository at:
https://gitlab.com/rth7680/qemu.git tags/pull-nios-20220303
for you to fetch changes up to b72c9d5951f1dfa047f545408dd9e35597e6b9d3:
target/nios2: Rewrite interrupt handling (2022-03-03 09:51:59 -1000)
----------------------------------------------------------------
Rewrite nios2 interrupt handling
----------------------------------------------------------------
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 | 73 ++++++------- target/nios2/meson.build | 3 +- target/nios2/trace-events | 10 ++ 10 files changed, 152 insertions(+), 247 deletions(-) create mode 100644 target/nios2/trace-events
[PULL 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
[PULL 4/7] target/nios2: Hoist R_ZERO check in rdctl
In reply to Richard HendersonThis 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
@@ -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
Previously, we would avoid setting CPU_INTERRUPT_HARD when interrupts are disabled at a particular point in time, instead queuing the value into cpu->irq_pending. This is more complicated than required.
Instead, set CPU_INTERRUPT_HARD any time there is a pending interrupt, and exclusively check for interrupts disabled in nios2_cpu_exec_interrupt.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -491,19 +491,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
[PULL 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
@@ -2705,6 +2705,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
@@ -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
[PULL 6/7] target/nios2: Special case ipending in rdctl and wrctl
In reply to Richard HendersonIt 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/nios2/translate.c +14 -0
@@ -452,6 +452,17 @@ 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, and so we +* must perform the AND here, and anywhere else we need the +* guest value of ipending. +*/ +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 +488,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
[PULL 3/7] target/nios2: Only build mmu.c for system mode
In reply to Richard HendersonWe 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
@@ -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
@@ -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
[PULL 5/7] target/nios2: Split mmu_write
In reply to Richard HendersonCreate 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
@@ -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
@@ -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
@@ -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
Peter Maydell
AppliedQuoted 7 lines · Richard Henderson
The following changes since commit
36eae3a732a1f2aa81391e871ac0e9bb3233e7d7:Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-migration-20220302b' into staging (2022-03-02 20:55:48 +0000)
are available in the Git repository at:
Quoted 9 lines
https://gitlab.com/rth7680/qemu.git tags/pull-nios-20220303
for you to fetch changes up to
b72c9d5951f1dfa047f545408dd9e35597e6b9d3:target/nios2: Rewrite interrupt handling (2022-03-03 09:51:59 -1000)
----------------------------------------------------------------
Rewrite nios2 interrupt handling
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/7.0
for any user-visible changes.
-- PMM