Skip to contentSkip to conversation

target/riscv: check 'I' and 'E' after checking 'G' in riscv_cpu_realize

PATCH Superseded Weiwei Li 2 participants 4 messages May 17, 2022 RISC-V

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Weiwei Li

author
#0 lore raw

PATCH v2 1/2 target/riscv: check 'I' and 'E' after checking 'G' in riscv_cpu_realize

- setting ext_g will implicitly set ext_i

---
 target/riscv/cpu.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
target/riscv/cpu.c +12 -11
index ccacdee215..b12f69c584 100644
@@ -583,6 +583,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
     if (env->misa_ext == 0) {
         uint32_t ext = 0;
 
+        if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m &
+                                cpu->cfg.ext_a & cpu->cfg.ext_f &
+                                cpu->cfg.ext_d)) {
+            warn_report("Setting G will also set IMAFD");
+            cpu->cfg.ext_i = true;
+            cpu->cfg.ext_m = true;
+            cpu->cfg.ext_a = true;
+            cpu->cfg.ext_f = true;
+            cpu->cfg.ext_d = true;
+        }
+
+
         /* Do some ISA extension error checking */
         if (cpu->cfg.ext_i && cpu->cfg.ext_e) {
             error_setg(errp,
@@ -596,17 +608,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m &
-                                cpu->cfg.ext_a & cpu->cfg.ext_f &
-                                cpu->cfg.ext_d)) {
-            warn_report("Setting G will also set IMAFD");
-            cpu->cfg.ext_i = true;
-            cpu->cfg.ext_m = true;
-            cpu->cfg.ext_a = true;
-            cpu->cfg.ext_f = true;
-            cpu->cfg.ext_d = true;
-        }
-
         if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx ||
             cpu->cfg.ext_zhinxmin) {
             cpu->cfg.ext_zfinx = true;
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 2/2 target/riscv: disable zb* extensions for sifive/ibex cpu types by default

- properties for zb* extensions are enabled by default which will make sifive/ibex cpu types implicitly support zb* extensions

---
 target/riscv/cpu.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
target/riscv/cpu.c +24 -0
index b12f69c584..e205be34e9 100644
@@ -176,6 +176,10 @@ static void rv64_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv64_sifive_e_cpu_init(Object *obj)
@@ -184,6 +188,10 @@ static void rv64_sifive_e_cpu_init(Object *obj)
     set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv128_base_cpu_init(Object *obj)
@@ -211,6 +219,10 @@ static void rv32_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_sifive_e_cpu_init(Object *obj)
@@ -219,6 +231,10 @@ static void rv32_sifive_e_cpu_init(Object *obj)
     set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_ibex_cpu_init(Object *obj)
@@ -228,6 +244,10 @@ static void rv32_ibex_cpu_init(Object *obj)
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
     qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_imafcu_nommu_cpu_init(Object *obj)
@@ -237,6 +257,10 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)
     set_priv_version(env, PRIV_VERSION_1_10_0);
     set_resetvec(env, DEFAULT_RSTVEC);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 #endif
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 2/2] target/riscv: disable zb* extensions for sifive/ibex cpu types by default

Quoted 14 lines · Weiwei Li

- properties for zb* extensions are enabled by default which will make sifive/ibex cpu types implicitly support zb* extensions

---
 target/riscv/cpu.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
target/riscv/cpu.c +0 -0
index b12f69c584..e205be34e9 100644

target/riscv/cpu.c static void rv64_sifive_u_cpu_init(Object *obj) · line 182

Quoted 7 lines
target/riscv/cpu.c +4 -0
@@ -176,6 +176,10 @@ static void rv64_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);

This is very error prone. I think we should either disable the extensions by default, then enable them for the rv32/rv64 CPUs, or instead do something like this:
https://patchew.org/QEMU/[email protected]/

Alistair

Quoted 62 lines
target/riscv/cpu.c +20 -1
 }
 
 static void rv64_sifive_e_cpu_init(Object *obj)
@@ -184,6 +188,10 @@ static void rv64_sifive_e_cpu_init(Object *obj)
     set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv128_base_cpu_init(Object *obj)
@@ -211,6 +219,10 @@ static void rv32_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_sifive_e_cpu_init(Object *obj)
@@ -219,6 +231,10 @@ static void rv32_sifive_e_cpu_init(Object *obj)
     set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_ibex_cpu_init(Object *obj)
@@ -228,6 +244,10 @@ static void rv32_ibex_cpu_init(Object *obj)
     set_priv_version(env, PRIV_VERSION_1_10_0);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
     qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 
 static void rv32_imafcu_nommu_cpu_init(Object *obj)
@@ -237,6 +257,10 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)
     set_priv_version(env, PRIV_VERSION_1_10_0);
     set_resetvec(env, DEFAULT_RSTVEC);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
 }
 #endif
 
--

2.17.1

author
#3 lore raw

Re: [PATCH v2 2/2] target/riscv: disable zb* extensions for sifive/ibex cpu types by default

Quoted 26 lines · Alistair Francis
Quoted 13 lines · Weiwei Li

- properties for zb* extensions are enabled by default which will make sifive/ibex cpu types implicitly support zb* extensions

---
  target/riscv/cpu.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
target/riscv/cpu.c +0 -0
index b12f69c584..e205be34e9 100644

target/riscv/cpu.c static void rv64_sifive_u_cpu_init(Object *obj) · line 182

Quoted 7 lines
target/riscv/cpu.c +4 -0
@@ -176,6 +176,10 @@ static void rv64_sifive_u_cpu_init(Object *obj)
      CPURISCVState *env = &RISCV_CPU(obj)->env;
      set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
      set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);

This is very error prone. I think we should either disable the extensions by default, then enable them for the rv32/rv64 CPUs, or instead do something like this:
https://patchew.org/QEMU/[email protected]/

Quoted 1 line

Alistair

OK, I think the way from your patchset is better.

Regards,

Weiwei Li

Quoted 62 lines
Quoted 62 lines
target/riscv/cpu.c +20 -1
  }
 
  static void rv64_sifive_e_cpu_init(Object *obj)
@@ -184,6 +188,10 @@ static void rv64_sifive_e_cpu_init(Object *obj)
      set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
      set_priv_version(env, PRIV_VERSION_1_10_0);
      qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
  }
 
  static void rv128_base_cpu_init(Object *obj)
@@ -211,6 +219,10 @@ static void rv32_sifive_u_cpu_init(Object *obj)
      CPURISCVState *env = &RISCV_CPU(obj)->env;
      set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
      set_priv_version(env, PRIV_VERSION_1_10_0);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
  }
 
  static void rv32_sifive_e_cpu_init(Object *obj)
@@ -219,6 +231,10 @@ static void rv32_sifive_e_cpu_init(Object *obj)
      set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
      set_priv_version(env, PRIV_VERSION_1_10_0);
      qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
  }
 
  static void rv32_ibex_cpu_init(Object *obj)
@@ -228,6 +244,10 @@ static void rv32_ibex_cpu_init(Object *obj)
      set_priv_version(env, PRIV_VERSION_1_10_0);
      qdev_prop_set_bit(DEVICE(obj), "mmu", false);
      qdev_prop_set_bit(DEVICE(obj), "x-epmp", true);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
  }
 
  static void rv32_imafcu_nommu_cpu_init(Object *obj)
@@ -237,6 +257,10 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)
      set_priv_version(env, PRIV_VERSION_1_10_0);
      set_resetvec(env, DEFAULT_RSTVEC);
      qdev_prop_set_bit(DEVICE(obj), "mmu", false);
+    qdev_prop_set_bit(DEVICE(obj), "zba", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbb", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbc", false);
+    qdev_prop_set_bit(DEVICE(obj), "zbs", false);
  }
  #endif
 
--

2.17.1