Add get_gid(), get_tgid() and tlb_entry_matches_gid(), to get and use gid in
lvz functions.

Signed-off-by: SignKirigami <[email protected]>
Signed-off-by: Hengyu Yu <[email protected]>
---
 target/loongarch/cpu.h            | 13 +++++++++++++
 target/loongarch/tcg/tlb_helper.c |  5 +++++
 2 files changed, 18 insertions(+)

diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 42305e4b05..9987d47734 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -588,6 +588,19 @@ static inline bool will_return_to_guest(CPULoongArchState 
*env)
     return FIELD_EX64(get_sys(env, VM_LEVEL0)->CSR_GSTAT, CSR_GSTAT, PVM);
 }
 
+static inline uint8_t get_gid(CPULoongArchState *env, int vm_level)
+{
+    CPUSysState *host = get_sys(env, VM_LEVEL0);
+
+    if (vm_level) {
+        return FIELD_EX64(host->CSR_GSTAT, CSR_GSTAT, GID);
+    }
+    if (FIELD_EX64(host->CSR_GTLBC, CSR_GTLBC, USETGID)) {
+        return FIELD_EX64(host->CSR_GTLBC, CSR_GTLBC, TGID);
+    }
+    return 0;
+}
+
 static inline CPUTimerState *env_timer(CPULoongArchState *env)
 {
     return &env->sys_states[0].timer_state;
diff --git a/target/loongarch/tcg/tlb_helper.c 
b/target/loongarch/tcg/tlb_helper.c
index 33d5e04eb4..178f55a67e 100644
--- a/target/loongarch/tcg/tlb_helper.c
+++ b/target/loongarch/tcg/tlb_helper.c
@@ -34,6 +34,11 @@ static bool tlb_match_asid(bool global, int asid, int 
tlb_asid)
     return !global && tlb_asid == asid;
 }
 
+static inline bool tlb_entry_matches_gid(const LoongArchTLB *tlb, uint8_t gid)
+{
+    return FIELD_EX64(tlb->tlb_misc, TLB_MISC, GID) == gid;
+}
+
 bool check_ps(CPULoongArchState *env, uint8_t tlb_ps)
 {
     CPUSysState *sys = env_sys(env);
-- 
2.56.0


Reply via email to