mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-25 11:46:58 +00:00
target-arm: Move aarch64_cpu_do_interrupt() to helper.c
Move the aarch64_cpu_do_interrupt() function to helper.c. We want to be able to call this from code that isn't AArch64-only, and the move allows us to avoid awkward #ifdeffery at the callsite. Backports commit f3a9b6945cbbb23f3a70da14e9ffdf1e60c580a8 from qemu
This commit is contained in:
parent
c06519a2fd
commit
e1925bb5fb
|
@ -243,8 +243,8 @@ void arm_gt_stimer_cb(void *opaque);
|
|||
#ifdef TARGET_AARCH64
|
||||
int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
|
||||
int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
|
||||
#endif
|
||||
|
||||
void aarch64_cpu_do_interrupt(CPUState *cs);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -512,100 +512,3 @@ uint64_t HELPER(crc32c_64)(uint64_t acc, uint64_t val, uint32_t bytes)
|
|||
/* Linux crc32c converts the output to one's complement. */
|
||||
return crc32c(acc, buf, bytes) ^ 0xffffffff;
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
/* Handle a CPU exception. */
|
||||
void aarch64_cpu_do_interrupt(CPUState *cs)
|
||||
{
|
||||
CPUARMState *env = cs->env_ptr;
|
||||
ARMCPU *cpu = ARM_CPU(env->uc, cs);
|
||||
unsigned int new_el = env->exception.target_el;
|
||||
target_ulong addr = env->cp15.vbar_el[new_el];
|
||||
unsigned int new_mode = aarch64_pstate_mode(new_el, true);
|
||||
|
||||
if (arm_current_el(env) < new_el) {
|
||||
if (env->aarch64) {
|
||||
addr += 0x400;
|
||||
} else {
|
||||
addr += 0x600;
|
||||
}
|
||||
} else if (pstate_read(env) & PSTATE_SP) {
|
||||
addr += 0x200;
|
||||
}
|
||||
|
||||
arm_log_exception(cs->exception_index);
|
||||
qemu_log_mask(CPU_LOG_INT, "...from EL%d to EL%d\n", arm_current_el(env),
|
||||
new_el);
|
||||
if (qemu_loglevel_mask(CPU_LOG_INT)
|
||||
&& !excp_is_internal(cs->exception_index)) {
|
||||
qemu_log_mask(CPU_LOG_INT, "...with ESR 0x%" PRIx32 "\n",
|
||||
env->exception.syndrome);
|
||||
}
|
||||
|
||||
if (arm_is_psci_call(cpu, cs->exception_index)) {
|
||||
arm_handle_psci_call(cpu);
|
||||
qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cs->exception_index) {
|
||||
case EXCP_PREFETCH_ABORT:
|
||||
case EXCP_DATA_ABORT:
|
||||
env->cp15.far_el[new_el] = env->exception.vaddress;
|
||||
qemu_log_mask(CPU_LOG_INT, "...with FAR 0x%" PRIx64 "\n",
|
||||
env->cp15.far_el[new_el]);
|
||||
/* fall through */
|
||||
case EXCP_BKPT:
|
||||
case EXCP_UDEF:
|
||||
case EXCP_SWI:
|
||||
case EXCP_HVC:
|
||||
case EXCP_HYP_TRAP:
|
||||
case EXCP_SMC:
|
||||
env->cp15.esr_el[new_el] = env->exception.syndrome;
|
||||
break;
|
||||
case EXCP_IRQ:
|
||||
case EXCP_VIRQ:
|
||||
addr += 0x80;
|
||||
break;
|
||||
case EXCP_FIQ:
|
||||
case EXCP_VFIQ:
|
||||
addr += 0x100;
|
||||
break;
|
||||
case EXCP_SEMIHOST:
|
||||
/* UNICORN: Commented out
|
||||
qemu_log_mask(CPU_LOG_INT,
|
||||
"...handling as semihosting call 0x%" PRIx64 "\n",
|
||||
env->xregs[0]);
|
||||
env->xregs[0] = do_arm_semihosting(env);*/
|
||||
return;
|
||||
default:
|
||||
cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index);
|
||||
}
|
||||
|
||||
if (is_a64(env)) {
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = pstate_read(env);
|
||||
aarch64_save_sp(env, arm_current_el(env));
|
||||
env->elr_el[new_el] = env->pc;
|
||||
} else {
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = cpsr_read(env);
|
||||
if (!env->thumb) {
|
||||
env->cp15.esr_el[new_el] |= 1 << 25;
|
||||
}
|
||||
env->elr_el[new_el] = env->regs[15];
|
||||
|
||||
aarch64_sync_32_to_64(env);
|
||||
|
||||
env->condexec_bits = 0;
|
||||
}
|
||||
qemu_log_mask(CPU_LOG_INT, "...with ELR 0x%" PRIx64 "\n",
|
||||
env->elr_el[new_el]);
|
||||
|
||||
pstate_write(env, PSTATE_DAIF | new_mode);
|
||||
env->aarch64 = 1;
|
||||
aarch64_restore_sp(env, new_el);
|
||||
|
||||
env->pc = addr;
|
||||
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -5245,6 +5245,100 @@ void arm_cpu_do_interrupt(CPUState *cs)
|
|||
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
||||
}
|
||||
|
||||
/* Handle a CPU exception. */
|
||||
void aarch64_cpu_do_interrupt(CPUState *cs)
|
||||
{
|
||||
CPUARMState *env = cs->env_ptr;
|
||||
ARMCPU *cpu = ARM_CPU(env->uc, cs);
|
||||
unsigned int new_el = env->exception.target_el;
|
||||
target_ulong addr = env->cp15.vbar_el[new_el];
|
||||
unsigned int new_mode = aarch64_pstate_mode(new_el, true);
|
||||
|
||||
if (arm_current_el(env) < new_el) {
|
||||
if (env->aarch64) {
|
||||
addr += 0x400;
|
||||
} else {
|
||||
addr += 0x600;
|
||||
}
|
||||
} else if (pstate_read(env) & PSTATE_SP) {
|
||||
addr += 0x200;
|
||||
}
|
||||
|
||||
arm_log_exception(cs->exception_index);
|
||||
qemu_log_mask(CPU_LOG_INT, "...from EL%d to EL%d\n", arm_current_el(env),
|
||||
new_el);
|
||||
if (qemu_loglevel_mask(CPU_LOG_INT)
|
||||
&& !excp_is_internal(cs->exception_index)) {
|
||||
qemu_log_mask(CPU_LOG_INT, "...with ESR 0x%" PRIx32 "\n",
|
||||
env->exception.syndrome);
|
||||
}
|
||||
|
||||
if (arm_is_psci_call(cpu, cs->exception_index)) {
|
||||
arm_handle_psci_call(cpu);
|
||||
qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cs->exception_index) {
|
||||
case EXCP_PREFETCH_ABORT:
|
||||
case EXCP_DATA_ABORT:
|
||||
env->cp15.far_el[new_el] = env->exception.vaddress;
|
||||
qemu_log_mask(CPU_LOG_INT, "...with FAR 0x%" PRIx64 "\n",
|
||||
env->cp15.far_el[new_el]);
|
||||
/* fall through */
|
||||
case EXCP_BKPT:
|
||||
case EXCP_UDEF:
|
||||
case EXCP_SWI:
|
||||
case EXCP_HVC:
|
||||
case EXCP_HYP_TRAP:
|
||||
case EXCP_SMC:
|
||||
env->cp15.esr_el[new_el] = env->exception.syndrome;
|
||||
break;
|
||||
case EXCP_IRQ:
|
||||
case EXCP_VIRQ:
|
||||
addr += 0x80;
|
||||
break;
|
||||
case EXCP_FIQ:
|
||||
case EXCP_VFIQ:
|
||||
addr += 0x100;
|
||||
break;
|
||||
case EXCP_SEMIHOST:
|
||||
/* UNICORN: Commented out
|
||||
qemu_log_mask(CPU_LOG_INT,
|
||||
"...handling as semihosting call 0x%" PRIx64 "\n",
|
||||
env->xregs[0]);
|
||||
env->xregs[0] = do_arm_semihosting(env);*/
|
||||
return;
|
||||
default:
|
||||
cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index);
|
||||
}
|
||||
|
||||
if (is_a64(env)) {
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = pstate_read(env);
|
||||
aarch64_save_sp(env, arm_current_el(env));
|
||||
env->elr_el[new_el] = env->pc;
|
||||
} else {
|
||||
env->banked_spsr[aarch64_banked_spsr_index(new_el)] = cpsr_read(env);
|
||||
if (!env->thumb) {
|
||||
env->cp15.esr_el[new_el] |= 1 << 25;
|
||||
}
|
||||
env->elr_el[new_el] = env->regs[15];
|
||||
|
||||
aarch64_sync_32_to_64(env);
|
||||
|
||||
env->condexec_bits = 0;
|
||||
}
|
||||
qemu_log_mask(CPU_LOG_INT, "...with ELR 0x%" PRIx64 "\n",
|
||||
env->elr_el[new_el]);
|
||||
|
||||
pstate_write(env, PSTATE_DAIF | new_mode);
|
||||
env->aarch64 = 1;
|
||||
aarch64_restore_sp(env, new_el);
|
||||
|
||||
env->pc = addr;
|
||||
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
||||
}
|
||||
|
||||
/* Return the exception level which controls this address translation regime */
|
||||
static inline uint32_t regime_el(CPUARMState *env, ARMMMUIdx mmu_idx)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue