Skip to contentSkip to conversation

target/riscv: Use TARGET_FMT_lx for env->mhartid

PATCH Applied Bin Meng 5 participants 6 messages Jan 9, 2023 – Jan 16, 2023 RISC-V

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 target/riscv: Use TARGET_FMT_lx for env->mhartid

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

---

 target/riscv/cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +3 -3
index cc75ca7667..a5ed6d3f63 100644
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
             (env->priv_ver < isa_edata_arr[i].min_version)) {
             isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
 #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);
 #else
             warn_report("disabling %s extension because "
                         "privilege spec version does not match",
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · Bin Meng

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

Oh, a 32-bit host user!

Quoted 11 lines

---

  target/riscv/cpu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +0 -0
index cc75ca7667..a5ed6d3f63 100644

target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 665

Quoted 9 lines
target/riscv/cpu.c +3 -3
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
              (env->priv_ver < isa_edata_arr[i].min_version)) {
              isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
  #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);

Could we cast it to vaddr instead? I'm trying to remove target_[u]long from hw/ and restrict it to the target/ directory. Per "exec/cpu-common.h":

/**
* vaddr:
* Type wide enough to contain any #target_ulong virtual address. */
typedef uint64_t vaddr;

Alternatively, since this value has to be accessed out of target/, can we change its type to vaddr in CPURISCVState?

Thanks,

Phil.

#2 lore raw
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Bin Meng

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

Oh, a 32-bit host user!

Quoted 11 lines

---

  target/riscv/cpu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +0 -0
index cc75ca7667..a5ed6d3f63 100644

target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 665

Quoted 9 lines
target/riscv/cpu.c +3 -3
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
              (env->priv_ver < isa_edata_arr[i].min_version)) {
              isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
  #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);

Could we cast it to vaddr instead? I'm trying to remove target_[u]long from hw/ and restrict it to the target/ directory. Per "exec/cpu-common.h":

Quoted 9 lines

/**
* vaddr:
* Type wide enough to contain any #target_ulong virtual address. */
typedef uint64_t vaddr;

Alternatively, since this value has to be accessed out of target/, can we change its type to vaddr in CPURISCVState?

Technically it does not represent a virtual address but a target dependent register that can be 32-bit or 64-bit. Change env->mhartid to vaddr looks weird to me.

Regards,
Bin

#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Bin Meng

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

Oh, a 32-bit host user!

Quoted 15 lines

---

  target/riscv/cpu.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +0 -1
index cc75ca7667..a5ed6d3f63 100644
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
               (env->priv_ver < isa_edata_arr[i].min_version)) {
               isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
   #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
Quoted 8 lines

target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 665

Quoted 5 lines
target/riscv/cpu.c +3 -2
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);

Could we cast it to vaddr instead? I'm trying to remove target_[u]long from hw/ and restrict it to the target/ directory. Per "exec/cpu-common.h":

This isn't in hw/, it's in target/. And no, it's a target-width register.

r~

Reviewed-by on v1 1/1
#4 lore raw
In reply to Bin Meng
Quoted 5 lines · Bin Meng

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

Alistair

Quoted 26 lines

---

 target/riscv/cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +3 -4
index cc75ca7667..a5ed6d3f63 100644
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
             (env->priv_ver < isa_edata_arr[i].min_version)) {
             isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
 #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);
 #else
             warn_report("disabling %s extension because "
                         "privilege spec version does not match",
--

2.34.1

#5 lore raw
In reply to Bin Meng
Quoted 5 lines · Bin Meng

env->mhartid is currently casted to long before printed, which drops the high 32-bit for rv64 on 32-bit host. Use TARGET_FMT_lx instead.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 26 lines

---

 target/riscv/cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/riscv/cpu.c +3 -4
index cc75ca7667..a5ed6d3f63 100644
@@ -660,9 +660,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
             (env->priv_ver < isa_edata_arr[i].min_version)) {
             isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
 #ifndef CONFIG_USER_ONLY
-            warn_report("disabling %s extension for hart 0x%lx because "
-                        "privilege spec version does not match",
-                        isa_edata_arr[i].name, (unsigned long)env->mhartid);
+            warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
+                        " because privilege spec version does not match",
+                        isa_edata_arr[i].name, env->mhartid);
 #else
             warn_report("disabling %s extension because "
                         "privilege spec version does not match",
--

2.34.1