* [PATCH v2 0/2] Set MISA.[C|X] based on the selected extensions
@ 2025-11-28 2:22 frank.chang
2025-11-28 2:23 ` [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
2025-11-28 2:23 ` [PATCH v2 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-28 2:22 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.
Changelog:
* v2: Fix the missing parentheses bug.
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 | 47 ++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions
2025-11-28 2:22 [PATCH v2 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
@ 2025-11-28 2:23 ` frank.chang
2025-11-28 12:16 ` Daniel Henrique Barboza
2026-03-11 2:26 ` Frank Chang
2025-11-28 2:23 ` [PATCH v2 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
1 sibling, 2 replies; 5+ messages in thread
From: frank.chang @ 2025-11-28 2:23 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 | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 440626ddfad..752eee32289 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1150,6 +1150,37 @@ 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 +1188,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 v2 2/2] target/riscv: Update MISA.X for non-standard extensions
2025-11-28 2:22 [PATCH v2 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
2025-11-28 2:23 ` [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
@ 2025-11-28 2:23 ` frank.chang
1 sibling, 0 replies; 5+ messages in thread
From: frank.chang @ 2025-11-28 2:23 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>
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 752eee32289..61d7666288e 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1181,6 +1181,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;
@@ -1189,6 +1203,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 v2 1/2] target/riscv: Update MISA.C for Zc* extensions
2025-11-28 2:23 ` [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
@ 2025-11-28 12:16 ` Daniel Henrique Barboza
2026-03-11 2:26 ` Frank Chang
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Henrique Barboza @ 2025-11-28 12:16 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/27/25 11:23 PM, 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 | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index 440626ddfad..752eee32289 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -1150,6 +1150,37 @@ 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 +1188,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 v2 1/2] target/riscv: Update MISA.C for Zc* extensions
2025-11-28 2:23 ` [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
2025-11-28 12:16 ` Daniel Henrique Barboza
@ 2026-03-11 2:26 ` Frank Chang
1 sibling, 0 replies; 5+ messages in thread
From: Frank Chang @ 2026-03-11 2:26 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Max Chou
[-- Attachment #1: Type: text/plain, Size: 2489 bytes --]
Gentle ping
Thanks~
On Fri, Nov 28, 2025 at 10:23 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>
> ---
> target/riscv/tcg/tcg-cpu.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index 440626ddfad..752eee32289 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -1150,6 +1150,37 @@ 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 +1188,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
>
>
[-- Attachment #2: Type: text/html, Size: 3344 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-11 2:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-28 2:22 [PATCH v2 0/2] Set MISA.[C|X] based on the selected extensions frank.chang
2025-11-28 2:23 ` [PATCH v2 1/2] target/riscv: Update MISA.C for Zc* extensions frank.chang
2025-11-28 12:16 ` Daniel Henrique Barboza
2026-03-11 2:26 ` Frank Chang
2025-11-28 2:23 ` [PATCH v2 2/2] target/riscv: Update MISA.X for non-standard extensions frank.chang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox