qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 01/15] arm/cpu: Add sysreg definitions in cpu-sysregs.h


From: Richard Henderson
Subject: Re: [PATCH 01/15] arm/cpu: Add sysreg definitions in cpu-sysregs.h
Date: Fri, 7 Feb 2025 10:34:26 -0800
User-agent: Mozilla Thunderbird

On 2/7/25 03:02, Cornelia Huck wrote:
diff --git a/target/arm/cpu-sysregs.h b/target/arm/cpu-sysregs.h
new file mode 100644
index 000000000000..de09ebae91a5
--- /dev/null
+++ b/target/arm/cpu-sysregs.h
...
+static const uint32_t id_register_sysreg[NUM_ID_IDX] = {

You can't place the data into a header like this.

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 2213c277348d..4bbce34e268d 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -30,6 +30,7 @@
  #include "qapi/qapi-types-common.h"
  #include "target/arm/multiprocessing.h"
  #include "target/arm/gtimer.h"
+#include "target/arm/cpu-sysregs.h"

The data will be replicated into *every* user of cpu.h.

+static inline uint64_t _get_idreg(uint64_t *idregs, uint32_t index)
+{
+    return idregs[index];
+}
+
+static inline void _set_idreg(uint64_t *idregs, uint32_t index, uint64_t value)
+{
+    idregs[index] = value;
+}

No leading underscores -- this is not a freestanding environment like the 
kernel.
We must respect the system implementation namespace.

+/* REG is ID_XXX */
+#define FIELD_DP64_IDREG(ARRAY, REG, FIELD, VALUE)              \
+{                                                             \
+    uint64_t regval = _get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX);   \
+        regval = FIELD_DP64(regval, REG, FIELD, VALUE);                 \
+    _set_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX, regval);             \
+}
+
+#define FIELD_DP32_IDREG(ARRAY, REG, FIELD, VALUE)              \
+{                                                             \
+uint64_t regval = _get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX);       \
+regval = FIELD_DP32(regval, REG, FIELD, VALUE);               \
+_set_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX, regval);                 \
+}
+
+#define FIELD_EX64_IDREG(ARRAY, REG, FIELD)                     \
+FIELD_EX64(_get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX), REG, FIELD)  \
+
+#define FIELD_EX32_IDREG(ARRAY, REG, FIELD)                     \
+FIELD_EX32(_get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX), REG, FIELD)  \
+
+#define FIELD_SEX64_IDREG(ARRAY, REG, FIELD)                     \
+FIELD_SEX64(_get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX), REG, FIELD)  \
+
+#define SET_IDREG(ARRAY, REG, VALUE)                            \
+_set_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX, VALUE)
+
+#define GET_IDREG(ARRAY, REG)                                   \
+_get_idreg((uint64_t *)ARRAY, REG ## _EL1_IDX)

The casts look wrong, and seem very likely to hide bugs.
The macros should be written to be type-safe.

Perhaps like this:

#define FIELD_EX64_IDREG(ISAR, REG, FIELD) \
    ({ const ARMISARegisters *i_ = (ISAR); \
       FIELD_EX64(i_->idregs[REG ## _EL1_IDX], REG, FIELD); })


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]