* [PATCH 0/2] Set MISA.[C|X] based on the selected extensions
@ 2025-11-14 9:01 frank.chang
2025-11-14 9:01 ` [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
2025-11-14 9:01 ` [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
0 siblings, 2 replies; 5+ messages in thread
From: frank.chang @ 2025-11-14 9:01 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
MISA.C and MISA.X should be set when the following extensions are
selected:
MISA.C:
* Zca and not F.
* Zca, Zcf and F (but not D) is specified (RV32 only).
* Zca, Zcf and Zcd if D is specified (RV32 only).
* Zca, Zcd if D is specified (RV64 only)
MISA.X:
* When there are any non-standard extensions enabled.
This patchset sets MISA.[C|X] bits based on the selected extensions.
Frank Chang (2):
target/riscv: Update MISA.C for Zc* extensions
target/riscv: Update MISA.X for non-standard extensions
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 46 ++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions
2025-11-14 9:01 [PATCH 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
@ 2025-11-14 9:01 ` frank.chang
2025-11-17 13:53 ` Daniel Henrique Barboza
2025-11-14 9:01 ` [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
1 sibling, 1 reply; 5+ messages in thread
From: frank.chang @ 2025-11-14 9:01 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang, Max Chou
From: Frank Chang <frank.chang@sifive.com>
MISA.C is set if the following extensions are selected:
* Zca and not F.
* Zca, Zcf and F (but not D) is specified (RV32 only).
* Zca, Zcf and Zcd if D is specified (RV32 only).
* Zca, Zcd if D is specified (RV64 only).
Therefore, we need to set MISA.C according to the rules for Zc*
extensions.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Max Chou <max.chou@sifive.com>
---
target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 440626ddfad..da09a2417cc 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1150,6 +1150,36 @@ static void riscv_cpu_enable_implied_rules(RISCVCPU *cpu)
}
}
+/*
+ * MISA.C is set if the following extensions are selected:
+ * - Zca and not F.
+ * - Zca, Zcf and F (but not D) is specified on RV32.
+ * - Zca, Zcf and Zcd if D is specified on RV32.
+ * - Zca, Zcd if D is specified on RV64.
+ */
+static void riscv_cpu_update_misa_c(RISCVCPU *cpu)
+{
+ CPURISCVState *env = &cpu->env;
+
+ if (cpu->cfg.ext_zca && !riscv_has_ext(env, RVF)) {
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
+ return;
+ }
+
+ if (riscv_cpu_mxl(env) == MXL_RV32 &&
+ cpu->cfg.ext_zca && cpu->cfg.ext_zcf &&
+ riscv_has_ext(env, RVD) ? cpu->cfg.ext_zcd : riscv_has_ext(env, RVF)) {
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
+ return;
+ }
+
+ if (riscv_cpu_mxl(env) == MXL_RV64 &&
+ cpu->cfg.ext_zca && cpu->cfg.ext_zcd) {
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
+ return;
+ }
+}
+
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
{
CPURISCVState *env = &cpu->env;
@@ -1157,6 +1187,7 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
riscv_cpu_init_implied_exts_rules();
riscv_cpu_enable_implied_rules(cpu);
+ riscv_cpu_update_misa_c(cpu);
riscv_cpu_validate_misa_priv(env, &local_err);
if (local_err != NULL) {
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions
2025-11-14 9:01 [PATCH 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
2025-11-14 9:01 ` [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
@ 2025-11-14 9:01 ` frank.chang
2025-11-17 13:53 ` Daniel Henrique Barboza
1 sibling, 1 reply; 5+ messages in thread
From: frank.chang @ 2025-11-14 9:01 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang, Max Chou
From: Frank Chang <frank.chang@sifive.com>
MISA.X is set if there are any non-standard extensions.
We should set MISA.X when any of the vendor extensions is enabled.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Max Chou <max.chou@sifive.com>
---
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 8899bf7667a..2e0c92fe593 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;
#define RVH RV('H')
#define RVG RV('G')
#define RVB RV('B')
+#define RVX RV('X')
extern const uint32_t misa_bits[];
const char *riscv_get_misa_ext_name(uint32_t bit);
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index da09a2417cc..0d730f4d774 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1180,6 +1180,20 @@ static void riscv_cpu_update_misa_c(RISCVCPU *cpu)
}
}
+/* MISA.X is set when any of the non-standard extensions is enabled. */
+static void riscv_cpu_update_misa_x(RISCVCPU *cpu)
+{
+ CPURISCVState *env = &cpu->env;
+ const RISCVCPUMultiExtConfig *arr = riscv_cpu_vendor_exts;
+
+ for (int i = 0; arr[i].name != NULL; i++) {
+ if (isa_ext_is_enabled(cpu, arr[i].offset)) {
+ riscv_cpu_set_misa_ext(env, env->misa_ext | RVX);
+ break;
+ }
+ }
+}
+
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
{
CPURISCVState *env = &cpu->env;
@@ -1188,6 +1202,7 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
riscv_cpu_init_implied_exts_rules();
riscv_cpu_enable_implied_rules(cpu);
riscv_cpu_update_misa_c(cpu);
+ riscv_cpu_update_misa_x(cpu);
riscv_cpu_validate_misa_priv(env, &local_err);
if (local_err != NULL) {
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions
2025-11-14 9:01 ` [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
@ 2025-11-17 13:53 ` Daniel Henrique Barboza
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Henrique Barboza @ 2025-11-17 13:53 UTC (permalink / raw)
To: frank.chang, qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li, Liu Zhiwei,
open list:RISC-V TCG CPUs, Max Chou
On 11/14/25 6:01 AM, frank.chang@sifive.com wrote:
> From: Frank Chang <frank.chang@sifive.com>
>
> MISA.C is set if the following extensions are selected:
> * Zca and not F.
> * Zca, Zcf and F (but not D) is specified (RV32 only).
> * Zca, Zcf and Zcd if D is specified (RV32 only).
> * Zca, Zcd if D is specified (RV64 only).
>
> Therefore, we need to set MISA.C according to the rules for Zc*
> extensions.
>
> Signed-off-by: Frank Chang <frank.chang@sifive.com>
> Reviewed-by: Max Chou <max.chou@sifive.com>
> ---
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index 440626ddfad..da09a2417cc 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -1150,6 +1150,36 @@ static void riscv_cpu_enable_implied_rules(RISCVCPU *cpu)
> }
> }
>
> +/*
> + * MISA.C is set if the following extensions are selected:
> + * - Zca and not F.
> + * - Zca, Zcf and F (but not D) is specified on RV32.
> + * - Zca, Zcf and Zcd if D is specified on RV32.
> + * - Zca, Zcd if D is specified on RV64.
> + */
> +static void riscv_cpu_update_misa_c(RISCVCPU *cpu)
> +{
> + CPURISCVState *env = &cpu->env;
> +
> + if (cpu->cfg.ext_zca && !riscv_has_ext(env, RVF)) {
> + riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
> + return;
> + }
> +
> + if (riscv_cpu_mxl(env) == MXL_RV32 &&
> + cpu->cfg.ext_zca && cpu->cfg.ext_zcf &&
> + riscv_has_ext(env, RVD) ? cpu->cfg.ext_zcd : riscv_has_ext(env, RVF)) {
> + riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
> + return;
> + }
> +
> + if (riscv_cpu_mxl(env) == MXL_RV64 &&
> + cpu->cfg.ext_zca && cpu->cfg.ext_zcd) {
> + riscv_cpu_set_misa_ext(env, env->misa_ext | RVC);
> + return;
> + }
> +}
> +
> void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> {
> CPURISCVState *env = &cpu->env;
> @@ -1157,6 +1187,7 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
>
> riscv_cpu_init_implied_exts_rules();
> riscv_cpu_enable_implied_rules(cpu);
> + riscv_cpu_update_misa_c(cpu);
>
> riscv_cpu_validate_misa_priv(env, &local_err);
> if (local_err != NULL) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions
2025-11-14 9:01 ` [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
@ 2025-11-17 13:53 ` Daniel Henrique Barboza
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Henrique Barboza @ 2025-11-17 13:53 UTC (permalink / raw)
To: frank.chang, qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li, Liu Zhiwei,
open list:RISC-V TCG CPUs, Max Chou
On 11/14/25 6:01 AM, frank.chang@sifive.com wrote:
> From: Frank Chang <frank.chang@sifive.com>
>
> MISA.X is set if there are any non-standard extensions.
> We should set MISA.X when any of the vendor extensions is enabled.
>
> Signed-off-by: Frank Chang <frank.chang@sifive.com>
> Reviewed-by: Max Chou <max.chou@sifive.com>
> ---
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> target/riscv/cpu.h | 1 +
> target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 8899bf7667a..2e0c92fe593 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;
> #define RVH RV('H')
> #define RVG RV('G')
> #define RVB RV('B')
> +#define RVX RV('X')
>
> extern const uint32_t misa_bits[];
> const char *riscv_get_misa_ext_name(uint32_t bit);
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index da09a2417cc..0d730f4d774 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -1180,6 +1180,20 @@ static void riscv_cpu_update_misa_c(RISCVCPU *cpu)
> }
> }
>
> +/* MISA.X is set when any of the non-standard extensions is enabled. */
> +static void riscv_cpu_update_misa_x(RISCVCPU *cpu)
> +{
> + CPURISCVState *env = &cpu->env;
> + const RISCVCPUMultiExtConfig *arr = riscv_cpu_vendor_exts;
> +
> + for (int i = 0; arr[i].name != NULL; i++) {
> + if (isa_ext_is_enabled(cpu, arr[i].offset)) {
> + riscv_cpu_set_misa_ext(env, env->misa_ext | RVX);
> + break;
> + }
> + }
> +}
> +
> void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> {
> CPURISCVState *env = &cpu->env;
> @@ -1188,6 +1202,7 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> riscv_cpu_init_implied_exts_rules();
> riscv_cpu_enable_implied_rules(cpu);
> riscv_cpu_update_misa_c(cpu);
> + riscv_cpu_update_misa_x(cpu);
>
> riscv_cpu_validate_misa_priv(env, &local_err);
> if (local_err != NULL) {
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-17 13:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 9:01 [PATCH 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
2025-11-14 9:01 ` [PATCH 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
2025-11-17 13:53 ` Daniel Henrique Barboza
2025-11-14 9:01 ` [PATCH 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
2025-11-17 13:53 ` Daniel Henrique Barboza
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).