Sparc64: handle MMU global bit and nucleus context

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Blue Swirl 2009-12-05 11:14:55 +00:00
parent dd5121bd8a
commit 2a90358f8a
2 changed files with 21 additions and 11 deletions

View File

@ -277,10 +277,12 @@ enum {
#define TTE_VALID_BIT (1ULL << 63) #define TTE_VALID_BIT (1ULL << 63)
#define TTE_USED_BIT (1ULL << 41) #define TTE_USED_BIT (1ULL << 41)
#define TTE_LOCKED_BIT (1ULL << 6) #define TTE_LOCKED_BIT (1ULL << 6)
#define TTE_GLOBAL_BIT (1ULL << 0)
#define TTE_IS_VALID(tte) ((tte) & TTE_VALID_BIT) #define TTE_IS_VALID(tte) ((tte) & TTE_VALID_BIT)
#define TTE_IS_USED(tte) ((tte) & TTE_USED_BIT) #define TTE_IS_USED(tte) ((tte) & TTE_USED_BIT)
#define TTE_IS_LOCKED(tte) ((tte) & TTE_LOCKED_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_USED(tte) ((tte) |= TTE_USED_BIT)
#define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT) #define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT)

View File

@ -388,7 +388,8 @@ static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
// requires virtual address mask value calculated from TTE entry size // requires virtual address mask value calculated from TTE entry size
static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, static inline int ultrasparc_tag_match(SparcTLBEntry *tlb,
uint64_t address, uint64_t context, uint64_t address, uint64_t context,
target_phys_addr_t *physical) target_phys_addr_t *physical,
int is_nucleus)
{ {
uint64_t mask; uint64_t mask;
@ -410,8 +411,9 @@ static inline int ultrasparc_tag_match(SparcTLBEntry *tlb,
// valid, context match, virtual address match? // valid, context match, virtual address match?
if (TTE_IS_VALID(tlb->tte) && if (TTE_IS_VALID(tlb->tte) &&
compare_masked(context, tlb->tag, 0x1fff) && ((is_nucleus && compare_masked(0, tlb->tag, 0x1fff))
compare_masked(address, tlb->tag, mask)) || TTE_IS_GLOBAL(tlb->tte) || compare_masked(context, tlb->tag, 0x1fff))
&& compare_masked(address, tlb->tag, mask))
{ {
// decode physical address // decode physical address
*physical = ((tlb->tte & mask) | (address & ~mask)) & 0x1ffffffe000ULL; *physical = ((tlb->tte & mask) | (address & ~mask)) & 0x1ffffffe000ULL;
@ -427,6 +429,7 @@ static int get_physical_address_data(CPUState *env,
{ {
unsigned int i; unsigned int i;
uint64_t context; uint64_t context;
int is_nucleus;
if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */ if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */
*physical = ultrasparc_truncate_physical(address); *physical = ultrasparc_truncate_physical(address);
@ -435,12 +438,13 @@ static int get_physical_address_data(CPUState *env,
} }
context = env->dmmu.mmu_primary_context & 0x1fff; context = env->dmmu.mmu_primary_context & 0x1fff;
is_nucleus = env->tl > 0;
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
// ctx match, vaddr match, valid? // ctx match, vaddr match, valid?
if (ultrasparc_tag_match(&env->dtlb[i], if (ultrasparc_tag_match(&env->dtlb[i],
address, context, physical) address, context, physical,
) { is_nucleus)) {
// access ok? // access ok?
if (((env->dtlb[i].tte & 0x4) && is_user) || if (((env->dtlb[i].tte & 0x4) && is_user) ||
(!(env->dtlb[i].tte & 0x2) && (rw == 1))) { (!(env->dtlb[i].tte & 0x2) && (rw == 1))) {
@ -486,6 +490,7 @@ static int get_physical_address_code(CPUState *env,
{ {
unsigned int i; unsigned int i;
uint64_t context; uint64_t context;
int is_nucleus;
if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) { if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) {
/* IMMU disabled */ /* IMMU disabled */
@ -495,12 +500,13 @@ static int get_physical_address_code(CPUState *env,
} }
context = env->dmmu.mmu_primary_context & 0x1fff; context = env->dmmu.mmu_primary_context & 0x1fff;
is_nucleus = env->tl > 0;
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
// ctx match, vaddr match, valid? // ctx match, vaddr match, valid?
if (ultrasparc_tag_match(&env->itlb[i], if (ultrasparc_tag_match(&env->itlb[i],
address, context, physical) address, context, physical,
) { is_nucleus)) {
// access ok? // access ok?
if ((env->itlb[i].tte & 0x4) && is_user) { if ((env->itlb[i].tte & 0x4) && is_user) {
if (env->immu.sfsr) /* Fault status register */ if (env->immu.sfsr) /* Fault status register */
@ -596,7 +602,7 @@ void dump_mmu(CPUState *env)
} }
if ((env->dtlb[i].tte & 0x8000000000000000ULL) != 0) { if ((env->dtlb[i].tte & 0x8000000000000000ULL) != 0) {
printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64 printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64
", %s, %s, %s, %s, ctx %" PRId64 "\n", ", %s, %s, %s, %s, ctx %" PRId64 " %s\n",
i, i,
env->dtlb[i].tag & (uint64_t)~0x1fffULL, env->dtlb[i].tag & (uint64_t)~0x1fffULL,
env->dtlb[i].tte & (uint64_t)0x1ffffffe000ULL, env->dtlb[i].tte & (uint64_t)0x1ffffffe000ULL,
@ -604,7 +610,8 @@ void dump_mmu(CPUState *env)
env->dtlb[i].tte & 0x4? "priv": "user", env->dtlb[i].tte & 0x4? "priv": "user",
env->dtlb[i].tte & 0x2? "RW": "RO", env->dtlb[i].tte & 0x2? "RW": "RO",
env->dtlb[i].tte & 0x40? "locked": "unlocked", env->dtlb[i].tte & 0x40? "locked": "unlocked",
env->dtlb[i].tag & (uint64_t)0x1fffULL); env->dtlb[i].tag & (uint64_t)0x1fffULL,
TTE_IS_GLOBAL(env->dtlb[i].tag)? "global" : "local");
} }
} }
} }
@ -630,14 +637,15 @@ void dump_mmu(CPUState *env)
} }
if ((env->itlb[i].tte & 0x8000000000000000ULL) != 0) { if ((env->itlb[i].tte & 0x8000000000000000ULL) != 0) {
printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64 printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64
", %s, %s, %s, ctx %" PRId64 "\n", ", %s, %s, %s, ctx %" PRId64 " %s\n",
i, i,
env->itlb[i].tag & (uint64_t)~0x1fffULL, env->itlb[i].tag & (uint64_t)~0x1fffULL,
env->itlb[i].tte & (uint64_t)0x1ffffffe000ULL, env->itlb[i].tte & (uint64_t)0x1ffffffe000ULL,
mask, mask,
env->itlb[i].tte & 0x4? "priv": "user", env->itlb[i].tte & 0x4? "priv": "user",
env->itlb[i].tte & 0x40? "locked": "unlocked", env->itlb[i].tte & 0x40? "locked": "unlocked",
env->itlb[i].tag & (uint64_t)0x1fffULL); env->itlb[i].tag & (uint64_t)0x1fffULL,
TTE_IS_GLOBAL(env->itlb[i].tag)? "global" : "local");
} }
} }
} }