void validate_csr(CPURISCVState *env, uint64_t which, uint64_t write, uint64_t new_pc) { unsigned my_priv = get_field(env->csr[NEW_CSR_MSTATUS], MSTATUS_PRV); unsigned csr_priv = get_field((which), 0x300); unsigned csr_read_only = get_field((which), 0xC00) == 3; if (((write) && csr_read_only) || (my_priv < csr_priv)) { do_raise_exception_err(env, NEW_RISCV_EXCP_ILLEGAL_INST, new_pc); } return; }
/* called by qemu's softmmu to fill the qemu tlb */ void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx, uintptr_t retaddr) { int ret; ret = riscv_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx); if (ret) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; do_raise_exception_err(env, cs->exception_index, retaddr); } }
static void do_unaligned_access(CPURISCVState *env, target_ulong addr, int rw, int is_user, uintptr_t retaddr) { CPUState *cs = CPU(riscv_env_get_cpu(env)); if (rw & 0x2) { cs->exception_index = RISCV_EXCP_INST_ADDR_MIS; } else if (rw == 0x1) { cs->exception_index = RISCV_EXCP_STORE_ADDR_MIS; env->helper_csr[CSR_BADVADDR] = addr; } else { cs->exception_index = RISCV_EXCP_LOAD_ADDR_MIS; env->helper_csr[CSR_BADVADDR] = addr; } do_raise_exception_err(env, cs->exception_index, 0); }
void riscv_cpu_do_unaligned_access(CPUState *cs, target_ulong addr, int rw, int is_user, uintptr_t retaddr) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; printf("addr: %016lx\n", addr); if (rw & 0x2) { fprintf(stderr, "unaligned inst fetch not handled here\n"); exit(1); } else if (rw == 0x1) { printf("Store\n"); cs->exception_index = NEW_RISCV_EXCP_STORE_AMO_ADDR_MIS; env->csr[NEW_CSR_MBADADDR] = addr; } else { printf("Load\n"); cs->exception_index = NEW_RISCV_EXCP_LOAD_ADDR_MIS; env->csr[NEW_CSR_MBADADDR] = addr; } do_raise_exception_err(env, cs->exception_index, retaddr); }
void helper_raise_exception(CPURISCVState *env, uint32_t exception) { do_raise_exception_err(env, exception, 0); }
void helper_raise_exception_mbadaddr(CPURISCVState *env, uint32_t exception, target_ulong bad_pc) { env->csr[NEW_CSR_MBADADDR] = bad_pc; do_raise_exception_err(env, exception, 0); }
void helper_raise_exception_err(CPURISCVState *env, uint32_t exception, target_ulong pc) { do_raise_exception_err(env, exception, pc); }
void helper_raise_exception_debug(CPURISCVState *env) { do_raise_exception_err(env, EXCP_DEBUG, 0); }
void helper_raise_exception(CPURISCVState *env, uint32_t exception) { // TODO which one? do_raise_exception_err(env, exception, 0); // do_raise_exception_err(env, exception, GETPC()); }
void do_raise_exception_direct_err (uint32_t exception, int error_code) { do_restore_state (GETPC ()); do_raise_exception_err (exception, error_code); }
void do_raise_exception (uint32_t exception) { do_raise_exception_err(exception, 0); }