Skip to contentSkip to conversation

Minor MMU fixes for PowerPC 40x emulation

Qemu-devel Applied John Clark 3 participants 9 messages Oct 2, 2010 – Oct 5, 2010 1 message not in the archive

lore
Share & tools
lore

John Clark

author
#0 lore raw

Hello,

I found I had to make a few minor changes to the MMU code for the PowerPC 40x emulation to get NetBSD to run on a virtual PowerPC 405 core with qemu-system-ppcemb. The 'tlbre' instruction was not working, and permission checking for a TLB entry was not as strict as it should be. Diffs are included below.

Thank you.

- John Clark

target-ppc/helper.c +2 -2
index 3bc8a34..a8c1802 100644
@@ -1172,9 +1172,9 @@ static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
         case 0x1:
         check_perms:
             /* Check from TLB entry */
-            /* XXX: there is a problem here or in the TLB fill code... */
+            /* There is no longer a need to force PAGE_EXEC permission here */
+            /* because of the tlb->attr fix in helper_4xx_tlbwe_lo() */
             ctx->prot = tlb->prot;
-            ctx->prot |= PAGE_EXEC;
             ret = check_prot(ctx->prot, rw, access_type);
             if (ret == -2)
                 env->spr[SPR_40x_ESR] = 0;
target-ppc/op_helper.c +3 -3
index 3e6db85..54356e8 100644
@@ -3929,7 +3929,7 @@ static inline int booke_page_size_to_tlb(target_ulong page_size)
 }
 
 /* Helpers for 4xx TLB management */
-target_ulong helper_4xx_tlbre_lo (target_ulong entry)
+target_ulong helper_4xx_tlbre_hi (target_ulong entry)
 {
     ppcemb_tlb_t *tlb;
     target_ulong ret;
@@ -3939,7 +3939,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
     tlb = &env->tlb[entry].tlbe;
     ret = tlb->EPN;
     if (tlb->prot & PAGE_VALID)
-        ret |= 0x400;
+        ret |= 0x40;    /* V bit is 0x40, not 0x400 */
     size = booke_page_size_to_tlb(tlb->size);
     if (size < 0 || size > 0x7)
         size = 1;
@@ -3948,7 +3948,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
     return ret;
 }
 
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)
 {
     ppcemb_tlb_t *tlb;
     target_ulong ret;
#1 lore raw
Quoted 17 lines · John Clark

Hello,

I found I had to make a few minor changes to the MMU code for the PowerPC 40x emulation to get NetBSD to run on a virtual PowerPC 405 core with qemu-system-ppcemb. The 'tlbre' instruction was not working, and permission checking for a TLB entry was not as strict as it should be. Diffs are included below.

Thank you.

- John Clark

target-ppc/helper.c +0 -0
index 3bc8a34..a8c1802 100644

target-ppc/helper.c static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, · line 1176

Quoted 6 lines
target-ppc/helper.c +2 -1
@@ -1172,9 +1172,9 @@ static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
        case 0x1:
        check_perms:
            /* Check from TLB entry */
-            /* XXX: there is a problem here or in the TLB fill code... */
+            /* There is no longer a need to force PAGE_EXEC permission here */
+            /* because of the tlb->attr fix in helper_4xx_tlbwe_lo() */

I guess that comment is superfluous, as readers several years from now don't care what was broken back in the day :).

Quoted 19 lines
target-ppc/helper.c +0 -1
            ctx->prot = tlb->prot;
-            ctx->prot |= PAGE_EXEC;
            ret = check_prot(ctx->prot, rw, access_type);
            if (ret == -2)
                env->spr[SPR_40x_ESR] = 0;
target-ppc/op_helper.c +1 -1
index 3e6db85..54356e8 100644
@@ -3929,7 +3929,7 @@ static inline int booke_page_size_to_tlb(target_ulong page_size)
 }
 
 /* Helpers for 4xx TLB management */
-target_ulong helper_4xx_tlbre_lo (target_ulong entry)
+target_ulong helper_4xx_tlbre_hi (target_ulong entry)
 {
    ppcemb_tlb_t *tlb;
    target_ulong ret;

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3942

Quoted 5 lines
target-ppc/op_helper.c +1 -1
@@ -3939,7 +3939,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
    tlb = &env->tlb[entry].tlbe;
    ret = tlb->EPN;
    if (tlb->prot & PAGE_VALID)
-        ret |= 0x400;
+        ret |= 0x40;    /* V bit is 0x40, not 0x400 */

Ouch. Mind to make it a define?

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3951

Quoted 9 lines
target-ppc/op_helper.c +1 -1
    size = booke_page_size_to_tlb(tlb->size);
    if (size < 0 || size > 0x7)
        size = 1;
@@ -3948,7 +3948,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
    return ret;
 }
 
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)

Huh?

Alex

Quoted 4 lines
target-ppc/op_helper.c +0 -0
 {
    ppcemb_tlb_t *tlb;
    target_ulong ret;
#3 lore raw
In reply to a message not in the archive
Quoted 18 lines · John Clark
Quoted 6 lines

target-ppc/helper.c static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, · line 1176

Quoted 4 lines
           /* Check from TLB entry */
target-ppc/helper.c +2 -1
-            /* XXX: there is a problem here or in the TLB fill code... */
+            /* There is no longer a need to force PAGE_EXEC permission here */
+            /* because of the tlb->attr fix in helper_4xx_tlbwe_lo() */

I guess that comment is superfluous, as readers several years from now don't care what was broken back in the day :).

Yes, I suppose so :)

Quoted 8 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3942

Quoted 6 lines
target-ppc/op_helper.c +1 -1
@@ -3939,7 +3939,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
   tlb = &env->tlb[entry].tlbe;
   ret = tlb->EPN;
   if (tlb->prot & PAGE_VALID)
-        ret |= 0x400;
+        ret |= 0x40;    /* V bit is 0x40, not 0x400 */

Ouch. Mind to make it a define?

Quoted 1 line

Sure, I was surprised that there wasn't a define for that when I found it.

The ppc emulation code lacks a lot of defines. In fact, the same goes for x86 emulation too ;). But that doesn't mean we have to keep it that way!

Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
target-ppc/op_helper.c +0 -0
   size = booke_page_size_to_tlb(tlb->size);
   if (size < 0 || size > 0x7)
       size = 1;
@@ -3948,7 +3948,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
   return ret;
 }
 
Quoted 4 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3951

Quoted 2 lines
target-ppc/op_helper.c +1 -1
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)

Huh?

Quoted 5 lines

To summarize, 'tlbre' has two forms: one to retrieve the high bits of a TLB entry (TLBHI), and one to retrieve the low bits (TLBLO) of a TLB entry. This code had the TLBLO form returning the bits corresponding to TLBHI and vice versa, hence the name change. You can verify this if you like with this IBM PowerPC 405 core user manual on page 362:

Well the thing that strikes me as weird is mostly that you're changing a function name, but no callers to it. So is this function never used? Or was tlbre_lo defined before already and is now defined twice?

Alex

PS: Please use the "reply to all" function of your mailer. Others might be interested in the reply too :).

author
#4 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3951

Quoted 3 lines
target-ppc/op_helper.c +1 -1
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)

Huh?

Quoted 7 lines
Quoted 5 lines

To summarize, 'tlbre' has two forms: one to retrieve the high bits of a TLB entry (TLBHI), and one to retrieve the low bits (TLBLO) of a TLB entry. This code had the TLBLO form returning the bits corresponding to TLBHI and vice versa, hence the name change. You can verify this if you like with this IBM PowerPC 405 core user manual on page 362:

Well the thing that strikes me as weird is mostly that you're changing a function name, but no callers to it. So is this function never used? Or was tlbre_lo defined before already and is now defined twice?

You'll see that helper_4xx_tlbre_hi changes to helper_4xx_tlbre_lo and that helper_4xx_tlbre_lo changes to helper_4xx_tlbre_hi, so helper_4xx_tlbre_lo is not multiply defined.

Quoted 3 lines

PS: Please use the "reply to all" function of your mailer. Others might be interested in the reply too :).

Yes, I realized my mistake a few minutes after sending the previous reply and corrected it.

- John

#5 lore raw
In reply to Alexander Graf
Quoted 38 lines · Alexander Graf
Quoted 18 lines · John Clark
Quoted 6 lines

target-ppc/helper.c static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, · line 1176

Quoted 4 lines
           /* Check from TLB entry */
target-ppc/helper.c +2 -1
-            /* XXX: there is a problem here or in the TLB fill code... */
+            /* There is no longer a need to force PAGE_EXEC permission here */
+            /* because of the tlb->attr fix in helper_4xx_tlbwe_lo() */

I guess that comment is superfluous, as readers several years from now don't care what was broken back in the day :).

Yes, I suppose so :)

Quoted 8 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3942

Quoted 6 lines
target-ppc/op_helper.c +1 -1
@@ -3939,7 +3939,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
   tlb = &env->tlb[entry].tlbe;
   ret = tlb->EPN;
   if (tlb->prot & PAGE_VALID)
-        ret |= 0x400;
+        ret |= 0x40;    /* V bit is 0x40, not 0x400 */

Ouch. Mind to make it a define?

Quoted 1 line

Sure, I was surprised that there wasn't a define for that when I found it.

The ppc emulation code lacks a lot of defines. In fact, the same goes for x86 emulation too ;). But that doesn't mean we have to keep it that way!

Quoted 13 lines
Quoted 12 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3951

Quoted 10 lines
target-ppc/op_helper.c +1 -1
   size = booke_page_size_to_tlb(tlb->size);
   if (size < 0 || size > 0x7)
       size = 1;
@@ -3948,7 +3948,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
   return ret;
 }
 
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)

Huh?

Quoted 7 lines
Quoted 5 lines

To summarize, 'tlbre' has two forms: one to retrieve the high bits of a TLB entry (TLBHI), and one to retrieve the low bits (TLBLO) of a TLB entry. This code had the TLBLO form returning the bits corresponding to TLBHI and vice versa, hence the name change. You can verify this if you like with this IBM PowerPC 405 core user manual on page 362:

Well the thing that strikes me as weird is mostly that you're changing a function name, but no callers to it. So is this function never used? Or was tlbre_lo defined before already and is now defined twice?

Hi,

Alex:
I think you've missed the part of the patch that renames the _lo -> _hi. As John says, qemu had the hi/lo parts reversed when reading 4xx TLB regs.

Except for the comments and the define, the patch looks good to me. John, please also add a Signed-off-by line.

Cheers

#6 lore raw
Quoted 45 lines · Edgar E. Iglesias
Quoted 44 lines · Alexander Graf
Quoted 18 lines · John Clark
Quoted 6 lines

target-ppc/helper.c static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, · line 1176

Quoted 4 lines
          /* Check from TLB entry */
target-ppc/helper.c +2 -1
-            /* XXX: there is a problem here or in the TLB fill code... */
+            /* There is no longer a need to force PAGE_EXEC permission here */
+            /* because of the tlb->attr fix in helper_4xx_tlbwe_lo() */

I guess that comment is superfluous, as readers several years from now don't care what was broken back in the day :).

Yes, I suppose so :)

Quoted 8 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3942

Quoted 6 lines
target-ppc/op_helper.c +1 -1
@@ -3939,7 +3939,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
  tlb = &env->tlb[entry].tlbe;
  ret = tlb->EPN;
  if (tlb->prot & PAGE_VALID)
-        ret |= 0x400;
+        ret |= 0x40;    /* V bit is 0x40, not 0x400 */

Ouch. Mind to make it a define?

Quoted 1 line

Sure, I was surprised that there wasn't a define for that when I found it.

The ppc emulation code lacks a lot of defines. In fact, the same goes for x86 emulation too ;). But that doesn't mean we have to keep it that way!

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
target-ppc/op_helper.c +0 -0
  size = booke_page_size_to_tlb(tlb->size);
  if (size < 0 || size > 0x7)
      size = 1;
@@ -3948,7 +3948,7 @@ target_ulong helper_4xx_tlbre_lo (target_ulong entry)
  return ret;
 }
 
Quoted 4 lines

target-ppc/op_helper.c target_ulong helper_4xx_tlbre_lo (target_ulong entry) · line 3951

Quoted 2 lines
target-ppc/op_helper.c +1 -1
-target_ulong helper_4xx_tlbre_hi (target_ulong entry)
+target_ulong helper_4xx_tlbre_lo (target_ulong entry)

Huh?

To summarize, 'tlbre' has two forms: one to retrieve the high bits of a TLB entry (TLBHI), and one to retrieve the low bits (TLBLO) of a TLB entry. This code had the TLBLO form returning the bits corresponding to TLBHI and vice versa, hence the name change. You can verify this if you like with this IBM PowerPC 405 core user manual on page 362:

Quoted 7 lines
Quoted 1 line

Well the thing that strikes me as weird is mostly that you're changing a function name, but no callers to it. So is this function never used? Or was tlbre_lo defined before already and is now defined twice?

Hi,

Alex:
I think you've missed the part of the patch that renames the _lo -> _hi. As John says, qemu had the hi/lo parts reversed when reading 4xx TLB regs.

Oh. THERE it is! Hah. Yeah, I really missed that line - exchanging both functions makes sense.

Thanks,

Alex

author
#7 lore raw
In reply to Edgar E. Iglesias
Quoted 10 lines

Hi,

Alex:
I think you've missed the part of the patch that renames the _lo -> _hi. As John says, qemu had the hi/lo parts reversed when reading 4xx TLB regs.

Except for the comments and the define, the patch looks good to me. John, please also add a Signed-off-by line.

Cheers

Ok, I have removed the superfluous comments, added defines for magic numbers, added braces to conform to the QEMU coding style guidelines, and regression tested it in my system. Patch included below.

Thanks.

- John

--

 target-ppc/helper.c    |    2 -
 target-ppc/op_helper.c |   74 +++++++++++++++++++++++++++++++----------------
 2 files changed, 49 insertions(+), 27 deletions(-)
target-ppc/helper.c +0 -2
index 3bc8a34..edbdd80 100644
@@ -1172,9 +1172,7 @@ static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
         case 0x1:
         check_perms:
             /* Check from TLB entry */
-            /* XXX: there is a problem here or in the TLB fill code... */
             ctx->prot = tlb->prot;
-            ctx->prot |= PAGE_EXEC;
             ret = check_prot(ctx->prot, rw, access_type);
             if (ret == -2)
                 env->spr[SPR_40x_ESR] = 0;
target-ppc/op_helper.c +49 -25

139 lines not on this page · raw message

--

#8 lore raw
Quoted 15 lines · John Clark
Quoted 10 lines

Hi,

Alex:
I think you've missed the part of the patch that renames the _lo -> _hi. As John says, qemu had the hi/lo parts reversed when reading 4xx TLB regs.

Except for the comments and the define, the patch looks good to me. John, please also add a Signed-off-by line.

Cheers

Ok, I have removed the superfluous comments, added defines for magic numbers, added braces to conform to the QEMU coding style guidelines, and regression tested it in my system. Patch included below.

Quoted 5 lines

Thanks.

- John

#9 lore raw
Quoted 18 lines · Alexander Graf
Quoted 15 lines · John Clark
Quoted 10 lines

Hi,

Alex:
I think you've missed the part of the patch that renames the _lo -> _hi. As John says, qemu had the hi/lo parts reversed when reading 4xx TLB regs.

Except for the comments and the define, the patch looks good to me. John, please also add a Signed-off-by line.

Cheers

Ok, I have removed the superfluous comments, added defines for magic numbers, added braces to conform to the QEMU coding style guidelines, and regression tested it in my system. Patch included below.

Quoted 7 lines
Quoted 5 lines

Thanks.

- John

Applied, thanks John and Alex.

Cheers