mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
Merge patch series "RISCVCPUConfig related cleanups"
Daniel Henrique Barboza <dbarboza@ventanamicro.com> says:
These cleanups were suggested by LIU Zhiwei during the review of
d3e6d5762b
("Merge patch series "make write_misa a no-op and FEATURE_*
cleanups"").
* b4-shazam-merge:
target/riscv/csr.c: avoid env_archcpu() usages when reading RISCVCPUConfig
target/riscv/csr.c: use riscv_cpu_cfg() to avoid env_cpu() pointers
target/riscv/csr.c: simplify mctr()
target/riscv/csr.c: use env_archcpu() in ctr()
Message-ID: <20230224174520.92490-1-dbarboza@ventanamicro.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
This commit is contained in:
commit
0b28c7ea0e
1 changed files with 48 additions and 61 deletions
|
@ -40,11 +40,46 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops)
|
||||||
csr_ops[csrno & (CSR_TABLE_SIZE - 1)] = *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);
|
||||||
|
|
||||||
|
if (env->priv == PRV_M || !riscv_cpu_cfg(env)->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)
|
static RISCVException fs(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
if (!env->debugger && !riscv_cpu_fp_enabled(env) &&
|
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;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -130,7 +165,7 @@ static RISCVException ctr32(CPURISCVState *env, int csrno)
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
static RISCVException mctr(CPURISCVState *env, int csrno)
|
static RISCVException mctr(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
int pmu_num = riscv_cpu_cfg(env)->pmu_num;
|
||||||
int ctr_index;
|
int ctr_index;
|
||||||
int base_csrno = CSR_MHPMCOUNTER3;
|
int base_csrno = CSR_MHPMCOUNTER3;
|
||||||
|
|
||||||
|
@ -139,7 +174,7 @@ static RISCVException mctr(CPURISCVState *env, int csrno)
|
||||||
base_csrno += 0x80;
|
base_csrno += 0x80;
|
||||||
}
|
}
|
||||||
ctr_index = csrno - base_csrno;
|
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*/
|
/* The PMU is not enabled or counter is out of range*/
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
@ -184,9 +219,7 @@ static RISCVException any32(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_any(CPURISCVState *env, int csrno)
|
static int aia_any(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_smaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_smaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,9 +228,7 @@ static int aia_any(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_any32(CPURISCVState *env, int csrno)
|
static int aia_any32(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_smaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_smaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,9 +255,7 @@ static int smode32(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_smode(CPURISCVState *env, int csrno)
|
static int aia_smode(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_ssaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_ssaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,9 +264,7 @@ static int aia_smode(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_smode32(CPURISCVState *env, int csrno)
|
static int aia_smode32(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_ssaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_ssaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,9 +359,8 @@ static RISCVException sstateen(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
bool virt = riscv_cpu_virt_enabled(env);
|
bool virt = riscv_cpu_virt_enabled(env);
|
||||||
int index = csrno - CSR_SSTATEEN0;
|
int index = csrno - CSR_SSTATEEN0;
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
|
||||||
|
|
||||||
if (!cpu->cfg.ext_smstateen) {
|
if (!riscv_cpu_cfg(env)->ext_smstateen) {
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,9 +454,7 @@ static RISCVException pointer_masking(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_hmode(CPURISCVState *env, int csrno)
|
static int aia_hmode(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_ssaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_ssaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,9 +463,7 @@ static int aia_hmode(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static int aia_hmode32(CPURISCVState *env, int csrno)
|
static int aia_hmode32(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_ssaia) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_ssaia) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,9 +509,7 @@ static RISCVException debug(CPURISCVState *env, int csrno)
|
||||||
|
|
||||||
static RISCVException seed(CPURISCVState *env, int csrno)
|
static RISCVException seed(CPURISCVState *env, int csrno)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu = env_archcpu(env);
|
if (!riscv_cpu_cfg(env)->ext_zkr) {
|
||||||
|
|
||||||
if (!cpu->cfg.ext_zkr) {
|
|
||||||
return RISCV_EXCP_ILLEGAL_INST;
|
return RISCV_EXCP_ILLEGAL_INST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,7 +636,7 @@ static RISCVException read_vl(CPURISCVState *env, int csrno,
|
||||||
|
|
||||||
static int read_vlenb(CPURISCVState *env, int csrno, target_ulong *val)
|
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;
|
return RISCV_EXCP_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,7 +691,7 @@ static RISCVException write_vstart(CPURISCVState *env, int csrno,
|
||||||
* The vstart CSR is defined to have only enough writable bits
|
* The vstart CSR is defined to have only enough writable bits
|
||||||
* to hold the largest element index, i.e. lg2(VLEN) 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;
|
return RISCV_EXCP_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1913,39 +1933,6 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno,
|
||||||
return RISCV_EXCP_NONE;
|
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,
|
static RISCVException read_senvcfg(CPURISCVState *env, int csrno,
|
||||||
target_ulong *val)
|
target_ulong *val)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue