|
From: | gaosong |
Subject: | Re: [PATCH v15 8/9] target/loongarch: Adjust functions and structure to support user-mode |
Date: | Mon, 13 Jun 2022 11:50:03 +0800 |
User-agent: | Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
Thank you for your advice.void helper_asrtle_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
{
if (rj > rk) {
env->badvaddr = env->pc;
do_raise_exception(env, EXCCODE_BCE, env->badvaddr);
}
}
Well, not quite. The value of env->pc is not current; it is too expensive to update all of the time. We need to recover that value by using TCG unwinding, e.g.:
if (rj > rk) {
cpu_restore_state(env_cpu(env), GETPC(), true);
env->badvaddr = env->pc;
However,
do_raise_exception(env, EXCCODE_ADEM, GETPC());
expects to do it's own cpu_restore_state via cpu_loop_exit_restore(), and we should not do that twice.
Therefore, since the value of badvaddr is something that we can more easily recover later than earlier, we should move the setting of badvaddr for ADEM to loongarch_cpu_do_interrupt():
case EXCCODE_ADEM:
env->badvaddr = env->pc;
cause = cs->exception_index;
break;
It is probably worthwhile to check how many other exceptions should be having the same effect.
void helper_asrtle_d(CPULoongArchState *env, target_ulong rj,
target_ulong rk)
{
+ CPUState *cs = env_cpu(env);
+
if (rj > rk) {
- env->badaddr = env->pc;
- do_raise_exception(env, EXCCODE_BCE, env->badaddr);
+ cpu_restore_state(cs, GETPC(), true);
+ cs->exception_index = EXCCODE_BCE;
+ cpu_loop_exit(cs);
}
}
cpu.c
case EXCCODE_ADEM:
+ case EXCCODE_BCE:
case EXCCODE_SYS:
case EXCCODE_BRK:
+ case EXCCODE_INE:
+ case EXCCODE_IPE:
+ case EXCCODE_FPE:
+ env->badvaddr = env->pc;
+ QEMU_FALLTHROUGH;
case EXCCODE_PIL:
case EXCCODE_PIS:
case EXCCODE_PME:
case EXCCODE_PNR:
case EXCCODE_PNX:
case EXCCODE_PPI:
- case EXCCODE_INE:
- case EXCCODE_IPE:
- case EXCCODE_FPE:
cause = cs->exception_index;
break;
[Prev in Thread] | Current Thread | [Next in Thread] |