#ifdef CONFIG_TCG
env->fcsr0_mask = FCSR0_M1 | FCSR0_M2 | FCSR0_M3;
+
+ if (is_la64(env)) {
+ env->hw_pte_mask = MAKE_64BIT_MASK(0, 9) |
+ R_TLBENTRY_64_PPN_MASK |
+ R_TLBENTRY_64_NR_MASK |
+ R_TLBENTRY_64_NX_MASK |
+ R_TLBENTRY_64_RPLV_MASK;
+ } else {
+ env->hw_pte_mask = MAKE_64BIT_MASK(0, 9) |
+ R_TLBENTRY_32_PPN_MASK;
+ }
#endif
env->fcsr0 = 0x0;
cpu_loop_exit_restore(cs, retaddr);
}
+static inline uint64_t loongarch_sanitize_hw_pte(CPULoongArchState *env,
+ uint64_t pte)
+{
+ uint64_t palen_mask = loongarch_palen_mask(env);
+ uint64_t ppn_mask = is_la64(env) ? R_TLBENTRY_64_PPN_MASK : R_TLBENTRY_32_PPN_MASK;
+
+ /*
+ * Keep only architecturally-defined PTE bits. Guests may use some
+ * otherwise-unused bits for software purposes.
+ */
+ pte &= env->hw_pte_mask;
+
+ return (pte & ~ppn_mask) | ((pte & ppn_mask) & palen_mask);
+}
+
target_ulong helper_lddir(CPULoongArchState *env, target_ulong base,
uint32_t level, uint32_t mem_idx)
{
{
CPUState *cs = env_cpu(env);
hwaddr phys, tmp0, ptindex, ptoffset0, ptoffset1;
+ uint64_t pte_raw;
uint64_t badv;
uint64_t ptbase = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTBASE);
uint64_t ptwidth = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTWIDTH);
* and the other is the huge page entry,
* whose bit 6 should be 1.
*/
- base = base & palen_mask;
if (FIELD_EX64(base, TLBENTRY, HUGE)) {
/*
* Gets the huge page level and Gets huge page size.
* when loaded into the tlb,
* so the tlb page size needs to be divided by 2.
*/
- tmp0 = base;
+ tmp0 = loongarch_sanitize_hw_pte(env, base);
if (odd) {
tmp0 += MAKE_64BIT_MASK(ps, 1);
}
} else {
badv = env->CSR_TLBRBADV;
+ base = base & palen_mask;
+
ptindex = (badv >> ptbase) & ((1 << ptwidth) - 1);
ptindex = ptindex & ~0x1; /* clear bit 0 */
ptoffset0 = ptindex << 3;
ptoffset1 = (ptindex + 1) << 3;
phys = base | (odd ? ptoffset1 : ptoffset0);
- tmp0 = ldq_le_phys(cs->as, phys) & palen_mask;
+ pte_raw = ldq_le_phys(cs->as, phys);
+ tmp0 = loongarch_sanitize_hw_pte(env, pte_raw);
ps = ptbase;
}