Skip to contentSkip to conversation

target-mips: fix updating XContext on mmu exception

PATCH In review Yongbok Kim 3 participants 3 messages Oct 29, 2015 – Oct 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 target-mips: fix updating XContext on mmu exception

Correct updating XContext.Region field on mmu exceptions. If Config3.CTXTC = 0 then the R field of XContext has to be updated with the value of bits 63..62 of the virtual address upon a TLB exception.
Also fixed the below line which overs 80 characters.

---
 target-mips/helper.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
target-mips/helper.c +4 -3
index 2d86323..b3fe816 100644
@@ -293,9 +293,10 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
         (env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
 #if defined(TARGET_MIPS64)
     env->CP0_EntryHi &= env->SEGMask;
-    env->CP0_XContext = (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
-                        ((address & 0xC00000000000ULL) >> (55 - env->SEGBITS)) |
-                        ((address & ((1ULL << env->SEGBITS) - 1) & 0xFFFFFFFFFFFFE000ULL) >> 9);
+    env->CP0_XContext =
+        /* PTEBase */   (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
+        /* R */         (extract64(address, 62, 2) << (env->SEGBITS - 9)) |
+        /* BadVPN2 */   (extract64(address, 13, env->SEGBITS - 13) << 4);
 #endif
     cs->exception_index = exception;
     env->error_code = error_code;
Signature · 1 line
1.7.1
Reviewed-by on v4 1/1
#1 lore raw
Quoted 4 lines · Yongbok Kim

Correct updating XContext.Region field on mmu exceptions. If Config3.CTXTC = 0 then the R field of XContext has to be updated with the value of bits 63..62 of the virtual address upon a TLB exception.

It wouldn't hurt to mention how the existing behaviour is wrong, since it requires a little staring (and counting of zeros) to see it, i.e. that the old mask incorrectly selected bits 47:46 of the address, and shifted them down into the middle of BadVPN2.

Quoted 3 lines

Also fixed the below line which overs 80 characters.

Cheers
James

Quoted 26 lines
---
 target-mips/helper.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
target-mips/helper.c +4 -3
index 2d86323..b3fe816 100644
@@ -293,9 +293,10 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
         (env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
 #if defined(TARGET_MIPS64)
     env->CP0_EntryHi &= env->SEGMask;
-    env->CP0_XContext = (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
-                        ((address & 0xC00000000000ULL) >> (55 - env->SEGBITS)) |
-                        ((address & ((1ULL << env->SEGBITS) - 1) & 0xFFFFFFFFFFFFE000ULL) >> 9);
+    env->CP0_XContext =
+        /* PTEBase */   (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
+        /* R */         (extract64(address, 62, 2) << (env->SEGBITS - 9)) |
+        /* BadVPN2 */   (extract64(address, 13, env->SEGBITS - 13) << 4);
 #endif
     cs->exception_index = exception;
     env->error_code = error_code;
Signature · 1 line
1.7.1
#2 lore raw
In reply to Yongbok Kim
Quoted 20 lines · Yongbok Kim

Correct updating XContext.Region field on mmu exceptions. If Config3.CTXTC = 0 then the R field of XContext has to be updated with the value of bits 63..62 of the virtual address upon a TLB exception.
Also fixed the below line which overs 80 characters.

---
 target-mips/helper.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
target-mips/helper.c +0 -0
index 2d86323..b3fe816 100644
@@ -293,9 +293,10 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,
         (env->CP0_EntryHi & 0xFF) | (address & (TARGET_PAGE_MASK << 1));
 #if defined(TARGET_MIPS64)
     env->CP0_EntryHi &= env->SEGMask;

target-mips/helper.c static void raise_mmu_exception(CPUMIPSState *env, target_ulong address, · line 302

Quoted 10 lines
target-mips/helper.c +4 -3
-    env->CP0_XContext = (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
-                        ((address & 0xC00000000000ULL) >> (55 - env->SEGBITS)) |
-                        ((address & ((1ULL << env->SEGBITS) - 1) & 0xFFFFFFFFFFFFE000ULL) >> 9);
+    env->CP0_XContext =
+        /* PTEBase */   (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |
+        /* R */         (extract64(address, 62, 2) << (env->SEGBITS - 9)) |
+        /* BadVPN2 */   (extract64(address, 13, env->SEGBITS - 13) << 4);
 #endif
     cs->exception_index = exception;
     env->error_code = error_code;

Thanks for cleaning up the XContext calculation. I applied this one as well as SIGRIE and RDHWR patches to the target-mips queue.

Regards,
Leon