Include provision for a name suffix.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/helper.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/target/arm/helper.c b/target/arm/helper.c
index a4cd4cf232..0e4be14606 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -7263,6 +7263,28 @@ void register_cp_regs_for_features(ARMCPU *cpu)
#endif
}
+/*
+ * Copy a ARMCPRegInfo structure, allocating it along with the name
+ * and an optional suffix to the name.
+ */
+static ARMCPRegInfo *alloc_cpreg(const ARMCPRegInfo *in,
+ const char *name, const char *suffix)
+{
+ size_t name_len = strlen(name);
+ size_t suff_len = suffix ? strlen(suffix) : 0;
+ ARMCPRegInfo *out = g_malloc(sizeof(*in) + name_len + suff_len + 1);
+ char *p = (char *)(out + 1);
+
+ *out = *in;
+ out->name = p;
+
+ memcpy(p, name, name_len + 1);
+ if (suffix) {
+ memcpy(p + name_len, suffix, suff_len + 1);
+ }
+ return out;
+}
+
/*
* Private utility function for define_one_arm_cp_reg():
* add a single reginfo struct to the hash table.
@@ -7275,7 +7297,6 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,
CPUARMState *env = &cpu->env;
ARMCPRegInfo *r2;
bool ns = secstate & ARM_CP_SECSTATE_NS;
- size_t name_len;
/* Overriding of an existing definition must be explicitly requested. */
if (!(r->type & ARM_CP_OVERRIDE)) {
@@ -7285,11 +7306,7 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,
}
}
- /* Combine cpreg and name into one allocation. */
- name_len = strlen(name) + 1;
- r2 = g_malloc(sizeof(*r2) + name_len);
- *r2 = *r;
- r2->name = memcpy(r2 + 1, name, name_len);
+ r2 = alloc_cpreg(r, name, NULL);
/*
* Update fields to match the instantiation, overwiting wildcards
--
2.43.0