target/arm: More v8.1M features
cover target/arm: More v8.1M features
This patchset implements a somewhat miscellaneous collection of new-in-v8.1M features, as well as some bugfixes. It's for-6.0 material.
In the bugfix category:
* RAZWI (or BusFault for unprivileged accesses) the whole of the system PPB address range, not just the SCS
* Don't clobber ID_PFR1.Security on M-profile
* Don't allow VMRS/VMSR to fp sysregs that don't exist on M-profile
In the features category:
* v8.1M PXN extension
* VSCCLRM and CLRM insns
* VLDR/VSTR (sysreg) insns
* new M-profile fp sysregs: FPSCR_nzcvqc, FPCXT_S, FPCXT_NS
* update FPDSCR masking to allow new-in-v8.1M bits in that register
As usual, none of this will be enabled until we eventually get to the point of a complete v8.1M implementation and can define a Cortex-M55 CPU model.
thanks
-- PMM
Peter Maydell (15):
hw/intc/armv7m_nvic: Make all of system PPB range be RAZWI/BusFault target/arm: Implement v8.1M PXN extension
target/arm: Don't clobber ID_PFR1.Security on M-profile cores target/arm: Implement VSCCLRM insn
target/arm: Implement CLRM instruction
target/arm: Enforce M-profile VMRS/VMSR register restrictions target/arm: Refactor M-profile VMSR/VMRS handling target/arm: Move general-use constant expanders up in translate.c target/arm: Implement VLDR/VSTR system register target/arm: Implement M-profile FPSCR_nzcvqc
target/arm: Use new FPCR_NZCV_MASK constant
target/arm: Factor out preserve-fp-state from full_vfp_access_check() target/arm: Implement FPCXT_S fp system register target/arm: Implement FPCXT_NS fp system register hw/intc/armv7m_nvic: Update FPDSCR masking for v8.1M
include/hw/intc/armv7m_nvic.h | 1 + target/arm/cpu.h | 30 ++ target/arm/m-nocp.decode | 8 +- target/arm/t32.decode | 6 +- target/arm/vfp.decode | 14 + hw/arm/armv7m.c | 2 +- hw/intc/armv7m_nvic.c | 87 ++++- target/arm/cpu.c | 5 +- target/arm/helper.c | 7 +- target/arm/translate.c | 102 ++++-- target/arm/translate-vfp.c.inc | 581 +++++++++++++++++++++++++++++++-- 11 files changed, 765 insertions(+), 78 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/15 hw/intc/armv7m_nvic: Make all of system PPB range be RAZWI/BusFault
For M-profile CPUs, the range from 0xe0000000 to 0xe00fffff is the Private Peripheral Bus range, which includes all of the memory mapped devices and registers that are part of the CPU itself, including the NVIC, systick timer, and debug and trace components like the Data Watchpoint and Trace unit (DWT). Within this large region, the range 0xe000e000 to 0xe000efff is the System Control Space (NVIC, system registers, systick) and 0xe002e000 to 0exe002efff is its Non-secure alias.
The architecture is clear that within the SCS unimplemented registers should be RES0 for privileged accesses and generate BusFault for unprivileged accesses, and we currently implement this.
It is less clear about how to handle accesses to unimplemented regions of the wider PPB. Unprivileged accesses should definitely cause BusFaults (R_DQQS), but the behaviour of privileged accesses is not given as a general rule. However, the register definitions of individual registers for components like the DWT all state that they are RES0 if the relevant component is not implemented, so the simplest way to provide that is to provide RAZ/WI for the whole range for privileged accesses. (The v7M Arm ARM does say that reserved registers should be UNK/SBZP.)
Expand the container MemoryRegion that the NVIC exposes so that it covers the whole PPB space. This means:
* moving the address that the ARMV7M device maps it to down by 0xe000 bytes
* moving the off and the offsets within the container of all the subregions forward by 0xe000 bytes
* adding a new default MemoryRegion that covers the whole container at a lower priority than anything else and which provides the RAZWI/BusFault behaviour
--- include/hw/intc/armv7m_nvic.h | 1 + hw/arm/armv7m.c | 2 +- hw/intc/armv7m_nvic.c | 78 ++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 12 deletions(-)
include/hw/intc/armv7m_nvic.h +1 -0
@@ -84,6 +84,7 @@ struct NVICState {MemoryRegion systickmem;MemoryRegion systick_ns_mem;MemoryRegion container; +MemoryRegion defaultmem;uint32_t num_irq;qemu_irq excpout;
hw/arm/armv7m.c +1 -1
@@ -225,7 +225,7 @@ static void armv7m_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (DEVICE (s->cpu),ARM_CPU_IRQ )); -memory_region_add_subregion (&s->container,0xe000e000 , +memory_region_add_subregion (&s->container,0xe0000000 ,sysbus_mmio_get_region (sbd,0 ));for (i =0 ; i <ARRAY_SIZE (s->bitband); i++) {
hw/intc/armv7m_nvic.c +67 -11
119 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 01/15] hw/intc/armv7m_nvic: Make all of system PPB range be RAZWI/BusFault
Quoted 33 lines · Peter Maydell
For M-profile CPUs, the range from
0xe0000000to0xe00fffffis the Private Peripheral Bus range, which includes all of the memory mapped devices and registers that are part of the CPU itself, including the NVIC, systick timer, and debug and trace components like the Data Watchpoint and Trace unit (DWT). Within this large region, the range0xe000e000to0xe000efffis the System Control Space (NVIC, system registers, systick) and0xe002e000to 0exe002efff is its Non-secure alias.The architecture is clear that within the SCS unimplemented registers should be RES0 for privileged accesses and generate BusFault for unprivileged accesses, and we currently implement this.
It is less clear about how to handle accesses to unimplemented regions of the wider PPB. Unprivileged accesses should definitely cause BusFaults (
R_DQQS), but the behaviour of privileged accesses is not given as a general rule. However, the register definitions of individual registers for components like the DWT all state that they are RES0 if the relevant component is not implemented, so the simplest way to provide that is to provide RAZ/WI for the whole range for privileged accesses. (The v7M Arm ARM does say that reserved registers should be UNK/SBZP.)Expand the container MemoryRegion that the NVIC exposes so that it covers the whole PPB space. This means:
* moving the address that the ARMV7M device maps it to down by0xe000bytes
* moving the off and the offsets within the container of all the subregions forward by0xe000bytes
* adding a new default MemoryRegion that covers the whole container at a lower priority than anything else and which provides the RAZWI/BusFault behaviour
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>---
r~
PATCH 2/15 target/arm: Implement v8.1M PXN extension
In reply to Peter MaydellIn v8.1M the PXN architecture extension adds a new PXN bit to the MPU_RLAR registers, which forbids execution of code in the region from a privileged mode.
This is another feature which is just in the generic "in v8.1M" set and has no ID register field indicating its presence.
--- target/arm/helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/arm/helper.c +6 -1
@@ -11754,6 +11754,11 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, }else {uint32_t ap =extract32 (env->pmsav8.rbar[secure][matchregion],1 ,2 );uint32_t xn =extract32 (env->pmsav8.rbar[secure][matchregion],0 ,1 ); +bool pxn = false; + +if (arm_feature (env,ARM_FEATURE_V8_1M )) { + pxn =extract32 (env->pmsav8.rlar[secure][matchregion],4 ,1 ); + }if (m_is_system_region (env, address)) {/* System space is always execute never */
@@ -11761,7 +11766,7 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, } *prot =simple_ap_to_rw_prot (env, mmu_idx, ap); -if (*prot && !xn) { +if (*prot && !xn && !(pxn && !is_user)) { *prot |=PAGE_EXEC ; }/* We don't need to look the attribute up in the MAIR0/MAIR1
Signature · 1 line
2.20.1
Re: [PATCH 02/15] target/arm: Implement v8.1M PXN extension
Quoted 11 lines · Peter Maydell
In v8.1M the PXN architecture extension adds a new PXN bit to the
MPU_RLARregisters, which forbids execution of code in the region from a privileged mode.This is another feature which is just in the generic "in v8.1M" set and has no ID register field indicating its presence.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
r~
PATCH 3/15 target/arm: Don't clobber ID_PFR1.Security on M-profile cores
In reply to Peter MaydellIn arm_cpu_realizefn() we check whether the board code disabled EL3 via the has_el3 CPU object property, which we create if the CPU starts with the ARM_FEATURE_EL3 feature bit. If it is disabled, then we turn off ARM_FEATURE_EL3 and also zero out the relevant fields in the ID_PFR1 and ID_AA64PFR0 registers.
This codepath was incorrectly being taken for M-profile CPUs, which do not have an EL3 and don't set ARM_FEATURE_EL3, but which may have the M-profile Security extension and so should have non-zero values in the ID_PFR1.Security field.
Restrict the handling of the feature flag to A/R-profile cores.
--- target/arm/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.c +1 -1
@@ -1674,7 +1674,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } } -if (!cpu->has_el3) { +if (!arm_feature (env,ARM_FEATURE_M ) && !cpu->has_el3) {/* If the has_el3 CPU property is disabled then we need to disable the * feature. */
Signature · 1 line
2.20.1
Re: [PATCH 03/15] target/arm: Don't clobber ID_PFR1.Security on M-profile cores
Quoted 11 lines · Peter Maydell
In
arm_cpu_realizefn()we check whether the board code disabled EL3 via thehas_el3CPU object property, which we create if the CPU starts with theARM_FEATURE_EL3feature bit. If it is disabled, then we turn offARM_FEATURE_EL3and also zero out the relevant fields in theID_PFR1andID_AA64PFR0registers.This codepath was incorrectly being taken for M-profile CPUs, which do not have an EL3 and don't set
ARM_FEATURE_EL3, but which may have the M-profile Security extension and so should have non-zero values in the ID_PFR1.Security field.
Quoted 6 lines
Restrict the handling of the feature flag to A/R-profile cores.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 4/15 target/arm: Implement VSCCLRM insn
In reply to Peter MaydellImplement the v8.1M VSCCLRM insn, which zeros floating point registers if there is an active floating point context.
Because we want to use arm_gen_condlabel(), we need to move the definition of that function up in translate.c so it is before the #include of translate-vfp.c.inc.
--- target/arm/cpu.h | 9 ++++ target/arm/m-nocp.decode | 8 +++- target/arm/translate.c | 18 +++---- target/arm/translate-vfp.c.inc | 86 ++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 11 deletions(-)
target/arm/cpu.h +9 -0
@@ -3555,6 +3555,15 @@ static inline bool isar_feature_aa32_mprofile(const ARMISARegisters *id)return FIELD_EX32 (id->id_pfr1,ID_PFR1 ,MPROGMOD ) !=0 ; } +static inline bool isar_feature_aa32_m_sec_state (const ARMISARegisters *id) +{ +/* +* Return true if M-profile state handling insns +* (VSCCLRM, CLRM, FPCTX access insns) are implemented +*/ +return FIELD_EX32 (id->id_pfr1,ID_PFR1 ,SECURITY ) >=3 ; +} +static inline bool isar_feature_aa32_fp16_arith (const ARMISARegisters *id) {/* Sadly this is encoded differently for A-profile and M-profile */
target/arm/m-nocp.decode +6 -2
@@ -29,13 +29,17 @@ # If the coprocessor is not present or disabled then we will generate # the NOCP exception; otherwise we let the insn through to the main decode. +%vd_dp 22:1 12:4 +%vd_sp 12:4 22:1 + &nocp cp { # Special cases which do not take an early NOCP: VLLDM and VLSTM VLLDM_VLSTM 1110 1100 001 l:1 rn:4 0000 1010 0000 0000 - # TODO: VSCCLRM (new in v8.1M) is similar: - #VSCCLRM 1110 1100 1-01 1111 ---- 1011 ---- ---0 + # VSCCLRM (new in v8.1M) is similar: + VSCCLRM 1110 1100 1.01 1111 .... 1011 imm:7 0 vd=%vd_dp size=3 + VSCCLRM 1110 1100 1.01 1111 .... 1010 imm:8 vd=%vd_sp size=2 NOCP 111- 1110 ---- ---- ---- cp:4 ---- ---- &nocp NOCP 111- 110- ---- ---- ---- cp:4 ---- ---- &nocp
target/arm/translate.c +9 -9
@@ -100,6 +100,15 @@ void arm_translate_init(void)a64_translate_init (); } +/* Generate a label used for skipping this instruction */ +static void arm_gen_condlabel (DisasContext *s) +{ +if (!s->condjmp) { + s->condlabel =gen_new_label (); + s->condjmp =1 ; + } +} +/* Flags for the disas_set_da_iss info argument: * lower bits hold the Rt register number, higher bits are flags. */
@@ -5156,15 +5165,6 @@ static void gen_srs(DisasContext *s, s->base.is_jmp =DISAS_UPDATE_EXIT ; } -/* Generate a label used for skipping this instruction */ -static void arm_gen_condlabel (DisasContext *s) -{ -if (!s->condjmp) { - s->condlabel =gen_new_label (); - s->condjmp =1 ; - } -} -/* Skip this instruction if the ARM condition is false */ static void arm_skip_unless (DisasContext *s,uint32_t cond) {
target/arm/translate-vfp.c.inc +86 -0
92 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 04/15] target/arm: Implement VSCCLRM insn
target/arm/translate-vfp.c.inc static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a) · line 3440
Quoted 4 lines · Peter Maydell
target/arm/translate-vfp.c.inc +4
-0+ aspen = load_cpu_field(v7m.fpccr[M_REG_S]); + sfpa = load_cpu_field(v7m.control[M_REG_S]); + tcg_gen_andi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK); + tcg_gen_subi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK);
xori would be clearer, i think.
Quoted 4 lines
target/arm/translate-vfp.c.inc +4
-0+ /* Zero the Sregs from btmreg to topreg inclusive. */ + zero64 = tcg_const_i64(0); + zero32 = tcg_const_i32(0); + if (btmreg & 1) {
target/arm/translate-vfp.c.inc static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a) · line 3489
Quoted 10 lines
target/arm/translate-vfp.c.inc +10
-0+ write_neon_element32(zero32, btmreg >> 1, 1, MO_32); + btmreg++; + } + for (; btmreg + 1 <= topreg; btmreg += 2) { + write_neon_element64(zero64, btmreg >> 1, 0, MO_64); + } + if (btmreg == topreg) { + write_neon_element32(zero32, btmreg >> 1, 0, MO_32); + btmreg++; + }
I hadn't implemented MO_32 for write_neon_element64 because there were no users. Better to just add the case there using tcg_gen_st32_i64, then you don't need a 32-bit zero.
Otherwise,
r~
PATCH 5/15 target/arm: Implement CLRM instruction
In reply to Peter MaydellIn v8.1M the new CLRM instruction allows zeroing an arbitrary set of the general-purpose registers and APSR. Implement this.
The encoding is a subset of the LDMIA T2 encoding, using what would be Rn=0b1111 (which UNDEFs for LDMIA).
--- target/arm/t32.decode | 6 +++++- target/arm/translate.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
target/arm/t32.decode +5 -1
@@ -609,7 +609,11 @@ UXTAB 1111 1010 0101 .... 1111 .... 10.. .... @rrr_rot STM_t32 1110 1000 10.0 .... ................ @ldstm i=1 b=0 STM_t32 1110 1001 00.0 .... ................ @ldstm i=0 b=1 -LDM_t32 1110 1000 10.1 .... ................ @ldstm i=1 b=0 +{ + # Rn=15 UNDEFs for LDM; M-profile CLRM uses that encoding + CLRM 1110 1000 1001 1111 list:16 + LDM_t32 1110 1000 10.1 .... ................ @ldstm i=1 b=0 +} LDM_t32 1110 1001 00.1 .... ................ @ldstm i=0 b=1 &rfe !extern rn w pu
target/arm/translate.c +38 -0
@@ -7965,6 +7965,44 @@ static bool trans_LDM_t16(DisasContext *s, arg_ldst_block *a)return do_ldm (s, a,1 ); } +static bool trans_CLRM (DisasContext *s,arg_CLRM *a) +{ +int i; +TCGv_i32 zero; + +if (!dc_isar_feature (aa32_m_sec_state, s)) { +return false; + } + +if (extract32 (a->list,13 ,1 )) { +return false; + } + +if (!a->list) { +/* UNPREDICTABLE; we choose to UNDEF */ +return false; + } + + zero =tcg_const_i32 (0 ); +for (i =0 ; i <15 ; i++) { +if (extract32 (a->list, i,1 )) { +/* Clear R[i] */ +tcg_gen_mov_i32 (cpu_R[i], zero); + } + } +if (extract32 (a->list,15 ,1 )) { +/* +* Clear APSR (by calling the MSR helper with the same argument +* as for "MSR APSR_nzcvqg, Rn": mask = 0b1100, SYSM=0) +*/ +TCGv_i32 maskreg =tcg_const_i32 (0xc <<8 ); +gen_helper_v7m_msr (cpu_env, maskreg, zero); +tcg_temp_free_i32 (maskreg); + } +tcg_temp_free_i32 (zero); +return true; +} +/* * Branch, branch with link */
Signature · 1 line
2.20.1
Re: [PATCH 05/15] target/arm: Implement CLRM instruction
Quoted 11 lines · Peter Maydell
In v8.1M the new CLRM instruction allows zeroing an arbitrary set of the general-purpose registers and APSR. Implement this.
The encoding is a subset of the LDMIA T2 encoding, using what would be Rn=0b1111 (which UNDEFs for LDMIA).
Signed-off-by Peter Maydell <[email protected]>--- target/arm/t32.decode | 6 +++++- target/arm/translate.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
r~
PATCH 6/15 target/arm: Enforce M-profile VMRS/VMSR register restrictions
In reply to Peter MaydellFor M-profile before v8.1M, the only valid register for VMSR/VMRS is the FPSCR. We have a comment that states this, but the actual logic to forbid accesses for any other register value is missing, so we would end up with A-profile style behaviour. Add the missing check.
--- target/arm/translate-vfp.c.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/arm/translate-vfp.c.inc +4 -1
@@ -622,7 +622,10 @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a) * Accesses to R15 are UNPREDICTABLE; we choose to undef. * (FPSCR -> r15 is a special case which writes to the PSR flags.) */ - if (a->rt == 15 && (!a->l || a->reg != ARM_VFP_FPSCR)) { + if (a->reg != ARM_VFP_FPSCR) { + return false; + } + if (a->rt == 15 && !a->l) { return false; } }
Signature · 1 line
2.20.1
Re: [PATCH 06/15] target/arm: Enforce M-profile VMRS/VMSR register restrictions
target/arm/translate-vfp.c.inc static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a) · line 628
Quoted 5 lines · Peter Maydell
target/arm/translate-vfp.c.inc +4
-1- if (a->rt == 15 && (!a->l || a->reg != ARM_VFP_FPSCR)) { + if (a->reg != ARM_VFP_FPSCR) { + return false; + } + if (a->rt == 15 && !a->l) {
Alternately, the parenthesis are just off:
if ((a->rt == 15 && !a->l) || a->reg != ARM_VFP_FPSCR)
Either way,
r~
Re: [PATCH 06/15] target/arm: Enforce M-profile VMRS/VMSR register restrictions
Quoted 11 lines · Richard Henderson
target/arm/translate-vfp.c.inc static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a) · line 628
Quoted 5 lines · Peter Maydell
target/arm/translate-vfp.c.inc +4
-1- if (a->rt == 15 && (!a->l || a->reg != ARM_VFP_FPSCR)) { + if (a->reg != ARM_VFP_FPSCR) { + return false; + } + if (a->rt == 15 && !a->l) {Alternately, the parenthesis are just off:
if ((a->rt == 15 && !a->l) || a->reg != ARM_VFP_FPSCR)
Mmm. As you've probably discovered by now, the refactoring in the subsequent patches means that this code gets moved and changed anyway; I just wanted it in this separate patch so the bugfix wasn't hidden in the refactoring.
thanks
-- PMM
PATCH 7/15 target/arm: Refactor M-profile VMSR/VMRS handling
In reply to Peter MaydellCurrently M-profile borrows the A-profile code for VMSR and VMRS (access to the FP system registers), because all it needs to support is the FPSCR. In v8.1M things become significantly more complicated in two ways:
* there are several new FP system registers; some have side effects on read, and one (FPCXT_NS) needs to avoid the usual vfp_access_check() and the "only if FPU implemented" check
* all sysregs are now accessible both by VMRS/VMSR (which reads/writes a general purpose register) and also by VLDR/VSTR (which reads/writes them directly to memory)
Refactor the structure of how we handle VMSR/VMRS to cope with this:
* keep the M-profile code entirely separate from the A-profile code
* abstract out the "read or write the general purpose register" part of the code into a loadfn or storefn function pointer, so we can reuse it for VLDR/VSTR.
--- target/arm/cpu.h | 3 + target/arm/translate-vfp.c.inc | 181 ++++++++++++++++++++++++++++++--- 2 files changed, 170 insertions(+), 14 deletions(-)
target/arm/cpu.h +3 -0
@@ -1569,6 +1569,9 @@ enum arm_cpu_mode {#define ARM_VFP_FPINST 9#define ARM_VFP_FPINST2 10 +/* QEMU-internal value meaning "FPSCR, but we care only about NZCV" */ +#define QEMU_VFP_FPSCR_NZCV 0xffff +/* iwMMXt coprocessor control registers. */ #define ARM_IWMMXT_wCID 0#define ARM_IWMMXT_wCon 1
target/arm/translate-vfp.c.inc +167 -14
194 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 8/15 target/arm: Move general-use constant expanders up in translate.c
In reply to Peter MaydellThe constant-expander functions like negate, plus_2, etc, are generally useful; move them up in translate.c so we can use them in the VFP/Neon decoders as well as in the A32/T32/T16 decoders.
--- target/arm/translate.c | 46 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-)
target/arm/translate.c +25 -21
@@ -109,6 +109,30 @@ static void arm_gen_condlabel(DisasContext *s) } } +/* +* Constant expanders for the decoders. +*/ + +static int negate (DisasContext *s,int x) +{ +return -x; +} + +static int plus_2 (DisasContext *s,int x) +{ +return x +2 ; +} + +static int times_2 (DisasContext *s,int x) +{ +return x *2 ; +} + +static int times_4 (DisasContext *s,int x) +{ +return x *4 ; +} +/* Flags for the disas_set_da_iss info argument: * lower bits hold the Rt register number, higher bits are flags. */
@@ -5174,29 +5198,9 @@ static void arm_skip_unless(DisasContext *s, uint32_t cond)/* -* Constant expanders for the decoders. +* Constant expanders used by T16/T32 decode */ -static int negate (DisasContext *s,int x) -{ -return -x; -} - -static int plus_2 (DisasContext *s,int x) -{ -return x +2 ; -} - -static int times_2 (DisasContext *s,int x) -{ -return x *2 ; -} - -static int times_4 (DisasContext *s,int x) -{ -return x *4 ; -} -/* Return only the rotation part of T32ExpandImm. */ static int t32_expandimm_rot (DisasContext *s,int x) {
Signature · 1 line
2.20.1
Re: [PATCH 08/15] target/arm: Move general-use constant expanders up in translate.c
Quoted 8 lines · Peter Maydell
The constant-expander functions like negate,
plus_2, etc, are generally useful; move them up intranslate.cso we can use them in the VFP/Neon decoders as well as in the A32/T32/T16 decoders.Signed-off-by Peter Maydell <[email protected]>--- target/arm/translate.c | 46 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-)
r~
PATCH 9/15 target/arm: Implement VLDR/VSTR system register
In reply to Peter MaydellImplement the new-in-v8.1M VLDR/VSTR variants which directly read or write FP system registers to memory.
--- target/arm/vfp.decode | 14 ++++++ target/arm/translate-vfp.c.inc | 89 ++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+)
target/arm/vfp.decode +14 -0
@@ -84,6 +84,20 @@ VLDR_VSTR_hp ---- 1101 u:1 .0 l:1 rn:4 .... 1001 imm:8 vd=%vd_sp VLDR_VSTR_sp ---- 1101 u:1 .0 l:1 rn:4 .... 1010 imm:8 vd=%vd_sp VLDR_VSTR_dp ---- 1101 u:1 .0 l:1 rn:4 .... 1011 imm:8 vd=%vd_dp +# M-profile VLDR/VSTR to sysreg +%vldr_sysreg 22:1 13:3 +%imm7_0x4 0:7 !function=times_4 + +&vldr_sysreg rn reg imm a w p +@vldr_sysreg .... ... . a:1 . . . rn:4 ... . ... .. ....... \ + reg=%vldr_sysreg imm=%imm7_0x4 &vldr_sysreg + +# P=0 W=0 is SEE "Related encodings", so split into two patterns +VLDR_sysreg ---- 110 1 . . w:1 1 .... ... 0 111 11 ....... @vldr_sysreg p=1 +VLDR_sysreg ---- 110 0 . . 1 1 .... ... 0 111 11 ....... @vldr_sysreg p=0 w=1 +VSTR_sysreg ---- 110 1 . . w:1 0 .... ... 0 111 11 ....... @vldr_sysreg p=1 +VSTR_sysreg ---- 110 0 . . 1 0 .... ... 0 111 11 ....... @vldr_sysreg p=0 w=1 + # We split the load/store multiple up into two patterns to avoid # overlap with other insns in the "Advanced SIMD load/store and 64-bit move" # grouping:
target/arm/translate-vfp.c.inc +89 -0
95 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 10/15 target/arm: Implement M-profile FPSCR_nzcvqc
In reply to Peter Maydellv8.1M defines a new FP system register FPSCR_nzcvqc; this behaves like the existing FPSCR, except that it reads and writes only bits [31:27] of the FPSCR (the N, Z, C, V and QC flag bits). (Unlike the FPSCR, the special case for Rt=15 of writing the CPSR.NZCV is not permitted.)
Implement the register. Since we don't yet implement MVE, we handle the QC bit as RES0, with todo comments for where we will need to add support later.
--- target/arm/cpu.h | 13 +++++++++++++ target/arm/translate-vfp.c.inc | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
target/arm/cpu.h +13 -0
@@ -1524,6 +1524,13 @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val);#define FPCR_FZ (1 << 24)/* Flush-to-zero enable bit */ #define FPCR_DN (1 << 25)/* Default NaN enable bit */ #define FPCR_QC (1 << 27)/* Cumulative saturation bit */ +#define FPCR_V (1 << 28)/* FP overflow flag */ +#define FPCR_C (1 << 29)/* FP carry flag */ +#define FPCR_Z (1 << 30)/* FP zero flag */ +#define FPCR_N (1 << 31)/* FP negative flag */ + +#define FPCR_NZCV_MASK (FPCR_N | FPCR_Z | FPCR_C | FPCR_V) +#define FPCR_NZCVQC_MASK (FPCR_NZCV_MASK | FPCR_QC)static inline uint32_t vfp_get_fpsr (CPUARMState *env) {
@@ -1568,6 +1575,12 @@ enum arm_cpu_mode {#define ARM_VFP_FPEXC 8#define ARM_VFP_FPINST 9#define ARM_VFP_FPINST2 10 +/* These ones are M-profile only */ +#define ARM_VFP_FPSCR_NZCVQC 2 +#define ARM_VFP_VPR 12 +#define ARM_VFP_P0 13 +#define ARM_VFP_FPCXT_NS 14 +#define ARM_VFP_FPCXT_S 15/* QEMU-internal value meaning "FPSCR, but we care only about NZCV" */ #define QEMU_VFP_FPSCR_NZCV 0xffff
target/arm/translate-vfp.c.inc +27 -0
@@ -648,6 +648,11 @@ static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno) case ARM_VFP_FPSCR: case QEMU_VFP_FPSCR_NZCV: break; + case ARM_VFP_FPSCR_NZCVQC: + if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { + return false; + } + break; default: return fp_sysreg_check_failed; }
@@ -682,6 +687,22 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, tcg_temp_free_i32(tmp); gen_lookup_tb(s); break; + case ARM_VFP_FPSCR_NZCVQC: + { + TCGv_i32 fpscr; + tmp = loadfn(s, opaque); + /* + * TODO: when we implement MVE, write the QC bit. + * For non-MVE, QC is RES0. + */ + tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK); + fpscr = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]); + tcg_gen_andi_i32(fpscr, fpscr, ~FPCR_NZCV_MASK); + tcg_gen_or_i32(fpscr, fpscr, tmp); + store_cpu_field(fpscr, vfp.xregs[ARM_VFP_FPSCR]); + tcg_temp_free_i32(tmp); + break; + } default: g_assert_not_reached(); }
@@ -710,6 +731,12 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, gen_helper_vfp_get_fpscr(tmp, cpu_env); storefn(s, opaque, tmp); break; + case ARM_VFP_FPSCR_NZCVQC: + /* + * TODO: MVE has a QC bit, which we probably won't store + * in the xregs[] field. For non-MVE, where QC is RES0, + * we can just fall through to the FPSCR_NZCV case. + */ case QEMU_VFP_FPSCR_NZCV: /* * Read just NZCV; this is a special case to avoid the
Signature · 1 line
2.20.1
PATCH 11/15 target/arm: Use new FPCR_NZCV_MASK constant
In reply to Peter MaydellWe defined a constant name for the mask of NZCV bits in the FPCR/FPSCR in the previous commit; use it in a couple of places in existing code, where we're masking out everything except NZCV for the "load to Rt=15 sets CPSR.NZCV" special case.
--- target/arm/translate-vfp.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/translate-vfp.c.inc +2 -2
@@ -743,7 +743,7 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, * helper call for the "VMRS to CPSR.NZCV" insn. */ tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]); - tcg_gen_andi_i32(tmp, tmp, 0xf0000000); + tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK); storefn(s, opaque, tmp); break; default:
@@ -884,7 +884,7 @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a) case ARM_VFP_FPSCR: if (a->rt == 15) { tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]); - tcg_gen_andi_i32(tmp, tmp, 0xf0000000); + tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK); } else { tmp = tcg_temp_new_i32(); gen_helper_vfp_get_fpscr(tmp, cpu_env);
Signature · 1 line
2.20.1
Re: [PATCH 11/15] target/arm: Use new FPCR_NZCV_MASK constant
Quoted 9 lines · Peter Maydell
We defined a constant name for the mask of NZCV bits in the FPCR/FPSCR in the previous commit; use it in a couple of places in existing code, where we're masking out everything except NZCV for the "load to Rt=15 sets CPSR.NZCV" special case.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/translate-vfp.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 12/15 target/arm: Factor out preserve-fp-state from full_vfp_access_check()
In reply to Peter MaydellFactor out the code which handles M-profile lazy FP state preservation from full_vfp_access_check(); accesses to the FPCXT_NS register are a special case which need to do just this part (corresponding in the pseudocode to the PreserveFPState() function), and not the full set of actions matching the pseudocode ExecuteFPCheck() which normal FP instructions need to do.
--- target/arm/translate-vfp.c.inc | 45 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-)
target/arm/translate-vfp.c.inc +27 -18
@@ -83,6 +83,32 @@ static inline long vfp_f16_offset(unsigned reg, bool top) return offs; } +/* + * Generate code for M-profile lazy FP state preservation if needed; + * this corresponds to the pseudocode PreserveFPState() function. + */ +static void gen_preserve_fp_state(DisasContext *s) +{ + if (s->v7m_lspact) { + /* + * Lazy state saving affects external memory and also the NVIC, + * so we must mark it as an IO operation for icount (and cause + * this to be the last insn in the TB). + */ + if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { + s->base.is_jmp = DISAS_UPDATE_EXIT; + gen_io_start(); + } + gen_helper_v7m_preserve_fp_state(cpu_env); + /* + * If the preserve_fp_state helper doesn't throw an exception + * then it will clear LSPACT; we don't need to repeat this for + * any further FP insns in this TB. + */ + s->v7m_lspact = false; + } +} + /* * Check that VFP access is enabled. If it is, do the necessary * M-profile lazy-FP handling and then return true.
@@ -113,24 +139,7 @@ static bool full_vfp_access_check(DisasContext *s, bool ignore_vfp_enabled) /* Handle M-profile lazy FP state mechanics */ /* Trigger lazy-state preservation if necessary */ - if (s->v7m_lspact) { - /* - * Lazy state saving affects external memory and also the NVIC, - * so we must mark it as an IO operation for icount (and cause - * this to be the last insn in the TB). - */ - if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { - s->base.is_jmp = DISAS_UPDATE_EXIT; - gen_io_start(); - } - gen_helper_v7m_preserve_fp_state(cpu_env); - /* - * If the preserve_fp_state helper doesn't throw an exception - * then it will clear LSPACT; we don't need to repeat this for - * any further FP insns in this TB. - */ - s->v7m_lspact = false; - } + gen_preserve_fp_state(s); /* Update ownership of FP context: set FPCCR.S to match current state */ if (s->v8m_fpccr_s_wrong) {
Signature · 1 line
2.20.1
Re: [PATCH 12/15] target/arm: Factor out preserve-fp-state from full_vfp_access_check()
Quoted 11 lines · Peter Maydell
Factor out the code which handles M-profile lazy FP state preservation from
full_vfp_access_check(); accesses to theFPCXT_NSregister are a special case which need to do just this part (corresponding in the pseudocode to thePreserveFPState()function), and not the full set of actions matching the pseudocodeExecuteFPCheck()which normal FP instructions need to do.Signed-off-by Peter Maydell <[email protected]>--- target/arm/translate-vfp.c.inc | 45 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-)
r~
PATCH 13/15 target/arm: Implement FPCXT_S fp system register
In reply to Peter MaydellImplement the new-in-v8.1M FPCXT_S floating point system register. This is for saving and restoring the secure floating point context, and it reads and writes bits [27:0] from the FPSCR and the CONTROL.SFPA bit in bit [31].
--- target/arm/translate-vfp.c.inc | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
target/arm/translate-vfp.c.inc +58 -0
@@ -662,6 +662,14 @@ static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno) return false; } break; + case ARM_VFP_FPCXT_S: + if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { + return false; + } + if (!s->v8m_secure) { + return false; + } + break; default: return fp_sysreg_check_failed; }
@@ -712,6 +720,26 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, tcg_temp_free_i32(tmp); break; } + case ARM_VFP_FPCXT_S: + { + TCGv_i32 sfpa, control, fpscr; + /* Set FPSCR[27:0] and CONTROL.SFPA from value */ + tmp = loadfn(s, opaque); + sfpa = tcg_temp_new_i32(); + tcg_gen_shri_i32(sfpa, tmp, 31); + control = load_cpu_field(v7m.control[M_REG_S]); + tcg_gen_deposit_i32(control, control, sfpa, + R_V7M_CONTROL_SFPA_SHIFT, 1); + store_cpu_field(control, v7m.control[M_REG_S]); + fpscr = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]); + tcg_gen_andi_i32(fpscr, fpscr, FPCR_NZCV_MASK); + tcg_gen_andi_i32(tmp, tmp, ~FPCR_NZCV_MASK); + tcg_gen_or_i32(fpscr, fpscr, tmp); + store_cpu_field(fpscr, vfp.xregs[ARM_VFP_FPSCR]); + tcg_temp_free_i32(tmp); + tcg_temp_free_i32(sfpa); + break; + } default: g_assert_not_reached(); }
@@ -755,6 +783,36 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK); storefn(s, opaque, tmp); break; + case ARM_VFP_FPCXT_S: + { + TCGv_i32 control, sfpa, fpscr; + /* Bits [27:0] from FPSCR, bit [31] from CONTROL.SFPA */ + tmp = tcg_temp_new_i32(); + sfpa = tcg_temp_new_i32(); + gen_helper_vfp_get_fpscr(tmp, cpu_env); + tcg_gen_andi_i32(tmp, tmp, ~FPCR_NZCV_MASK); + control = load_cpu_field(v7m.control[M_REG_S]); + tcg_gen_andi_i32(sfpa, control, R_V7M_CONTROL_SFPA_MASK); + tcg_gen_shli_i32(sfpa, sfpa, 31 - R_V7M_CONTROL_SFPA_SHIFT); + tcg_gen_or_i32(tmp, tmp, sfpa); + tcg_temp_free_i32(sfpa); + /* + * Store result before updating FPSCR etc, in case + * it is a memory write which causes an exception. + */ + storefn(s, opaque, tmp); + /* + * Now we must reset FPSCR from FPDSCR_NS, and clear + * CONTROL.SFPA; so we'll end the TB here. + */ + tcg_gen_andi_i32(control, control, ~R_V7M_CONTROL_SFPA_MASK); + store_cpu_field(control, v7m.control[M_REG_S]); + fpscr = load_cpu_field(v7m.fpdscr[M_REG_NS]); + gen_helper_vfp_set_fpscr(cpu_env, fpscr); + tcg_temp_free_i32(fpscr); + gen_lookup_tb(s); + break; + } default: g_assert_not_reached(); }
Signature · 1 line
2.20.1
PATCH 14/15 target/arm: Implement FPCXT_NS fp system register
In reply to Peter MaydellImplement the v8.1M FPCXT_NS floating-point system register. This is a little more complicated than FPCXT_S, because it has specific handling for "current FP state is inactive", and it only wants to do PreserveFPState(), not the full set of actions done by ExecuteFPCheck() which vfp_access_check() implements.
--- target/arm/translate-vfp.c.inc | 110 ++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 7 deletions(-)
target/arm/translate-vfp.c.inc +103 -7
@@ -647,8 +647,20 @@ typedef enum fp_sysreg_check_result { fp_sysreg_check_continue, /* caller should continue generating code */ } fp_sysreg_check_result; -static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno) +/* + * Emit code to check common UNDEF cases and handle lazy state preservation + * including the special casing for FPCXT_NS. For reads of sysregs, caller + * should provide storefn and opaque; for writes to sysregs these can be NULL. + * On return, if *insn_end_label is not NULL the caller needs to gen_set_label() + * it at the end of the other code generated for the insn. + */ +static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno, + fp_sysreg_storefn *storefn, + void *opaque, + TCGLabel **insn_end_label) { + *insn_end_label = NULL; + if (!dc_isar_feature(aa32_fpsp_v2, s)) { return fp_sysreg_check_failed; }
@@ -663,6 +675,7 @@ static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno) } break; case ARM_VFP_FPCXT_S: + case ARM_VFP_FPCXT_NS: if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { return false; }
@@ -674,8 +687,46 @@ static fp_sysreg_check_result fp_sysreg_checks(DisasContext *s, int regno) return fp_sysreg_check_failed; } - if (!vfp_access_check(s)) { - return fp_sysreg_check_done; + /* + * FPCXT_NS is a special case: it has specific handling for + * "current FP state is inactive", and must do the PreserveFPState() + * but not the usual full set of actions done by ExecuteFPCheck(). + * We don't have a TB flag that matches the fpInactive check, so we + * do it at runtime as we don't expect FPCXT_NS accesses to be frequent. + * The code emitted here handles the fpInactive special case; + * the caller just has to do the codegen for the normal (!fpInactive) + * special case, and then set the label at the end. + */ + if (regno == ARM_VFP_FPCXT_NS) { + /* fpInactive = FPCCR_NS.ASPEN == 1 && CONTROL.FPCA == 0 */ + TCGLabel *fp_active_label = gen_new_label(); + TCGv_i32 aspen, fpca; + aspen = load_cpu_field(v7m.fpccr[M_REG_NS]); + fpca = load_cpu_field(v7m.control[M_REG_S]); + tcg_gen_andi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK); + tcg_gen_subi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK); + tcg_gen_andi_i32(fpca, fpca, R_V7M_CONTROL_FPCA_MASK); + tcg_gen_or_i32(fpca, fpca, aspen); + tcg_gen_brcondi_i32(TCG_COND_NE, fpca, 0, fp_active_label); + tcg_temp_free_i32(aspen); + tcg_temp_free_i32(fpca); + + /* fpInactive case: FPCXT_NS reads as FPDSCR_NS, write is NOP */ + if (storefn) { + TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]); + storefn(s, opaque, tmp); + } + /* jump to end of insn */ + *insn_end_label = gen_new_label(); + tcg_gen_br(*insn_end_label); + + gen_set_label(fp_active_label); + /* !fpInactive: PreserveFPState() and handle register as normal */ + gen_preserve_fp_state(s); + } else { + if (!vfp_access_check(s)) { + return fp_sysreg_check_done; + } } return fp_sysreg_check_continue;
@@ -687,8 +738,10 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, { /* Do a write to an M-profile floating point system register */ TCGv_i32 tmp; + TCGLabel *insn_end_label; + bool lookup_tb = false; - switch (fp_sysreg_checks(s, regno)) { + switch (fp_sysreg_checks(s, regno, NULL, NULL, &insn_end_label)) { case fp_sysreg_check_failed: return false; case fp_sysreg_check_done:
@@ -702,7 +755,7 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, tmp = loadfn(s, opaque); gen_helper_vfp_set_fpscr(cpu_env, tmp); tcg_temp_free_i32(tmp); - gen_lookup_tb(s); + lookup_tb = true; break; case ARM_VFP_FPSCR_NZCVQC: {
@@ -721,6 +774,7 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, break; } case ARM_VFP_FPCXT_S: + case ARM_VFP_FPCXT_NS: { TCGv_i32 sfpa, control, fpscr; /* Set FPSCR[27:0] and CONTROL.SFPA from value */
@@ -743,6 +797,12 @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, default: g_assert_not_reached(); } + if (insn_end_label) { + gen_set_label(insn_end_label); + } + if (lookup_tb) { + gen_lookup_tb(s); + } return true; }
@@ -752,8 +812,10 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, { /* Do a read from an M-profile floating point system register */ TCGv_i32 tmp; + TCGLabel *insn_end_label; + bool lookup_tb = false; - switch (fp_sysreg_checks(s, regno)) { + switch (fp_sysreg_checks(s, regno, storefn, opaque, &insn_end_label)) { case fp_sysreg_check_failed: return false; case fp_sysreg_check_done:
@@ -810,12 +872,46 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, fpscr = load_cpu_field(v7m.fpdscr[M_REG_NS]); gen_helper_vfp_set_fpscr(cpu_env, fpscr); tcg_temp_free_i32(fpscr); - gen_lookup_tb(s); + lookup_tb = true; + break; + } + case ARM_VFP_FPCXT_NS: + { + TCGv_i32 control, sfpa, fpscr, fpdscr, zero; + /* Reads the same as FPCXT_S, but side effects differ */ + tmp = tcg_temp_new_i32(); + sfpa = tcg_temp_new_i32(); + fpscr = tcg_temp_new_i32(); + gen_helper_vfp_get_fpscr(fpscr, cpu_env); + tcg_gen_andi_i32(tmp, fpscr, ~FPCR_NZCV_MASK); + control = load_cpu_field(v7m.control[M_REG_S]); + tcg_gen_andi_i32(sfpa, control, R_V7M_CONTROL_SFPA_MASK); + tcg_gen_shli_i32(sfpa, sfpa, 31 - R_V7M_CONTROL_SFPA_SHIFT); + tcg_gen_or_i32(tmp, tmp, sfpa); + tcg_temp_free_i32(control); + /* Store result before updating FPSCR, in case it faults */ + storefn(s, opaque, tmp); + /* If SFPA is zero then set FPSCR from FPDSCR_NS */ + fpdscr = load_cpu_field(v7m.fpdscr[M_REG_NS]); + zero = tcg_const_i32(0); + tcg_gen_movcond_i32(TCG_COND_EQ, fpscr, sfpa, zero, fpdscr, fpscr); + gen_helper_vfp_set_fpscr(cpu_env, fpscr); + tcg_temp_free_i32(zero); + tcg_temp_free_i32(sfpa); + tcg_temp_free_i32(fpdscr); + tcg_temp_free_i32(fpscr); + lookup_tb = true; break; } default: g_assert_not_reached(); } + if (insn_end_label) { + gen_set_label(insn_end_label); + } + if (lookup_tb) { + gen_lookup_tb(s); + } return true; }
Signature · 1 line
2.20.1
PATCH 15/15 hw/intc/armv7m_nvic: Update FPDSCR masking for v8.1M
In reply to Peter MaydellThe FPDSCR register has a similar layout to the FPSCR. In v8.1M it gains new fields FZ16 (if half-precision floating point is supported) and LTPSIZE (always reads as 4). Update the reset value and the code that handles writes to this register accordingly.
--- target/arm/cpu.h | 5 +++++ hw/intc/armv7m_nvic.c | 9 ++++++++- target/arm/cpu.c | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-)
target/arm/cpu.h +5 -0
@@ -1521,14 +1521,19 @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val);#define FPCR_IXE (1 << 12)/* Inexact exception trap enable */ #define FPCR_IDE (1 << 15)/* Input Denormal exception trap enable */ #define FPCR_FZ16 (1 << 19)/* ARMv8.2+, FP16 flush-to-zero */ +#define FPCR_RMODE_MASK (3 << 22)/* Rounding mode */ #define FPCR_FZ (1 << 24)/* Flush-to-zero enable bit */ #define FPCR_DN (1 << 25)/* Default NaN enable bit */ +#define FPCR_AHP (1 << 26)/* Alternative half-precision */ #define FPCR_QC (1 << 27)/* Cumulative saturation bit */ #define FPCR_V (1 << 28)/* FP overflow flag */ #define FPCR_C (1 << 29)/* FP carry flag */ #define FPCR_Z (1 << 30)/* FP zero flag */ #define FPCR_N (1 << 31)/* FP negative flag */ +#define FPCR_LTPSIZE_SHIFT 16/* LTPSIZE, M-profile only */ +#define FPCR_LTPSIZE_MASK (7 << FPCR_LTPSIZE_SHIFT) +#define FPCR_NZCV_MASK (FPCR_N | FPCR_Z | FPCR_C | FPCR_V)#define FPCR_NZCVQC_MASK (FPCR_NZCV_MASK | FPCR_QC)
hw/intc/armv7m_nvic.c +8 -1
@@ -2068,7 +2068,14 @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,break ;case 0xf3c :/* FPDSCR */ if (cpu_isar_feature (aa32_vfp_simd, cpu)) { - value &=0x07c00000 ; +uint32_t mask =FPCR_AHP |FPCR_DN |FPCR_FZ |FPCR_RMODE_MASK ; +if (cpu_isar_feature (any_fp16, cpu)) { + mask |=FPCR_FZ16 ; + } + value &= mask; +if (cpu_isar_feature (aa32_lob, cpu)) { + value |=4 <<FPCR_LTPSIZE_SHIFT ; + } cpu->env.v7m.fpdscr[attrs.secure] = value; }break ;
target/arm/cpu.c +3 -0
@@ -262,6 +262,9 @@ static void arm_cpu_reset(DeviceState *dev)* always reset to 4. */ env->v7m.ltpsize =4 ; +/* The LTPSIZE field in FPDSCR is constant and reads as 4. */ + env->v7m.fpdscr[M_REG_NS ] =4 <<FPCR_LTPSIZE_SHIFT ; + env->v7m.fpdscr[M_REG_S ] =4 <<FPCR_LTPSIZE_SHIFT ; }if (arm_feature (env,ARM_FEATURE_M_SECURITY )) {
Signature · 1 line
2.20.1