target/arm: CONFIG_TCG=n part 1
cover target/arm: CONFIG_TCG=n part 1
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]
This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]
Claudio Fontana (5):
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
Fabiano Rosas (15):
target/arm: Move PC alignment check
target/arm: Move cpregs code out of cpu.h
target/arm: Move cpregs code into cpregs.c target/arm: Move define_debug_regs() to cpregs.c target/arm: Wrap breakpoint/watchpoint updates with tcg_enabled 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 target/arm: Move regime_using_lpae_format into internal.h target/arm: Don't access TCG code when debugging with KVM cpu-defs.h: Expose CPUTLBEntryFull to non-TCG code target/arm: Move cortex sysregs into cpregs.c tests/qtest: Restrict bcm2835-dma-test to CONFIG_RASPI tests/avocado: Skip tests that require a missing accelerator tests/avocado: Tag TCG tests with accel:tcg
MAINTAINERS | 1 +
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 | 9533 +++++++++++++++++++++++
target/arm/cpregs.h | 104 +
target/arm/cpu.c | 9 +-
target/arm/cpu.h | 91 -
target/arm/cpu64.c | 1 +
target/arm/cpu_tcg.c | 59 -
target/arm/helper.c | 9461 +---------------------
target/arm/internals.h | 38 +-
target/arm/machine.c | 30 +-
target/arm/meson.build | 48 +-
target/arm/ptw.c | 4 +
target/arm/tcg-stubs.c | 27 +
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 | 0
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 | 0
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 | 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}/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/avocado/avocado_qemu/__init__.py | 4 +
tests/avocado/boot_linux_console.py | 1 +
tests/avocado/reverse_debugging.py | 8 +
tests/qtest/meson.build | 4 +-
64 files changed, 10210 insertions(+), 10060 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 (100%)
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 (100%)
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 (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}/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
PATCH 1/20 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
@@ -10803,7 +10803,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;
@@ -10865,7 +10865,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
PATCH 2/20 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"
@@ -10852,7 +10853,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
PATCH 3/20 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
@@ -10616,11 +10616,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
PATCH 4/20 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
PATCH 5/20 target/arm: Move cpregs code out of cpu.h
In reply to Fabiano RosasSince commit cf7c6d1004 ("target/arm: Split out cpregs.h") we now have a cpregs.h header which is more suitable for this code.
Code moved verbatim.
--- target/arm/cpregs.h | 98 +++++++++++++++++++++++++++++++++++++++++++++ target/arm/cpu.h | 91 ----------------------------------------- 2 files changed, 98 insertions(+), 91 deletions(-)
target/arm/cpregs.h +98 -0
@@ -120,6 +120,104 @@ enum { ARM_CP_SME = 1 << 19, }; +/* +* Interface for defining coprocessor registers. +* Registers are defined in tables of arm_cp_reginfo structs +* which are passed to define_arm_cp_regs(). +*/ + +/* +* When looking up a coprocessor register we look for it +* via an integer which encodes all of: +* coprocessor number +* Crn, Crm, opc1, opc2 fields +* 32 or 64 bit register (ie is it accessed via MRC/MCR +* or via MRRC/MCRR?) +* non-secure/secure bank (AArch32 only) +* We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field. +* (In this case crn and opc2 should be zero.) +* For AArch64, there is no 32/64 bit size distinction; +* instead all registers have a 2 bit op0, 3 bit op1 and op2, +* and 4 bit CRn and CRm. The encoding patterns are chosen +* to be easy to convert to and from the KVM encodings, and also +* so that the hashtable can contain both AArch32 and AArch64 +* registers (to allow for interprocessing where we might run +* 32 bit code on a 64 bit core). +*/ +/* +* This bit is private to our hashtable cpreg; in KVM register +* IDs the AArch64/32 distinction is the KVM_REG_ARM/ARM64 +* in the upper bits of the 64 bit ID. +*/ +#define CP_REG_AA64_SHIFT 28 +#define CP_REG_AA64_MASK (1 << CP_REG_AA64_SHIFT) + +/* +* To enable banking of coprocessor registers depending on ns-bit we +* add a bit to distinguish between secure and non-secure cpregs in the +* hashtable. +*/ +#define CP_REG_NS_SHIFT 29 +#define CP_REG_NS_MASK (1 << CP_REG_NS_SHIFT) + +#define ENCODE_CP_REG (cp, is64, ns, crn, crm, opc1, opc2) \ + ((ns) << CP_REG_NS_SHIFT | ((cp) << 16) | ((is64) << 15) | \ + ((crn) << 11) | ((crm) << 7) | ((opc1) << 3) | (opc2)) + +#define ENCODE_AA64_CP_REG (cp, crn, crm, op0, op1, op2) \ + (CP_REG_AA64_MASK | \ + ((cp) << CP_REG_ARM_COPROC_SHIFT) | \ + ((op0) << CP_REG_ARM64_SYSREG_OP0_SHIFT) | \ + ((op1) << CP_REG_ARM64_SYSREG_OP1_SHIFT) | \ + ((crn) << CP_REG_ARM64_SYSREG_CRN_SHIFT) | \ + ((crm) << CP_REG_ARM64_SYSREG_CRM_SHIFT) | \ + ((op2) << CP_REG_ARM64_SYSREG_OP2_SHIFT)) + +/* +* Convert a full 64 bit KVM register ID to the truncated 32 bit +* version used as a key for the coprocessor register hashtable +*/ +static inline uint32_t kvm_to_cpreg_id (uint64_t kvmid) +{ +uint32_t cpregid = kvmid; +if ((kvmid &CP_REG_ARCH_MASK ) ==CP_REG_ARM64 ) { + cpregid |=CP_REG_AA64_MASK ; + }else { +if ((kvmid &CP_REG_SIZE_MASK ) ==CP_REG_SIZE_U64 ) { + cpregid |= (1 <<15 ); + } + +/* +* KVM is always non-secure so add the NS flag on AArch32 register +* entries. +*/ + cpregid |=1 <<CP_REG_NS_SHIFT ; + } +return cpregid; +} + +/* +* Convert a truncated 32 bit hashtable key into the full +* 64 bit KVM register ID. +*/ +static inline uint64_t cpreg_to_kvm_id (uint32_t cpregid) +{ +uint64_t kvmid; + +if (cpregid &CP_REG_AA64_MASK ) { + kvmid = cpregid & ~CP_REG_AA64_MASK ; + kvmid |=CP_REG_SIZE_U64 |CP_REG_ARM64 ; + }else { + kvmid = cpregid & ~(1 <<15 ); +if (cpregid & (1 <<15 )) { + kvmid |=CP_REG_SIZE_U64 |CP_REG_ARM ; + }else { + kvmid |=CP_REG_SIZE_U32 |CP_REG_ARM ; + } + } +return kvmid; +} +/* * Valid values for ARMCPRegInfo state field, indicating which of * the AArch32 and AArch64 execution states this register is visible in.
target/arm/cpu.h +0 -91
97 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH 6/20 target/arm: Move cpregs code into cpregs.c
In reply to Fabiano RosasCode moved verbatim.
--- target/arm/cpregs.c | 9090 +++++++++++++++++++++++++++++++++++++++ target/arm/helper.c | 9067 -------------------------------------- target/arm/meson.build | 1 + target/arm/trace-events | 2 +- 4 files changed, 9092 insertions(+), 9068 deletions(-) create mode 100644 target/arm/cpregs.c
target/arm/cpregs.c new file +9090 -0
@@ -0,0 +1,9090 @@ +/* +* 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 ; + } +if (cpu_isar_feature (aa64_hcx, cpu)) { + valid_mask |=SCR_HXEN ; + } + }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 );
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.
PATCH 7/20 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 | 384 ++++++++++++++++++++++++++++++++++++++ target/arm/debug_helper.c | 367 ------------------------------------ target/arm/internals.h | 9 - 3 files changed, 384 insertions(+), 376 deletions(-)
target/arm/cpregs.c +384 -0
@@ -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"
@@ -287,6 +288,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.
@@ -6289,6 +6358,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.
@@ -6521,6 +6716,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/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)) | \
Signature · 1 line
2.35.3
PATCH 8/20 target/arm: Wrap breakpoint/watchpoint updates with tcg_enabled
In reply to Fabiano RosasThis is in preparation for moving debug_helper.c into a TCG-specific directory.
--- target/arm/cpu.c | 6 ++++-- target/arm/machine.c | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
target/arm/cpu.c +4 -2
@@ -536,8 +536,10 @@ 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/machine.c +5 -2
@@ -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"
@@ -848,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
PATCH 9/20 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.
---
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
@@ -161,6 +161,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
PATCH 10/20 target/arm: move helpers to tcg/
In reply to Fabiano RosasFrom: Claudio Fontana <[email protected]>
---
target/arm/meson.build | 16 ++--------------
target/arm/tcg-stubs.c | 23 +++++++++++++++++++++++
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, 39 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 +23 -0
@@ -0,0 +1,23 @@ +/* +* 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 (); +}
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
PATCH 11/20 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
PATCH 12/20 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.
--- hw/arm/boot.c | 6 +++++- hw/intc/armv7m_nvic.c | 20 +++++++++++++------- target/arm/arm-powerctl.c | 7 +++++-- target/arm/cpregs.c | 2 +- target/arm/cpu.c | 3 ++- target/arm/helper.c | 16 ++++++++++++---- target/arm/machine.c | 5 ++++- 7 files changed, 42 insertions(+), 17 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 +1 -1
@@ -5182,7 +5182,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
target/arm/cpu.c +2 -1
@@ -539,8 +539,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 +12 -4
@@ -339,7 +339,9 @@ void aarch64_set_svcr(CPUARMState *env, uint64_t new, uint64_t mask) memset(env->zarray, 0, sizeof(env->zarray)); } -arm_rebuild_hflags (env); +if (tcg_enabled ()) { +arm_rebuild_hflags (env); + } }#endif /* TARGET_AARCH64 */
@@ -608,7 +610,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); } }
@@ -1167,7 +1169,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)
@@ -1723,7 +1728,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 +4 -1
@@ -871,7 +871,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
PATCH 13/20 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 | 4 + target/arm/tcg/hflags.c | 370 +++++++++++++++++++++++++++++++++++++ target/arm/tcg/meson.build | 1 + 5 files changed, 378 insertions(+), 360 deletions(-) create mode 100644 target/arm/tcg/hflags.c
target/arm/helper.c +1 -360
@@ -238,32 +238,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. */
@@ -1872,7 +1846,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 );
@@ -2583,339 +2557,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 +4 -0
@@ -21,3 +21,7 @@ void raise_exception_ra(CPUARMState *env, uint32_t excp, uint32_t syndrome, {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
PATCH 14/20 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.
--- 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
PATCH 15/20 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.
--- 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
PATCH 16/20 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
PATCH 17/20 target/arm: Move cortex sysregs into cpregs.c
In reply to Fabiano RosasThe file cpu_tcg.c is about to be moved into the tcg/ directory, so move the register definitions into cpregs.c along with all the others.
--- target/arm/cpregs.c | 59 ++++++++++++++++++++++++++++++++++++++++++ target/arm/cpregs.h | 6 +++++ target/arm/cpu64.c | 1 + target/arm/cpu_tcg.c | 59 ------------------------------------------ target/arm/internals.h | 6 ----- 5 files changed, 66 insertions(+), 65 deletions(-)
target/arm/cpregs.c +59 -0
@@ -9472,3 +9472,62 @@ void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque) {/* Helper coprocessor reset function for do-nothing-on-reset registers */ } + +#ifndef CONFIG_USER_ONLY +static uint64_t l2ctlr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +ARMCPU *cpu =env_archcpu (env); + +/* Number of cores is in [25:24]; otherwise we RAZ */ +return (cpu->core_count -1 ) <<24 ; +} + +static const ARMCPRegInfo cortex_a72_a57_a53_cp_reginfo[] = { + { .name ="L2CTLR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =11 , .crm =0 , .opc2 =2 , + .access =PL1_RW , .readfn = l2ctlr_read, + .writefn = arm_cp_write_ignore }, + { .name ="L2CTLR" , + .cp =15 , .opc1 =1 , .crn =9 , .crm =0 , .opc2 =2 , + .access =PL1_RW , .readfn = l2ctlr_read, + .writefn = arm_cp_write_ignore }, + { .name ="L2ECTLR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =11 , .crm =0 , .opc2 =3 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="L2ECTLR" , + .cp =15 , .opc1 =1 , .crn =9 , .crm =0 , .opc2 =3 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="L2ACTLR" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =1 , .crn =15 , .crm =0 , .opc2 =0 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="CPUACTLR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =15 , .crm =2 , .opc2 =0 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="CPUACTLR" , + .cp =15 , .opc1 =0 , .crm =15 , + .access =PL1_RW , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, + { .name ="CPUECTLR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =15 , .crm =2 , .opc2 =1 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="CPUECTLR" , + .cp =15 , .opc1 =1 , .crm =15 , + .access =PL1_RW , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, + { .name ="CPUMERRSR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =15 , .crm =2 , .opc2 =2 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="CPUMERRSR" , + .cp =15 , .opc1 =2 , .crm =15 , + .access =PL1_RW , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, + { .name ="L2MERRSR_EL1" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =1 , .crn =15 , .crm =2 , .opc2 =3 , + .access =PL1_RW , .type =ARM_CP_CONST , .resetvalue =0 }, + { .name ="L2MERRSR" , + .cp =15 , .opc1 =3 , .crm =15 , + .access =PL1_RW , .type =ARM_CP_CONST |ARM_CP_64BIT , .resetvalue =0 }, +}; + +void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu) +{ +define_arm_cp_regs (cpu, cortex_a72_a57_a53_cp_reginfo); +} +#endif /* !CONFIG_USER_ONLY */
target/arm/cpregs.h +6 -0
@@ -591,4 +591,10 @@ static inline bool arm_cpreg_in_idspace(const ARMCPRegInfo *ri) ri->crn, ri->crm); } +#ifdef CONFIG_USER_ONLY +static inline void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu) { } +#else +void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu); +#endif +#endif /* TARGET_ARM_CPREGS_H */
target/arm/cpu64.c +1 -0
@@ -29,6 +29,7 @@#include "qapi/visitor.h" #include "hw/qdev-properties.h" #include "internals.h" +#include "cpregs.h" static void aarch64_a35_initfn (Object *obj) {
target/arm/cpu_tcg.c +0 -59
65 lines not on this page · raw message
target/arm/internals.h +0 -6
@@ -1366,12 +1366,6 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp);void arm_cpu_lpa2_finalize (ARMCPU *cpu,Error **errp);#endif -#ifdef CONFIG_USER_ONLY -static inline void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu) { } -#else -void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu); -#endif -bool el_is_in_host (CPUARMState *env,int el);void aa32_max_features (ARMCPU *cpu);
Signature · 1 line
2.35.3
PATCH 18/20 tests/qtest: Restrict bcm2835-dma-test to CONFIG_RASPI
In reply to Fabiano RosasWe will soon enable the build without TCG, which does not support many machines, so only run the bcm2835-dma-test when the corresponding machine is present.
--- tests/qtest/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qtest/meson.build +2 -2
@@ -207,11 +207,11 @@ qtests_aarch64 = \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-test'] : []) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ ['arm-cpu-features', 'numa-test', 'boot-serial-test', - 'migration-test', - 'bcm2835-dma-test'] + 'migration-test'] qtests_s390x = \ (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \
Signature · 1 line
2.35.3
PATCH 19/20 tests/avocado: Skip tests that require a missing accelerator
In reply to Fabiano RosasIf a test was tagged with the "accel" tag and the specified accelerator it not present in the qemu binary, cancel the test.
We can now write tests without explicit calls to require_accelerator, just the tag is enough.
--- tests/avocado/avocado_qemu/__init__.py | 4 ++++ 1 file changed, 4 insertions(+)
tests/avocado/avocado_qemu/__init__.py +4 -0
@@ -274,6 +274,10 @@ def setUp(self): super().setUp('qemu-system-') + accel_required = self._get_unique_tag_val('accel') + if accel_required: + self.require_accelerator(accel_required) + self.machine = self.params.get('machine', default=self._get_unique_tag_val('machine'))
Signature · 1 line
2.35.3
PATCH 20/20 tests/avocado: Tag TCG tests with accel:tcg
In reply to Fabiano RosasThis allows the test to be skipped when TCG is not present in the QEMU binary.
--- tests/avocado/boot_linux_console.py | 1 + tests/avocado/reverse_debugging.py | 8 ++++++++ 2 files changed, 9 insertions(+)
tests/avocado/boot_linux_console.py +1 -0
@@ -990,6 +990,7 @@ def test_arm_orangepi_uboot_netbsd9(self): def test_aarch64_raspi3_atf(self): """ + :avocado: tags=accel:tcg :avocado: tags=arch:aarch64 :avocado: tags=machine:raspi3b :avocado: tags=cpu:cortex-a53
tests/avocado/reverse_debugging.py +8 -0
@@ -173,6 +173,10 @@ def reverse_debugging(self, shift=7, args=None): vm.shutdown() class ReverseDebugging_X86_64(ReverseDebugging): + """ + :avocado: tags=accel:tcg + """ + REG_PC = 0x10 REG_CS = 0x12 def get_pc(self, g):
@@ -190,6 +194,10 @@ def test_x86_64_pc(self): self.reverse_debugging() class ReverseDebugging_AArch64(ReverseDebugging): + """ + :avocado: tags=accel:tcg + """ + REG_PC = 32 # unidentified gitlab timeout problem
Signature · 1 line
2.35.3
Hi Fabiano,
Quoted 11 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]
$ git am 20230111_richard_henderson_target_arm_introduce_aarch64_set_svcr.mbx Applying: target/arm: Introduce aarch64_set_svcr $ git am ./20230118_farosas_target_arm_config_tcg_n_part_1.mbx Applying: target/arm: rename handle_semihosting to tcg_handle_semihosting Applying: target/arm: wrap psci call with tcg_enabled Applying: target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() Applying: target/arm: Move PC alignment check Applying: target/arm: Move cpregs code out of cpu.h Applying: target/arm: Move define_debug_regs() to cpregs.c error: target/arm/cpregs.c: does not exist in index Patch failed at 0006 target/arm: Move define_debug_regs() to cpregs.c
I am based on commit 7ec8aeb604 ("Merge tag 'pull-tpm-2023-01-17-1' of https://github.com/stefanberger/qemu-tpm into staging"), what am I missing?
Quoted 28 lines · Philippe Mathieu-Daudé
Hi Fabiano,
Quoted 11 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]$ git am 20230111_richard_henderson_target_arm_introduce_aarch64_set_svcr.mbx Applying: target/arm: Introduce aarch64_set_svcr $ git am ./20230118_farosas_target_arm_config_tcg_n_part_1.mbx Applying: target/arm: rename handle_semihosting to tcg_handle_semihosting Applying: target/arm: wrap psci call with tcg_enabled Applying: target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() Applying: target/arm: Move PC alignment check Applying: target/arm: Move cpregs code out of cpu.h Applying: target/arm: Move define_debug_regs() to cpregs.c error: target/arm/cpregs.c: does not exist in index Patch failed at 0006 target/arm: Move define_debug_regs() to cpregs.c
Quoted 2 lines
I am based on commit
7ec8aeb604("Merge tag 'pull-tpm-2023-01-17-1' of
https://github.com/stefanberger/qemu-tpm into staging"), what am I missing?
How did you fetch the series? You are missing patch 06. Maybe it is too big for the method you used?
Quoted 30 lines · Fabiano Rosas
Quoted 28 lines · Philippe Mathieu-Daudé
Hi Fabiano,
Quoted 11 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]$ git am 20230111_richard_henderson_target_arm_introduce_aarch64_set_svcr.mbx Applying: target/arm: Introduce aarch64_set_svcr $ git am ./20230118_farosas_target_arm_config_tcg_n_part_1.mbx Applying: target/arm: rename handle_semihosting to tcg_handle_semihosting Applying: target/arm: wrap psci call with tcg_enabled Applying: target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() Applying: target/arm: Move PC alignment check Applying: target/arm: Move cpregs code out of cpu.h Applying: target/arm: Move define_debug_regs() to cpregs.c error: target/arm/cpregs.c: does not exist in index Patch failed at 0006 target/arm: Move define_debug_regs() to cpregs.c
Quoted 5 lines
Quoted 2 lines
I am based on commit
7ec8aeb604("Merge tag 'pull-tpm-2023-01-17-1' of
https://github.com/stefanberger/qemu-tpm into staging"), what am I missing?How did you fetch the series? You are missing patch 06. Maybe it is too big for the method you used?
Actually the tool warned about patch 6 missing, but I didn't notice:
$ b4 am [email protected] Grabbing thread from lore.kernel.org/all/20230118193518.26433-1-farosas%40suse.de/t.mbox.gz Analyzing 20 messages in the thread Checking attestation on all messages, may take a moment... --- ✓ [PATCH 1/20] target/arm: rename handle_semihosting to tcg_handle_semihosting ✓ Signed: DKIM/suse.de ✓ [PATCH 2/20] target/arm: wrap psci call with tcg_enabled ✓ Signed: DKIM/suse.de ✓ [PATCH 3/20] target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() ✓ Signed: DKIM/suse.de ✓ [PATCH 4/20] target/arm: Move PC alignment check ✓ Signed: DKIM/suse.de ✓ [PATCH 5/20] target/arm: Move cpregs code out of cpu.h ✓ Signed: DKIM/suse.de ERROR: missing [6/20]! ✓ [PATCH 7/20] target/arm: Move define_debug_regs() to cpregs.c ✓ Signed: DKIM/suse.de ✓ [PATCH 8/20] target/arm: Wrap breakpoint/watchpoint updates with tcg_enabled ✓ Signed: DKIM/suse.de ✓ [PATCH 9/20] target/arm: move translate modules to tcg/ ✓ Signed: DKIM/suse.de ✓ [PATCH 10/20] target/arm: move helpers to tcg/ ✓ Signed: DKIM/suse.de ✓ [PATCH 11/20] target/arm: Move psci.c into the tcg directory ✓ Signed: DKIM/suse.de ✓ [PATCH 12/20] target/arm: Wrap arm_rebuild_hflags calls with tcg_enabled ✓ Signed: DKIM/suse.de ✓ [PATCH 13/20] target/arm: Move hflags code into the tcg directory ✓ Signed: DKIM/suse.de ✓ [PATCH 14/20] target/arm: Move regime_using_lpae_format into internal.h ✓ Signed: DKIM/suse.de ✓ [PATCH 15/20] target/arm: Don't access TCG code when debugging with KVM ✓ Signed: DKIM/suse.de ✓ [PATCH 16/20] cpu-defs.h: Expose CPUTLBEntryFull to non-TCG code ✓ Signed: DKIM/suse.de ✓ [PATCH 17/20] target/arm: Move cortex sysregs into cpregs.c ✓ Signed: DKIM/suse.de ✓ [PATCH 18/20] tests/qtest: Restrict bcm2835-dma-test to CONFIG_RASPI ✓ Signed: DKIM/suse.de ✓ [PATCH 19/20] tests/avocado: Skip tests that require a missing accelerator ✓ Signed: DKIM/suse.de ✓ [PATCH 20/20] tests/avocado: Tag TCG tests with accel:tcg ✓ Signed: DKIM/suse.de --- Total patches: 19 --- WARNING: Thread incomplete!
Indeed patch 6 is missing:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 27 lines · Fabiano Rosas
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]$ git am 20230111_richard_henderson_target_arm_introduce_aarch64_set_svcr.mbx Applying: target/arm: Introduce aarch64_set_svcr $ git am ./20230118_farosas_target_arm_config_tcg_n_part_1.mbx Applying: target/arm: rename handle_semihosting to tcg_handle_semihosting Applying: target/arm: wrap psci call with tcg_enabled Applying: target/arm: wrap call to aarch64_sve_change_el in tcg_enabled() Applying: target/arm: Move PC alignment check Applying: target/arm: Move cpregs code out of cpu.h Applying: target/arm: Move define_debug_regs() to cpregs.c error: target/arm/cpregs.c: does not exist in index Patch failed at 0006 target/arm: Move define_debug_regs() to cpregs.cQuoted 5 lines
Quoted 2 lines
I am based on commit
7ec8aeb604("Merge tag 'pull-tpm-2023-01-17-1' of
https://github.com/stefanberger/qemu-tpm into staging"), what am I missing?How did you fetch the series? You are missing patch 06. Maybe it is too big for the method you used?
Actually the tool warned about patch 6 missing, but I didn't notice:
$ b4 am [email protected] Grabbing thread from lore.kernel.org/all/20230118193518.26433-1-farosas%40suse.de/t.mbox.gz Analyzing 20 messages in the thread Checking attestation on all messages, may take a moment... ---
...
Quoted 5 lines
✓ [PATCH 5/20] target/arm: Move cpregs code out of
cpu.h✓ Signed: DKIM/suse.de
ERROR: missing [6/20]!
✓ [PATCH 7/20] target/arm: Movedefine_debug_regs()tocpregs.c✓ Signed: DKIM/suse.de
...
Quoted 7 lines
---
Total patches: 19
---
WARNING: Thread incomplete!Indeed patch 6 is missing:
https://lore.kernel.org/qemu-devel/[email protected]/
I could find it here:
https://marc.info/?l=qemu-arm&m=167407090423121
Quoted 19 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]Claudio Fontana (5):
target/arm: renamehandle_semihostingtotcg_handle_semihostingtarget/arm: wrap psci call withtcg_enabledtarget/arm: wrap call toaarch64_sve_change_elintcg_enabled()target/arm: move helpers to tcg/
target/arm: Movepsci.cinto the tcg directory
Quoted 16 lines
Fabiano Rosas (15):
target/arm: Move PC alignment check
target/arm: Move cpregs code out ofcpu.htarget/arm: Move cpregs code intocpregs.ctarget/arm: Movedefine_debug_regs()tocpregs.ctarget/arm: Wrap breakpoint/watchpoint updates withtcg_enabledtarget/arm: move translate modules to tcg/ target/arm: Wraparm_rebuild_hflagscalls withtcg_enabledtarget/arm: Move hflags code into the tcg directory target/arm: Moveregime_using_lpae_formatintointernal.htarget/arm: Don't access TCG code when debugging with KVMcpu-defs.h: Expose CPUTLBEntryFull to non-TCG code target/arm: Move cortex sysregs intocpregs.ctests/qtest: Restrict bcm2835-dma-test toCONFIG_RASPItests/avocado: Skip tests that require a missing accelerator tests/avocado: Tag TCG tests with accel:tcg
Testing on Darwin:
14/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/test-hmp
ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached 17/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test
qemu-system-aarch64: unknown type 'arm-gicv3'
18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg
19/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/vnc-display-test
qemu-system-aarch64: No machine specified, and there is no default
20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg
Reproducers:
$ ./qemu-system-aarch64 -display none -S -M mps3-an547 -accel qtest -monitor stdio QEMU 7.2.50 monitor - type 'help' for more information (qemu) gva2gpa 0 ** ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Bail out! ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Abort trap: 6
frame #4: 0x0000000101fdd6cc
libglib-2.0.0.dylib`g_assertion_message_expr + 116
frame #5: 0x0000000100360ce0
qemu-system-aarch64`arm_v7m_mmu_idx_for_secstate(env=<unavailable>, secstate=<unavailable>) at helper.c:2495:5
frame #6: 0x000000010035f7f4
qemu-system-aarch64`arm_mmu_idx_el(env=<unavailable>, el=<unavailable>) at helper.c:2514:16
frame #7: 0x00000001002d17ec
qemu-system-aarch64`arm_cpu_get_phys_page_attrs_debug(cs=<unavailable>, addr=0, attrs=0x000000016fdfda50) at ptw.c:2982:23
frame #8: 0x00000001003c660c qemu-system-aarch64`hmp_gva2gpa(mon=0x000060000390f0c0, qdict=<unavailable>) at misc.c:714:12
$ ./qemu-system-aarch64 -display none -machine sbsa-ref -accel qtest qemu-system-aarch64: unknown type 'arm-gicv3' Abort trap: 6
frame #2: 0x00000001958522c8 libsystem_c.dylib`abort + 180
frame #3: 0x00000001003d32e8
qemu-system-aarch64`qdev_new(name="arm-gicv3") at qdev.c:164:9
frame #4: 0x00000001002f30d4 qemu-system-aarch64`sbsa_ref_init
[inlined] create_gic(sms=0x0000000103ff0d10) at sbsa-ref.c:405:16
frame #5: 0x00000001002f30a0
qemu-system-aarch64`sbsa_ref_init(machine=0x0000000103ff0d10) at sbsa-ref.c:773:5
frame #6: 0x00000001000905c0 qemu-system-aarch64`machine_run_board_init(machine=0x0000000103ff0d10, mem_path=<unavailable>, errp=<unavailable>) at machine.c:1404:5
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]
Quoted 6 lines
Testing on Darwin:
18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg 20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg
These two errors have been fixed by:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]
Quoted 7 lines
Quoted 2 lines
This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
Testing on Darwin:
19/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/vnc-display-test
qemu-system-aarch64: No machine specified, and there is no default
This one is fixed by:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Testing on Darwin:
17/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test qemu-system-aarch64: unknown type 'arm-gicv3'
Reproducers:
$ ./qemu-system-aarch64 -display none -machine sbsa-ref -accel qtest qemu-system-aarch64: unknown type 'arm-gicv3' Abort trap: 6
Quoted 9 lines
frame #2:
0x00000001958522c8libsystem_c.dylib`abort + 180
frame #3:0x00000001003d32e8
qemu-system-aarch64`qdev_new(name="arm-gicv3") at qdev.c:164:9
frame #4:0x00000001002f30d4qemu-system-aarch64`sbsa_ref_init
[inlined]create_gic(sms=0x0000000103ff0d10)at sbsa-ref.c:405:16
frame #5:0x00000001002f30a0
qemu-system-aarch64`sbsa_ref_init(machine=0x0000000103ff0d10) at sbsa-ref.c:773:5
frame #6:0x00000001000905c0
qemu-system-aarch64`machine_run_board_init(machine=0x0000000103ff0d10, mem_path=<unavailable>, errp=<unavailable>) at machine.c:1404:5
For this one, I *think* the sbsa-ref create_gic() should follow what the virt machine does to select the gic, generalizing Alex's changes from
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 94 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]Claudio Fontana (5):
target/arm: renamehandle_semihostingtotcg_handle_semihostingtarget/arm: wrap psci call withtcg_enabledtarget/arm: wrap call toaarch64_sve_change_elintcg_enabled()target/arm: move helpers to tcg/
target/arm: Movepsci.cinto the tcg directoryQuoted 16 lines
Fabiano Rosas (15):
target/arm: Move PC alignment check
target/arm: Move cpregs code out ofcpu.htarget/arm: Move cpregs code intocpregs.ctarget/arm: Movedefine_debug_regs()tocpregs.ctarget/arm: Wrap breakpoint/watchpoint updates withtcg_enabledtarget/arm: move translate modules to tcg/ target/arm: Wraparm_rebuild_hflagscalls withtcg_enabledtarget/arm: Move hflags code into the tcg directory target/arm: Moveregime_using_lpae_formatintointernal.htarget/arm: Don't access TCG code when debugging with KVMcpu-defs.h: Expose CPUTLBEntryFull to non-TCG code target/arm: Move cortex sysregs intocpregs.ctests/qtest: Restrict bcm2835-dma-test toCONFIG_RASPItests/avocado: Skip tests that require a missing accelerator tests/avocado: Tag TCG tests with accel:tcgTesting on Darwin:
14/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/test-hmp
ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached
17/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test
qemu-system-aarch64: unknown type 'arm-gicv3'
18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg 19/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/vnc-display-test
qemu-system-aarch64: No machine specified, and there is no default 20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcgReproducers:
$ ./qemu-system-aarch64 -display none -S -M mps3-an547 -accel qtest -monitor stdio QEMU 7.2.50 monitor - type 'help' for more information (qemu) gva2gpa 0 ** ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Bail out! ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Abort trap: 6frame #4: 0x0000000101fdd6cc libglib-2.0.0.dylib`g_assertion_message_expr + 116 frame #5: 0x0000000100360ce0 qemu-system-aarch64`arm_v7m_mmu_idx_for_secstate(env=<unavailable>, secstate=<unavailable>) at helper.c:2495:5 frame #6: 0x000000010035f7f4 qemu-system-aarch64`arm_mmu_idx_el(env=<unavailable>, el=<unavailable>) at helper.c:2514:16 frame #7: 0x00000001002d17ec qemu-system-aarch64`arm_cpu_get_phys_page_attrs_debug(cs=<unavailable>, addr=0, attrs=0x000000016fdfda50) at ptw.c:2982:23 frame #8: 0x00000001003c660cqemu-system-aarch64`hmp_gva2gpa(mon=0x000060000390f0c0, qdict=<unavailable>) at misc.c:714:12
$ ./qemu-system-aarch64 -display none -machine sbsa-ref -accel qtest qemu-system-aarch64: unknown type 'arm-gicv3' Abort trap: 6frame #2: 0x00000001958522c8 libsystem_c.dylib`abort + 180 frame #3: 0x00000001003d32e8 qemu-system-aarch64`qdev_new(name="arm-gicv3") at qdev.c:164:9 frame #4: 0x00000001002f30d4 qemu-system-aarch64`sbsa_ref_init [inlined] create_gic(sms=0x0000000103ff0d10) at sbsa-ref.c:405:16 frame #5: 0x00000001002f30a0 qemu-system-aarch64`sbsa_ref_init(machine=0x0000000103ff0d10) at sbsa-ref.c:773:5 frame #6: 0x00000001000905c0
Quoted 2 lines
qemu-system-aarch64`machine_run_board_init(machine=0x0000000103ff0d10, mem_path=<unavailable>, errp=<unavailable>) at machine.c:1404:5
Are these errors without TCG? If so they will be fixed by the other half of the series by removing the machines/cpus that depend on TCG. Nothing against fixing this now in the specific tests, of course, but a user on the cmdline would also hit these.
Quoted 9 lines · Fabiano Rosas
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
Are you saying, we can *link* this configuration but not *run* it yet?
Quoted 89 lines
Quoted 86 lines
Quoted 12 lines
For the build _with_ TCG, this should behave the same as master.
Based on Richard's "target/arm: Introduce
aarch64_set_svcr":
https://lore.kernel.org/r/[email protected]Claudio Fontana (5):
target/arm: renamehandle_semihostingtotcg_handle_semihostingtarget/arm: wrap psci call withtcg_enabledtarget/arm: wrap call toaarch64_sve_change_elintcg_enabled()target/arm: move helpers to tcg/
target/arm: Movepsci.cinto the tcg directoryQuoted 16 lines
Fabiano Rosas (15):
target/arm: Move PC alignment check
target/arm: Move cpregs code out ofcpu.htarget/arm: Move cpregs code intocpregs.ctarget/arm: Movedefine_debug_regs()tocpregs.ctarget/arm: Wrap breakpoint/watchpoint updates withtcg_enabledtarget/arm: move translate modules to tcg/ target/arm: Wraparm_rebuild_hflagscalls withtcg_enabledtarget/arm: Move hflags code into the tcg directory target/arm: Moveregime_using_lpae_formatintointernal.htarget/arm: Don't access TCG code when debugging with KVMcpu-defs.h: Expose CPUTLBEntryFull to non-TCG code target/arm: Move cortex sysregs intocpregs.ctests/qtest: Restrict bcm2835-dma-test toCONFIG_RASPItests/avocado: Skip tests that require a missing accelerator tests/avocado: Tag TCG tests with accel:tcgTesting on Darwin:
14/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/test-hmp
ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached
17/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test
qemu-system-aarch64: unknown type 'arm-gicv3'
18/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/boot-serial-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcg 19/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/vnc-display-test
qemu-system-aarch64: No machine specified, and there is no default 20/20 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test
qemu-system-aarch64: -accel tcg: invalid accelerator tcgReproducers:
$ ./qemu-system-aarch64 -display none -S -M mps3-an547 -accel qtest -monitor stdio QEMU 7.2.50 monitor - type 'help' for more information (qemu) gva2gpa 0 ** ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Bail out! ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Abort trap: 6frame #4: 0x0000000101fdd6cc libglib-2.0.0.dylib`g_assertion_message_expr + 116 frame #5: 0x0000000100360ce0 qemu-system-aarch64`arm_v7m_mmu_idx_for_secstate(env=<unavailable>, secstate=<unavailable>) at helper.c:2495:5 frame #6: 0x000000010035f7f4 qemu-system-aarch64`arm_mmu_idx_el(env=<unavailable>, el=<unavailable>) at helper.c:2514:16 frame #7: 0x00000001002d17ec qemu-system-aarch64`arm_cpu_get_phys_page_attrs_debug(cs=<unavailable>, addr=0, attrs=0x000000016fdfda50) at ptw.c:2982:23 frame #8: 0x00000001003c660cqemu-system-aarch64`hmp_gva2gpa(mon=0x000060000390f0c0, qdict=<unavailable>) at misc.c:714:12
$ ./qemu-system-aarch64 -display none -machine sbsa-ref -accel qtest qemu-system-aarch64: unknown type 'arm-gicv3' Abort trap: 6frame #2: 0x00000001958522c8 libsystem_c.dylib`abort + 180 frame #3: 0x00000001003d32e8 qemu-system-aarch64`qdev_new(name="arm-gicv3") at qdev.c:164:9 frame #4: 0x00000001002f30d4 qemu-system-aarch64`sbsa_ref_init [inlined] create_gic(sms=0x0000000103ff0d10) at sbsa-ref.c:405:16 frame #5: 0x00000001002f30a0 qemu-system-aarch64`sbsa_ref_init(machine=0x0000000103ff0d10) at sbsa-ref.c:773:5 frame #6: 0x00000001000905c0Quoted 2 lines
qemu-system-aarch64`machine_run_board_init(machine=0x0000000103ff0d10, mem_path=<unavailable>, errp=<unavailable>) at machine.c:1404:5
Quoted 1 line
Are these errors without TCG?
Yes.
Quoted 4 lines
If so they will be fixed by the other half
of the series by removing the machines/cpus that depend on TCG. Nothing against fixing this now in the specific tests, of course, but a user on the cmdline would also hit these.
I ran 'make check' which calls 'make check-qtest' -> 'make check-qtest-aarch64'.
Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Fabiano Rosas
Quoted 1 line · Philippe Mathieu-Daudé
On 18/1/23 20:34, Fabiano Rosas wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
Are you saying, we can *link* this configuration but not *run* it yet?
Strictly speaking, we cannot run it. While it works most of the time, there are still references to machines and cpus that are TCG-only. Try running -machine ? or -cpu ? for instance. If a user tries to pass one of those, there might be breakages like the ones you saw.
The other series (I just sent a v4) removes everything that depends on TCG. Then it will be 100% safe to use --disable-tcg and consume the result.
Philippe Mathieu-Daudé
Tested-byQuoted 21 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
Reproducers:
$ ./qemu-system-aarch64 -display none -S -M mps3-an547 -accel qtest -monitor stdio QEMU 7.2.50 monitor - type 'help' for more information (qemu) gva2gpa 0 ** ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Bail out! ERROR:../../target/arm/helper.c:2495:arm_v7m_mmu_idx_for_secstate: code should not be reached Abort trap: 6
Quoted 10 lines
frame #4:
0x0000000101fdd6cc
libglib-2.0.0.dylib`g_assertion_message_expr + 116
frame #5:0x0000000100360ce0
qemu-system-aarch64`arm_v7m_mmu_idx_for_secstate(env=<unavailable>, secstate=<unavailable>) at helper.c:2495:5
frame #6:0x000000010035f7f4
qemu-system-aarch64`arm_mmu_idx_el(env=<unavailable>, el=<unavailable>) at helper.c:2514:16
frame #7:0x00000001002d17ec
qemu-system-aarch64`arm_cpu_get_phys_page_attrs_debug(cs=<unavailable>, addr=0, attrs=0x000000016fdfda50) at ptw.c:2982:23
frame #8:0x00000001003c660c
qemu-system-aarch64`hmp_gva2gpa(mon=0x000060000390f0c0, qdict=<unavailable>) at misc.c:714:12
This problem was previously fixed by this series:
https://www.mail-archive.com/[email protected]/msg777719.html
In particular by this patch:
https://www.mail-archive.com/[email protected]/msg777724.html
Since all issues have been identified:
Quoted 8 lines · Fabiano Rosas
These are the already reviewed patches from the first half of my previous series:
https://lore.kernel.org/r/[email protected]This unbreaks the --disable-tcg build, but there are issues in runtime that are still being hashed out in the other series.
For the build _with_ TCG, this should behave the same as master.
If you respin, please include this build-only CI test to avoid your work to bitrot until the rest is merged:
https://lore.kernel.org/qemu-devel/[email protected]/
Peter, if this is good enough for you please consider the CI patch on top of this series.
Regards,
Phil.