[PATCH 2/3] target/loongarch: Fix CSR STLBPS register write emulation

Bibo Mao posted 3 patches 7 months, 3 weeks ago
Maintainers: Song Gao <gaosong@loongson.cn>
[PATCH 2/3] target/loongarch: Fix CSR STLBPS register write emulation
Posted by Bibo Mao 7 months, 3 weeks ago
Function helper_csrwr_stlbps() is emulation with CSR STLBPS register
write operation. However there is only parameter checking action, and
no register updating action. Here update value of CSR_STLBPS when
parameter passes to check.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 target/loongarch/tcg/csr_helper.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c
index 46d331ce8a..28b1bb86bd 100644
--- a/target/loongarch/tcg/csr_helper.c
+++ b/target/loongarch/tcg/csr_helper.c
@@ -29,7 +29,11 @@ target_ulong helper_csrwr_stlbps(CPULoongArchState *env, target_ulong val)
     if (!check_ps(env, tlb_ps)) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "Attempted set ps %d\n", tlb_ps);
+    } else {
+        /* Only update PS field, reserved bit keeps zero */
+        env->CSR_STLBPS = FIELD_DP64(old_v, CSR_STLBPS, PS, tlb_ps);
     }
+
     return old_v;
 }
 
-- 
2.39.3
Re: [PATCH 2/3] target/loongarch: Fix CSR STLBPS register write emulation
Posted by gaosong 7 months, 1 week ago
在 2025/6/18 下午2:26, Bibo Mao 写道:
> Function helper_csrwr_stlbps() is emulation with CSR STLBPS register
> write operation. However there is only parameter checking action, and
> no register updating action. Here update value of CSR_STLBPS when
> parameter passes to check.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   target/loongarch/tcg/csr_helper.c | 4 ++++
>   1 file changed, 4 insertions(+)
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c
> index 46d331ce8a..28b1bb86bd 100644
> --- a/target/loongarch/tcg/csr_helper.c
> +++ b/target/loongarch/tcg/csr_helper.c
> @@ -29,7 +29,11 @@ target_ulong helper_csrwr_stlbps(CPULoongArchState *env, target_ulong val)
>       if (!check_ps(env, tlb_ps)) {
>           qemu_log_mask(LOG_GUEST_ERROR,
>                         "Attempted set ps %d\n", tlb_ps);
> +    } else {
> +        /* Only update PS field, reserved bit keeps zero */
> +        env->CSR_STLBPS = FIELD_DP64(old_v, CSR_STLBPS, PS, tlb_ps);
>       }
> +
>       return old_v;
>   }
>