target/ppc: Move TCG code from excp_helper.c to tcg-excp_helper.c
cover target/ppc: Move TCG code from excp_helper.c to tcg-excp_helper.c
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 various system helpers to TCG target/ppc: Restrict ATTN helper to TCG
target/ppc/cpu.h | 5 - target/ppc/internal.h | 6 + hw/ppc/spapr_hcall.c | 6 +- target/ppc/excp_helper.c | 943 +---------------------------------- target/ppc/tcg-excp_helper.c | 923 ++++++++++++++++++++++++++++++++++ target/ppc/meson.build | 1 + 6 files changed, 950 insertions(+), 934 deletions(-) create mode 100644 target/ppc/tcg-excp_helper.c
Signature · 1 line
2.47.1
RFC PATCH 1/15 hw/ppc/spapr: Restrict CONFER hypercall to TCG
TODO: Add PPC folks why :)
---
RFC: Missing appropriate commit description...
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
PATCH 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
PATCH 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
PATCH 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
PATCH 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
PATCH 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
PATCH 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 | 2 ++ target/ppc/excp_helper.c | 26 -------------------------- target/ppc/tcg-excp_helper.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 26 deletions(-)
target/ppc/internal.h +2 -0
@@ -289,6 +289,8 @@ 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); + +G_NORETURN void powerpc_checkstop(CPUPPCState *env, const char *reason);#endif FIELD (GER_MSK ,XMSK ,0 ,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
PATCH 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
PATCH 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
PATCH 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 | 3 ++ target/ppc/excp_helper.c | 101 +++++------------------------------ target/ppc/tcg-excp_helper.c | 71 ++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 89 deletions(-)
target/ppc/internal.h +3 -0
@@ -291,6 +291,9 @@ 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); +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 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 +71 -0
75 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH 10/15] target/ppc: Restrict ppc_tcg_hv_emu() to TCG
Quoted 6 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".
Quoted 6 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/ppc/internal.h | 3 ++ target/ppc/excp_helper.c | 101 +++++------------------------------ target/ppc/tcg-excp_helper.c | 71 ++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 89 deletions(-)
I missed this code is TARGET_PPC64 ...:
target/ppc/tcg-excp_helper.c
Quoted 47 lines
static void powerpc_excp_books(PowerPCCPU *cpu, int excp) { CPUPPCState *env = &cpu->env;target/ppc/excp_helper.c +11
-14@@ -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 ) { +/* 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)) { -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);break ; - }#endif target/ppc/tcg-excp_helper.c +0
-0
... so should be this:
Quoted 19 lines
target/ppc/tcg-excp_helper.c +18
-0+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 /* !CONFIG_USER_ONLY */
PATCH 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
PATCH 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
PATCH 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);bool is_prefix_insn_excp (CPUPPCState *env,int excp);void ppc_tcg_hv_emu (CPUPPCState *env,target_ulong *new_msr,int *srr0,int *srr1);
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
PATCH 14/15 target/ppc: Restrict various system helpers to TCG
In reply to Philippe Mathieu-DaudéWe don't need to expose ppc_ldl_code() anymore.
Similarly, make raise_exception() scope local.
--- target/ppc/cpu.h | 1 - target/ppc/internal.h | 2 - target/ppc/excp_helper.c | 414 ---------------------------------- target/ppc/tcg-excp_helper.c | 416 ++++++++++++++++++++++++++++++++++- 4 files changed, 414 insertions(+), 419 deletions(-)
target/ppc/cpu.h +0 -1
@@ -2752,7 +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,
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 -414
417 lines not on this page · raw message
target/ppc/tcg-excp_helper.c +414 -2
444 lines not on this page · raw message
Signature · 1 line
2.47.1
PATCH 15/15 target/ppc: Restrict ATTN helper to TCG
In reply to Philippe Mathieu-DaudéMove helper_attn() to tcg-excp_helper.c and makeraise_exception_err() static.
--- target/ppc/cpu.h | 2 -- target/ppc/excp_helper.c | 20 -------------------- target/ppc/tcg-excp_helper.c | 13 ++++++++++++- 3 files changed, 12 insertions(+), 23 deletions(-)
target/ppc/cpu.h +0 -2
@@ -2752,8 +2752,6 @@ static inline void cpu_get_tb_cpu_state(CPUPPCState *env, vaddr *pc, }#endif -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/excp_helper.c +0 -20
@@ -31,11 +31,6 @@#include "trace.h" -#ifdef CONFIG_TCG -#include "exec/helper-proto.h" -#include "exec/cpu_ldst.h" -#endif -/*****************************************************************************/ /* Exception processing */ #ifndef CONFIG_USER_ONLY
@@ -400,21 +395,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 */
target/ppc/tcg-excp_helper.c +12 -1
@@ -56,7 +56,7 @@ void helper_raise_exception(CPUPPCState *env, uint32_t exception)#ifndef CONFIG_USER_ONLY -void raise_exception_err (CPUPPCState *env,uint32_t exception, +static G_NORETURN void raise_exception_err(CPUPPCState *env, uint32_t exception,uint32_t error_code) {raise_exception_err_ra (env, exception, error_code,0 );
@@ -544,6 +544,17 @@ void helper_pminsn(CPUPPCState *env, uint32_t insn) ppc_maybe_interrupt(env); } +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 /* TARGET_PPC64 */ static void do_rfi (CPUPPCState *env,target_ulong nip,target_ulong msr)
Signature · 1 line
2.47.1