target/ppc: powerpc_excp improvements (1/n)
v2 cover target/ppc: powerpc_excp improvements (1/n)
This series comprises of the first 4 patches from the RFC v2 plus an extra patch addressing review comments.
Patch 1,3,4,5 have been reviewed.
Patch 2 addresses prior comments from patch 3 and has not been reviewed.
RFC v1:
https://lists.nongnu.org/archive/html/qemu-ppc/2021-06/msg00026.html
RFC v2:
https://lists.nongnu.org/archive/html/qemu-ppc/2021-12/msg00542.html
Fabiano Rosas (5):
target/ppc: powerpc_excp: Set alternate SRRs directly target/ppc: powerpc_excp: Add excp_vectors bounds check target/ppc: powerpc_excp: Set vector earlier target/ppc: powerpc_excp: Move system call vectored code together target/ppc: powerpc_excp: Stop passing excp_model around
target/ppc/excp_helper.c | 102 ++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 56 deletions(-)
Signature · 1 line
2.33.1
PATCH v2 1/5 target/ppc: powerpc_excp: Set alternate SRRs directly
There are currently only two interrupts that use alternate SRRs, so let them write to them directly during the setup code.
No functional change intended.
--- target/ppc/excp_helper.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
target/ppc/excp_helper.c +8 -15
@@ -298,7 +298,7 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;target_ulong msr, new_msr, vector; -int srr0, srr1, asrr0, asrr1, lev =-1 ; +int srr0, srr1, lev =-1 ;qemu_log_mask (CPU_LOG_INT ,"Raise exception at " TARGET_FMT_lx" => %08x (%02x)\n" , env->nip, excp, env->error_code);
@@ -319,8 +319,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)/* target registers */ srr0 =SPR_SRR0 ; srr1 =SPR_SRR1 ; - asrr0 =-1 ; - asrr1 =-1 ;/* * check for special resume at 0x100 from doze/nap/sleep/winkle on
@@ -410,8 +408,9 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)/* FIXME: choose one or the other based on CPU type */ srr0 =SPR_BOOKE_MCSRR0 ; srr1 =SPR_BOOKE_MCSRR1 ; - asrr0 =SPR_BOOKE_CSRR0 ; - asrr1 =SPR_BOOKE_CSRR1 ; + + env->spr[SPR_BOOKE_CSRR0 ] = env->nip; + env->spr[SPR_BOOKE_CSRR1 ] = msr;break ;default :break ;
@@ -570,8 +569,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)/* FIXME: choose one or the other based on CPU type */ srr0 =SPR_BOOKE_DSRR0 ; srr1 =SPR_BOOKE_DSRR1 ; - asrr0 =SPR_BOOKE_CSRR0 ; - asrr1 =SPR_BOOKE_CSRR1 ; + + env->spr[SPR_BOOKE_CSRR0 ] = env->nip; + env->spr[SPR_BOOKE_CSRR1 ] = msr; +/* DBSR already modified by caller */ }else {cpu_abort (cs,"Debug exception triggered on unsupported model\n" );
@@ -838,14 +839,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) vector |= env->excp_prefix; -/* If any alternate SRR register are defined, duplicate saved values */ -if (asrr0 !=-1 ) { - env->spr[asrr0] = env->nip; - } -if (asrr1 !=-1 ) { - env->spr[asrr1] = msr; - } -#if defined(TARGET_PPC64 )if (excp_model ==POWERPC_EXCP_BOOKE ) {if (env->spr[SPR_BOOKE_EPCR ] &EPCR_ICM ) {
Signature · 1 line
2.33.1
PATCH v2 2/5 target/ppc: powerpc_excp: Add excp_vectors bounds check
In reply to Fabiano RosasThe next patch will start accessing the excp_vectors array earlier in the function, so add a bounds check as first thing here.
This converts the empty return on POWERPC_EXCP_NONE to an error. This exception number never reaches this function and if it does it probably means something else went wrong up the line.
--- target/ppc/excp_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target/ppc/excp_helper.c +4 -3
@@ -300,6 +300,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)target_ulong msr, new_msr, vector;int srr0, srr1, lev =-1 ; +if (excp <=POWERPC_EXCP_NONE || excp >=POWERPC_EXCP_NB ) { +cpu_abort (cs,"Invalid PowerPC exception %d. Aborting\n" , excp); + } +qemu_log_mask (CPU_LOG_INT ,"Raise exception at " TARGET_FMT_lx" => %08x (%02x)\n" , env->nip, excp, env->error_code);
@@ -353,9 +357,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)#endif switch (excp) { -case POWERPC_EXCP_NONE : -/* Should never happen */ -return ;case POWERPC_EXCP_CRITICAL :/* Critical input */ switch (excp_model) {case POWERPC_EXCP_40x:
Signature · 1 line
2.33.1
Re: [PATCH v2 2/5] target/ppc: powerpc_excp: Add excp_vectors bounds check
Quoted 8 lines · Fabiano Rosas
The next patch will start accessing the
excp_vectorsarray earlier in the function, so add a bounds check as first thing here.This converts the empty return on
POWERPC_EXCP_NONEto an error. This exception number never reaches this function and if it does it probably means something else went wrong up the line.Signed-off-by Fabiano Rosas <[email protected]>
r~
Re: [PATCH v2 2/5] target/ppc: powerpc_excp: Add excp_vectors bounds check
In reply to Fabiano RosasQuoted 8 lines · Fabiano Rosas
The next patch will start accessing the
excp_vectorsarray earlier in the function, so add a bounds check as first thing here.This converts the empty return on
POWERPC_EXCP_NONEto an error. This exception number never reaches this function and if it does it probably means something else went wrong up the line.Signed-off-by Fabiano Rosas <[email protected]>
Thanks,
C.
Quoted 30 lines
--- target/ppc/excp_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)target/ppc/excp_helper.c +4
-3@@ -300,6 +300,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)target_ulong msr, new_msr, vector;int srr0, srr1, lev =-1 ; +if (excp <=POWERPC_EXCP_NONE || excp >=POWERPC_EXCP_NB ) { +cpu_abort (cs,"Invalid PowerPC exception %d. Aborting\n" , excp); + } +qemu_log_mask (CPU_LOG_INT ,"Raise exception at " TARGET_FMT_lx" => %08x (%02x)\n" , env->nip, excp, env->error_code);@@ -353,9 +357,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)#endif switch (excp) { -case POWERPC_EXCP_NONE : -/* Should never happen */ -return ;case POWERPC_EXCP_CRITICAL :/* Critical input */ switch (excp_model) {case POWERPC_EXCP_40x:
Re: [PATCH v2 2/5] target/ppc: powerpc_excp: Add excp_vectors bounds check
In reply to Fabiano RosasQuoted 8 lines · Fabiano Rosas
The next patch will start accessing the
excp_vectorsarray earlier in the function, so add a bounds check as first thing here.This converts the empty return on
POWERPC_EXCP_NONEto an error. This exception number never reaches this function and if it does it probably means something else went wrong up the line.Signed-off-by Fabiano Rosas <[email protected]>
Quoted 29 lines
--- target/ppc/excp_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)target/ppc/excp_helper.c +4
-3@@ -300,6 +300,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)target_ulong msr, new_msr, vector;int srr0, srr1, lev =-1 ; +if (excp <=POWERPC_EXCP_NONE || excp >=POWERPC_EXCP_NB ) { +cpu_abort (cs,"Invalid PowerPC exception %d. Aborting\n" , excp); + } +qemu_log_mask (CPU_LOG_INT ,"Raise exception at " TARGET_FMT_lx" => %08x (%02x)\n" , env->nip, excp, env->error_code);@@ -353,9 +357,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)#endif switch (excp) { -case POWERPC_EXCP_NONE : -/* Should never happen */ -return ;case POWERPC_EXCP_CRITICAL :/* Critical input */ switch (excp_model) {case POWERPC_EXCP_40x:
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 3/5 target/ppc: powerpc_excp: Set vector earlier
In reply to Fabiano RosasNone of the interrupt setup code touches 'vector', so we can move it earlier in the function. This will allow us to later move the System Call Vectored setup that is on the top level into the POWERPC_EXCP_SYSCALL_VECTORED code block.
This patch also moves the verification for when 'excp' does not have an address associated with it. We now bail a little earlier when that is the case. This should not cause any visible effects.
--- target/ppc/excp_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
target/ppc/excp_helper.c +8 -8
@@ -356,6 +356,14 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) }#endif + vector = env->excp_vectors[excp]; +if (vector == (target_ulong)-1ULL ) { +cpu_abort (cs,"Raised an exception without defined vector %d\n" , + excp); + } + + vector |= env->excp_prefix; +switch (excp) {case POWERPC_EXCP_CRITICAL :/* Critical input */ switch (excp_model) {
@@ -832,14 +840,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) }#endif - vector = env->excp_vectors[excp]; -if (vector == (target_ulong)-1ULL ) { -cpu_abort (cs,"Raised an exception without defined vector %d\n" , - excp); - } - - vector |= env->excp_prefix; -#if defined(TARGET_PPC64 )if (excp_model ==POWERPC_EXCP_BOOKE ) {if (env->spr[SPR_BOOKE_EPCR ] &EPCR_ICM ) {
Signature · 1 line
2.33.1
Re: [PATCH v2 3/5] target/ppc: powerpc_excp: Set vector earlier
Quoted 9 lines · Fabiano Rosas
None of the interrupt setup code touches 'vector', so we can move it earlier in the function. This will allow us to later move the System Call Vectored setup that is on the top level into the
POWERPC_EXCP_SYSCALL_VECTOREDcode block.This patch also moves the verification for when 'excp' does not have an address associated with it. We now bail a little earlier when that is the case. This should not cause any visible effects.
Quoted 5 lines
Signed-off-by Fabiano Rosas<[email protected]>Reviewed-by Cédric Le Goater<[email protected]>--- target/ppc/excp_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
r~
Re: [PATCH v2 3/5] target/ppc: powerpc_excp: Set vector earlier
In reply to Fabiano RosasQuoted 11 lines · Fabiano Rosas
None of the interrupt setup code touches 'vector', so we can move it earlier in the function. This will allow us to later move the System Call Vectored setup that is on the top level into the
POWERPC_EXCP_SYSCALL_VECTOREDcode block.This patch also moves the verification for when 'excp' does not have an address associated with it. We now bail a little earlier when that is the case. This should not cause any visible effects.
Signed-off-by Fabiano Rosas <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
Quoted 38 lines
--- target/ppc/excp_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)target/ppc/excp_helper.c +8
-8@@ -356,6 +356,14 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) }#endif + vector = env->excp_vectors[excp]; +if (vector == (target_ulong)-1ULL ) { +cpu_abort (cs,"Raised an exception without defined vector %d\n" , + excp); + } + + vector |= env->excp_prefix; +switch (excp) {case POWERPC_EXCP_CRITICAL :/* Critical input */ switch (excp_model) {@@ -832,14 +840,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) }#endif - vector = env->excp_vectors[excp]; -if (vector == (target_ulong)-1ULL ) { -cpu_abort (cs,"Raised an exception without defined vector %d\n" , - excp); - } - - vector |= env->excp_prefix; -#if defined(TARGET_PPC64 )if (excp_model ==POWERPC_EXCP_BOOKE ) {if (env->spr[SPR_BOOKE_EPCR ] &EPCR_ICM ) {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 4/5 target/ppc: powerpc_excp: Move system call vectored code together
In reply to Fabiano RosasNow that 'vector' is known before calling the interrupt-specific setup code, we can move all of the scv setup into one place.
No functional change intended.
--- target/ppc/excp_helper.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
target/ppc/excp_helper.c +5 -8
@@ -550,6 +550,11 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp) env->nip +=4 ; new_msr |= env->msr & ((target_ulong )1 <<MSR_EE ); new_msr |= env->msr & ((target_ulong )1 <<MSR_RI ); + + vector += lev *0x20 ; + + env->lr = env->nip; + env->ctr = msr;break ;case POWERPC_EXCP_FPU :/* Floating-point unavailable exception */ case POWERPC_EXCP_APU :/* Auxiliary processor unavailable */
@@ -863,14 +868,6 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)/* Save MSR */ env->spr[srr1] = msr; - -#if defined(TARGET_PPC64 ) - } else { - vector += lev *0x20 ; - - env->lr = env->nip; - env->ctr = msr; -#endif }/* This can update new_msr and vector if AIL applies */
Signature · 1 line
2.33.1
PATCH v2 5/5 target/ppc: powerpc_excp: Stop passing excp_model around
In reply to Fabiano RosasWe can just access it directly in powerpc_excp.
--- target/ppc/excp_helper.c | 43 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-)
target/ppc/excp_helper.c +21 -22
@@ -293,10 +293,11 @@ static inline void powerpc_set_excp_state(PowerPCCPU *cpu,* Note that this function should be greatly optimized when called * with a constant excp, from ppc_hw_interrupt */ -static inline void powerpc_excp (PowerPCCPU *cpu,int excp_model,int excp) +static inline void powerpc_excp (PowerPCCPU *cpu,int excp) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; +int excp_model = env->excp_model;target_ulong msr, new_msr, vector;int srr0, srr1, lev =-1 ;
@@ -879,9 +880,8 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)void ppc_cpu_do_interrupt (CPUState *cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); -CPUPPCState *env = &cpu->env; -powerpc_excp (cpu, env->excp_model, cs->exception_index); +powerpc_excp (cpu, cs->exception_index); }static void ppc_hw_interrupt (CPUPPCState *env)
@@ -892,20 +892,20 @@ static void ppc_hw_interrupt(CPUPPCState *env)/* External reset */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_RESET )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_RESET ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_RESET ); +powerpc_excp (cpu,POWERPC_EXCP_RESET );return ; }/* Machine check exception */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_MCK )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_MCK ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_MCHECK ); +powerpc_excp (cpu,POWERPC_EXCP_MCHECK );return ; }#if 0 /* TODO */ /* External debug exception */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_DEBUG )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_DEBUG ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_DEBUG ); +powerpc_excp (cpu,POWERPC_EXCP_DEBUG );return ; }#endif
@@ -925,7 +925,7 @@ static void ppc_hw_interrupt(CPUPPCState *env)if ((async_deliver || msr_hv ==0 ) && hdice) {/* HDEC clears on delivery */ env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_HDECR ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_HDECR ); +powerpc_excp (cpu,POWERPC_EXCP_HDECR );return ; } }
@@ -935,7 +935,7 @@ static void ppc_hw_interrupt(CPUPPCState *env)/* LPCR will be clear when not supported so this will work */ bool hvice = !!(env->spr[SPR_LPCR ] &LPCR_HVICE );if ((async_deliver || msr_hv ==0 ) && hvice) { -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_HVIRT ); +powerpc_excp (cpu,POWERPC_EXCP_HVIRT );return ; } }
@@ -947,14 +947,14 @@ static void ppc_hw_interrupt(CPUPPCState *env)/* HEIC blocks delivery to the hypervisor */ if ((async_deliver && !(heic && msr_hv && !msr_pr)) || (env->has_hv_mode && msr_hv ==0 && !lpes0)) { -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_EXTERNAL ); +powerpc_excp (cpu,POWERPC_EXCP_EXTERNAL );return ; } }if (msr_ce !=0 ) {/* External critical interrupt */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_CEXT )) { -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_CRITICAL ); +powerpc_excp (cpu,POWERPC_EXCP_CRITICAL );return ; } }
@@ -962,24 +962,24 @@ static void ppc_hw_interrupt(CPUPPCState *env)/* Watchdog timer on embedded PowerPC */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_WDT )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_WDT ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_WDT ); +powerpc_excp (cpu,POWERPC_EXCP_WDT );return ; }if (env->pending_interrupts & (1 <<PPC_INTERRUPT_CDOORBELL )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_CDOORBELL ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_DOORCI ); +powerpc_excp (cpu,POWERPC_EXCP_DOORCI );return ; }/* Fixed interval timer on embedded PowerPC */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_FIT )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_FIT ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_FIT ); +powerpc_excp (cpu,POWERPC_EXCP_FIT );return ; }/* Programmable interval timer on embedded PowerPC */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_PIT )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_PIT ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_PIT ); +powerpc_excp (cpu,POWERPC_EXCP_PIT );return ; }/* Decrementer exception */
@@ -987,32 +987,32 @@ static void ppc_hw_interrupt(CPUPPCState *env)if (ppc_decr_clear_on_delivery (env)) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_DECR ); } -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_DECR ); +powerpc_excp (cpu,POWERPC_EXCP_DECR );return ; }if (env->pending_interrupts & (1 <<PPC_INTERRUPT_DOORBELL )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_DOORBELL );if (is_book3s_arch2x (env)) { -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_SDOOR ); +powerpc_excp (cpu,POWERPC_EXCP_SDOOR ); }else { -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_DOORI ); +powerpc_excp (cpu,POWERPC_EXCP_DOORI ); }return ; }if (env->pending_interrupts & (1 <<PPC_INTERRUPT_HDOORBELL )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_HDOORBELL ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_SDOOR_HV ); +powerpc_excp (cpu,POWERPC_EXCP_SDOOR_HV );return ; }if (env->pending_interrupts & (1 <<PPC_INTERRUPT_PERFM )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_PERFM ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_PERFM ); +powerpc_excp (cpu,POWERPC_EXCP_PERFM );return ; }/* Thermal interrupt */ if (env->pending_interrupts & (1 <<PPC_INTERRUPT_THERM )) { env->pending_interrupts &= ~(1 <<PPC_INTERRUPT_THERM ); -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_THERM ); +powerpc_excp (cpu,POWERPC_EXCP_THERM );return ; } }
@@ -1037,9 +1037,8 @@ static void ppc_hw_interrupt(CPUPPCState *env)void ppc_cpu_do_system_reset (CPUState *cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); -CPUPPCState *env = &cpu->env; -powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_RESET ); +powerpc_excp (cpu,POWERPC_EXCP_RESET ); }void ppc_cpu_do_fwnmi_machine_check (CPUState *cs,target_ulong vector)
Signature · 1 line
2.33.1
Cédric Le Goater
AppliedQuoted 5 lines · Fabiano Rosas
This series comprises of the first 4 patches from the RFC v2 plus an extra patch addressing review comments.
Patch 1,3,4,5 have been reviewed.
Quoted 8 lines
Patch 2 addresses prior comments from patch 3 and has not been reviewed.
RFC v1:
https://lists.nongnu.org/archive/html/qemu-ppc/2021-06/msg00026.htmlRFC v2:
https://lists.nongnu.org/archive/html/qemu-ppc/2021-12/msg00542.html
Applied in ppc-next.
Thanks,
C.