Skip to contentSkip to conversation

target/arm: SB and PredRes extensions

PATCH Superseded Richard Henderson 2 participants 8 messages Feb 20, 2019 – Feb 28, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover target/arm: SB and PredRes extensions

Both of these are defined by the ARMv8.5 spec, but back-defined as v8.0 extensions.

All of the relevant instructions are nops within QEMU. Tested by locally setting SCTLR_EL1.EnRCTX for aarch64-linux-user and then executing each of the insns to see that they decode properly.

The SB extension is already upstream in linux 5.0-rc1, with the HWCAP entry. The PredRes extension has no upstream support yet, so we need to wait to see what they do for userland ABI.

r~

Richard Henderson (2):
target/arm: Implement ARMv8.0-SB
target/arm: Implement ARMv8.0-PredRes

 target/arm/cpu.h           | 21 ++++++++++++++++
 linux-user/elfload.c       |  1 +
 target/arm/cpu.c           |  2 ++
 target/arm/cpu64.c         |  4 ++++
 target/arm/helper.c        | 49 ++++++++++++++++++++++++++++++++++++++
 target/arm/translate-a64.c | 14 +++++++++++
 target/arm/translate.c     | 22 +++++++++++++++++
 7 files changed, 113 insertions(+)
Signature · 1 line
2.17.2
#1 lore raw

PATCH 1/2 target/arm: Implement ARMv8.0-SB

---
 target/arm/cpu.h           | 10 ++++++++++
 linux-user/elfload.c       |  1 +
 target/arm/cpu.c           |  1 +
 target/arm/cpu64.c         |  2 ++
 target/arm/translate-a64.c | 14 ++++++++++++++
 target/arm/translate.c     | 22 ++++++++++++++++++++++
 6 files changed, 50 insertions(+)
target/arm/cpu.h +10 -0
index 0480f9baba..76d6a73c0e 100644
@@ -3302,6 +3302,11 @@ static inline bool isar_feature_aa32_dp(const ARMISARegisters *id)
     return FIELD_EX32(id->id_isar6, ID_ISAR6, DP) != 0;
 }
 
+static inline bool isar_feature_aa32_sb(const ARMISARegisters *id)
+{
+    return FIELD_EX32(id->id_isar6, ID_ISAR6, SB) != 0;
+}
+
 static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id)
 {
     /*
@@ -3405,6 +3410,11 @@ static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id)
              FIELD_DP64(0, ID_AA64ISAR1, GPI, 0xf))) != 0;
 }
 
+static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
+{
+    return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
+}
+
 static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id)
 {
     /* We always set the AdvSIMD and FP fields identically wrt FP16.  */
linux-user/elfload.c +1 -0
index ef7138839d..02ba705e73 100644
@@ -603,6 +603,7 @@ static uint32_t get_elf_hwcap(void)
     GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE);
     GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG);
     GET_FEATURE_ID(aa64_condm_4, ARM_HWCAP_A64_FLAGM);
+    GET_FEATURE_ID(aa64_sb, ARM_HWCAP_A64_SB);
 
 #undef GET_FEATURE_ID
 
target/arm/cpu.c +1 -0
index a5599ae19f..5cd27f2f64 100644
@@ -2027,6 +2027,7 @@ static void arm_max_initfn(Object *obj)
 
             t = cpu->isar.id_isar6;
             t = FIELD_DP32(t, ID_ISAR6, DP, 1);
+            t = FIELD_DP32(t, ID_ISAR6, SB, 1);
             cpu->isar.id_isar6 = t;
 
             t = cpu->id_mmfr4;
target/arm/cpu64.c +2 -0
index fc54734256..95c6ee4cda 100644
@@ -343,6 +343,7 @@ static void aarch64_max_initfn(Object *obj)
         t = FIELD_DP64(t, ID_AA64ISAR1, API, 0);
         t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 1);
         t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0);
+        t = FIELD_DP64(t, ID_AA64ISAR1, SB, 1);
         cpu->isar.id_aa64isar1 = t;
 
         t = cpu->isar.id_aa64pfr0;
@@ -373,6 +374,7 @@ static void aarch64_max_initfn(Object *obj)
 
         u = cpu->isar.id_isar6;
         u = FIELD_DP32(u, ID_ISAR6, DP, 1);
+        u = FIELD_DP32(u, ID_ISAR6, SB, 1);
         cpu->isar.id_isar6 = u;
 
         /*
target/arm/translate-a64.c +14 -0
index 1d9bf81c0e..40c4f2fe54 100644
@@ -1638,7 +1638,21 @@ static void handle_sync(DisasContext *s, uint32_t insn,
         reset_btype(s);
         gen_goto_tb(s, 0, s->pc);
         return;
+
+    case 7: /* SB */
+        if (crm != 0 || !dc_isar_feature(aa64_sb, s)) {
+            goto do_unallocated;
+        }
+        /*
+         * TODO: There is no speculation barrier opcode for TCG;
+         * MB and end the TB instead.
+         */
+        tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+        s->base.is_jmp = DISAS_TOO_MANY;
+        return;
+
     default:
+    do_unallocated:
         unallocated_encoding(s);
         return;
     }
target/arm/translate.c +22 -0
index 92f0c8d557..796ba2df43 100644
@@ -9192,6 +9192,17 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
                  */
                 gen_goto_tb(s, 0, s->pc & ~1);
                 return;
+            case 7: /* sb */
+                if (!dc_isar_feature(aa32_sb, s)) {
+                    goto illegal_op;
+                }
+                /*
+                 * TODO: There is no speculation barrier opcode
+                 * for TCG; MB and end the TB instead.
+                 */
+                tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+                s->base.is_jmp = DISAS_TOO_MANY;
+                return;
             default:
                 goto illegal_op;
             }
@@ -11810,6 +11821,17 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
                              */
                             gen_goto_tb(s, 0, s->pc & ~1);
                             break;
+                        case 7: /* sb */
+                            if (!dc_isar_feature(aa32_sb, s)) {
+                                goto illegal_op;
+                            }
+                            /*
+                             * TODO: There is no speculation barrier opcode
+                             * for TCG; MB and end the TB instead.
+                             */
+                            tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+                            s->base.is_jmp = DISAS_TOO_MANY;
+                            break;
                         default:
                             goto illegal_op;
                         }
Signature · 1 line
2.17.2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] target/arm: Implement ARMv8.0-SB

Quoted 8 lines · Richard Henderson
target/arm/translate.c +0 -0
@@ -9192,6 +9192,17 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
                  */
                 gen_goto_tb(s, 0, s->pc & ~1);
                 return;

target/arm/translate.c static void disas_arm_insn(DisasContext *s, unsigned int insn) · line 9204

Quoted 10 lines
target/arm/translate.c +10 -0
+            case 7: /* sb */
+                if (!dc_isar_feature(aa32_sb, s)) {
+                    goto illegal_op;
+                }
+                /*
+                 * TODO: There is no speculation barrier opcode
+                 * for TCG; MB and end the TB instead.
+                 */
+                tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+                s->base.is_jmp = DISAS_TOO_MANY;

Why do we do the "end the TB" code differently here than we do for the implementation of ISB in the case immediately above ?

In the A32 encoding bits [3:0] are "(0)", so we should check that they're 0 and UNDEF if not.

Quoted 8 lines
target/arm/translate.c +1 -0
+                return;
             default:
                 goto illegal_op;
             }
@@ -11810,6 +11821,17 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
                              */
                             gen_goto_tb(s, 0, s->pc & ~1);
                             break;

target/arm/translate.c static void disas_thumb2_insn(DisasContext *s, uint32_t insn) · line 11833

Quoted 10 lines
target/arm/translate.c +10 -0
+                        case 7: /* sb */
+                            if (!dc_isar_feature(aa32_sb, s)) {
+                                goto illegal_op;
+                            }
+                            /*
+                             * TODO: There is no speculation barrier opcode
+                             * for TCG; MB and end the TB instead.
+                             */
+                            tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+                            s->base.is_jmp = DISAS_TOO_MANY;

Similarly here: inconsistency about how we end the TB, and not checking the [3:0] bits for being zero.

(We also I think are not fully decoding some of the other sbz/sbo fields for insns in this group, but that's more of an existing bug than a new one.)

Quoted 6 lines
target/arm/translate.c +1 -1
+                            break;
                         default:
                             goto illegal_op;
                         }
--

2.17.2

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] target/arm: Implement ARMv8.0-SB

Quoted 16 lines · Peter Maydell
Quoted 14 lines · Richard Henderson
target/arm/translate.c +6 -0
@@ -9192,6 +9192,17 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
                  */
                 gen_goto_tb(s, 0, s->pc & ~1);
                 return;
+            case 7: /* sb */
+                if (!dc_isar_feature(aa32_sb, s)) {
+                    goto illegal_op;
+                }
+                /*
+                 * TODO: There is no speculation barrier opcode
Quoted 8 lines

target/arm/translate.c static void disas_arm_insn(DisasContext *s, unsigned int insn) · line 9204

Quoted 4 lines
target/arm/translate.c +4 -0
+                 * for TCG; MB and end the TB instead.
+                 */
+                tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+                s->base.is_jmp = DISAS_TOO_MANY;

Why do we do the "end the TB" code differently here than we do for the implementation of ISB in the case immediately above ?

No good reason, I suppose. This is how we end the TB for MSR, I think. But I can change it.

r~

#4 lore raw

PATCH 2/2 target/arm: Implement ARMv8.0-PredRes

In reply to Richard Henderson

This is named "Execution and Data prediction restriction instructions" within the ARMv8.5 manual, and given the name "PredRes" by binutils.

---
 target/arm/cpu.h    | 11 ++++++++++
 target/arm/cpu.c    |  1 +
 target/arm/cpu64.c  |  2 ++
 target/arm/helper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+)
target/arm/cpu.h +11 -0
index 76d6a73c0e..202ff1f1ea 100644
@@ -1074,6 +1074,7 @@ void pmu_init(ARMCPU *cpu);
 #define SCTLR_UMA     (1U << 9) /* v8 onward, AArch64 only */
 #define SCTLR_F       (1U << 10) /* up to v6 */
 #define SCTLR_SW      (1U << 10) /* v7, RES0 in v8 */
+#define SCTLR_EnRCTX  (1U << 10) /* in v8.0-specres */
 #define SCTLR_Z       (1U << 11) /* in v7, RES1 in v8 */
 #define SCTLR_EOS     (1U << 11) /* v8.5-ExS */
 #define SCTLR_I       (1U << 12)
@@ -3307,6 +3308,11 @@ static inline bool isar_feature_aa32_sb(const ARMISARegisters *id)
     return FIELD_EX32(id->id_isar6, ID_ISAR6, SB) != 0;
 }
 
+static inline bool isar_feature_aa32_specres(const ARMISARegisters *id)
+{
+    return FIELD_EX32(id->id_isar6, ID_ISAR6, SPECRES) != 0;
+}
+
 static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id)
 {
     /*
@@ -3415,6 +3421,11 @@ static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
     return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
 }
 
+static inline bool isar_feature_aa64_specres(const ARMISARegisters *id)
+{
+    return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SPECRES) != 0;
+}
+
 static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id)
 {
     /* We always set the AdvSIMD and FP fields identically wrt FP16.  */
target/arm/cpu.c +1 -0
index 5cd27f2f64..c1d2848baa 100644
@@ -2028,6 +2028,7 @@ static void arm_max_initfn(Object *obj)
             t = cpu->isar.id_isar6;
             t = FIELD_DP32(t, ID_ISAR6, DP, 1);
             t = FIELD_DP32(t, ID_ISAR6, SB, 1);
+            t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
             cpu->isar.id_isar6 = t;
 
             t = cpu->id_mmfr4;
target/arm/cpu64.c +2 -0
index 95c6ee4cda..5f273399db 100644
@@ -344,6 +344,7 @@ static void aarch64_max_initfn(Object *obj)
         t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 1);
         t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0);
         t = FIELD_DP64(t, ID_AA64ISAR1, SB, 1);
+        t = FIELD_DP64(t, ID_AA64ISAR1, SPECRES, 1);
         cpu->isar.id_aa64isar1 = t;
 
         t = cpu->isar.id_aa64pfr0;
@@ -375,6 +376,7 @@ static void aarch64_max_initfn(Object *obj)
         u = cpu->isar.id_isar6;
         u = FIELD_DP32(u, ID_ISAR6, DP, 1);
         u = FIELD_DP32(u, ID_ISAR6, SB, 1);
+        u = FIELD_DP32(u, ID_ISAR6, SPECRES, 1);
         cpu->isar.id_isar6 = u;
 
         /*
target/arm/helper.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
2.17.2
Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] target/arm: Implement ARMv8.0-PredRes

Quoted 3 lines · Richard Henderson

This is named "Execution and Data prediction restriction instructions" within the ARMv8.5 manual, and given the name "PredRes" by binutils.

The official name is v8.0-PredInv.
(You can see this used in the xml descriptions for the new insns, eg:
https://developer.arm.com/docs/ddi0595/b/aarch64-system-instructions/cfp-rctx )

Quoted 14 lines
---
 target/arm/cpu.h    | 11 ++++++++++
 target/arm/cpu.c    |  1 +
 target/arm/cpu64.c  |  2 ++
 target/arm/helper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+)
target/arm/cpu.h +0 -0
index 76d6a73c0e..202ff1f1ea 100644

target/arm/cpu.h void pmu_init(ARMCPU *cpu); · line 1077

Quoted 4 lines
target/arm/cpu.h +1 -0
@@ -1074,6 +1074,7 @@ void pmu_init(ARMCPU *cpu);
 #define SCTLR_UMA     (1U << 9) /* v8 onward, AArch64 only */
 #define SCTLR_F       (1U << 10) /* up to v6 */
 #define SCTLR_SW      (1U << 10) /* v7, RES0 in v8 */
+#define SCTLR_EnRCTX  (1U << 10) /* in v8.0-specres */

You should delete the "RES0 in v8" from the preceding comment (and update the feature name to v8.0-PredInv).

target/arm/cpu.h void pmu_init(ARMCPU *cpu);

Quoted 6 lines
target/arm/cpu.h +2 -0
 #define SCTLR_Z       (1U << 11) /* in v7, RES1 in v8 */
 #define SCTLR_EOS     (1U << 11) /* v8.5-ExS */
 #define SCTLR_I       (1U << 12)
 
+
+    /* All v8.0-a cpus support aarch64.  */

True, but why is it relevant here ?

Quoted 8 lines
target/arm/cpu.h +3 -1
+    if (cpu_isar_feature(aa64_specres, cpu)) {
+        define_arm_cp_regs(cpu, specres_reginfo);
+    }
 }
 
 void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
--

2.17.2

Otherwise

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] target/arm: Implement ARMv8.0-PredRes

Quoted 9 lines · Peter Maydell
Quoted 3 lines · Richard Henderson

This is named "Execution and Data prediction restriction instructions" within the ARMv8.5 manual, and given the name "PredRes" by binutils.

The official name is v8.0-PredInv.
(You can see this used in the xml descriptions for the new insns, eg:
https://developer.arm.com/docs/ddi0595/b/aarch64-system-instructions/cfp-rctx )

Thanks. I may file a bug against binutils. ;-)

Quoted 8 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6834

Quoted 2 lines
target/arm/helper.c +2 -0
+
+    /* All v8.0-a cpus support aarch64.  */

True, but why is it relevant here ?

Quoted 3 lines
target/arm/helper.c +3 -0
+    if (cpu_isar_feature(aa64_specres, cpu)) {
+        define_arm_cp_regs(cpu, specres_reginfo);
+    }

The context, I think, is that we're in a function that handles a32, and I am not checking arm_feature(cpu, ARM_FEATURE_AARCH64) before checking cpu_isar_feature(aa64_specres, cpu).

At least that's my recollection.

r~

#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] target/arm: Implement ARMv8.0-PredRes

Quoted 23 lines · Richard Henderson
Quoted 9 lines · Peter Maydell
Quoted 3 lines · Richard Henderson

This is named "Execution and Data prediction restriction instructions" within the ARMv8.5 manual, and given the name "PredRes" by binutils.

The official name is v8.0-PredInv.
(You can see this used in the xml descriptions for the new insns, eg:
https://developer.arm.com/docs/ddi0595/b/aarch64-system-instructions/cfp-rctx )

Thanks. I may file a bug against binutils. ;-)

Quoted 8 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6834

Quoted 2 lines
target/arm/helper.c +2 -0
+
+    /* All v8.0-a cpus support aarch64.  */

True, but why is it relevant here ?

Quoted 3 lines
target/arm/helper.c +3 -0
+    if (cpu_isar_feature(aa64_specres, cpu)) {
+        define_arm_cp_regs(cpu, specres_reginfo);
+    }
Quoted 5 lines

The context, I think, is that we're in a function that handles a32, and I am not checking arm_feature(cpu, ARM_FEATURE_AARCH64) before checking cpu_isar_feature(aa64_specres, cpu).

At least that's my recollection.

Ah, so in theory if we had a v8.0 CPU which was AArch32 only it would not have those ID bits set and fail to register these registers. I'm pretty sure it would also not work in a bunch of other ways too...

thanks
-- PMM