On 2025/7/26 上午9:45, Richard Henderson wrote:
On 7/24/25 15:37, Bibo Mao wrote:
With tlb_flush_range_by_mmuidx(), the virtual address is 64 bit.
However on LoongArch TLB emulation system, virtual address is
48 bit. It is necessary to convert 48 bit address to 64 bit when
flush tlb, also fix address calculation issue with odd page.

Signed-off-by: Bibo Mao <maob...@loongson.cn>
---
  target/loongarch/tcg/tlb_helper.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c
index 715c5a20da..61cc19610e 100644
--- a/target/loongarch/tcg/tlb_helper.c
+++ b/target/loongarch/tcg/tlb_helper.c
@@ -96,6 +96,15 @@ static void raise_mmu_exception(CPULoongArchState *env, target_ulong address,
     }
  }
+/* Convert 48 bit virtual address from LoongArch TLB to 64 bit VA */
+static inline target_ulong __vaddr(target_ulong addr)
+{
+    target_ulong high;
+
+    high = -(addr >> (TARGET_VIRT_ADDR_SPACE_BITS - 1));
+    return addr + (high << TARGET_VIRT_ADDR_SPACE_BITS);
+}

Don't use __ symbols.
Also, this function is

     sextract64(addr, 0, TARGET_VIRT_ADDR_SPACE_BITS - 1)
yeap, sextract64 is simpler and effective. How about loongarch_vppn_to_vaddr compared with __vaddr about function name?

Regards
Bibo Mao


r~


Reply via email to