在 2025/9/6 下午3:04, Bibo Mao 写道:
With function loongarch_tlb_search_cb(), change return value type from
bool type to pointer LoongArchTLB *, the pointer type can be use directly
in future.

Signed-off-by: Bibo Mao <maob...@loongson.cn>
---
  target/loongarch/tcg/tlb_helper.c | 22 ++++++++++++++--------
  1 file changed, 14 insertions(+), 8 deletions(-)
Reviewed-by: Song Gao <gaos...@loongson.cn>

Thanks.
Song Gao
diff --git a/target/loongarch/tcg/tlb_helper.c 
b/target/loongarch/tcg/tlb_helper.c
index 5b78146769..c7f30eaf15 100644
--- a/target/loongarch/tcg/tlb_helper.c
+++ b/target/loongarch/tcg/tlb_helper.c
@@ -203,8 +203,9 @@ static uint32_t get_random_tlb(uint32_t low, uint32_t high)
   * field in tlb entry contains bit[47:13], so need adjust.
   * virt_vpn = vaddr[47:13]
   */
-static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr,
-                                    int *index, int csr_asid, tlb_match func)
+static LoongArchTLB *loongarch_tlb_search_cb(CPULoongArchState *env,
+                                             vaddr vaddr, int csr_asid,
+                                             tlb_match func)
  {
      LoongArchTLB *tlb;
      uint16_t tlb_asid, stlb_idx;
@@ -229,8 +230,7 @@ static bool loongarch_tlb_search_cb(CPULoongArchState *env, 
vaddr vaddr,
if (func(tlb_g, csr_asid, tlb_asid) &&
                  (vpn == (tlb_vppn >> compare_shift))) {
-                *index = i * 256 + stlb_idx;
-                return true;
+                return tlb;
              }
          }
      }
@@ -248,12 +248,11 @@ static bool loongarch_tlb_search_cb(CPULoongArchState 
*env, vaddr vaddr,
              vpn = (vaddr & TARGET_VIRT_MASK) >> (tlb_ps + 1);
              if (func(tlb_g, csr_asid, tlb_asid) &&
                  (vpn == (tlb_vppn >> compare_shift))) {
-                *index = i;
-                return true;
+                return tlb;
              }
          }
      }
-    return false;
+    return NULL;
  }
static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr,
@@ -261,10 +260,17 @@ static bool loongarch_tlb_search(CPULoongArchState *env, 
vaddr vaddr,
  {
      int csr_asid;
      tlb_match func;
+    LoongArchTLB *tlb;
func = tlb_match_any;
      csr_asid = FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID);
-    return loongarch_tlb_search_cb(env, vaddr, index, csr_asid, func);
+    tlb = loongarch_tlb_search_cb(env, vaddr, csr_asid, func);
+    if (tlb) {
+        *index = tlb - env->tlb;
+        return true;
+    }
+
+    return false;
  }
void helper_tlbsrch(CPULoongArchState *env)


Reply via email to