On 6/10/22 20:10, gaosong wrote:
pc             0x120000638         0x120000638 <main+32>
badvaddr       0x120000638         0x120000638 <main+32>
...
So badvaddr is the PC,

Yes.

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.


r~

Reply via email to