target/arm: Allow CONFIG_TCG=n builds
v2 cover target/arm: Allow CONFIG_TCG=n builds
This series makes the necessary changes to allow the use of --disable-tcg for arm.
For the v2 I have taken a more strict approach to avoid introducing changes in behavior, specially regarding the cpregs hash table.
changes:
patch 5:
Move all cpregs related code from helper.c into cpregs.c;
patches 6 & 7:
These are ARMCPRegInfo and accessors that are currently in helper files. I moved them into cpregs.c, otherwise we can't move the helpers into tcg/
patch 11:
Richard suggested we handle the tcg_enable check in a header, but I noticed that are many more instances of arm_rebuild_hflags being called from code that is tcg-only, so I'm not sure if we want to have the added overhead in all calls. I have extracted all of the new tcg_enable() calls so we can judge if it's worth it.
dropped the previous patch 11:
[RFC PATCH 11/27] target/arm: only perform TCG cpu and machine inits if TCG enabled
This patch had a mistake when we moved register_cp_regs_for_features() under tcg_enabled(). That caused the cp_regs hash table to be empty and no registers being written in write_cpustate_to_list().
v1:
https://lore.kernel.org/r/[email protected]
I have included the other two already reviewed series to facilitate the merge. Patch 12 is the first from this series proper.
I could use some help with the last two patches which deal with the fact that ptw.c needs CPUTLBEntryFull and probe_access_full which are _currently_ only compiled with CONFIG_TCG=y.
The 3 cpregs patches were split from the larger commit[1] from the original series. We're still left with one huge patch, but it is only code movement, it can be checked with:
diff -u <(sed -n 's/^-//p' patch) <(sed -n 's/^\+//p' patch)
1- [RFC v14 14/80] target/arm: split cpregs from tcg/helper.c
https://lore.kernel.org/r/[email protected]
Claudio Fontana (8):
target/arm: rename handle_semihosting to tcg_handle_semihosting target/arm: wrap psci call with tcg_enabled target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() target/arm: move helpers to tcg/
target/arm: Move psci.c into the tcg directory
tests: do not run test-hmp on all machines for ARM KVM-only
tests: do not run qom-test on all machines for ARM KVM-only
tests: device-introspect-test: cope with ARM TCG-only devices
Fabiano Rosas (11):
target/arm: Move PC alignment check
target/arm: Move cpregs code into cpregs.c target/arm: Move define_debug_regs() to cpregs.c target/arm: Move helper_set_pstate_* into cpregs.c target/arm: move translate modules to tcg/ target/arm: Wrap arm_rebuild_hflags calls with tcg_enabled target/arm: Move hflags code into the tcg directory tests/tcg: Do not build/run TCG tests if TCG is disabled target/arm: Move regime_using_lpae_format into internal.h cpu-defs.h: Expose CPUTLBEntryFull to non-TCG code target/arm: don't access TCG code when debugging with KVM
MAINTAINERS | 1 +
configure | 4 +
hw/arm/boot.c | 6 +-
hw/intc/armv7m_nvic.c | 20 +-
include/exec/cpu-defs.h | 6 +
target/arm/arm-powerctl.c | 7 +-
target/arm/cpregs.c | 9505 +++++++++++++++++++++++
target/arm/cpu.c | 10 +-
target/arm/helper.c | 9459 +---------------------
target/arm/internals.h | 32 +-
target/arm/machine.c | 31 +-
target/arm/meson.build | 48 +-
target/arm/ptw.c | 4 +
target/arm/tcg-stubs.c | 33 +
target/arm/{ => tcg}/a32-uncond.decode | 0
target/arm/{ => tcg}/a32.decode | 0
target/arm/{ => tcg}/crypto_helper.c | 0
target/arm/{ => tcg}/debug_helper.c | 367 -
target/arm/{ => tcg}/helper-a64.c | 0
target/arm/tcg/hflags.c | 370 +
target/arm/{ => tcg}/iwmmxt_helper.c | 0
target/arm/{ => tcg}/m-nocp.decode | 0
target/arm/{ => tcg}/m_helper.c | 0
target/arm/tcg/meson.build | 51 +
target/arm/{ => tcg}/mte_helper.c | 0
target/arm/{ => tcg}/mve.decode | 0
target/arm/{ => tcg}/mve_helper.c | 0
target/arm/{ => tcg}/neon-dp.decode | 0
target/arm/{ => tcg}/neon-ls.decode | 0
target/arm/{ => tcg}/neon-shared.decode | 0
target/arm/{ => tcg}/neon_helper.c | 0
target/arm/{ => tcg}/op_helper.c | 1 +
target/arm/{ => tcg}/pauth_helper.c | 0
target/arm/{ => tcg}/psci.c | 0
target/arm/{ => tcg}/sme-fa64.decode | 0
target/arm/{ => tcg}/sme.decode | 0
target/arm/{ => tcg}/sme_helper.c | 29 -
target/arm/{ => tcg}/sve.decode | 0
target/arm/{ => tcg}/sve_helper.c | 0
target/arm/{ => tcg}/t16.decode | 0
target/arm/{ => tcg}/t32.decode | 0
target/arm/{ => tcg}/tlb_helper.c | 18 -
target/arm/{ => tcg}/translate-a64.c | 1 +
target/arm/{ => tcg}/translate-a64.h | 0
target/arm/{ => tcg}/translate-m-nocp.c | 0
target/arm/{ => tcg}/translate-mve.c | 0
target/arm/{ => tcg}/translate-neon.c | 0
target/arm/{ => tcg}/translate-sme.c | 0
target/arm/{ => tcg}/translate-sve.c | 0
target/arm/{ => tcg}/translate-vfp.c | 0
target/arm/{ => tcg}/translate.c | 1 +
target/arm/{ => tcg}/translate.h | 0
target/arm/{ => tcg}/vec_helper.c | 0
target/arm/{ => tcg}/vec_internal.h | 0
target/arm/{ => tcg}/vfp-uncond.decode | 0
target/arm/{ => tcg}/vfp.decode | 0
target/arm/trace-events | 2 +-
tests/Makefile.include | 10 +
tests/qtest/device-introspect-test.c | 32 +-
tests/qtest/qom-test.c | 21 +
tests/qtest/test-hmp.c | 21 +
61 files changed, 10154 insertions(+), 9936 deletions(-)
create mode 100644 target/arm/cpregs.c
create mode 100644 target/arm/tcg-stubs.c
rename target/arm/{ => tcg}/a32-uncond.decode (100%)
rename target/arm/{ => tcg}/a32.decode (100%)
rename target/arm/{ => tcg}/crypto_helper.c (100%)
rename target/arm/{ => tcg}/debug_helper.c (63%)
rename target/arm/{ => tcg}/helper-a64.c (100%)
create mode 100644 target/arm/tcg/hflags.c
rename target/arm/{ => tcg}/iwmmxt_helper.c (100%)
rename target/arm/{ => tcg}/m-nocp.decode (100%)
rename target/arm/{ => tcg}/m_helper.c (100%)
create mode 100644 target/arm/tcg/meson.build
rename target/arm/{ => tcg}/mte_helper.c (100%)
rename target/arm/{ => tcg}/mve.decode (100%)
rename target/arm/{ => tcg}/mve_helper.c (100%)
rename target/arm/{ => tcg}/neon-dp.decode (100%)
rename target/arm/{ => tcg}/neon-ls.decode (100%)
rename target/arm/{ => tcg}/neon-shared.decode (100%)
rename target/arm/{ => tcg}/neon_helper.c (100%)
rename target/arm/{ => tcg}/op_helper.c (99%)
rename target/arm/{ => tcg}/pauth_helper.c (100%)
rename target/arm/{ => tcg}/psci.c (100%)
rename target/arm/{ => tcg}/sme-fa64.decode (100%)
rename target/arm/{ => tcg}/sme.decode (100%)
rename target/arm/{ => tcg}/sme_helper.c (98%)
rename target/arm/{ => tcg}/sve.decode (100%)
rename target/arm/{ => tcg}/sve_helper.c (100%)
rename target/arm/{ => tcg}/t16.decode (100%)
rename target/arm/{ => tcg}/t32.decode (100%)
rename target/arm/{ => tcg}/tlb_helper.c (94%)
rename target/arm/{ => tcg}/translate-a64.c (99%)
rename target/arm/{ => tcg}/translate-a64.h (100%)
rename target/arm/{ => tcg}/translate-m-nocp.c (100%)
rename target/arm/{ => tcg}/translate-mve.c (100%)
rename target/arm/{ => tcg}/translate-neon.c (100%)
rename target/arm/{ => tcg}/translate-sme.c (100%)
rename target/arm/{ => tcg}/translate-sve.c (100%)
rename target/arm/{ => tcg}/translate-vfp.c (100%)
rename target/arm/{ => tcg}/translate.c (99%)
rename target/arm/{ => tcg}/translate.h (100%)
rename target/arm/{ => tcg}/vec_helper.c (100%)
rename target/arm/{ => tcg}/vec_internal.h (100%)
rename target/arm/{ => tcg}/vfp-uncond.decode (100%)
rename target/arm/{ => tcg}/vfp.decode (100%)Signature · 1 line
2.35.3
RFC PATCH v2 1/19 target/arm: rename handle_semihosting to tcg_handle_semihosting
From: Claudio Fontana <[email protected]>
make it clearer from the name that this is a tcg-only function.
--- target/arm/helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/helper.c +2 -2
@@ -10765,7 +10765,7 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)* trapped to the hypervisor in KVM. */ #ifdef CONFIG_TCG -static void handle_semihosting (CPUState *cs) +static void tcg_handle_semihosting (CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;
@@ -10827,7 +10827,7 @@ void arm_cpu_do_interrupt(CPUState *cs)*/ #ifdef CONFIG_TCG if (cs->exception_index ==EXCP_SEMIHOST ) { -handle_semihosting (cs); +tcg_handle_semihosting (cs);return ; }#endif
Signature · 1 line
2.35.3
RFC PATCH v2 2/19 target/arm: wrap psci call with tcg_enabled
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
for "all" builds (tcg + kvm), we want to avoid doing the psci check if tcg is built-in, but not enabled.
--- target/arm/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/helper.c +2 -1
@@ -22,6 +22,7 @@#include "hw/irq.h" #include "sysemu/cpu-timers.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "qapi/qapi-commands-machine-target.h" #include "qapi/error.h" #include "qemu/guest-random.h"
@@ -10814,7 +10815,7 @@ void arm_cpu_do_interrupt(CPUState *cs) env->exception.syndrome); } -if (arm_is_psci_call (cpu, cs->exception_index)) { +if (tcg_enabled () &&arm_is_psci_call (cpu, cs->exception_index)) {arm_handle_psci_call (cpu);qemu_log_mask (CPU_LOG_INT ,"...handled as PSCI call\n" );return ;
Signature · 1 line
2.35.3
RFC PATCH v2 3/19 target/arm: wrap call to aarch64_sve_change_el in tcg_enabled()
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
--- target/arm/helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
target/arm/helper.c +7 -5
@@ -10578,11 +10578,13 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)unsigned int cur_el =arm_current_el (env);int rt; -/* -* Note that new_el can never be 0. If cur_el is 0, then -* el0_a64 is is_a64(), else el0_a64 is ignored. -*/ -aarch64_sve_change_el (env, cur_el, new_el,is_a64 (env)); +if (tcg_enabled ()) { +/* +* Note that new_el can never be 0. If cur_el is 0, then +* el0_a64 is is_a64(), else el0_a64 is ignored. +*/ +aarch64_sve_change_el (env, cur_el, new_el,is_a64 (env)); + }if (cur_el < new_el) {/*
Signature · 1 line
2.35.3
RFC PATCH v2 4/19 target/arm: Move PC alignment check
In reply to Fabiano RosasMove this earlier to make the next patch diff cleaner. While here update the comment slightly to not give the impression that the misalignment affects only TCG.
--- target/arm/machine.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
target/arm/machine.c +9 -9
@@ -839,6 +839,15 @@ static int cpu_post_load(void *opaque, int version_id) } } +/* +* Misaligned thumb pc is architecturally impossible. Fail the +* incoming migration. For TCG it would trigger the assert in +* thumb_tr_translate_insn(). +*/ +if (!is_a64 (env) && env->thumb && (env->regs[15 ] &1 )) { +return -1 ; + } +hw_breakpoint_update_all (cpu);hw_watchpoint_update_all (cpu);
@@ -856,15 +865,6 @@ static int cpu_post_load(void *opaque, int version_id) } } -/* -* Misaligned thumb pc is architecturally impossible. -* We have an assert in thumb_tr_translate_insn to verify this. -* Fail an incoming migrate to avoid this assert. -*/ -if (!is_a64 (env) && env->thumb && (env->regs[15 ] &1 )) { -return -1 ; - } -if (!kvm_enabled ()) {pmu_op_finish (&cpu->env); }
Signature · 1 line
2.35.3
RFC PATCH v2 5/19 target/arm: Move cpregs code into cpregs.c
In reply to Fabiano RosasCode moved verbatim.
--- target/arm/cpregs.c | 9089 ++++++++++++++++++++++++++++++++++++ target/arm/cpu.c | 1 + target/arm/helper.c | 9067 ----------------------------------- target/arm/machine.c | 1 + target/arm/meson.build | 1 + target/arm/op_helper.c | 1 + target/arm/trace-events | 2 +- target/arm/translate-a64.c | 1 + target/arm/translate.c | 1 + 9 files changed, 9096 insertions(+), 9068 deletions(-) create mode 100644 target/arm/cpregs.c
target/arm/cpregs.c new file +9089 -0
@@ -0,0 +1,9089 @@ +/* +* ARM CP registers +* +* This code is licensed under the GNU GPL v2 or later. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "trace.h" +#include "cpu.h" +#include "internals.h" +#include "exec/helper-proto.h" +#include "qemu/main-loop.h" +#include "exec/exec-all.h" +#include "hw/irq.h" +#include "sysemu/cpu-timers.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" +#include "cpregs.h" + +#define ARM_CPU_FREQ 1000000000/* FIXME: 1 GHz, should be configurable */ + +static uint64_t raw_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +assert (ri->fieldoffset); +if (cpreg_field_is_64bit (ri)) { +return CPREG_FIELD64 (env, ri); + }else { +return CPREG_FIELD32 (env, ri); + } +} + +void raw_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +assert (ri->fieldoffset); +if (cpreg_field_is_64bit (ri)) { +CPREG_FIELD64 (env, ri) = value; + }else { +CPREG_FIELD32 (env, ri) = value; + } +} + +static void *raw_ptr (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return (char *)env + ri->fieldoffset; +} + +uint64_t read_raw_cp_reg (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* Raw read of a coprocessor register (as needed for migration, etc). */ +if (ri->type &ARM_CP_CONST ) { +return ri->resetvalue; + }else if (ri->raw_readfn) { +return ri->raw_readfn (env, ri); + }else if (ri->readfn) { +return ri->readfn (env, ri); + }else { +return raw_read (env, ri); + } +} + +static void write_raw_cp_reg (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t v) +{ +/* +* Raw write of a coprocessor register (as needed for migration, etc). +* Note that constant registers are treated as write-ignored; the +* caller should check for success by whether a readback gives the +* value written. +*/ +if (ri->type &ARM_CP_CONST ) { +return ; + }else if (ri->raw_writefn) { + ri->raw_writefn (env, ri, v); + }else if (ri->writefn) { + ri->writefn (env, ri, v); + }else { +raw_write (env, ri, v); + } +} + +static bool raw_accessors_invalid (const ARMCPRegInfo *ri) +{ +/* +* Return true if the regdef would cause an assertion if you called +* read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a +* program bug for it not to have the NO_RAW flag). +* NB that returning false here doesn't necessarily mean that calling +* read/write_raw_cp_reg() is safe, because we can't distinguish "has +* read/write access functions which are safe for raw use" from "has +* read/write access functions which have side effects but has forgotten +* to provide raw access functions". +* The tests here line up with the conditions in read/write_raw_cp_reg() +* and assertions in raw_read()/raw_write(). +*/ +if ((ri->type &ARM_CP_CONST ) || + ri->fieldoffset || + ((ri->raw_writefn || ri->writefn) && (ri->raw_readfn || ri->readfn))) { +return false; + } +return true; +} + +bool write_cpustate_to_list (ARMCPU *cpu,bool kvm_sync) +{ +/* Write the coprocessor state from cpu->env to the (index,value) list. */ +int i; +bool ok = true; + +for (i =0 ; i < cpu->cpreg_array_len; i++) { +uint32_t regidx =kvm_to_cpreg_id (cpu->cpreg_indexes[i]); +const ARMCPRegInfo *ri; +uint64_t newval; + + ri =get_arm_cp_reginfo (cpu->cp_regs, regidx); +if (!ri) { + ok = false; +continue ; + } +if (ri->type &ARM_CP_NO_RAW ) { +continue ; + } + + newval =read_raw_cp_reg (&cpu->env, ri); +if (kvm_sync) { +/* +* Only sync if the previous list->cpustate sync succeeded. +* Rather than tracking the success/failure state for every +* item in the list, we just recheck "does the raw write we must +* have made in write_list_to_cpustate() read back OK" here. +*/ +uint64_t oldval = cpu->cpreg_values[i]; + +if (oldval == newval) { +continue ; + } + +write_raw_cp_reg (&cpu->env, ri, oldval); +if (read_raw_cp_reg (&cpu->env, ri) != oldval) { +continue ; + } + +write_raw_cp_reg (&cpu->env, ri, newval); + } + cpu->cpreg_values[i] = newval; + } +return ok; +} + +bool write_list_to_cpustate (ARMCPU *cpu) +{ +int i; +bool ok = true; + +for (i =0 ; i < cpu->cpreg_array_len; i++) { +uint32_t regidx =kvm_to_cpreg_id (cpu->cpreg_indexes[i]); +uint64_t v = cpu->cpreg_values[i]; +const ARMCPRegInfo *ri; + + ri =get_arm_cp_reginfo (cpu->cp_regs, regidx); +if (!ri) { + ok = false; +continue ; + } +if (ri->type &ARM_CP_NO_RAW ) { +continue ; + } +/* +* Write value and confirm it reads back as written +* (to catch read-only registers and partially read-only +* registers where the incoming migration value doesn't match) +*/ +write_raw_cp_reg (&cpu->env, ri, v); +if (read_raw_cp_reg (&cpu->env, ri) != v) { + ok = false; + } + } +return ok; +} + +static void add_cpreg_to_list (gpointer key,gpointer opaque) +{ +ARMCPU *cpu = opaque; +uint32_t regidx = (uintptr_t )key; +const ARMCPRegInfo *ri =get_arm_cp_reginfo (cpu->cp_regs, regidx); + +if (!(ri->type & (ARM_CP_NO_RAW |ARM_CP_ALIAS ))) { + cpu->cpreg_indexes[cpu->cpreg_array_len] =cpreg_to_kvm_id (regidx); +/* The value array need not be initialized at this point */ + cpu->cpreg_array_len++; + } +} + +static void count_cpreg (gpointer key,gpointer opaque) +{ +ARMCPU *cpu = opaque; +const ARMCPRegInfo *ri; + + ri =g_hash_table_lookup (cpu->cp_regs, key); + +if (!(ri->type & (ARM_CP_NO_RAW |ARM_CP_ALIAS ))) { + cpu->cpreg_array_len++; + } +} + +static gint cpreg_key_compare (gconstpointer a,gconstpointer b) +{ +uint64_t aidx =cpreg_to_kvm_id ((uintptr_t )a); +uint64_t bidx =cpreg_to_kvm_id ((uintptr_t )b); + +if (aidx > bidx) { +return 1 ; + } +if (aidx < bidx) { +return -1 ; + } +return 0 ; +} + +void init_cpreg_list (ARMCPU *cpu) +{ +/* +* Initialise the cpreg_tuples[] array based on the cp_regs hash. +* Note that we require cpreg_tuples[] to be sorted by key ID. +*/ +GList *keys; +int arraylen; + + keys =g_hash_table_get_keys (cpu->cp_regs); + keys =g_list_sort (keys, cpreg_key_compare); + + cpu->cpreg_array_len =0 ; + +g_list_foreach (keys, count_cpreg, cpu); + + arraylen = cpu->cpreg_array_len; + cpu->cpreg_indexes =g_new (uint64_t, arraylen); + cpu->cpreg_values =g_new (uint64_t, arraylen); + cpu->cpreg_vmstate_indexes =g_new (uint64_t, arraylen); + cpu->cpreg_vmstate_values =g_new (uint64_t, arraylen); + cpu->cpreg_vmstate_array_len = cpu->cpreg_array_len; + cpu->cpreg_array_len =0 ; + +g_list_foreach (keys, add_cpreg_to_list, cpu); + +assert (cpu->cpreg_array_len == arraylen); + +g_list_free (keys); +} + +/* +* Some registers are not accessible from AArch32 EL3 if SCR.NS == 0. +*/ +static CPAccessResult access_el3_aa32ns (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +if (!is_a64 (env) &&arm_current_el (env) ==3 && +arm_is_secure_below_el3 (env)) { +return CP_ACCESS_TRAP_UNCATEGORIZED ; + } +return CP_ACCESS_OK ; +} + +/* +* Some secure-only AArch32 registers trap to EL3 if used from +* Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts). +* Note that an access from Secure EL1 can only happen if EL3 is AArch64. +* We assume that the .access field is set to PL1_RW. +*/ +static CPAccessResult access_trap_aa32s_el1 (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==3 ) { +return CP_ACCESS_OK ; + } +if (arm_is_secure_below_el3 (env)) { +if (env->cp15.scr_el3 &SCR_EEL2 ) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_TRAP_EL3 ; + } +/* This will be EL1 NS and EL2 NS, which just UNDEF */ +return CP_ACCESS_TRAP_UNCATEGORIZED ; +} + +/* +* Check for traps to performance monitor registers, which are controlled +* by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3. +*/ +static CPAccessResult access_tpm (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); + +if (el <2 && (mdcr_el2 &MDCR_TPM )) { +return CP_ACCESS_TRAP_EL2 ; + } +if (el <3 && (env->cp15.mdcr_el3 &MDCR_TPM )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} + +/* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */ +static CPAccessResult access_tvm_trvm (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 ) { +uint64_t trap = isread ?HCR_TRVM :HCR_TVM ; +if (arm_hcr_el2_eff (env) & trap) { +return CP_ACCESS_TRAP_EL2 ; + } + } +return CP_ACCESS_OK ; +} + +/* Check for traps from EL1 due to HCR_EL2.TSW. */ +static CPAccessResult access_tsw (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && (arm_hcr_el2_eff (env) &HCR_TSW )) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} + +/* Check for traps from EL1 due to HCR_EL2.TACR. */ +static CPAccessResult access_tacr (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && (arm_hcr_el2_eff (env) &HCR_TACR )) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} + +/* Check for traps from EL1 due to HCR_EL2.TTLB. */ +static CPAccessResult access_ttlb (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && (arm_hcr_el2_eff (env) &HCR_TTLB )) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} + +/* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBIS. */ +static CPAccessResult access_ttlbis (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && + (arm_hcr_el2_eff (env) & (HCR_TTLB |HCR_TTLBIS ))) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} + +#ifdef TARGET_AARCH64 +/* Check for traps from EL1 due to HCR_EL2.TTLB or TTLBOS. */ +static CPAccessResult access_ttlbos (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && + (arm_hcr_el2_eff (env) & (HCR_TTLB |HCR_TTLBOS ))) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} +#endif + +static void dacr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); + +raw_write (env, ri, value); +tlb_flush (CPU (cpu));/* Flush TLB as domain not tracked in TLB */ +} + +static void fcse_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); + +if (raw_read (env, ri) != value) { +/* +* Unlike real hardware the qemu TLB uses virtual addresses, +* not modified virtual addresses, so this causes a TLB flush. +*/ +tlb_flush (CPU (cpu)); +raw_write (env, ri, value); + } +} + +static void contextidr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); + +if (raw_read (env, ri) != value && !arm_feature (env,ARM_FEATURE_PMSA ) + && !extended_addresses_enabled (env)) { +/* +* For VMSA (when not using the LPAE long descriptor page table +* format) this register includes the ASID, so do a TLB flush. +* For PMSA it is purely a process ID and no action is needed. +*/ +tlb_flush (CPU (cpu)); + } +raw_write (env, ri, value); +} + +static int alle1_tlbmask (CPUARMState *env) +{ +/* +* Note that the 'ALL' scope must invalidate both stage 1 and +* stage 2 translations, whereas most other scopes only invalidate +* stage 1 translations. +*/ +return (ARMMMUIdxBit_E10_1 | + ARMMMUIdxBit_E10_1_PAN | + ARMMMUIdxBit_E10_0 | + ARMMMUIdxBit_Stage2 | + ARMMMUIdxBit_Stage2_S); +} + + +/* IS variants of TLB operations must affect all cores */ +static void tlbiall_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_all_cpus_synced (cs); +} + +static void tlbiasid_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_all_cpus_synced (cs); +} + +static void tlbimva_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_page_all_cpus_synced (cs, value &TARGET_PAGE_MASK ); +} + +static void tlbimvaa_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_page_all_cpus_synced (cs, value &TARGET_PAGE_MASK ); +} + +/* +* Non-IS variants of TLB operations are upgraded to +* IS versions if we are at EL1 and HCR_EL2.FB is effectively set to +* force broadcast of these operations. +*/ +static bool tlb_force_broadcast (CPUARMState *env) +{ +return arm_current_el (env) ==1 && (arm_hcr_el2_eff (env) &HCR_FB ); +} + +static void tlbiall_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Invalidate all (TLBIALL) */ +CPUState *cs =env_cpu (env); + +if (tlb_force_broadcast (env)) { +tlb_flush_all_cpus_synced (cs); + }else { +tlb_flush (cs); + } +} + +static void tlbimva_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */ +CPUState *cs =env_cpu (env); + + value &=TARGET_PAGE_MASK ; +if (tlb_force_broadcast (env)) { +tlb_flush_page_all_cpus_synced (cs, value); + }else { +tlb_flush_page (cs, value); + } +} + +static void tlbiasid_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Invalidate by ASID (TLBIASID) */ +CPUState *cs =env_cpu (env); + +if (tlb_force_broadcast (env)) { +tlb_flush_all_cpus_synced (cs); + }else { +tlb_flush (cs); + } +} + +static void tlbimvaa_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */ +CPUState *cs =env_cpu (env); + + value &=TARGET_PAGE_MASK ; +if (tlb_force_broadcast (env)) { +tlb_flush_page_all_cpus_synced (cs, value); + }else { +tlb_flush_page (cs, value); + } +} + +static void tlbiall_nsnh_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_by_mmuidx (cs,alle1_tlbmask (env)); +} + +static void tlbiall_nsnh_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_by_mmuidx_all_cpus_synced (cs,alle1_tlbmask (env)); +} + + +static void tlbiall_hyp_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_by_mmuidx (cs, ARMMMUIdxBit_E2); +} + +static void tlbiall_hyp_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); + +tlb_flush_by_mmuidx_all_cpus_synced (cs, ARMMMUIdxBit_E2); +} + +static void tlbimva_hyp_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); +uint64_t pageaddr = value & ~MAKE_64BIT_MASK (0 ,12 ); + +tlb_flush_page_by_mmuidx (cs, pageaddr, ARMMMUIdxBit_E2); +} + +static void tlbimva_hyp_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); +uint64_t pageaddr = value & ~MAKE_64BIT_MASK (0 ,12 ); + +tlb_flush_page_by_mmuidx_all_cpus_synced (cs, pageaddr, + ARMMMUIdxBit_E2); +} + +static void tlbiipas2_hyp_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); +uint64_t pageaddr = (value &MAKE_64BIT_MASK (0 ,28 )) <<12 ; + +tlb_flush_page_by_mmuidx (cs, pageaddr, ARMMMUIdxBit_Stage2); +} + +static void tlbiipas2is_hyp_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *cs =env_cpu (env); +uint64_t pageaddr = (value &MAKE_64BIT_MASK (0 ,28 )) <<12 ; + +tlb_flush_page_by_mmuidx_all_cpus_synced (cs, pageaddr, ARMMMUIdxBit_Stage2); +} + +static const ARMCPRegInfo cp_reginfo[] = { +/* +* Define the secure and non-secure FCSE identifier CP registers +* separately because there is no secure bank in V8 (no _EL3). This allows +* the secure register to be properly reset and migrated. There is also no +* v8 EL1 version of the register so the non-secure instance stands alone. +*/ + { .name ="FCSEIDR" , + .cp =15 , .opc1 =0 , .crn =13 , .crm =0 , .opc2 =0 , + .access =PL1_RW , .secure =ARM_CP_SECSTATE_NS , + .fieldoffset = offsetof(CPUARMState, cp15.fcseidr_ns), + .resetvalue =0 , .writefn = fcse_write, .raw_writefn = raw_write, }, + { .name ="FCSEIDR_S" , + .cp =15 , .opc1 =0 , .crn =13 , .crm =0 , .opc2 =0 , + .access =PL1_RW , .secure =ARM_CP_SECSTATE_S , + .fieldoffset = offsetof(CPUARMState, cp15.fcseidr_s), + .resetvalue =0 , .writefn = fcse_write, .raw_writefn = raw_write, }, +/* +* Define the secure and non-secure context identifier CP registers +* separately because there is no secure bank in V8 (no _EL3). This allows +* the secure register to be properly reset and migrated. In the +* non-secure case, the 32-bit register will have reset and migration +* disabled during registration as it is handled by the 64-bit instance. +*/ + { .name ="CONTEXTIDR_EL1" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =0 , .crn =13 , .crm =0 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .secure =ARM_CP_SECSTATE_NS , + .fieldoffset = offsetof(CPUARMState, cp15.contextidr_el[1]), + .resetvalue =0 , .writefn = contextidr_write, .raw_writefn = raw_write, }, + { .name ="CONTEXTIDR_S" , .state =ARM_CP_STATE_AA32 , + .cp =15 , .opc1 =0 , .crn =13 , .crm =0 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .secure =ARM_CP_SECSTATE_S , + .fieldoffset = offsetof(CPUARMState, cp15.contextidr_s), + .resetvalue =0 , .writefn = contextidr_write, .raw_writefn = raw_write, }, +}; + +static const ARMCPRegInfo not_v8_cp_reginfo[] = { +/* +* NB: Some of these registers exist in v8 but with more precise +* definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]). +*/ +/* MMU Domain access control / MPU write buffer control */ + { .name ="DACR" , + .cp =15 , .opc1 =CP_ANY , .crn =3 , .crm =CP_ANY , .opc2 =CP_ANY , + .access =PL1_RW , .accessfn = access_tvm_trvm, .resetvalue =0 , + .writefn = dacr_write, .raw_writefn = raw_write, + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.dacr_s), +offsetoflow32 (CPUARMState, cp15.dacr_ns) } }, +/* +* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs. +* For v6 and v5, these mappings are overly broad. +*/ + { .name ="TLB_LOCKDOWN" , .cp =15 , .crn =10 , .crm =0 , + .opc1 =CP_ANY , .opc2 =CP_ANY , .access =PL1_RW , .type =ARM_CP_NOP }, + { .name ="TLB_LOCKDOWN" , .cp =15 , .crn =10 , .crm =1 , + .opc1 =CP_ANY , .opc2 =CP_ANY , .access =PL1_RW , .type =ARM_CP_NOP }, + { .name ="TLB_LOCKDOWN" , .cp =15 , .crn =10 , .crm =4 , + .opc1 =CP_ANY , .opc2 =CP_ANY , .access =PL1_RW , .type =ARM_CP_NOP }, + { .name ="TLB_LOCKDOWN" , .cp =15 , .crn =10 , .crm =8 , + .opc1 =CP_ANY , .opc2 =CP_ANY , .access =PL1_RW , .type =ARM_CP_NOP }, +/* Cache maintenance ops; some of this space may be overridden later. */ + { .name ="CACHEMAINT" , .cp =15 , .crn =7 , .crm =CP_ANY , + .opc1 =0 , .opc2 =CP_ANY , .access =PL1_W , + .type =ARM_CP_NOP |ARM_CP_OVERRIDE }, +}; + +static const ARMCPRegInfo not_v6_cp_reginfo[] = { +/* +* Not all pre-v6 cores implemented this WFI, so this is slightly +* over-broad. +*/ + { .name ="WFI_v5" , .cp =15 , .crn =7 , .crm =8 , .opc1 =0 , .opc2 =2 , + .access =PL1_W , .type =ARM_CP_WFI }, +}; + +static const ARMCPRegInfo not_v7_cp_reginfo[] = { +/* +* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which +* is UNPREDICTABLE; we choose to NOP as most implementations do). +*/ + { .name ="WFI_v6" , .cp =15 , .crn =7 , .crm =0 , .opc1 =0 , .opc2 =4 , + .access =PL1_W , .type =ARM_CP_WFI }, +/* +* L1 cache lockdown. Not architectural in v6 and earlier but in practice +* implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and +* OMAPCP will override this space. +*/ + { .name ="DLOCKDOWN" , .cp =15 , .crn =9 , .crm =0 , .opc1 =0 , .opc2 =0 , + .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c9_data), + .resetvalue =0 }, + { .name ="ILOCKDOWN" , .cp =15 , .crn =9 , .crm =0 , .opc1 =0 , .opc2 =1 , + .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c9_insn), + .resetvalue =0 }, +/* v6 doesn't have the cache ID registers but Linux reads them anyway */ + { .name ="DUMMY" , .cp =15 , .crn =0 , .crm =0 , .opc1 =1 , .opc2 =CP_ANY , + .access =PL1_R , .type =ARM_CP_CONST |ARM_CP_NO_RAW , + .resetvalue =0 }, +/* +* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR; +* implementing it as RAZ means the "debug architecture version" bits +* will read as a reserved value, which should cause Linux to not try +* to use the debug hardware. +*/ + { .name ="DBGDIDR" , .cp =14 , .crn =0 , .crm =0 , .opc1 =0 , .opc2 =0 , + .access =PL0_R , .type =ARM_CP_CONST , .resetvalue =0 }, +/* +* MMU TLB control. Note that the wildcarding means we cover not just +* the unified TLB ops but also the dside/iside/inner-shareable variants. +*/ + { .name ="TLBIALL" , .cp =15 , .crn =8 , .crm =CP_ANY , + .opc1 =CP_ANY , .opc2 =0 , .access =PL1_W , .writefn = tlbiall_write, + .type =ARM_CP_NO_RAW }, + { .name ="TLBIMVA" , .cp =15 , .crn =8 , .crm =CP_ANY , + .opc1 =CP_ANY , .opc2 =1 , .access =PL1_W , .writefn = tlbimva_write, + .type =ARM_CP_NO_RAW }, + { .name ="TLBIASID" , .cp =15 , .crn =8 , .crm =CP_ANY , + .opc1 =CP_ANY , .opc2 =2 , .access =PL1_W , .writefn = tlbiasid_write, + .type =ARM_CP_NO_RAW }, + { .name ="TLBIMVAA" , .cp =15 , .crn =8 , .crm =CP_ANY , + .opc1 =CP_ANY , .opc2 =3 , .access =PL1_W , .writefn = tlbimvaa_write, + .type =ARM_CP_NO_RAW }, + { .name ="PRRR" , .cp =15 , .crn =10 , .crm =2 , + .opc1 =0 , .opc2 =0 , .access =PL1_RW , .type =ARM_CP_NOP }, + { .name ="NMRR" , .cp =15 , .crn =10 , .crm =2 , + .opc1 =0 , .opc2 =1 , .access =PL1_RW , .type =ARM_CP_NOP }, +}; + +static void cpacr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint32_t mask =0 ; + +/* In ARMv8 most bits of CPACR_EL1 are RES0. */ +if (!arm_feature (env,ARM_FEATURE_V8 )) { +/* +* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI. +* ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP. +* TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell. +*/ +if (cpu_isar_feature (aa32_vfp_simd,env_archcpu (env))) { +/* VFP coprocessor: cp10 & cp11 [23:20] */ + mask |=R_CPACR_ASEDIS_MASK | +R_CPACR_D32DIS_MASK | +R_CPACR_CP11_MASK | +R_CPACR_CP10_MASK ; + +if (!arm_feature (env,ARM_FEATURE_NEON )) { +/* ASEDIS [31] bit is RAO/WI */ + value |=R_CPACR_ASEDIS_MASK ; + } + +/* +* VFPv3 and upwards with NEON implement 32 double precision +* registers (D0-D31). +*/ +if (!cpu_isar_feature (aa32_simd_r32,env_archcpu (env))) { +/* D32DIS [30] is RAO/WI if D16-31 are not implemented. */ + value |=R_CPACR_D32DIS_MASK ; + } + } + value &= mask; + } + +/* +* For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 +* is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. +*/ +if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && + !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + mask =R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ; + value = (value & ~mask) | (env->cp15.cpacr_el1 & mask); + } + + env->cp15.cpacr_el1 = value; +} + +static uint64_t cpacr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* +* For A-profile AArch32 EL3 (but not M-profile secure mode), if NSACR.CP10 +* is 0 then CPACR.{CP11,CP10} ignore writes and read as 0b00. +*/ +uint64_t value = env->cp15.cpacr_el1; + +if (arm_feature (env,ARM_FEATURE_EL3 ) && !arm_el_is_aa64 (env,3 ) && + !arm_is_secure (env) && !extract32 (env->cp15.nsacr,10 ,1 )) { + value = ~(R_CPACR_CP11_MASK |R_CPACR_CP10_MASK ); + } +return value; +} + + +static void cpacr_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* +* Call cpacr_write() so that we reset with the correct RAO bits set +* for our CPU features. +*/ +cpacr_write (env, ri,0 ); +} + +static CPAccessResult cpacr_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_feature (env,ARM_FEATURE_V8 )) { +/* Check if CPACR accesses are to be trapped to EL2 */ +if (arm_current_el (env) ==1 &&arm_is_el2_enabled (env) && +FIELD_EX64 (env->cp15.cptr_el[2 ],CPTR_EL2 ,TCPAC )) { +return CP_ACCESS_TRAP_EL2 ; +/* Check if CPACR accesses are to be trapped to EL3 */ + }else if (arm_current_el (env) <3 && +FIELD_EX64 (env->cp15.cptr_el[3 ],CPTR_EL3 ,TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult cptr_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +/* Check if CPTR accesses are set to trap to EL3 */ +if (arm_current_el (env) ==2 && +FIELD_EX64 (env->cp15.cptr_el[3 ],CPTR_EL3 ,TCPAC )) { +return CP_ACCESS_TRAP_EL3 ; + } + +return CP_ACCESS_OK ; +} + +static const ARMCPRegInfo v6_cp_reginfo[] = { +/* prefetch by MVA in v6, NOP in v7 */ + { .name ="MVA_prefetch" , + .cp =15 , .crn =7 , .crm =13 , .opc1 =0 , .opc2 =1 , + .access =PL1_W , .type =ARM_CP_NOP }, +/* +* We need to break the TB after ISB to execute self-modifying code +* correctly and also to take any pending interrupts immediately. +* So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag. +*/ + { .name ="ISB" , .cp =15 , .crn =7 , .crm =5 , .opc1 =0 , .opc2 =4 , + .access =PL0_W , .type =ARM_CP_NO_RAW , .writefn = arm_cp_write_ignore }, + { .name ="DSB" , .cp =15 , .crn =7 , .crm =10 , .opc1 =0 , .opc2 =4 , + .access =PL0_W , .type =ARM_CP_NOP }, + { .name ="DMB" , .cp =15 , .crn =7 , .crm =10 , .opc1 =0 , .opc2 =5 , + .access =PL0_W , .type =ARM_CP_NOP }, + { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 , .opc2 =2 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ifar_s), + offsetof(CPUARMState, cp15.ifar_ns) }, + .resetvalue =0 , }, +/* +* Watchpoint Fault Address Register : should actually only be present +* for 1136, 1176, 11MPCore. +*/ + { .name ="WFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 , .opc2 =1 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 , }, + { .name ="CPACR" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , + .crn =1 , .crm =0 , .opc1 =0 , .opc2 =2 , .accessfn = cpacr_access, + .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.cpacr_el1), + .resetfn = cpacr_reset, .writefn = cpacr_write, .readfn = cpacr_read }, +}; + +typedef struct pm_event { +uint16_t number;/* PMEVTYPER.evtCount is 16 bits wide */ +/* If the event is supported on this CPU (used to generate PMCEID[01]) */ +bool (*supported)(CPUARMState *); +/* +* Retrieve the current count of the underlying event. The programmed +* counters hold a difference from the return value from this function +*/ +uint64_t (*get_count)(CPUARMState *); +/* +* Return how many nanoseconds it will take (at a minimum) for count events +* to occur. A negative value indicates the counter will never overflow, or +* that the counter has otherwise arranged for the overflow bit to be set +* and the PMU interrupt to be raised on overflow. +*/ +int64_t (*ns_per_count)(uint64_t ); +}pm_event ; + +static bool event_always_supported (CPUARMState *env) +{ +return true; +} + +static uint64_t swinc_get_count (CPUARMState *env) +{ +/* +* SW_INCR events are written directly to the pmevcntr's by writes to +* PMSWINC, so there is no underlying count maintained by the PMU itself +*/ +return 0 ; +} + +static int64_t swinc_ns_per (uint64_t ignored) +{ +return -1 ; +} + +/* +* Return the underlying cycle count for the PMU cycle counters. If we're in +* usermode, simply return 0. +*/ +static uint64_t cycles_get_count (CPUARMState *env) +{ +#ifndef CONFIG_USER_ONLY +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), +ARM_CPU_FREQ ,NANOSECONDS_PER_SECOND ); +#else +return cpu_get_host_ticks (); +#endif +} + +#ifndef CONFIG_USER_ONLY +static int64_t cycles_ns_per (uint64_t cycles) +{ +return (ARM_CPU_FREQ /NANOSECONDS_PER_SECOND ) * cycles; +} + +static bool instructions_supported (CPUARMState *env) +{ +return icount_enabled () ==1 ;/* Precise instruction counting */ +} + +static uint64_t instructions_get_count (CPUARMState *env) +{ +return (uint64_t )icount_get_raw (); +} + +static int64_t instructions_ns_per (uint64_t icount) +{ +return icount_to_ns ((int64_t )icount); +} +#endif + +static bool pmuv3p1_events_supported (CPUARMState *env) +{ +/* For events which are supported in any v8.1 PMU */ +return cpu_isar_feature (any_pmuv3p1,env_archcpu (env)); +} + +static bool pmuv3p4_events_supported (CPUARMState *env) +{ +/* For events which are supported in any v8.1 PMU */ +return cpu_isar_feature (any_pmuv3p4,env_archcpu (env)); +} + +static uint64_t zero_event_get_count (CPUARMState *env) +{ +/* For events which on QEMU never fire, so their count is always zero */ +return 0 ; +} + +static int64_t zero_event_ns_per (uint64_t cycles) +{ +/* An event which never fires can never overflow */ +return -1 ; +} + +static const pm_event pm_events[] = { + { .number =0x000 ,/* SW_INCR */ + .supported = event_always_supported, + .get_count = swinc_get_count, + .ns_per_count = swinc_ns_per, + }, +#ifndef CONFIG_USER_ONLY + { .number =0x008 ,/* INST_RETIRED, Instruction architecturally executed */ + .supported = instructions_supported, + .get_count = instructions_get_count, + .ns_per_count = instructions_ns_per, + }, + { .number =0x011 ,/* CPU_CYCLES, Cycle */ + .supported = event_always_supported, + .get_count = cycles_get_count, + .ns_per_count = cycles_ns_per, + }, +#endif + { .number =0x023 ,/* STALL_FRONTEND */ + .supported = pmuv3p1_events_supported, + .get_count = zero_event_get_count, + .ns_per_count = zero_event_ns_per, + }, + { .number =0x024 ,/* STALL_BACKEND */ + .supported = pmuv3p1_events_supported, + .get_count = zero_event_get_count, + .ns_per_count = zero_event_ns_per, + }, + { .number =0x03c ,/* STALL */ + .supported = pmuv3p4_events_supported, + .get_count = zero_event_get_count, + .ns_per_count = zero_event_ns_per, + }, +}; + +/* +* Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of +* events (i.e. the statistical profiling extension), this implementation +* should first be updated to something sparse instead of the current +* supported_event_map[] array. +*/ +#define MAX_EVENT_ID 0x3c +#define UNSUPPORTED_EVENT UINT16_MAX +static uint16_t supported_event_map[MAX_EVENT_ID +1 ]; + +/* +* Called upon CPU initialization to initialize PMCEID[01]_EL0 and build a map +* of ARM event numbers to indices in our pm_events array. +* +* Note: Events in the 0x40XX range are not currently supported. +*/ +void pmu_init (ARMCPU *cpu) +{ +unsigned int i; + +/* +* Empty supported_event_map and cpu->pmceid[01] before adding supported +* events to them +*/ +for (i =0 ; i <ARRAY_SIZE (supported_event_map); i++) { + supported_event_map[i] =UNSUPPORTED_EVENT ; + } + cpu->pmceid0 =0 ; + cpu->pmceid1 =0 ; + +for (i =0 ; i <ARRAY_SIZE (pm_events); i++) { +const pm_event *cnt = &pm_events[i]; +assert (cnt->number <=MAX_EVENT_ID ); +/* We do not currently support events in the 0x40xx range */ +assert (cnt->number <=0x3f ); + +if (cnt->supported (&cpu->env)) { + supported_event_map[cnt->number] = i; +uint64_t event_mask =1ULL << (cnt->number &0x1f ); +if (cnt->number &0x20 ) { + cpu->pmceid1 |= event_mask; + }else { + cpu->pmceid0 |= event_mask; + } + } + } +} + +/* +* Check at runtime whether a PMU event is supported for the current machine +*/ +static bool event_supported (uint16_t number) +{ +if (number >MAX_EVENT_ID ) { +return false; + } +return supported_event_map[number] !=UNSUPPORTED_EVENT ; +} + +static CPAccessResult pmreg_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +/* +* Performance monitor registers user accessibility is controlled +* by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable +* trapping to EL2 or EL3 for other accesses. +*/ +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); + +if (el ==0 && !(env->cp15.c9_pmuserenr &1 )) { +return CP_ACCESS_TRAP ; + } +if (el <2 && (mdcr_el2 &MDCR_TPM )) { +return CP_ACCESS_TRAP_EL2 ; + } +if (el <3 && (env->cp15.mdcr_el3 &MDCR_TPM )) { +return CP_ACCESS_TRAP_EL3 ; + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult pmreg_access_xevcntr (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* ER: event counter read trap control */ +if (arm_feature (env,ARM_FEATURE_V8 ) + &&arm_current_el (env) ==0 + && (env->cp15.c9_pmuserenr & (1 <<3 )) !=0 + && isread) { +return CP_ACCESS_OK ; + } + +return pmreg_access (env, ri, isread); +} + +static CPAccessResult pmreg_access_swinc (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* SW: software increment write trap control */ +if (arm_feature (env,ARM_FEATURE_V8 ) + &&arm_current_el (env) ==0 + && (env->cp15.c9_pmuserenr & (1 <<1 )) !=0 + && !isread) { +return CP_ACCESS_OK ; + } + +return pmreg_access (env, ri, isread); +} + +static CPAccessResult pmreg_access_selr (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* ER: event counter read trap control */ +if (arm_feature (env,ARM_FEATURE_V8 ) + &&arm_current_el (env) ==0 + && (env->cp15.c9_pmuserenr & (1 <<3 )) !=0 ) { +return CP_ACCESS_OK ; + } + +return pmreg_access (env, ri, isread); +} + +static CPAccessResult pmreg_access_ccntr (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* CR: cycle counter read trap control */ +if (arm_feature (env,ARM_FEATURE_V8 ) + &&arm_current_el (env) ==0 + && (env->cp15.c9_pmuserenr & (1 <<2 )) !=0 + && isread) { +return CP_ACCESS_OK ; + } + +return pmreg_access (env, ri, isread); +} + +/* +* Bits in MDCR_EL2 and MDCR_EL3 which pmu_counter_enabled() looks at. +* We use these to decide whether we need to wrap a write to MDCR_EL2 +* or MDCR_EL3 in pmu_op_start()/pmu_op_finish() calls. +*/ +#define MDCR_EL2_PMU_ENABLE_BITS \ + (MDCR_HPME | MDCR_HPMD | MDCR_HPMN | MDCR_HCCD | MDCR_HLP) +#define MDCR_EL3_PMU_ENABLE_BITS (MDCR_SPME | MDCR_SCCD) + +/* +* Returns true if the counter (pass 31 for PMCCNTR) should count events using +* the current EL, security state, and register configuration. +*/ +static bool pmu_counter_enabled (CPUARMState *env,uint8_t counter) +{ +uint64_t filter; +bool e, p, u, nsk, nsu, nsh, m; +bool enabled, prohibited = false, filtered; +bool secure =arm_is_secure (env); +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); +uint8_t hpmn = mdcr_el2 &MDCR_HPMN ; + +if (!arm_feature (env,ARM_FEATURE_PMU )) { +return false; + } + +if (!arm_feature (env,ARM_FEATURE_EL2 ) || + (counter < hpmn || counter ==31 )) { + e = env->cp15.c9_pmcr &PMCRE ; + }else { + e = mdcr_el2 &MDCR_HPME ; + } + enabled = e && (env->cp15.c9_pmcnten & (1 << counter)); + +/* Is event counting prohibited? */ +if (el ==2 && (counter < hpmn || counter ==31 )) { + prohibited = mdcr_el2 &MDCR_HPMD ; + } +if (secure) { + prohibited = prohibited || !(env->cp15.mdcr_el3 &MDCR_SPME ); + } + +if (counter ==31 ) { +/* +* The cycle counter defaults to running. PMCR.DP says "disable +* the cycle counter when event counting is prohibited". +* Some MDCR bits disable the cycle counter specifically. +*/ + prohibited = prohibited && env->cp15.c9_pmcr &PMCRDP ; +if (cpu_isar_feature (any_pmuv3p5,env_archcpu (env))) { +if (secure) { + prohibited = prohibited || (env->cp15.mdcr_el3 &MDCR_SCCD ); + } +if (el ==2 ) { + prohibited = prohibited || (mdcr_el2 &MDCR_HCCD ); + } + } + } + +if (counter ==31 ) { + filter = env->cp15.pmccfiltr_el0; + }else { + filter = env->cp15.c14_pmevtyper[counter]; + } + + p = filter &PMXEVTYPER_P ; + u = filter &PMXEVTYPER_U ; + nsk =arm_feature (env,ARM_FEATURE_EL3 ) && (filter &PMXEVTYPER_NSK ); + nsu =arm_feature (env,ARM_FEATURE_EL3 ) && (filter &PMXEVTYPER_NSU ); + nsh =arm_feature (env,ARM_FEATURE_EL2 ) && (filter &PMXEVTYPER_NSH ); + m =arm_el_is_aa64 (env,1 ) && +arm_feature (env,ARM_FEATURE_EL3 ) && (filter &PMXEVTYPER_M ); + +if (el ==0 ) { + filtered = secure ? u : u != nsu; + }else if (el ==1 ) { + filtered = secure ? p : p != nsk; + }else if (el ==2 ) { + filtered = !nsh; + }else {/* EL3 */ + filtered = m != p; + } + +if (counter !=31 ) { +/* +* If not checking PMCCNTR, ensure the counter is setup to an event we +* support +*/ +uint16_t event = filter &PMXEVTYPER_EVTCOUNT ; +if (!event_supported (event)) { +return false; + } + } + +return enabled && !prohibited && !filtered; +} + +static void pmu_update_irq (CPUARMState *env) +{ +ARMCPU *cpu =env_archcpu (env); +qemu_set_irq (cpu->pmu_interrupt, (env->cp15.c9_pmcr &PMCRE ) && + (env->cp15.c9_pminten & env->cp15.c9_pmovsr)); +} + +static bool pmccntr_clockdiv_enabled (CPUARMState *env) +{ +/* +* Return true if the clock divider is enabled and the cycle counter +* is supposed to tick only once every 64 clock cycles. This is +* controlled by PMCR.D, but if PMCR.LC is set to enable the long +* (64-bit) cycle counter PMCR.D has no effect. +*/ +return (env->cp15.c9_pmcr & (PMCRD |PMCRLC )) ==PMCRD ; +} + +static bool pmevcntr_is_64_bit (CPUARMState *env,int counter) +{ +/* Return true if the specified event counter is configured to be 64 bit */ + +/* This isn't intended to be used with the cycle counter */ +assert (counter <31 ); + +if (!cpu_isar_feature (any_pmuv3p5,env_archcpu (env))) { +return false; + } + +if (arm_feature (env,ARM_FEATURE_EL2 )) { +/* +* MDCR_EL2.HLP still applies even when EL2 is disabled in the +* current security state, so we don't use arm_mdcr_el2_eff() here. +*/ +bool hlp = env->cp15.mdcr_el2 &MDCR_HLP ; +int hpmn = env->cp15.mdcr_el2 &MDCR_HPMN ; + +if (hpmn !=0 && counter >= hpmn) { +return hlp; + } + } +return env->cp15.c9_pmcr &PMCRLP ; +} + +/* +* Ensure c15_ccnt is the guest-visible count so that operations such as +* enabling/disabling the counter or filtering, modifying the count itself, +* etc. can be done logically. This is essentially a no-op if the counter is +* not enabled at the time of the call. +*/ +static void pmccntr_op_start (CPUARMState *env) +{ +uint64_t cycles =cycles_get_count (env); + +if (pmu_counter_enabled (env,31 )) { +uint64_t eff_cycles = cycles; +if (pmccntr_clockdiv_enabled (env)) { + eff_cycles /=64 ; + } + +uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta; + +uint64_t overflow_mask = env->cp15.c9_pmcr &PMCRLC ? \ +1ull <<63 :1ull <<31 ; +if (env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask) { + env->cp15.c9_pmovsr |= (1ULL <<31 ); +pmu_update_irq (env); + } + + env->cp15.c15_ccnt = new_pmccntr; + } + env->cp15.c15_ccnt_delta = cycles; +} + +/* +* If PMCCNTR is enabled, recalculate the delta between the clock and the +* guest-visible count. A call to pmccntr_op_finish should follow every call to +* pmccntr_op_start. +*/ +static void pmccntr_op_finish (CPUARMState *env) +{ +if (pmu_counter_enabled (env,31 )) { +#ifndef CONFIG_USER_ONLY +/* Calculate when the counter will next overflow */ +uint64_t remaining_cycles = -env->cp15.c15_ccnt; +if (!(env->cp15.c9_pmcr &PMCRLC )) { + remaining_cycles = (uint32_t )remaining_cycles; + } +int64_t overflow_in =cycles_ns_per (remaining_cycles); + +if (overflow_in >0 ) { +int64_t overflow_at; + +if (!sadd64_overflow (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), + overflow_in, &overflow_at)) { +ARMCPU *cpu =env_archcpu (env); +timer_mod_anticipate_ns (cpu->pmu_timer, overflow_at); + } + } +#endif + +uint64_t prev_cycles = env->cp15.c15_ccnt_delta; +if (pmccntr_clockdiv_enabled (env)) { + prev_cycles /=64 ; + } + env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt; + } +} + +static void pmevcntr_op_start (CPUARMState *env,uint8_t counter) +{ + +uint16_t event = env->cp15.c14_pmevtyper[counter] &PMXEVTYPER_EVTCOUNT ; +uint64_t count =0 ; +if (event_supported (event)) { +uint16_t event_idx = supported_event_map[event]; + count = pm_events[event_idx].get_count (env); + } + +if (pmu_counter_enabled (env, counter)) { +uint64_t new_pmevcntr = count - env->cp15.c14_pmevcntr_delta[counter]; +uint64_t overflow_mask =pmevcntr_is_64_bit (env, counter) ? +1ULL <<63 :1ULL <<31 ; + +if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & overflow_mask) { + env->cp15.c9_pmovsr |= (1 << counter); +pmu_update_irq (env); + } + env->cp15.c14_pmevcntr[counter] = new_pmevcntr; + } + env->cp15.c14_pmevcntr_delta[counter] = count; +} + +static void pmevcntr_op_finish (CPUARMState *env,uint8_t counter) +{ +if (pmu_counter_enabled (env, counter)) { +#ifndef CONFIG_USER_ONLY +uint16_t event = env->cp15.c14_pmevtyper[counter] &PMXEVTYPER_EVTCOUNT ; +uint16_t event_idx = supported_event_map[event]; +uint64_t delta = -(env->cp15.c14_pmevcntr[counter] +1 ); +int64_t overflow_in; + +if (!pmevcntr_is_64_bit (env, counter)) { + delta = (uint32_t )delta; + } + overflow_in = pm_events[event_idx].ns_per_count (delta); + +if (overflow_in >0 ) { +int64_t overflow_at; + +if (!sadd64_overflow (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), + overflow_in, &overflow_at)) { +ARMCPU *cpu =env_archcpu (env); +timer_mod_anticipate_ns (cpu->pmu_timer, overflow_at); + } + } +#endif + + env->cp15.c14_pmevcntr_delta[counter] -= + env->cp15.c14_pmevcntr[counter]; + } +} + +void pmu_op_start (CPUARMState *env) +{ +unsigned int i; +pmccntr_op_start (env); +for (i =0 ; i <pmu_num_counters (env); i++) { +pmevcntr_op_start (env, i); + } +} + +void pmu_op_finish (CPUARMState *env) +{ +unsigned int i; +pmccntr_op_finish (env); +for (i =0 ; i <pmu_num_counters (env); i++) { +pmevcntr_op_finish (env, i); + } +} + +void pmu_pre_el_change (ARMCPU *cpu,void *ignored) +{ +pmu_op_start (&cpu->env); +} + +void pmu_post_el_change (ARMCPU *cpu,void *ignored) +{ +pmu_op_finish (&cpu->env); +} + +void arm_pmu_timer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +/* +* Update all the counter values based on the current underlying counts, +* triggering interrupts to be raised, if necessary. pmu_op_finish() also +* has the effect of setting the cpu->pmu_timer to the next earliest time a +* counter may expire. +*/ +pmu_op_start (&cpu->env); +pmu_op_finish (&cpu->env); +} + +static void pmcr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmu_op_start (env); + +if (value &PMCRC ) { +/* The counter has been reset */ + env->cp15.c15_ccnt =0 ; + } + +if (value &PMCRP ) { +unsigned int i; +for (i =0 ; i <pmu_num_counters (env); i++) { + env->cp15.c14_pmevcntr[i] =0 ; + } + } + + env->cp15.c9_pmcr &= ~PMCR_WRITABLE_MASK ; + env->cp15.c9_pmcr |= (value &PMCR_WRITABLE_MASK ); + +pmu_op_finish (env); +} + +static void pmswinc_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +unsigned int i; +uint64_t overflow_mask, new_pmswinc; + +for (i =0 ; i <pmu_num_counters (env); i++) { +/* Increment a counter's count iff: */ +if ((value & (1 << i)) &&/* counter's bit is set */ +/* counter is enabled and not filtered */ +pmu_counter_enabled (env, i) && +/* counter is SW_INCR */ + (env->cp15.c14_pmevtyper[i] &PMXEVTYPER_EVTCOUNT ) ==0x0 ) { +pmevcntr_op_start (env, i); + +/* +* Detect if this write causes an overflow since we can't predict +* PMSWINC overflows like we can for other events +*/ + new_pmswinc = env->cp15.c14_pmevcntr[i] +1 ; + + overflow_mask =pmevcntr_is_64_bit (env, i) ? +1ULL <<63 :1ULL <<31 ; + +if (env->cp15.c14_pmevcntr[i] & ~new_pmswinc & overflow_mask) { + env->cp15.c9_pmovsr |= (1 << i); +pmu_update_irq (env); + } + + env->cp15.c14_pmevcntr[i] = new_pmswinc; + +pmevcntr_op_finish (env, i); + } + } +} + +static uint64_t pmccntr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +uint64_t ret; +pmccntr_op_start (env); + ret = env->cp15.c15_ccnt; +pmccntr_op_finish (env); +return ret; +} + +static void pmselr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* +* The value of PMSELR.SEL affects the behavior of PMXEVTYPER and +* PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the +* meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are +* accessed. +*/ + env->cp15.c9_pmselr = value &0x1f ; +} + +static void pmccntr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmccntr_op_start (env); + env->cp15.c15_ccnt = value; +pmccntr_op_finish (env); +} + +static void pmccntr_write32 (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint64_t cur_val =pmccntr_read (env,NULL ); + +pmccntr_write (env, ri,deposit64 (cur_val,0 ,32 , value)); +} + +static void pmccfiltr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmccntr_op_start (env); + env->cp15.pmccfiltr_el0 = value &PMCCFILTR_EL0 ; +pmccntr_op_finish (env); +} + +static void pmccfiltr_write_a32 (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmccntr_op_start (env); +/* M is not accessible from AArch32 */ + env->cp15.pmccfiltr_el0 = (env->cp15.pmccfiltr_el0 &PMCCFILTR_M ) | + (value &PMCCFILTR ); +pmccntr_op_finish (env); +} + +static uint64_t pmccfiltr_read_a32 (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* M is not visible in AArch32 */ +return env->cp15.pmccfiltr_el0 &PMCCFILTR ; +} + +static void pmcntenset_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmu_op_start (env); + value &=pmu_counter_mask (env); + env->cp15.c9_pmcnten |= value; +pmu_op_finish (env); +} + +static void pmcntenclr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmu_op_start (env); + value &=pmu_counter_mask (env); + env->cp15.c9_pmcnten &= ~value; +pmu_op_finish (env); +} + +static void pmovsr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=pmu_counter_mask (env); + env->cp15.c9_pmovsr &= ~value; +pmu_update_irq (env); +} + +static void pmovsset_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=pmu_counter_mask (env); + env->cp15.c9_pmovsr |= value; +pmu_update_irq (env); +} + +static void pmevtyper_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value,const uint8_t counter) +{ +if (counter ==31 ) { +pmccfiltr_write (env, ri, value); + }else if (counter <pmu_num_counters (env)) { +pmevcntr_op_start (env, counter); + +/* +* If this counter's event type is changing, store the current +* underlying count for the new type in c14_pmevcntr_delta[counter] so +* pmevcntr_op_finish has the correct baseline when it converts back to +* a delta. +*/ +uint16_t old_event = env->cp15.c14_pmevtyper[counter] & +PMXEVTYPER_EVTCOUNT ; +uint16_t new_event = value &PMXEVTYPER_EVTCOUNT ; +if (old_event != new_event) { +uint64_t count =0 ; +if (event_supported (new_event)) { +uint16_t event_idx = supported_event_map[new_event]; + count = pm_events[event_idx].get_count (env); + } + env->cp15.c14_pmevcntr_delta[counter] = count; + } + + env->cp15.c14_pmevtyper[counter] = value &PMXEVTYPER_MASK ; +pmevcntr_op_finish (env, counter); + } +/* +* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when +* PMSELR value is equal to or greater than the number of implemented +* counters, but not equal to 0x1f. We opt to behave as a RAZ/WI. +*/ +} + +static uint64_t pmevtyper_read (CPUARMState *env,const ARMCPRegInfo *ri, +const uint8_t counter) +{ +if (counter ==31 ) { +return env->cp15.pmccfiltr_el0; + }else if (counter <pmu_num_counters (env)) { +return env->cp15.c14_pmevtyper[counter]; + }else { +/* +* We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER +* are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write(). +*/ +return 0 ; + } +} + +static void pmevtyper_writefn (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +pmevtyper_write (env, ri, value, counter); +} + +static void pmevtyper_rawwrite (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); + env->cp15.c14_pmevtyper[counter] = value; + +/* +* pmevtyper_rawwrite is called between a pair of pmu_op_start and +* pmu_op_finish calls when loading saved state for a migration. Because +* we're potentially updating the type of event here, the value written to +* c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a +* different counter type. Therefore, we need to set this value to the +* current count for the counter type we're writing so that pmu_op_finish +* has the correct count for its calculation. +*/ +uint16_t event = value &PMXEVTYPER_EVTCOUNT ; +if (event_supported (event)) { +uint16_t event_idx = supported_event_map[event]; + env->cp15.c14_pmevcntr_delta[counter] = + pm_events[event_idx].get_count (env); + } +} + +static uint64_t pmevtyper_readfn (CPUARMState *env,const ARMCPRegInfo *ri) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +return pmevtyper_read (env, ri, counter); +} + +static void pmxevtyper_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmevtyper_write (env, ri, value, env->cp15.c9_pmselr &31 ); +} + +static uint64_t pmxevtyper_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return pmevtyper_read (env, ri, env->cp15.c9_pmselr &31 ); +} + +static void pmevcntr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value,uint8_t counter) +{ +if (!cpu_isar_feature (any_pmuv3p5,env_archcpu (env))) { +/* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */ + value &=MAKE_64BIT_MASK (0 ,32 ); + } +if (counter <pmu_num_counters (env)) { +pmevcntr_op_start (env, counter); + env->cp15.c14_pmevcntr[counter] = value; +pmevcntr_op_finish (env, counter); + } +/* +* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR +* are CONSTRAINED UNPREDICTABLE. +*/ +} + +static uint64_t pmevcntr_read (CPUARMState *env,const ARMCPRegInfo *ri, +uint8_t counter) +{ +if (counter <pmu_num_counters (env)) { +uint64_t ret; +pmevcntr_op_start (env, counter); + ret = env->cp15.c14_pmevcntr[counter]; +pmevcntr_op_finish (env, counter); +if (!cpu_isar_feature (any_pmuv3p5,env_archcpu (env))) { +/* Before FEAT_PMUv3p5, top 32 bits of event counters are RES0 */ + ret &=MAKE_64BIT_MASK (0 ,32 ); + } +return ret; + }else { +/* +* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR +* are CONSTRAINED UNPREDICTABLE. +*/ +return 0 ; + } +} + +static void pmevcntr_writefn (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +pmevcntr_write (env, ri, value, counter); +} + +static uint64_t pmevcntr_readfn (CPUARMState *env,const ARMCPRegInfo *ri) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +return pmevcntr_read (env, ri, counter); +} + +static void pmevcntr_rawwrite (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +assert (counter <pmu_num_counters (env)); + env->cp15.c14_pmevcntr[counter] = value; +pmevcntr_write (env, ri, value, counter); +} + +static uint64_t pmevcntr_rawread (CPUARMState *env,const ARMCPRegInfo *ri) +{ +uint8_t counter = ((ri->crm &3 ) <<3 ) | (ri->opc2 &7 ); +assert (counter <pmu_num_counters (env)); +return env->cp15.c14_pmevcntr[counter]; +} + +static void pmxevcntr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +pmevcntr_write (env, ri, value, env->cp15.c9_pmselr &31 ); +} + +static uint64_t pmxevcntr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return pmevcntr_read (env, ri, env->cp15.c9_pmselr &31 ); +} + +static void pmuserenr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +if (arm_feature (env,ARM_FEATURE_V8 )) { + env->cp15.c9_pmuserenr = value &0xf ; + }else { + env->cp15.c9_pmuserenr = value &1 ; + } +} + +static void pmintenset_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* We have no event counters so only the C bit can be changed */ + value &=pmu_counter_mask (env); + env->cp15.c9_pminten |= value; +pmu_update_irq (env); +} + +static void pmintenclr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=pmu_counter_mask (env); + env->cp15.c9_pminten &= ~value; +pmu_update_irq (env); +} + +static void vbar_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* +* Note that even though the AArch64 view of this register has bits +* [10:0] all RES0 we can only mask the bottom 5, to comply with the +* architectural requirements for bits which are RES0 only in some +* contexts. (ARMv8 would permit us to do no masking at all, but ARMv7 +* requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.) +*/ +raw_write (env, ri, value & ~0x1FULL ); +} + +static void scr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) +{ +/* Begin with base v8.0 state. */ +uint64_t valid_mask =0x3fff ; +ARMCPU *cpu =env_archcpu (env); +uint64_t changed; + +/* +* Because SCR_EL3 is the "real" cpreg and SCR is the alias, reset always +* passes the reginfo for SCR_EL3, which has type ARM_CP_STATE_AA64. +* Instead, choose the format based on the mode of EL3. +*/ +if (arm_el_is_aa64 (env,3 )) { + value |=SCR_FW |SCR_AW ;/* RES1 */ + valid_mask &= ~SCR_NET ;/* RES0 */ + +if (!cpu_isar_feature (aa64_aa32_el1, cpu) && + !cpu_isar_feature (aa64_aa32_el2, cpu)) { + value |=SCR_RW ;/* RAO/WI */ + } +if (cpu_isar_feature (aa64_ras, cpu)) { + valid_mask |=SCR_TERR ; + } +if (cpu_isar_feature (aa64_lor, cpu)) { + valid_mask |=SCR_TLOR ; + } +if (cpu_isar_feature (aa64_pauth, cpu)) { + valid_mask |=SCR_API |SCR_APK ; + } +if (cpu_isar_feature (aa64_sel2, cpu)) { + valid_mask |=SCR_EEL2 ; + } +if (cpu_isar_feature (aa64_mte, cpu)) { + valid_mask |=SCR_ATA ; + } +if (cpu_isar_feature (aa64_scxtnum, cpu)) { + valid_mask |=SCR_ENSCXT ; + } +if (cpu_isar_feature (aa64_doublefault, cpu)) { + valid_mask |=SCR_EASE |SCR_NMEA ; + } +if (cpu_isar_feature (aa64_sme, cpu)) { + valid_mask |=SCR_ENTP2 ; + } + }else { + valid_mask &= ~(SCR_RW |SCR_ST ); +if (cpu_isar_feature (aa32_ras, cpu)) { + valid_mask |=SCR_TERR ; + } + } + +if (!arm_feature (env,ARM_FEATURE_EL2 )) { + valid_mask &= ~SCR_HCE ; + +/* +* On ARMv7, SMD (or SCD as it is called in v7) is only +* supported if EL2 exists. The bit is UNK/SBZP when +* EL2 is unavailable. In QEMU ARMv7, we force it to always zero +* when EL2 is unavailable. +* On ARMv8, this bit is always available. +*/ +if (arm_feature (env,ARM_FEATURE_V7 ) && + !arm_feature (env,ARM_FEATURE_V8 )) { + valid_mask &= ~SCR_SMD ; + } + } + +/* Clear all-context RES0 bits. */ + value &= valid_mask; + changed = env->cp15.scr_el3 ^ value; + env->cp15.scr_el3 = value; + +/* +* If SCR_EL3.NS changes, i.e. arm_is_secure_below_el3, then +* we must invalidate all TLBs below EL3. +*/ +if (changed &SCR_NS ) { +tlb_flush_by_mmuidx (env_cpu (env), (ARMMMUIdxBit_E10_0 | + ARMMMUIdxBit_E20_0 | + ARMMMUIdxBit_E10_1 | + ARMMMUIdxBit_E20_2 | + ARMMMUIdxBit_E10_1_PAN | + ARMMMUIdxBit_E20_2_PAN | + ARMMMUIdxBit_E2)); + } +} + +static void scr_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* +* scr_write will set the RES1 bits on an AArch64-only CPU. +* The reset value will be 0x30 on an AArch64-only CPU and 0 otherwise. +*/ +scr_write (env, ri,0 ); +} + +static CPAccessResult access_tid4 (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && + (arm_hcr_el2_eff (env) & (HCR_TID2 |HCR_TID4 ))) { +return CP_ACCESS_TRAP_EL2 ; + } + +return CP_ACCESS_OK ; +} + +static uint64_t ccsidr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +ARMCPU *cpu =env_archcpu (env); + +/* +* Acquire the CSSELR index from the bank corresponding to the CCSIDR +* bank +*/ +uint32_t index =A32_BANKED_REG_GET (env, csselr, + ri->secure &ARM_CP_SECSTATE_S ); + +return cpu->ccsidr[index]; +} + +static void csselr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +raw_write (env, ri, value &0xf ); +} + +static uint64_t isr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +CPUState *cs =env_cpu (env); +bool el1 =arm_current_el (env) ==1 ; +uint64_t hcr_el2 = el1 ?arm_hcr_el2_eff (env) :0 ; +uint64_t ret =0 ; + +if (hcr_el2 &HCR_IMO ) { +if (cs->interrupt_request &CPU_INTERRUPT_VIRQ ) { + ret |=CPSR_I ; + } + }else { +if (cs->interrupt_request &CPU_INTERRUPT_HARD ) { + ret |=CPSR_I ; + } + } + +if (hcr_el2 &HCR_FMO ) { +if (cs->interrupt_request &CPU_INTERRUPT_VFIQ ) { + ret |=CPSR_F ; + } + }else { +if (cs->interrupt_request &CPU_INTERRUPT_FIQ ) { + ret |=CPSR_F ; + } + } + +if (hcr_el2 &HCR_AMO ) { +if (cs->interrupt_request &CPU_INTERRUPT_VSERR ) { + ret |=CPSR_A ; + } + } + +return ret; +} + +static CPAccessResult access_aa64_tid1 (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==1 && (arm_hcr_el2_eff (env) &HCR_TID1 )) { +return CP_ACCESS_TRAP_EL2 ; + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult access_aa32_tid1 (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_feature (env,ARM_FEATURE_V8 )) { +return access_aa64_tid1 (env, ri, isread); + } + +return CP_ACCESS_OK ; +} + +static const ARMCPRegInfo v7_cp_reginfo[] = { +/* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */ + { .name ="NOP" , .cp =15 , .crn =7 , .crm =0 , .opc1 =0 , .opc2 =4 , + .access =PL1_W , .type =ARM_CP_NOP }, +/* +* Performance monitors are implementation defined in v7, +* but with an ARM recommended set of registers, which we +* follow. +* +* Performance registers fall into three categories: +* (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR) +* (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR) +* (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others) +* For the cases controlled by PMUSERENR we must set .access to PL0_RW +* or PL0_RO as appropriate and then check PMUSERENR in the helper fn. +*/ + { .name ="PMCNTENSET" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =1 , + .access =PL0_RW , .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmcnten), + .writefn = pmcntenset_write, + .accessfn = pmreg_access, + .raw_writefn = raw_write }, + { .name ="PMCNTENSET_EL0" , .state =ARM_CP_STATE_AA64 , .type =ARM_CP_IO , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =12 , .opc2 =1 , + .access =PL0_RW , .accessfn = pmreg_access, + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten), .resetvalue = 0, + .writefn = pmcntenset_write, .raw_writefn = raw_write }, + { .name ="PMCNTENCLR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =2 , + .access =PL0_RW , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmcnten), + .accessfn = pmreg_access, + .writefn = pmcntenclr_write, + .type =ARM_CP_ALIAS |ARM_CP_IO }, + { .name ="PMCNTENCLR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =12 , .opc2 =2 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten), + .writefn = pmcntenclr_write }, + { .name ="PMOVSR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =3 , + .access =PL0_RW , .type =ARM_CP_IO , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmovsr), + .accessfn = pmreg_access, + .writefn = pmovsr_write, + .raw_writefn = raw_write }, + { .name ="PMOVSCLR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =12 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsr_write, + .raw_writefn = raw_write }, + { .name ="PMSWINC" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =4 , + .access =PL0_W , .accessfn = pmreg_access_swinc, + .type =ARM_CP_NO_RAW |ARM_CP_IO , + .writefn = pmswinc_write }, + { .name ="PMSWINC_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =12 , .opc2 =4 , + .access =PL0_W , .accessfn = pmreg_access_swinc, + .type =ARM_CP_NO_RAW |ARM_CP_IO , + .writefn = pmswinc_write }, + { .name ="PMSELR" , .cp =15 , .crn =9 , .crm =12 , .opc1 =0 , .opc2 =5 , + .access =PL0_RW , .type =ARM_CP_ALIAS , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmselr), + .accessfn = pmreg_access_selr, .writefn = pmselr_write, + .raw_writefn = raw_write}, + { .name ="PMSELR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =12 , .opc2 =5 , + .access =PL0_RW , .accessfn = pmreg_access_selr, + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmselr), + .writefn = pmselr_write, .raw_writefn = raw_write, }, + { .name ="PMCCNTR" , .cp =15 , .crn =9 , .crm =13 , .opc1 =0 , .opc2 =0 , + .access =PL0_RW , .resetvalue =0 , .type =ARM_CP_ALIAS |ARM_CP_IO , + .readfn = pmccntr_read, .writefn = pmccntr_write32, + .accessfn = pmreg_access_ccntr }, + { .name ="PMCCNTR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =13 , .opc2 =0 , + .access =PL0_RW , .accessfn = pmreg_access_ccntr, + .type =ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), + .readfn = pmccntr_read, .writefn = pmccntr_write, + .raw_readfn = raw_read, .raw_writefn = raw_write, }, + { .name ="PMCCFILTR" , .cp =15 , .opc1 =0 , .crn =14 , .crm =15 , .opc2 =7 , + .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .resetvalue =0 , }, + { .name ="PMCCFILTR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =15 , .opc2 =7 , + .writefn = pmccfiltr_write, .raw_writefn = raw_write, + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), + .resetvalue =0 , }, + { .name ="PMXEVTYPER" , .cp =15 , .crn =9 , .crm =13 , .opc1 =0 , .opc2 =1 , + .access =PL0_RW , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = pmreg_access, + .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, + { .name ="PMXEVTYPER_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =13 , .opc2 =1 , + .access =PL0_RW , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = pmreg_access, + .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, + { .name ="PMXEVCNTR" , .cp =15 , .crn =9 , .crm =13 , .opc1 =0 , .opc2 =2 , + .access =PL0_RW , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = pmreg_access_xevcntr, + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, + { .name ="PMXEVCNTR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =13 , .opc2 =2 , + .access =PL0_RW , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = pmreg_access_xevcntr, + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, + { .name ="PMUSERENR" , .cp =15 , .crn =9 , .crm =14 , .opc1 =0 , .opc2 =0 , + .access =PL0_R |PL1_RW , .accessfn = access_tpm, + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmuserenr), + .resetvalue =0 , + .writefn = pmuserenr_write, .raw_writefn = raw_write }, + { .name ="PMUSERENR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =14 , .opc2 =0 , + .access =PL0_R |PL1_RW , .accessfn = access_tpm, .type =ARM_CP_ALIAS , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmuserenr), + .resetvalue =0 , + .writefn = pmuserenr_write, .raw_writefn = raw_write }, + { .name ="PMINTENSET" , .cp =15 , .crn =9 , .crm =14 , .opc1 =0 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tpm, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pminten), + .resetvalue =0 , + .writefn = pmintenset_write, .raw_writefn = raw_write }, + { .name ="PMINTENSET_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tpm, + .type =ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten), + .writefn = pmintenset_write, .raw_writefn = raw_write, + .resetvalue =0x0 }, + { .name ="PMINTENCLR" , .cp =15 , .crn =9 , .crm =14 , .opc1 =0 , .opc2 =2 , + .access =PL1_RW , .accessfn = access_tpm, + .type =ARM_CP_ALIAS |ARM_CP_IO |ARM_CP_NO_RAW , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten), + .writefn = pmintenclr_write, }, + { .name ="PMINTENCLR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =2 , + .access =PL1_RW , .accessfn = access_tpm, + .type =ARM_CP_ALIAS |ARM_CP_IO |ARM_CP_NO_RAW , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten), + .writefn = pmintenclr_write }, + { .name ="CCSIDR" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .crn =0 , .crm =0 , .opc1 =1 , .opc2 =0 , + .access =PL1_R , + .accessfn = access_tid4, + .readfn = ccsidr_read, .type =ARM_CP_NO_RAW }, + { .name ="CSSELR" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .crn =0 , .crm =0 , .opc1 =2 , .opc2 =0 , + .access =PL1_RW , + .accessfn = access_tid4, + .writefn = csselr_write, .resetvalue =0 , + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.csselr_s), + offsetof(CPUARMState, cp15.csselr_ns) } }, +/* +* Auxiliary ID register: this actually has an IMPDEF value but for now +* just RAZ for all cores: +*/ + { .name ="AIDR" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =1 , .crn =0 , .crm =0 , .opc2 =7 , + .access =PL1_R , .type =ARM_CP_CONST , + .accessfn = access_aa64_tid1, + .resetvalue =0 }, +/* +* Auxiliary fault status registers: these also are IMPDEF, and we +* choose to RAZ/WI for all cores. +*/ + { .name ="AFSR0_EL1" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =0 , .crn =5 , .crm =1 , .opc2 =0 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="AFSR1_EL1" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =0 , .crn =5 , .crm =1 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .type =ARM_CP_CONST , .resetvalue =0 }, +/* +* MAIR can just read-as-written because we don't implement caches +* and so don't need to care about memory attributes. +*/ + { .name ="MAIR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =0 , .crn =10 , .crm =2 , .opc2 =0 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .fieldoffset = offsetof(CPUARMState, cp15.mair_el[1]), + .resetvalue =0 }, + { .name ="MAIR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =10 , .crm =2 , .opc2 =0 , + .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[3]), + .resetvalue =0 }, +/* +* For non-long-descriptor page tables these are PRRR and NMRR; +* regardless they still act as reads-as-written for QEMU. +*/ +/* +* MAIR0/1 are defined separately from their 64-bit counterpart which +* allows them to assign the correct fieldoffset based on the endianness +* handled in the field definitions. +*/ + { .name ="MAIR0" , .state =ARM_CP_STATE_AA32 , + .cp =15 , .opc1 =0 , .crn =10 , .crm =2 , .opc2 =0 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.mair0_s), + offsetof(CPUARMState, cp15.mair0_ns) }, + .resetfn = arm_cp_reset_ignore }, + { .name ="MAIR1" , .state =ARM_CP_STATE_AA32 , + .cp =15 , .opc1 =0 , .crn =10 , .crm =2 , .opc2 =1 , + .access =PL1_RW , .accessfn = access_tvm_trvm, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.mair1_s), + offsetof(CPUARMState, cp15.mair1_ns) }, + .resetfn = arm_cp_reset_ignore }, + { .name ="ISR_EL1" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =0 , .crn =12 , .crm =1 , .opc2 =0 , + .type =ARM_CP_NO_RAW , .access =PL1_R , .readfn = isr_read }, +/* 32 bit ITLB invalidates */ + { .name ="ITLBIALL" , .cp =15 , .opc1 =0 , .crn =8 , .crm =5 , .opc2 =0 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiall_write }, + { .name ="ITLBIMVA" , .cp =15 , .opc1 =0 , .crn =8 , .crm =5 , .opc2 =1 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbimva_write }, + { .name ="ITLBIASID" , .cp =15 , .opc1 =0 , .crn =8 , .crm =5 , .opc2 =2 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiasid_write }, +/* 32 bit DTLB invalidates */ + { .name ="DTLBIALL" , .cp =15 , .opc1 =0 , .crn =8 , .crm =6 , .opc2 =0 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiall_write }, + { .name ="DTLBIMVA" , .cp =15 , .opc1 =0 , .crn =8 , .crm =6 , .opc2 =1 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbimva_write }, + { .name ="DTLBIASID" , .cp =15 , .opc1 =0 , .crn =8 , .crm =6 , .opc2 =2 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiasid_write }, +/* 32 bit TLB invalidates */ + { .name ="TLBIALL" , .cp =15 , .opc1 =0 , .crn =8 , .crm =7 , .opc2 =0 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiall_write }, + { .name ="TLBIMVA" , .cp =15 , .opc1 =0 , .crn =8 , .crm =7 , .opc2 =1 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbimva_write }, + { .name ="TLBIASID" , .cp =15 , .opc1 =0 , .crn =8 , .crm =7 , .opc2 =2 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbiasid_write }, + { .name ="TLBIMVAA" , .cp =15 , .opc1 =0 , .crn =8 , .crm =7 , .opc2 =3 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlb, + .writefn = tlbimvaa_write }, +}; + +static const ARMCPRegInfo v7mp_cp_reginfo[] = { +/* 32 bit TLB invalidates, Inner Shareable */ + { .name ="TLBIALLIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =0 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlbis, + .writefn = tlbiall_is_write }, + { .name ="TLBIMVAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =1 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlbis, + .writefn = tlbimva_is_write }, + { .name ="TLBIASIDIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =2 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlbis, + .writefn = tlbiasid_is_write }, + { .name ="TLBIMVAAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =3 , + .type =ARM_CP_NO_RAW , .access =PL1_W , .accessfn = access_ttlbis, + .writefn = tlbimvaa_is_write }, +}; + +static const ARMCPRegInfo pmovsset_cp_reginfo[] = { +/* PMOVSSET is not implemented in v7 before v7ve */ + { .name ="PMOVSSET" , .cp =15 , .opc1 =0 , .crn =9 , .crm =14 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset =offsetoflow32 (CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, + { .name ="PMOVSSET_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =9 , .crm =14 , .opc2 =3 , + .access =PL0_RW , .accessfn = pmreg_access, + .type =ARM_CP_ALIAS |ARM_CP_IO , + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), + .writefn = pmovsset_write, + .raw_writefn = raw_write }, +}; + +static void teecr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ + value &=1 ; + env->teecr = value; +} + +static CPAccessResult teecr_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +/* +* HSTR.TTEE only exists in v7A, not v8A, but v8A doesn't have T2EE +* at all, so we don't need to check whether we're v8A. +*/ +if (arm_current_el (env) <2 && !arm_is_secure_below_el3 (env) && + (env->cp15.hstr_el2 &HSTR_TTEE )) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_OK ; +} + +static CPAccessResult teehbr_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (arm_current_el (env) ==0 && (env->teecr &1 )) { +return CP_ACCESS_TRAP ; + } +return teecr_access (env, ri, isread); +} + +static const ARMCPRegInfo t2ee_cp_reginfo[] = { + { .name ="TEECR" , .cp =14 , .crn =0 , .crm =0 , .opc1 =6 , .opc2 =0 , + .access =PL1_RW , .fieldoffset = offsetof(CPUARMState , teecr), + .resetvalue =0 , + .writefn = teecr_write, .accessfn = teecr_access }, + { .name ="TEEHBR" , .cp =14 , .crn =1 , .crm =0 , .opc1 =6 , .opc2 =0 , + .access =PL0_RW , .fieldoffset = offsetof(CPUARMState , teehbr), + .accessfn = teehbr_access, .resetvalue =0 }, +}; + +static const ARMCPRegInfo v6k_cp_reginfo[] = { + { .name ="TPIDR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .opc2 =2 , .crn =13 , .crm =0 , + .access =PL0_RW , + .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el[0]), .resetvalue = 0 }, + { .name ="TPIDRURW" , .cp =15 , .crn =13 , .crm =0 , .opc1 =0 , .opc2 =2 , + .access =PL0_RW , + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.tpidrurw_s), +offsetoflow32 (CPUARMState, cp15.tpidrurw_ns) }, + .resetfn = arm_cp_reset_ignore }, + { .name ="TPIDRRO_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .opc2 =3 , .crn =13 , .crm =0 , + .access =PL0_R |PL1_W , + .fieldoffset = offsetof(CPUARMState, cp15.tpidrro_el[0]), + .resetvalue =0 }, + { .name ="TPIDRURO" , .cp =15 , .crn =13 , .crm =0 , .opc1 =0 , .opc2 =3 , + .access =PL0_R |PL1_W , + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.tpidruro_s), +offsetoflow32 (CPUARMState, cp15.tpidruro_ns) }, + .resetfn = arm_cp_reset_ignore }, + { .name ="TPIDR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =0 , .opc2 =4 , .crn =13 , .crm =0 , + .access =PL1_RW , + .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el[1]), .resetvalue = 0 }, + { .name ="TPIDRPRW" , .opc1 =0 , .cp =15 , .crn =13 , .crm =0 , .opc2 =4 , + .access =PL1_RW , + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.tpidrprw_s), +offsetoflow32 (CPUARMState, cp15.tpidrprw_ns) }, + .resetvalue =0 }, +}; + +#ifndef CONFIG_USER_ONLY + +static CPAccessResult gt_cntfrq_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +/* +* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero. +* Writable only at the highest implemented exception level. +*/ +int el =arm_current_el (env); +uint64_t hcr; +uint32_t cntkctl; + +switch (el) { +case 0 : + hcr =arm_hcr_el2_eff (env); +if ((hcr & (HCR_E2H |HCR_TGE )) == (HCR_E2H |HCR_TGE )) { + cntkctl = env->cp15.cnthctl_el2; + }else { + cntkctl = env->cp15.c14_cntkctl; + } +if (!extract32 (cntkctl,0 ,2 )) { +return CP_ACCESS_TRAP ; + } +break ; +case 1 : +if (!isread && ri->state ==ARM_CP_STATE_AA32 && +arm_is_secure_below_el3 (env)) { +/* Accesses from 32-bit Secure EL1 UNDEF (*not* trap to EL3!) */ +return CP_ACCESS_TRAP_UNCATEGORIZED ; + } +break ; +case 2 : +case 3 : +break ; + } + +if (!isread && el <arm_highest_el (env)) { +return CP_ACCESS_TRAP_UNCATEGORIZED ; + } + +return CP_ACCESS_OK ; +} + +static CPAccessResult gt_counter_access (CPUARMState *env,int timeridx, +bool isread) +{ +unsigned int cur_el =arm_current_el (env); +bool has_el2 =arm_is_el2_enabled (env); +uint64_t hcr =arm_hcr_el2_eff (env); + +switch (cur_el) { +case 0 : +/* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]CTEN. */ +if ((hcr & (HCR_E2H |HCR_TGE )) == (HCR_E2H |HCR_TGE )) { +return (extract32 (env->cp15.cnthctl_el2, timeridx,1 ) + ?CP_ACCESS_OK :CP_ACCESS_TRAP_EL2 ); + } + +/* CNT[PV]CT: not visible from PL0 if EL0[PV]CTEN is zero */ +if (!extract32 (env->cp15.c14_cntkctl, timeridx,1 )) { +return CP_ACCESS_TRAP ; + } + +/* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PCTEN. */ +if (hcr &HCR_E2H ) { +if (timeridx ==GTIMER_PHYS && + !extract32 (env->cp15.cnthctl_el2,10 ,1 )) { +return CP_ACCESS_TRAP_EL2 ; + } + }else { +/* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */ +if (has_el2 && timeridx ==GTIMER_PHYS && + !extract32 (env->cp15.cnthctl_el2,1 ,1 )) { +return CP_ACCESS_TRAP_EL2 ; + } + } +break ; + +case 1 : +/* Check CNTHCTL_EL2.EL1PCTEN, which changes location based on E2H. */ +if (has_el2 && timeridx ==GTIMER_PHYS && + (hcr &HCR_E2H + ? !extract32 (env->cp15.cnthctl_el2,10 ,1 ) + : !extract32 (env->cp15.cnthctl_el2,0 ,1 ))) { +return CP_ACCESS_TRAP_EL2 ; + } +break ; + } +return CP_ACCESS_OK ; +} + +static CPAccessResult gt_timer_access (CPUARMState *env,int timeridx, +bool isread) +{ +unsigned int cur_el =arm_current_el (env); +bool has_el2 =arm_is_el2_enabled (env); +uint64_t hcr =arm_hcr_el2_eff (env); + +switch (cur_el) { +case 0 : +if ((hcr & (HCR_E2H |HCR_TGE )) == (HCR_E2H |HCR_TGE )) { +/* If HCR_EL2.<E2H,TGE> == '11': check CNTHCTL_EL2.EL0[PV]TEN. */ +return (extract32 (env->cp15.cnthctl_el2,9 - timeridx,1 ) + ?CP_ACCESS_OK :CP_ACCESS_TRAP_EL2 ); + } + +/* +* CNT[PV]_CVAL, CNT[PV]_CTL, CNT[PV]_TVAL: not visible from +* EL0 if EL0[PV]TEN is zero. +*/ +if (!extract32 (env->cp15.c14_cntkctl,9 - timeridx,1 )) { +return CP_ACCESS_TRAP ; + } +/* fall through */ + +case 1 : +if (has_el2 && timeridx ==GTIMER_PHYS ) { +if (hcr &HCR_E2H ) { +/* If HCR_EL2.<E2H,TGE> == '10': check CNTHCTL_EL2.EL1PTEN. */ +if (!extract32 (env->cp15.cnthctl_el2,11 ,1 )) { +return CP_ACCESS_TRAP_EL2 ; + } + }else { +/* If HCR_EL2.<E2H> == 0: check CNTHCTL_EL2.EL1PCEN. */ +if (!extract32 (env->cp15.cnthctl_el2,1 ,1 )) { +return CP_ACCESS_TRAP_EL2 ; + } + } + } +break ; + } +return CP_ACCESS_OK ; +} + +static CPAccessResult gt_pct_access (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +return gt_counter_access (env,GTIMER_PHYS , isread); +} + +static CPAccessResult gt_vct_access (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +return gt_counter_access (env,GTIMER_VIRT , isread); +} + +static CPAccessResult gt_ptimer_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +return gt_timer_access (env,GTIMER_PHYS , isread); +} + +static CPAccessResult gt_vtimer_access (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +return gt_timer_access (env,GTIMER_VIRT , isread); +} + +static CPAccessResult gt_stimer_access (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* +* The AArch64 register view of the secure physical timer is +* always accessible from EL3, and configurably accessible from +* Secure EL1. +*/ +switch (arm_current_el (env)) { +case 1 : +if (!arm_is_secure (env)) { +return CP_ACCESS_TRAP ; + } +if (!(env->cp15.scr_el3 &SCR_ST )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +case 0 : +case 2 : +return CP_ACCESS_TRAP ; +case 3 : +return CP_ACCESS_OK ; +default : +g_assert_not_reached (); + } +} + +static uint64_t gt_get_countervalue (CPUARMState *env) +{ +ARMCPU *cpu =env_archcpu (env); + +return qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /gt_cntfrq_period_ns (cpu); +} + +static void gt_recalc_timer (ARMCPU *cpu,int timeridx) +{ +ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx]; + +if (gt->ctl &1 ) { +/* +* Timer enabled: calculate and set current ISTATUS, irq, and +* reset timer to when ISTATUS next has to change +*/ +uint64_t offset = timeridx ==GTIMER_VIRT ? + cpu->env.cp15.cntvoff_el2 :0 ; +uint64_t count =gt_get_countervalue (&cpu->env); +/* Note that this must be unsigned 64 bit arithmetic: */ +int istatus = count - offset >= gt->cval; +uint64_t nexttick; +int irqstate; + + gt->ctl =deposit32 (gt->ctl,2 ,1 , istatus); + + irqstate = (istatus && !(gt->ctl &2 )); +qemu_set_irq (cpu->gt_timer_outputs[timeridx], irqstate); + +if (istatus) { +/* Next transition is when count rolls back over to zero */ + nexttick =UINT64_MAX ; + }else { +/* Next transition is when we hit cval */ + nexttick = gt->cval + offset; + } +/* +* Note that the desired next expiry time might be beyond the +* signed-64-bit range of a QEMUTimer -- in this case we just +* set the timer for as far in the future as possible. When the +* timer expires we will reset the timer for any remaining period. +*/ +if (nexttick >INT64_MAX /gt_cntfrq_period_ns (cpu)) { +timer_mod_ns (cpu->gt_timer[timeridx],INT64_MAX ); + }else { +timer_mod (cpu->gt_timer[timeridx], nexttick); + } +trace_arm_gt_recalc (timeridx, irqstate, nexttick); + }else { +/* Timer disabled: ISTATUS and timer output always clear */ + gt->ctl &= ~4 ; +qemu_set_irq (cpu->gt_timer_outputs[timeridx],0 ); +timer_del (cpu->gt_timer[timeridx]); +trace_arm_gt_recalc_disabled (timeridx); + } +} + +static void gt_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri, +int timeridx) +{ +ARMCPU *cpu =env_archcpu (env); + +timer_del (cpu->gt_timer[timeridx]); +} + +static uint64_t gt_cnt_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_get_countervalue (env); +} + +static uint64_t gt_virt_cnt_offset (CPUARMState *env) +{ +uint64_t hcr; + +switch (arm_current_el (env)) { +case 2 : + hcr =arm_hcr_el2_eff (env); +if (hcr &HCR_E2H ) { +return 0 ; + } +break ; +case 0 : + hcr =arm_hcr_el2_eff (env); +if ((hcr & (HCR_E2H |HCR_TGE )) == (HCR_E2H |HCR_TGE )) { +return 0 ; + } +break ; + } + +return env->cp15.cntvoff_el2; +} + +static uint64_t gt_virt_cnt_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_get_countervalue (env) -gt_virt_cnt_offset (env); +} + +static void gt_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +int timeridx, +uint64_t value) +{ +trace_arm_gt_cval_write (timeridx, value); + env->cp15.c14_timer[timeridx].cval = value; +gt_recalc_timer (env_archcpu (env), timeridx); +} + +static uint64_t gt_tval_read (CPUARMState *env,const ARMCPRegInfo *ri, +int timeridx) +{ +uint64_t offset =0 ; + +switch (timeridx) { +case GTIMER_VIRT : +case GTIMER_HYPVIRT : + offset =gt_virt_cnt_offset (env); +break ; + } + +return (uint32_t )(env->cp15.c14_timer[timeridx].cval - + (gt_get_countervalue (env) - offset)); +} + +static void gt_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +int timeridx, +uint64_t value) +{ +uint64_t offset =0 ; + +switch (timeridx) { +case GTIMER_VIRT : +case GTIMER_HYPVIRT : + offset =gt_virt_cnt_offset (env); +break ; + } + +trace_arm_gt_tval_write (timeridx, value); + env->cp15.c14_timer[timeridx].cval =gt_get_countervalue (env) - offset + +sextract64 (value,0 ,32 ); +gt_recalc_timer (env_archcpu (env), timeridx); +} + +static void gt_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +int timeridx, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +uint32_t oldval = env->cp15.c14_timer[timeridx].ctl; + +trace_arm_gt_ctl_write (timeridx, value); + env->cp15.c14_timer[timeridx].ctl =deposit64 (oldval,0 ,2 , value); +if ((oldval ^ value) &1 ) { +/* Enable toggled */ +gt_recalc_timer (cpu, timeridx); + }else if ((oldval ^ value) &2 ) { +/* +* IMASK toggled: don't need to recalculate, +* just set the interrupt line based on ISTATUS +*/ +int irqstate = (oldval &4 ) && !(value &2 ); + +trace_arm_gt_imask_toggle (timeridx, irqstate); +qemu_set_irq (cpu->gt_timer_outputs[timeridx], irqstate); + } +} + +static void gt_phys_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +gt_timer_reset (env, ri,GTIMER_PHYS ); +} + +static void gt_phys_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_cval_write (env, ri,GTIMER_PHYS , value); +} + +static uint64_t gt_phys_tval_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_tval_read (env, ri,GTIMER_PHYS ); +} + +static void gt_phys_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_tval_write (env, ri,GTIMER_PHYS , value); +} + +static void gt_phys_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_ctl_write (env, ri,GTIMER_PHYS , value); +} + +static int gt_phys_redir_timeridx (CPUARMState *env) +{ +switch (arm_mmu_idx (env)) { +case ARMMMUIdx_E20_0: +case ARMMMUIdx_E20_2: +case ARMMMUIdx_E20_2_PAN: +return GTIMER_HYP ; +default : +return GTIMER_PHYS ; + } +} + +static int gt_virt_redir_timeridx (CPUARMState *env) +{ +switch (arm_mmu_idx (env)) { +case ARMMMUIdx_E20_0: +case ARMMMUIdx_E20_2: +case ARMMMUIdx_E20_2_PAN: +return GTIMER_HYPVIRT ; +default : +return GTIMER_VIRT ; + } +} + +static uint64_t gt_phys_redir_cval_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_phys_redir_timeridx (env); +return env->cp15.c14_timer[timeridx].cval; +} + +static void gt_phys_redir_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_phys_redir_timeridx (env); +gt_cval_write (env, ri, timeridx, value); +} + +static uint64_t gt_phys_redir_tval_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_phys_redir_timeridx (env); +return gt_tval_read (env, ri, timeridx); +} + +static void gt_phys_redir_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_phys_redir_timeridx (env); +gt_tval_write (env, ri, timeridx, value); +} + +static uint64_t gt_phys_redir_ctl_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_phys_redir_timeridx (env); +return env->cp15.c14_timer[timeridx].ctl; +} + +static void gt_phys_redir_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_phys_redir_timeridx (env); +gt_ctl_write (env, ri, timeridx, value); +} + +static void gt_virt_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +gt_timer_reset (env, ri,GTIMER_VIRT ); +} + +static void gt_virt_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_cval_write (env, ri,GTIMER_VIRT , value); +} + +static uint64_t gt_virt_tval_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_tval_read (env, ri,GTIMER_VIRT ); +} + +static void gt_virt_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_tval_write (env, ri,GTIMER_VIRT , value); +} + +static void gt_virt_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_ctl_write (env, ri,GTIMER_VIRT , value); +} + +static void gt_cntvoff_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); + +trace_arm_gt_cntvoff_write (value); +raw_write (env, ri, value); +gt_recalc_timer (cpu,GTIMER_VIRT ); +} + +static uint64_t gt_virt_redir_cval_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_virt_redir_timeridx (env); +return env->cp15.c14_timer[timeridx].cval; +} + +static void gt_virt_redir_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_virt_redir_timeridx (env); +gt_cval_write (env, ri, timeridx, value); +} + +static uint64_t gt_virt_redir_tval_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_virt_redir_timeridx (env); +return gt_tval_read (env, ri, timeridx); +} + +static void gt_virt_redir_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_virt_redir_timeridx (env); +gt_tval_write (env, ri, timeridx, value); +} + +static uint64_t gt_virt_redir_ctl_read (CPUARMState *env, +const ARMCPRegInfo *ri) +{ +int timeridx =gt_virt_redir_timeridx (env); +return env->cp15.c14_timer[timeridx].ctl; +} + +static void gt_virt_redir_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +int timeridx =gt_virt_redir_timeridx (env); +gt_ctl_write (env, ri, timeridx, value); +} + +static void gt_hyp_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +gt_timer_reset (env, ri,GTIMER_HYP ); +} + +static void gt_hyp_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_cval_write (env, ri,GTIMER_HYP , value); +} + +static uint64_t gt_hyp_tval_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_tval_read (env, ri,GTIMER_HYP ); +} + +static void gt_hyp_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_tval_write (env, ri,GTIMER_HYP , value); +} + +static void gt_hyp_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_ctl_write (env, ri,GTIMER_HYP , value); +} + +static void gt_sec_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +gt_timer_reset (env, ri,GTIMER_SEC ); +} + +static void gt_sec_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_cval_write (env, ri,GTIMER_SEC , value); +} + +static uint64_t gt_sec_tval_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_tval_read (env, ri,GTIMER_SEC ); +} + +static void gt_sec_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_tval_write (env, ri,GTIMER_SEC , value); +} + +static void gt_sec_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_ctl_write (env, ri,GTIMER_SEC , value); +} + +static void gt_hv_timer_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +gt_timer_reset (env, ri,GTIMER_HYPVIRT ); +} + +static void gt_hv_cval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_cval_write (env, ri,GTIMER_HYPVIRT , value); +} + +static uint64_t gt_hv_tval_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return gt_tval_read (env, ri,GTIMER_HYPVIRT ); +} + +static void gt_hv_tval_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_tval_write (env, ri,GTIMER_HYPVIRT , value); +} + +static void gt_hv_ctl_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +gt_ctl_write (env, ri,GTIMER_HYPVIRT , value); +} + +void arm_gt_ptimer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +gt_recalc_timer (cpu,GTIMER_PHYS ); +} + +void arm_gt_vtimer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +gt_recalc_timer (cpu,GTIMER_VIRT ); +} + +void arm_gt_htimer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +gt_recalc_timer (cpu,GTIMER_HYP ); +} + +void arm_gt_stimer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +gt_recalc_timer (cpu,GTIMER_SEC ); +} + +void arm_gt_hvtimer_cb (void *opaque) +{ +ARMCPU *cpu = opaque; + +gt_recalc_timer (cpu,GTIMER_HYPVIRT ); +} + +static void arm_gt_cntfrq_reset (CPUARMState *env,const ARMCPRegInfo *opaque)
Lines of this file are not shown. View the raw message.
target/arm/helper.c +0 -9067
9,067 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.35.3
Part of the diff is not shown here. View the raw message.
Re: [RFC PATCH v2 05/19] target/arm: Move cpregs code into cpregs.c
Quoted 6 lines · Fabiano Rosas
target/arm/cpu.c | 1 + target/arm/machine.c | 1 + target/arm/meson.build | 1 + target/arm/op_helper.c | 1 + target/arm/translate-a64.c | 1 + target/arm/translate.c | 1 +
These additions of #include "cpregs.h" are unrelated to the code movement.
Otherwise,
r~
RFC PATCH v2 6/19 target/arm: Move define_debug_regs() to cpregs.c
In reply to Fabiano RosasThe debug_helper.c file will move into a tcg-specific directory, so take the cpregs code out of it. That code needs to be present in KVM builds as well.
--- target/arm/cpregs.c | 383 ++++++++++++++++++++++++++++++++++++++ target/arm/cpu.c | 7 +- target/arm/debug_helper.c | 367 ------------------------------------ target/arm/internals.h | 9 - target/arm/machine.c | 6 +- 5 files changed, 392 insertions(+), 380 deletions(-)
target/arm/cpregs.c +383 -0
@@ -287,6 +287,74 @@ static CPAccessResult access_trap_aa32s_el1(CPUARMState *env,return CP_ACCESS_TRAP_UNCATEGORIZED ; } +static uint64_t arm_mdcr_el2_eff (CPUARMState *env) +{ +return arm_is_el2_enabled (env) ? env->cp15.mdcr_el2 :0 ; +} + +/* +* Check for traps to "powerdown debug" registers, which are controlled +* by MDCR.TDOSA +*/ +static CPAccessResult access_tdosa (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); +bool mdcr_el2_tdosa = (mdcr_el2 &MDCR_TDOSA ) || (mdcr_el2 &MDCR_TDE ) || + (arm_hcr_el2_eff (env) &HCR_TGE ); + +if (el <2 && mdcr_el2_tdosa) { +return CP_ACCESS_TRAP_EL2 ; + } +if (el <3 && (env->cp15.mdcr_el3 &MDCR_TDOSA )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} + +/* +* Check for traps to "debug ROM" registers, which are controlled +* by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3. +*/ +static CPAccessResult access_tdra (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); +bool mdcr_el2_tdra = (mdcr_el2 &MDCR_TDRA ) || (mdcr_el2 &MDCR_TDE ) || + (arm_hcr_el2_eff (env) &HCR_TGE ); + +if (el <2 && mdcr_el2_tdra) { +return CP_ACCESS_TRAP_EL2 ; + } +if (el <3 && (env->cp15.mdcr_el3 &MDCR_TDA )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} + +/* +* Check for traps to general debug registers, which are controlled +* by MDCR_EL2.TDA for EL2 and MDCR_EL3.TDA for EL3. +*/ +static CPAccessResult access_tda (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +int el =arm_current_el (env); +uint64_t mdcr_el2 =arm_mdcr_el2_eff (env); +bool mdcr_el2_tda = (mdcr_el2 &MDCR_TDA ) || (mdcr_el2 &MDCR_TDE ) || + (arm_hcr_el2_eff (env) &HCR_TGE ); + +if (el <2 && mdcr_el2_tda) { +return CP_ACCESS_TRAP_EL2 ; + } +if (el <3 && (env->cp15.mdcr_el3 &MDCR_TDA )) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} +/* * Check for traps to performance monitor registers, which are controlled * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
@@ -6286,6 +6354,132 @@ static CPAccessResult ctr_el0_access(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +static void oslar_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* +* Writes to OSLAR_EL1 may update the OS lock status, which can be +* read via a bit in OSLSR_EL1. +*/ +int oslock; + +if (ri->state ==ARM_CP_STATE_AA32 ) { + oslock = (value ==0xC5ACCE55 ); + }else { + oslock = value &1 ; + } + + env->cp15.oslsr_el1 =deposit32 (env->cp15.oslsr_el1,1 ,1 , oslock); +} + +static void osdlr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +/* +* Only defined bit is bit 0 (DLK); if Feat_DoubleLock is not +* implemented this is RAZ/WI. +*/ +if (arm_feature (env,ARM_FEATURE_AARCH64 ) + ?cpu_isar_feature (aa64_doublelock, cpu) + :cpu_isar_feature (aa32_doublelock, cpu)) { + env->cp15.osdlr_el1 = value &1 ; + } +} + +static const ARMCPRegInfo debug_cp_reginfo[] = { +/* +* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped +* debug components. The AArch64 version of DBGDRAR is named MDRAR_EL1; +* unlike DBGDRAR it is never accessible from EL0. +* DBGDSAR is deprecated and must RAZ from v8 anyway, so it has no AArch64 +* accessor. +*/ + { .name ="DBGDRAR" , .cp =14 , .crn =1 , .crm =0 , .opc1 =0 , .opc2 =0 , + .access =PL0_R , .accessfn = access_tdra, + .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="MDRAR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =2 , .opc1 =0 , .crn =1 , .crm =0 , .opc2 =0 , + .access =PL1_R , .accessfn = access_tdra, + .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="DBGDSAR" , .cp =14 , .crn =2 , .crm =0 , .opc1 =0 , .opc2 =0 , + .access =PL0_R , .accessfn = access_tdra, + .type =ARM_CP_CONST , .resetvalue =0 }, +/* Monitor debug system control register; the 32-bit alias is DBGDSCRext. */ + { .name ="MDSCR_EL1" , .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm =2 , .opc2 =2 , + .access =PL1_RW , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1), + .resetvalue =0 }, +/* +* MDCCSR_EL0[30:29] map to EDSCR[30:29]. Simply RAZ as the external +* Debug Communication Channel is not implemented. +*/ + { .name ="MDCCSR_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =2 , .opc1 =3 , .crn =0 , .crm =1 , .opc2 =0 , + .access =PL0_R , .accessfn = access_tda, + .type =ARM_CP_CONST , .resetvalue =0 }, +/* +* DBGDSCRint[15,12,5:2] map to MDSCR_EL1[15,12,5:2]. Map all bits as +* it is unlikely a guest will care. +* We don't implement the configurable EL0 access. +*/ + { .name ="DBGDSCRint" , .state =ARM_CP_STATE_AA32 , + .cp =14 , .opc1 =0 , .crn =0 , .crm =1 , .opc2 =0 , + .type =ARM_CP_ALIAS , + .access =PL1_R , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.mdscr_el1), }, + { .name ="OSLAR_EL1" , .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =1 , .crm =0 , .opc2 =4 , + .access =PL1_W , .type =ARM_CP_NO_RAW , + .accessfn = access_tdosa, + .writefn = oslar_write }, + { .name ="OSLSR_EL1" , .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =1 , .crm =1 , .opc2 =4 , + .access =PL1_R , .resetvalue =10 , + .accessfn = access_tdosa, + .fieldoffset = offsetof(CPUARMState, cp15.oslsr_el1) }, +/* Dummy OSDLR_EL1: 32-bit Linux will read this */ + { .name ="OSDLR_EL1" , .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =1 , .crm =3 , .opc2 =4 , + .access =PL1_RW , .accessfn = access_tdosa, + .writefn = osdlr_write, + .fieldoffset = offsetof(CPUARMState, cp15.osdlr_el1) }, +/* +* Dummy DBGVCR: Linux wants to clear this on startup, but we don't +* implement vector catch debug events yet. +*/ + { .name ="DBGVCR" , + .cp =14 , .opc1 =0 , .crn =0 , .crm =7 , .opc2 =0 , + .access =PL1_RW , .accessfn = access_tda, + .type =ARM_CP_NOP }, +/* +* Dummy DBGVCR32_EL2 (which is only for a 64-bit hypervisor +* to save and restore a 32-bit guest's DBGVCR) +*/ + { .name ="DBGVCR32_EL2" , .state =ARM_CP_STATE_AA64 , + .opc0 =2 , .opc1 =4 , .crn =0 , .crm =7 , .opc2 =0 , + .access =PL2_RW , .accessfn = access_tda, + .type =ARM_CP_NOP |ARM_CP_EL3_NO_EL2_KEEP }, +/* +* Dummy MDCCINT_EL1, since we don't implement the Debug Communications +* Channel but Linux may try to access this register. The 32-bit +* alias is DBGDCCINT. +*/ + { .name ="MDCCINT_EL1" , .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm =2 , .opc2 =0 , + .access =PL1_RW , .accessfn = access_tda, + .type =ARM_CP_NOP }, +}; + +static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { +/* 64 bit access versions of the (dummy) debug registers */ + { .name ="DBGDRAR" , .cp =14 , .crm =1 , .opc1 =0 , + .access =PL0_R , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, + { .name ="DBGDSAR" , .cp =14 , .crm =2 , .opc1 =0 , + .access =PL0_R , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, +}; +/* * Check for traps to RAS registers, which are controlled * by HCR_EL2.TERR and SCR_EL3.TERR.
@@ -6520,6 +6714,195 @@ static const ARMCPRegInfo sme_reginfo[] = { };#endif /* TARGET_AARCH64 */ +static void dbgwvr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +int i = ri->crm; + +/* +* Bits [1:0] are RES0. +* +* It is IMPLEMENTATION DEFINED whether [63:49] ([63:53] with FEAT_LVA) +* are hardwired to the value of bit [48] ([52] with FEAT_LVA), or if +* they contain the value written. It is CONSTRAINED UNPREDICTABLE +* whether the RESS bits are ignored when comparing an address. +* +* Therefore we are allowed to compare the entire register, which lets +* us avoid considering whether or not FEAT_LVA is actually enabled. +*/ + value &= ~3ULL ; + +raw_write (env, ri, value); + +if (tcg_enabled ()) { +hw_watchpoint_update (cpu, i); + } +} + +static void dbgwcr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +int i = ri->crm; + +raw_write (env, ri, value); + +if (tcg_enabled ()) { +hw_watchpoint_update (cpu, i); + } +} + +static void dbgbvr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +int i = ri->crm; + +raw_write (env, ri, value); + +if (tcg_enabled ()) { +hw_breakpoint_update (cpu, i); + } +} + +static void dbgbcr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =env_archcpu (env); +int i = ri->crm; + +/* +* BAS[3] is a read-only copy of BAS[2], and BAS[1] a read-only +* copy of BAS[0]. +*/ + value =deposit64 (value,6 ,1 ,extract64 (value,5 ,1 )); + value =deposit64 (value,8 ,1 ,extract64 (value,7 ,1 )); + +raw_write (env, ri, value); + +if (tcg_enabled ()) { +hw_breakpoint_update (cpu, i); + } +} + +static void define_debug_regs (ARMCPU *cpu) +{ +/* +* Define v7 and v8 architectural debug registers. +* These are just dummy implementations for now. +*/ +int i; +int wrps, brps, ctx_cmps; + +/* +* The Arm ARM says DBGDIDR is optional and deprecated if EL1 cannot +* use AArch32. Given that bit 15 is RES1, if the value is 0 then +* the register must not exist for this cpu. +*/ +if (cpu->isar.dbgdidr !=0 ) { +ARMCPRegInfo dbgdidr = { + .name ="DBGDIDR" , .cp =14 , .crn =0 , .crm =0 , + .opc1 =0 , .opc2 =0 , + .access =PL0_R , .accessfn = access_tda, + .type =ARM_CP_CONST , .resetvalue = cpu->isar.dbgdidr, + }; +define_one_arm_cp_reg (cpu, &dbgdidr); + } + +/* +* DBGDEVID is present in the v7 debug architecture if +* DBGDIDR.DEVID_imp is 1 (bit 15); from v7.1 and on it is +* mandatory (and bit 15 is RES1). DBGDEVID1 and DBGDEVID2 exist +* from v7.1 of the debug architecture. Because no fields have yet +* been defined in DBGDEVID2 (and quite possibly none will ever +* be) we don't define an ARMISARegisters field for it. +* These registers exist only if EL1 can use AArch32, but that +* happens naturally because they are only PL1 accessible anyway. +*/ +if (extract32 (cpu->isar.dbgdidr,15 ,1 )) { +ARMCPRegInfo dbgdevid = { + .name ="DBGDEVID" , + .cp =14 , .opc1 =0 , .crn =7 , .opc2 =2 , .crn =7 , + .access =PL1_R , .accessfn = access_tda, + .type =ARM_CP_CONST , .resetvalue = cpu->isar.dbgdevid, + }; +define_one_arm_cp_reg (cpu, &dbgdevid); + } +if (cpu_isar_feature (aa32_debugv7p1, cpu)) { +ARMCPRegInfo dbgdevid12[] = { + { + .name ="DBGDEVID1" , + .cp =14 , .opc1 =0 , .crn =7 , .opc2 =1 , .crn =7 , + .access =PL1_R , .accessfn = access_tda, + .type =ARM_CP_CONST , .resetvalue = cpu->isar.dbgdevid1, + }, { + .name ="DBGDEVID2" , + .cp =14 , .opc1 =0 , .crn =7 , .opc2 =0 , .crn =7 , + .access =PL1_R , .accessfn = access_tda, + .type =ARM_CP_CONST , .resetvalue =0 , + }, + }; +define_arm_cp_regs (cpu, dbgdevid12); + } + + brps =arm_num_brps (cpu); + wrps =arm_num_wrps (cpu); + ctx_cmps =arm_num_ctx_cmps (cpu); + +assert (ctx_cmps <= brps); + +define_arm_cp_regs (cpu, debug_cp_reginfo); + +if (arm_feature (&cpu->env,ARM_FEATURE_LPAE )) { +define_arm_cp_regs (cpu, debug_lpae_cp_reginfo); + } + +for (i =0 ; i < brps; i++) { +char *dbgbvr_el1_name =g_strdup_printf ("DBGBVR%d_EL1" , i); +char *dbgbcr_el1_name =g_strdup_printf ("DBGBCR%d_EL1" , i); +ARMCPRegInfo dbgregs[] = { + { .name = dbgbvr_el1_name, .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm = i, .opc2 =4 , + .access =PL1_RW , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.dbgbvr[i]), + .writefn = dbgbvr_write, .raw_writefn = raw_write + }, + { .name = dbgbcr_el1_name, .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm = i, .opc2 =5 , + .access =PL1_RW , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.dbgbcr[i]), + .writefn = dbgbcr_write, .raw_writefn = raw_write + }, + }; +define_arm_cp_regs (cpu, dbgregs); +g_free (dbgbvr_el1_name); +g_free (dbgbcr_el1_name); + } + +for (i =0 ; i < wrps; i++) { +char *dbgwvr_el1_name =g_strdup_printf ("DBGWVR%d_EL1" , i); +char *dbgwcr_el1_name =g_strdup_printf ("DBGWCR%d_EL1" , i); +ARMCPRegInfo dbgregs[] = { + { .name = dbgwvr_el1_name, .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm = i, .opc2 =6 , + .access =PL1_RW , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.dbgwvr[i]), + .writefn = dbgwvr_write, .raw_writefn = raw_write + }, + { .name = dbgwcr_el1_name, .state =ARM_CP_STATE_BOTH , + .cp =14 , .opc0 =2 , .opc1 =0 , .crn =0 , .crm = i, .opc2 =7 , + .access =PL1_RW , .accessfn = access_tda, + .fieldoffset = offsetof(CPUARMState, cp15.dbgwcr[i]), + .writefn = dbgwcr_write, .raw_writefn = raw_write + }, + }; +define_arm_cp_regs (cpu, dbgregs); +g_free (dbgwvr_el1_name); +g_free (dbgwcr_el1_name); + } +} +static void define_pmu_regs (ARMCPU *cpu) {/*
target/arm/cpu.c +5 -2
@@ -537,8 +537,11 @@ static void arm_cpu_reset_hold(Object *obj) }#endif -hw_breakpoint_update_all (cpu); -hw_watchpoint_update_all (cpu); +if (tcg_enabled ()) { +hw_breakpoint_update_all (cpu); +hw_watchpoint_update_all (cpu); + } +arm_rebuild_hflags (env); }
target/arm/debug_helper.c +0 -367
391 lines not on this page · raw message
target/arm/internals.h +0 -9
@@ -1363,15 +1363,6 @@ int exception_target_el(CPUARMState *env);bool arm_singlestep_active (CPUARMState *env);bool arm_generate_debug_exceptions (CPUARMState *env); -/* Add the cpreg definitions for debug related system registers */ -void define_debug_regs (ARMCPU *cpu); - -/* Effective value of MDCR_EL2 */ -static inline uint64_t arm_mdcr_el2_eff (CPUARMState *env) -{ -return arm_is_el2_enabled (env) ? env->cp15.mdcr_el2 :0 ; -} -/* Powers of 2 for sve_vq_map et al. */ #define SVE_VQ_POW2_MAP \ ((1 << (1 - 1)) | (1 << (2 - 1)) | \
target/arm/machine.c +4 -2
@@ -849,8 +849,10 @@ static int cpu_post_load(void *opaque, int version_id)return -1 ; } -hw_breakpoint_update_all (cpu); -hw_watchpoint_update_all (cpu); +if (tcg_enabled ()) { +hw_breakpoint_update_all (cpu); +hw_watchpoint_update_all (cpu); + }/* * TCG gen_update_fp_context() relies on the invariant that
Signature · 1 line
2.35.3
Re: [RFC PATCH v2 06/19] target/arm: Move define_debug_regs() to cpregs.c
target/arm/cpu.c static void arm_cpu_reset_hold(Object *obj) · line 543
Quoted 7 lines · Fabiano Rosas
target/arm/cpu.c +4
-2-hw_breakpoint_update_all (cpu); -hw_watchpoint_update_all (cpu); +if (tcg_enabled ()) { +hw_breakpoint_update_all (cpu); +hw_watchpoint_update_all (cpu); + }
This and the other tcg_enabled() addition don't belong with code movement.
Otherwise,
r~
RFC PATCH v2 7/19 target/arm: Move helper_set_pstate_* into cpregs.c
In reply to Fabiano RosasWe want to move sme_helper into the tcg directory, but the cpregs accessor functions cannot go along, otherwise they would be separate from the respective ARMCPRegInfo definition which needs to be compiled with CONFIG_TCG=n as well.
--- target/arm/cpregs.c | 29 +++++++++++++++++++++++++++++ target/arm/sme_helper.c | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-)
target/arm/cpregs.c +29 -0
@@ -6633,6 +6633,35 @@ static CPAccessResult access_esm(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +void helper_set_pstate_sm (CPUARMState *env,uint32_t i) +{ +if (i ==FIELD_EX64 (env->svcr,SVCR ,SM )) { +return ; + } + env->svcr ^=R_SVCR_SM_MASK ; +arm_reset_sve_state (env); +} + +void helper_set_pstate_za (CPUARMState *env,uint32_t i) +{ +if (i ==FIELD_EX64 (env->svcr,SVCR ,ZA )) { +return ; + } + env->svcr ^=R_SVCR_ZA_MASK ; + +/* +* ResetSMEState. +* +* SetPSTATE_ZA zeros on enable and disable. We can zero this only +* on enable: while disabled, the storage is inaccessible and the +* value does not matter. We're not saving the storage in vmstate +* when disabled either. +*/ +if (i) { +memset (env->zarray,0 ,sizeof (env->zarray)); + } +} +static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {
target/arm/sme_helper.c +0 -29
@@ -38,35 +38,6 @@ void arm_reset_sve_state(CPUARMState *env)vfp_set_fpcr (env,0x0800009f ); } -void helper_set_pstate_sm (CPUARMState *env,uint32_t i) -{ -if (i ==FIELD_EX64 (env->svcr,SVCR ,SM )) { -return ; - } - env->svcr ^=R_SVCR_SM_MASK ; -arm_reset_sve_state (env); -} - -void helper_set_pstate_za (CPUARMState *env,uint32_t i) -{ -if (i ==FIELD_EX64 (env->svcr,SVCR ,ZA )) { -return ; - } - env->svcr ^=R_SVCR_ZA_MASK ; - -/* -* ResetSMEState. -* -* SetPSTATE_ZA zeros on enable and disable. We can zero this only -* on enable: while disabled, the storage is inaccessible and the -* value does not matter. We're not saving the storage in vmstate -* when disabled either. -*/ -if (i) { -memset (env->zarray,0 ,sizeof (env->zarray)); - } -} -void helper_sme_zero (CPUARMState *env,uint32_t imm,uint32_t svl) {uint32_t i;
Signature · 1 line
2.35.3
Re: [RFC PATCH v2 07/19] target/arm: Move helper_set_pstate_* into cpregs.c
Quoted 4 lines · Fabiano Rosas
We want to move
sme_helperinto the tcg directory, but the cpregs accessor functions cannot go along, otherwise they would be separate from the respective ARMCPRegInfo definition which needs to be compiled withCONFIG_TCG=nas well.
Hmm. I would have hoped these could stay tcg-only, somehow.
I wonder if it warrants being an ARM_CP_SPECIAL_MASK value instead of svcr_write.
r~
Re: [RFC PATCH v2 07/19] target/arm: Move helper_set_pstate_* into cpregs.c
Quoted 8 lines · Richard Henderson
Quoted 4 lines · Fabiano Rosas
We want to move
sme_helperinto the tcg directory, but the cpregs accessor functions cannot go along, otherwise they would be separate from the respective ARMCPRegInfo definition which needs to be compiled withCONFIG_TCG=nas well.Hmm. I would have hoped these could stay tcg-only, somehow.
I wonder if it warrants being anARM_CP_SPECIAL_MASKvalue instead ofsvcr_write.
In general, what characterizes as "special" for a register to use ARM_CP_SPECIAL_MASK?
And specifically for svcr_write, it seems to me that helper_set_pstate_{sm,za} and arm_reset_sve_state are straight-forward enough that they could (if it made sense) be used by non-tcg code (except they eventually call vfp_set_fpscr that still needs to be split).
Quoted 3 lines
r~
Re: [RFC PATCH v2 07/19] target/arm: Move helper_set_pstate_* into cpregs.c
Quoted 9 lines · Fabiano Rosas
Quoted 6 lines · Richard Henderson
Quoted 4 lines · Fabiano Rosas
We want to move
sme_helperinto the tcg directory, but the cpregs accessor functions cannot go along, otherwise they would be separate from the respective ARMCPRegInfo definition which needs to be compiled withCONFIG_TCG=nas well.
Quoted 5 lines
Quoted 2 lines
Hmm. I would have hoped these could stay tcg-only, somehow.
I wonder if it warrants being anARM_CP_SPECIAL_MASKvalue instead ofsvcr_write.In general, what characterizes as "special" for a register to use
ARM_CP_SPECIAL_MASK?
It means that the register has special-case handling code in the translate.c/translate-a64.c TCG codegen functions. Non-special registers can be handled all in the same way (load a constant, read a field from the CPU state struct, or call a read/write function); the special cases directly emit code to handle whatever they are doing. See the switch commented "Handle special cases first" in target/arm/translate-a64.c function handle_sys().
-- PMM
Re: [RFC PATCH v2 07/19] target/arm: Move helper_set_pstate_* into cpregs.c
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
Quoted 4 lines · Fabiano Rosas
We want to move
sme_helperinto the tcg directory, but the cpregs accessor functions cannot go along, otherwise they would be separate from the respective ARMCPRegInfo definition which needs to be compiled withCONFIG_TCG=nas well.Hmm. I would have hoped these could stay tcg-only, somehow.
I wonder if it warrants being anARM_CP_SPECIAL_MASKvalue instead ofsvcr_write.
To answer my own question, ARM_CP_SPECIAL_MASK forces NO_RAW, which is not what we want for migration.
I'll think of something better here though.
r~
RFC PATCH v2 8/19 target/arm: move translate modules to tcg/
In reply to Fabiano RosasIntroduce the target/arm/tcg directory. Its purpose is to hold the TCG code that is selected by CONFIG_TCG.
---
I also moved translate-{m-nocp,mve,neon,vfp,sme}.c
Originally from:
https://lore.kernel.org/r/[email protected]
[RFC v14 01/80] target/arm: move translate modules to tcg/
---
MAINTAINERS | 1 +
target/arm/meson.build | 30 ++++-------------------
target/arm/{ => tcg}/a32-uncond.decode | 0
target/arm/{ => tcg}/a32.decode | 0
target/arm/{ => tcg}/m-nocp.decode | 0
target/arm/tcg/meson.build | 32 +++++++++++++++++++++++++
target/arm/{ => tcg}/mve.decode | 0
target/arm/{ => tcg}/neon-dp.decode | 0
target/arm/{ => tcg}/neon-ls.decode | 0
target/arm/{ => tcg}/neon-shared.decode | 0
target/arm/{ => tcg}/sme-fa64.decode | 0
target/arm/{ => tcg}/sme.decode | 0
target/arm/{ => tcg}/sve.decode | 0
target/arm/{ => tcg}/t16.decode | 0
target/arm/{ => tcg}/t32.decode | 0
target/arm/{ => tcg}/translate-a64.c | 0
target/arm/{ => tcg}/translate-a64.h | 0
target/arm/{ => tcg}/translate-m-nocp.c | 0
target/arm/{ => tcg}/translate-mve.c | 0
target/arm/{ => tcg}/translate-neon.c | 0
target/arm/{ => tcg}/translate-sme.c | 0
target/arm/{ => tcg}/translate-sve.c | 0
target/arm/{ => tcg}/translate-vfp.c | 0
target/arm/{ => tcg}/translate.c | 0
target/arm/{ => tcg}/translate.h | 0
target/arm/{ => tcg}/vfp-uncond.decode | 0
target/arm/{ => tcg}/vfp.decode | 0
27 files changed, 37 insertions(+), 26 deletions(-)
rename target/arm/{ => tcg}/a32-uncond.decode (100%)
rename target/arm/{ => tcg}/a32.decode (100%)
rename target/arm/{ => tcg}/m-nocp.decode (100%)
create mode 100644 target/arm/tcg/meson.build
rename target/arm/{ => tcg}/mve.decode (100%)
rename target/arm/{ => tcg}/neon-dp.decode (100%)
rename target/arm/{ => tcg}/neon-ls.decode (100%)
rename target/arm/{ => tcg}/neon-shared.decode (100%)
rename target/arm/{ => tcg}/sme-fa64.decode (100%)
rename target/arm/{ => tcg}/sme.decode (100%)
rename target/arm/{ => tcg}/sve.decode (100%)
rename target/arm/{ => tcg}/t16.decode (100%)
rename target/arm/{ => tcg}/t32.decode (100%)
rename target/arm/{ => tcg}/translate-a64.c (100%)
rename target/arm/{ => tcg}/translate-a64.h (100%)
rename target/arm/{ => tcg}/translate-m-nocp.c (100%)
rename target/arm/{ => tcg}/translate-mve.c (100%)
rename target/arm/{ => tcg}/translate-neon.c (100%)
rename target/arm/{ => tcg}/translate-sme.c (100%)
rename target/arm/{ => tcg}/translate-sve.c (100%)
rename target/arm/{ => tcg}/translate-vfp.c (100%)
rename target/arm/{ => tcg}/translate.c (100%)
rename target/arm/{ => tcg}/translate.h (100%)
rename target/arm/{ => tcg}/vfp-uncond.decode (100%)
rename target/arm/{ => tcg}/vfp.decode (100%)MAINTAINERS +1 -0
@@ -159,6 +159,7 @@ M: Peter Maydell <[email protected]> L: [email protected] S: Maintained F: target/arm/ +F: target/arm/tcg/ F: tests/tcg/arm/ F: tests/tcg/aarch64/ F: tests/qtest/arm-cpu-features.c
target/arm/meson.build +4 -26
@@ -1,22 +1,4 @@ -gen = [ - decodetree.process('sve.decode', extra_args: '--decode=disas_sve'), - decodetree.process('sme.decode', extra_args: '--decode=disas_sme'), - decodetree.process('sme-fa64.decode', extra_args: '--static-decode=disas_sme_fa64'), - decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'), - decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'), - decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'), - decodetree.process('vfp.decode', extra_args: '--decode=disas_vfp'), - decodetree.process('vfp-uncond.decode', extra_args: '--decode=disas_vfp_uncond'), - decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'), - decodetree.process('mve.decode', extra_args: '--decode=disas_mve'), - decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'), - decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'), - decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'), - decodetree.process('t16.decode', extra_args: ['-w', '16', '--static-decode=disas_t16']), -] - arm_ss = ss.source_set() -arm_ss.add(gen) arm_ss.add(files( 'cpregs.c', 'cpu.c',
@@ -30,11 +12,6 @@ arm_ss.add(files( 'neon_helper.c', 'op_helper.c', 'tlb_helper.c', - 'translate.c', - 'translate-m-nocp.c', - 'translate-mve.c', - 'translate-neon.c', - 'translate-vfp.c', 'vec_helper.c', 'vfp_helper.c', 'cpu_tcg.c',
@@ -51,9 +28,6 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'pauth_helper.c', 'sve_helper.c', 'sme_helper.c', - 'translate-a64.c', - 'translate-sve.c', - 'translate-sme.c', )) arm_softmmu_ss = ss.source_set()
@@ -68,5 +42,9 @@ arm_softmmu_ss.add(files( subdir('hvf') +if 'CONFIG_TCG' in config_all + subdir('tcg') +endif + target_arch += {'arm': arm_ss} target_softmmu_arch += {'arm': arm_softmmu_ss}
target/arm/tcg/a32-uncond.decode renamed from target/arm/a32-uncond.decode +0 -0
target/arm/tcg/a32.decode renamed from target/arm/a32.decode +0 -0
target/arm/tcg/m-nocp.decode renamed from target/arm/m-nocp.decode +0 -0
target/arm/tcg/meson.build new file +32 -0
@@ -0,0 +1,32 @@ +gen = [ + decodetree.process('sve.decode', extra_args: '--decode=disas_sve'), + decodetree.process('sme.decode', extra_args: '--decode=disas_sme'), + decodetree.process('sme-fa64.decode', extra_args: '--static-decode=disas_sme_fa64'), + decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'), + decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'), + decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'), + decodetree.process('vfp.decode', extra_args: '--decode=disas_vfp'), + decodetree.process('vfp-uncond.decode', extra_args: '--decode=disas_vfp_uncond'), + decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'), + decodetree.process('mve.decode', extra_args: '--decode=disas_mve'), + decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'), + decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'), + decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'), + decodetree.process('t16.decode', extra_args: ['-w', '16', '--static-decode=disas_t16']), +] + +arm_ss.add(gen) + +arm_ss.add(files( + 'translate.c', + 'translate-m-nocp.c', + 'translate-mve.c', + 'translate-neon.c', + 'translate-vfp.c', +)) + +arm_ss.add(when: 'TARGET_AARCH64', if_true: files( + 'translate-a64.c', + 'translate-sve.c', + 'translate-sme.c', +))
target/arm/tcg/mve.decode renamed from target/arm/mve.decode +0 -0
target/arm/tcg/neon-dp.decode renamed from target/arm/neon-dp.decode +0 -0
target/arm/tcg/neon-ls.decode renamed from target/arm/neon-ls.decode +0 -0
target/arm/tcg/neon-shared.decode renamed from target/arm/neon-shared.decode +0 -0
target/arm/tcg/sme-fa64.decode renamed from target/arm/sme-fa64.decode +0 -0
target/arm/tcg/sme.decode renamed from target/arm/sme.decode +0 -0
target/arm/tcg/sve.decode renamed from target/arm/sve.decode +0 -0
target/arm/tcg/t16.decode renamed from target/arm/t16.decode +0 -0
target/arm/tcg/t32.decode renamed from target/arm/t32.decode +0 -0
target/arm/tcg/translate-a64.c renamed from target/arm/translate-a64.c +0 -0
target/arm/tcg/translate-a64.h renamed from target/arm/translate-a64.h +0 -0
target/arm/tcg/translate-m-nocp.c renamed from target/arm/translate-m-nocp.c +0 -0
target/arm/tcg/translate-mve.c renamed from target/arm/translate-mve.c +0 -0
target/arm/tcg/translate-neon.c renamed from target/arm/translate-neon.c +0 -0
target/arm/tcg/translate-sme.c renamed from target/arm/translate-sme.c +0 -0
target/arm/tcg/translate-sve.c renamed from target/arm/translate-sve.c +0 -0
target/arm/tcg/translate-vfp.c renamed from target/arm/translate-vfp.c +0 -0
target/arm/tcg/translate.c renamed from target/arm/translate.c +0 -0
target/arm/tcg/translate.h renamed from target/arm/translate.h +0 -0
target/arm/tcg/vfp-uncond.decode renamed from target/arm/vfp-uncond.decode +0 -0
target/arm/tcg/vfp.decode renamed from target/arm/vfp.decode +0 -0
Signature · 1 line
2.35.3
RFC PATCH v2 9/19 target/arm: move helpers to tcg/
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
---
Included {sme,mve}_helper.c and left a couple of files behind that still have non-tcg code to be removed from them:
helper.c (and op_helper.h as a dep)vfp_helper.c
Originally from:
https://lore.kernel.org/r/[email protected]
[RFC v14 02/80] target/arm: move helpers to tcg/
---
target/arm/meson.build | 16 ++--------------
target/arm/tcg-stubs.c | 28 ++++++++++++++++++++++++++++
target/arm/{ => tcg}/crypto_helper.c | 0
target/arm/{ => tcg}/debug_helper.c | 0
target/arm/{ => tcg}/helper-a64.c | 0
target/arm/{ => tcg}/iwmmxt_helper.c | 0
target/arm/{ => tcg}/m_helper.c | 0
target/arm/tcg/meson.build | 14 ++++++++++++++
target/arm/{ => tcg}/mte_helper.c | 0
target/arm/{ => tcg}/mve_helper.c | 0
target/arm/{ => tcg}/neon_helper.c | 0
target/arm/{ => tcg}/op_helper.c | 0
target/arm/{ => tcg}/pauth_helper.c | 0
target/arm/{ => tcg}/sme_helper.c | 0
target/arm/{ => tcg}/sve_helper.c | 0
target/arm/{ => tcg}/tlb_helper.c | 0
target/arm/{ => tcg}/vec_helper.c | 0
target/arm/{ => tcg}/vec_internal.h | 0
18 files changed, 44 insertions(+), 14 deletions(-)
create mode 100644 target/arm/tcg-stubs.c
rename target/arm/{ => tcg}/crypto_helper.c (100%)
rename target/arm/{ => tcg}/debug_helper.c (100%)
rename target/arm/{ => tcg}/helper-a64.c (100%)
rename target/arm/{ => tcg}/iwmmxt_helper.c (100%)
rename target/arm/{ => tcg}/m_helper.c (100%)
rename target/arm/{ => tcg}/mte_helper.c (100%)
rename target/arm/{ => tcg}/mve_helper.c (100%)
rename target/arm/{ => tcg}/neon_helper.c (100%)
rename target/arm/{ => tcg}/op_helper.c (100%)
rename target/arm/{ => tcg}/pauth_helper.c (100%)
rename target/arm/{ => tcg}/sme_helper.c (100%)
rename target/arm/{ => tcg}/sve_helper.c (100%)
rename target/arm/{ => tcg}/tlb_helper.c (100%)
rename target/arm/{ => tcg}/vec_helper.c (100%)
rename target/arm/{ => tcg}/vec_internal.h (100%)target/arm/meson.build +2 -14
@@ -2,17 +2,8 @@ arm_ss = ss.source_set() arm_ss.add(files( 'cpregs.c', 'cpu.c', - 'crypto_helper.c', - 'debug_helper.c', 'gdbstub.c', 'helper.c', - 'iwmmxt_helper.c', - 'm_helper.c', - 'mve_helper.c', - 'neon_helper.c', - 'op_helper.c', - 'tlb_helper.c', - 'vec_helper.c', 'vfp_helper.c', 'cpu_tcg.c', ))
@@ -23,11 +14,6 @@ arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c'), if_false: fil arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'cpu64.c', 'gdbstub64.c', - 'helper-a64.c', - 'mte_helper.c', - 'pauth_helper.c', - 'sve_helper.c', - 'sme_helper.c', )) arm_softmmu_ss = ss.source_set()
@@ -44,6 +30,8 @@ subdir('hvf') if 'CONFIG_TCG' in config_all subdir('tcg') +else + arm_ss.add(files('tcg-stubs.c')) endif target_arch += {'arm': arm_ss}
target/arm/tcg-stubs.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* QEMU ARM stubs for some TCG helper functions +* +* Copyright 2021 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internals.h" + +void write_v7m_exception (CPUARMState *env,uint32_t new_exc) +{ +g_assert_not_reached (); +} + +void raise_exception_ra (CPUARMState *env,uint32_t excp,uint32_t syndrome, +uint32_t target_el,uintptr_t ra) +{ +g_assert_not_reached (); +} + +void arm_reset_sve_state (CPUARMState *env) +{ +g_assert_not_reached (); +}
target/arm/tcg/crypto_helper.c renamed from target/arm/crypto_helper.c +0 -0
target/arm/tcg/debug_helper.c renamed from target/arm/debug_helper.c +0 -0
target/arm/tcg/helper-a64.c renamed from target/arm/helper-a64.c +0 -0
target/arm/tcg/iwmmxt_helper.c renamed from target/arm/iwmmxt_helper.c +0 -0
target/arm/tcg/m_helper.c renamed from target/arm/m_helper.c +0 -0
target/arm/tcg/meson.build +14 -0
@@ -23,10 +23,24 @@ arm_ss.add(files( 'translate-mve.c', 'translate-neon.c', 'translate-vfp.c', + 'crypto_helper.c', + 'debug_helper.c', + 'iwmmxt_helper.c', + 'm_helper.c', + 'mve_helper.c', + 'neon_helper.c', + 'op_helper.c', + 'tlb_helper.c', + 'vec_helper.c', )) arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'translate-a64.c', 'translate-sve.c', 'translate-sme.c', + 'helper-a64.c', + 'mte_helper.c', + 'pauth_helper.c', + 'sme_helper.c', + 'sve_helper.c', ))
target/arm/tcg/mte_helper.c renamed from target/arm/mte_helper.c +0 -0
target/arm/tcg/mve_helper.c renamed from target/arm/mve_helper.c +0 -0
target/arm/tcg/neon_helper.c renamed from target/arm/neon_helper.c +0 -0
target/arm/tcg/op_helper.c renamed from target/arm/op_helper.c +0 -0
target/arm/tcg/pauth_helper.c renamed from target/arm/pauth_helper.c +0 -0
target/arm/tcg/sme_helper.c renamed from target/arm/sme_helper.c +0 -0
target/arm/tcg/sve_helper.c renamed from target/arm/sve_helper.c +0 -0
target/arm/tcg/tlb_helper.c renamed from target/arm/tlb_helper.c +0 -0
target/arm/tcg/vec_helper.c renamed from target/arm/vec_helper.c +0 -0
target/arm/tcg/vec_internal.h renamed from target/arm/vec_internal.h +0 -0
Signature · 1 line
2.35.3
RFC PATCH v2 10/19 target/arm: Move psci.c into the tcg directory
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
---
target/arm/meson.build | 1 -
target/arm/tcg/meson.build | 4 ++++
target/arm/{ => tcg}/psci.c | 0
3 files changed, 4 insertions(+), 1 deletion(-)
rename target/arm/{ => tcg}/psci.c (100%)target/arm/meson.build +0 -1
@@ -22,7 +22,6 @@ arm_softmmu_ss.add(files( 'arm-powerctl.c', 'machine.c', 'monitor.c', - 'psci.c', 'ptw.c', ))
target/arm/tcg/meson.build +4 -0
@@ -44,3 +44,7 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'sme_helper.c', 'sve_helper.c', )) + +arm_softmmu_ss.add(files( + 'psci.c', +))
target/arm/tcg/psci.c renamed from target/arm/psci.c +0 -0
Signature · 1 line
2.35.3
RFC PATCH v2 11/19 target/arm: Wrap arm_rebuild_hflags calls with tcg_enabled
In reply to Fabiano RosasThis is in preparation to moving the hflags code into its own file under the tcg/ directory.
---
I extracted these into a separate patch so we can discuss. If I move the tcg_enabled check to a header that would add overhead for all the calls where we know for sure that the code is running with TCG. And I don't think we want a new arm_rebuild_hflags_foo to be used for common code.
--- hw/arm/boot.c | 6 +++++- hw/intc/armv7m_nvic.c | 20 +++++++++++++------- target/arm/arm-powerctl.c | 7 +++++-- target/arm/cpregs.c | 8 ++++++-- target/arm/cpu.c | 4 ++-- target/arm/helper.c | 12 +++++++++--- target/arm/machine.c | 6 +++++- 7 files changed, 45 insertions(+), 18 deletions(-)
hw/arm/boot.c +5 -1
@@ -15,6 +15,7 @@#include "hw/arm/boot.h" #include "hw/arm/linux-boot-if.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "sysemu/sysemu.h" #include "sysemu/numa.h" #include "hw/boards.h"
@@ -827,7 +828,10 @@ static void do_cpu_reset(void *opaque) info->secondary_cpu_reset_hook (cpu, info); } } -arm_rebuild_hflags (env); + +if (tcg_enabled ()) { +arm_rebuild_hflags (env); + } } }
hw/intc/armv7m_nvic.c +13 -7
@@ -18,6 +18,7 @@#include "hw/intc/armv7m_nvic.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "sysemu/tcg.h" #include "sysemu/runstate.h" #include "target/arm/cpu.h" #include "exec/exec-all.h"
@@ -2466,8 +2467,10 @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,/* This is UNPREDICTABLE; treat as RAZ/WI */ exit_ok: -/* Ensure any changes made are reflected in the cached hflags. */ -arm_rebuild_hflags (&s->cpu->env); +if (tcg_enabled ()) { +/* Ensure any changes made are reflected in the cached hflags. */ +arm_rebuild_hflags (&s->cpu->env); + }return MEMTX_OK ; }
@@ -2648,11 +2651,14 @@ static void armv7m_nvic_reset(DeviceState *dev) } } -/* -* We updated state that affects the CPU's MMUidx and thus its hflags; -* and we can't guarantee that we run before the CPU reset function. -*/ -arm_rebuild_hflags (&s->cpu->env); +if (tcg_enabled ()) { +/* +* We updated state that affects the CPU's MMUidx and thus its +* hflags; and we can't guarantee that we run before the CPU +* reset function. +*/ +arm_rebuild_hflags (&s->cpu->env); + } }static void nvic_systick_trigger (void *opaque,int n,int level)
target/arm/arm-powerctl.c +5 -2
@@ -15,6 +15,7 @@#include "arm-powerctl.h" #include "qemu/log.h" #include "qemu/main-loop.h" +#include "sysemu/tcg.h" #ifndef DEBUG_ARM_POWERCTL #define DEBUG_ARM_POWERCTL 0
@@ -127,8 +128,10 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, target_cpu->env.regs[0 ] = info->context_id; } -/* CP15 update requires rebuilding hflags */ -arm_rebuild_hflags (&target_cpu->env); +if (tcg_enabled ()) { +/* CP15 update requires rebuilding hflags */ +arm_rebuild_hflags (&target_cpu->env); + }/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry);
target/arm/cpregs.c +6 -2
@@ -16,6 +16,7 @@#include "exec/exec-all.h" #include "hw/irq.h" #include "sysemu/cpu-timers.h" +#include "sysemu/tcg.h" #include "qapi/error.h" #include "qemu/guest-random.h" #include "cpregs.h"
@@ -5178,7 +5179,7 @@ static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,/* This may enable/disable the MMU, so do a TLB flush. */ tlb_flush (CPU (cpu)); -if (ri->type &ARM_CP_SUPPRESS_TB_END ) { +if (tcg_enabled () && ri->type &ARM_CP_SUPPRESS_TB_END ) {/* * Normally we would always end the TB on an SCTLR write; see the * comment in ARMCPRegInfo sctlr initialization below for why Xscale
@@ -6667,7 +6668,10 @@ static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri, {helper_set_pstate_sm (env,FIELD_EX64 (value,SVCR ,SM ));helper_set_pstate_za (env,FIELD_EX64 (value,SVCR ,ZA )); -arm_rebuild_hflags (env); + +if (tcg_enabled ()) { +arm_rebuild_hflags (env); + } } static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/cpu.c +2 -2
@@ -540,9 +540,9 @@ static void arm_cpu_reset_hold(Object *obj)if (tcg_enabled ()) {hw_breakpoint_update_all (cpu);hw_watchpoint_update_all (cpu); - } -arm_rebuild_hflags (env); +arm_rebuild_hflags (env); + } }#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY )
target/arm/helper.c +9 -3
@@ -570,7 +570,7 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask, } mask &= ~CACHED_CPSR_BITS ; env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask); -if (rebuild_hflags) { +if (tcg_enabled () && rebuild_hflags) {arm_rebuild_hflags (env); } }
@@ -1129,7 +1129,10 @@ static void take_aarch32_exception(CPUARMState *env, int new_mode, env->regs[14 ] = env->regs[15 ] + offset; } env->regs[15 ] = newpc; -arm_rebuild_hflags (env); + +if (tcg_enabled ()) { +arm_rebuild_hflags (env); + } }static void arm_cpu_do_interrupt_aarch32_hyp (CPUState *cs)
@@ -1685,7 +1688,10 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)pstate_write (env,PSTATE_DAIF | new_mode); env->aarch64 = true;aarch64_restore_sp (env, new_el); -helper_rebuild_hflags_a64 (env, new_el); + +if (tcg_enabled ()) { +helper_rebuild_hflags_a64 (env, new_el); + } env->pc = addr;
target/arm/machine.c +5 -1
@@ -2,6 +2,7 @@#include "cpu.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "kvm_arm.h" #include "internals.h" #include "migration/cpu.h"
@@ -871,7 +872,10 @@ static int cpu_post_load(void *opaque, int version_id)if (!kvm_enabled ()) {pmu_op_finish (&cpu->env); } -arm_rebuild_hflags (&cpu->env); + +if (tcg_enabled ()) { +arm_rebuild_hflags (&cpu->env); + }return 0 ; }
Signature · 1 line
2.35.3
RFC PATCH v2 12/19 target/arm: Move hflags code into the tcg directory
In reply to Fabiano RosasThe hflags are used only for TCG code, so introduce a new file hflags.c to keep that code.
--- target/arm/helper.c | 361 +----------------------------------- target/arm/internals.h | 2 + target/arm/tcg-stubs.c | 5 + target/arm/tcg/hflags.c | 370 +++++++++++++++++++++++++++++++++++++ target/arm/tcg/meson.build | 1 + 5 files changed, 379 insertions(+), 360 deletions(-) create mode 100644 target/arm/tcg/hflags.c
target/arm/helper.c +1 -360
@@ -239,32 +239,6 @@ int sme_exception_el(CPUARMState *env, int el)return 0 ; } -/* This corresponds to the ARM pseudocode function IsFullA64Enabled(). */ -static bool sme_fa64 (CPUARMState *env,int el) -{ -if (!cpu_isar_feature (aa64_sme_fa64,env_archcpu (env))) { -return false; - } - -if (el <=1 && !el_is_in_host (env, el)) { -if (!FIELD_EX64 (env->vfp.smcr_el[1 ],SMCR ,FA64 )) { -return false; - } - } -if (el <=2 &&arm_is_el2_enabled (env)) { -if (!FIELD_EX64 (env->vfp.smcr_el[2 ],SMCR ,FA64 )) { -return false; - } - } -if (arm_feature (env,ARM_FEATURE_EL3 )) { -if (!FIELD_EX64 (env->vfp.smcr_el[3 ],SMCR ,FA64 )) { -return false; - } - } - -return true; -} -/* * Given that SVE is enabled, return the vector length for EL. */
@@ -1832,7 +1806,7 @@ int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx) } } -static int aa64_va_parameter_tcma (uint64_t tcr,ARMMMUIdx mmu_idx) +int aa64_va_parameter_tcma (uint64_t tcr,ARMMMUIdx mmu_idx) {if (regime_has_2_ranges (mmu_idx)) {return extract64 (tcr,57 ,2 );
@@ -2543,339 +2517,6 @@ ARMMMUIdx arm_mmu_idx(CPUARMState *env)return arm_mmu_idx_el (env,arm_current_el (env)); } -static CPUARMTBFlags rebuild_hflags_common (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx, -CPUARMTBFlags flags) -{ -DP_TBFLAG_ANY (flags,FPEXC_EL , fp_el); -DP_TBFLAG_ANY (flags,MMUIDX ,arm_to_core_mmu_idx (mmu_idx)); - -if (arm_singlestep_active (env)) { -DP_TBFLAG_ANY (flags,SS_ACTIVE ,1 ); - } -return flags; -} - -static CPUARMTBFlags rebuild_hflags_common_32 (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx, -CPUARMTBFlags flags) -{ -bool sctlr_b =arm_sctlr_b (env); - -if (sctlr_b) { -DP_TBFLAG_A32 (flags,SCTLR__B ,1 ); - } -if (arm_cpu_data_is_big_endian_a32 (env, sctlr_b)) { -DP_TBFLAG_ANY (flags,BE_DATA ,1 ); - } -DP_TBFLAG_A32 (flags,NS , !access_secure_reg (env)); - -return rebuild_hflags_common (env, fp_el, mmu_idx, flags); -} - -static CPUARMTBFlags rebuild_hflags_m32 (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx) -{ -CPUARMTBFlags flags = {}; -uint32_t ccr = env->v7m.ccr[env->v7m.secure]; - -/* Without HaveMainExt, CCR.UNALIGN_TRP is RES1. */ -if (ccr &R_V7M_CCR_UNALIGN_TRP_MASK ) { -DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); - } - -if (arm_v7m_is_handler_mode (env)) { -DP_TBFLAG_M32 (flags,HANDLER ,1 ); - } - -/* -* v8M always applies stack limit checks unless CCR.STKOFHFNMIGN -* is suppressing them because the requested execution priority -* is less than 0. -*/ -if (arm_feature (env,ARM_FEATURE_V8 ) && - !((mmu_idx &ARM_MMU_IDX_M_NEGPRI ) && - (ccr &R_V7M_CCR_STKOFHFNMIGN_MASK ))) { -DP_TBFLAG_M32 (flags,STACKCHECK ,1 ); - } - -if (arm_feature (env,ARM_FEATURE_M_SECURITY ) && env->v7m.secure) { -DP_TBFLAG_M32 (flags,SECURE ,1 ); - } - -return rebuild_hflags_common_32 (env, fp_el, mmu_idx, flags); -} - -static CPUARMTBFlags rebuild_hflags_a32 (CPUARMState *env,int fp_el, -ARMMMUIdx mmu_idx) -{ -CPUARMTBFlags flags = {}; -int el =arm_current_el (env); - -if (arm_sctlr (env, el) &SCTLR_A ) { -DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); - } - -if (arm_el_is_aa64 (env,1 )) { -DP_TBFLAG_A32 (flags,VFPEN ,1 ); - } - -if (el <2 && env->cp15.hstr_el2 && - (arm_hcr_el2_eff (env) & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) { -DP_TBFLAG_A32 (flags,HSTR_ACTIVE ,1 ); - } - -if (env->uncached_cpsr &CPSR_IL ) { -DP_TBFLAG_ANY (flags,PSTATE__IL ,1 ); - } - -/* -* The SME exception we are testing for is raised via -* AArch64.CheckFPAdvSIMDEnabled(), as called from -* AArch32.CheckAdvSIMDOrFPEnabled(). -*/ -if (el ==0 - &&FIELD_EX64 (env->svcr,SVCR ,SM ) - && (!arm_is_el2_enabled (env) - || (arm_el_is_aa64 (env,2 ) && !(env->cp15.hcr_el2 &HCR_TGE ))) - &&arm_el_is_aa64 (env,1 ) - && !sme_fa64 (env, el)) { -DP_TBFLAG_A32 (flags,SME_TRAP_NONSTREAMING ,1 ); - } - -return rebuild_hflags_common_32 (env, fp_el, mmu_idx, flags); -} - -static CPUARMTBFlags rebuild_hflags_a64 (CPUARMState *env,int el,int fp_el, -ARMMMUIdx mmu_idx) -{ -CPUARMTBFlags flags = {}; -ARMMMUIdx stage1 =stage_1_mmu_idx (mmu_idx); -uint64_t tcr =regime_tcr (env, mmu_idx); -uint64_t sctlr; -int tbii, tbid; - -DP_TBFLAG_ANY (flags,AARCH64_STATE ,1 ); - -/* Get control bits for tagged addresses. */ - tbid =aa64_va_parameter_tbi (tcr, mmu_idx); - tbii = tbid & ~aa64_va_parameter_tbid (tcr, mmu_idx); - -DP_TBFLAG_A64 (flags,TBII , tbii); -DP_TBFLAG_A64 (flags,TBID , tbid); - -if (cpu_isar_feature (aa64_sve,env_archcpu (env))) { -int sve_el =sve_exception_el (env, el); - -/* -* If either FP or SVE are disabled, translator does not need len. -* If SVE EL > FP EL, FP exception has precedence, and translator -* does not need SVE EL. Save potential re-translations by forcing -* the unneeded data to zero. -*/ -if (fp_el !=0 ) { -if (sve_el > fp_el) { - sve_el =0 ; - } - }else if (sve_el ==0 ) { -DP_TBFLAG_A64 (flags,VL ,sve_vqm1_for_el (env, el)); - } -DP_TBFLAG_A64 (flags,SVEEXC_EL , sve_el); - } -if (cpu_isar_feature (aa64_sme,env_archcpu (env))) { -int sme_el =sme_exception_el (env, el); -bool sm =FIELD_EX64 (env->svcr,SVCR ,SM ); - -DP_TBFLAG_A64 (flags,SMEEXC_EL , sme_el); -if (sme_el ==0 ) { -/* Similarly, do not compute SVL if SME is disabled. */ -int svl =sve_vqm1_for_el_sm (env, el, true); -DP_TBFLAG_A64 (flags,SVL , svl); -if (sm) { -/* If SVE is disabled, we will not have set VL above. */ -DP_TBFLAG_A64 (flags,VL , svl); - } - } -if (sm) { -DP_TBFLAG_A64 (flags,PSTATE_SM ,1 ); -DP_TBFLAG_A64 (flags,SME_TRAP_NONSTREAMING , !sme_fa64 (env, el)); - } -DP_TBFLAG_A64 (flags,PSTATE_ZA ,FIELD_EX64 (env->svcr,SVCR ,ZA )); - } - - sctlr =regime_sctlr (env, stage1); - -if (sctlr &SCTLR_A ) { -DP_TBFLAG_ANY (flags,ALIGN_MEM ,1 ); - } - -if (arm_cpu_data_is_big_endian_a64 (el, sctlr)) { -DP_TBFLAG_ANY (flags,BE_DATA ,1 ); - } - -if (cpu_isar_feature (aa64_pauth,env_archcpu (env))) { -/* -* In order to save space in flags, we record only whether -* pauth is "inactive", meaning all insns are implemented as -* a nop, or "active" when some action must be performed. -* The decision of which action to take is left to a helper. -*/ -if (sctlr & (SCTLR_EnIA | SCTLR_EnIB | SCTLR_EnDA | SCTLR_EnDB)) { -DP_TBFLAG_A64 (flags,PAUTH_ACTIVE ,1 ); - } - } - -if (cpu_isar_feature (aa64_bti,env_archcpu (env))) { -/* Note that SCTLR_EL[23].BT == SCTLR_BT1. */ -if (sctlr & (el ==0 ?SCTLR_BT0 :SCTLR_BT1 )) { -DP_TBFLAG_A64 (flags,BT ,1 ); - } - } - -/* Compute the condition for using AccType_UNPRIV for LDTR et al. */ -if (!(env->pstate &PSTATE_UAO )) { -switch (mmu_idx) { -case ARMMMUIdx_E10_1: -case ARMMMUIdx_E10_1_PAN: -/* TODO: ARMv8.3-NV */ -DP_TBFLAG_A64 (flags,UNPRIV ,1 ); -break ; -case ARMMMUIdx_E20_2: -case ARMMMUIdx_E20_2_PAN: -/* -* Note that EL20_2 is gated by HCR_EL2.E2H == 1, but EL20_0 is -* gated by HCR_EL2.<E2H,TGE> == '11', and so is LDTR. -*/ -if (env->cp15.hcr_el2 &HCR_TGE ) { -DP_TBFLAG_A64 (flags,UNPRIV ,1 ); - } -break ; -default : -break ; - } - } - -if (env->pstate &PSTATE_IL ) { -DP_TBFLAG_ANY (flags,PSTATE__IL ,1 ); - } - -if (cpu_isar_feature (aa64_mte,env_archcpu (env))) { -/* -* Set MTE_ACTIVE if any access may be Checked, and leave clear -* if all accesses must be Unchecked: -* 1) If no TBI, then there are no tags in the address to check, -* 2) If Tag Check Override, then all accesses are Unchecked, -* 3) If Tag Check Fail == 0, then Checked access have no effect, -* 4) If no Allocation Tag Access, then all accesses are Unchecked. -*/ -if (allocation_tag_access_enabled (env, el, sctlr)) { -DP_TBFLAG_A64 (flags,ATA ,1 ); -if (tbid - && !(env->pstate &PSTATE_TCO ) - && (sctlr & (el ==0 ?SCTLR_TCF0 :SCTLR_TCF ))) { -DP_TBFLAG_A64 (flags,MTE_ACTIVE ,1 ); - } - } -/* And again for unprivileged accesses, if required. */ -if (EX_TBFLAG_A64 (flags,UNPRIV ) - && tbid - && !(env->pstate &PSTATE_TCO ) - && (sctlr &SCTLR_TCF0 ) - &&allocation_tag_access_enabled (env,0 , sctlr)) { -DP_TBFLAG_A64 (flags,MTE0_ACTIVE ,1 ); - } -/* Cache TCMA as well as TBI. */ -DP_TBFLAG_A64 (flags,TCMA ,aa64_va_parameter_tcma (tcr, mmu_idx)); - } - -return rebuild_hflags_common (env, fp_el, mmu_idx, flags); -} - -static CPUARMTBFlags rebuild_hflags_internal (CPUARMState *env) -{ -int el =arm_current_el (env); -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - -if (is_a64 (env)) { -return rebuild_hflags_a64 (env, el, fp_el, mmu_idx); - }else if (arm_feature (env,ARM_FEATURE_M )) { -return rebuild_hflags_m32 (env, fp_el, mmu_idx); - }else { -return rebuild_hflags_a32 (env, fp_el, mmu_idx); - } -} - -void arm_rebuild_hflags (CPUARMState *env) -{ - env->hflags =rebuild_hflags_internal (env); -} - -/* -* If we have triggered a EL state change we can't rely on the -* translator having passed it to us, we need to recompute. -*/ -void HELPER (rebuild_hflags_m32_newel )(CPUARMState *env) -{ -int el =arm_current_el (env); -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - - env->hflags =rebuild_hflags_m32 (env, fp_el, mmu_idx); -} - -void HELPER (rebuild_hflags_m32 )(CPUARMState *env,int el) -{ -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - - env->hflags =rebuild_hflags_m32 (env, fp_el, mmu_idx); -} - -/* -* If we have triggered a EL state change we can't rely on the -* translator having passed it to us, we need to recompute. -*/ -void HELPER (rebuild_hflags_a32_newel )(CPUARMState *env) -{ -int el =arm_current_el (env); -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - env->hflags =rebuild_hflags_a32 (env, fp_el, mmu_idx); -} - -void HELPER (rebuild_hflags_a32 )(CPUARMState *env,int el) -{ -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - - env->hflags =rebuild_hflags_a32 (env, fp_el, mmu_idx); -} - -void HELPER (rebuild_hflags_a64 )(CPUARMState *env,int el) -{ -int fp_el =fp_exception_el (env, el); -ARMMMUIdx mmu_idx =arm_mmu_idx_el (env, el); - - env->hflags =rebuild_hflags_a64 (env, el, fp_el, mmu_idx); -} - -static inline void assert_hflags_rebuild_correctly (CPUARMState *env) -{ -#ifdef CONFIG_DEBUG_TCG -CPUARMTBFlags c = env->hflags; -CPUARMTBFlags r =rebuild_hflags_internal (env); - -if (unlikely (c.flags != r.flags || c.flags2 != r.flags2)) { -fprintf (stderr,"TCG hflags mismatch " -"(current:(0x%08x,0x" TARGET_FMT_lx")" -" rebuilt:(0x%08x,0x" TARGET_FMT_lx")\n" , - c.flags, c.flags2, r.flags, r.flags2); -abort (); - } -#endif -} -static bool mve_no_pred (CPUARMState *env) {/*
target/arm/internals.h +2 -0
@@ -1087,6 +1087,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,int aa64_va_parameter_tbi (uint64_t tcr,ARMMMUIdx mmu_idx);int aa64_va_parameter_tbid (uint64_t tcr,ARMMMUIdx mmu_idx); +int aa64_va_parameter_tcma (uint64_t tcr,ARMMMUIdx mmu_idx);/* Determine if allocation tags are available. */ static inline bool allocation_tag_access_enabled(CPUARMState *env, int el,
@@ -1368,4 +1369,5 @@ bool arm_generate_debug_exceptions(CPUARMState *env); ((1 << (1 -1 )) | (1 << (2 -1 )) | \ (1 << (4 - 1)) | (1 << (8 - 1)) | (1 << (16 - 1))) +void assert_hflags_rebuild_correctly (CPUARMState *env);#endif
target/arm/tcg-stubs.c +5 -0
@@ -26,3 +26,8 @@ void arm_reset_sve_state(CPUARMState *env) {g_assert_not_reached (); } + +/* Temporarily while cpu_get_tb_cpu_state() is still in common code */ +void assert_hflags_rebuild_correctly (CPUARMState *env) +{ +}
target/arm/tcg/hflags.c new file +370 -0
370 lines not on this page · raw message
target/arm/tcg/meson.build +1 -0
@@ -25,6 +25,7 @@ arm_ss.add(files( 'translate-vfp.c', 'crypto_helper.c', 'debug_helper.c', + 'hflags.c', 'iwmmxt_helper.c', 'm_helper.c', 'mve_helper.c',
Signature · 1 line
2.35.3
Re: [RFC PATCH v2 12/19] target/arm: Move hflags code into the tcg directory
Quoted 5 lines · Fabiano Rosas
target/arm/tcg/hflags.c new file +5
-0+inline void assert_hflags_rebuild_correctly (CPUARMState *env) +{ +#ifdef CONFIG_DEBUG_TCG +CPUARMTBFlags c = env->hflags; +CPUARMTBFlags r =rebuild_hflags_internal (env);
target/arm/tcg/hflags.c line 370
Quoted 10 lines
target/arm/tcg/hflags.c new file +10
-0+ +if (unlikely (c.flags != r.flags || c.flags2 != r.flags2)) { +fprintf (stderr,"TCG hflags mismatch " +"(current:(0x%08x,0x" TARGET_FMT_lx")" +" rebuilt:(0x%08x,0x" TARGET_FMT_lx")\n" , + c.flags, c.flags2, r.flags, r.flags2); +abort (); + } +#endif +}
Inline marker non-functional.
Anyway, this should not be separated from cpu_get_tb_cpu_state, where it folds to no-op when --disable-debug-tcg. Indeed, I once had it textually inlined in cpu_get_tb_cpu_state, before Philippe thought it looked nicer as a separate helper function.
Otherwise,
r~
RFC PATCH v2 13/19 tests: do not run test-hmp on all machines for ARM KVM-only
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
--- tests/qtest/test-hmp.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tests/qtest/test-hmp.c +21 -0
@@ -157,8 +157,29 @@ int main(int argc, char **argv)g_test_init (&argc, &argv,NULL ); +/* +* XXX currently we build also boards for ARM that are +* incompatible with KVM. We therefore need to check this +* explicitly, and only test virt for kvm-only arm builds. After +* we do the work of Kconfig etc to ensure that only +* KVM-compatible boards are built for the kvm-only build, we +* could remove this. +*/ +#ifndef CONFIG_TCG + { +const char *arch =qtest_get_arch (); + +if (strcmp (arch,"arm" ) ==0 ||strcmp (arch,"aarch64" ) ==0 ) { +add_machine_test_case ("virt" ); + goto add_machine_test_done; + } + } +#endif /* !CONFIG_TCG */ +qtest_cb_for_every_machine (add_machine_test_case,g_test_quick ()); + goto add_machine_test_done; + add_machine_test_done:/* as none machine has no memory by default, add a test case with memory */ qtest_add_data_func ("hmp/none+2MB" ,g_strdup ("none -m 2" ), test_machine);
Signature · 1 line
2.35.3
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ... it shouldn't be too hard to add some "depends on TCG" statements to the machine entries in hw/arm/Kconfig, should it?
Anyway, if that's not possible (yet), I suggest to add your hack to qtest_cb_for_every_machine() instead, so you could change this in one central place instead of adding a hack to each and every test that uses this function.
Thomas
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
(plus the cpregs code movement which conflicts with everything, so I'd rather merge it sooner)
Quoted 2 lines
it shouldn't be too hard to add some
"depends on TCG" statements to the machine entries in hw/arm/Kconfig, should it?
I havent't looked into it yet. If it turns out to be simple I can do it now.
Quoted 4 lines
Anyway, if that's not possible (yet), I suggest to add your hack to
qtest_cb_for_every_machine()instead, so you could change this in one central place instead of adding a hack to each and every test that uses this function.
Good idea.
Quoted 2 lines
Thomas
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 13 lines · Fabiano Rosas
Quoted 10 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Quoted 5 lines
Quoted 1 line
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
-- PMM
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Fabiano Rosas
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
Quoted 7 lines
Quoted 3 lines
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
But what does "all machines" mean in a no-TCG build? The original intent of the patch was that only 'virt' should be present and therefore the only one tested.
Quoted 2 lines
-- PMM
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 23 lines · Fabiano Rosas
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Fabiano Rosas
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
Quoted 7 lines
Quoted 3 lines
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
But what does "all machines" mean in a no-TCG build? The original intent of the patch was that only 'virt' should be present and therefore the only one tested.
It means "every machine the user can create". If the machine can't run then either we shouldn't compile it in, or else we should be compiling in enough extra stuff to allow it to work.
-- PMM
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 32 lines · Peter Maydell
Quoted 23 lines · Fabiano Rosas
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Fabiano Rosas
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
Quoted 7 lines
Quoted 3 lines
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
But what does "all machines" mean in a no-TCG build? The original intent of the patch was that only 'virt' should be present and therefore the only one tested.
Quoted 6 lines
It means "every machine the user can create". If the machine can't run then either we shouldn't compile it in, or else we should be compiling in enough extra stuff to allow it to work.
-- PMM
Hi,
once upon a time there was a series by Philippe to accomplish that (KConfig) right?
Ciao,
Claudio
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 38 lines · Claudio Fontana
Quoted 37 lines · Peter Maydell
Quoted 23 lines · Fabiano Rosas
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Fabiano Rosas
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
Quoted 7 lines
Quoted 3 lines
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
But what does "all machines" mean in a no-TCG build? The original intent of the patch was that only 'virt' should be present and therefore the only one tested.
It means "every machine the user can create". If the machine can't run then either we shouldn't compile it in, or else we should be compiling in enough extra stuff to allow it to work.
Quoted 5 lines
Quoted 1 line
-- PMM
Hi,
once upon a time there was a series by Philippe to accomplish that (KConfig) right?
Maybe that one:
https://lore.kernel.org/qemu-devel/[email protected]/
?
Thomas
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
In reply to Claudio FontanaQuoted 38 lines · Claudio Fontana
Quoted 37 lines · Peter Maydell
Quoted 23 lines · Fabiano Rosas
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Fabiano Rosas
Quoted 11 lines · Thomas Huth
Quoted 8 lines · Fabiano Rosas
From: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
Why don't you fix it immediately? ...
My idea was to have in this series the minimum to unbreak the --disable-tcg build and later bring the rest of the changes incrementally.
Quoted 7 lines
Quoted 3 lines
This test is basically checking "all the machines should work". That's an important invariant to maintain, so I don't think we should just skip it for Arm targets.
But what does "all machines" mean in a no-TCG build? The original intent of the patch was that only 'virt' should be present and therefore the only one tested.
It means "every machine the user can create". If the machine can't run then either we shouldn't compile it in, or else we should be compiling in enough extra stuff to allow it to work.
Quoted 5 lines
Quoted 1 line
-- PMM
Hi,
once upon a time there was a series by Philippe to accomplish that (KConfig) right?
Is this it?
https://www.mail-archive.com/[email protected]/msg777719.html
I have now moved the cpus into the tcg directory:
# ./qemu-system-aarch64 -cpu ? Available CPUs: a64fx cortex-a35 cortex-a53 cortex-a55 cortex-a57 cortex-a72 cortex-a76 host max neoverse-n1
What remains is changing the Kconfig to not bring all the machines. Nowadays for KVM is the 'virt' machine the only one we use? I did some tests yesterday by keeping only CONFIG_ARM_VIRT and was left with this:
# ./qemu-system-aarch64 -machine ? Supported machines are: none empty machine virt-2.10 QEMU 2.10 ARM Virtual Machine virt-2.11 QEMU 2.11 ARM Virtual Machine virt-2.12 QEMU 2.12 ARM Virtual Machine virt-2.6 QEMU 2.6 ARM Virtual Machine virt-2.7 QEMU 2.7 ARM Virtual Machine virt-2.8 QEMU 2.8 ARM Virtual Machine virt-2.9 QEMU 2.9 ARM Virtual Machine virt-3.0 QEMU 3.0 ARM Virtual Machine virt-3.1 QEMU 3.1 ARM Virtual Machine virt-4.0 QEMU 4.0 ARM Virtual Machine virt-4.1 QEMU 4.1 ARM Virtual Machine virt-4.2 QEMU 4.2 ARM Virtual Machine virt-5.0 QEMU 5.0 ARM Virtual Machine virt-5.1 QEMU 5.1 ARM Virtual Machine virt-5.2 QEMU 5.2 ARM Virtual Machine virt-6.0 QEMU 6.0 ARM Virtual Machine virt-6.1 QEMU 6.1 ARM Virtual Machine virt-6.2 QEMU 6.2 ARM Virtual Machine virt-7.0 QEMU 7.0 ARM Virtual Machine virt-7.1 QEMU 7.1 ARM Virtual Machine virt-7.2 QEMU 7.2 ARM Virtual Machine virt QEMU 8.0 ARM Virtual Machine (alias of virt-8.0) virt-8.0 QEMU 8.0 ARM Virtual Machine x-remote Experimental remote machine
But qtest dislikes that even more. I need to figure out why.
The approach of that series seems interesting, moving CONFIG_FOO=y from default.mak into Kconfig as 'default y if TCG'. Maybe that will yield better results, I'll try to follow that route.
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 1 line · Fabiano Rosas
Nowadays for KVM is the 'virt' machine the only one we use?
Also sbsa-ref.
r~
Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
Quoted 4 lines · Richard Henderson
Quoted 1 line · Fabiano Rosas
Nowadays for KVM is the 'virt' machine the only one we use?
Also sbsa-ref.
It seems not, sbsa_ref_init has this:
if (kvm_enabled()) {
error_report("sbsa-ref: KVM is not supported for this machine");
exit(1);
}Re: [RFC PATCH v2 13/19] tests: do not run test-hmp on all machines for ARM KVM-only
In reply to Fabiano RosasQuoted 2 lines · Fabiano Rosas
What remains is changing the
Kconfigto not bring all the machines. Nowadays for KVM is the 'virt' machine the only one we use?
I think perhaps also xlnx-versal-virt -- at any rate, the source files include some KVM related headers...
Alistair, Edgar -- does xlnx-versal-virt work with KVM ?
thanks
-- PMM
RFC PATCH v2 14/19 tests: do not run qom-test on all machines for ARM KVM-only
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
on ARM we currently list and build all machines, even when building KVM-only, without TCG.
Until we fix this (and we only list and build machines that are compatible with KVM), only test specifically using the "virt" machine in this case.
--- tests/qtest/qom-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tests/qtest/qom-test.c +21 -0
@@ -105,7 +105,28 @@ int main(int argc, char **argv) {g_test_init (&argc, &argv,NULL ); +/* +* XXX currently we build also boards for ARM that are +* incompatible with KVM. We therefore need to check this +* explicitly, and only test virt for kvm-only arm builds. After +* we do the work of Kconfig etc to ensure that only +* KVM-compatible boards are built for the kvm-only build, we +* could remove this. +*/ +#ifndef CONFIG_TCG + { +const char *arch =qtest_get_arch (); + +if (strcmp (arch,"arm" ) ==0 ||strcmp (arch,"aarch64" ) ==0 ) { +add_machine_test_case ("virt" ); + goto add_machine_test_done; + } + } +#endif /* !CONFIG_TCG */ +qtest_cb_for_every_machine (add_machine_test_case,g_test_quick ()); + goto add_machine_test_done; + add_machine_test_done:return g_test_run (); }
Signature · 1 line
2.35.3
RFC PATCH v2 15/19 tests: device-introspect-test: cope with ARM TCG-only devices
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
Skip the test_device_intro_concrete for now for ARM KVM-only build, as on ARM we currently build devices for ARM that are not compatible with a KVM-only build.
We can remove this workaround when we fix this in KConfig etc, and we only list and build machines that are compatible with KVM for KVM-only builds.
Alternative implementation provided by Alex.
--- tests/qtest/device-introspect-test.c | 32 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
tests/qtest/device-introspect-test.c +27 -5
@@ -304,6 +304,24 @@ static void test_abstract_interfaces(void)qtest_quit (qts); } +/* +* XXX currently we build also boards for ARM that are incompatible with KVM. +* We therefore need to check this explicitly, and only test virt for kvm-only +* arm builds. +* After we do the work of Kconfig etc to ensure that only KVM-compatible boards +* are built for the kvm-only build, we could remove this. +*/ +static bool skip_machine_tests (void ) +{ +#ifndef CONFIG_TCG +const char *arch =qtest_get_arch (); +if (strcmp (arch,"arm" ) ==0 ||strcmp (arch,"aarch64" ) ==0 ) { +return true; + } +#endif /* !CONFIG_TCG */ +return false; +} +static void add_machine_test_case (const char *mname) {char *path, *args;
@@ -328,11 +346,15 @@ int main(int argc, char **argv)qtest_add_func ("device/introspect/none" , test_device_intro_none);qtest_add_func ("device/introspect/abstract" , test_device_intro_abstract);qtest_add_func ("device/introspect/abstract-interfaces" , test_abstract_interfaces); -if (g_test_quick ()) { -qtest_add_data_func ("device/introspect/concrete/defaults/none" , -g_strdup (common_args), test_device_intro_concrete); - }else { -qtest_cb_for_every_machine (add_machine_test_case, true); + +if (!skip_machine_tests ()) { +if (g_test_quick ()) { +qtest_add_data_func ("device/introspect/concrete/defaults/none" , +g_strdup (common_args), + test_device_intro_concrete); + }else { +qtest_cb_for_every_machine (add_machine_test_case, true); + } }return g_test_run ();
Signature · 1 line
2.35.3
RFC PATCH v2 16/19 tests/tcg: Do not build/run TCG tests if TCG is disabled
In reply to Fabiano RosasThe tests under tests/tcg depend on the TCG accelerator. Do not build them if --disable-tcg was given in the configure line.
Test against CONFIG_TCG='' instead of CONFIG_TCG=y to account for CONFIG_TCG=m.
sample output:
$ make check-tcg GIT ui/keycodemapdb meson dtc SKIPPED x86_64-softmmu guest-tests because TCG is disabled in this build
--- configure | 4 ++++ tests/Makefile.include | 10 ++++++++++ 2 files changed, 14 insertions(+)
configure +4 -0
@@ -2351,6 +2351,10 @@ if test "$plugins" = "yes" ; then echo "CONFIG_PLUGIN=y" >> $config_host_mak fi +if test "$tcg" = "enabled" ; then + echo "CONFIG_TCG=y" >> $config_host_mak +fi + if test -n "$gdb_bin"; then gdb_version=$($gdb_bin --version | head -n 1) if version_ge ${gdb_version##* } 9.1; then
tests/Makefile.include +10 -0
@@ -45,6 +45,7 @@ RUN_TCG_TARGET_RULES=$(patsubst %,run-tcg-tests-%, $(TCG_TESTS_TARGETS)) $(foreach TARGET,$(TCG_TESTS_TARGETS), \ $(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak: config-host.mak)) +ifneq ($(CONFIG_TCG),) .PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%) $(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak $(call quiet-command, \
@@ -56,6 +57,15 @@ $(TCG_TESTS_TARGETS:%=run-tcg-tests-%): run-tcg-tests-%: build-tcg-tests-% $(call quiet-command, \ $(MAKE) -C tests/tcg/$* $(SUBDIR_MAKEFLAGS) SPEED=$(SPEED) run, \ "RUN", "$* guest-tests") +else +.PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%) +$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): + @echo " SKIPPED $(subst build-tcg-tests-,,$@) guest-tests because TCG is disabled in this build" + +.PHONY: $(TCG_TESTS_TARGETS:%=run-tcg-tests-%) +$(TCG_TESTS_TARGETS:%=run-tcg-tests-%): + @echo " SKIPPED $(subst run-tcg-tests-,,$@) guest-tests because TCG is disabled in this build" +endif .PHONY: $(TCG_TESTS_TARGETS:%=clean-tcg-tests-%) $(TCG_TESTS_TARGETS:%=clean-tcg-tests-%): clean-tcg-tests-%:
Signature · 1 line
2.35.3
RFC PATCH v2 17/19 target/arm: Move regime_using_lpae_format into internal.h
In reply to Fabiano RosasThis function is needed by common code (ptw.c), so move it along with the other regime_* functions in internal.h. When we enable the build without TCG, the tlb_helper.c file will not be present.
---
Richard: this cannot into ptw.c because that file is softmmu only
--- target/arm/internals.h | 21 ++++++++++++++++++--- target/arm/tcg/tlb_helper.c | 18 ------------------ 2 files changed, 18 insertions(+), 21 deletions(-)
target/arm/internals.h +18 -3
@@ -614,9 +614,6 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env,/* Return the MMU index for a v7M CPU in the specified security state */ ARMMMUIdx arm_v7m_mmu_idx_for_secstate (CPUARMState *env,bool secstate); -/* Return true if the translation regime is using LPAE format page tables */ -bool regime_using_lpae_format (CPUARMState *env,ARMMMUIdx mmu_idx); -/* * Return true if the stage 1 translation regime is using LPAE * format page tables
@@ -781,6 +778,24 @@ static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx)return env->cp15.tcr_el[regime_el (env, mmu_idx)]; } +/* Return true if the translation regime is using LPAE format page tables */ +static inline bool regime_using_lpae_format (CPUARMState *env,ARMMMUIdx mmu_idx) +{ +int el =regime_el (env, mmu_idx); +if (el ==2 ||arm_el_is_aa64 (env, el)) { +return true; + } +if (arm_feature (env,ARM_FEATURE_PMSA ) && +arm_feature (env,ARM_FEATURE_V8 )) { +return true; + } +if (arm_feature (env,ARM_FEATURE_LPAE ) + && (regime_tcr (env, mmu_idx) &TTBCR_EAE )) { +return true; + } +return false; +} +/** * arm_num_brps: Return number of implemented breakpoints. * Note that the ID register BRPS field is "number of bps - 1",
target/arm/tcg/tlb_helper.c +0 -18
@@ -12,24 +12,6 @@#include "exec/helper-proto.h" -/* Return true if the translation regime is using LPAE format page tables */ -bool regime_using_lpae_format (CPUARMState *env,ARMMMUIdx mmu_idx) -{ -int el =regime_el (env, mmu_idx); -if (el ==2 ||arm_el_is_aa64 (env, el)) { -return true; - } -if (arm_feature (env,ARM_FEATURE_PMSA ) && -arm_feature (env,ARM_FEATURE_V8 )) { -return true; - } -if (arm_feature (env,ARM_FEATURE_LPAE ) - && (regime_tcr (env, mmu_idx) &TTBCR_EAE )) { -return true; - } -return false; -} -/* * Returns true if the stage 1 translation regime is using LPAE format page * tables. Used when raising alignment exceptions, whose FSR changes depending
Signature · 1 line
2.35.3
Re: [RFC PATCH v2 17/19] target/arm: Move regime_using_lpae_format into internal.h
Quoted 11 lines · Fabiano Rosas
This function is needed by common code (
ptw.c), so move it along with the other regime_* functions ininternal.h. When we enable the build without TCG, thetlb_helper.cfile will not be present.Signed-off-by Fabiano Rosas<[email protected]>---
Richard: this cannot intoptw.cbecause that file is softmmu only--- target/arm/internals.h | 21 ++++++++++++++++++--- target/arm/tcg/tlb_helper.c | 18 ------------------ 2 files changed, 18 insertions(+), 21 deletions(-)
Not thrilled, because of the size of the function, but I have no better suggestions.
r~
RFC PATCH v2 18/19 cpu-defs.h: Expose CPUTLBEntryFull to non-TCG code
In reply to Fabiano RosasThis struct has no dependencies on TCG code and it is being used in target/arm/ptw.c to simplify the passing around of page table walk results. Those routines can be reached by KVM code via the gdbstub breakpoint code, so take the structure out of CONFIG_TCG to make it visible when building with --disable-tcg.
--- include/exec/cpu-defs.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/exec/cpu-defs.h +6 -0
@@ -135,6 +135,10 @@ typedef struct CPUTLBEntry {QEMU_BUILD_BUG_ON (sizeof (CPUTLBEntry) != (1 <<CPU_TLB_ENTRY_BITS )); + +#endif /* !CONFIG_USER_ONLY && CONFIG_TCG */ + +#if !defined(CONFIG_USER_ONLY )/* * The full TLB entry, which is not accessed by generated TCG code, * so the layout is not as critical as that of CPUTLBEntry. This is
@@ -176,7 +180,9 @@ typedef struct CPUTLBEntryFull {TARGET_PAGE_ENTRY_EXTRA #endif } CPUTLBEntryFull; +#endif /* !CONFIG_USER_ONLY */ +#if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_TCG )/* * Data elements that are per MMU mode, minus the bits accessed by * the TCG fast path.
Signature · 1 line
2.35.3
RFC PATCH v2 19/19 target/arm: don't access TCG code when debugging with KVM
In reply to Fabiano RosasWhen TCG is disabled this part of the code should not be reachable, so wrap it with an ifdef for now.
This allows us to start using CONFIG_TCG=n (--disable-tcg in the configure line).
--- target/arm/ptw.c | 4 ++++ 1 file changed, 4 insertions(+)
target/arm/ptw.c +4 -0
@@ -254,6 +254,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, ptw->out_host =NULL ; ptw->out_rw = false; }else { +#ifdef CONFIG_TCG CPUTLBEntryFull *full;int flags;
@@ -270,6 +271,9 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, ptw->out_rw = full->prot &PAGE_WRITE ; pte_attrs = full->pte_attrs; pte_secure = full->attrs.secure; +#else +g_assert_not_reached (); +#endif }if (regime_is_stage2 (s2_mmu_idx)) {
Signature · 1 line
2.35.3