target/ppc: Move TCG code from excp_helper.c to tcg-excp_helper.c
v2 cover target/ppc: Move TCG code from excp_helper.c to tcg-excp_helper.c
Since v1:
- Keep ppc_tcg_hv_emu() within TARGET_PPC64 (patch #10)
Hi,
This series is a simply a cleanup restricting TCG specific exception-related code to TCG, by moving code to a new unit named 'tcg-excp_helper.c'.
I ended doing it as a preliminary cleanup for the "Extract TCG state from CPUState".
Diffstat shows 1K lines moved, but the patches are trivial to review using 'git-diff --color-moved=dimmed-zebra' option.
Branch published as:
https://gitlab.com/philmd/qemu/-/tree/ppc_excp_extract_tcg
Regards,
Phil.
Philippe Mathieu-Daudé (15):
hw/ppc/spapr: Restrict CONFER hypercall to TCG hw/ppc/spapr: Restrict part of PAGE_INIT hypercall to TCG target/ppc: Make ppc_ldl_code() declaration public target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c target/ppc: Move ppc_ldl_code() to tcg-excp_helper.c target/ppc: Ensure powerpc_checkstop() is only called under TCG target/ppc: Restrict powerpc_checkstop() to TCG target/ppc: Remove raise_exception_ra()
target/ppc: Restrict exception helpers to TCG
target/ppc: Restrict ppc_tcg_hv_emu() to TCG
target/ppc: Restrict various common helpers to TCG target/ppc: Fix style in excp_helper.c
target/ppc: Make powerpc_excp() prototype public target/ppc: Restrict ATTN / SCV / PMINSN helpers to TCG target/ppc: Restrict various system helpers to TCG
target/ppc/cpu.h | 5 - target/ppc/internal.h | 11 +- hw/ppc/spapr_hcall.c | 6 +- target/ppc/excp_helper.c | 943 +---------------------------------- target/ppc/tcg-excp_helper.c | 924 ++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 6 files changed, 955 insertions(+), 935 deletions(-) create mode 100644 target/ppc/tcg-excp_helper.c
Signature · 1 line
2.47.1
PATCH v2 1/15 hw/ppc/spapr: Restrict CONFER hypercall to TCG
TODO: Add PPC folks why :)
--- hw/ppc/spapr_hcall.c | 2 ++ 1 file changed, 2 insertions(+)
hw/ppc/spapr_hcall.c +2 -0
@@ -578,6 +578,8 @@ static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr,CPUState *cs =CPU (cpu);SpaprCpuState *spapr_cpu; +assert (tcg_enabled ());/* KVM will have handled this */ +/* * -1 means confer to all other CPUs without dispatch counter check, * otherwise it's a targeted confer.
Signature · 1 line
2.47.1
Re: [PATCH v2 01/15] hw/ppc/spapr: Restrict CONFER hypercall to TCG
Hi Philippe,
Quoted 1 line · Philippe Mathieu-Daudé
TODO: Add PPC folks why :)
While this appear be TCG specific, may I know what caused you to bring this change? Usually we have blanks stubs for hcalls in KVM mode which are only TCG specific. That helps in avoiding building TCG specific code when building with TCG disabled.
Nick, thoughts?
regards,
Harsh
Quoted 19 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ppc/spapr_hcall.c | 2 ++ 1 file changed, 2 insertions(+)hw/ppc/spapr_hcall.c +2
-0@@ -578,6 +578,8 @@ static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr,CPUState *cs =CPU (cpu);SpaprCpuState *spapr_cpu; +assert (tcg_enabled ());/* KVM will have handled this */ +/* * -1 means confer to all other CPUs without dispatch counter check, * otherwise it's a targeted confer.
PATCH v2 2/15 hw/ppc/spapr: Restrict part of PAGE_INIT hypercall to TCG
In reply to Philippe Mathieu-DaudéRestrict the tb_flush() call to TCG. Assert we are using KVM or TCG.
--- hw/ppc/spapr_hcall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ppc/spapr_hcall.c +3 -1
@@ -299,8 +299,10 @@ static target_ulong h_page_init(PowerPCCPU *cpu, SpaprMachineState *spapr,if (flags & (H_ICACHE_SYNCHRONIZE |H_ICACHE_INVALIDATE )) {if (kvm_enabled ()) {kvmppc_icbi_range (cpu, pdst, len); - }else { + }else if (tcg_enabled ()) {tb_flush (CPU (cpu)); + }else { +g_assert_not_reached (); } }
Signature · 1 line
2.47.1
Re: [PATCH v2 02/15] hw/ppc/spapr: Restrict part of PAGE_INIT hypercall to TCG
Quoted 3 lines · Philippe Mathieu-Daudé
Restrict the
tb_flush()call to TCG. Assert we are using KVM or TCG.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 20 lines
--- hw/ppc/spapr_hcall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/ppc/spapr_hcall.c +3
-1@@ -299,8 +299,10 @@ static target_ulong h_page_init(PowerPCCPU *cpu, SpaprMachineState *spapr,if (flags & (H_ICACHE_SYNCHRONIZE |H_ICACHE_INVALIDATE )) {if (kvm_enabled ()) {kvmppc_icbi_range (cpu, pdst, len); - }else { + }else if (tcg_enabled ()) {tb_flush (CPU (cpu)); + }else { +g_assert_not_reached (); } }
PATCH v2 3/15 target/ppc: Make ppc_ldl_code() declaration public
In reply to Philippe Mathieu-DaudéWe are going to move code calling ppc_ldl_code() out of excp_helper.c where it is defined. Expose its declaration for few commits, until eventually making it static again once everything is moved.
--- target/ppc/internal.h | 2 ++ target/ppc/excp_helper.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
target/ppc/internal.h +2 -0
@@ -268,6 +268,8 @@ static inline void pte_invalidate(target_ulong *pte0)#define PTE_PTEM_MASK 0x7FFFFFBF#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B) +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr); +#ifdef CONFIG_USER_ONLY void ppc_cpu_record_sigsegv(CPUState *cs, vaddr addr, MMUAccessType access_type,
target/ppc/excp_helper.c +1 -1
@@ -144,7 +144,7 @@ static inline bool insn_need_byteswap(CPUArchState *env)return !!(env->msr & ((target_ulong )1 <<MSR_LE )); } -static uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) {uint32_t insn =cpu_ldl_code (env, addr);
Signature · 1 line
2.47.1
Re: [PATCH v2 03/15] target/ppc: Make ppc_ldl_code() declaration public
Quoted 6 lines · Philippe Mathieu-Daudé
We are going to move code calling
ppc_ldl_code()out ofexcp_helper.cwhere it is defined. Expose its declaration for few commits, until eventually making it static again once everything is moved.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 31 lines
--- target/ppc/internal.h | 2 ++ target/ppc/excp_helper.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)target/ppc/internal.h +2
-0@@ -268,6 +268,8 @@ static inline void pte_invalidate(target_ulong *pte0)#define PTE_PTEM_MASK 0x7FFFFFBF#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B) +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr); +#ifdef CONFIG_USER_ONLY void ppc_cpu_record_sigsegv(CPUState *cs, vaddr addr, MMUAccessType access_type,target/ppc/excp_helper.c +1
-1@@ -144,7 +144,7 @@ static inline bool insn_need_byteswap(CPUArchState *env)return !!(env->msr & ((target_ulong )1 <<MSR_LE )); } -static uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) {uint32_t insn =cpu_ldl_code (env, addr);
PATCH v2 4/15 target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c
In reply to Philippe Mathieu-DaudéMove the TCGCPUOps handlers to a new unit: tcg-excp_helper.c, only built when TCG is selected.
See in target/ppc/cpu_init.c:
#ifdef CONFIG_TCG
static const TCGCPUOps ppc_tcg_ops = {
...
.do_unaligned_access = ppc_cpu_do_unaligned_access, .do_transaction_failed = ppc_cpu_do_transaction_failed, .debug_excp_handler = ppc_cpu_debug_excp_handler, .debug_check_breakpoint = ppc_cpu_debug_check_breakpoint, .debug_check_watchpoint = ppc_cpu_debug_check_watchpoint,
};
#endif /* CONFIG_TCG */
--- target/ppc/excp_helper.c | 173 ------------------------------ target/ppc/tcg-excp_helper.c | 202 +++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 3 files changed, 203 insertions(+), 173 deletions(-) create mode 100644 target/ppc/tcg-excp_helper.c
target/ppc/excp_helper.c +0 -173
@@ -3144,178 +3144,5 @@ void helper_book3s_trace(CPUPPCState *env, target_ulong prev_ip)raise_exception_err (env,POWERPC_EXCP_TRACE , error_code); } -void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr, -MMUAccessType access_type, -int mmu_idx,uintptr_t retaddr) -{ -CPUPPCState *env =cpu_env (cs); -uint32_t insn; - -/* Restore state and reload the insn we executed, for filling in DSISR. */ -cpu_restore_state (cs, retaddr); - insn =ppc_ldl_code (env, env->nip); - -switch (env->mmu_model) { -case POWERPC_MMU_SOFT_4xx: - env->spr[SPR_40x_DEAR] = vaddr; -break ; -case POWERPC_MMU_BOOKE : -case POWERPC_MMU_BOOKE206 : - env->spr[SPR_BOOKE_DEAR ] = vaddr; -break ; -default : - env->spr[SPR_DAR ] = vaddr; -break ; - } - - cs->exception_index =POWERPC_EXCP_ALIGN ; - env->error_code = insn &0x03FF0000 ; -cpu_loop_exit (cs); -} - -void ppc_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, -vaddr vaddr,unsigned size, -MMUAccessType access_type, -int mmu_idx,MemTxAttrs attrs, -MemTxResult response,uintptr_t retaddr) -{ -CPUPPCState *env =cpu_env (cs); - -switch (env->excp_model) { -#if defined(TARGET_PPC64 ) -case POWERPC_EXCP_POWER8 : -case POWERPC_EXCP_POWER9 : -case POWERPC_EXCP_POWER10 : -case POWERPC_EXCP_POWER11 : -/* -* Machine check codes can be found in processor User Manual or -* Linux or skiboot source. -*/ -if (access_type ==MMU_DATA_LOAD ) { - env->spr[SPR_DAR ] = vaddr; - env->spr[SPR_DSISR ] =PPC_BIT (57 ); - env->error_code =PPC_BIT (42 ); - - }else if (access_type ==MMU_DATA_STORE ) { -/* -* MCE for stores in POWER is asynchronous so hardware does -* not set DAR, but QEMU can do better. -*/ - env->spr[SPR_DAR ] = vaddr; - env->error_code =PPC_BIT (36 ) |PPC_BIT (43 ) |PPC_BIT (45 ); - env->error_code |=PPC_BIT (42 ); - - }else {/* Fetch */ -/* -* is_prefix_insn_excp() tests !PPC_BIT(42) to avoid fetching -* the instruction, so that must always be clear for fetches. -*/ - env->error_code =PPC_BIT (36 ) |PPC_BIT (44 ) |PPC_BIT (45 ); - } -break ; -#endif -default : -/* -* TODO: Check behaviour for other CPUs, for now do nothing. -* Could add a basic MCE even if real hardware ignores. -*/ -return ; - } - - cs->exception_index =POWERPC_EXCP_MCHECK ; -cpu_loop_exit_restore (cs, retaddr); -} - -void ppc_cpu_debug_excp_handler (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (cs->watchpoint_hit) { -if (cs->watchpoint_hit->flags &BP_CPU ) { - env->spr[SPR_DAR ] = cs->watchpoint_hit->hitaddr; - env->spr[SPR_DSISR ] =PPC_BIT (41 ); - cs->watchpoint_hit =NULL ; -raise_exception (env,POWERPC_EXCP_DSI ); - } - cs->watchpoint_hit =NULL ; - }else if (cpu_breakpoint_test (cs, env->nip,BP_CPU )) { -raise_exception_err (env,POWERPC_EXCP_TRACE , -PPC_BIT (33 ) |PPC_BIT (43 )); - } - } -#endif -} - -bool ppc_cpu_debug_check_breakpoint (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -target_ulong priv; - - priv = env->spr[SPR_CIABR ] &PPC_BITMASK (62 ,63 ); -switch (priv) { -case 0x1 :/* problem */ -return env->msr & ((target_ulong )1 <<MSR_PR ); -case 0x2 :/* supervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - !(env->msr & ((target_ulong )1 <<MSR_HV ))); -case 0x3 :/* hypervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - (env->msr & ((target_ulong )1 <<MSR_HV ))); -default : -g_assert_not_reached (); - } - } -#endif - -return false; -} - -bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (wp == env->dawr0_watchpoint) { -uint32_t dawrx = env->spr[SPR_DAWRX0 ]; -bool wt =extract32 (dawrx,PPC_BIT_NR (59 ),1 ); -bool wti =extract32 (dawrx,PPC_BIT_NR (60 ),1 ); -bool hv =extract32 (dawrx,PPC_BIT_NR (61 ),1 ); -bool sv =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); -bool pr =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); - -if ((env->msr & ((target_ulong )1 <<MSR_PR )) && !pr) { -return false; - }else if ((env->msr & ((target_ulong )1 <<MSR_HV )) && !hv) { -return false; - }else if (!sv) { -return false; - } - -if (!wti) { -if (env->msr & ((target_ulong )1 <<MSR_DR )) { -if (!wt) { -return false; - } - }else { -if (wt) { -return false; - } - } - } - -return true; - } - } -#endif - -return false; -} -#endif /* !CONFIG_USER_ONLY */ #endif /* CONFIG_TCG */
target/ppc/tcg-excp_helper.c new file +202 -0
202 lines not on this page · raw message
target/ppc/meson.build +1 -0
@@ -14,6 +14,7 @@ ppc_ss.add(when: 'CONFIG_TCG', if_true: files( 'int_helper.c', 'mem_helper.c', 'misc_helper.c', + 'tcg-excp_helper.c', 'timebase_helper.c', 'translate.c', 'power8-pmu.c',
Signature · 1 line
2.47.1
Re: [PATCH v2 04/15] target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c
Quoted 3 lines · Philippe Mathieu-Daudé
Move the TCGCPUOps handlers to a new unit:
tcg-excp_helper.c, only built when TCG is selected.
Nice.
Just a thought - will the filename look better as excp_helper-tcg.c ? That naming usually help developers when using tab completion.
Quoted 13 lines
See in
target/ppc/cpu_init.c:#ifdef
CONFIG_TCG
static const TCGCPUOpsppc_tcg_ops= {
...
.do_unaligned_access =ppc_cpu_do_unaligned_access, .do_transaction_failed =ppc_cpu_do_transaction_failed, .debug_excp_handler =ppc_cpu_debug_excp_handler, .debug_check_breakpoint =ppc_cpu_debug_check_breakpoint, .debug_check_watchpoint =ppc_cpu_debug_check_watchpoint,
};
#endif /*CONFIG_TCG*/
Thanks for capturing this in commit log.
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 410 lines
--- target/ppc/excp_helper.c | 173 ------------------------------ target/ppc/tcg-excp_helper.c | 202 +++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 3 files changed, 203 insertions(+), 173 deletions(-)create mode 100644
target/ppc/tcg-excp_helper.ctarget/ppc/excp_helper.c +0
-173@@ -3144,178 +3144,5 @@ void helper_book3s_trace(CPUPPCState *env, target_ulong prev_ip)raise_exception_err (env,POWERPC_EXCP_TRACE , error_code); } -void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr, -MMUAccessType access_type, -int mmu_idx,uintptr_t retaddr) -{ -CPUPPCState *env =cpu_env (cs); -uint32_t insn; - -/* Restore state and reload the insn we executed, for filling in DSISR. */ -cpu_restore_state (cs, retaddr); - insn =ppc_ldl_code (env, env->nip); - -switch (env->mmu_model) { -case POWERPC_MMU_SOFT_4xx: - env->spr[SPR_40x_DEAR] = vaddr; -break ; -case POWERPC_MMU_BOOKE : -case POWERPC_MMU_BOOKE206 : - env->spr[SPR_BOOKE_DEAR ] = vaddr; -break ; -default : - env->spr[SPR_DAR ] = vaddr; -break ; - } - - cs->exception_index =POWERPC_EXCP_ALIGN ; - env->error_code = insn &0x03FF0000 ; -cpu_loop_exit (cs); -} - -void ppc_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, -vaddr vaddr,unsigned size, -MMUAccessType access_type, -int mmu_idx,MemTxAttrs attrs, -MemTxResult response,uintptr_t retaddr) -{ -CPUPPCState *env =cpu_env (cs); - -switch (env->excp_model) { -#if defined(TARGET_PPC64 ) -case POWERPC_EXCP_POWER8 : -case POWERPC_EXCP_POWER9 : -case POWERPC_EXCP_POWER10 : -case POWERPC_EXCP_POWER11 : -/* -* Machine check codes can be found in processor User Manual or -* Linux or skiboot source. -*/ -if (access_type ==MMU_DATA_LOAD ) { - env->spr[SPR_DAR ] = vaddr; - env->spr[SPR_DSISR ] =PPC_BIT (57 ); - env->error_code =PPC_BIT (42 ); - - }else if (access_type ==MMU_DATA_STORE ) { -/* -* MCE for stores in POWER is asynchronous so hardware does -* not set DAR, but QEMU can do better. -*/ - env->spr[SPR_DAR ] = vaddr; - env->error_code =PPC_BIT (36 ) |PPC_BIT (43 ) |PPC_BIT (45 ); - env->error_code |=PPC_BIT (42 ); - - }else {/* Fetch */ -/* -* is_prefix_insn_excp() tests !PPC_BIT(42) to avoid fetching -* the instruction, so that must always be clear for fetches. -*/ - env->error_code =PPC_BIT (36 ) |PPC_BIT (44 ) |PPC_BIT (45 ); - } -break ; -#endif -default : -/* -* TODO: Check behaviour for other CPUs, for now do nothing. -* Could add a basic MCE even if real hardware ignores. -*/ -return ; - } - - cs->exception_index =POWERPC_EXCP_MCHECK ; -cpu_loop_exit_restore (cs, retaddr); -} - -void ppc_cpu_debug_excp_handler (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (cs->watchpoint_hit) { -if (cs->watchpoint_hit->flags &BP_CPU ) { - env->spr[SPR_DAR ] = cs->watchpoint_hit->hitaddr; - env->spr[SPR_DSISR ] =PPC_BIT (41 ); - cs->watchpoint_hit =NULL ; -raise_exception (env,POWERPC_EXCP_DSI ); - } - cs->watchpoint_hit =NULL ; - }else if (cpu_breakpoint_test (cs, env->nip,BP_CPU )) { -raise_exception_err (env,POWERPC_EXCP_TRACE , -PPC_BIT (33 ) |PPC_BIT (43 )); - } - } -#endif -} - -bool ppc_cpu_debug_check_breakpoint (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -target_ulong priv; - - priv = env->spr[SPR_CIABR ] &PPC_BITMASK (62 ,63 ); -switch (priv) { -case 0x1 :/* problem */ -return env->msr & ((target_ulong )1 <<MSR_PR ); -case 0x2 :/* supervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - !(env->msr & ((target_ulong )1 <<MSR_HV ))); -case 0x3 :/* hypervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - (env->msr & ((target_ulong )1 <<MSR_HV ))); -default : -g_assert_not_reached (); - } - } -#endif - -return false; -} - -bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (wp == env->dawr0_watchpoint) { -uint32_t dawrx = env->spr[SPR_DAWRX0 ]; -bool wt =extract32 (dawrx,PPC_BIT_NR (59 ),1 ); -bool wti =extract32 (dawrx,PPC_BIT_NR (60 ),1 ); -bool hv =extract32 (dawrx,PPC_BIT_NR (61 ),1 ); -bool sv =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); -bool pr =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); - -if ((env->msr & ((target_ulong )1 <<MSR_PR )) && !pr) { -return false; - }else if ((env->msr & ((target_ulong )1 <<MSR_HV )) && !hv) { -return false; - }else if (!sv) { -return false; - } - -if (!wti) { -if (env->msr & ((target_ulong )1 <<MSR_DR )) { -if (!wt) { -return false; - } - }else { -if (wt) { -return false; - } - } - } - -return true; - } - } -#endif - -return false; -} -#endif /* !CONFIG_USER_ONLY */ #endif /* CONFIG_TCG */ target/ppc/tcg-excp_helper.c new file +202
-0@@ -0,0 +1,202 @@ +/* +* PowerPC exception emulation helpers for QEMU (TCG specific) +* +* Copyright (c) 2003-2007 Jocelyn Mayer +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#include "qemu/osdep.h" +#include "exec/cpu_ldst.h" + +#include "hw/ppc/ppc.h" +#include "internal.h" +#include "cpu.h" +#include "trace.h" + +#ifndef CONFIG_USER_ONLY + +void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr, +MMUAccessType access_type, +int mmu_idx,uintptr_t retaddr) +{ +CPUPPCState *env =cpu_env (cs); +uint32_t insn; + +/* Restore state and reload the insn we executed, for filling in DSISR. */ +cpu_restore_state (cs, retaddr); + insn =ppc_ldl_code (env, env->nip); + +switch (env->mmu_model) { +case POWERPC_MMU_SOFT_4xx: + env->spr[SPR_40x_DEAR] = vaddr; +break ; +case POWERPC_MMU_BOOKE : +case POWERPC_MMU_BOOKE206 : + env->spr[SPR_BOOKE_DEAR ] = vaddr; +break ; +default : + env->spr[SPR_DAR ] = vaddr; +break ; + } + + cs->exception_index =POWERPC_EXCP_ALIGN ; + env->error_code = insn &0x03FF0000 ; +cpu_loop_exit (cs); +} + +void ppc_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr vaddr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, +MemTxResult response,uintptr_t retaddr) +{ +CPUPPCState *env =cpu_env (cs); + +switch (env->excp_model) { +#if defined(TARGET_PPC64 ) +case POWERPC_EXCP_POWER8 : +case POWERPC_EXCP_POWER9 : +case POWERPC_EXCP_POWER10 : +case POWERPC_EXCP_POWER11 : +/* +* Machine check codes can be found in processor User Manual or +* Linux or skiboot source. +*/ +if (access_type ==MMU_DATA_LOAD ) { + env->spr[SPR_DAR ] = vaddr; + env->spr[SPR_DSISR ] =PPC_BIT (57 ); + env->error_code =PPC_BIT (42 ); + + }else if (access_type ==MMU_DATA_STORE ) { +/* +* MCE for stores in POWER is asynchronous so hardware does +* not set DAR, but QEMU can do better. +*/ + env->spr[SPR_DAR ] = vaddr; + env->error_code =PPC_BIT (36 ) |PPC_BIT (43 ) |PPC_BIT (45 ); + env->error_code |=PPC_BIT (42 ); + + }else {/* Fetch */ +/* +* is_prefix_insn_excp() tests !PPC_BIT(42) to avoid fetching +* the instruction, so that must always be clear for fetches. +*/ + env->error_code =PPC_BIT (36 ) |PPC_BIT (44 ) |PPC_BIT (45 ); + } +break ; +#endif +default : +/* +* TODO: Check behaviour for other CPUs, for now do nothing. +* Could add a basic MCE even if real hardware ignores. +*/ +return ; + } + + cs->exception_index =POWERPC_EXCP_MCHECK ; +cpu_loop_exit_restore (cs, retaddr); +} + +void ppc_cpu_debug_excp_handler (CPUState *cs) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +if (cs->watchpoint_hit) { +if (cs->watchpoint_hit->flags &BP_CPU ) { + env->spr[SPR_DAR ] = cs->watchpoint_hit->hitaddr; + env->spr[SPR_DSISR ] =PPC_BIT (41 ); + cs->watchpoint_hit =NULL ; +raise_exception (env,POWERPC_EXCP_DSI ); + } + cs->watchpoint_hit =NULL ; + }else if (cpu_breakpoint_test (cs, env->nip,BP_CPU )) { +raise_exception_err (env,POWERPC_EXCP_TRACE , +PPC_BIT (33 ) |PPC_BIT (43 )); + } + } +#endif +} + +bool ppc_cpu_debug_check_breakpoint (CPUState *cs) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +target_ulong priv; + + priv = env->spr[SPR_CIABR ] &PPC_BITMASK (62 ,63 ); +switch (priv) { +case 0x1 :/* problem */ +return env->msr & ((target_ulong )1 <<MSR_PR ); +case 0x2 :/* supervisor */ +return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && + !(env->msr & ((target_ulong )1 <<MSR_HV ))); +case 0x3 :/* hypervisor */ +return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && + (env->msr & ((target_ulong )1 <<MSR_HV ))); +default : +g_assert_not_reached (); + } + } +#endif + +return false; +} + +bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +if (wp == env->dawr0_watchpoint) { +uint32_t dawrx = env->spr[SPR_DAWRX0 ]; +bool wt =extract32 (dawrx,PPC_BIT_NR (59 ),1 ); +bool wti =extract32 (dawrx,PPC_BIT_NR (60 ),1 ); +bool hv =extract32 (dawrx,PPC_BIT_NR (61 ),1 ); +bool sv =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); +bool pr =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); + +if ((env->msr & ((target_ulong )1 <<MSR_PR )) && !pr) { +return false; + }else if ((env->msr & ((target_ulong )1 <<MSR_HV )) && !hv) { +return false; + }else if (!sv) { +return false; + } + +if (!wti) { +if (env->msr & ((target_ulong )1 <<MSR_DR )) { +if (!wt) { +return false; + } + }else { +if (wt) { +return false; + } + } + } + +return true; + } + } +#endif + +return false; +} + +#endif /* !CONFIG_USER_ONLY */ target/ppc/meson.build +1
-0@@ -14,6 +14,7 @@ ppc_ss.add(when: 'CONFIG_TCG', if_true: files( 'int_helper.c', 'mem_helper.c', 'misc_helper.c', + 'tcg-excp_helper.c', 'timebase_helper.c', 'translate.c', 'power8-pmu.c',
Re: [PATCH v2 04/15] target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c
Quoted 8 lines · Harsh Prateek Bora
Quoted 3 lines · Philippe Mathieu-Daudé
Move the TCGCPUOps handlers to a new unit:
tcg-excp_helper.c, only built when TCG is selected.Nice.
Just a thought - will the filename look better asexcp_helper-tcg.c? That naming usually help developers when using tab completion.
Or maybe stick to either _ or - in the filename and not mix both in one name? If you want to use -tcg or tcg- then also rename to excp-helper. We already have a mix of _ and - names but at least try to be consistent within one name.
Regards,
BALATON Zoltan
Quoted 437 lines
Quoted 13 lines
See in
target/ppc/cpu_init.c:#ifdef
CONFIG_TCG
static const TCGCPUOpsppc_tcg_ops= {
...
.do_unaligned_access =ppc_cpu_do_unaligned_access, .do_transaction_failed =ppc_cpu_do_transaction_failed, .debug_excp_handler =ppc_cpu_debug_excp_handler, .debug_check_breakpoint =ppc_cpu_debug_check_breakpoint, .debug_check_watchpoint =ppc_cpu_debug_check_watchpoint,
};
#endif /*CONFIG_TCG*/Thanks for capturing this in commit log.
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Harsh Prateek Bora <[email protected]>Quoted 415 lines
--- target/ppc/excp_helper.c | 173 ------------------------------ target/ppc/tcg-excp_helper.c | 202 +++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 3 files changed, 203 insertions(+), 173 deletions(-)create mode 100644
target/ppc/tcg-excp_helper.ctarget/ppc/excp_helper.c +0
-7@@ -3144,178 +3144,5 @@ void helper_book3s_trace(CPUPPCState *env, target_ulong prev_ip)raise_exception_err (env ,POWERPC_EXCP_TRACE ,error_code ); } -void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, - MMUAccessType access_type, - int mmu_idx, uintptr_t retaddr) -{ -CPUPPCState *env =cpu_env (cs); -uint32_t insn; - -/* Restore state and reload the insn we executed, for filling in DSISR. */
target/ppc/excp_helper.c +0
-26-cpu_restore_state (cs, retaddr); - insn =ppc_ldl_code (env, env->nip); - -switch (env->mmu_model) { -case POWERPC_MMU_SOFT_4xx: - env->spr[SPR_40x_DEAR] = vaddr; -break ; -case POWERPC_MMU_BOOKE : -case POWERPC_MMU_BOOKE206 : - env->spr[SPR_BOOKE_DEAR ] = vaddr; -break ; -default : - env->spr[SPR_DAR ] = vaddr; -break ; - } - - cs->exception_index =POWERPC_EXCP_ALIGN ; - env->error_code = insn &0x03FF0000 ; -cpu_loop_exit (cs); -} - -void ppc_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, -vaddr vaddr,unsigned size, -MMUAccessType access_type, -int mmu_idx,MemTxAttrs attrs, - MemTxResult response, uintptr_tretaddr)
target/ppc/excp_helper.c +0
-139-{ -CPUPPCState *env =cpu_env (cs); - -switch (env->excp_model) { -#if defined(TARGET_PPC64 ) -case POWERPC_EXCP_POWER8 : -case POWERPC_EXCP_POWER9 : -case POWERPC_EXCP_POWER10 : -case POWERPC_EXCP_POWER11 : -/* -* Machine check codes can be found in processor User Manual or -* Linux or skiboot source. -*/ -if (access_type ==MMU_DATA_LOAD ) { - env->spr[SPR_DAR ] = vaddr; - env->spr[SPR_DSISR ] =PPC_BIT (57 ); - env->error_code =PPC_BIT (42 ); - - }else if (access_type ==MMU_DATA_STORE ) { -/* -* MCE for stores in POWER is asynchronous so hardware does -* not set DAR, but QEMU can do better. -*/ - env->spr[SPR_DAR ] = vaddr; - env->error_code =PPC_BIT (36 ) |PPC_BIT (43 ) |PPC_BIT (45 ); - env->error_code |=PPC_BIT (42 ); - - }else {/* Fetch */ -/* -* is_prefix_insn_excp() tests !PPC_BIT(42) to avoid fetching -* the instruction, so that must always be clear for fetches. -*/ - env->error_code =PPC_BIT (36 ) |PPC_BIT (44 ) |PPC_BIT (45 ); - } -break ; -#endif -default : -/* -* TODO: Check behaviour for other CPUs, for now do nothing. -* Could add a basic MCE even if real hardware ignores. -*/ -return ; - } - - cs->exception_index =POWERPC_EXCP_MCHECK ; -cpu_loop_exit_restore (cs, retaddr); -} - -void ppc_cpu_debug_excp_handler (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (cs->watchpoint_hit) { -if (cs->watchpoint_hit->flags &BP_CPU ) { - env->spr[SPR_DAR ] = cs->watchpoint_hit->hitaddr; - env->spr[SPR_DSISR ] =PPC_BIT (41 ); - cs->watchpoint_hit =NULL ; -raise_exception (env,POWERPC_EXCP_DSI ); - } - cs->watchpoint_hit =NULL ; - }else if (cpu_breakpoint_test (cs, env->nip,BP_CPU )) { -raise_exception_err (env,POWERPC_EXCP_TRACE , -PPC_BIT (33 ) |PPC_BIT (43 )); - } - } -#endif -} - -bool ppc_cpu_debug_check_breakpoint (CPUState *cs) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -target_ulong priv; - - priv = env->spr[SPR_CIABR ] &PPC_BITMASK (62 ,63 ); -switch (priv) { -case 0x1 :/* problem */ -return env->msr & ((target_ulong )1 <<MSR_PR ); -case 0x2 :/* supervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - !(env->msr & ((target_ulong )1 <<MSR_HV ))); -case 0x3 :/* hypervisor */ -return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && - (env->msr & ((target_ulong )1 <<MSR_HV ))); -default : -g_assert_not_reached (); - } - } -#endif - -return false; -} - -bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp) -{ -#if defined(TARGET_PPC64 ) -CPUPPCState *env =cpu_env (cs); - -if (env->insns_flags2 &PPC2_ISA207S ) { -if (wp == env->dawr0_watchpoint) { -uint32_t dawrx = env->spr[SPR_DAWRX0 ]; -bool wt =extract32 (dawrx,PPC_BIT_NR (59 ),1 ); -bool wti =extract32 (dawrx,PPC_BIT_NR (60 ),1 ); -bool hv =extract32 (dawrx,PPC_BIT_NR (61 ),1 ); -bool sv =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); -bool pr =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); - -if ((env->msr & ((target_ulong )1 <<MSR_PR )) && !pr) { -return false; - }else if ((env->msr & ((target_ulong )1 <<MSR_HV )) && !hv) { -return false; - }else if (!sv) { -return false; - } - -if (!wti) { -if (env->msr & ((target_ulong )1 <<MSR_DR )) { -if (!wt) { -return false; - } - }else { -if (wt) { -return false; - } - } - } - -return true; - } - } -#endif - -return false; -} -#endif /* !CONFIG_USER_ONLY */ #endif /* CONFIG_TCG */ target/ppc/tcg-excp_helper.c new file +17
-0@@ -0,0 +1,202 @@ +/* +* PowerPC exception emulation helpers for QEMU (TCG specific) +* +* Copyright (c) 2003-2007 Jocelyn Mayer +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */target/ppc/tcg-excp_helper.c new file +18
-0+#include "qemu/osdep.h" +#include "exec/cpu_ldst.h" + +#include "hw/ppc/ppc.h" +#include "internal.h" +#include "cpu.h" +#include "trace.h" + +#ifndef CONFIG_USER_ONLY + +void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr, +MMUAccessType access_type, +int mmu_idx,uintptr_t retaddr) +{ +CPUPPCState *env =cpu_env (cs); +uint32_t insn; + +/* Restore state and reload the insn we executed, for filling in DSISR. */
target/ppc/tcg-excp_helper.c new file +26
-0+cpu_restore_state (cs, retaddr); + insn =ppc_ldl_code (env, env->nip); + +switch (env->mmu_model) { +case POWERPC_MMU_SOFT_4xx: + env->spr[SPR_40x_DEAR] = vaddr; +break ; +case POWERPC_MMU_BOOKE : +case POWERPC_MMU_BOOKE206 : + env->spr[SPR_BOOKE_DEAR ] = vaddr; +break ; +default : + env->spr[SPR_DAR ] = vaddr; +break ; + } + + cs->exception_index =POWERPC_EXCP_ALIGN ; + env->error_code = insn &0x03FF0000 ; +cpu_loop_exit (cs); +} + +void ppc_cpu_do_transaction_failed (CPUState *cs,hwaddr physaddr, +vaddr vaddr,unsigned size, +MMUAccessType access_type, +int mmu_idx,MemTxAttrs attrs, + MemTxResult response, uintptr_tretaddr)
target/ppc/tcg-excp_helper.c new file +140
-0+{ +CPUPPCState *env =cpu_env (cs); + +switch (env->excp_model) { +#if defined(TARGET_PPC64 ) +case POWERPC_EXCP_POWER8 : +case POWERPC_EXCP_POWER9 : +case POWERPC_EXCP_POWER10 : +case POWERPC_EXCP_POWER11 : +/* +* Machine check codes can be found in processor User Manual or +* Linux or skiboot source. +*/ +if (access_type ==MMU_DATA_LOAD ) { + env->spr[SPR_DAR ] = vaddr; + env->spr[SPR_DSISR ] =PPC_BIT (57 ); + env->error_code =PPC_BIT (42 ); + + }else if (access_type ==MMU_DATA_STORE ) { +/* +* MCE for stores in POWER is asynchronous so hardware does +* not set DAR, but QEMU can do better. +*/ + env->spr[SPR_DAR ] = vaddr; + env->error_code =PPC_BIT (36 ) |PPC_BIT (43 ) |PPC_BIT (45 ); + env->error_code |=PPC_BIT (42 ); + + }else {/* Fetch */ +/* +* is_prefix_insn_excp() tests !PPC_BIT(42) to avoid fetching +* the instruction, so that must always be clear for fetches. +*/ + env->error_code =PPC_BIT (36 ) |PPC_BIT (44 ) |PPC_BIT (45 ); + } +break ; +#endif +default : +/* +* TODO: Check behaviour for other CPUs, for now do nothing. +* Could add a basic MCE even if real hardware ignores. +*/ +return ; + } + + cs->exception_index =POWERPC_EXCP_MCHECK ; +cpu_loop_exit_restore (cs, retaddr); +} + +void ppc_cpu_debug_excp_handler (CPUState *cs) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +if (cs->watchpoint_hit) { +if (cs->watchpoint_hit->flags &BP_CPU ) { + env->spr[SPR_DAR ] = cs->watchpoint_hit->hitaddr; + env->spr[SPR_DSISR ] =PPC_BIT (41 ); + cs->watchpoint_hit =NULL ; +raise_exception (env,POWERPC_EXCP_DSI ); + } + cs->watchpoint_hit =NULL ; + }else if (cpu_breakpoint_test (cs, env->nip,BP_CPU )) { +raise_exception_err (env,POWERPC_EXCP_TRACE , +PPC_BIT (33 ) |PPC_BIT (43 )); + } + } +#endif +} + +bool ppc_cpu_debug_check_breakpoint (CPUState *cs) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +target_ulong priv; + + priv = env->spr[SPR_CIABR ] &PPC_BITMASK (62 ,63 ); +switch (priv) { +case 0x1 :/* problem */ +return env->msr & ((target_ulong )1 <<MSR_PR ); +case 0x2 :/* supervisor */ +return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && + !(env->msr & ((target_ulong )1 <<MSR_HV ))); +case 0x3 :/* hypervisor */ +return (!(env->msr & ((target_ulong )1 <<MSR_PR )) && + (env->msr & ((target_ulong )1 <<MSR_HV ))); +default : +g_assert_not_reached (); + } + } +#endif + +return false; +} + +bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp) +{ +#if defined(TARGET_PPC64 ) +CPUPPCState *env =cpu_env (cs); + +if (env->insns_flags2 &PPC2_ISA207S ) { +if (wp == env->dawr0_watchpoint) { +uint32_t dawrx = env->spr[SPR_DAWRX0 ]; +bool wt =extract32 (dawrx,PPC_BIT_NR (59 ),1 ); +bool wti =extract32 (dawrx,PPC_BIT_NR (60 ),1 ); +bool hv =extract32 (dawrx,PPC_BIT_NR (61 ),1 ); +bool sv =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); +bool pr =extract32 (dawrx,PPC_BIT_NR (62 ),1 ); + +if ((env->msr & ((target_ulong )1 <<MSR_PR )) && !pr) { +return false; + }else if ((env->msr & ((target_ulong )1 <<MSR_HV )) && !hv) { +return false; + }else if (!sv) { +return false; + } + +if (!wti) { +if (env->msr & ((target_ulong )1 <<MSR_DR )) { +if (!wt) { +return false; + } + }else { +if (wt) { +return false; + } + } + } + +return true; + } + } +#endif + +return false; +} + +#endif /* !CONFIG_USER_ONLY */ target/ppc/meson.build +1
-0@@ -14,6 +14,7 @@ ppc_ss.add(when: 'CONFIG_TCG', if_true: files( 'int_helper.c', 'mem_helper.c', 'misc_helper.c', + 'tcg-excp_helper.c', 'timebase_helper.c', 'translate.c', 'power8-pmu.c',
Re: [PATCH v2 04/15] target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c
Quoted 11 lines · BALATON Zoltan
Quoted 8 lines · Harsh Prateek Bora
Quoted 3 lines · Philippe Mathieu-Daudé
Move the TCGCPUOps handlers to a new unit:
tcg-excp_helper.c, only built when TCG is selected.Nice.
Just a thought - will the filename look better asexcp_helper-tcg.c? That naming usually help developers when using tab completion.Or maybe stick to either _ or - in the filename and not mix both in one name? If you want to use -tcg or tcg- then also rename to excp-helper. We already have a mix of _ and - names but at least try to be consistent within one name.
Other targets use a sub-directory:
$ ls -1d target/*/tcg target/arm/tcg target/i386/tcg target/loongarch/tcg target/mips/tcg target/riscv/tcg target/s390x/tcg
I'm not interested in particular with this target and ready to work a lot on it, this is why I went with a surgical approach.
Quoted 3 lines
Regards,
BALATON Zoltan
PATCH v2 5/15 target/ppc: Move ppc_ldl_code() to tcg-excp_helper.c
In reply to Philippe Mathieu-Daudé--- target/ppc/excp_helper.c | 21 --------------------- target/ppc/tcg-excp_helper.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 21 deletions(-)
target/ppc/excp_helper.c +0 -21
@@ -136,27 +136,6 @@ static void dump_hcall(CPUPPCState *env) env->nip); } -#ifdef CONFIG_TCG -/* Return true iff byteswap is needed to load instruction */ -static inline bool insn_need_byteswap (CPUArchState *env) -{ -/* SYSTEM builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */ -return !!(env->msr & ((target_ulong )1 <<MSR_LE )); -} - -uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) -{ -uint32_t insn =cpu_ldl_code (env, addr); - -if (insn_need_byteswap (env)) { - insn =bswap32 (insn); - } - -return insn; -} - -#endif -static void ppc_excp_debug_sw_tlb (CPUPPCState *env,int excp) {const char *es;
target/ppc/tcg-excp_helper.c +18 -0
@@ -199,4 +199,22 @@ bool ppc_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) return false; } +/* Return true iff byteswap is needed to load instruction */ +static inline bool insn_need_byteswap (CPUArchState *env) +{ +/* SYSTEM builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */ +return !!(env->msr & ((target_ulong )1 <<MSR_LE )); +} + +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) +{ +uint32_t insn =cpu_ldl_code (env, addr); + +if (insn_need_byteswap (env)) { + insn =bswap32 (insn); + } + +return insn; +} +#endif /* !CONFIG_USER_ONLY */
Signature · 1 line
2.47.1
Re: [PATCH v2 05/15] target/ppc: Move ppc_ldl_code() to tcg-excp_helper.c
Quoted 6 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/excp_helper.c | 21 --------------------- target/ppc/tcg-excp_helper.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 21 deletions(-)
This patch also needs to remove the function declaration introduced in internal.h in patch 3.
Otherwise,
Quoted 59 lines
target/ppc/excp_helper.c +0
-21@@ -136,27 +136,6 @@ static void dump_hcall(CPUPPCState *env) env->nip); } -#ifdef CONFIG_TCG -/* Return true iff byteswap is needed to load instruction */ -static inline bool insn_need_byteswap (CPUArchState *env) -{ -/* SYSTEM builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */ -return !!(env->msr & ((target_ulong )1 <<MSR_LE )); -} - -uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) -{ -uint32_t insn =cpu_ldl_code (env, addr); - -if (insn_need_byteswap (env)) { - insn =bswap32 (insn); - } - -return insn; -} - -#endif -static void ppc_excp_debug_sw_tlb (CPUPPCState *env,int excp) {const char *es;target/ppc/tcg-excp_helper.c +18
-0@@ -199,4 +199,22 @@ bool ppc_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp) return false; } +/* Return true iff byteswap is needed to load instruction */ +static inline bool insn_need_byteswap (CPUArchState *env) +{ +/* SYSTEM builds TARGET_BIG_ENDIAN. Need to swap when MSR[LE] is set */ +return !!(env->msr & ((target_ulong )1 <<MSR_LE )); +} + +uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr) +{ +uint32_t insn =cpu_ldl_code (env, addr); + +if (insn_need_byteswap (env)) { + insn =bswap32 (insn); + } + +return insn; +} +#endif /* !CONFIG_USER_ONLY */
Re: [PATCH v2 05/15] target/ppc: Move ppc_ldl_code() to tcg-excp_helper.c
Quoted 11 lines · Harsh Prateek Bora
Quoted 6 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/ppc/excp_helper.c | 21 ---------------------target/ppc/tcg-excp_helper.c| 18 ++++++++++++++++++2 files changed, 18 insertions(+), 21 deletions(-)This patch also needs to remove the function declaration introduced in
internal.hin patch 3.
No, it is still used in 2 distinct units:
$ git grep ppc_ldl_code a09cb1ead a09cb1ead:target/ppc/excp_helper.c:1291: return is_prefix_insn(env, ppc_ldl_code(env, env->nip)); a09cb1ead:target/ppc/excp_helper.c:1516: uint32_t insn = ppc_ldl_code(env, env->nip); a09cb1ead:target/ppc/excp_helper.c:1519: uint32_t insn2 = ppc_ldl_code(env, env->nip + 4); a09cb1ead:target/ppc/internal.h:271:uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr); a09cb1ead:target/ppc/tcg-excp_helper.c:38: insn = ppc_ldl_code(env, env->nip); a09cb1ead:target/ppc/tcg-excp_helper.c:209:uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr)
Quoted 2 lines
Otherwise,
Reviewed-by Harsh Prateek Bora <[email protected]>
Thanks!
PATCH v2 6/15 target/ppc: Ensure powerpc_checkstop() is only called under TCG
In reply to Philippe Mathieu-Daudé--- target/ppc/excp_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
target/ppc/excp_helper.c +2 -4
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "system/tcg.h" #include "system/system.h" #include "system/runstate.h" #include "cpu.h"
@@ -30,7 +31,6 @@#include "trace.h" #ifdef CONFIG_TCG -#include "system/tcg.h" #include "exec/helper-proto.h" #include "exec/cpu_ldst.h" #endif
@@ -443,13 +443,11 @@ void helper_attn(CPUPPCState *env)static void powerpc_mcheck_checkstop (CPUPPCState *env) {/* KVM guests always have MSR[ME] enabled */ -#ifdef CONFIG_TCG if (FIELD_EX64 (env->msr,MSR ,ME )) {return ; } - +assert (tcg_enabled ());powerpc_checkstop (env,"machine check with MSR[ME]=0" ); -#endif }static void powerpc_excp_40x (PowerPCCPU *cpu,int excp)
Signature · 1 line
2.47.1
Re: [PATCH v2 06/15] target/ppc: Ensure powerpc_checkstop() is only called under TCG
Quoted 26 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/excp_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)target/ppc/excp_helper.c +1
-1@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "system/tcg.h" #include "system/system.h" #include "system/runstate.h" #include "cpu.h" @@ -30,7 +31,6 @@#include "trace.h" #ifdef CONFIG_TCG -#include "system/tcg.h" #include "exec/helper-proto.h" #include "exec/cpu_ldst.h" #endif
target/ppc/excp_helper.c void helper_attn(CPUPPCState *env) · line 449
Quoted 9 lines
target/ppc/excp_helper.c +1
-2@@ -443,13 +443,11 @@ void helper_attn(CPUPPCState *env)static void powerpc_mcheck_checkstop (CPUPPCState *env) {/* KVM guests always have MSR[ME] enabled */ -#ifdef CONFIG_TCG if (FIELD_EX64 (env->msr,MSR ,ME )) {return ; } - +assert (tcg_enabled ());
Shouldn't this be a no-op if not TCG ?
Nick, please advise ?
regards,
Harsh
Quoted 5 lines
target/ppc/excp_helper.c +0
-1powerpc_checkstop (env,"machine check with MSR[ME]=0" ); -#endif }static void powerpc_excp_40x (PowerPCCPU *cpu,int excp)
Re: [PATCH v2 06/15] target/ppc: Ensure powerpc_checkstop() is only called under TCG
Quoted 40 lines · Harsh Prateek Bora
Quoted 25 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/ppc/excp_helper.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)target/ppc/excp_helper.c +1
-1@@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "system/tcg.h" #include "system/system.h" #include "system/runstate.h" #include "cpu.h"@@ -30,7 +31,6 @@ #include "trace.h" #ifdef CONFIG_TCG -#include "system/tcg.h" #include "exec/helper-proto.h" #include "exec/cpu_ldst.h" #endiftarget/ppc/excp_helper.c void helper_attn(CPUPPCState *env) · line 449
Quoted 9 lines
target/ppc/excp_helper.c +1
-2@@ -443,13 +443,11 @@ void helper_attn(CPUPPCState *env) static void powerpc_mcheck_checkstop(CPUPPCState *env) { /* KVM guests always have MSR[ME] enabled */ -#ifdef CONFIG_TCG if (FIELD_EX64(env->msr, MSR, ME)) { return; } - + assert(tcg_enabled());Shouldn't this be a no-op if not TCG ?
Quoted 2 lines
Nick, please advise ?
Also, patch title needs update - it's powerpc_mcheck_checkstop.
Quoted 7 lines
regards,
HarshQuoted 4 lines
target/ppc/excp_helper.c +0
-1powerpc_checkstop(env, "machine check with MSR[ME]=0"); -#endif } static void powerpc_excp_40x(PowerPCCPU *cpu, int excp)
Re: [PATCH v2 06/15] target/ppc: Ensure powerpc_checkstop() is only called under TCG
In reply to Harsh Prateek BoraQuoted 41 lines · Harsh Prateek Bora
Quoted 26 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/excp_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)target/ppc/excp_helper.c +1
-1@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "system/tcg.h" #include "system/system.h" #include "system/runstate.h" #include "cpu.h" @@ -30,7 +31,6 @@#include "trace.h" #ifdef CONFIG_TCG -#include "system/tcg.h" #include "exec/helper-proto.h" #include "exec/cpu_ldst.h" #endif target/ppc/excp_helper.c void helper_attn(CPUPPCState *env) · line 449
Quoted 9 lines
target/ppc/excp_helper.c +1
-2@@ -443,13 +443,11 @@ void helper_attn(CPUPPCState *env)static void powerpc_mcheck_checkstop (CPUPPCState *env) {/* KVM guests always have MSR[ME] enabled */ -#ifdef CONFIG_TCG if (FIELD_EX64 (env->msr,MSR ,ME )) {return ; } - +assert (tcg_enabled ());Shouldn't this be a no-op if not TCG ?
Quoted 1 line
Nick, please advise ?
If KVM, I think we would rather catch that it got called instead of no-op.
At this point the guest is crashed, so it's not overly rude to assert. I'm okay with this.
Thanks,
Nick
PATCH v2 7/15 target/ppc: Restrict powerpc_checkstop() to TCG
In reply to Philippe Mathieu-DaudéExpose powerpc_checkstop() prototype, and move it to tcg-excp_helper.c, only built when TCG is available.
--- target/ppc/internal.h | 4 +++- target/ppc/excp_helper.c | 26 -------------------------- target/ppc/tcg-excp_helper.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 27 deletions(-)
target/ppc/internal.h +3 -1
@@ -289,7 +289,9 @@ void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,void ppc_cpu_debug_excp_handler (CPUState *cs);bool ppc_cpu_debug_check_breakpoint (CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); -#endif + +G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); +#endif /* !CONFIG_USER_ONLY */ FIELD(GER_MSK, XMSK, 0, 4)FIELD (GER_MSK ,YMSK ,4 ,4 )
target/ppc/excp_helper.c +0 -26
@@ -400,32 +400,6 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, } #ifdef CONFIG_TCG -/* - * This stops the machine and logs CPU state without killing QEMU (like - * cpu_abort()) because it is often a guest error as opposed to a QEMU error, - * so the machine can still be debugged. - */ -static G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason) -{ - CPUState *cs = env_cpu(env); - FILE *f; - - f = qemu_log_trylock(); - if (f) { - fprintf(f, "Entering checkstop state: %s\n", reason); - cpu_dump_state(cs, f, CPU_DUMP_FPU | CPU_DUMP_CCOP); - qemu_log_unlock(f); - } - - /* - * This stops the machine and logs CPU state without killing QEMU - * (like cpu_abort()) so the machine can still be debugged (because - * it is often a guest error). - */ - qemu_system_guest_panicked(NULL); - cpu_loop_exit_noexc(cs); -} - #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) void helper_attn(CPUPPCState *env) {
target/ppc/tcg-excp_helper.c +28 -0
@@ -17,7 +17,9 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "exec/cpu_ldst.h" +#include "system/runstate.h" #include "hw/ppc/ppc.h" #include "internal.h"
@@ -199,6 +201,32 @@ bool ppc_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)return false; } +/* +* This stops the machine and logs CPU state without killing QEMU (like +* cpu_abort()) because it is often a guest error as opposed to a QEMU error, +* so the machine can still be debugged. +*/ +G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason) +{ +CPUState *cs =env_cpu (env); +FILE *f; + + f =qemu_log_trylock (); +if (f) { +fprintf (f,"Entering checkstop state: %s\n" , reason); +cpu_dump_state (cs, f,CPU_DUMP_FPU |CPU_DUMP_CCOP ); +qemu_log_unlock (f); + } + +/* +* This stops the machine and logs CPU state without killing QEMU +* (like cpu_abort()) so the machine can still be debugged (because +* it is often a guest error). +*/ +qemu_system_guest_panicked (NULL ); +cpu_loop_exit_noexc (cs); +} +/* Return true iff byteswap is needed to load instruction */ static inline bool insn_need_byteswap (CPUArchState *env) {
Signature · 1 line
2.47.1
Re: [PATCH v2 07/15] target/ppc: Restrict powerpc_checkstop() to TCG
Quoted 4 lines · Philippe Mathieu-Daudé
Expose
powerpc_checkstop()prototype, and move it totcg-excp_helper.c, only built when TCG is available.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 105 lines
--- target/ppc/internal.h | 4 +++- target/ppc/excp_helper.c | 26 -------------------------- target/ppc/tcg-excp_helper.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 27 deletions(-)target/ppc/internal.h +3
-1@@ -289,7 +289,9 @@ void ppc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,void ppc_cpu_debug_excp_handler (CPUState *cs);bool ppc_cpu_debug_check_breakpoint (CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); -#endif + +G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); +#endif /* !CONFIG_USER_ONLY */ FIELD(GER_MSK, XMSK, 0, 4)FIELD (GER_MSK ,YMSK ,4 ,4 )target/ppc/excp_helper.c +0
-26@@ -400,32 +400,6 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, } #ifdef CONFIG_TCG -/* - * This stops the machine and logs CPU state without killing QEMU (like - * cpu_abort()) because it is often a guest error as opposed to a QEMU error, - * so the machine can still be debugged. - */ -static G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason) -{ - CPUState *cs = env_cpu(env); - FILE *f; - - f = qemu_log_trylock(); - if (f) { - fprintf(f, "Entering checkstop state: %s\n", reason); - cpu_dump_state(cs, f, CPU_DUMP_FPU | CPU_DUMP_CCOP); - qemu_log_unlock(f); - } - - /* - * This stops the machine and logs CPU state without killing QEMU - * (like cpu_abort()) so the machine can still be debugged (because - * it is often a guest error). - */ - qemu_system_guest_panicked(NULL); - cpu_loop_exit_noexc(cs); -} - #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) void helper_attn(CPUPPCState *env) {target/ppc/tcg-excp_helper.c +28
-0@@ -17,7 +17,9 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "exec/cpu_ldst.h" +#include "system/runstate.h" #include "hw/ppc/ppc.h" #include "internal.h" @@ -199,6 +201,32 @@ bool ppc_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)return false; } +/* +* This stops the machine and logs CPU state without killing QEMU (like +* cpu_abort()) because it is often a guest error as opposed to a QEMU error, +* so the machine can still be debugged. +*/ +G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason) +{ +CPUState *cs =env_cpu (env); +FILE *f; + + f =qemu_log_trylock (); +if (f) { +fprintf (f,"Entering checkstop state: %s\n" , reason); +cpu_dump_state (cs, f,CPU_DUMP_FPU |CPU_DUMP_CCOP ); +qemu_log_unlock (f); + } + +/* +* This stops the machine and logs CPU state without killing QEMU +* (like cpu_abort()) so the machine can still be debugged (because +* it is often a guest error). +*/ +qemu_system_guest_panicked (NULL ); +cpu_loop_exit_noexc (cs); +} +/* Return true iff byteswap is needed to load instruction */ static inline bool insn_need_byteswap (CPUArchState *env) {
PATCH v2 8/15 target/ppc: Remove raise_exception_ra()
In reply to Philippe Mathieu-DaudéIntroduced in commit db789c6cd33 ("ppc: Provide basic raise_exception_* functions"), raise_exception_ra() has never been used. Remove as dead code.
--- target/ppc/cpu.h | 2 -- target/ppc/excp_helper.c | 6 ------ 2 files changed, 8 deletions(-)
target/ppc/cpu.h +0 -2
@@ -2753,8 +2753,6 @@ static inline void cpu_get_tb_cpu_state(CPUPPCState *env, vaddr *pc,#endif G_NORETURN void raise_exception(CPUPPCState *env, uint32_t exception); -G_NORETURN void raise_exception_ra(CPUPPCState *env, uint32_t exception, -uintptr_t raddr); G_NORETURN void raise_exception_err(CPUPPCState *env, uint32_t exception,uint32_t error_code); G_NORETURN void raise_exception_err_ra(CPUPPCState *env, uint32_t exception,
target/ppc/excp_helper.c +0 -6
@@ -2528,12 +2528,6 @@ void raise_exception(CPUPPCState *env, uint32_t exception)raise_exception_err_ra (env, exception,0 ,0 ); } -void raise_exception_ra (CPUPPCState *env,uint32_t exception, -uintptr_t raddr) -{ -raise_exception_err_ra (env, exception,0 , raddr); -} -#ifdef CONFIG_TCG void helper_raise_exception_err (CPUPPCState *env,uint32_t exception,uint32_t error_code)
Signature · 1 line
2.47.1
Re: [PATCH v2 08/15] target/ppc: Remove raise_exception_ra()
Quoted 5 lines · Philippe Mathieu-Daudé
Introduced in commit
db789c6cd33("ppc: Provide basic raise_exception_* functions"),raise_exception_ra()has never been used. Remove as dead code.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Although there are a bunch of raise_exception_err_ra calls passing error_code as 0, I hope removing this is fine as still unused.
Quoted 35 lines
--- target/ppc/cpu.h | 2 -- target/ppc/excp_helper.c | 6 ------ 2 files changed, 8 deletions(-)target/ppc/cpu.h +0
-2@@ -2753,8 +2753,6 @@ static inline void cpu_get_tb_cpu_state(CPUPPCState *env, vaddr *pc,#endif G_NORETURN void raise_exception(CPUPPCState *env, uint32_t exception); -G_NORETURN void raise_exception_ra(CPUPPCState *env, uint32_t exception, -uintptr_t raddr); G_NORETURN void raise_exception_err(CPUPPCState *env, uint32_t exception,uint32_t error_code); G_NORETURN void raise_exception_err_ra(CPUPPCState *env, uint32_t exception,target/ppc/excp_helper.c +0
-6@@ -2528,12 +2528,6 @@ void raise_exception(CPUPPCState *env, uint32_t exception)raise_exception_err_ra (env, exception,0 ,0 ); } -void raise_exception_ra (CPUPPCState *env,uint32_t exception, -uintptr_t raddr) -{ -raise_exception_err_ra (env, exception,0 , raddr); -} -#ifdef CONFIG_TCG void helper_raise_exception_err (CPUPPCState *env,uint32_t exception,uint32_t error_code)
Re: [PATCH v2 08/15] target/ppc: Remove raise_exception_ra()
Quoted 11 lines · Harsh Prateek Bora
Quoted 5 lines · Philippe Mathieu-Daudé
Introduced in commit
db789c6cd33("ppc: Provide basic raise_exception_* functions"),raise_exception_ra()has never been used. Remove as dead code.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Although there are a bunch of
raise_exception_err_racalls passingerror_codeas 0, I hope removing this is fine as still unused.
I dunno about error_code=0, where I'm suspicious is raddr=0, I'd expect raddr=GETPC(), but I haven't bothered to check yet.
Quoted 7 lines
Reviewed-by Harsh Prateek Bora <[email protected]>Quoted 4 lines
---
target/ppc/cpu.h | 2 --
target/ppc/excp_helper.c| 6 ------2 files changed, 8 deletions(-)
PATCH v2 9/15 target/ppc: Restrict exception helpers to TCG
In reply to Philippe Mathieu-DaudéMove exception helpers to tcg-excp_helper.c so they are only built when TCG is selected.
--- target/ppc/excp_helper.c | 34 -------------------------------- target/ppc/tcg-excp_helper.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 34 deletions(-)
target/ppc/excp_helper.c +0 -34
@@ -2504,41 +2504,7 @@ bool ppc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)#endif /* !CONFIG_USER_ONLY */ -/*****************************************************************************/ -/* Exceptions processing helpers */ - -void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, -uint32_t error_code,uintptr_t raddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = exception; - env->error_code = error_code; -cpu_loop_exit_restore (cs, raddr); -} - -void raise_exception_err (CPUPPCState *env,uint32_t exception, -uint32_t error_code) -{ -raise_exception_err_ra (env, exception, error_code,0 ); -} - -void raise_exception (CPUPPCState *env,uint32_t exception) -{ -raise_exception_err_ra (env, exception,0 ,0 ); -} -#ifdef CONFIG_TCG -void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, -uint32_t error_code) -{ -raise_exception_err_ra (env, exception, error_code,0 ); -} - -void helper_raise_exception (CPUPPCState *env,uint32_t exception) -{ -raise_exception_err_ra (env, exception,0 ,0 ); -}#ifndef CONFIG_USER_ONLY void helper_store_msr (CPUPPCState *env,target_ulong val)
target/ppc/tcg-excp_helper.c +38 -0
@@ -19,15 +19,53 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" #include "system/runstate.h" +#include "helper_regs.h" #include "hw/ppc/ppc.h" #include "internal.h" #include "cpu.h" #include "trace.h" +/*****************************************************************************/ +/* Exceptions processing helpers */ + +void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, +uint32_t error_code,uintptr_t raddr) +{ +CPUState *cs =env_cpu (env); + + cs->exception_index = exception; + env->error_code = error_code; +cpu_loop_exit_restore (cs, raddr); +} + +void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, +uint32_t error_code) +{ +raise_exception_err_ra (env, exception, error_code,0 ); +} + +void helper_raise_exception (CPUPPCState *env,uint32_t exception) +{ +raise_exception_err_ra (env, exception,0 ,0 ); +} +#ifndef CONFIG_USER_ONLY +void raise_exception_err (CPUPPCState *env,uint32_t exception, +uint32_t error_code) +{ +raise_exception_err_ra (env, exception, error_code,0 ); +} + +void raise_exception (CPUPPCState *env,uint32_t exception) +{ +raise_exception_err_ra (env, exception,0 ,0 ); +} +void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
Signature · 1 line
2.47.1
Re: [PATCH v2 09/15] target/ppc: Restrict exception helpers to TCG
Quoted 89 lines · Philippe Mathieu-Daudé
Move exception helpers to
tcg-excp_helper.cso they are only built when TCG is selected.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/excp_helper.c | 34 -------------------------------- target/ppc/tcg-excp_helper.c | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 34 deletions(-)target/ppc/excp_helper.c +0
-34@@ -2504,41 +2504,7 @@ bool ppc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)#endif /* !CONFIG_USER_ONLY */ -/*****************************************************************************/ -/* Exceptions processing helpers */ - -void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, -uint32_t error_code,uintptr_t raddr) -{ -CPUState *cs =env_cpu (env); - - cs->exception_index = exception; - env->error_code = error_code; -cpu_loop_exit_restore (cs, raddr); -} - -void raise_exception_err (CPUPPCState *env,uint32_t exception, -uint32_t error_code) -{ -raise_exception_err_ra (env, exception, error_code,0 ); -} - -void raise_exception (CPUPPCState *env,uint32_t exception) -{ -raise_exception_err_ra (env, exception,0 ,0 ); -} -#ifdef CONFIG_TCG -void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, -uint32_t error_code) -{ -raise_exception_err_ra (env, exception, error_code,0 ); -} - -void helper_raise_exception (CPUPPCState *env,uint32_t exception) -{ -raise_exception_err_ra (env, exception,0 ,0 ); -}#ifndef CONFIG_USER_ONLY void helper_store_msr (CPUPPCState *env,target_ulong val)target/ppc/tcg-excp_helper.c +19
-0@@ -19,15 +19,53 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" #include "system/runstate.h" +#include "helper_regs.h" #include "hw/ppc/ppc.h" #include "internal.h" #include "cpu.h" #include "trace.h" +/*****************************************************************************/ +/* Exceptions processing helpers */ + +void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, +uint32_t error_code,uintptr_t raddr) +{ +CPUState *cs =env_cpu (env); + + cs->exception_index = exception; + env->error_code = error_code; +cpu_loop_exit_restore (cs, raddr); +} + +void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, +uint32_t error_code) +{
target/ppc/tcg-excp_helper.c line 57
Quoted 10 lines
target/ppc/tcg-excp_helper.c +8
-0+raise_exception_err_ra (env, exception, error_code,0 ); +} + +void helper_raise_exception (CPUPPCState *env,uint32_t exception) +{ +raise_exception_err_ra (env, exception,0 ,0 ); +} +#ifndef CONFIG_USER_ONLY
In excp_helper.c, below helpers were getting built when CONFIG_USER_ONLY is defined. Is this change to move under above ifndef intentional?
regards,
Harsh
Quoted 14 lines
target/ppc/tcg-excp_helper.c +11
-0+void raise_exception_err (CPUPPCState *env,uint32_t exception, +uint32_t error_code) +{ +raise_exception_err_ra (env, exception, error_code,0 ); +} + +void raise_exception (CPUPPCState *env,uint32_t exception) +{ +raise_exception_err_ra (env, exception,0 ,0 ); +} +void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
Re: [PATCH v2 09/15] target/ppc: Restrict exception helpers to TCG
Quoted 93 lines · Harsh Prateek Bora
Quoted 90 lines · Philippe Mathieu-Daudé
Move exception helpers to
tcg-excp_helper.cso they are only built when TCG is selected.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/ppc/excp_helper.c | 34 --------------------------------target/ppc/tcg-excp_helper.c| 38 ++++++++++++++++++++++++++++++++++++2 files changed, 38 insertions(+), 34 deletions(-)target/ppc/excp_helper.c +0
-34@@ -2504,41 +2504,7 @@ bool ppc_cpu_exec_interrupt(CPUState *cs, intinterrupt_request) #endif /* !CONFIG_USER_ONLY */ -/ *****************************************************************************/ -/* Exceptions processing helpers */ - -void raise_exception_err_ra(CPUPPCState *env, uint32_t exception, - uint32_t error_code, uintptr_t raddr) -{ - CPUState *cs = env_cpu(env); - - cs->exception_index = exception; - env->error_code = error_code; - cpu_loop_exit_restore(cs, raddr); -} - -void raise_exception_err (CPUPPCState *env,uint32_t exception, - uint32_t error_code) -{ - raise_exception_err_ra(env, exception, error_code, 0); -} - -void raise_exception (CPUPPCState *env,uint32_t exception) -{ - raise_exception_err_ra(env, exception, 0, 0); -} - #ifdef CONFIG_TCG -void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, - uint32_t error_code) -{ - raise_exception_err_ra(env, exception, error_code, 0); -} - -void helper_raise_exception (CPUPPCState *env,uint32_t exception) -{ - raise_exception_err_ra(env, exception, 0, 0); -} #ifndef CONFIG_USER_ONLY void helper_store_msr(CPUPPCState *env, target_ulong val)target/ppc/tcg-excp_helper.c +22
-0@@ -19,15 +19,53 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +#include "exec/helper-proto.h" #include "system/runstate.h" +#include "helper_regs.h" #include "hw/ppc/ppc.h" #include "internal.h" #include "cpu.h" #include "trace.h" +/ *****************************************************************************/ +/* Exceptions processing helpers */ + +void raise_exception_err_ra (CPUPPCState *env,uint32_t exception, + uint32_t error_code, uintptr_t raddr) +{ + CPUState *cs = env_cpu(env); + + cs->exception_index = exception; + env->error_code = error_code; + cpu_loop_exit_restore(cs, raddr); +} + +void helper_raise_exception_err (CPUPPCState *env,uint32_t exception, + uint32_t error_code) +{ + raise_exception_err_ra(env, exception, error_code, 0); +} +
Quoted 8 lines
target/ppc/tcg-excp_helper.c line 56
Quoted 6 lines
target/ppc/tcg-excp_helper.c +5
-0+void helper_raise_exception (CPUPPCState *env,uint32_t exception) +{ + raise_exception_err_ra(env, exception, 0, 0); +} + #ifndef CONFIG_USER_ONLYIn
excp_helper.c, below helpers were getting built whenCONFIG_USER_ONLYis defined. Is this change to move under above ifndef intentional?
Yes, they are unused otherwise. I'll mention in commit description.
Quoted 3 lines
regards,
Harsh
PATCH v2 10/15 target/ppc: Restrict ppc_tcg_hv_emu() to TCG
In reply to Philippe Mathieu-DaudéMake is_prefix_insn_excp() prototype but have it guarded by a tcg_enabled() check. Inline part of it in powerpc_excp_books().
Extract POWERPC_EXCP_HV_EMU handling code to ppc_tcg_hv_emu(), also exposing its prototype in "internal.h".
--- target/ppc/internal.h | 6 +++ target/ppc/excp_helper.c | 101 +++++------------------------------ target/ppc/tcg-excp_helper.c | 75 ++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 89 deletions(-)
target/ppc/internal.h +6 -0
@@ -291,6 +291,12 @@ bool ppc_cpu_debug_check_breakpoint(CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); + +#if defined(TARGET_PPC64 ) +bool is_prefix_insn_excp (CPUPPCState *env,int excp); +void ppc_tcg_hv_emu (CPUPPCState *env,target_ulong *new_msr, +int *srr0,int *srr1); +#endif /* TARGET_PPC64 */ #endif /* !CONFIG_USER_ONLY */ FIELD (GER_MSK ,XMSK ,0 ,4 )
target/ppc/excp_helper.c +12 -89
126 lines not on this page · raw message
target/ppc/tcg-excp_helper.c +75 -0
79 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH v2 10/15] target/ppc: Restrict ppc_tcg_hv_emu() to TCG
Quoted 125 lines · Philippe Mathieu-Daudé
Make
is_prefix_insn_excp()prototype but have it guarded by atcg_enabled()check. Inline part of it inpowerpc_excp_books().Extract
POWERPC_EXCP_HV_EMUhandling code toppc_tcg_hv_emu(), also exposing its prototype in "internal.h".Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/internal.h | 6 +++ target/ppc/excp_helper.c | 101 +++++------------------------------ target/ppc/tcg-excp_helper.c | 75 ++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 89 deletions(-)target/ppc/internal.h +6
-0@@ -291,6 +291,12 @@ bool ppc_cpu_debug_check_breakpoint(CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); + +#if defined(TARGET_PPC64 ) +bool is_prefix_insn_excp (CPUPPCState *env,int excp); +void ppc_tcg_hv_emu (CPUPPCState *env,target_ulong *new_msr, +int *srr0,int *srr1); +#endif /* TARGET_PPC64 */ #endif /* !CONFIG_USER_ONLY */ FIELD (GER_MSK ,XMSK ,0 ,4 )target/ppc/excp_helper.c +1
-75@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "system/kvm.h" #include "system/tcg.h" #include "system/system.h" #include "system/runstate.h" @@ -1194,81 +1195,6 @@ static bool books_vhyp_handles_hv_excp(PowerPCCPU *cpu)return false; } -#ifdef CONFIG_TCG -static bool is_prefix_insn (CPUPPCState *env,uint32_t insn) -{ -if (!(env->insns_flags2 &PPC2_ISA310 )) { -return false; - } -return ((insn &0xfc000000 ) ==0x04000000 ); -} - -static bool is_prefix_insn_excp (PowerPCCPU *cpu,int excp) -{ -CPUPPCState *env = &cpu->env; - -if (!(env->insns_flags2 &PPC2_ISA310 )) { -return false; - } - -if (!tcg_enabled ()) { -/* -* This does not load instructions and set the prefix bit correctly -* for injected interrupts with KVM. That may have to be discovered -* and set by the KVM layer before injecting. -*/ -return false; - } - -switch (excp) { -case POWERPC_EXCP_MCHECK : -if (!(env->error_code &PPC_BIT (42 ))) { -/* -* Fetch attempt caused a machine check, so attempting to fetch -* again would cause a recursive machine check. -*/ -return false; - } -break ; -case POWERPC_EXCP_HDSI : -/* HDSI PRTABLE_FAULT has the originating access type in error_code */ -if ((env->spr[SPR_HDSISR ] &DSISR_PRTABLE_FAULT ) && - (env->error_code ==MMU_INST_FETCH )) { -/* -* Fetch failed due to partition scope translation, so prefix -* indication is not relevant (and attempting to load the -* instruction at NIP would cause recursive faults with the same -* translation). -*/ -return false; - } -break ; - -case POWERPC_EXCP_DSI : -case POWERPC_EXCP_DSEG : -case POWERPC_EXCP_ALIGN : -case POWERPC_EXCP_PROGRAM : -case POWERPC_EXCP_FPU : -case POWERPC_EXCP_TRACE : -case POWERPC_EXCP_HV_EMU : -case POWERPC_EXCP_VPU : -case POWERPC_EXCP_VSXU : -case POWERPC_EXCP_FU : -case POWERPC_EXCP_HV_FU : -break ; -default : -return false; - } - -return is_prefix_insn (env,ppc_ldl_code (env, env->nip)); -} -#else -static bool is_prefix_insn_excp (PowerPCCPU *cpu,int excp) -{ -return false; -} -#endif -static void powerpc_excp_books (PowerPCCPU *cpu,int excp) {CPUPPCState *env = &cpu->env;
target/ppc/excp_helper.c static void powerpc_excp_books(PowerPCCPU *cpu, int excp) · line 1239
Quoted 5 lines
target/ppc/excp_helper.c +1
-1@@ -1310,7 +1236,15 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp) } vector |= env->excp_prefix; -if (is_prefix_insn_excp (cpu, excp)) { +if (env->insns_flags2 &PPC2_ISA310 ) {
I guess you meant checking for ! of above. is_prefix_insn_excp() returns false for ! of above.
Quoted 19 lines
target/ppc/excp_helper.c +8
-4+/* nothing to do */ + }else if (kvm_enabled ()) { +/* +* This does not load instructions and set the prefix bit correctly +* for injected interrupts with KVM. That may have to be discovered +* and set by the KVM layer before injecting. +*/ + }else if (tcg_enabled () &&is_prefix_insn_excp (env, excp)) { msr |=PPC_BIT (34 ); }@@ -1484,20 +1418,9 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int excp) new_msr |= env->msr & ((target_ulong )1 <<MSR_RI );break ;#ifdef CONFIG_TCG -case POWERPC_EXCP_HV_EMU : { -uint32_t insn =ppc_ldl_code (env, env->nip); - env->spr[SPR_HEIR ] = insn; -if (is_prefix_insn (env, insn)) {
target/ppc/excp_helper.c static void powerpc_excp_books(PowerPCCPU *cpu, int excp) · line 1422
Quoted 10 lines
target/ppc/excp_helper.c +2
-8-uint32_t insn2 =ppc_ldl_code (env, env->nip +4 ); - env->spr[SPR_HEIR ] <<=32 ; - env->spr[SPR_HEIR ] |= insn2; - } - srr0 =SPR_HSRR0 ; - srr1 =SPR_HSRR1 ; - new_msr |= (target_ulong )MSR_HVB ; - new_msr |= env->msr & ((target_ulong )1 <<MSR_RI ); +case POWERPC_EXCP_HV_EMU : +ppc_tcg_hv_emu (env, &new_msr, &srr0, &srr1);
Naming suggestion: ppc_excp_hv_emu may be more apt.
Thanks,
Harsh
Quoted 89 lines
target/ppc/excp_helper.c +0
-1break ; - }#endif case POWERPC_EXCP_VPU :/* Vector unavailable exception */ case POWERPC_EXCP_VSXU :/* VSX unavailable exception */ target/ppc/tcg-excp_helper.c +75
-0@@ -283,4 +283,79 @@ uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr)return insn; } +#if defined(TARGET_PPC64 ) + +static bool is_prefix_insn (CPUPPCState *env,uint32_t insn) +{ +if (!(env->insns_flags2 &PPC2_ISA310 )) { +return false; + } +return ((insn &0xfc000000 ) ==0x04000000 ); +} + +bool is_prefix_insn_excp (CPUPPCState *env,int excp) +{ +switch (excp) { +case POWERPC_EXCP_MCHECK : +if (!(env->error_code &PPC_BIT (42 ))) { +/* +* Fetch attempt caused a machine check, so attempting to fetch +* again would cause a recursive machine check. +*/ +return false; + } +break ; +case POWERPC_EXCP_HDSI : +/* HDSI PRTABLE_FAULT has the originating access type in error_code */ +if ((env->spr[SPR_HDSISR ] &DSISR_PRTABLE_FAULT ) && + (env->error_code ==MMU_INST_FETCH )) { +/* +* Fetch failed due to partition scope translation, so prefix +* indication is not relevant (and attempting to load the +* instruction at NIP would cause recursive faults with the same +* translation). +*/ +return false; + } +break ; + +case POWERPC_EXCP_DSI : +case POWERPC_EXCP_DSEG : +case POWERPC_EXCP_ALIGN : +case POWERPC_EXCP_PROGRAM : +case POWERPC_EXCP_FPU : +case POWERPC_EXCP_TRACE : +case POWERPC_EXCP_HV_EMU : +case POWERPC_EXCP_VPU : +case POWERPC_EXCP_VSXU : +case POWERPC_EXCP_FU : +case POWERPC_EXCP_HV_FU : +break ; +default : +return false; + } + +return is_prefix_insn (env,ppc_ldl_code (env, env->nip)); +} + +void ppc_tcg_hv_emu (CPUPPCState *env,target_ulong *new_msr, +int *srr0,int *srr1) +{ +uint32_t insn =ppc_ldl_code (env, env->nip); + + env->spr[SPR_HEIR ] = insn; +if (is_prefix_insn (env, insn)) { +uint32_t insn2 =ppc_ldl_code (env, env->nip +4 ); + + env->spr[SPR_HEIR ] <<=32 ; + env->spr[SPR_HEIR ] |= insn2; + } + *srr0 =SPR_HSRR0 ; + *srr1 =SPR_HSRR1 ; + *new_msr |= (target_ulong )MSR_HVB ; + *new_msr |= env->msr & ((target_ulong )1 <<MSR_RI ); +} + +#endif /* TARGET_PPC64 */ +#endif /* !CONFIG_USER_ONLY */
PATCH v2 11/15 target/ppc: Restrict various common helpers to TCG
In reply to Philippe Mathieu-DaudéMove helpers common to system/user emulation to tcg-excp_helper.c.
--- target/ppc/excp_helper.c | 141 ---------------------------------- target/ppc/tcg-excp_helper.c | 143 +++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 141 deletions(-)
target/ppc/excp_helper.c +0 -141
@@ -2634,148 +2634,7 @@ void helper_rfmci(CPUPPCState *env)/* FIXME: choose CSRR1 or MCSRR1 based on cpu type */ do_rfi (env, env->spr[SPR_BOOKE_MCSRR0 ], env->spr[SPR_BOOKE_MCSRR1 ]); } -#endif /* !CONFIG_USER_ONLY */ -void helper_TW (CPUPPCState *env,target_ulong arg1,target_ulong arg2, -uint32_t flags) -{ -if (!likely (!(((int32_t )arg1 < (int32_t )arg2 && (flags &0x10 )) || - ((int32_t )arg1 > (int32_t )arg2 && (flags &0x08 )) || - ((int32_t )arg1 == (int32_t )arg2 && (flags &0x04 )) || - ((uint32_t )arg1 < (uint32_t )arg2 && (flags &0x02 )) || - ((uint32_t )arg1 > (uint32_t )arg2 && (flags &0x01 ))))) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } -} - -#ifdef TARGET_PPC64 -void helper_TD (CPUPPCState *env,target_ulong arg1,target_ulong arg2, -uint32_t flags) -{ -if (!likely (!(((int64_t )arg1 < (int64_t )arg2 && (flags &0x10 )) || - ((int64_t )arg1 > (int64_t )arg2 && (flags &0x08 )) || - ((int64_t )arg1 == (int64_t )arg2 && (flags &0x04 )) || - ((uint64_t )arg1 < (uint64_t )arg2 && (flags &0x02 )) || - ((uint64_t )arg1 > (uint64_t )arg2 && (flags &0x01 ))))) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } -} -#endif /* TARGET_PPC64 */ - -static uint32_t helper_SIMON_LIKE_32_64 (uint32_t x,uint64_t key,uint32_t lane) -{ -const uint16_t c =0xfffc ; -const uint64_t z0 =0xfa2561cdf44ac398ULL ; -uint16_t z =0 , temp; -uint16_t k[32 ], eff_k[32 ], xleft[33 ], xright[33 ], fxleft[32 ]; - -for (int i =3 ; i >=0 ; i--) { - k[i] = key &0xffff ; - key >>=16 ; - } - xleft[0 ] = x &0xffff ; - xright[0 ] = (x >>16 ) &0xffff ; - -for (int i =0 ; i <28 ; i++) { - z = (z0 >> (63 - i)) &1 ; - temp =ror16 (k[i +3 ],3 ) ^ k[i +1 ]; - k[i +4 ] = c ^ z ^ k[i] ^ temp ^ror16 (temp,1 ); - } - -for (int i =0 ; i <8 ; i++) { - eff_k[4 * i +0 ] = k[4 * i + ((0 + lane) %4 )]; - eff_k[4 * i +1 ] = k[4 * i + ((1 + lane) %4 )]; - eff_k[4 * i +2 ] = k[4 * i + ((2 + lane) %4 )]; - eff_k[4 * i +3 ] = k[4 * i + ((3 + lane) %4 )]; - } - -for (int i =0 ; i <32 ; i++) { - fxleft[i] = (rol16 (xleft[i],1 ) & -rol16 (xleft[i],8 )) ^rol16 (xleft[i],2 ); - xleft[i +1 ] = xright[i] ^ fxleft[i] ^ eff_k[i]; - xright[i +1 ] = xleft[i]; - } - -return (((uint32_t )xright[32 ]) <<16 ) | xleft[32 ]; -} - -static uint64_t hash_digest (uint64_t ra,uint64_t rb,uint64_t key) -{ -uint64_t stage0_h =0ULL , stage0_l =0ULL ; -uint64_t stage1_h, stage1_l; - -for (int i =0 ; i <4 ; i++) { - stage0_h |=ror64 (rb &0xff ,8 * (2 * i +1 )); - stage0_h |= ((ra >>32 ) &0xff ) << (8 *2 * i); - stage0_l |=ror64 ((rb >>32 ) &0xff ,8 * (2 * i +1 )); - stage0_l |= (ra &0xff ) << (8 *2 * i); - rb >>=8 ; - ra >>=8 ; - } - - stage1_h = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_h >>32 , key,0 ) <<32 ; - stage1_h |=helper_SIMON_LIKE_32_64 (stage0_h, key,1 ); - stage1_l = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_l >>32 , key,2 ) <<32 ; - stage1_l |=helper_SIMON_LIKE_32_64 (stage0_l, key,3 ); - -return stage1_h ^ stage1_l; -} - -static void do_hash (CPUPPCState *env,target_ulong ea,target_ulong ra, -target_ulong rb,uint64_t key,bool store) -{ -uint64_t calculated_hash =hash_digest (ra, rb, key), loaded_hash; - -if (store) { -cpu_stq_data_ra (env, ea, calculated_hash,GETPC ()); - }else { - loaded_hash =cpu_ldq_data_ra (env, ea,GETPC ()); -if (loaded_hash != calculated_hash) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } - } -} - -#include "qemu/guest-random.h" - -#ifdef TARGET_PPC64 -#define HELPER_HASH (op, key, store, dexcr_aspect) \ -void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ - target_ulong rb) \ -{ \ - if (env->msr & R_MSR_PR_MASK) { \ - if (!(env->spr[SPR_DEXCR] & R_DEXCR_PRO_##dexcr_aspect##_MASK || \ - env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ - return; \ - } else if (!(env->msr & R_MSR_HV_MASK)) { \ - if (!(env->spr[SPR_DEXCR] & R_DEXCR_PNH_##dexcr_aspect##_MASK || \ - env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ - return; \ - } else if (!(env->msr & R_MSR_S_MASK)) { \ - if (!(env->spr[SPR_HDEXCR] & R_HDEXCR_HNU_##dexcr_aspect##_MASK)) \ - return; \ - } \ - \ - do_hash(env, ea, ra, rb, key, store); \ -} -#else -#define HELPER_HASH (op, key, store, dexcr_aspect) \ -void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ - target_ulong rb) \ -{ \ - do_hash(env, ea, ra, rb, key, store); \ -} -#endif /* TARGET_PPC64 */ - -HELPER_HASH(HASHST, env->spr[SPR_HASHKEYR], true, NPHIE) -HELPER_HASH(HASHCHK, env->spr[SPR_HASHKEYR], false, NPHIE) -HELPER_HASH(HASHSTP, env->spr[SPR_HASHPKEYR], true, PHIE) -HELPER_HASH(HASHCHKP, env->spr[SPR_HASHPKEYR], false, PHIE) - -#ifndef CONFIG_USER_ONLY /* Embedded.Processor Control */ static int dbell2irq (target_ulong rb) {
target/ppc/tcg-excp_helper.c +143 -0
149 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH v2 11/15] target/ppc: Restrict various common helpers to TCG
Quoted 166 lines · Philippe Mathieu-Daudé
Move helpers common to system/user emulation to
tcg-excp_helper.c.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/excp_helper.c | 141 ---------------------------------- target/ppc/tcg-excp_helper.c | 143 +++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 141 deletions(-)target/ppc/excp_helper.c +0
-141@@ -2634,148 +2634,7 @@ void helper_rfmci(CPUPPCState *env)/* FIXME: choose CSRR1 or MCSRR1 based on cpu type */ do_rfi (env, env->spr[SPR_BOOKE_MCSRR0 ], env->spr[SPR_BOOKE_MCSRR1 ]); } -#endif /* !CONFIG_USER_ONLY */ -void helper_TW (CPUPPCState *env,target_ulong arg1,target_ulong arg2, -uint32_t flags) -{ -if (!likely (!(((int32_t )arg1 < (int32_t )arg2 && (flags &0x10 )) || - ((int32_t )arg1 > (int32_t )arg2 && (flags &0x08 )) || - ((int32_t )arg1 == (int32_t )arg2 && (flags &0x04 )) || - ((uint32_t )arg1 < (uint32_t )arg2 && (flags &0x02 )) || - ((uint32_t )arg1 > (uint32_t )arg2 && (flags &0x01 ))))) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } -} - -#ifdef TARGET_PPC64 -void helper_TD (CPUPPCState *env,target_ulong arg1,target_ulong arg2, -uint32_t flags) -{ -if (!likely (!(((int64_t )arg1 < (int64_t )arg2 && (flags &0x10 )) || - ((int64_t )arg1 > (int64_t )arg2 && (flags &0x08 )) || - ((int64_t )arg1 == (int64_t )arg2 && (flags &0x04 )) || - ((uint64_t )arg1 < (uint64_t )arg2 && (flags &0x02 )) || - ((uint64_t )arg1 > (uint64_t )arg2 && (flags &0x01 ))))) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } -} -#endif /* TARGET_PPC64 */ - -static uint32_t helper_SIMON_LIKE_32_64 (uint32_t x,uint64_t key,uint32_t lane) -{ -const uint16_t c =0xfffc ; -const uint64_t z0 =0xfa2561cdf44ac398ULL ; -uint16_t z =0 , temp; -uint16_t k[32 ], eff_k[32 ], xleft[33 ], xright[33 ], fxleft[32 ]; - -for (int i =3 ; i >=0 ; i--) { - k[i] = key &0xffff ; - key >>=16 ; - } - xleft[0 ] = x &0xffff ; - xright[0 ] = (x >>16 ) &0xffff ; - -for (int i =0 ; i <28 ; i++) { - z = (z0 >> (63 - i)) &1 ; - temp =ror16 (k[i +3 ],3 ) ^ k[i +1 ]; - k[i +4 ] = c ^ z ^ k[i] ^ temp ^ror16 (temp,1 ); - } - -for (int i =0 ; i <8 ; i++) { - eff_k[4 * i +0 ] = k[4 * i + ((0 + lane) %4 )]; - eff_k[4 * i +1 ] = k[4 * i + ((1 + lane) %4 )]; - eff_k[4 * i +2 ] = k[4 * i + ((2 + lane) %4 )]; - eff_k[4 * i +3 ] = k[4 * i + ((3 + lane) %4 )]; - } - -for (int i =0 ; i <32 ; i++) { - fxleft[i] = (rol16 (xleft[i],1 ) & -rol16 (xleft[i],8 )) ^rol16 (xleft[i],2 ); - xleft[i +1 ] = xright[i] ^ fxleft[i] ^ eff_k[i]; - xright[i +1 ] = xleft[i]; - } - -return (((uint32_t )xright[32 ]) <<16 ) | xleft[32 ]; -} - -static uint64_t hash_digest (uint64_t ra,uint64_t rb,uint64_t key) -{ -uint64_t stage0_h =0ULL , stage0_l =0ULL ; -uint64_t stage1_h, stage1_l; - -for (int i =0 ; i <4 ; i++) { - stage0_h |=ror64 (rb &0xff ,8 * (2 * i +1 )); - stage0_h |= ((ra >>32 ) &0xff ) << (8 *2 * i); - stage0_l |=ror64 ((rb >>32 ) &0xff ,8 * (2 * i +1 )); - stage0_l |= (ra &0xff ) << (8 *2 * i); - rb >>=8 ; - ra >>=8 ; - } - - stage1_h = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_h >>32 , key,0 ) <<32 ; - stage1_h |=helper_SIMON_LIKE_32_64 (stage0_h, key,1 ); - stage1_l = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_l >>32 , key,2 ) <<32 ; - stage1_l |=helper_SIMON_LIKE_32_64 (stage0_l, key,3 ); - -return stage1_h ^ stage1_l; -} - -static void do_hash (CPUPPCState *env,target_ulong ea,target_ulong ra, -target_ulong rb,uint64_t key,bool store) -{ -uint64_t calculated_hash =hash_digest (ra, rb, key), loaded_hash; - -if (store) { -cpu_stq_data_ra (env, ea, calculated_hash,GETPC ()); - }else { - loaded_hash =cpu_ldq_data_ra (env, ea,GETPC ()); -if (loaded_hash != calculated_hash) { -raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , -POWERPC_EXCP_TRAP ,GETPC ()); - } - } -} - -#include "qemu/guest-random.h" - -#ifdef TARGET_PPC64 -#define HELPER_HASH (op, key, store, dexcr_aspect) \ -void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ - target_ulong rb) \ -{ \ - if (env->msr & R_MSR_PR_MASK) { \ - if (!(env->spr[SPR_DEXCR] & R_DEXCR_PRO_##dexcr_aspect##_MASK || \ - env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ - return; \ - } else if (!(env->msr & R_MSR_HV_MASK)) { \ - if (!(env->spr[SPR_DEXCR] & R_DEXCR_PNH_##dexcr_aspect##_MASK || \ - env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ - return; \ - } else if (!(env->msr & R_MSR_S_MASK)) { \ - if (!(env->spr[SPR_HDEXCR] & R_HDEXCR_HNU_##dexcr_aspect##_MASK)) \ - return; \ - } \ - \ - do_hash(env, ea, ra, rb, key, store); \ -} -#else -#define HELPER_HASH (op, key, store, dexcr_aspect) \ -void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ - target_ulong rb) \ -{ \ - do_hash(env, ea, ra, rb, key, store); \ -} -#endif /* TARGET_PPC64 */ - -HELPER_HASH(HASHST, env->spr[SPR_HASHKEYR], true, NPHIE) -HELPER_HASH(HASHCHK, env->spr[SPR_HASHKEYR], false, NPHIE) -HELPER_HASH(HASHSTP, env->spr[SPR_HASHPKEYR], true, PHIE) -HELPER_HASH(HASHCHKP, env->spr[SPR_HASHPKEYR], false, PHIE) - -#ifndef CONFIG_USER_ONLY /* Embedded.Processor Control */ static int dbell2irq (target_ulong rb) {target/ppc/tcg-excp_helper.c +0
-0
target/ppc/tcg-excp_helper.c void raise_exception(CPUPPCState *env, uint32_t exception) · line 69
Quoted 4 lines
target/ppc/tcg-excp_helper.c +1
-0@@ -66,6 +66,149 @@ void raise_exception(CPUPPCState *env, uint32_t exception) raise_exception_err_ra(env, exception, 0, 0); } +#endif /* CONFIG_USER_ONLY */
Comment update needed: /* !CONFIG_USER_ONLY */
Otherwise,
Quoted 145 lines
target/ppc/tcg-excp_helper.c +142
-0+ +void helper_TW (CPUPPCState *env,target_ulong arg1,target_ulong arg2, +uint32_t flags) +{ +if (!likely (!(((int32_t )arg1 < (int32_t )arg2 && (flags &0x10 )) || + ((int32_t )arg1 > (int32_t )arg2 && (flags &0x08 )) || + ((int32_t )arg1 == (int32_t )arg2 && (flags &0x04 )) || + ((uint32_t )arg1 < (uint32_t )arg2 && (flags &0x02 )) || + ((uint32_t )arg1 > (uint32_t )arg2 && (flags &0x01 ))))) { +raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , +POWERPC_EXCP_TRAP ,GETPC ()); + } +} + +#ifdef TARGET_PPC64 +void helper_TD (CPUPPCState *env,target_ulong arg1,target_ulong arg2, +uint32_t flags) +{ +if (!likely (!(((int64_t )arg1 < (int64_t )arg2 && (flags &0x10 )) || + ((int64_t )arg1 > (int64_t )arg2 && (flags &0x08 )) || + ((int64_t )arg1 == (int64_t )arg2 && (flags &0x04 )) || + ((uint64_t )arg1 < (uint64_t )arg2 && (flags &0x02 )) || + ((uint64_t )arg1 > (uint64_t )arg2 && (flags &0x01 ))))) { +raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , +POWERPC_EXCP_TRAP ,GETPC ()); + } +} +#endif /* TARGET_PPC64 */ + +static uint32_t helper_SIMON_LIKE_32_64 (uint32_t x,uint64_t key,uint32_t lane) +{ +const uint16_t c =0xfffc ; +const uint64_t z0 =0xfa2561cdf44ac398ULL ; +uint16_t z =0 , temp; +uint16_t k[32 ], eff_k[32 ], xleft[33 ], xright[33 ], fxleft[32 ]; + +for (int i =3 ; i >=0 ; i--) { + k[i] = key &0xffff ; + key >>=16 ; + } + xleft[0 ] = x &0xffff ; + xright[0 ] = (x >>16 ) &0xffff ; + +for (int i =0 ; i <28 ; i++) { + z = (z0 >> (63 - i)) &1 ; + temp =ror16 (k[i +3 ],3 ) ^ k[i +1 ]; + k[i +4 ] = c ^ z ^ k[i] ^ temp ^ror16 (temp,1 ); + } + +for (int i =0 ; i <8 ; i++) { + eff_k[4 * i +0 ] = k[4 * i + ((0 + lane) %4 )]; + eff_k[4 * i +1 ] = k[4 * i + ((1 + lane) %4 )]; + eff_k[4 * i +2 ] = k[4 * i + ((2 + lane) %4 )]; + eff_k[4 * i +3 ] = k[4 * i + ((3 + lane) %4 )]; + } + +for (int i =0 ; i <32 ; i++) { + fxleft[i] = (rol16 (xleft[i],1 ) & +rol16 (xleft[i],8 )) ^rol16 (xleft[i],2 ); + xleft[i +1 ] = xright[i] ^ fxleft[i] ^ eff_k[i]; + xright[i +1 ] = xleft[i]; + } + +return (((uint32_t )xright[32 ]) <<16 ) | xleft[32 ]; +} + +static uint64_t hash_digest (uint64_t ra,uint64_t rb,uint64_t key) +{ +uint64_t stage0_h =0ULL , stage0_l =0ULL ; +uint64_t stage1_h, stage1_l; + +for (int i =0 ; i <4 ; i++) { + stage0_h |=ror64 (rb &0xff ,8 * (2 * i +1 )); + stage0_h |= ((ra >>32 ) &0xff ) << (8 *2 * i); + stage0_l |=ror64 ((rb >>32 ) &0xff ,8 * (2 * i +1 )); + stage0_l |= (ra &0xff ) << (8 *2 * i); + rb >>=8 ; + ra >>=8 ; + } + + stage1_h = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_h >>32 , key,0 ) <<32 ; + stage1_h |=helper_SIMON_LIKE_32_64 (stage0_h, key,1 ); + stage1_l = (uint64_t )helper_SIMON_LIKE_32_64 (stage0_l >>32 , key,2 ) <<32 ; + stage1_l |=helper_SIMON_LIKE_32_64 (stage0_l, key,3 ); + +return stage1_h ^ stage1_l; +} + +static void do_hash (CPUPPCState *env,target_ulong ea,target_ulong ra, +target_ulong rb,uint64_t key,bool store) +{ +uint64_t calculated_hash =hash_digest (ra, rb, key), loaded_hash; + +if (store) { +cpu_stq_data_ra (env, ea, calculated_hash,GETPC ()); + }else { + loaded_hash =cpu_ldq_data_ra (env, ea,GETPC ()); +if (loaded_hash != calculated_hash) { +raise_exception_err_ra (env,POWERPC_EXCP_PROGRAM , +POWERPC_EXCP_TRAP ,GETPC ()); + } + } +} + +#include "qemu/guest-random.h" + +#ifdef TARGET_PPC64 +#define HELPER_HASH (op, key, store, dexcr_aspect) \ +void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ + target_ulong rb) \ +{ \ + if (env->msr & R_MSR_PR_MASK) { \ + if (!(env->spr[SPR_DEXCR] & R_DEXCR_PRO_##dexcr_aspect##_MASK || \ + env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ + return; \ + } else if (!(env->msr & R_MSR_HV_MASK)) { \ + if (!(env->spr[SPR_DEXCR] & R_DEXCR_PNH_##dexcr_aspect##_MASK || \ + env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK)) \ + return; \ + } else if (!(env->msr & R_MSR_S_MASK)) { \ + if (!(env->spr[SPR_HDEXCR] & R_HDEXCR_HNU_##dexcr_aspect##_MASK)) \ + return; \ + } \ + \ + do_hash(env, ea, ra, rb, key, store); \ +} +#else +#define HELPER_HASH (op, key, store, dexcr_aspect) \ +void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra, \ + target_ulong rb) \ +{ \ + do_hash(env, ea, ra, rb, key, store); \ +} +#endif /* TARGET_PPC64 */ + +HELPER_HASH(HASHST, env->spr[SPR_HASHKEYR], true, NPHIE) +HELPER_HASH(HASHCHK, env->spr[SPR_HASHKEYR], false, NPHIE) +HELPER_HASH(HASHSTP, env->spr[SPR_HASHPKEYR], true, PHIE) +HELPER_HASH(HASHCHKP, env->spr[SPR_HASHPKEYR], false, PHIE) + +#ifndef CONFIG_USER_ONLY +void ppc_cpu_do_unaligned_access (CPUState *cs,vaddr vaddr,MMUAccessType access_type,int mmu_idx,uintptr_t retaddr)
PATCH v2 12/15 target/ppc: Fix style in excp_helper.c
In reply to Philippe Mathieu-DaudéFix style in do_rfi() before moving the code around.
--- target/ppc/excp_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/ppc/excp_helper.c +2 -1
@@ -2481,8 +2481,9 @@ static void do_rfi(CPUPPCState *env, target_ulong nip, target_ulong msr) msr &= ~(1ULL <<MSR_POW );/* MSR:TGPR cannot be set by any form of rfi */ -if (env->flags &POWERPC_FLAG_TGPR ) +if (env->flags &POWERPC_FLAG_TGPR ) { msr &= ~(1ULL <<MSR_TGPR ); + }#ifdef TARGET_PPC64 /* Switching to 32-bit ? Crop the nip */
Signature · 1 line
2.47.1
Re: [PATCH v2 12/15] target/ppc: Fix style in excp_helper.c
Quoted 3 lines · Philippe Mathieu-Daudé
Fix style in
do_rfi()before moving the code around.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 19 lines
--- target/ppc/excp_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/ppc/excp_helper.c +2
-1@@ -2481,8 +2481,9 @@ static void do_rfi(CPUPPCState *env, target_ulong nip, target_ulong msr) msr &= ~(1ULL <<MSR_POW );/* MSR:TGPR cannot be set by any form of rfi */ -if (env->flags &POWERPC_FLAG_TGPR ) +if (env->flags &POWERPC_FLAG_TGPR ) { msr &= ~(1ULL <<MSR_TGPR ); + }#ifdef TARGET_PPC64 /* Switching to 32-bit ? Crop the nip */
PATCH v2 13/15 target/ppc: Make powerpc_excp() prototype public
In reply to Philippe Mathieu-DaudéIn order to move TCG specific code dependent on powerpc_excp() in the next commit, expose its prototype in "internal.h".
--- target/ppc/internal.h | 1 + target/ppc/excp_helper.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
target/ppc/internal.h +1 -0
@@ -291,6 +291,7 @@ bool ppc_cpu_debug_check_breakpoint(CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); +void powerpc_excp (PowerPCCPU *cpu,int excp);#if defined(TARGET_PPC64 )bool is_prefix_insn_excp (CPUPPCState *env,int excp);
target/ppc/excp_helper.c +1 -1
@@ -1494,7 +1494,7 @@ static inline void powerpc_excp_books(PowerPCCPU *cpu, int excp) }#endif /* TARGET_PPC64 */ -static void powerpc_excp (PowerPCCPU *cpu,int excp) +void powerpc_excp (PowerPCCPU *cpu,int excp) {CPUPPCState *env = &cpu->env;
Signature · 1 line
2.47.1
Re: [PATCH v2 13/15] target/ppc: Make powerpc_excp() prototype public
Quoted 4 lines · Philippe Mathieu-Daudé
In order to move TCG specific code dependent on
powerpc_excp()in the next commit, expose its prototype in "internal.h".Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 30 lines
--- target/ppc/internal.h | 1 + target/ppc/excp_helper.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)target/ppc/internal.h +1
-0@@ -291,6 +291,7 @@ bool ppc_cpu_debug_check_breakpoint(CPUState *cs);bool ppc_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp); G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason); +void powerpc_excp (PowerPCCPU *cpu,int excp);#if defined(TARGET_PPC64 )bool is_prefix_insn_excp (CPUPPCState *env,int excp);target/ppc/excp_helper.c +1
-1@@ -1494,7 +1494,7 @@ static inline void powerpc_excp_books(PowerPCCPU *cpu, int excp) }#endif /* TARGET_PPC64 */ -static void powerpc_excp (PowerPCCPU *cpu,int excp) +void powerpc_excp (PowerPCCPU *cpu,int excp) {CPUPPCState *env = &cpu->env;
PATCH v2 14/15 target/ppc: Restrict ATTN / SCV / PMINSN helpers to TCG
In reply to Philippe Mathieu-DaudéMove helper_attn(), helper_scv() and helper_pminsn() to tcg-excp_helper.c.
--- target/ppc/excp_helper.c | 45 ------------------------------------ target/ppc/tcg-excp_helper.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 45 deletions(-)
target/ppc/excp_helper.c +0 -45
@@ -400,21 +400,6 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, env->reserve_addr =-1 ; } -#ifdef CONFIG_TCG -#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY ) -void helper_attn (CPUPPCState *env) -{ -/* POWER attn is unprivileged when enabled by HID, otherwise illegal */ -if ((*env->check_attn)(env)) { -powerpc_checkstop (env,"host executed attn" ); - }else { -raise_exception_err (env,POWERPC_EXCP_HV_EMU , -POWERPC_EXCP_INVAL |POWERPC_EXCP_INVAL_INVAL ); - } -} -#endif -#endif /* CONFIG_TCG */ -static void powerpc_mcheck_checkstop (CPUPPCState *env) {/* KVM guests always have MSR[ME] enabled */
@@ -2445,36 +2430,6 @@ void helper_ppc_maybe_interrupt(CPUPPCState *env)ppc_maybe_interrupt (env); } -#ifdef TARGET_PPC64 -void helper_scv (CPUPPCState *env,uint32_t lev) -{ -if (env->spr[SPR_FSCR ] & (1ull <<FSCR_SCV )) { -raise_exception_err (env,POWERPC_EXCP_SYSCALL_VECTORED , lev); - }else { -raise_exception_err (env,POWERPC_EXCP_FU ,FSCR_IC_SCV ); - } -} - -void helper_pminsn (CPUPPCState *env,uint32_t insn) -{ -CPUState *cs =env_cpu (env); - - cs->halted =1 ; - -/* Condition for waking up at 0x100 */ - env->resume_as_sreset = (insn !=PPC_PM_STOP ) || - (env->spr[SPR_PSSCR ] &PSSCR_EC ); - -/* HDECR is not to wake from PM state, it may have already fired */ -if (env->resume_as_sreset) { -PowerPCCPU *cpu =env_archcpu (env); -ppc_set_irq (cpu,PPC_INTERRUPT_HDECR ,0 ); - } - -ppc_maybe_interrupt (env); -} -#endif /* TARGET_PPC64 */ -static void do_rfi (CPUPPCState *env,target_ulong nip,target_ulong msr) {/* MSR:POW cannot be set by any form of rfi */
target/ppc/tcg-excp_helper.c +39 -0
@@ -499,6 +499,45 @@ void ppc_tcg_hv_emu(CPUPPCState *env, target_ulong *new_msr, *new_msr |= env->msr & ((target_ulong )1 <<MSR_RI ); } +void helper_attn (CPUPPCState *env) +{ +/* POWER attn is unprivileged when enabled by HID, otherwise illegal */ +if ((*env->check_attn)(env)) { +powerpc_checkstop (env,"host executed attn" ); + }else { +raise_exception_err (env,POWERPC_EXCP_HV_EMU , +POWERPC_EXCP_INVAL |POWERPC_EXCP_INVAL_INVAL ); + } +} + +void helper_scv (CPUPPCState *env,uint32_t lev) +{ +if (env->spr[SPR_FSCR ] & (1ull <<FSCR_SCV )) { +raise_exception_err (env,POWERPC_EXCP_SYSCALL_VECTORED , lev); + }else { +raise_exception_err (env,POWERPC_EXCP_FU ,FSCR_IC_SCV ); + } +} + +void helper_pminsn (CPUPPCState *env,uint32_t insn) +{ +CPUState *cs =env_cpu (env); + + cs->halted =1 ; + +/* Condition for waking up at 0x100 */ + env->resume_as_sreset = (insn !=PPC_PM_STOP ) || + (env->spr[SPR_PSSCR ] &PSSCR_EC ); + +/* HDECR is not to wake from PM state, it may have already fired */ +if (env->resume_as_sreset) { +PowerPCCPU *cpu =env_archcpu (env); +ppc_set_irq (cpu,PPC_INTERRUPT_HDECR ,0 ); + } + +ppc_maybe_interrupt (env); +} +#endif /* TARGET_PPC64 */ #endif /* !CONFIG_USER_ONLY */
Signature · 1 line
2.47.1
Re: [PATCH v2 14/15] target/ppc: Restrict ATTN / SCV / PMINSN helpers to TCG
Quoted 4 lines · Philippe Mathieu-Daudé
Move
helper_attn(),helper_scv()andhelper_pminsn()totcg-excp_helper.c.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 118 lines
--- target/ppc/excp_helper.c | 45 ------------------------------------ target/ppc/tcg-excp_helper.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 45 deletions(-)target/ppc/excp_helper.c +0
-45@@ -400,21 +400,6 @@ static void powerpc_set_excp_state(PowerPCCPU *cpu, target_ulong vector, env->reserve_addr =-1 ; } -#ifdef CONFIG_TCG -#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY ) -void helper_attn (CPUPPCState *env) -{ -/* POWER attn is unprivileged when enabled by HID, otherwise illegal */ -if ((*env->check_attn)(env)) { -powerpc_checkstop (env,"host executed attn" ); - }else { -raise_exception_err (env,POWERPC_EXCP_HV_EMU , -POWERPC_EXCP_INVAL |POWERPC_EXCP_INVAL_INVAL ); - } -} -#endif -#endif /* CONFIG_TCG */ -static void powerpc_mcheck_checkstop (CPUPPCState *env) {/* KVM guests always have MSR[ME] enabled */ @@ -2445,36 +2430,6 @@ void helper_ppc_maybe_interrupt(CPUPPCState *env)ppc_maybe_interrupt (env); } -#ifdef TARGET_PPC64 -void helper_scv (CPUPPCState *env,uint32_t lev) -{ -if (env->spr[SPR_FSCR ] & (1ull <<FSCR_SCV )) { -raise_exception_err (env,POWERPC_EXCP_SYSCALL_VECTORED , lev); - }else { -raise_exception_err (env,POWERPC_EXCP_FU ,FSCR_IC_SCV ); - } -} - -void helper_pminsn (CPUPPCState *env,uint32_t insn) -{ -CPUState *cs =env_cpu (env); - - cs->halted =1 ; - -/* Condition for waking up at 0x100 */ - env->resume_as_sreset = (insn !=PPC_PM_STOP ) || - (env->spr[SPR_PSSCR ] &PSSCR_EC ); - -/* HDECR is not to wake from PM state, it may have already fired */ -if (env->resume_as_sreset) { -PowerPCCPU *cpu =env_archcpu (env); -ppc_set_irq (cpu,PPC_INTERRUPT_HDECR ,0 ); - } - -ppc_maybe_interrupt (env); -} -#endif /* TARGET_PPC64 */ -static void do_rfi (CPUPPCState *env,target_ulong nip,target_ulong msr) {/* MSR:POW cannot be set by any form of rfi */ target/ppc/tcg-excp_helper.c +39
-0@@ -499,6 +499,45 @@ void ppc_tcg_hv_emu(CPUPPCState *env, target_ulong *new_msr, *new_msr |= env->msr & ((target_ulong )1 <<MSR_RI ); } +void helper_attn (CPUPPCState *env) +{ +/* POWER attn is unprivileged when enabled by HID, otherwise illegal */ +if ((*env->check_attn)(env)) { +powerpc_checkstop (env,"host executed attn" ); + }else { +raise_exception_err (env,POWERPC_EXCP_HV_EMU , +POWERPC_EXCP_INVAL |POWERPC_EXCP_INVAL_INVAL ); + } +} + +void helper_scv (CPUPPCState *env,uint32_t lev) +{ +if (env->spr[SPR_FSCR ] & (1ull <<FSCR_SCV )) { +raise_exception_err (env,POWERPC_EXCP_SYSCALL_VECTORED , lev); + }else { +raise_exception_err (env,POWERPC_EXCP_FU ,FSCR_IC_SCV ); + } +} + +void helper_pminsn (CPUPPCState *env,uint32_t insn) +{ +CPUState *cs =env_cpu (env); + + cs->halted =1 ; + +/* Condition for waking up at 0x100 */ + env->resume_as_sreset = (insn !=PPC_PM_STOP ) || + (env->spr[SPR_PSSCR ] &PSSCR_EC ); + +/* HDECR is not to wake from PM state, it may have already fired */ +if (env->resume_as_sreset) { +PowerPCCPU *cpu =env_archcpu (env); +ppc_set_irq (cpu,PPC_INTERRUPT_HDECR ,0 ); + } + +ppc_maybe_interrupt (env); +} +#endif /* TARGET_PPC64 */ #endif /* !CONFIG_USER_ONLY */
PATCH v2 15/15 target/ppc: Restrict various system helpers to TCG
In reply to Philippe Mathieu-DaudéMove various TCG system helpers to tcg-excp_helper.c.
ppc_ldl_code(), raise_exception() and raise_exception_err() are only used within this file, restrict their declaration scope.
--- target/ppc/cpu.h | 3 - target/ppc/internal.h | 2 - target/ppc/excp_helper.c | 389 ----------------------------------- target/ppc/tcg-excp_helper.c | 387 +++++++++++++++++++++++++++++++++- 4 files changed, 384 insertions(+), 397 deletions(-)
target/ppc/cpu.h +0 -3
@@ -2752,9 +2752,6 @@ static inline void cpu_get_tb_cpu_state(CPUPPCState *env, vaddr *pc, }#endif -G_NORETURN void raise_exception(CPUPPCState *env, uint32_t exception); -G_NORETURN void raise_exception_err(CPUPPCState *env, uint32_t exception, -uint32_t error_code); G_NORETURN void raise_exception_err_ra(CPUPPCState *env, uint32_t exception,uint32_t error_code,uintptr_t raddr);
target/ppc/internal.h +0 -2
@@ -268,8 +268,6 @@ static inline void pte_invalidate(target_ulong *pte0)#define PTE_PTEM_MASK 0x7FFFFFBF#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B) -uint32_t ppc_ldl_code (CPUArchState *env,target_ulong addr); -#ifdef CONFIG_USER_ONLY void ppc_cpu_record_sigsegv(CPUState *cs, vaddr addr, MMUAccessType access_type,
target/ppc/excp_helper.c +0 -389
398 lines not on this page · raw message
target/ppc/tcg-excp_helper.c +384 -3
420 lines not on this page · raw message
Signature · 1 line
2.47.1
Quoted 15 lines · Philippe Mathieu-Daudé
Since v1:
- Keepppc_tcg_hv_emu()withinTARGET_PPC64(patch #10)Hi,
This series is a simply a cleanup restricting TCG specific exception-related code to TCG, by moving code to a new unit named '
tcg-excp_helper.c'.I ended doing it as a preliminary cleanup for the "Extract TCG state from CPUState".
Diffstat shows 1K lines moved, but the patches are trivial to review using 'git-diff --color-moved=dimmed-zebra' option.
Quoted 6 lines
Branch published as:
https://gitlab.com/philmd/qemu/-/tree/ppc_excp_extract_tcgRegards,
Phil.
I pulled this in and just added some minor changelog and comment and subject line tweaks noticed in review.
Patch 2 was already merged, patch 10 I left out because it had a few possible issues (but it generally looks good if you plan to resubmit it some time).
Thanks very much, it's a nice cleanup. Sorry I have been slow with things...
Thanks,
Nick
Quoted 26 lines
Philippe Mathieu-Daudé (15):
hw/ppc/spapr: Restrict CONFER hypercall to TCG hw/ppc/spapr: Restrict part ofPAGE_INIThypercall to TCG target/ppc: Makeppc_ldl_code()declaration public target/ppc: Move TCG specific exception handlers totcg-excp_helper.ctarget/ppc: Moveppc_ldl_code()totcg-excp_helper.ctarget/ppc: Ensurepowerpc_checkstop()is only called under TCG target/ppc: Restrictpowerpc_checkstop()to TCG target/ppc: Removeraise_exception_ra()
target/ppc: Restrict exception helpers to TCG
target/ppc: Restrictppc_tcg_hv_emu()to TCG
target/ppc: Restrict various common helpers to TCG target/ppc: Fix style inexcp_helper.c
target/ppc: Makepowerpc_excp()prototype public target/ppc: Restrict ATTN / SCV / PMINSN helpers to TCG target/ppc: Restrict various system helpers to TCGtarget/ppc/cpu.h | 5 - target/ppc/internal.h | 11 +- hw/ppc/spapr_hcall.c | 6 +- target/ppc/excp_helper.c | 943 +---------------------------------- target/ppc/tcg-excp_helper.c | 924 ++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 6 files changed, 955 insertions(+), 935 deletions(-) create mode 100644 target/ppc/tcg-excp_helper.c
Quoted 7 lines · Nicholas Piggin
Quoted 3 lines · Philippe Mathieu-Daudé
This series is a simply a cleanup restricting TCG specific exception-related code to TCG, by moving code to a new unit named '
tcg-excp_helper.c'.
Quoted 6 lines
I pulled this in and just added some minor changelog and comment and subject line tweaks noticed in review.
Patch 2 was already merged, patch 10 I left out because it had a few possible issues (but it generally looks good if you plan to resubmit it some time).
Thank you Nick, I will!
Quoted 6 lines
Thanks very much, it's a nice cleanup. Sorry I have been slow with things...
Thanks,
Nick