target/riscv: add zicsr/zifencei to isa_string
PATCH 1/1 target/riscv: add zicsr/zifencei to isa_string
Zicsr/Zifencei is not in 'I' since ISA version 20190608, thus to fully express the capability of the CPU, they should be exposed in isa_string.
--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/riscv/cpu.c +2 -0
@@ -1027,6 +1027,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zicsr, ext_icsr), +ISA_EDATA_ENTRY (zifencei, ext_ifencei),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx),
Signature · 1 line
2.35.1
This patch could work successfully in qemu. With command "cat /proc/device-tree/cpus/cpu@0/riscv\,isa", string "zicsr" and "zifencei" could be found in linux device tree.
Quoted 15 lines · Hongren (Zenithal) Zheng
Zicsr/Zifencei is not in 'I' since ISA version 20190608, thus to fully express the capability of the CPU, they should be exposed in
isa_string.Signed-off-by Hongren (Zenithal) Zheng <[email protected]>--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/riscv/cpu.c +0
-0
target/riscv/cpu.c static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) · line 1031
Quoted 5 lines
target/riscv/cpu.c +2
-0@@ -1027,6 +1027,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zicsr, ext_icsr), +ISA_EDATA_ENTRY (zifencei, ext_ifencei),
Shouldn't we have a spec version check here?
Alistair
Quoted 7 lines
target/riscv/cpu.c +0
-1ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), ISA_EDATA_ENTRY(zfinx, ext_zfinx), --2.35.1
Quoted 11 lines · Alistair Francis
Quoted 10 lines · Hongren (Zenithal) Zheng
Zicsr/Zifencei is not in 'I' since ISA version 20190608, thus to fully express the capability of the CPU, they should be exposed in
isa_string.Signed-off-by Hongren (Zenithal) Zheng <[email protected]>--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 12 lines
target/riscv/cpu.c static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) · line 1031
Quoted 10 lines
target/riscv/cpu.c +2
-0@@ -1027,6 +1027,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zicsr, ext_icsr), +ISA_EDATA_ENTRY (zifencei, ext_ifencei),Shouldn't we have a spec version check here?
I think that can be done, but most of the time it is not necessary. For old specs, the "short-isa-string" can be a workaround.
This patch is actually a follow-up of "target/riscv: Change "G" expansion"
https://github.com/alistair23/qemu/commit/72bd25b7b88d0536bfb5666990e296587d4057a5
where "G" is expanded with "zicsr"/"zifencei" without checking unpriv spec version.
From the summary from Kito from gnu toolchain
https://lkml.org/lkml/2022/1/24/537
we know that there are at least 3 formally released unpriv specs:
2.2, 20190608 and 20191213, and frequent informal release from
https://github.com/riscv/riscv-isa-manual/releases
If we add a spec check, we need to add a PROP_STRING and and parse the version. We then need an enum like PRIV_VERSION_1_12_0 and we needs to g_strcmp0 in riscv_cpu_realize, just as what priv spec had done.
And we need to define a default unpriv spec version, which should be 20191213.
I can add a separate patch for it if you do think it is necessary.
If the guest does want old spec version, I think the recently added "short-isa-string" option from Tsukasa OI is suitable. Instead of -cpu rv64,unpriv_spec=2.2 they can just use -cpu rv64,short-isa-string=true to solve the issue.
Cc Tsukasa OI
Quoted 10 lines
Alistair
Quoted 7 lines
target/riscv/cpu.c +0
-1ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), ISA_EDATA_ENTRY(zfinx, ext_zfinx), --2.35.1
Alistair Francis
Reviewed-byQuoted 48 lines · Hongren (Zenithal) Zheng
Quoted 11 lines · Alistair Francis
Quoted 10 lines · Hongren (Zenithal) Zheng
Zicsr/Zifencei is not in 'I' since ISA version 20190608, thus to fully express the capability of the CPU, they should be exposed in
isa_string.Signed-off-by Hongren (Zenithal) Zheng <[email protected]>--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)Quoted 12 lines
target/riscv/cpu.c static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) · line 1031
Quoted 10 lines
target/riscv/cpu.c +2
-0@@ -1027,6 +1027,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zicsr, ext_icsr), +ISA_EDATA_ENTRY (zifencei, ext_ifencei),Shouldn't we have a spec version check here?
I think that can be done, but most of the time it is not necessary. For old specs, the "short-isa-string" can be a workaround.
This patch is actually a follow-up of "target/riscv: Change "G" expansion"
https://github.com/alistair23/qemu/commit/72bd25b7b88d0536bfb5666990e296587d4057a5
where "G" is expanded with "zicsr"/"zifencei" without checking unpriv spec version.From the summary from Kito from gnu toolchain
https://lkml.org/lkml/2022/1/24/537
we know that there are at least 3 formally released unpriv specs:
2.2, 20190608 and 20191213, and frequent informal release from
https://github.com/riscv/riscv-isa-manual/releasesIf we add a spec check, we need to add a
PROP_STRINGand and parse the version. We then need an enum likePRIV_VERSION_1_12_0and we needs tog_strcmp0inriscv_cpu_realize, just as what priv spec had done.And we need to define a default unpriv spec version, which should be 20191213.
Quoted 6 lines
I can add a separate patch for it if you do think it is necessary.
If the guest does want old spec version, I think the recently added "short-isa-string" option from Tsukasa OI is suitable. Instead of -cpu rv64,unpriv_spec=2.2 they can just use -cpu rv64,short-isa-string=true to solve the issue.
Ok, fair point
Alistair
Quoted 13 lines
Cc Tsukasa OI
Quoted 10 lines
Alistair
Quoted 7 lines
target/riscv/cpu.c +0
-1ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), ISA_EDATA_ENTRY(zfinx, ext_zfinx), --2.35.1
Alistair Francis
AppliedQuoted 6 lines · Hongren (Zenithal) Zheng
Zicsr/Zifencei is not in 'I' since ISA version 20190608, thus to fully express the capability of the CPU, they should be exposed in
isa_string.Signed-off-by Hongren (Zenithal) Zheng <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 21 lines
--- target/riscv/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/riscv/cpu.c +2
-1@@ -1027,6 +1027,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { +ISA_EDATA_ENTRY (zicsr, ext_icsr), +ISA_EDATA_ENTRY (zifencei, ext_ifencei),ISA_EDATA_ENTRY (zfh, ext_zfh),ISA_EDATA_ENTRY (zfhmin, ext_zfhmin),ISA_EDATA_ENTRY (zfinx, ext_zfinx), --2.35.1