[PATCH v2 3/3] target/loongarch: Fix exception ADEF/ADEM missing update CSR_BADV

Song Gao posted 3 patches 1 month, 2 weeks ago
Maintainers: Song Gao <gaosong@loongson.cn>
There is a newer version of this series
[PATCH v2 3/3] target/loongarch: Fix exception ADEF/ADEM missing update CSR_BADV
Posted by Song Gao 1 month, 2 weeks ago
Exception ADEM/ADEF need update CSR_BADV, ADEF value from env->pc,
ADEM value from the virtual address.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/tcg/tcg_cpu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
index c05a06eeb5..53e0970797 100644
--- a/target/loongarch/tcg/tcg_cpu.c
+++ b/target/loongarch/tcg/tcg_cpu.c
@@ -109,10 +109,12 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
         }
         QEMU_FALLTHROUGH;
     case EXCCODE_PIF:
-    case EXCCODE_ADEF:
         cause = cs->exception_index;
         update_badinstr = 0;
         break;
+    case EXCCODE_ADEF:
+        update_badinstr = 0;
+        QEMU_FALLTHROUGH;
     case EXCCODE_BCE:
         env->CSR_BADV = env->pc;
         QEMU_FALLTHROUGH;
@@ -225,6 +227,7 @@ static void loongarch_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
 {
     CPULoongArchState *env = cpu_env(cs);
 
+    env->CSR_BADV = addr;
     if (access_type == MMU_INST_FETCH) {
         do_raise_exception(env, EXCCODE_ADEF, retaddr);
     } else {
-- 
2.41.0
Re: [PATCH v2 3/3] target/loongarch: Fix exception ADEF/ADEM missing update CSR_BADV
Posted by Bibo Mao 1 month, 2 weeks ago

On 2025/12/24 上午11:19, Song Gao wrote:
> Exception ADEM/ADEF need update CSR_BADV, ADEF value from env->pc,
> ADEM value from the virtual address.
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   target/loongarch/tcg/tcg_cpu.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c
> index c05a06eeb5..53e0970797 100644
> --- a/target/loongarch/tcg/tcg_cpu.c
> +++ b/target/loongarch/tcg/tcg_cpu.c
> @@ -109,10 +109,12 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
>           }
>           QEMU_FALLTHROUGH;
>       case EXCCODE_PIF:
> -    case EXCCODE_ADEF:
>           cause = cs->exception_index;
>           update_badinstr = 0;
>           break;
> +    case EXCCODE_ADEF:
> +        update_badinstr = 0;
> +        QEMU_FALLTHROUGH;
I think this modification is unnecessary. CSR_BADV is already set with 
exception EXCCODE_ADEF/EXCCODE_ADEM.

Regards
Bibo Mao
>       case EXCCODE_BCE:
>           env->CSR_BADV = env->pc;
>           QEMU_FALLTHROUGH;
> @@ -225,6 +227,7 @@ static void loongarch_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
>   {
>       CPULoongArchState *env = cpu_env(cs);
>   
> +    env->CSR_BADV = addr;
>       if (access_type == MMU_INST_FETCH) {
>           do_raise_exception(env, EXCCODE_ADEF, retaddr);
>       } else {
> 


Re: [PATCH v2 3/3] target/loongarch: Fix exception ADEF/ADEM missing update CSR_BADV
Posted by gaosong 1 month, 2 weeks ago
在 2025/12/24 下午5:42, Bibo Mao 写道:
>
>
> On 2025/12/24 上午11:19, Song Gao wrote:
>> Exception ADEM/ADEF need update CSR_BADV, ADEF value from env->pc,
>> ADEM value from the virtual address.
>>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> ---
>>   target/loongarch/tcg/tcg_cpu.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/target/loongarch/tcg/tcg_cpu.c 
>> b/target/loongarch/tcg/tcg_cpu.c
>> index c05a06eeb5..53e0970797 100644
>> --- a/target/loongarch/tcg/tcg_cpu.c
>> +++ b/target/loongarch/tcg/tcg_cpu.c
>> @@ -109,10 +109,12 @@ static void loongarch_cpu_do_interrupt(CPUState 
>> *cs)
>>           }
>>           QEMU_FALLTHROUGH;
>>       case EXCCODE_PIF:
>> -    case EXCCODE_ADEF:
>>           cause = cs->exception_index;
>>           update_badinstr = 0;
>>           break;
>> +    case EXCCODE_ADEF:
>> +        update_badinstr = 0;
>> +        QEMU_FALLTHROUGH;
> I think this modification is unnecessary. CSR_BADV is already set with 
> exception EXCCODE_ADEF/EXCCODE_ADEM.
>
I will drop this.

Thanks.
Song Gao
> Regards
> Bibo Mao
>>       case EXCCODE_BCE:
>>           env->CSR_BADV = env->pc;
>>           QEMU_FALLTHROUGH;
>> @@ -225,6 +227,7 @@ static void 
>> loongarch_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
>>   {
>>       CPULoongArchState *env = cpu_env(cs);
>>   +    env->CSR_BADV = addr;
>>       if (access_type == MMU_INST_FETCH) {
>>           do_raise_exception(env, EXCCODE_ADEF, retaddr);
>>       } else {
>>