Fifth RISC-V PR for QEMU 8.0
Subsystems (2)
merged tag 'buildsys-qom-qdev-ui-20230227'
The following changes since commit 627634031092e1514f363fd8659a579398de0f0e:
Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)
are available in the Git repository at:
https://gitlab.com/palmer-dabbelt/qemu.git tags/pull-riscv-to-apply-20230303
for you to fetch changes up to 37151032989ecf6e7ce8b65bc7bcb400d0318b2c:
Merge patch series "target/riscv: some vector_helper.c cleanups" (2023-03-01 18:09:48 -0800)
----------------------------------------------------------------
Fifth RISC-V PR for QEMU 8.0
* Experimantal support for writable misa.
* Support for Svadu extension.
* Support for the Zicond extension.
* Fixes to gdbstub, CSR accesses, dependencies between the various floating-point exceptions, and XTheadMemPair.
* Many cleanups.
----------------------------------------------------------------
There's a lot of cleanups here, a handful of which ended up stepping on each other and were necessary for various features. I tried to keep each individual patch set intact, but that led to some merge conflicts and a bit of a clunky history -- I'm not sure what the right answer is there, happy to re-spin this to be more linear if that's problem for folks.
Unfortunately the OpenSBI bump is still failing CI, it turns out I missed the second stage. I was intending on having a sixth PR anyway as I'd really like to get the ACPI patches in for 8.0 so we can start testing everywhere else. There's also a patch set from Daniel that's ready to go but depends on some recently merged TCG patches, so I figured it'd be better to just send what's ready now rather than trying to make the history more complicated.
This all passes my local tests ("make check" and a bunch of Linux configs), but "push-ci-now" is still tripping up on OpenSBI as that's due to some network resources changing. With any luck I'll have some time to sort things out this weekend (though always happy to have some help if anyone wants to throw in some time).
----------------------------------------------------------------
Bin Meng (20):
target/riscv: gdbstub: Check priv spec version before reporting CSR target/riscv: Add some comments to clarify the priority policy of riscv_csrrw_check() target/riscv: Use g_assert() for the predicate() NULL check target/riscv: gdbstub: Minor change for better readability target/riscv: gdbstub: Do not generate CSR XML if Zicsr is disabled target/riscv: Coding style fixes in csr.c
target/riscv: Use 'bool' type for read_only
target/riscv: Simplify {read, write}_pmpcfg() a little bit target/riscv: Simplify getting RISCVCPU pointer from env
target/riscv: Avoid reporting odd-numbered pmpcfgX in the CSR XML for RV64 target/riscv: gdbstub: Turn on debugger mode before calling CSR predicate() target/riscv: gdbstub: Drop the vector CSRs in riscv-vector.xml target/riscv: Allow debugger to access user timer and counter CSRs target/riscv: Allow debugger to access seed CSR
target/riscv: Allow debugger to access {h, s}stateen CSRs target/riscv: Allow debugger to access sstc CSRs
target/riscv: Drop priv level check in mseccfg predicate() target/riscv: Group all predicate() routines together
hw/riscv: Skip re-generating DT nodes for a given DTB
hw/riscv: Move the dtb load bits outside of create_fdt()
Christoph Müllner (1):
RISC-V: XTheadMemPair: Remove register restrictions for store-pair
Daniel Henrique Barboza (16):
target/riscv: introduce riscv_cpu_cfg()
target/riscv: do not mask unsupported QEMU extensions in write_misa() target/riscv: allow MISA writes as experimental
target/riscv: remove RISCV_FEATURE_DEBUG
target/riscv/cpu.c: error out if EPMP is enabled without PMP target/riscv: remove RISCV_FEATURE_EPMP
target/riscv: remove RISCV_FEATURE_PMP
hw/riscv/virt.c: do not use RISCV_FEATURE_MMU in create_fdt_socket_cpus() target/riscv: remove RISCV_FEATURE_MMU
target/riscv/cpu: remove CPUArchState::features and friends target/riscv/csr.c: use env_archcpu() in ctr() target/riscv/csr.c: simplify mctr()
target/riscv/csr.c: use riscv_cpu_cfg() to avoid env_cpu() pointers target/riscv/csr.c: avoid env_archcpu() usages when reading RISCVCPUConfig target/riscv/vector_helper.c: create vext_set_tail_elems_1s() target/riscv/vector_helper.c: avoid env_archcpu() when reading RISCVCPUConfig
Palmer Dabbelt (6):
Merge patch series "make write_misa a no-op and FEATURE_* cleanups" Merge patch series "target/riscv: Some updates to float point related extensions" Merge patch series "target/riscv: Various fixes to gdbstub and CSR access" Merge patch series "target/riscv: Add support for Svadu extension" Merge patch series "RISCVCPUConfig related cleanups"
Merge patch series "target/riscv: some vector_helper.c cleanups"
Shaobo Song (1):
target/riscv: Fix checking of whether instruciton at 'pc_next' spans pages
Weiwei Li (21):
target/riscv: Fix the relationship between Zfhmin and Zfh
target/riscv: Fix the relationship between Zhinxmin and Zhinx target/riscv: Simplify the check for Zfhmin and Zhinxmin
target/riscv: Add cfg properties for Zv* extensions
target/riscv: Fix relationship between V, Zve*, F and D
target/riscv: Add property check for Zvfh{min} extensions
target/riscv: Indent fixes in cpu.c
target/riscv: Simplify check for Zve32f and Zve64f
target/riscv: Replace check for F/D to Zve32f/Zve64d in trans_rvv.c.inc target/riscv: Remove redundunt check for zve32f and zve64f
target/riscv: Add support for Zvfh/zvfhmin extensions
target/riscv: Fix check for vector load/store instructions when EEW=64 target/riscv: Simplify check for EEW = 64 in trans_rvv.c.inc target/riscv: Expose properties for Zv* extensions
target/riscv: Add support for Zicond extension
target/riscv: Fix the relationship between menvcfg.PBMTE/STCE and Svpbmt/Sstc extensions target/riscv: Fix the relationship of PBMTE/STCE fields between menvcfg and henvcfg target/riscv: Add csr support for svadu
target/riscv: Add *envcfg.PBMTE related check in address translation target/riscv: Add *envcfg.HADE related check in address translation target/riscv: Export Svadu property
hw/riscv/sifive_u.c | 30 +-- hw/riscv/virt.c | 35 +-- include/hw/riscv/sifive_u.h | 1 + target/riscv/cpu.c | 134 ++++++---- target/riscv/cpu.h | 34 +-- target/riscv/cpu_bits.h | 4 + target/riscv/cpu_helper.c | 24 +- target/riscv/csr.c | 354 ++++++++++++++------------- target/riscv/gdbstub.c | 100 ++------ target/riscv/insn32.decode | 4 + target/riscv/insn_trans/trans_rvv.c.inc | 184 +++++--------- target/riscv/insn_trans/trans_rvzfh.c.inc | 25 +- target/riscv/insn_trans/trans_rvzicond.c.inc | 49 ++++ target/riscv/insn_trans/trans_xthead.c.inc | 4 - target/riscv/machine.c | 11 +- target/riscv/monitor.c | 2 +- target/riscv/op_helper.c | 2 +- target/riscv/pmp.c | 8 +- target/riscv/translate.c | 3 +- target/riscv/vector_helper.c | 104 +++----- 20 files changed, 538 insertions(+), 574 deletions(-) create mode 100644 target/riscv/insn_trans/trans_rvzicond.c.inc
[PULL 01/59] target/riscv: introduce riscv_cpu_cfg()
From: Daniel Henrique Barboza <[email protected]>
We're going to do changes that requires accessing the RISCVCPUConfig struct from the RISCVCPU, having access only to a CPURISCVState 'env' pointer. Add a helper to make the code easier to read.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 5 +++++ 1 file changed, 5 insertions(+)
target/riscv/cpu.h +5 -0
@@ -654,6 +654,11 @@ static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env)#endif #define riscv_cpu_mxl_bits (env) (1UL << (4 + riscv_cpu_mxl(env))) +static inline const RISCVCPUConfig *riscv_cpu_cfg (CPURISCVState *env) +{ +return &env_archcpu (env)->cfg; +} +#if defined(TARGET_RISCV32 )#define cpu_recompute_xl (env) ((void)(env), MXL_RV32)#else
Signature · 1 line
2.39.2
[PULL 04/59] target/riscv: remove RISCV_FEATURE_DEBUG
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
RISCV_FEATURE_DEBUG will always follow the value defined by cpu->cfg.debug flag. Read the flag instead.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 6 +----- target/riscv/cpu.h | 1 - target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 2 +- target/riscv/machine.c | 3 +-- 5 files changed, 4 insertions(+), 10 deletions(-)
target/riscv/cpu.c +1 -5
@@ -637,7 +637,7 @@ static void riscv_cpu_reset_hold(Object *obj)set_default_nan_mode (1 , &env->fp_status);#ifndef CONFIG_USER_ONLY -if (riscv_feature (env,RISCV_FEATURE_DEBUG )) { +if (cpu->cfg.debug) {riscv_trigger_init (env); }
@@ -935,10 +935,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (cpu->cfg.debug) { -riscv_set_feature (env,RISCV_FEATURE_DEBUG ); - } -#ifndef CONFIG_USER_ONLY if (cpu->cfg.ext_sstc) {
target/riscv/cpu.h +0 -1
@@ -89,7 +89,6 @@ enum {RISCV_FEATURE_MMU ,RISCV_FEATURE_PMP , RISCV_FEATURE_EPMP, - RISCV_FEATURE_DEBUG };/* Privileged specification version */
target/riscv/cpu_helper.c +1 -1
@@ -105,7 +105,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags =FIELD_DP32 (flags,TB_FLAGS ,MSTATUS_HS_VS , get_field(env->mstatus_hs, MSTATUS_VS)); } -if (riscv_feature (env,RISCV_FEATURE_DEBUG ) && !icount_enabled ()) { +if (cpu->cfg.debug && !icount_enabled ()) { flags =FIELD_DP32 (flags,TB_FLAGS ,ITRIGGER , env->itrigger_enabled); }#endif
target/riscv/csr.c +1 -1
@@ -437,7 +437,7 @@ static RISCVException epmp(CPURISCVState *env, int csrno)static RISCVException debug (CPURISCVState *env,int csrno) { -if (riscv_feature (env,RISCV_FEATURE_DEBUG )) { +if (riscv_cpu_cfg (env)->debug) {return RISCV_EXCP_NONE ; }
target/riscv/machine.c +1 -2
@@ -226,9 +226,8 @@ static const VMStateDescription vmstate_kvmtimer = {static bool debug_needed (void *opaque) {RISCVCPU *cpu = opaque; -CPURISCVState *env = &cpu->env; -return riscv_feature (env,RISCV_FEATURE_DEBUG ); +return cpu->cfg.debug; }static int debug_post_load (void *opaque,int version_id)
Signature · 1 line
2.39.2
[PULL 05/59] target/riscv/cpu.c: error out if EPMP is enabled without PMP
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
Instead of silently ignoring the EPMP setting if there is no PMP available, error out informing the user that EPMP depends on PMP support:
$ ./qemu-system-riscv64 -cpu rv64,pmp=false,x-epmp=true qemu-system-riscv64: Invalid configuration: EPMP requires PMP support
This will force users to pick saner options in the QEMU command line.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
target/riscv/cpu.c +7 -2
@@ -925,13 +925,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)if (cpu->cfg.pmp) {riscv_set_feature (env,RISCV_FEATURE_PMP ); + } + +if (cpu->cfg.epmp) { +riscv_set_feature (env,RISCV_FEATURE_EPMP );/* * Enhanced PMP should only be available * on harts with PMP support */ -if (cpu->cfg.epmp) { -riscv_set_feature (env,RISCV_FEATURE_EPMP ); +if (!cpu->cfg.pmp) { +error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +return ; } }
Signature · 1 line
2.39.2
[PULL 07/59] target/riscv: remove RISCV_FEATURE_PMP
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
RISCV_FEATURE_PMP is being set via riscv_set_feature() by mirroring the cpu->cfg.pmp flag. Use the flag instead.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 4 ---- target/riscv/cpu.h | 1 - target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 2 +- target/riscv/machine.c | 3 +-- target/riscv/op_helper.c | 2 +- target/riscv/pmp.c | 2 +- 7 files changed, 5 insertions(+), 11 deletions(-)
target/riscv/cpu.c +0 -4
@@ -923,10 +923,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)riscv_set_feature (env,RISCV_FEATURE_MMU ); } -if (cpu->cfg.pmp) { -riscv_set_feature (env,RISCV_FEATURE_PMP ); - } -if (cpu->cfg.epmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available
target/riscv/cpu.h +0 -1
@@ -87,7 +87,6 @@so a cpu features bitfield is required, likewise for optional PMP support */ enum {RISCV_FEATURE_MMU , -RISCV_FEATURE_PMP , };/* Privileged specification version */
target/riscv/cpu_helper.c +1 -1
@@ -706,7 +706,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,pmp_priv_t pmp_priv;int pmp_index =-1 ; -if (!riscv_feature (env,RISCV_FEATURE_PMP )) { +if (!riscv_cpu_cfg (env)->pmp) { *prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ;return TRANSLATE_SUCCESS ; }
target/riscv/csr.c +1 -1
@@ -419,7 +419,7 @@ static int aia_hmode32(CPURISCVState *env, int csrno)static RISCVException pmp (CPURISCVState *env,int csrno) { -if (riscv_feature (env,RISCV_FEATURE_PMP )) { +if (riscv_cpu_cfg (env)->pmp) {return RISCV_EXCP_NONE ; }
target/riscv/machine.c +1 -2
@@ -27,9 +27,8 @@static bool pmp_needed (void *opaque) {RISCVCPU *cpu = opaque; -CPURISCVState *env = &cpu->env; -return riscv_feature (env,RISCV_FEATURE_PMP ); +return cpu->cfg.pmp; }static int pmp_post_load (void *opaque,int version_id)
target/riscv/op_helper.c +1 -1
@@ -195,7 +195,7 @@ target_ulong helper_mret(CPURISCVState *env)uint64_t mstatus = env->mstatus;target_ulong prev_priv =get_field (mstatus,MSTATUS_MPP ); -if (riscv_feature (env,RISCV_FEATURE_PMP ) && +if (riscv_cpu_cfg (env)->pmp && !pmp_get_num_rules (env) && (prev_priv !=PRV_M )) {riscv_raise_exception (env,RISCV_EXCP_INST_ACCESS_FAULT ,GETPC ()); }
target/riscv/pmp.c +1 -1
@@ -265,7 +265,7 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, } } -if ((!riscv_feature (env,RISCV_FEATURE_PMP )) || (mode ==PRV_M )) { +if (!riscv_cpu_cfg (env)->pmp || (mode ==PRV_M )) {/* * Privileged spec v1.10 states if HW doesn't implement any PMP entry * or no PMP entry matches an M-Mode access, the access succeeds.
Signature · 1 line
2.39.2
[PULL 08/59] hw/riscv/virt.c: do not use RISCV_FEATURE_MMU in create_fdt_socket_cpus()
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
Read cpu_ptr->cfg.mmu directly. As a bonus, use cpu_ptr in riscv_isa_string().
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/riscv/virt.c +4 -3
@@ -232,20 +232,21 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket,bool is_32_bit =riscv_is_32bit (&s->soc[0 ]);for (cpu = s->soc[socket].num_harts -1 ; cpu >=0 ; cpu--) { +RISCVCPU *cpu_ptr = &s->soc[socket].harts[cpu]; + cpu_phandle = (*phandle)++; cpu_name =g_strdup_printf ("/cpus/cpu@%d" , s->soc[socket].hartid_base + cpu);qemu_fdt_add_subnode (ms->fdt, cpu_name); -if (riscv_feature (&s->soc[socket].harts[cpu].env, -RISCV_FEATURE_MMU )) { +if (cpu_ptr->cfg.mmu) {qemu_fdt_setprop_string (ms->fdt, cpu_name,"mmu-type" , (is_32_bit) ?"riscv,sv32" :"riscv,sv48" ); }else {qemu_fdt_setprop_string (ms->fdt, cpu_name,"mmu-type" ,"riscv,none" ); } - name =riscv_isa_string (&s->soc[socket].harts[cpu]); + name =riscv_isa_string (cpu_ptr);qemu_fdt_setprop_string (ms->fdt, cpu_name,"riscv,isa" , name);g_free (name);qemu_fdt_setprop_string (ms->fdt, cpu_name,"compatible" ,"riscv" );
Signature · 1 line
2.39.2
[PULL 12/59] target/riscv: Fix the relationship between Zhinxmin and Zhinx
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Just like zfh and zfhmin, Zhinxmin is part of Zhinx so Zhinxmin will be enabled when Zhinx is enabled.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.c +5 -2
@@ -754,8 +754,11 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) }/* Set the ISA extensions, checks should have happened above */ -if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || - cpu->cfg.ext_zhinxmin) { +if (cpu->cfg.ext_zhinx) { + cpu->cfg.ext_zhinxmin = true; + } + +if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinxmin) { cpu->cfg.ext_zfinx = true; }
Signature · 1 line
2.39.2
[PULL 10/59] target/riscv/cpu: remove CPUArchState::features and friends
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
The attribute is no longer used since we can retrieve all the enabled features in the hart by using cpu->cfg instead.
Remove env->feature, riscv_feature() and riscv_set_feature(). We also need to bump vmstate_riscv_cpu version_id and minimal_version_id since 'features' is no longer being migrated.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 12 ------------ target/riscv/machine.c | 5 ++--- 2 files changed, 2 insertions(+), 15 deletions(-)
target/riscv/cpu.h +0 -12
@@ -175,8 +175,6 @@ struct CPUArchState {/* 128-bit helpers upper part return value */ target_ulong retxh; -uint32_t features; -#ifdef CONFIG_USER_ONLY uint32_t elf_flags;#endif
@@ -525,16 +523,6 @@ static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext)return (env->misa_ext & ext) !=0 ; } -static inline bool riscv_feature (CPURISCVState *env,int feature) -{ -return env->features & (1ULL << feature); -} - -static inline void riscv_set_feature (CPURISCVState *env,int feature) -{ - env->features |= (1ULL << feature); -} -#include "cpu_user.h" extern const char *const riscv_int_regnames[];
target/riscv/machine.c +2 -3
@@ -331,8 +331,8 @@ static const VMStateDescription vmstate_pmu_ctr_state = {const VMStateDescription vmstate_riscv_cpu = { .name ="cpu" , - .version_id =6 , - .minimum_version_id =6 , + .version_id =7 , + .minimum_version_id =7 , .post_load = riscv_cpu_post_load, .fields = (VMStateField []) {VMSTATE_UINTTL_ARRAY (env.gpr,RISCVCPU ,32 ),
@@ -351,7 +351,6 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINT32 (env.misa_ext,RISCVCPU ),VMSTATE_UINT32 (env.misa_mxl_max,RISCVCPU ),VMSTATE_UINT32 (env.misa_ext_mask,RISCVCPU ), -VMSTATE_UINT32 (env.features,RISCVCPU ),VMSTATE_UINTTL (env.priv,RISCVCPU ),VMSTATE_UINTTL (env.virt,RISCVCPU ), VMSTATE_UINT64(env.resetvec, RISCVCPU),
Signature · 1 line
2.39.2
[PULL 02/59] target/riscv: do not mask unsupported QEMU extensions in write_misa()
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
The masking done using env->misa_ext_mask already filters any extension that QEMU doesn't support. If the hart supports the extension then QEMU supports it as well.
If the masking done by env->misa_ext_mask is somehow letting unsupported QEMU extensions pass by, misa_ext_mask itself needs to be fixed instead.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 3 --- 1 file changed, 3 deletions(-)
target/riscv/csr.c +0 -3
@@ -1356,9 +1356,6 @@ static RISCVException write_misa(CPURISCVState *env, int csrno,/* Mask extensions that are not supported by this hart */ val &= env->misa_ext_mask; -/* Mask extensions that are not supported by QEMU */ - val &= (RVI |RVE |RVM |RVA |RVF |RVD |RVC |RVS |RVU |RVV ); -/* 'D' depends on 'F', so clear 'D' if 'F' is not present */ if ((val &RVD ) && !(val &RVF )) { val &= ~RVD ;
Signature · 1 line
2.39.2
[PULL 03/59] target/riscv: allow MISA writes as experimental
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
At this moment, and apparently since ever, we have no way of enabling RISCV_FEATURE_MISA. This means that all the code from write_misa(), all the nuts and bolts that handles how to properly write this CSR, has always been a no-op as well because write_misa() will always exit earlier.
This seems to be benign in the majority of cases. Booting an Ubuntu 'virt' guest and logging all the calls to 'write_misa' shows that no writes to MISA CSR was attempted. Writing MISA, i.e. enabling/disabling RISC-V extensions after the machine is powered on, seems to be a niche use.
After discussions in the mailing list, most notably in [1], we reached the consensus that this code is not suited to be exposed to users because it's not well tested, but at the same time removing it is a bit extreme because we would like to fix it, and it's easier to do so with the code available to use instead of fetching it from git log.
The approach taken here is to get rid of RISCV_FEATURE_MISA altogether and use a new experimental flag called x-misa-w. The default value is false, meaning that we're keeping the existing behavior of doing nothing if a write_misa() is attempted. As with any existing experimental flag, x-misa-w is also a temporary flag that we need to remove once we fix write_misa().
[1] https://lists.gnu.org/archive/html/qemu-devel/2023-02/msg05092.html
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 6 ++++++ target/riscv/cpu.h | 2 +- target/riscv/csr.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.c +6 -0
@@ -1210,6 +1210,12 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("rvv_ta_all_1s" ,RISCVCPU , cfg.rvv_ta_all_1s, false),DEFINE_PROP_BOOL ("rvv_ma_all_1s" ,RISCVCPU , cfg.rvv_ma_all_1s, false), + +/* +* write_misa() is marked as experimental for now so mark +* it with -x and default to 'false'. +*/ +DEFINE_PROP_BOOL ("x-misa-w" ,RISCVCPU , cfg.misa_w, false), DEFINE_PROP_END_OF_LIST(), };
target/riscv/cpu.h +1 -1
@@ -89,7 +89,6 @@ enum {RISCV_FEATURE_MMU ,RISCV_FEATURE_PMP ,RISCV_FEATURE_EPMP , -RISCV_FEATURE_MISA , RISCV_FEATURE_DEBUG };
@@ -498,6 +497,7 @@ struct RISCVCPUConfig {bool pmp;bool epmp;bool debug; +bool misa_w;bool short_isa_string; };
target/riscv/csr.c +1 -1
@@ -1329,7 +1329,7 @@ static RISCVException read_misa(CPURISCVState *env, int csrno,static RISCVException write_misa (CPURISCVState *env,int csrno,target_ulong val) { -if (!riscv_feature (env,RISCV_FEATURE_MISA )) { +if (!riscv_cpu_cfg (env)->misa_w) {/* drop write to misa */ return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 06/59] target/riscv: remove RISCV_FEATURE_EPMP
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
RISCV_FEATURE_EPMP is always set to the same value as the cpu->cfg.epmp flag. Use the flag directly.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 10 +++------- target/riscv/cpu.h | 1 - target/riscv/csr.c | 2 +- target/riscv/pmp.c | 4 ++-- 4 files changed, 6 insertions(+), 11 deletions(-)
target/riscv/cpu.c +3 -7
@@ -927,17 +927,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)riscv_set_feature (env,RISCV_FEATURE_PMP ); } -if (cpu->cfg.epmp) { -riscv_set_feature (env,RISCV_FEATURE_EPMP ); - +if (cpu->cfg.epmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -if (!cpu->cfg.pmp) { -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); -return ; - } +error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +return ; }
target/riscv/cpu.h +0 -1
@@ -88,7 +88,6 @@enum {RISCV_FEATURE_MMU ,RISCV_FEATURE_PMP , -RISCV_FEATURE_EPMP , };/* Privileged specification version */
target/riscv/csr.c +1 -1
@@ -428,7 +428,7 @@ static RISCVException pmp(CPURISCVState *env, int csrno)static RISCVException epmp (CPURISCVState *env,int csrno) { -if (env->priv ==PRV_M &&riscv_feature (env,RISCV_FEATURE_EPMP )) { +if (env->priv ==PRV_M &&riscv_cpu_cfg (env)->epmp) {return RISCV_EXCP_NONE ; }
target/riscv/pmp.c +2 -2
@@ -88,7 +88,7 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_feature (env,RISCV_FEATURE_EPMP )) { +if (riscv_cpu_cfg (env)->epmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;
@@ -239,7 +239,7 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, {bool ret; -if (riscv_feature (env,RISCV_FEATURE_EPMP )) { +if (riscv_cpu_cfg (env)->epmp) {if (MSECCFG_MMWP_ISSET (env)) {/* * The Machine Mode Whitelist Policy (mseccfg.MMWP) is set
Signature · 1 line
2.39.2
[PULL 09/59] target/riscv: remove RISCV_FEATURE_MMU
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
RISCV_FEATURE_MMU is set whether cpu->cfg.mmu is set, so let's just use the flag directly instead.
With this change the enum is also removed. It is worth noticing that this enum, and all the RISCV_FEATURES_* that were contained in it, predates the existence of the cpu->cfg object. Today, using cpu->cfg is an easier way to retrieve all the features and extensions enabled in the hart.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 4 ---- target/riscv/cpu.h | 7 ------- target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 4 ++-- target/riscv/monitor.c | 2 +- target/riscv/pmp.c | 2 +- 6 files changed, 5 insertions(+), 16 deletions(-)
target/riscv/cpu.c +0 -4
@@ -919,10 +919,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (cpu->cfg.mmu) { -riscv_set_feature (env,RISCV_FEATURE_MMU ); - } -if (cpu->cfg.epmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available
target/riscv/cpu.h +0 -7
@@ -81,13 +81,6 @@#define RVH RV('H')#define RVJ RV('J') -/* S extension denotes that Supervisor mode exists, however it is possible -to have a core that support S mode but does not have an MMU and there -is currently no bit in misa to indicate whether an MMU exists or not -so a cpu features bitfield is required, likewise for optional PMP support */ -enum { -RISCV_FEATURE_MMU , -};/* Privileged specification version */ enum {
target/riscv/cpu_helper.c +1 -1
@@ -796,7 +796,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, mode =PRV_U ; } -if (mode ==PRV_M || !riscv_feature (env,RISCV_FEATURE_MMU )) { +if (mode ==PRV_M || !riscv_cpu_cfg (env)->mmu) { *physical = addr; *prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ;return TRANSLATE_SUCCESS ;
target/riscv/csr.c +2 -2
@@ -2621,7 +2621,7 @@ static RISCVException rmw_siph(CPURISCVState *env, int csrno,static RISCVException read_satp (CPURISCVState *env,int csrno,target_ulong *val) { -if (!riscv_feature (env,RISCV_FEATURE_MMU )) { +if (!riscv_cpu_cfg (env)->mmu) { *val =0 ;return RISCV_EXCP_NONE ; }
@@ -2640,7 +2640,7 @@ static RISCVException write_satp(CPURISCVState *env, int csrno, {target_ulong vm, mask; -if (!riscv_feature (env,RISCV_FEATURE_MMU )) { +if (!riscv_cpu_cfg (env)->mmu) {return RISCV_EXCP_NONE ; }
target/riscv/monitor.c +1 -1
@@ -218,7 +218,7 @@ void hmp_info_mem(Monitor *mon, const QDict *qdict)return ; } -if (!riscv_feature (env,RISCV_FEATURE_MMU )) { +if (!riscv_cpu_cfg (env)->mmu) {monitor_printf (mon,"S-mode MMU unavailable\n" );return ; }
target/riscv/pmp.c +1 -1
@@ -315,7 +315,7 @@ int pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, }if (size ==0 ) { -if (riscv_feature (env,RISCV_FEATURE_MMU )) { +if (riscv_cpu_cfg (env)->mmu) {/* * If size is unknown (0), assume that all bytes * from addr to the end of the page will be accessed.
Signature · 1 line
2.39.2
[PULL 14/59] target/riscv: Add cfg properties for Zv* extensions
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Add properties for Zve64d,Zvfh,Zvfhmin extensions.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 3 +++ 1 file changed, 3 insertions(+)
target/riscv/cpu.h +3 -0
@@ -462,7 +462,10 @@ struct RISCVCPUConfig {bool ext_zhinxmin;bool ext_zve32f;bool ext_zve64f; +bool ext_zve64d;bool ext_zmmul; +bool ext_zvfh; +bool ext_zvfhmin;bool ext_smaia;bool ext_ssaia;bool ext_sscofpmf;
Signature · 1 line
2.39.2
[PULL 11/59] target/riscv: Fix the relationship between Zfhmin and Zfh
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Zfhmin is part of Zfh, so Zfhmin will be enabled when Zfh is enabled.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/riscv/cpu.c +5 -1
@@ -729,7 +729,11 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } -if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { +if (cpu->cfg.ext_zfh) { + cpu->cfg.ext_zfhmin = true; + } + +if (cpu->cfg.ext_zfhmin && !cpu->cfg.ext_f) {error_setg (errp,"Zfh/Zfhmin extensions require F extension" );return ; }
Signature · 1 line
2.39.2
[PULL 15/59] target/riscv: Fix relationship between V, Zve*, F and D
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Add dependence chain:
* V => Zve64d => Zve64f => Zve32f => F
* V => Zve64d => D
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
target/riscv/cpu.c +18 -3
@@ -743,12 +743,27 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } -if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { -error_setg (errp,"V extension requires D extension" ); +/* The V vector extension depends on the Zve64d extension */ +if (cpu->cfg.ext_v) { + cpu->cfg.ext_zve64d = true; + } + +/* The Zve64d extension depends on the Zve64f extension */ +if (cpu->cfg.ext_zve64d) { + cpu->cfg.ext_zve64f = true; + } + +/* The Zve64f extension depends on the Zve32f extension */ +if (cpu->cfg.ext_zve64f) { + cpu->cfg.ext_zve32f = true; + } + +if (cpu->cfg.ext_zve64d && !cpu->cfg.ext_d) { +error_setg (errp,"Zve64d/V extensions require D extension" );return ; } -if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { +if (cpu->cfg.ext_zve32f && !cpu->cfg.ext_f) {error_setg (errp,"Zve32f/Zve64f extensions require F extension" );return ; }
Signature · 1 line
2.39.2
[PULL 13/59] target/riscv: Simplify the check for Zfhmin and Zhinxmin
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
We needn't check Zfh and Zhinx in these instructions.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvzfh.c.inc | 25 +++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-)
target/riscv/insn_trans/trans_rvzfh.c.inc +12 -13
@@ -28,15 +28,14 @@ } \ } while (0) -#define REQUIRE_ZFH_OR_ZFHMIN(ctx) do { \ - if (!(ctx->cfg_ptr->ext_zfh || ctx->cfg_ptr->ext_zfhmin)) { \ +#define REQUIRE_ZFHMIN(ctx) do { \ + if (!ctx->cfg_ptr->ext_zfhmin) { \ return false; \ } \ } while (0) -#define REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN(ctx) do { \ - if (!(ctx->cfg_ptr->ext_zfh || ctx->cfg_ptr->ext_zfhmin || \ - ctx->cfg_ptr->ext_zhinx || ctx->cfg_ptr->ext_zhinxmin)) { \ +#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do { \ + if (!(ctx->cfg_ptr->ext_zfhmin || ctx->cfg_ptr->ext_zhinxmin)) { \ return false; \ } \ } while (0)
@@ -47,7 +46,7 @@ static bool trans_flh(DisasContext *ctx, arg_flh *a) TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN(ctx); + REQUIRE_ZFHMIN(ctx); decode_save_opc(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE);
@@ -70,7 +69,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) TCGv t0; REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN(ctx); + REQUIRE_ZFHMIN(ctx); decode_save_opc(ctx); t0 = get_gpr(ctx, a->rs1, EXT_NONE);
@@ -401,7 +400,7 @@ static bool trans_fmax_h(DisasContext *ctx, arg_fmax_h *a) static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN(ctx); + REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx); TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
@@ -418,7 +417,7 @@ static bool trans_fcvt_s_h(DisasContext *ctx, arg_fcvt_s_h *a) static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN(ctx); + REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx); REQUIRE_ZDINX_OR_D(ctx); TCGv_i64 dest = dest_fpr(ctx, a->rd);
@@ -436,7 +435,7 @@ static bool trans_fcvt_d_h(DisasContext *ctx, arg_fcvt_d_h *a) static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN(ctx); + REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx); TCGv_i64 dest = dest_fpr(ctx, a->rd); TCGv_i64 src1 = get_fpr_hs(ctx, a->rs1);
@@ -452,7 +451,7 @@ static bool trans_fcvt_h_s(DisasContext *ctx, arg_fcvt_h_s *a) static bool trans_fcvt_h_d(DisasContext *ctx, arg_fcvt_h_d *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN_OR_ZHINX_OR_ZHINXMIN(ctx); + REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx); REQUIRE_ZDINX_OR_D(ctx); TCGv_i64 dest = dest_fpr(ctx, a->rd);
@@ -585,7 +584,7 @@ static bool trans_fcvt_h_wu(DisasContext *ctx, arg_fcvt_h_wu *a) static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN(ctx); + REQUIRE_ZFHMIN(ctx); TCGv dest = dest_gpr(ctx, a->rd);
@@ -605,7 +604,7 @@ static bool trans_fmv_x_h(DisasContext *ctx, arg_fmv_x_h *a) static bool trans_fmv_h_x(DisasContext *ctx, arg_fmv_h_x *a) { REQUIRE_FPU; - REQUIRE_ZFH_OR_ZFHMIN(ctx); + REQUIRE_ZFHMIN(ctx); TCGv t0 = get_gpr(ctx, a->rs1, EXT_ZERO);
Signature · 1 line
2.39.2
[PULL 16/59] target/riscv: Add property check for Zvfh{min} extensions
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Add check for Zvfh and Zvfhmin.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/riscv/cpu.c +14 -0
@@ -768,6 +768,20 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if (cpu->cfg.ext_zvfh) { + cpu->cfg.ext_zvfhmin = true; + } + +if (cpu->cfg.ext_zvfhmin && !cpu->cfg.ext_zve32f) { +error_setg (errp,"Zvfh/Zvfhmin extensions require Zve32f extension" ); +return ; + } + +if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) { +error_setg (errp,"Zvfh extensions requires Zfhmin extension" ); +return ; + } +/* Set the ISA extensions, checks should have happened above */ if (cpu->cfg.ext_zhinx) { cpu->cfg.ext_zhinxmin = true;
Signature · 1 line
2.39.2
[PULL 17/59] target/riscv: Indent fixes in cpu.c
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Fix indent problems in vector related check.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
target/riscv/cpu.c +22 -22
@@ -798,7 +798,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) }if (cpu->cfg.ext_f) {error_setg (errp, -"Zfinx cannot be supported together with F extension" ); +"Zfinx cannot be supported together with F extension" );return ; } }
@@ -861,40 +861,40 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) ext |=RVV ;if (!is_power_of_2 (cpu->cfg.vlen)) {error_setg (errp, -"Vector extension VLEN must be power of 2" ); +"Vector extension VLEN must be power of 2" );return ; }if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) {error_setg (errp, -"Vector extension implementation only supports VLEN " -"in the range [128, %d]" ,RV_VLEN_MAX ); +"Vector extension implementation only supports VLEN " +"in the range [128, %d]" ,RV_VLEN_MAX );return ; }if (!is_power_of_2 (cpu->cfg.elen)) {error_setg (errp, -"Vector extension ELEN must be power of 2" ); +"Vector extension ELEN must be power of 2" );return ; } -if (cpu->cfg.elen >64 || cpu->cfg.elen <8 ) { -error_setg (errp, -"Vector extension implementation only supports ELEN " -"in the range [8, 64]" ); -return ; - } -if (cpu->cfg.vext_spec) { -if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { - vext_version =VEXT_VERSION_1_00_0 ; - }else { +if (cpu->cfg.elen >64 || cpu->cfg.elen <8 ) {error_setg (errp, -"Unsupported vector spec version '%s'" , - cpu->cfg.vext_spec); +"Vector extension implementation only supports ELEN " +"in the range [8, 64]" );return ; } - }else { -qemu_log ("vector version is not specified, " -"use the default value v1.0\n" ); - } -set_vext_version (env, vext_version); +if (cpu->cfg.vext_spec) { +if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { + vext_version =VEXT_VERSION_1_00_0 ; + }else { +error_setg (errp, +"Unsupported vector spec version '%s'" , + cpu->cfg.vext_spec); +return ; + } + }else { +qemu_log ("vector version is not specified, " +"use the default value v1.0\n" ); + } +set_vext_version (env, vext_version); }if (cpu->cfg.ext_j) { ext |=RVJ ;
Signature · 1 line
2.39.2
[PULL 18/59] target/riscv: Simplify check for Zve32f and Zve64f
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
V/Zve64f depend on Zve32f, so we can only check Zve32f in these cases.
Message-ID: <[email protected]>
--- target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 3 +-- target/riscv/insn_trans/trans_rvv.c.inc | 8 ++------ 3 files changed, 4 insertions(+), 9 deletions(-)
target/riscv/cpu_helper.c +1 -1
@@ -51,7 +51,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, *pc = env->xl ==MXL_RV32 ? env->pc &UINT32_MAX : env->pc; *cs_base =0 ; -if (riscv_has_ext (env,RVV ) || cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { +if (cpu->cfg.ext_zve32f) {/* * If env->vl equals to VLMAX, we can use generic vector operation * expanders (GVEC) to accerlate the vector operations.
target/riscv/csr.c +1 -2
@@ -93,8 +93,7 @@ static RISCVException vs(CPURISCVState *env, int csrno)CPUState *cs =env_cpu (env);RISCVCPU *cpu =RISCV_CPU (cs); -if (env->misa_ext &RVV || - cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { +if (cpu->cfg.ext_zve32f) {#if !defined(CONFIG_USER_ONLY )if (!env->debugger && !riscv_cpu_vector_enabled (env)) {return RISCV_EXCP_ILLEGAL_INST ;
target/riscv/insn_trans/trans_rvv.c.inc +2 -6
@@ -173,9 +173,7 @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) { TCGv s1, dst; - if (!require_rvv(s) || - !(has_ext(s, RVV) || s->cfg_ptr->ext_zve32f || - s->cfg_ptr->ext_zve64f)) { + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { return false; }
@@ -210,9 +208,7 @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) { TCGv dst; - if (!require_rvv(s) || - !(has_ext(s, RVV) || s->cfg_ptr->ext_zve32f || - s->cfg_ptr->ext_zve64f)) { + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { return false; }
Signature · 1 line
2.39.2
[PULL 19/59] target/riscv: Replace check for F/D to Zve32f/Zve64d in trans_rvv.c.inc
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Check for Zve32f/Zve64d can overlap check for F/D.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +4 -4
@@ -41,9 +41,9 @@ static bool require_rvf(DisasContext *s) switch (s->sew) { case MO_16: case MO_32: - return has_ext(s, RVF); + return s->cfg_ptr->ext_zve32f; case MO_64: - return has_ext(s, RVD); + return s->cfg_ptr->ext_zve64d; default: return false; }
@@ -58,9 +58,9 @@ static bool require_scale_rvf(DisasContext *s) switch (s->sew) { case MO_8: case MO_16: - return has_ext(s, RVF); + return s->cfg_ptr->ext_zve32f; case MO_32: - return has_ext(s, RVD); + return s->cfg_ptr->ext_zve64d; default: return false; }
Signature · 1 line
2.39.2
[PULL 20/59] target/riscv: Remove redundunt check for zve32f and zve64f
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Require_zve32/64f have been overlapped by require_rvf/require_scale_rvf.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 128 ++++-------------------- 1 file changed, 21 insertions(+), 107 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +21 -107
@@ -66,50 +66,6 @@ static bool require_scale_rvf(DisasContext *s) } } -static bool require_zve32f(DisasContext *s) -{ - /* RVV + Zve32f = RVV. */ - if (has_ext(s, RVV)) { - return true; - } - - /* Zve32f doesn't support FP64. (Section 18.2) */ - return s->cfg_ptr->ext_zve32f ? s->sew <= MO_32 : true; -} - -static bool require_scale_zve32f(DisasContext *s) -{ - /* RVV + Zve32f = RVV. */ - if (has_ext(s, RVV)) { - return true; - } - - /* Zve32f doesn't support FP64. (Section 18.2) */ - return s->cfg_ptr->ext_zve64f ? s->sew <= MO_16 : true; -} - -static bool require_zve64f(DisasContext *s) -{ - /* RVV + Zve64f = RVV. */ - if (has_ext(s, RVV)) { - return true; - } - - /* Zve64f doesn't support FP64. (Section 18.2) */ - return s->cfg_ptr->ext_zve64f ? s->sew <= MO_32 : true; -} - -static bool require_scale_zve64f(DisasContext *s) -{ - /* RVV + Zve64f = RVV. */ - if (has_ext(s, RVV)) { - return true; - } - - /* Zve64f doesn't support FP64. (Section 18.2) */ - return s->cfg_ptr->ext_zve64f ? s->sew <= MO_16 : true; -} - /* Destination vector register group cannot overlap source mask register. */ static bool require_vm(int vm, int vd) {
@@ -2331,9 +2287,7 @@ static bool opfvv_check(DisasContext *s, arg_rmrr *a) return require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s) && - vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm) && - require_zve32f(s) && - require_zve64f(s); + vext_check_sss(s, a->rd, a->rs1, a->rs2, a->vm); } /* OPFVV without GVEC IR */
@@ -2421,9 +2375,7 @@ static bool opfvf_check(DisasContext *s, arg_rmrr *a) return require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s) && - vext_check_ss(s, a->rd, a->rs2, a->vm) && - require_zve32f(s) && - require_zve64f(s); + vext_check_ss(s, a->rd, a->rs2, a->vm); } /* OPFVF without GVEC IR */
@@ -2461,9 +2413,7 @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) require_scale_rvf(s) && (s->sew != MO_8) && vext_check_isa_ill(s) && - vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); } /* OPFVV with WIDEN */
@@ -2506,9 +2456,7 @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) require_scale_rvf(s) && (s->sew != MO_8) && vext_check_isa_ill(s) && - vext_check_ds(s, a->rd, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_ds(s, a->rd, a->rs2, a->vm); } /* OPFVF with WIDEN */
@@ -2540,9 +2488,7 @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) require_scale_rvf(s) && (s->sew != MO_8) && vext_check_isa_ill(s) && - vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); } /* WIDEN OPFVV with WIDEN */
@@ -2585,9 +2531,7 @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) require_scale_rvf(s) && (s->sew != MO_8) && vext_check_isa_ill(s) && - vext_check_dd(s, a->rd, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_dd(s, a->rd, a->rs2, a->vm); } /* WIDEN OPFVF with WIDEN */
@@ -2664,9 +2608,7 @@ static bool opfv_check(DisasContext *s, arg_rmr *a) require_rvf(s) && vext_check_isa_ill(s) && /* OPFV instructions ignore vs1 check */ - vext_check_ss(s, a->rd, a->rs2, a->vm) && - require_zve32f(s) && - require_zve64f(s); + vext_check_ss(s, a->rd, a->rs2, a->vm); } static bool do_opfv(DisasContext *s, arg_rmr *a,
@@ -2731,9 +2673,7 @@ static bool opfvv_cmp_check(DisasContext *s, arg_rmrr *a) return require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s) && - vext_check_mss(s, a->rd, a->rs1, a->rs2) && - require_zve32f(s) && - require_zve64f(s); + vext_check_mss(s, a->rd, a->rs1, a->rs2); } GEN_OPFVV_TRANS(vmfeq_vv, opfvv_cmp_check)
@@ -2746,9 +2686,7 @@ static bool opfvf_cmp_check(DisasContext *s, arg_rmrr *a) return require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s) && - vext_check_ms(s, a->rd, a->rs2) && - require_zve32f(s) && - require_zve64f(s); + vext_check_ms(s, a->rd, a->rs2); } GEN_OPFVF_TRANS(vmfeq_vf, opfvf_cmp_check)
@@ -2769,9 +2707,7 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) if (require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s) && - require_align(a->rd, s->lmul) && - require_zve32f(s) && - require_zve64f(s)) { + require_align(a->rd, s->lmul)) { gen_set_rm(s, RISCV_FRM_DYN); TCGv_i64 t1;
@@ -2856,18 +2792,14 @@ static bool opfv_widen_check(DisasContext *s, arg_rmr *a) static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) { return opfv_widen_check(s, a) && - require_rvf(s) && - require_zve32f(s) && - require_zve64f(s); + require_rvf(s); } static bool opffv_widen_check(DisasContext *s, arg_rmr *a) { return opfv_widen_check(s, a) && require_scale_rvf(s) && - (s->sew != MO_8) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + (s->sew != MO_8); } #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \
@@ -2918,9 +2850,7 @@ static bool opfxv_widen_check(DisasContext *s, arg_rmr *a) require_scale_rvf(s) && vext_check_isa_ill(s) && /* OPFV widening instructions ignore vs1 check */ - vext_check_ds(s, a->rd, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_ds(s, a->rd, a->rs2, a->vm); } #define GEN_OPFXV_WIDEN_TRANS(NAME) \
@@ -2975,18 +2905,14 @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) { return opfv_narrow_check(s, a) && require_rvf(s) && - (s->sew != MO_64) && - require_zve32f(s) && - require_zve64f(s); + (s->sew != MO_64); } static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) { return opfv_narrow_check(s, a) && require_scale_rvf(s) && - (s->sew != MO_8) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + (s->sew != MO_8); } #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \
@@ -3035,9 +2961,7 @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) require_scale_rvf(s) && vext_check_isa_ill(s) && /* OPFV narrowing instructions ignore vs1 check */ - vext_check_sd(s, a->rd, a->rs2, a->vm) && - require_scale_zve32f(s) && - require_scale_zve64f(s); + vext_check_sd(s, a->rd, a->rs2, a->vm); } #define GEN_OPXFV_NARROW_TRANS(NAME, HELPER, FRM) \
@@ -3111,9 +3035,7 @@ GEN_OPIVV_WIDEN_TRANS(vwredsumu_vs, reduction_widen_check) static bool freduction_check(DisasContext *s, arg_rmrr *a) { return reduction_check(s, a) && - require_rvf(s) && - require_zve32f(s) && - require_zve64f(s); + require_rvf(s); } GEN_OPFVV_TRANS(vfredusum_vs, freduction_check)
@@ -3540,9 +3462,7 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) { if (require_rvv(s) && require_rvf(s) && - vext_check_isa_ill(s) && - require_zve32f(s) && - require_zve64f(s)) { + vext_check_isa_ill(s)) { gen_set_rm(s, RISCV_FRM_DYN); unsigned int ofs = (8 << s->sew);
@@ -3568,9 +3488,7 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) { if (require_rvv(s) && require_rvf(s) && - vext_check_isa_ill(s) && - require_zve32f(s) && - require_zve64f(s)) { + vext_check_isa_ill(s)) { gen_set_rm(s, RISCV_FRM_DYN); /* The instructions ignore LMUL and vector register group. */
@@ -3621,17 +3539,13 @@ GEN_OPIVI_TRANS(vslidedown_vi, IMM_ZX, vslidedown_vx, slidedown_check) static bool fslideup_check(DisasContext *s, arg_rmrr *a) { return slideup_check(s, a) && - require_rvf(s) && - require_zve32f(s) && - require_zve64f(s); + require_rvf(s); } static bool fslidedown_check(DisasContext *s, arg_rmrr *a) { return slidedown_check(s, a) && - require_rvf(s) && - require_zve32f(s) && - require_zve64f(s); + require_rvf(s); } GEN_OPFVF_TRANS(vfslide1up_vf, fslideup_check)
Signature · 1 line
2.39.2
[PULL 21/59] target/riscv: Add support for Zvfh/zvfhmin extensions
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Zvfh supports vector float point instructions with SEW = 16 and supports conversions between 8-bit integers and binary16 values.
Zvfhmin supports vfwcvt.f.f.v and vfncvt.f.f.w instructions.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 31 +++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +29 -2
@@ -40,6 +40,7 @@ static bool require_rvf(DisasContext *s) switch (s->sew) { case MO_16: + return s->cfg_ptr->ext_zvfh; case MO_32: return s->cfg_ptr->ext_zve32f; case MO_64:
@@ -57,6 +58,25 @@ static bool require_scale_rvf(DisasContext *s) switch (s->sew) { case MO_8: + return s->cfg_ptr->ext_zvfh; + case MO_16: + return s->cfg_ptr->ext_zve32f; + case MO_32: + return s->cfg_ptr->ext_zve64d; + default: + return false; + } +} + +static bool require_scale_rvfmin(DisasContext *s) +{ + if (s->mstatus_fs == 0) { + return false; + } + + switch (s->sew) { + case MO_8: + return s->cfg_ptr->ext_zvfhmin; case MO_16: return s->cfg_ptr->ext_zve32f; case MO_32:
@@ -2798,7 +2818,7 @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) static bool opffv_widen_check(DisasContext *s, arg_rmr *a) { return opfv_widen_check(s, a) && - require_scale_rvf(s) && + require_scale_rvfmin(s) && (s->sew != MO_8); }
@@ -2909,6 +2929,13 @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) } static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) +{ + return opfv_narrow_check(s, a) && + require_scale_rvfmin(s) && + (s->sew != MO_8); +} + +static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) { return opfv_narrow_check(s, a) && require_scale_rvf(s) &&
@@ -2952,7 +2979,7 @@ GEN_OPFV_NARROW_TRANS(vfncvt_f_x_w, opfxv_narrow_check, vfncvt_f_x_w, GEN_OPFV_NARROW_TRANS(vfncvt_f_f_w, opffv_narrow_check, vfncvt_f_f_w, RISCV_FRM_DYN) /* Reuse the helper function from vfncvt.f.f.w */ -GEN_OPFV_NARROW_TRANS(vfncvt_rod_f_f_w, opffv_narrow_check, vfncvt_f_f_w, +GEN_OPFV_NARROW_TRANS(vfncvt_rod_f_f_w, opffv_rod_narrow_check, vfncvt_f_f_w, RISCV_FRM_ROD) static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a)
Signature · 1 line
2.39.2
[PULL 22/59] target/riscv: Fix check for vector load/store instructions when EEW=64
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
The V extension supports all vector load and store instructions except the V extension does not support EEW=64 for index values when XLEN=32. (Section 18.3)
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +4 -5
@@ -287,13 +287,12 @@ static bool vext_check_st_index(DisasContext *s, int vd, int vs2, int nf, require_nf(vd, nf, s->lmul); /* - * All Zve* extensions support all vector load and store instructions, - * except Zve64* extensions do not support EEW=64 for index values - * when XLEN=32. (Section 18.2) + * V extension supports all vector load and store instructions, + * except V extension does not support EEW=64 for index values + * when XLEN=32. (Section 18.3) */ if (get_xl(s) == MXL_RV32) { - ret &= (!has_ext(s, RVV) && - s->cfg_ptr->ext_zve64f ? eew != MO_64 : true); + ret &= (eew != MO_64); } return ret;
Signature · 1 line
2.39.2
[PULL 23/59] target/riscv: Simplify check for EEW = 64 in trans_rvv.c.inc
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Only V extension supports EEW = 64 in these cases: Zve64* extensions don't support EEW = 64 in these cases as commented before the check.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +4 -8
@@ -1998,8 +1998,7 @@ static bool vmulh_vv_check(DisasContext *s, arg_rmrr *a) * are not included for EEW=64 in Zve64*. (Section 18.2) */ return opivv_check(s, a) && - (!has_ext(s, RVV) && - s->cfg_ptr->ext_zve64f ? s->sew != MO_64 : true); + (!has_ext(s, RVV) ? s->sew != MO_64 : true); } static bool vmulh_vx_check(DisasContext *s, arg_rmrr *a)
@@ -2012,8 +2011,7 @@ static bool vmulh_vx_check(DisasContext *s, arg_rmrr *a) * are not included for EEW=64 in Zve64*. (Section 18.2) */ return opivx_check(s, a) && - (!has_ext(s, RVV) && - s->cfg_ptr->ext_zve64f ? s->sew != MO_64 : true); + (!has_ext(s, RVV) ? s->sew != MO_64 : true); } GEN_OPIVV_GVEC_TRANS(vmul_vv, mul)
@@ -2230,8 +2228,7 @@ static bool vsmul_vv_check(DisasContext *s, arg_rmrr *a) * for EEW=64 in Zve64*. (Section 18.2) */ return opivv_check(s, a) && - (!has_ext(s, RVV) && - s->cfg_ptr->ext_zve64f ? s->sew != MO_64 : true); + (!has_ext(s, RVV) ? s->sew != MO_64 : true); } static bool vsmul_vx_check(DisasContext *s, arg_rmrr *a)
@@ -2242,8 +2239,7 @@ static bool vsmul_vx_check(DisasContext *s, arg_rmrr *a) * for EEW=64 in Zve64*. (Section 18.2) */ return opivx_check(s, a) && - (!has_ext(s, RVV) && - s->cfg_ptr->ext_zve64f ? s->sew != MO_64 : true); + (!has_ext(s, RVV) ? s->sew != MO_64 : true); } GEN_OPIVV_TRANS(vsmul_vv, vsmul_vv_check)
Signature · 1 line
2.39.2
[PULL 24/59] target/riscv: Expose properties for Zv* extensions
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Expose Zve64d,Zvfh,Zvfhmin properties.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 7 +++++++ 1 file changed, 7 insertions(+)
target/riscv/cpu.c +7 -0
@@ -101,6 +101,9 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zkt, true,PRIV_VERSION_1_12_0 , ext_zkt),ISA_EXT_DATA_ENTRY (zve32f, true,PRIV_VERSION_1_12_0 , ext_zve32f),ISA_EXT_DATA_ENTRY (zve64f, true,PRIV_VERSION_1_12_0 , ext_zve64f), +ISA_EXT_DATA_ENTRY (zve64d, true,PRIV_VERSION_1_12_0 , ext_zve64d), +ISA_EXT_DATA_ENTRY (zvfh, true,PRIV_VERSION_1_12_0 , ext_zvfh), +ISA_EXT_DATA_ENTRY (zvfhmin, true,PRIV_VERSION_1_12_0 , ext_zvfhmin),ISA_EXT_DATA_ENTRY (zhinx, true,PRIV_VERSION_1_12_0 , ext_zhinx),ISA_EXT_DATA_ENTRY (zhinxmin, true,PRIV_VERSION_1_12_0 , ext_zhinxmin), ISA_EXT_DATA_ENTRY(smaia, true, PRIV_VERSION_1_12_0, ext_smaia),
@@ -1126,6 +1129,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("Zfhmin" ,RISCVCPU , cfg.ext_zfhmin, false),DEFINE_PROP_BOOL ("Zve32f" ,RISCVCPU , cfg.ext_zve32f, false),DEFINE_PROP_BOOL ("Zve64f" ,RISCVCPU , cfg.ext_zve64f, false), +DEFINE_PROP_BOOL ("Zve64d" ,RISCVCPU , cfg.ext_zve64d, false),DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true), DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true),
@@ -1185,6 +1189,9 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false),DEFINE_PROP_BOOL ("x-ssaia" ,RISCVCPU , cfg.ext_ssaia, false), +DEFINE_PROP_BOOL ("x-zvfh" ,RISCVCPU , cfg.ext_zvfh, false), +DEFINE_PROP_BOOL ("x-zvfhmin" ,RISCVCPU , cfg.ext_zvfhmin, false), + DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.39.2
[PULL 25/59] target/riscv: gdbstub: Check priv spec version before reporting CSR
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
The gdbstub CSR XML is dynamically generated according to the result of the CSR predicate() result. This has been working fine until commit 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12") introduced the privilege spec version check in riscv_csrrw_check().
When debugging the 'sifive_u' machine whose priv spec is at 1.10, gdbstub reports priv spec 1.12 CSRs like menvcfg in the XML, hence we see "remote failure reply 'E14'" message when examining all CSRs via "info register system" from gdb.
Add the priv spec version check in the CSR XML generation logic to fix this issue.
Message-ID: <[email protected]>
--- target/riscv/gdbstub.c | 3 +++ 1 file changed, 3 insertions(+)
target/riscv/gdbstub.c +3 -0
@@ -290,6 +290,9 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)g_string_append_printf (s,"<feature name=\"org.gnu.gdb.riscv.csr\">" );for (i =0 ; i <CSR_TABLE_SIZE ; i++) { +if (env->priv_ver < csr_ops[i].min_priv_ver) { +continue ; + } predicate = csr_ops[i].predicate;if (predicate && (predicate (env, i) ==RISCV_EXCP_NONE )) {if (csr_ops[i].name) {
Signature · 1 line
2.39.2
[PULL 26/59] target/riscv: Add some comments to clarify the priority policy of riscv_csrrw_check()
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
The priority policy of riscv_csrrw_check() was once adjusted in
commit eacaf4401956 ("target/riscv: Fix priority of csr related check in riscv_csrrw_check") whose commit message says the CSR existence check should come before
the access control check, but the code changes did not agree with
the commit message, that the predicate() check actually came after
the read / write check.
In fact this was intentional. Add some comments there so that people won't bother trying to change it without a solid reason.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
target/riscv/csr.c +10 -1
@@ -3776,11 +3776,12 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,int read_only =get_field (csrno,0xC00 ) ==3 ;int csr_min_priv = csr_ops[csrno].min_priv_ver; -/* ensure the CSR extension is enabled. */ +/* ensure the CSR extension is enabled */ if (!cpu->cfg.ext_icsr) {return RISCV_EXCP_ILLEGAL_INST ; } +/* privileged spec version check */ if (env->priv_ver < csr_min_priv) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -3790,10 +3791,18 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,return RISCV_EXCP_ILLEGAL_INST ; } +/* read / write check */ if (write_mask && read_only) {return RISCV_EXCP_ILLEGAL_INST ; } +/* +* The predicate() not only does existence check but also does some +* access control check which triggers for example virtual instruction +* exception in some cases. When writing read-only CSRs in those cases +* illegal instruction exception should be triggered instead of virtual +* instruction exception. Hence this comes after the read / write check. +*/ RISCVException ret = csr_ops[csrno].predicate (env, csrno);if (ret !=RISCV_EXCP_NONE ) {return ret;
Signature · 1 line
2.39.2
[PULL 27/59] target/riscv: Use g_assert() for the predicate() NULL check
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present riscv_csrrw_check() checks the CSR predicate() against NULL and throws RISCV_EXCP_ILLEGAL_INST if it is NULL. But this is a pure software check, and has nothing to do with the emulation of the hardware behavior, thus it is inappropriate to return illegal instruction exception when software forgets to install the hook.
Change to use g_assert() instead.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/riscv/csr.c +1 -5
@@ -3786,11 +3786,6 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,return RISCV_EXCP_ILLEGAL_INST ; } -/* check predicate */ -if (!csr_ops[csrno].predicate) { -return RISCV_EXCP_ILLEGAL_INST ; - } -/* read / write check */ if (write_mask && read_only) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -3803,6 +3798,7 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,* illegal instruction exception should be triggered instead of virtual * instruction exception. Hence this comes after the read / write check. */ +g_assert (csr_ops[csrno].predicate !=NULL );RISCVException ret = csr_ops[csrno].predicate (env, csrno);if (ret !=RISCV_EXCP_NONE ) {return ret;
Signature · 1 line
2.39.2
[PULL 28/59] target/riscv: gdbstub: Minor change for better readability
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Use a variable 'base_reg' to represent cs->gdb_num_regs so that the call to ricsv_gen_dynamic_vector_xml() can be placed in one single line for better readability.
Message-ID: <[email protected]>
--- target/riscv/gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/gdbstub.c +2 -2
@@ -385,9 +385,9 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) 32, "riscv-32bit-fpu.xml", 0); }if (env->misa_ext &RVV ) { +int base_reg = cs->gdb_num_regs;gdb_register_coprocessor (cs, riscv_gdb_get_vector, riscv_gdb_set_vector, -ricsv_gen_dynamic_vector_xml (cs, - cs->gdb_num_regs), +ricsv_gen_dynamic_vector_xml (cs, base_reg),"riscv-vector.xml" ,0 ); }switch (env->misa_mxl_max) {
Signature · 1 line
2.39.2
[PULL 29/59] target/riscv: gdbstub: Do not generate CSR XML if Zicsr is disabled
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
There is no need to generate the CSR XML if the Zicsr extension is not enabled.
Message-ID: <[email protected]>
--- target/riscv/gdbstub.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target/riscv/gdbstub.c +6 -3
@@ -406,7 +406,10 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs)g_assert_not_reached (); } -gdb_register_coprocessor (cs, riscv_gdb_get_csr, riscv_gdb_set_csr, -riscv_gen_dynamic_csr_xml (cs, cs->gdb_num_regs), -"riscv-csr.xml" ,0 ); +if (cpu->cfg.ext_icsr) { +int base_reg = cs->gdb_num_regs; +gdb_register_coprocessor (cs, riscv_gdb_get_csr, riscv_gdb_set_csr, +riscv_gen_dynamic_csr_xml (cs, base_reg), +"riscv-csr.xml" ,0 ); + } }
Signature · 1 line
2.39.2
[PULL 31/59] target/riscv: Use 'bool' type for read_only
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
The read_only variable is currently declared as an 'int', but it should really be a 'bool'.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
@@ -3775,7 +3775,7 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, RISCVCPU *cpu) {/* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ -int read_only =get_field (csrno,0xC00 ) ==3 ; +bool read_only =get_field (csrno,0xC00 ) ==3 ;int csr_min_priv = csr_ops[csrno].min_priv_ver;/* ensure the CSR extension is enabled */
Signature · 1 line
2.39.2
[PULL 32/59] target/riscv: Simplify {read, write}_pmpcfg() a little bit
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Use the register index that has already been calculated in the pmpcfg_csr_{read,write} call.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/csr.c +2 -2
@@ -3360,7 +3360,7 @@ static RISCVException read_pmpcfg(CPURISCVState *env, int csrno,if (!check_pmp_reg_index (env, reg_index)) {return RISCV_EXCP_ILLEGAL_INST ; } - *val =pmpcfg_csr_read (env, csrno -CSR_PMPCFG0 ); + *val =pmpcfg_csr_read (env, reg_index);return RISCV_EXCP_NONE ; }
@@ -3372,7 +3372,7 @@ static RISCVException write_pmpcfg(CPURISCVState *env, int csrno,if (!check_pmp_reg_index (env, reg_index)) {return RISCV_EXCP_ILLEGAL_INST ; } -pmpcfg_csr_write (env, csrno -CSR_PMPCFG0 , val); +pmpcfg_csr_write (env, reg_index, val);return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 33/59] target/riscv: Simplify getting RISCVCPU pointer from env
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Use env_archcpu() to get RISCVCPU pointer from env directly.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
target/riscv/csr.c +12 -24
@@ -46,8 +46,7 @@ static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bit) {bool virt =riscv_cpu_virt_enabled (env); -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (env->priv ==PRV_M || !cpu->cfg.ext_smstateen) {return RISCV_EXCP_NONE ;
@@ -90,8 +89,7 @@ static RISCVException fs(CPURISCVState *env, int csrno)static RISCVException vs (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (env->misa_ext &RVV || cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) {
@@ -108,8 +106,7 @@ static RISCVException vs(CPURISCVState *env, int csrno)static RISCVException ctr (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY ) -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);int ctr_index;target_ulong ctr_mask;int base_csrno =CSR_CYCLE ;
@@ -166,8 +163,7 @@ static RISCVException ctr32(CPURISCVState *env, int csrno)#if !defined(CONFIG_USER_ONLY )static RISCVException mctr (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);int ctr_index;int base_csrno =CSR_MHPMCOUNTER3 ;
@@ -195,8 +191,7 @@ static RISCVException mctr32(CPURISCVState *env, int csrno)static RISCVException sscofpmf (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (!cpu->cfg.ext_sscofpmf) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -321,8 +316,7 @@ static RISCVException umode32(CPURISCVState *env, int csrno)static RISCVException mstateen (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (!cpu->cfg.ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -333,8 +327,7 @@ static RISCVException mstateen(CPURISCVState *env, int csrno)static RISCVException hstateen_pred (CPURISCVState *env,int csrno,int base) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (!cpu->cfg.ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -363,8 +356,7 @@ static RISCVException sstateen(CPURISCVState *env, int csrno) {bool virt =riscv_cpu_virt_enabled (env);int index = csrno -CSR_SSTATEEN0 ; -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);if (!cpu->cfg.ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -918,8 +910,7 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno,static RISCVException sstc (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);bool hmode_check = false;if (!cpu->cfg.ext_sstc || !env->rdtime_fn) {
@@ -1152,8 +1143,7 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,static RISCVException read_mvendorid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env); *val = cpu->cfg.mvendorid;return RISCV_EXCP_NONE ;
@@ -1162,8 +1152,7 @@ static RISCVException read_mvendorid(CPURISCVState *env, int csrno,static RISCVException read_marchid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env); *val = cpu->cfg.marchid;return RISCV_EXCP_NONE ;
@@ -1172,8 +1161,7 @@ static RISCVException read_marchid(CPURISCVState *env, int csrno,static RISCVException read_mimpid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env); *val = cpu->cfg.mimpid;return RISCV_EXCP_NONE ;
Signature · 1 line
2.39.2
[PULL 34/59] target/riscv: Avoid reporting odd-numbered pmpcfgX in the CSR XML for RV64
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present the odd-numbered PMP configuration registers for RV64 are reported in the CSR XML by QEMU gdbstub. However these registers do not exist on RV64 so trying to access them from gdb results in 'E14'.
Move the pmpcfgX index check from the actual read/write routine to the PMP CSR predicate() routine, so that non-existent pmpcfgX won't be reported in the CSR XML for RV64.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
target/riscv/csr.c +9 -15
@@ -412,6 +412,15 @@ static int aia_hmode32(CPURISCVState *env, int csrno)static RISCVException pmp (CPURISCVState *env,int csrno) {if (riscv_cpu_cfg (env)->pmp) { +if (csrno <=CSR_PMPCFG3 ) { +uint32_t reg_index = csrno -CSR_PMPCFG0 ; + +/* TODO: RV128 restriction check */ +if ((reg_index &1 ) && (riscv_cpu_mxl (env) ==MXL_RV64 )) { +return RISCV_EXCP_ILLEGAL_INST ; + } + } +return RISCV_EXCP_NONE ; }
@@ -3331,23 +3340,11 @@ static RISCVException write_mseccfg(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } -static bool check_pmp_reg_index (CPURISCVState *env,uint32_t reg_index) -{ -/* TODO: RV128 restriction check */ -if ((reg_index &1 ) && (riscv_cpu_mxl (env) ==MXL_RV64 )) { -return false; - } -return true; -} -static RISCVException read_pmpcfg (CPURISCVState *env,int csrno,target_ulong *val) {uint32_t reg_index = csrno -CSR_PMPCFG0 ; -if (!check_pmp_reg_index (env, reg_index)) { -return RISCV_EXCP_ILLEGAL_INST ; - } *val =pmpcfg_csr_read (env, reg_index);return RISCV_EXCP_NONE ; }
@@ -3357,9 +3354,6 @@ static RISCVException write_pmpcfg(CPURISCVState *env, int csrno, {uint32_t reg_index = csrno -CSR_PMPCFG0 ; -if (!check_pmp_reg_index (env, reg_index)) { -return RISCV_EXCP_ILLEGAL_INST ; - }pmpcfg_csr_write (env, reg_index, val);return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 30/59] target/riscv: Coding style fixes in csr.c
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Fix various places that violate QEMU coding style:
- correct multi-line comment format
- indent to opening parenthesis
Message-ID: <[email protected]>
--- target/riscv/csr.c | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 30 deletions(-)
target/riscv/csr.c +32 -30
@@ -963,7 +963,7 @@ static RISCVException sstc_32(CPURISCVState *env, int csrno) }static RISCVException read_vstimecmp (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->vstimecmp;
@@ -971,7 +971,7 @@ static RISCVException read_vstimecmp(CPURISCVState *env, int csrno, }static RISCVException read_vstimecmph (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->vstimecmp >>32 ;
@@ -979,7 +979,7 @@ static RISCVException read_vstimecmph(CPURISCVState *env, int csrno, }static RISCVException write_vstimecmp (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {RISCVCPU *cpu =env_archcpu (env);
@@ -996,7 +996,7 @@ static RISCVException write_vstimecmp(CPURISCVState *env, int csrno, }static RISCVException write_vstimecmph (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {RISCVCPU *cpu =env_archcpu (env);
@@ -1020,7 +1020,7 @@ static RISCVException read_stimecmp(CPURISCVState *env, int csrno, }static RISCVException read_stimecmph (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) {if (riscv_cpu_virt_enabled (env)) { *val = env->vstimecmp >>32 ;
@@ -1032,7 +1032,7 @@ static RISCVException read_stimecmph(CPURISCVState *env, int csrno, }static RISCVException write_stimecmp (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {RISCVCPU *cpu =env_archcpu (env);
@@ -1055,7 +1055,7 @@ static RISCVException write_stimecmp(CPURISCVState *env, int csrno, }static RISCVException write_stimecmph (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {RISCVCPU *cpu =env_archcpu (env);
@@ -1342,7 +1342,8 @@ static RISCVException write_misa(CPURISCVState *env, int csrno,/* 'E' excludes all other extensions */ if (val &RVE ) { -/* when we support 'E' we can do "val = RVE;" however +/* +* when we support 'E' we can do "val = RVE;" however * for now we just drop writes if 'E' is present. */ return RISCV_EXCP_NONE ;
@@ -1361,7 +1362,8 @@ static RISCVException write_misa(CPURISCVState *env, int csrno, val &= ~RVD ; } -/* Suppress 'C' if next instruction is not aligned +/* +* Suppress 'C' if next instruction is not aligned * TODO: this should check next_pc */ if ((val &RVC ) && (GETPC () & ~3 ) !=0 ) {
@@ -1830,28 +1832,28 @@ static RISCVException write_mscratch(CPURISCVState *env, int csrno, }static RISCVException read_mepc (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->mepc;return RISCV_EXCP_NONE ; }static RISCVException write_mepc (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) { env->mepc = val;return RISCV_EXCP_NONE ; }static RISCVException read_mcause (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->mcause;return RISCV_EXCP_NONE ; }static RISCVException write_mcause (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) { env->mcause = val;return RISCV_EXCP_NONE ;
@@ -1873,14 +1875,14 @@ static RISCVException write_mtval(CPURISCVState *env, int csrno,/* Execution environment configuration setup */ static RISCVException read_menvcfg (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->menvcfg;return RISCV_EXCP_NONE ; }static RISCVException write_menvcfg (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {uint64_t mask =MENVCFG_FIOM |MENVCFG_CBIE |MENVCFG_CBCFE |MENVCFG_CBZE ;
@@ -1893,14 +1895,14 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno, }static RISCVException read_menvcfgh (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->menvcfg >>32 ;return RISCV_EXCP_NONE ; }static RISCVException write_menvcfgh (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {uint64_t mask =MENVCFG_PBMTE |MENVCFG_STCE ;uint64_t valh = (uint64_t )val <<32 ;
@@ -1911,7 +1913,7 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, }static RISCVException read_senvcfg (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) {RISCVException ret;
@@ -1925,7 +1927,7 @@ static RISCVException read_senvcfg(CPURISCVState *env, int csrno, }static RISCVException write_senvcfg (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {uint64_t mask =SENVCFG_FIOM |SENVCFG_CBIE |SENVCFG_CBCFE |SENVCFG_CBZE ;RISCVException ret;
@@ -1940,7 +1942,7 @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno, }static RISCVException read_henvcfg (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) {RISCVException ret;
@@ -1954,7 +1956,7 @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno, }static RISCVException write_henvcfg (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {uint64_t mask =HENVCFG_FIOM |HENVCFG_CBIE |HENVCFG_CBCFE |HENVCFG_CBZE ;RISCVException ret;
@@ -1974,7 +1976,7 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, }static RISCVException read_henvcfgh (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) {RISCVException ret;
@@ -1988,7 +1990,7 @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno, }static RISCVException write_henvcfgh (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {uint64_t mask =HENVCFG_PBMTE |HENVCFG_STCE ;uint64_t valh = (uint64_t )val <<32 ;
@@ -2031,13 +2033,13 @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno, }static RISCVException write_mstateen_1_3 (CPURISCVState *env,int csrno, -target_ulong new_val) +target_ulong new_val) {return write_mstateen (env, csrno,SMSTATEEN_STATEEN , new_val); }static RISCVException read_mstateenh (CPURISCVState *env,int csrno, -target_ulong *val) +target_ulong *val) { *val = env->mstateen[csrno -CSR_MSTATEEN0H ] >>32 ;
@@ -2058,7 +2060,7 @@ static RISCVException write_mstateenh(CPURISCVState *env, int csrno, }static RISCVException write_mstateen0h (CPURISCVState *env,int csrno, -target_ulong new_val) +target_ulong new_val) {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ;
@@ -2066,7 +2068,7 @@ static RISCVException write_mstateen0h(CPURISCVState *env, int csrno, }static RISCVException write_mstateenh_1_3 (CPURISCVState *env,int csrno, -target_ulong new_val) +target_ulong new_val) {return write_mstateenh (env, csrno,SMSTATEEN_STATEEN , new_val); }
@@ -2103,7 +2105,7 @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno, }static RISCVException write_hstateen_1_3 (CPURISCVState *env,int csrno, -target_ulong new_val) +target_ulong new_val) {return write_hstateen (env, csrno,SMSTATEEN_STATEEN , new_val); }
@@ -2142,7 +2144,7 @@ static RISCVException write_hstateen0h(CPURISCVState *env, int csrno, }static RISCVException write_hstateenh_1_3 (CPURISCVState *env,int csrno, -target_ulong new_val) +target_ulong new_val) {return write_hstateenh (env, csrno,SMSTATEEN_STATEEN , new_val); }
@@ -3335,7 +3337,7 @@ static RISCVException read_mseccfg(CPURISCVState *env, int csrno, }static RISCVException write_mseccfg (CPURISCVState *env,int csrno, -target_ulong val) +target_ulong val) {mseccfg_csr_write (env, val);return RISCV_EXCP_NONE ;
Signature · 1 line
2.39.2
[PULL 35/59] target/riscv: gdbstub: Turn on debugger mode before calling CSR predicate()
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Since commit 94452ac4cf26 ("target/riscv: remove fflags, frm, and fcsr from riscv-*-fpu.xml") the 3 FPU CSRs are removed from the XML target decription. The
original intent of that commit was based on the assumption that
the 3 FPU CSRs will show up in the riscv-csr.xml so the ones in riscv-*-fpu.xml are redundant. But unforuantely that is not true.
As the FPU CSR predicate() has a run-time check on MSTATUS.FS,
at the time when CSR XML is generated MSTATUS.FS is unset, hence
no FPU CSRs will be reported.
The FPU CSR predicate() already considered such a case of being accessed by a debugger. All we need to do is to turn on debugger mode before calling predicate().
Message-ID: <[email protected]>
--- target/riscv/gdbstub.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/riscv/gdbstub.c +9 -0
@@ -280,6 +280,10 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)int bitsize =16 << env->misa_mxl_max;int i; +#if !defined(CONFIG_USER_ONLY ) + env->debugger = true; +#endif +/* Until gdb knows about 128-bit registers */ if (bitsize >64 ) { bitsize =64 ;
@@ -308,6 +312,11 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int base_reg)g_string_append_printf (s,"</feature>" ); cpu->dyn_csr_xml =g_string_free (s, false); + +#if !defined(CONFIG_USER_ONLY ) + env->debugger = false; +#endif +return CSR_TABLE_SIZE ; }
Signature · 1 line
2.39.2
[PULL 36/59] target/riscv: gdbstub: Drop the vector CSRs in riscv-vector.xml
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
It's worth noting that the vector CSR predicate() has a similar run-time check logic to the FPU CSR. With the previous patch our gdbstub can correctly report these vector CSRs via the CSR xml.
Commit 719d3561b269 ("target/riscv: gdb: support vector registers for rv64 & rv32") inserted these vector CSRs in an ad-hoc, non-standard way in the riscv-vector.xml. Now we can treat these CSRs no different from
other CSRs.
Message-ID: <[email protected]>
--- target/riscv/gdbstub.c | 75 ------------------------------------------ 1 file changed, 75 deletions(-)
target/riscv/gdbstub.c +0 -75
@@ -127,40 +127,6 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n)return 0 ; } -/* -* Convert register index number passed by GDB to the correspond -* vector CSR number. Vector CSRs are defined after vector registers -* in dynamic generated riscv-vector.xml, thus the starting register index -* of vector CSRs is 32. -* Return 0 if register index number is out of range. -*/ -static int riscv_gdb_vector_csrno (int num_regs) -{ -/* -* The order of vector CSRs in the switch case -* should match with the order defined in csr_ops[]. -*/ -switch (num_regs) { -case 32 : -return CSR_VSTART ; -case 33 : -return CSR_VXSAT ; -case 34 : -return CSR_VXRM ; -case 35 : -return CSR_VCSR ; -case 36 : -return CSR_VL ; -case 37 : -return CSR_VTYPE ; -case 38 : -return CSR_VLENB ; -default : -/* Unknown register. */ -return 0 ; - } -} -static int riscv_gdb_get_vector (CPURISCVState *env,GByteArray *buf,int n) {uint16_t vlenb =env_archcpu (env)->cfg.vlen >>3 ;
@@ -174,19 +140,6 @@ static int riscv_gdb_get_vector(CPURISCVState *env, GByteArray *buf, int n)return cnt; } -int csrno =riscv_gdb_vector_csrno (n); - -if (!csrno) { -return 0 ; - } - -target_ulong val =0 ; -int result =riscv_csrrw_debug (env, csrno, &val,0 ,0 ); - -if (result ==RISCV_EXCP_NONE ) { -return gdb_get_regl (buf, val); - } -return 0 ; }
@@ -201,19 +154,6 @@ static int riscv_gdb_set_vector(CPURISCVState *env, uint8_t *mem_buf, int n)return vlenb; } -int csrno =riscv_gdb_vector_csrno (n); - -if (!csrno) { -return 0 ; - } - -target_ulong val =ldtul_p (mem_buf); -int result =riscv_csrrw_debug (env, csrno,NULL , val,-1 ); - -if (result ==RISCV_EXCP_NONE ) { -return sizeof (target_ulong); - } -return 0 ; }
@@ -361,21 +301,6 @@ static int ricsv_gen_dynamic_vector_xml(CPUState *cs, int base_reg) num_regs++; } -/* Define vector CSRs */ -const char *vector_csrs[7 ] = { -"vstart" ,"vxsat" ,"vxrm" ,"vcsr" , -"vl" ,"vtype" ,"vlenb" - }; - -for (i =0 ; i <7 ; i++) { -g_string_append_printf (s, -"<reg name=\"%s\" bitsize=\"%d\"" -" regnum=\"%d\" group=\"vector\"" -" type=\"int\"/>" , - vector_csrs[i],TARGET_LONG_BITS , base_reg++); - num_regs++; - } -g_string_append_printf (s,"</feature>" ); cpu->dyn_vreg_xml =g_string_free (s, false);
Signature · 1 line
2.39.2
[PULL 39/59] target/riscv: Allow debugger to access {h, s}stateen CSRs
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present {h,s}stateen CSRs are not reported in the CSR XML hence gdb cannot access them.
Fix it by adjusting their predicate() routine logic so that the static config check comes before the run-time check, as well as adding a debugger check.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
target/riscv/csr.c +20 -2
@@ -337,13 +337,22 @@ static RISCVException hstateen_pred(CPURISCVState *env, int csrno, int base)return RISCV_EXCP_ILLEGAL_INST ; } +RISCVException ret =hmode (env, csrno); +if (ret !=RISCV_EXCP_NONE ) { +return ret; + } + +if (env->debugger) { +return RISCV_EXCP_NONE ; + } +if (env->priv <PRV_M ) {if (!(env->mstateen[csrno - base] &SMSTATEEN_STATEEN )) {return RISCV_EXCP_ILLEGAL_INST ; } } -return hmode (env, csrno); +return RISCV_EXCP_NONE ; }static RISCVException hstateen (CPURISCVState *env,int csrno)
@@ -366,6 +375,15 @@ static RISCVException sstateen(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } +RISCVException ret =smode (env, csrno); +if (ret !=RISCV_EXCP_NONE ) { +return ret; + } + +if (env->debugger) { +return RISCV_EXCP_NONE ; + } +if (env->priv <PRV_M ) {if (!(env->mstateen[index] &SMSTATEEN_STATEEN )) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -378,7 +396,7 @@ static RISCVException sstateen(CPURISCVState *env, int csrno) } } -return smode (env, csrno); +return RISCV_EXCP_NONE ; }/* Checks if PointerMasking registers could be accessed */
Signature · 1 line
2.39.2
[PULL 43/59] target/riscv: Fix checking of whether instruciton at 'pc_next' spans pages
In reply to Palmer DabbeltFrom: Shaobo Song <[email protected]>
This bug has a noticeable behavior of falling back to the main loop and respawning a redundant translation block including a single instruction when the end address of the compressive instruction is exactly on a page boundary, and slows down running system performance.
Message-ID: <[email protected]>
--- target/riscv/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/translate.c +1 -1
@@ -1261,7 +1261,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)uint16_t next_insn =cpu_lduw_code (env, ctx->base.pc_next);int len =insn_len (next_insn); -if (!is_same_page (&ctx->base, ctx->base.pc_next + len)) { +if (!is_same_page (&ctx->base, ctx->base.pc_next + len -1 )) { ctx->base.is_jmp =DISAS_TOO_MANY ; } }
Signature · 1 line
2.39.2
[PULL 44/59] RISC-V: XTheadMemPair: Remove register restrictions for store-pair
In reply to Palmer DabbeltFrom: Christoph Müllner <[email protected]>
The XTheadMemPair does not define any restrictions for store-pair instructions (th.sdd or th.swd). However, the current code enforces the restrictions that are required for load-pair instructions. Let's fix this by removing this code.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_xthead.c.inc | 4 ---- 1 file changed, 4 deletions(-)
target/riscv/insn_trans/trans_xthead.c.inc +0 -4
@@ -980,10 +980,6 @@ static bool trans_th_lwud(DisasContext *ctx, arg_th_pair *a) static bool gen_storepair_tl(DisasContext *ctx, arg_th_pair *a, MemOp memop, int shamt) { - if (a->rs == a->rd1 || a->rs == a->rd2 || a->rd1 == a->rd2) { - return false; - } - TCGv data1 = get_gpr(ctx, a->rd1, EXT_NONE); TCGv data2 = get_gpr(ctx, a->rd2, EXT_NONE); TCGv addr1 = tcg_temp_new();
Signature · 1 line
2.39.2
[PULL 37/59] target/riscv: Allow debugger to access user timer and counter CSRs
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present user timer and counter CSRs are not reported in the CSR XML hence gdb cannot access them.
Fix it by adding a debugger check in their predicate() routine.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 4 ++++ 1 file changed, 4 insertions(+)
target/riscv/csr.c +4 -0
@@ -131,6 +131,10 @@ static RISCVException ctr(CPURISCVState *env, int csrno) skip_ext_pmu_check: +if (env->debugger) { +return RISCV_EXCP_NONE ; + } +if (env->priv <PRV_M && !get_field (env->mcounteren, ctr_mask)) {return RISCV_EXCP_ILLEGAL_INST ; }
Signature · 1 line
2.39.2
[PULL 38/59] target/riscv: Allow debugger to access seed CSR
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present seed CSR is not reported in the CSR XML hence gdb cannot access it.
Fix it by adding a debugger check in its predicate() routine.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 4 ++++ 1 file changed, 4 insertions(+)
target/riscv/csr.c +4 -0
@@ -459,6 +459,10 @@ static RISCVException seed(CPURISCVState *env, int csrno) }#if !defined(CONFIG_USER_ONLY ) +if (env->debugger) { +return RISCV_EXCP_NONE ; + } +/* * With a CSR read-write instruction: * 1) The seed CSR is always available in machine mode as normal.
Signature · 1 line
2.39.2
[PULL 46/59] hw/riscv: Skip re-generating DT nodes for a given DTB
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Launch qemu-system-riscv64 with a given dtb for 'sifive_u' and 'virt' machines, QEMU complains:
qemu_fdt_add_subnode: Failed to create subnode /soc: FDT_ERR_EXISTS
The whole DT generation logic should be skipped when a given DTB is present.
Message-ID: <[email protected]>
--- hw/riscv/sifive_u.c | 1 + hw/riscv/virt.c | 1 + 2 files changed, 2 insertions(+)
hw/riscv/sifive_u.c +1 -0
@@ -118,6 +118,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,error_report ("load_device_tree() failed" );exit (1 ); } +return ; }else { fdt = ms->fdt =create_device_tree (&fdt_size);if (!fdt) {
hw/riscv/virt.c +1 -0
@@ -1015,6 +1015,7 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap)error_report ("load_device_tree() failed" );exit (1 ); } +return ; }else { ms->fdt =create_device_tree (&s->fdt_size);if (!ms->fdt) {
Signature · 1 line
2.39.2
[PULL 40/59] target/riscv: Allow debugger to access sstc CSRs
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
At present with a debugger attached sstc CSRs can only be accssed when CPU is in M-mode, or configured correctly.
Fix it by adjusting their predicate() routine logic so that the static config check comes before the run-time check, as well as adding a debugger check.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
target/riscv/csr.c +14 -5
@@ -952,6 +952,19 @@ static RISCVException sstc(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } +if ((csrno ==CSR_VSTIMECMP ) || (csrno ==CSR_VSTIMECMPH )) { + hmode_check = true; + } + +RISCVException ret = hmode_check ?hmode (env, csrno) :smode (env, csrno); +if (ret !=RISCV_EXCP_NONE ) { +return ret; + } + +if (env->debugger) { +return RISCV_EXCP_NONE ; + } +if (env->priv ==PRV_M ) {return RISCV_EXCP_NONE ; }
@@ -972,11 +985,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno) } } -if ((csrno ==CSR_VSTIMECMP ) || (csrno ==CSR_VSTIMECMPH )) { - hmode_check = true; - } - -return hmode_check ?hmode (env, csrno) :smode (env, csrno); +return RISCV_EXCP_NONE ; }static RISCVException sstc_32 (CPURISCVState *env,int csrno)
Signature · 1 line
2.39.2
[PULL 41/59] target/riscv: Drop priv level check in mseccfg predicate()
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
riscv_csrrw_check() already does the generic privilege level check hence there is no need to do the specific M-mode access check in the mseccfg predicate().
With this change debugger can access the mseccfg CSR anytime.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
@@ -451,7 +451,7 @@ static RISCVException pmp(CPURISCVState *env, int csrno)static RISCVException epmp (CPURISCVState *env,int csrno) { -if (env->priv ==PRV_M &&riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->epmp) {return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 42/59] target/riscv: Group all predicate() routines together
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Move sstc()/sstc32() to where all predicate() routines live, and smstateen_acc_ok() to near {read,write}_xenvcfg().
Message-ID: <[email protected]>
--- target/riscv/csr.c | 177 ++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 90 deletions(-)
target/riscv/csr.c +87 -90
@@ -40,42 +40,6 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) csr_ops[csrno & (CSR_TABLE_SIZE -1 )] = *ops; } -/* Predicates */ -#if !defined(CONFIG_USER_ONLY ) -static RISCVException smstateen_acc_ok (CPURISCVState *env,int index, -uint64_t bit) -{ -bool virt =riscv_cpu_virt_enabled (env); -RISCVCPU *cpu =env_archcpu (env); - -if (env->priv ==PRV_M || !cpu->cfg.ext_smstateen) { -return RISCV_EXCP_NONE ; - } - -if (!(env->mstateen[index] & bit)) { -return RISCV_EXCP_ILLEGAL_INST ; - } - -if (virt) { -if (!(env->hstateen[index] & bit)) { -return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; - } - -if (env->priv ==PRV_U && !(env->sstateen[index] & bit)) { -return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; - } - } - -if (env->priv ==PRV_U &&riscv_has_ext (env,RVS )) { -if (!(env->sstateen[index] & bit)) { -return RISCV_EXCP_ILLEGAL_INST ; - } - } - -return RISCV_EXCP_NONE ; -} -#endif -static RISCVException fs (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY )
@@ -399,6 +363,60 @@ static RISCVException sstateen(CPURISCVState *env, int csrno)return RISCV_EXCP_NONE ; } +static RISCVException sstc (CPURISCVState *env,int csrno) +{ +RISCVCPU *cpu =env_archcpu (env); +bool hmode_check = false; + +if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +if ((csrno ==CSR_VSTIMECMP ) || (csrno ==CSR_VSTIMECMPH )) { + hmode_check = true; + } + +RISCVException ret = hmode_check ?hmode (env, csrno) :smode (env, csrno); +if (ret !=RISCV_EXCP_NONE ) { +return ret; + } + +if (env->debugger) { +return RISCV_EXCP_NONE ; + } + +if (env->priv ==PRV_M ) { +return RISCV_EXCP_NONE ; + } + +/* +* No need of separate function for rv32 as menvcfg stores both menvcfg +* menvcfgh for RV32. +*/ +if (!(get_field (env->mcounteren,COUNTEREN_TM ) && +get_field (env->menvcfg,MENVCFG_STCE ))) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +if (riscv_cpu_virt_enabled (env)) { +if (!(get_field (env->hcounteren,COUNTEREN_TM ) && +get_field (env->henvcfg,HENVCFG_STCE ))) { +return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; + } + } + +return RISCV_EXCP_NONE ; +} + +static RISCVException sstc_32 (CPURISCVState *env,int csrno) +{ +if (riscv_cpu_mxl (env) !=MXL_RV32 ) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +return sstc (env, csrno); +} +/* Checks if PointerMasking registers could be accessed */ static RISCVException pointer_masking (CPURISCVState *env,int csrno) {
@@ -943,60 +961,6 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } -static RISCVException sstc (CPURISCVState *env,int csrno) -{ -RISCVCPU *cpu =env_archcpu (env); -bool hmode_check = false; - -if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { -return RISCV_EXCP_ILLEGAL_INST ; - } - -if ((csrno ==CSR_VSTIMECMP ) || (csrno ==CSR_VSTIMECMPH )) { - hmode_check = true; - } - -RISCVException ret = hmode_check ?hmode (env, csrno) :smode (env, csrno); -if (ret !=RISCV_EXCP_NONE ) { -return ret; - } - -if (env->debugger) { -return RISCV_EXCP_NONE ; - } - -if (env->priv ==PRV_M ) { -return RISCV_EXCP_NONE ; - } - -/* -* No need of separate function for rv32 as menvcfg stores both menvcfg -* menvcfgh for RV32. -*/ -if (!(get_field (env->mcounteren,COUNTEREN_TM ) && -get_field (env->menvcfg,MENVCFG_STCE ))) { -return RISCV_EXCP_ILLEGAL_INST ; - } - -if (riscv_cpu_virt_enabled (env)) { -if (!(get_field (env->hcounteren,COUNTEREN_TM ) && -get_field (env->henvcfg,HENVCFG_STCE ))) { -return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; - } - } - -return RISCV_EXCP_NONE ; -} - -static RISCVException sstc_32 (CPURISCVState *env,int csrno) -{ -if (riscv_cpu_mxl (env) !=MXL_RV32 ) { -return RISCV_EXCP_ILLEGAL_INST ; - } - -return sstc (env, csrno); -} -static RISCVException read_vstimecmp (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -1944,6 +1908,39 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException smstateen_acc_ok (CPURISCVState *env,int index, +uint64_t bit) +{ +bool virt =riscv_cpu_virt_enabled (env); +RISCVCPU *cpu =env_archcpu (env); + +if (env->priv ==PRV_M || !cpu->cfg.ext_smstateen) { +return RISCV_EXCP_NONE ; + } + +if (!(env->mstateen[index] & bit)) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +if (virt) { +if (!(env->hstateen[index] & bit)) { +return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; + } + +if (env->priv ==PRV_U && !(env->sstateen[index] & bit)) { +return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ; + } + } + +if (env->priv ==PRV_U &&riscv_has_ext (env,RVS )) { +if (!(env->sstateen[index] & bit)) { +return RISCV_EXCP_ILLEGAL_INST ; + } + } + +return RISCV_EXCP_NONE ; +} +static RISCVException read_senvcfg (CPURISCVState *env,int csrno,target_ulong *val) {
Signature · 1 line
2.39.2
[PULL 48/59] target/riscv: Fix the relationship between menvcfg.PBMTE/STCE and Svpbmt/Sstc extensions
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
menvcfg.PBMTE/STCE are read-only zero if Svpbmt/Sstc are not implemented.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
target/riscv/csr.c +6 -2
@@ -1885,10 +1885,12 @@ static RISCVException read_menvcfg(CPURISCVState *env, int csrno,static RISCVException write_menvcfg (CPURISCVState *env,int csrno,target_ulong val) { +RISCVCPUConfig *cfg = &env_archcpu (env)->cfg;uint64_t mask =MENVCFG_FIOM |MENVCFG_CBIE |MENVCFG_CBCFE |MENVCFG_CBZE ;if (riscv_cpu_mxl (env) ==MXL_RV64 ) { - mask |=MENVCFG_PBMTE |MENVCFG_STCE ; + mask |= (cfg->ext_svpbmt ?MENVCFG_PBMTE :0 ) | + (cfg->ext_sstc ?MENVCFG_STCE :0 ); } env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
@@ -1905,7 +1907,9 @@ static RISCVException read_menvcfgh(CPURISCVState *env, int csrno,static RISCVException write_menvcfgh (CPURISCVState *env,int csrno,target_ulong val) { -uint64_t mask =MENVCFG_PBMTE |MENVCFG_STCE ; +RISCVCPUConfig *cfg = &env_archcpu (env)->cfg; +uint64_t mask = (cfg->ext_svpbmt ?MENVCFG_PBMTE :0 ) | + (cfg->ext_sstc ?MENVCFG_STCE :0 );uint64_t valh = (uint64_t )val <<32 ; env->menvcfg = (env->menvcfg & ~mask) | (valh & mask);
Signature · 1 line
2.39.2
[PULL 45/59] target/riscv: Add support for Zicond extension
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
The spec can be found in https://github.com/riscv/riscv-zicond.
Two instructions are added:
- czero.eqz: Moves zero to a register rd, if the condition rs2 is equal to zero, otherwise moves rs1 to rd.
- czero.nez: Moves zero to a register rd, if the condition rs2 is nonzero, otherwise moves rs1 to rd.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 2 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzicond.c.inc | 49 ++++++++++++++++++++ target/riscv/translate.c | 1 + 5 files changed, 57 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzicond.c.inc
target/riscv/cpu.c +2 -0
@@ -74,6 +74,7 @@ struct isa_ext_data {static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (h, false,PRIV_VERSION_1_12_0 , ext_h),ISA_EXT_DATA_ENTRY (v, false,PRIV_VERSION_1_10_0 , ext_v), +ISA_EXT_DATA_ENTRY (zicond, true,PRIV_VERSION_1_12_0 , ext_zicond),ISA_EXT_DATA_ENTRY (zicsr, true,PRIV_VERSION_1_10_0 , ext_icsr),ISA_EXT_DATA_ENTRY (zifencei, true,PRIV_VERSION_1_10_0 , ext_ifencei),ISA_EXT_DATA_ENTRY (zihintpause, true,PRIV_VERSION_1_10_0 , ext_zihintpause),
@@ -1172,6 +1173,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("xventanacondops" ,RISCVCPU , cfg.ext_XVentanaCondOps, false),/* These are experimental so mark with 'x-' */ +DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),DEFINE_PROP_BOOL ("x-j" ,RISCVCPU , cfg.ext_j, false),/* ePMP 0.9.3 */ DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false),
target/riscv/cpu.h +1 -0
@@ -434,6 +434,7 @@ struct RISCVCPUConfig {bool ext_zkt;bool ext_ifencei;bool ext_icsr; +bool ext_zicond;bool ext_zihintpause;bool ext_smstateen;bool ext_sstc;
target/riscv/insn32.decode +4 -0
@@ -890,3 +890,7 @@ sm3p1 00 01000 01001 ..... 001 ..... 0010011 @r2 # *** RV32 Zksed Standard Extension *** sm4ed .. 11000 ..... ..... 000 ..... 0110011 @k_aes sm4ks .. 11010 ..... ..... 000 ..... 0110011 @k_aes + +# *** RV32 Zicond Standard Extension *** +czero_eqz 0000111 ..... ..... 101 ..... 0110011 @r +czero_nez 0000111 ..... ..... 111 ..... 0110011 @r
target/riscv/insn_trans/trans_rvzicond.c.inc new file +49 -0
49 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1103,6 +1103,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvh.c.inc" #include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" +#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_rvk.c.inc"
Signature · 1 line
2.39.2
[PULL 55/59] target/riscv/csr.c: simplify mctr()
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
Use riscv_cpu_cfg() to retrieve pmu_num.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
target/riscv/csr.c +2 -3
@@ -165,8 +165,7 @@ static RISCVException ctr32(CPURISCVState *env, int csrno)#if !defined(CONFIG_USER_ONLY )static RISCVException mctr (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +int pmu_num =riscv_cpu_cfg (env)->pmu_num;int ctr_index;int base_csrno =CSR_MHPMCOUNTER3 ;
@@ -175,7 +174,7 @@ static RISCVException mctr(CPURISCVState *env, int csrno) base_csrno +=0x80 ; } ctr_index = csrno - base_csrno; -if (!cpu->cfg.pmu_num || ctr_index >= cpu->cfg.pmu_num) { +if (!pmu_num || ctr_index >= pmu_num) {/* The PMU is not enabled or counter is out of range*/ return RISCV_EXCP_ILLEGAL_INST ; }
Signature · 1 line
2.39.2
[PULL 47/59] hw/riscv: Move the dtb load bits outside of create_fdt()
In reply to Palmer DabbeltFrom: Bin Meng <[email protected]>
Move the dtb load bits outside of create_fdt(), and put it explicitly in sifive_u_machine_init() and virt_machine_init(). With such change create_fdt() does exactly what its function name tells us.
Message-ID: <[email protected]>
--- hw/riscv/sifive_u.c | 31 +++++++++++++++---------------- hw/riscv/virt.c | 29 ++++++++++++++--------------- include/hw/riscv/sifive_u.h | 1 + 3 files changed, 30 insertions(+), 31 deletions(-)
hw/riscv/sifive_u.c +15 -16
@@ -99,7 +99,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,MachineState *ms =MACHINE (s);uint64_t mem_size = ms->ram_size;void *fdt; -int cpu, fdt_size; +int cpu;uint32_t *cells;char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;
@@ -112,19 +112,10 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, "sifive,plic-1.0.0", "riscv,plic0" }; -if (ms->dtb) { - fdt = ms->fdt =load_device_tree (ms->dtb, &fdt_size); -if (!fdt) { -error_report ("load_device_tree() failed" ); -exit (1 ); - } -return ; - }else { - fdt = ms->fdt =create_device_tree (&fdt_size); -if (!fdt) { -error_report ("create_device_tree() failed" ); -exit (1 ); - } + fdt = ms->fdt =create_device_tree (&s->fdt_size); +if (!fdt) { +error_report ("create_device_tree() failed" ); +exit (1 ); }qemu_fdt_setprop_string (fdt,"/" ,"model" ,"SiFive HiFive Unleashed A00" );
@@ -561,8 +552,16 @@ static void sifive_u_machine_init(MachineState *machine)qdev_connect_gpio_out (DEVICE (&(s->soc.gpio)),10 ,qemu_allocate_irq (sifive_u_machine_reset,NULL ,0 )); -/* create device tree */ -create_fdt (s, memmap,riscv_is_32bit (&s->soc.u_cpus)); +/* load/create device tree */ +if (machine->dtb) { + machine->fdt =load_device_tree (machine->dtb, &s->fdt_size); +if (!machine->fdt) { +error_report ("load_device_tree() failed" ); +exit (1 ); + } + }else { +create_fdt (s, memmap,riscv_is_32bit (&s->soc.u_cpus)); + }if (s->start_in_flash) {/*
hw/riscv/virt.c +14 -15
@@ -1009,19 +1009,10 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap)uint32_t irq_pcie_phandle =1 , irq_virtio_phandle =1 ;uint8_t rng_seed[32 ]; -if (ms->dtb) { - ms->fdt =load_device_tree (ms->dtb, &s->fdt_size); -if (!ms->fdt) { -error_report ("load_device_tree() failed" ); -exit (1 ); - } -return ; - }else { - ms->fdt =create_device_tree (&s->fdt_size); -if (!ms->fdt) { -error_report ("create_device_tree() failed" ); -exit (1 ); - } + ms->fdt =create_device_tree (&s->fdt_size); +if (!ms->fdt) { +error_report ("create_device_tree() failed" ); +exit (1 ); }qemu_fdt_setprop_string (ms->fdt,"/" ,"model" ,"riscv-virtio,qemu" );
@@ -1506,8 +1497,16 @@ static void virt_machine_init(MachineState *machine) }virt_flash_map (s, system_memory); -/* create device tree */ -create_fdt (s, memmap); +/* load/create device tree */ +if (machine->dtb) { + machine->fdt =load_device_tree (machine->dtb, &s->fdt_size); +if (!machine->fdt) { +error_report ("load_device_tree() failed" ); +exit (1 ); + } + }else { +create_fdt (s, memmap); + } s->machine_done.notify = virt_machine_done;qemu_add_machine_init_done_notifier (&s->machine_done);
include/hw/riscv/sifive_u.h +1 -0
@@ -68,6 +68,7 @@ typedef struct SiFiveUState {/*< public >*/ SiFiveUSoCState soc; +int fdt_size;bool start_in_flash;uint32_t msel;
Signature · 1 line
2.39.2
[PULL 49/59] target/riscv: Fix the relationship of PBMTE/STCE fields between menvcfg and henvcfg
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
henvcfg.PBMTE/STCE are read-only zero if menvcfg.PBMTE/STCE are zero.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
target/riscv/csr.c +9 -4
@@ -1956,7 +1956,11 @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno,return ret; } - *val = env->henvcfg; +/* +* henvcfg.pbmte is read_only 0 when menvcfg.pbmte = 0 +* henvcfg.stce is read_only 0 when menvcfg.stce = 0 +*/ + *val = env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE ) | env->menvcfg);return RISCV_EXCP_NONE ; }
@@ -1972,7 +1976,7 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, }if (riscv_cpu_mxl (env) ==MXL_RV64 ) { - mask |=HENVCFG_PBMTE |HENVCFG_STCE ; + mask |= env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE ); } env->henvcfg = (env->henvcfg & ~mask) | (val & mask);
@@ -1990,14 +1994,15 @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno,return ret; } - *val = env->henvcfg >>32 ; + *val = (env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE ) | + env->menvcfg)) >>32 ;return RISCV_EXCP_NONE ; }static RISCVException write_henvcfgh (CPURISCVState *env,int csrno,target_ulong val) { -uint64_t mask =HENVCFG_PBMTE |HENVCFG_STCE ; +uint64_t mask = env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE );uint64_t valh = (uint64_t )val <<32 ;RISCVException ret;
Signature · 1 line
2.39.2
[PULL 50/59] target/riscv: Add csr support for svadu
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Add ext_svadu property
Add HADE field in *envcfg:
* menvcfg.HADE is read-only zero if Svadu is not implemented.
* henvcfg.HADE is read-only zero if menvcfg.HADE is zero.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 1 + target/riscv/cpu_bits.h | 4 ++++ target/riscv/csr.c | 17 +++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-)
target/riscv/cpu.h +1 -0
@@ -450,6 +450,7 @@ struct RISCVCPUConfig {bool ext_zihintpause;bool ext_smstateen;bool ext_sstc; +bool ext_svadu;bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;
target/riscv/cpu_bits.h +4 -0
@@ -747,10 +747,12 @@ typedef enum RISCVException {#define MENVCFG_CBIE (3UL << 4)#define MENVCFG_CBCFE BIT(6)#define MENVCFG_CBZE BIT(7) +#define MENVCFG_HADE (1ULL << 61)#define MENVCFG_PBMTE (1ULL << 62)#define MENVCFG_STCE (1ULL << 63)/* For RV32 */ +#define MENVCFGH_HADE BIT(29)#define MENVCFGH_PBMTE BIT(30)#define MENVCFGH_STCE BIT(31)
@@ -763,10 +765,12 @@ typedef enum RISCVException {#define HENVCFG_CBIE MENVCFG_CBIE#define HENVCFG_CBCFE MENVCFG_CBCFE#define HENVCFG_CBZE MENVCFG_CBZE +#define HENVCFG_HADE MENVCFG_HADE#define HENVCFG_PBMTE MENVCFG_PBMTE#define HENVCFG_STCE MENVCFG_STCE/* For RV32 */ +#define HENVCFGH_HADE MENVCFGH_HADE#define HENVCFGH_PBMTE MENVCFGH_PBMTE#define HENVCFGH_STCE MENVCFGH_STCE
target/riscv/csr.c +11 -6
@@ -1890,7 +1890,8 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,if (riscv_cpu_mxl (env) ==MXL_RV64 ) { mask |= (cfg->ext_svpbmt ?MENVCFG_PBMTE :0 ) | - (cfg->ext_sstc ?MENVCFG_STCE :0 ); + (cfg->ext_sstc ?MENVCFG_STCE :0 ) | + (cfg->ext_svadu ?MENVCFG_HADE :0 ); } env->menvcfg = (env->menvcfg & ~mask) | (val & mask);
@@ -1909,7 +1910,8 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, {RISCVCPUConfig *cfg = &env_archcpu (env)->cfg;uint64_t mask = (cfg->ext_svpbmt ?MENVCFG_PBMTE :0 ) | - (cfg->ext_sstc ?MENVCFG_STCE :0 ); + (cfg->ext_sstc ?MENVCFG_STCE :0 ) | + (cfg->ext_svadu ?MENVCFG_HADE :0 );uint64_t valh = (uint64_t )val <<32 ; env->menvcfg = (env->menvcfg & ~mask) | (valh & mask);
@@ -1959,8 +1961,10 @@ static RISCVException read_henvcfg(CPURISCVState *env, int csrno,/* * henvcfg.pbmte is read_only 0 when menvcfg.pbmte = 0 * henvcfg.stce is read_only 0 when menvcfg.stce = 0 +* henvcfg.hade is read_only 0 when menvcfg.hade = 0 */ - *val = env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE ) | env->menvcfg); + *val = env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE |HENVCFG_HADE ) | + env->menvcfg);return RISCV_EXCP_NONE ; }
@@ -1976,7 +1980,7 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno, }if (riscv_cpu_mxl (env) ==MXL_RV64 ) { - mask |= env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE ); + mask |= env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE |HENVCFG_HADE ); } env->henvcfg = (env->henvcfg & ~mask) | (val & mask);
@@ -1994,7 +1998,7 @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno,return ret; } - *val = (env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE ) | + *val = (env->henvcfg & (~(HENVCFG_PBMTE |HENVCFG_STCE |HENVCFG_HADE ) | env->menvcfg)) >>32 ;return RISCV_EXCP_NONE ; }
@@ -2002,7 +2006,8 @@ static RISCVException read_henvcfgh(CPURISCVState *env, int csrno,static RISCVException write_henvcfgh (CPURISCVState *env,int csrno,target_ulong val) { -uint64_t mask = env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE ); +uint64_t mask = env->menvcfg & (HENVCFG_PBMTE |HENVCFG_STCE | +HENVCFG_HADE );uint64_t valh = (uint64_t )val <<32 ;RISCVException ret;
Signature · 1 line
2.39.2
[PULL 51/59] target/riscv: Add *envcfg.PBMTE related check in address translation
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
menvcfg.PBMTE bit controls whether the Svpbmt extension is available for use in S-mode and G-stage address translation.
henvcfg.PBMTE bit controls whether the Svpbmt extension is available for use in VS-stage address translation.
Set *envcfg.PBMTE default true for backward compatibility.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 3 +++ target/riscv/cpu_helper.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
target/riscv/cpu.c +3 -0
@@ -613,6 +613,9 @@ static void riscv_cpu_reset_hold(Object *obj) env->bins =0 ; env->two_stage_lookup = false; + env->menvcfg = (cpu->cfg.ext_svpbmt ?MENVCFG_PBMTE :0 ); + env->henvcfg = (cpu->cfg.ext_svpbmt ?HENVCFG_PBMTE :0 ); +/* Initialized default priorities of local interrupts. */ for (i =0 ; i <ARRAY_SIZE (env->miprio); i++) { iprio =riscv_cpu_default_priority (i);
target/riscv/cpu_helper.c +8 -2
@@ -936,9 +936,15 @@ restart:return TRANSLATE_FAIL ; } +bool pbmte = env->menvcfg &MENVCFG_PBMTE ; + +if (first_stage && two_stage &&riscv_cpu_virt_enabled (env)) { + pbmte = pbmte && (env->henvcfg &HENVCFG_PBMTE ); + } +if (riscv_cpu_sxl (env) ==MXL_RV32 ) { ppn = pte >>PTE_PPN_SHIFT ; - }else if (cpu->cfg.ext_svpbmt || cpu->cfg.ext_svnapot) { + }else if (pbmte || cpu->cfg.ext_svnapot) { ppn = (pte & (target_ulong )PTE_PPN_MASK ) >>PTE_PPN_SHIFT ; }else { ppn = pte >>PTE_PPN_SHIFT ;
@@ -950,7 +956,7 @@ restart:if (!(pte &PTE_V )) {/* Invalid PTE */ return TRANSLATE_FAIL ; - }else if (!cpu->cfg.ext_svpbmt && (pte &PTE_PBMT )) { + }else if (!pbmte && (pte &PTE_PBMT )) {return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */
Signature · 1 line
2.39.2
[PULL 52/59] target/riscv: Add *envcfg.HADE related check in address translation
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
When menvcfg.HADE is 1, hardware updating of PTE A/D bits is enabled during single-stage address translation. When the hypervisor extension is implemented, if menvcfg.HADE is 1, hardware updating of PTE A/D bits is enabled during G-stage address translation.
Set *envcfg.HADE default true for backward compatibility.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 6 ++++-- target/riscv/cpu_helper.c | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-)
target/riscv/cpu.c +4 -2
@@ -613,8 +613,10 @@ static void riscv_cpu_reset_hold(Object *obj) env->bins =0 ; env->two_stage_lookup = false; - env->menvcfg = (cpu->cfg.ext_svpbmt ?MENVCFG_PBMTE :0 ); - env->henvcfg = (cpu->cfg.ext_svpbmt ?HENVCFG_PBMTE :0 ); + env->menvcfg = (cpu->cfg.ext_svpbmt ?MENVCFG_PBMTE :0 ) | + (cpu->cfg.ext_svadu ?MENVCFG_HADE :0 ); + env->henvcfg = (cpu->cfg.ext_svpbmt ?HENVCFG_PBMTE :0 ) | + (cpu->cfg.ext_svadu ?HENVCFG_HADE :0 );/* Initialized default priorities of local interrupts. */ for (i =0 ; i <ARRAY_SIZE (env->miprio); i++) {
target/riscv/cpu_helper.c +6 -0
@@ -937,9 +937,11 @@ restart: }bool pbmte = env->menvcfg &MENVCFG_PBMTE ; +bool hade = env->menvcfg &MENVCFG_HADE ;if (first_stage && two_stage &&riscv_cpu_virt_enabled (env)) { pbmte = pbmte && (env->henvcfg &HENVCFG_PBMTE ); + hade = hade && (env->henvcfg &HENVCFG_HADE ); }if (riscv_cpu_sxl (env) ==MXL_RV32 ) {
@@ -998,6 +1000,10 @@ restart:/* Page table updates need to be atomic with MTTCG enabled */ if (updated_pte != pte) { +if (!hade) { +return TRANSLATE_FAIL ; + } +/* * - if accessed or dirty bits need updating, and the PTE is * in RAM, then we do so atomically with a compare and swap.
Signature · 1 line
2.39.2
[PULL 53/59] target/riscv: Export Svadu property
In reply to Palmer DabbeltFrom: Weiwei Li <[email protected]>
Set it default true for backward compatibility
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 3 +++ 1 file changed, 3 insertions(+)
target/riscv/cpu.c +3 -0
@@ -107,6 +107,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (ssaia, true,PRIV_VERSION_1_12_0 , ext_ssaia),ISA_EXT_DATA_ENTRY (sscofpmf, true,PRIV_VERSION_1_12_0 , ext_sscofpmf),ISA_EXT_DATA_ENTRY (sstc, true,PRIV_VERSION_1_12_0 , ext_sstc), +ISA_EXT_DATA_ENTRY (svadu, true,PRIV_VERSION_1_12_0 , ext_svadu),ISA_EXT_DATA_ENTRY (svinval, true,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot, true,PRIV_VERSION_1_12_0 , ext_svnapot), ISA_EXT_DATA_ENTRY(svpbmt, true, PRIV_VERSION_1_12_0, ext_svpbmt),
@@ -1104,6 +1105,8 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_BOOL ("svadu" ,RISCVCPU , cfg.ext_svadu, true), +DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false),
Signature · 1 line
2.39.2
[PULL 57/59] target/riscv/csr.c: avoid env_archcpu() usages when reading RISCVCPUConfig
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
Retrieving the CPU pointer using env_archcpu() just to access cpu->cfg can be avoided by using riscv_cpu_cfg().
Message-ID: <[email protected]>
--- target/riscv/csr.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-)
target/riscv/csr.c +9 -23
@@ -213,9 +213,7 @@ static RISCVException any32(CPURISCVState *env, int csrno)static int aia_any (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_smaia) { +if (!riscv_cpu_cfg (env)->ext_smaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -224,9 +222,7 @@ static int aia_any(CPURISCVState *env, int csrno)static int aia_any32 (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_smaia) { +if (!riscv_cpu_cfg (env)->ext_smaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -253,9 +249,7 @@ static int smode32(CPURISCVState *env, int csrno)static int aia_smode (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_ssaia) { +if (!riscv_cpu_cfg (env)->ext_ssaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -264,9 +258,7 @@ static int aia_smode(CPURISCVState *env, int csrno)static int aia_smode32 (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_ssaia) { +if (!riscv_cpu_cfg (env)->ext_ssaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -380,9 +372,7 @@ static RISCVException pointer_masking(CPURISCVState *env, int csrno)static int aia_hmode (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_ssaia) { +if (!riscv_cpu_cfg (env)->ext_ssaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -391,9 +381,7 @@ static int aia_hmode(CPURISCVState *env, int csrno)static int aia_hmode32 (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_ssaia) { +if (!riscv_cpu_cfg (env)->ext_ssaia) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -430,9 +418,7 @@ static RISCVException debug(CPURISCVState *env, int csrno)static RISCVException seed (CPURISCVState *env,int csrno) { -RISCVCPU *cpu =env_archcpu (env); - -if (!cpu->cfg.ext_zkr) { +if (!riscv_cpu_cfg (env)->ext_zkr) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -555,7 +541,7 @@ static RISCVException read_vl(CPURISCVState *env, int csrno,static int read_vlenb (CPURISCVState *env,int csrno,target_ulong *val) { - *val =env_archcpu (env)->cfg.vlen >>3 ; + *val =riscv_cpu_cfg (env)->vlen >>3 ;return RISCV_EXCP_NONE ; }
@@ -610,7 +596,7 @@ static RISCVException write_vstart(CPURISCVState *env, int csrno,* The vstart CSR is defined to have only enough writable bits * to hold the largest element index, i.e. lg2(VLEN) bits. */ - env->vstart = val & ~(~0ULL <<ctzl (env_archcpu (env)->cfg.vlen)); + env->vstart = val & ~(~0ULL <<ctzl (riscv_cpu_cfg (env)->vlen));return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 58/59] target/riscv/vector_helper.c: create vext_set_tail_elems_1s()
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
Commit 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions") added code to set the tail elements to 1 in the end of vext_ldst_stride(), vext_ldst_us(), vext_ldst_index() and vext_ldff(). Aside from a env->vl versus an evl value being used in the first loop, the code is being repeated 4 times.
Create a helper to avoid code repetition in all those functions. Arguments that are used in the callers (nf, esz and max_elems) are passed as arguments. All other values are being derived inside the helper.
Message-ID: <[email protected]>
--- target/riscv/vector_helper.c | 86 +++++++++++++----------------------- 1 file changed, 30 insertions(+), 56 deletions(-)
target/riscv/vector_helper.c +30 -56
@@ -267,6 +267,28 @@ GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw) GEN_VEXT_ST_ELEM(ste_w, int32_t, H4, stl) GEN_VEXT_ST_ELEM(ste_d, int64_t, H8, stq) +static void vext_set_tail_elems_1s (CPURISCVState *env,target_ulong vl, +void *vd,uint32_t desc,uint32_t nf, +uint32_t esz,uint32_t max_elems) +{ +uint32_t total_elems =vext_get_total_elems (env, desc, esz); +uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; +uint32_t vta =vext_vta (desc); +uint32_t registers_used; +int k; + +for (k =0 ; k < nf; ++k) { +vext_set_elems_1s (vd, vta, (k * max_elems + vl) * esz, + (k * max_elems + max_elems) * esz); + } + +if (nf * max_elems % total_elems !=0 ) { + registers_used = ((nf * max_elems) * esz + (vlenb -1 )) / vlenb; +vext_set_elems_1s (vd, vta, (nf * max_elems) * esz, + registers_used * vlenb); + } +} +/* *** stride: access vector element from strided memory */
@@ -281,8 +303,6 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,uint32_t nf =vext_nf (desc);uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz; -uint32_t total_elems =vext_get_total_elems (env, desc, esz); -uint32_t vta =vext_vta (desc);uint32_t vma =vext_vma (desc);for (i = env->vstart; i < env->vl; i++, env->vstart++) {
@@ -301,18 +321,8 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base, } } env->vstart =0 ; -/* set tail elements to 1s */ -for (k =0 ; k < nf; ++k) { -vext_set_elems_1s (vd, vta, (k * max_elems + env->vl) * esz, - (k * max_elems + max_elems) * esz); - } -if (nf * max_elems % total_elems !=0 ) { -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; -uint32_t registers_used = - ((nf * max_elems) * esz + (vlenb -1 )) / vlenb; -vext_set_elems_1s (vd, vta, (nf * max_elems) * esz, - registers_used * vlenb); - } + +vext_set_tail_elems_1s (env, env->vl, vd, desc, nf, esz, max_elems); }#define GEN_VEXT_LD_STRIDE (NAME ,ETYPE ,LOAD_FN ) \
@@ -359,8 +369,6 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,uint32_t nf =vext_nf (desc);uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz; -uint32_t total_elems =vext_get_total_elems (env, desc, esz); -uint32_t vta =vext_vta (desc);/* load bytes from guest memory */ for (i = env->vstart; i < evl; i++, env->vstart++) {
@@ -372,18 +380,8 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, } } env->vstart =0 ; -/* set tail elements to 1s */ -for (k =0 ; k < nf; ++k) { -vext_set_elems_1s (vd, vta, (k * max_elems + evl) * esz, - (k * max_elems + max_elems) * esz); - } -if (nf * max_elems % total_elems !=0 ) { -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; -uint32_t registers_used = - ((nf * max_elems) * esz + (vlenb -1 )) / vlenb; -vext_set_elems_1s (vd, vta, (nf * max_elems) * esz, - registers_used * vlenb); - } + +vext_set_tail_elems_1s (env, evl, vd, desc, nf, esz, max_elems); }/*
@@ -484,8 +482,6 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,uint32_t vm =vext_vm (desc);uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz; -uint32_t total_elems =vext_get_total_elems (env, desc, esz); -uint32_t vta =vext_vta (desc);uint32_t vma =vext_vma (desc);/* load bytes from guest memory */
@@ -505,18 +501,8 @@ vext_ldst_index(void *vd, void *v0, target_ulong base, } } env->vstart =0 ; -/* set tail elements to 1s */ -for (k =0 ; k < nf; ++k) { -vext_set_elems_1s (vd, vta, (k * max_elems + env->vl) * esz, - (k * max_elems + max_elems) * esz); - } -if (nf * max_elems % total_elems !=0 ) { -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; -uint32_t registers_used = - ((nf * max_elems) * esz + (vlenb -1 )) / vlenb; -vext_set_elems_1s (vd, vta, (nf * max_elems) * esz, - registers_used * vlenb); - } + +vext_set_tail_elems_1s (env, env->vl, vd, desc, nf, esz, max_elems); }#define GEN_VEXT_LD_INDEX (NAME ,ETYPE ,INDEX_FN ,LOAD_FN ) \
@@ -585,8 +571,6 @@ vext_ldff(void *vd, void *v0, target_ulong base,uint32_t vm =vext_vm (desc);uint32_t max_elems =vext_max_elems (desc, log2_esz);uint32_t esz =1 << log2_esz; -uint32_t total_elems =vext_get_total_elems (env, desc, esz); -uint32_t vta =vext_vta (desc);uint32_t vma =vext_vma (desc);target_ulong addr, offset, remain;
@@ -647,18 +631,8 @@ ProbeSuccess: } } env->vstart =0 ; -/* set tail elements to 1s */ -for (k =0 ; k < nf; ++k) { -vext_set_elems_1s (vd, vta, (k * max_elems + env->vl) * esz, - (k * max_elems + max_elems) * esz); - } -if (nf * max_elems % total_elems !=0 ) { -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; -uint32_t registers_used = - ((nf * max_elems) * esz + (vlenb -1 )) / vlenb; -vext_set_elems_1s (vd, vta, (nf * max_elems) * esz, - registers_used * vlenb); - } + +vext_set_tail_elems_1s (env, env->vl, vd, desc, nf, esz, max_elems); }#define GEN_VEXT_LDFF (NAME ,ETYPE ,LOAD_FN ) \
Signature · 1 line
2.39.2
[PULL 56/59] target/riscv/csr.c: use riscv_cpu_cfg() to avoid env_cpu() pointers
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
A common trend in this file is to retrieve a RISCVCPU pointer by first retrieving a CPUState pointer via env_cpu(). The CPU pointer is used only to access the RISCVCPUConfig object and nothing else.
Let's use riscv_cpu_cfg() to access what we need directly without these 2 pointers.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 50 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-)
target/riscv/csr.c +12 -38
@@ -46,10 +46,8 @@ static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bit) {bool virt =riscv_cpu_virt_enabled (env); -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); -if (env->priv ==PRV_M || !cpu->cfg.ext_smstateen) { +if (env->priv ==PRV_M || !riscv_cpu_cfg (env)->ext_smstateen) {return RISCV_EXCP_NONE ; }
@@ -81,7 +79,7 @@ static RISCVException fs(CPURISCVState *env, int csrno) {#if !defined(CONFIG_USER_ONLY )if (!env->debugger && !riscv_cpu_fp_enabled (env) && - !RISCV_CPU (env_cpu (env))->cfg.ext_zfinx) { + !riscv_cpu_cfg (env)->ext_zfinx) {return RISCV_EXCP_ILLEGAL_INST ; }#endif
@@ -90,11 +88,9 @@ static RISCVException fs(CPURISCVState *env, int csrno)static RISCVException vs (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); -if (env->misa_ext &RVV || - cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) { +riscv_cpu_cfg (env)->ext_zve32f || +riscv_cpu_cfg (env)->ext_zve64f) {#if !defined(CONFIG_USER_ONLY )if (!env->debugger && !riscv_cpu_vector_enabled (env)) {return RISCV_EXCP_ILLEGAL_INST ;
@@ -193,10 +189,7 @@ static RISCVException mctr32(CPURISCVState *env, int csrno)static RISCVException sscofpmf (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - -if (!cpu->cfg.ext_sscofpmf) { +if (!riscv_cpu_cfg (env)->ext_sscofpmf) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -319,10 +312,7 @@ static RISCVException umode32(CPURISCVState *env, int csrno)static RISCVException mstateen (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - -if (!cpu->cfg.ext_smstateen) { +if (!riscv_cpu_cfg (env)->ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -331,10 +321,7 @@ static RISCVException mstateen(CPURISCVState *env, int csrno)static RISCVException hstateen_pred (CPURISCVState *env,int csrno,int base) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - -if (!cpu->cfg.ext_smstateen) { +if (!riscv_cpu_cfg (env)->ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -361,10 +348,8 @@ static RISCVException sstateen(CPURISCVState *env, int csrno) {bool virt =riscv_cpu_virt_enabled (env);int index = csrno -CSR_SSTATEEN0 ; -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); -if (!cpu->cfg.ext_smstateen) { +if (!riscv_cpu_cfg (env)->ext_smstateen) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -916,11 +901,9 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno,static RISCVException sstc (CPURISCVState *env,int csrno) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs);bool hmode_check = false; -if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { +if (!riscv_cpu_cfg (env)->ext_sstc || !env->rdtime_fn) {return RISCV_EXCP_ILLEGAL_INST ; }
@@ -1150,30 +1133,21 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,static RISCVException read_mvendorid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - - *val = cpu->cfg.mvendorid; + *val =riscv_cpu_cfg (env)->mvendorid;return RISCV_EXCP_NONE ; }static RISCVException read_marchid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - - *val = cpu->cfg.marchid; + *val =riscv_cpu_cfg (env)->marchid;return RISCV_EXCP_NONE ; }static RISCVException read_mimpid (CPURISCVState *env,int csrno,target_ulong *val) { -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); - - *val = cpu->cfg.mimpid; + *val =riscv_cpu_cfg (env)->mimpid;return RISCV_EXCP_NONE ; }
Signature · 1 line
2.39.2
[PULL 54/59] target/riscv/csr.c: use env_archcpu() in ctr()
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
We don't need to use env_cpu() and CPUState().
Message-ID: <[email protected]>
--- target/riscv/csr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/csr.c +1 -2
@@ -108,8 +108,7 @@ static RISCVException vs(CPURISCVState *env, int csrno)static RISCVException ctr (CPURISCVState *env,int csrno) {#if !defined(CONFIG_USER_ONLY ) -CPUState *cs =env_cpu (env); -RISCVCPU *cpu =RISCV_CPU (cs); +RISCVCPU *cpu =env_archcpu (env);int ctr_index;target_ulong ctr_mask;int base_csrno =CSR_CYCLE ;
Signature · 1 line
2.39.2
[PULL 59/59] target/riscv/vector_helper.c: avoid env_archcpu() when reading RISCVCPUConfig
In reply to Palmer DabbeltFrom: Daniel Henrique Barboza <[email protected]>
This file has several uses of env_archcpu() that are used solely to read cfg->vlen. Use the new riscv_cpu_cfg() inline instead.
Message-ID: <[email protected]>
--- target/riscv/vector_helper.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
target/riscv/vector_helper.c +10 -10
@@ -272,7 +272,7 @@ static void vext_set_tail_elems_1s(CPURISCVState *env, target_ulong vl, uint32_t esz, uint32_t max_elems) { uint32_t total_elems = vext_get_total_elems(env, desc, esz); -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; +uint32_t vlenb =riscv_cpu_cfg (env)->vlen >>3 ;uint32_t vta =vext_vta (desc);uint32_t registers_used;int k;
@@ -671,7 +671,7 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, {uint32_t i, k, off, pos;uint32_t nf =vext_nf (desc); -uint32_t vlenb =env_archcpu (env)->cfg.vlen >>3 ; +uint32_t vlenb =riscv_cpu_cfg (env)->vlen >>3 ;uint32_t max_elems = vlenb >> log2_esz; k = env->vstart / max_elems;
@@ -1141,7 +1141,7 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \ { \uint32_t vl = env->vl; \uint32_t vm =vext_vm (desc); \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t i; \ \
@@ -1177,7 +1177,7 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, \ { \uint32_t vl = env->vl; \uint32_t vm =vext_vm (desc); \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t i; \ \
@@ -1376,7 +1376,7 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \ { \uint32_t vm =vext_vm (desc); \uint32_t vl = env->vl; \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t vma =vext_vma (desc); \uint32_t i; \
@@ -1439,7 +1439,7 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2, \ { \uint32_t vm =vext_vm (desc); \uint32_t vl = env->vl; \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t vma =vext_vma (desc); \uint32_t i; \
@@ -4152,7 +4152,7 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2, \ { \uint32_t vm =vext_vm (desc); \uint32_t vl = env->vl; \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t vma =vext_vma (desc); \uint32_t i; \
@@ -4190,7 +4190,7 @@ void HELPER(NAME)(void *vd, void *v0, uint64_t s1, void *vs2, \ { \uint32_t vm =vext_vm (desc); \uint32_t vl = env->vl; \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t vma =vext_vma (desc); \uint32_t i; \
@@ -4721,7 +4721,7 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, \ uint32_t desc) \ { \uint32_t vl = env->vl; \ -uint32_t total_elems =env_archcpu (env)->cfg.vlen; \ +uint32_t total_elems =riscv_cpu_cfg (env)->vlen; \uint32_t vta_all_1s =vext_vta_all_1s (desc); \uint32_t i; \int a, b; \
@@ -4808,7 +4808,7 @@ static void vmsetm(void *vd, void *v0, void *vs2, CPURISCVState *env, {uint32_t vm =vext_vm (desc);uint32_t vl = env->vl; -uint32_t total_elems =env_archcpu (env)->cfg.vlen; +uint32_t total_elems =riscv_cpu_cfg (env)->vlen;uint32_t vta_all_1s =vext_vta_all_1s (desc);uint32_t vma =vext_vma (desc);int i;
Signature · 1 line
2.39.2
Quoted 24 lines · Palmer Dabbelt
merged tag 'buildsys-qom-qdev-ui-20230227'
The following changes since commit627634031092e1514f363fd8659a579398de0f0e:Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)
are available in the Git repository at:
https://gitlab.com/palmer-dabbelt/qemu.git tags/pull-riscv-to-apply-20230303
for you to fetch changes up to
37151032989ecf6e7ce8b65bc7bcb400d0318b2c:Merge patch series "target/riscv: some
vector_helper.ccleanups" (2023-03-01 18:09:48 -0800)----------------------------------------------------------------
Fifth RISC-V PR for QEMU 8.0* Experimantal support for writable misa.
* Support for Svadu extension.
* Support for the Zicond extension.
* Fixes to gdbstub, CSR accesses, dependencies between the various floating-point exceptions, and XTheadMemPair.
* Many cleanups.
Quoted 7 lines
----------------------------------------------------------------
There's a lot of cleanups here, a handful of which ended up stepping on each other and were necessary for various features. I tried to keep each individual patch set intact, but that led to some merge conflicts and a bit of a clunky history -- I'm not sure what the right answer is there, happy to re-spin this to be more linear if that's problem for folks.
It looks like in this case you got lucky, but in general I don't recommend including merge commits in your pull requests, rather than fixing up patches by rebasing them. If I find that a pull request has merge conflicts when I try to merge it, I'm going to kick it back to you to rebase, and then you need to rebase and fix up the commits in it anyway...
thanks
-- PMM
Peter Maydell
AppliedQuoted 40 lines · Palmer Dabbelt
merged tag 'buildsys-qom-qdev-ui-20230227'
The following changes since commit627634031092e1514f363fd8659a579398de0f0e:Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)
are available in the Git repository at:
https://gitlab.com/palmer-dabbelt/qemu.git tags/pull-riscv-to-apply-20230303
for you to fetch changes up to
37151032989ecf6e7ce8b65bc7bcb400d0318b2c:Merge patch series "target/riscv: some
vector_helper.ccleanups" (2023-03-01 18:09:48 -0800)----------------------------------------------------------------
Fifth RISC-V PR for QEMU 8.0* Experimantal support for writable misa.
* Support for Svadu extension.
* Support for the Zicond extension.
* Fixes to gdbstub, CSR accesses, dependencies between the various floating-point exceptions, and XTheadMemPair.
* Many cleanups.----------------------------------------------------------------
There's a lot of cleanups here, a handful of which ended up stepping on each other and were necessary for various features. I tried to keep each individual patch set intact, but that led to some merge conflicts and a bit of a clunky history -- I'm not sure what the right answer is there, happy to re-spin this to be more linear if that's problem for folks.Unfortunately the OpenSBI bump is still failing CI, it turns out I missed the second stage. I was intending on having a sixth PR anyway as I'd really like to get the ACPI patches in for 8.0 so we can start testing everywhere else. There's also a patch set from Daniel that's ready to go but depends on some recently merged TCG patches, so I figured it'd be better to just send what's ready now rather than trying to make the history more complicated.
Quoted 7 lines
This all passes my local tests ("make check" and a bunch of Linux configs), but "push-ci-now" is still tripping up on OpenSBI as that's due to some network resources changing. With any luck I'll have some time to sort things out this weekend (though always happy to have some help if anyone wants to throw in some time).
----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes.
-- PMM