提交 3109cd98 编写于 作者: R Richard Henderson

target/riscv: Use env_cpu, env_archcpu

Cleanup in the boilerplate that each target must define.
Replace riscv_env_get_cpu with env_archcpu.  The combination
CPU(riscv_env_get_cpu) should have used ENV_GET_CPU to begin;
use env_cpu now.
Reviewed-by: NAlistair Francis <alistair.francis@wdc.com>
Signed-off-by: NRichard Henderson <richard.henderson@linaro.org>
上级 db70b311
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
void cpu_loop(CPURISCVState *env) void cpu_loop(CPURISCVState *env)
{ {
CPUState *cs = CPU(riscv_env_get_cpu(env)); CPUState *cs = env_cpu(env);
int trapnr, signum, sigcode; int trapnr, signum, sigcode;
target_ulong sigaddr; target_ulong sigaddr;
target_ulong ret; target_ulong ret;
......
...@@ -221,11 +221,6 @@ typedef struct RISCVCPU { ...@@ -221,11 +221,6 @@ typedef struct RISCVCPU {
} cfg; } cfg;
} RISCVCPU; } RISCVCPU;
static inline RISCVCPU *riscv_env_get_cpu(CPURISCVState *env)
{
return container_of(env, RISCVCPU, env);
}
static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext) static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext)
{ {
return (env->misa & ext) != 0; return (env->misa & ext) != 0;
......
...@@ -89,14 +89,12 @@ struct CpuAsyncInfo { ...@@ -89,14 +89,12 @@ struct CpuAsyncInfo {
static void riscv_cpu_update_mip_irqs_async(CPUState *target_cpu_state, static void riscv_cpu_update_mip_irqs_async(CPUState *target_cpu_state,
run_on_cpu_data data) run_on_cpu_data data)
{ {
CPURISCVState *env = &RISCV_CPU(target_cpu_state)->env;
RISCVCPU *cpu = riscv_env_get_cpu(env);
struct CpuAsyncInfo *info = (struct CpuAsyncInfo *) data.host_ptr; struct CpuAsyncInfo *info = (struct CpuAsyncInfo *) data.host_ptr;
if (info->new_mip) { if (info->new_mip) {
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); cpu_interrupt(target_cpu_state, CPU_INTERRUPT_HARD);
} else { } else {
cpu_reset_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); cpu_reset_interrupt(target_cpu_state, CPU_INTERRUPT_HARD);
} }
g_free(info); g_free(info);
...@@ -212,7 +210,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, ...@@ -212,7 +210,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
} }
} }
CPUState *cs = CPU(riscv_env_get_cpu(env)); CPUState *cs = env_cpu(env);
int va_bits = PGSHIFT + levels * ptidxbits; int va_bits = PGSHIFT + levels * ptidxbits;
target_ulong mask = (1L << (TARGET_LONG_BITS - (va_bits - 1))) - 1; target_ulong mask = (1L << (TARGET_LONG_BITS - (va_bits - 1))) - 1;
target_ulong masked_msbs = (addr >> (va_bits - 1)) & mask; target_ulong masked_msbs = (addr >> (va_bits - 1)) & mask;
...@@ -341,7 +339,7 @@ restart: ...@@ -341,7 +339,7 @@ restart:
static void raise_mmu_exception(CPURISCVState *env, target_ulong address, static void raise_mmu_exception(CPURISCVState *env, target_ulong address,
MMUAccessType access_type) MMUAccessType access_type)
{ {
CPUState *cs = CPU(riscv_env_get_cpu(env)); CPUState *cs = env_cpu(env);
int page_fault_exceptions = int page_fault_exceptions =
(env->priv_ver >= PRIV_VERSION_1_10_0) && (env->priv_ver >= PRIV_VERSION_1_10_0) &&
get_field(env->satp, SATP_MODE) != VM_1_10_MBARE; get_field(env->satp, SATP_MODE) != VM_1_10_MBARE;
......
...@@ -296,7 +296,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) ...@@ -296,7 +296,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
if (env->priv_ver <= PRIV_VERSION_1_09_1) { if (env->priv_ver <= PRIV_VERSION_1_09_1) {
if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP |
MSTATUS_MPRV | MSTATUS_SUM | MSTATUS_VM)) { MSTATUS_MPRV | MSTATUS_SUM | MSTATUS_VM)) {
tlb_flush(CPU(riscv_env_get_cpu(env))); tlb_flush(env_cpu(env));
} }
mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE | mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE |
MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM | MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM |
...@@ -307,7 +307,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val) ...@@ -307,7 +307,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
if (env->priv_ver >= PRIV_VERSION_1_10_0) { if (env->priv_ver >= PRIV_VERSION_1_10_0) {
if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV | if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV |
MSTATUS_MPRV | MSTATUS_SUM)) { MSTATUS_MPRV | MSTATUS_SUM)) {
tlb_flush(CPU(riscv_env_get_cpu(env))); tlb_flush(env_cpu(env));
} }
mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE | mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE |
MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM | MSTATUS_SPP | MSTATUS_FS | MSTATUS_MPRV | MSTATUS_SUM |
...@@ -382,7 +382,7 @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val) ...@@ -382,7 +382,7 @@ static int write_misa(CPURISCVState *env, int csrno, target_ulong val)
/* flush translation cache */ /* flush translation cache */
if (val != env->misa) { if (val != env->misa) {
tb_flush(CPU(riscv_env_get_cpu(env))); tb_flush(env_cpu(env));
} }
env->misa = val; env->misa = val;
...@@ -549,7 +549,7 @@ static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val) ...@@ -549,7 +549,7 @@ static int write_mbadaddr(CPURISCVState *env, int csrno, target_ulong val)
static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value,
target_ulong new_value, target_ulong write_mask) target_ulong new_value, target_ulong write_mask)
{ {
RISCVCPU *cpu = riscv_env_get_cpu(env); RISCVCPU *cpu = env_archcpu(env);
/* Allow software control of delegable interrupts not claimed by hardware */ /* Allow software control of delegable interrupts not claimed by hardware */
target_ulong mask = write_mask & delegable_ints & ~env->miclaim; target_ulong mask = write_mask & delegable_ints & ~env->miclaim;
uint32_t old_mip; uint32_t old_mip;
...@@ -712,7 +712,7 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) ...@@ -712,7 +712,7 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
return 0; return 0;
} }
if (env->priv_ver <= PRIV_VERSION_1_09_1 && (val ^ env->sptbr)) { if (env->priv_ver <= PRIV_VERSION_1_09_1 && (val ^ env->sptbr)) {
tlb_flush(CPU(riscv_env_get_cpu(env))); tlb_flush(env_cpu(env));
env->sptbr = val & (((target_ulong) env->sptbr = val & (((target_ulong)
1 << (TARGET_PHYS_ADDR_SPACE_BITS - PGSHIFT)) - 1); 1 << (TARGET_PHYS_ADDR_SPACE_BITS - PGSHIFT)) - 1);
} }
...@@ -724,7 +724,7 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) ...@@ -724,7 +724,7 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val)
return -1; return -1;
} else { } else {
if((val ^ env->satp) & SATP_ASID) { if((val ^ env->satp) & SATP_ASID) {
tlb_flush(CPU(riscv_env_get_cpu(env))); tlb_flush(env_cpu(env));
} }
env->satp = val; env->satp = val;
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env, void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env,
uint32_t exception, uintptr_t pc) uint32_t exception, uintptr_t pc)
{ {
CPUState *cs = CPU(riscv_env_get_cpu(env)); CPUState *cs = env_cpu(env);
qemu_log_mask(CPU_LOG_INT, "%s: %d\n", __func__, exception); qemu_log_mask(CPU_LOG_INT, "%s: %d\n", __func__, exception);
cs->exception_index = exception; cs->exception_index = exception;
cpu_loop_exit_restore(cs, pc); cpu_loop_exit_restore(cs, pc);
...@@ -128,7 +128,7 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb) ...@@ -128,7 +128,7 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb)
void helper_wfi(CPURISCVState *env) void helper_wfi(CPURISCVState *env)
{ {
CPUState *cs = CPU(riscv_env_get_cpu(env)); CPUState *cs = env_cpu(env);
if (env->priv == PRV_S && if (env->priv == PRV_S &&
env->priv_ver >= PRIV_VERSION_1_10_0 && env->priv_ver >= PRIV_VERSION_1_10_0 &&
...@@ -143,8 +143,7 @@ void helper_wfi(CPURISCVState *env) ...@@ -143,8 +143,7 @@ void helper_wfi(CPURISCVState *env)
void helper_tlb_flush(CPURISCVState *env) void helper_tlb_flush(CPURISCVState *env)
{ {
RISCVCPU *cpu = riscv_env_get_cpu(env); CPUState *cs = env_cpu(env);
CPUState *cs = CPU(cpu);
if (!(env->priv >= PRV_S) || if (!(env->priv >= PRV_S) ||
(env->priv == PRV_S && (env->priv == PRV_S &&
env->priv_ver >= PRIV_VERSION_1_10_0 && env->priv_ver >= PRIV_VERSION_1_10_0 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册