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 | 21 +++++++++++++++++++++ target/loongarch/tcg/tlb_helper.c | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index 3e3ae2bfa7..a42c5fe170 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -583,6 +583,27 @@ 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) +{ + return FIELD_EX64(get_sys(env, VM_LEVEL0)->CSR_GSTAT, CSR_GSTAT, GID); +} + +static inline uint8_t get_tgid(CPULoongArchState *env) +{ + CPUSysState *host = get_sys(env, VM_LEVEL0); + + if (env_vm_level(env) == VM_LEVEL1) { + return get_gid(env); + } + + if (FIELD_EX64(host->CSR_GTLBC, CSR_GTLBC, USETGID)) { + return FIELD_EX64(host->CSR_GTLBC, CSR_GTLBC, TGID); + } else if (will_return_to_guest(env)) { + return get_gid(env); + } + 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 d1f1d233fd..821aa26328 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -35,6 +35,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.55.0
