From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGstv-0001K8-K1 for qemu-devel@nongnu.org; Sat, 05 Dec 2009 06:34:11 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGstq-0001HQ-PT for qemu-devel@nongnu.org; Sat, 05 Dec 2009 06:34:11 -0500 Received: from [199.232.76.173] (port=49949 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGstq-0001HN-GK for qemu-devel@nongnu.org; Sat, 05 Dec 2009 06:34:06 -0500 Received: from mail-bw0-f212.google.com ([209.85.218.212]:49552) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGstp-0007cB-IR for qemu-devel@nongnu.org; Sat, 05 Dec 2009 06:34:06 -0500 Received: by bwz4 with SMTP id 4so2645449bwz.2 for ; Sat, 05 Dec 2009 03:34:04 -0800 (PST) Received: from localhost ([127.0.0.1] helo=[192.168.1.2]) by skyserv with esmtp (Exim 4.71) (envelope-from ) id 1NGstm-0003cV-UR for qemu-devel@nongnu.org; Sat, 05 Dec 2009 14:34:02 +0300 From: "Igor V. Kovalenko" Date: Sat, 05 Dec 2009 14:34:02 +0300 Message-ID: <20091205113402.13896.83188.stgit@skyserv> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] sparc64: implement global translation table entries List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Igor V. Kovalenko - match global tte against any context - show global tte in MMU dump Signed-off-by: Igor V. Kovalenko --- target-sparc/cpu.h | 18 ++++++++++++++++ target-sparc/helper.c | 18 +++++++--------- target-sparc/op_helper.c | 53 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h index 2fbe498..275ef53 100644 --- a/target-sparc/cpu.h +++ b/target-sparc/cpu.h @@ -277,10 +277,12 @@ enum { #define TTE_VALID_BIT (1ULL << 63) #define TTE_USED_BIT (1ULL << 41) #define TTE_LOCKED_BIT (1ULL << 6) +#define TTE_GLOBAL_BIT (1ULL << 0) #define TTE_IS_VALID(tte) ((tte) & TTE_VALID_BIT) #define TTE_IS_USED(tte) ((tte) & TTE_USED_BIT) #define TTE_IS_LOCKED(tte) ((tte) & TTE_LOCKED_BIT) +#define TTE_IS_GLOBAL(tte) ((tte) & TTE_GLOBAL_BIT) #define TTE_SET_USED(tte) ((tte) |= TTE_USED_BIT) #define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT) @@ -489,6 +491,22 @@ static inline void cpu_set_cwp(CPUSPARCState *env1, int new_cwp) /* sun4m.c, sun4u.c */ void cpu_check_irqs(CPUSPARCState *env); +#if defined (TARGET_SPARC64) + +static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask) +{ + return (x & mask) == (y & mask); +} + +#define MMU_CONTEXT_BITS 13 +#define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1) + +static inline int tlb_compare_context(const SparcTLBEntry *tlb, uint64_t context) +{ + return compare_masked(context, tlb->tag, MMU_CONTEXT_MASK); +} +#endif + static inline void PUT_PSR(CPUSPARCState *env1, target_ulong val) { env1->psr = val & PSR_ICC; diff --git a/target-sparc/helper.c b/target-sparc/helper.c index a4a879c..89048db 100644 --- a/target-sparc/helper.c +++ b/target-sparc/helper.c @@ -379,11 +379,6 @@ static inline target_phys_addr_t ultrasparc_truncate_physical(uint64_t x) * UltraSparc IIi I/DMMUs */ -static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask) -{ - return (x & mask) == (y & mask); -} - // Returns true if TTE tag is valid and matches virtual address value in context // requires virtual address mask value calculated from TTE entry size static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, @@ -410,7 +405,8 @@ static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, // valid, context match, virtual address match? if (TTE_IS_VALID(tlb->tte) && - compare_masked(context, tlb->tag, 0x1fff) && + (TTE_IS_GLOBAL(tlb->tte) || + tlb_compare_context(tlb, context)) && compare_masked(address, tlb->tag, mask)) { // decode physical address @@ -596,7 +592,7 @@ void dump_mmu(CPUState *env) } if ((env->dtlb[i].tte & 0x8000000000000000ULL) != 0) { fprintf(logfile, "[%02u] VA: %" PRIx64 ", PA: %" PRIx64 - ", %s, %s, %s, %s, ctx %" PRId64 "\n", + ", %s, %s, %s, %s, ctx %" PRId64 "%s\n", i, env->dtlb[i].tag & ~(__UINT64_C(0x1fff)), env->dtlb[i].tte & (__UINT64_C(0x1ffffffe000)), @@ -604,7 +600,8 @@ void dump_mmu(CPUState *env) env->dtlb[i].tte & 0x4? "priv": "user", env->dtlb[i].tte & 0x2? "RW": "RO", env->dtlb[i].tte & 0x40? "locked": "unlocked", - env->dtlb[i].tag & (__UINT64_C(0x1fff))); + env->dtlb[i].tag & (__UINT64_C(0x1fff)), + TTE_IS_GLOBAL(env->dtlb[i].tte) ? " (global)" : ""); } } @@ -630,14 +627,15 @@ void dump_mmu(CPUState *env) } if ((env->itlb[i].tte & 0x8000000000000000ULL) != 0) { fprintf(logfile, "[%02u] VA: %" PRIx64 ", PA: %" PRIx64 - ", %s, %s, %s, ctx %" PRId64 "\n", + ", %s, %s, %s, ctx %" PRId64 "%s\n", i, env->itlb[i].tag & ~(__UINT64_C(0x1fff)), env->itlb[i].tte & (__UINT64_C(0x1ffffffe000)), mask, env->itlb[i].tte & 0x4? "priv": "user", env->itlb[i].tte & 0x40? "locked": "unlocked", - env->itlb[i].tag & (__UINT64_C(0x1fff))); + env->itlb[i].tag & (__UINT64_C(0x1fff)), + TTE_IS_GLOBAL(env->itlb[i].tte) ? " (global)" : ""); } } diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c index af30d78..e3e5780 100644 --- a/target-sparc/op_helper.c +++ b/target-sparc/op_helper.c @@ -116,24 +116,59 @@ static void demap_tlb(SparcTLBEntry *tlb, target_ulong demap_addr, { unsigned int i; target_ulong mask; + uint64_t context; + + int is_demap_context = (demap_addr >> 6) & 1; + + // demap context + switch ((demap_addr >> 4) & 3) { + case 0: // primary + context = env1->dmmu.mmu_primary_context; + break; + case 1: // secondary + context = env1->dmmu.mmu_secondary_context; + break; + case 2: // nucleus + context = 0; + break; + case 3: // reserved + return; + } for (i = 0; i < 64; i++) { if (TTE_IS_VALID(tlb[i].tte)) { - mask = 0xffffffffffffe000ULL; - mask <<= 3 * ((tlb[i].tte >> 61) & 3); + if (is_demap_context) { + // will remove non-global entries matching context value + if (TTE_IS_GLOBAL(tlb[i].tte) || + !tlb_compare_context(&tlb[i], context)) { + continue; + } + } + else { + // demap page + // will remove any entry matching VA + mask = 0xffffffffffffe000ULL; + mask <<= 3 * ((tlb[i].tte >> 61) & 3); + + if (!compare_masked(demap_addr, tlb[i].tag, mask)) { + continue; + } + + // entry should be global or matching context value + if (!TTE_IS_GLOBAL(tlb[i].tte) && + !tlb_compare_context(&tlb[i], context)) { + continue; + } + } - if ((demap_addr & mask) == (tlb[i].tag & mask)) { - replace_tlb_entry(&tlb[i], 0, 0, env1); + replace_tlb_entry(&tlb[i], 0, 0, env1); #ifdef DEBUG_MMU - DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); - dump_mmu(env1); + DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); + dump_mmu(env1); #endif - } - //return; } } - } static void replace_tlb_1bit_lru(SparcTLBEntry *tlb,