mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-09 00:07:57 -06:00
target/riscv: Convert to CPUClass::tlb_fill
Note that env->pc is removed from the qemu_log as that value is garbage. The PC isn't recovered until cpu_restore_state, called from cpu_loop_exit_restore, called from riscv_raise_exception. Cc: qemu-riscv@nongnu.org Cc: Palmer Dabbelt <palmer@sifive.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
351bc97ecf
commit
8a4ca3c10a
3 changed files with 26 additions and 30 deletions
|
@ -355,14 +355,13 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
|
||||||
#endif
|
#endif
|
||||||
cc->gdb_stop_before_watchpoint = true;
|
cc->gdb_stop_before_watchpoint = true;
|
||||||
cc->disas_set_info = riscv_cpu_disas_set_info;
|
cc->disas_set_info = riscv_cpu_disas_set_info;
|
||||||
#ifdef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
cc->handle_mmu_fault = riscv_cpu_handle_mmu_fault;
|
|
||||||
#else
|
|
||||||
cc->do_unaligned_access = riscv_cpu_do_unaligned_access;
|
cc->do_unaligned_access = riscv_cpu_do_unaligned_access;
|
||||||
cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;
|
cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_TCG
|
#ifdef CONFIG_TCG
|
||||||
cc->tcg_initialize = riscv_translate_init;
|
cc->tcg_initialize = riscv_translate_init;
|
||||||
|
cc->tlb_fill = riscv_cpu_tlb_fill;
|
||||||
#endif
|
#endif
|
||||||
/* For now, mark unmigratable: */
|
/* For now, mark unmigratable: */
|
||||||
cc->vmsd = &vmstate_riscv_cpu;
|
cc->vmsd = &vmstate_riscv_cpu;
|
||||||
|
|
|
@ -261,8 +261,9 @@ hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
|
||||||
void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
||||||
MMUAccessType access_type, int mmu_idx,
|
MMUAccessType access_type, int mmu_idx,
|
||||||
uintptr_t retaddr);
|
uintptr_t retaddr);
|
||||||
int riscv_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int size,
|
bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
||||||
int rw, int mmu_idx);
|
MMUAccessType access_type, int mmu_idx,
|
||||||
|
bool probe, uintptr_t retaddr);
|
||||||
char *riscv_isa_string(RISCVCPU *cpu);
|
char *riscv_isa_string(RISCVCPU *cpu);
|
||||||
void riscv_cpu_list(void);
|
void riscv_cpu_list(void);
|
||||||
|
|
||||||
|
|
|
@ -379,53 +379,49 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
||||||
riscv_raise_exception(env, cs->exception_index, retaddr);
|
riscv_raise_exception(env, cs->exception_index, retaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called by qemu's softmmu to fill the qemu tlb */
|
|
||||||
void tlb_fill(CPUState *cs, target_ulong addr, int size,
|
void tlb_fill(CPUState *cs, target_ulong addr, int size,
|
||||||
MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
|
MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
|
||||||
{
|
{
|
||||||
int ret;
|
riscv_cpu_tlb_fill(cs, addr, size, access_type, mmu_idx, false, retaddr);
|
||||||
ret = riscv_cpu_handle_mmu_fault(cs, addr, size, access_type, mmu_idx);
|
|
||||||
if (ret == TRANSLATE_FAIL) {
|
|
||||||
RISCVCPU *cpu = RISCV_CPU(cs);
|
|
||||||
CPURISCVState *env = &cpu->env;
|
|
||||||
riscv_raise_exception(env, cs->exception_index, retaddr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int riscv_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size,
|
bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
||||||
int rw, int mmu_idx)
|
MMUAccessType access_type, int mmu_idx,
|
||||||
|
bool probe, uintptr_t retaddr)
|
||||||
{
|
{
|
||||||
|
#ifndef CONFIG_USER_ONLY
|
||||||
RISCVCPU *cpu = RISCV_CPU(cs);
|
RISCVCPU *cpu = RISCV_CPU(cs);
|
||||||
CPURISCVState *env = &cpu->env;
|
CPURISCVState *env = &cpu->env;
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
hwaddr pa = 0;
|
hwaddr pa = 0;
|
||||||
int prot;
|
int prot;
|
||||||
#endif
|
|
||||||
int ret = TRANSLATE_FAIL;
|
int ret = TRANSLATE_FAIL;
|
||||||
|
|
||||||
qemu_log_mask(CPU_LOG_MMU,
|
qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n",
|
||||||
"%s pc " TARGET_FMT_lx " ad %" VADDR_PRIx " rw %d mmu_idx \
|
__func__, address, access_type, mmu_idx);
|
||||||
%d\n", __func__, env->pc, address, rw, mmu_idx);
|
|
||||||
|
ret = get_physical_address(env, &pa, &prot, address, access_type, mmu_idx);
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
ret = get_physical_address(env, &pa, &prot, address, rw, mmu_idx);
|
|
||||||
qemu_log_mask(CPU_LOG_MMU,
|
qemu_log_mask(CPU_LOG_MMU,
|
||||||
"%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
|
"%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
|
||||||
" prot %d\n", __func__, address, ret, pa, prot);
|
" prot %d\n", __func__, address, ret, pa, prot);
|
||||||
|
|
||||||
if (riscv_feature(env, RISCV_FEATURE_PMP) &&
|
if (riscv_feature(env, RISCV_FEATURE_PMP) &&
|
||||||
!pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << rw)) {
|
!pmp_hart_has_privs(env, pa, TARGET_PAGE_SIZE, 1 << access_type)) {
|
||||||
ret = TRANSLATE_FAIL;
|
ret = TRANSLATE_FAIL;
|
||||||
}
|
}
|
||||||
if (ret == TRANSLATE_SUCCESS) {
|
if (ret == TRANSLATE_SUCCESS) {
|
||||||
tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK,
|
tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK,
|
||||||
prot, mmu_idx, TARGET_PAGE_SIZE);
|
prot, mmu_idx, TARGET_PAGE_SIZE);
|
||||||
} else if (ret == TRANSLATE_FAIL) {
|
return true;
|
||||||
raise_mmu_exception(env, address, rw);
|
} else if (probe) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
raise_mmu_exception(env, address, access_type);
|
||||||
|
riscv_raise_exception(env, cs->exception_index, retaddr);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
switch (rw) {
|
switch (access_type) {
|
||||||
case MMU_INST_FETCH:
|
case MMU_INST_FETCH:
|
||||||
cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
|
cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT;
|
||||||
break;
|
break;
|
||||||
|
@ -436,8 +432,8 @@ int riscv_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size,
|
||||||
cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
|
cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
cpu_loop_exit_restore(cs, retaddr);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue