diff mbox

[22/29] target-sparc: implement auto-demapping for UA2005 CPUs

Message ID 1475316333-9776-23-git-send-email-atar4qemu@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Artyom Tarasenko Oct. 1, 2016, 10:05 a.m. UTC
Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com>
---
 target-sparc/ldst_helper.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Richard Henderson Oct. 11, 2016, 2:17 p.m. UTC | #1
On 10/01/2016 05:05 AM, Artyom Tarasenko wrote:
> +                uint64_t size = 1024ULL * (8 << 3 * TTE_PGSIZE(tlb[i].tte));

Your previous expression, 8192 << 3 * TTE_PGSIZE is clearer.  Perhaps this 
itself should be extracted as a macro?

> +                if ((new_vaddr == vaddr) || ((new_vaddr < (vaddr + size))
> +                    && (vaddr < (new_vaddr + new_size)))) {

Please drop the unnecessary parenthesis and line up the expressions properly,

   if (new_vaddr == vaddr
       || (new_vaddr < vaddr + size
           && vaddr < new_vaddr + new_size)) {

so that one can tell at a glance how the subexpressions are nested.


r~
diff mbox

Patch

diff --git a/target-sparc/ldst_helper.c b/target-sparc/ldst_helper.c
index a85552e..c27e668 100644
--- a/target-sparc/ldst_helper.c
+++ b/target-sparc/ldst_helper.c
@@ -210,6 +210,27 @@  static void replace_tlb_1bit_lru(SparcTLBEntry *tlb,
 {
     unsigned int i, replace_used;
 
+    if (cpu_has_hypervisor(env1)) {
+        uint64_t new_vaddr = tlb_tag & ~0x1fffULL;
+        uint64_t new_size = 1024ULL * (8 << 3 * TTE_PGSIZE(tlb_tte));
+        uint32_t new_ctx = tlb_tag & 0x1fffU;
+        for (i = 0; i < 64; i++) {
+            uint32_t ctx = tlb[i].tag & 0x1fffU;
+            /* check if new mapping overlaps an existing one */
+            if (new_ctx == ctx) {
+                uint64_t vaddr = tlb[i].tag & ~0x1fffULL;
+                uint64_t size = 1024ULL * (8 << 3 * TTE_PGSIZE(tlb[i].tte));
+                if ((new_vaddr == vaddr) || ((new_vaddr < (vaddr + size))
+                    && (vaddr < (new_vaddr + new_size)))) {
+                    DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i, vaddr,
+                                new_vaddr);
+                    replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
+                    return;
+                }
+            }
+
+        }
+    }
     /* Try replacing invalid entry */
     for (i = 0; i < 64; i++) {
         if (!TTE_IS_VALID(tlb[i].tte)) {