Skip to contentSkip to conversation

SH4: Fixed last UTLB unused

PATCH Applied Lionel Landwerlin 2 participants 6 messages Feb 16, 2009 – Mar 3, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SH4: Fixed last UTLB unused

With my previous patch (the one monitoring tlb), I found that the last TLB entry was never use. Here a little fix.

---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-sh4/helper.c +1 -1
index cd0f392..918a946 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc == urb || urc == UTLB_SIZE)
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#1 lore raw

A more exact patch (according to datasheet) would be :

---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-sh4/helper.c +1 -1
index cd0f392..918a946 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc == urb || urc > (UTLB_SIZE - 1))
        urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#2 lore raw

Still not happy with the fix ...

---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-sh4/helper.c +1 -1
index cd0f392..8498d3f 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc > urb || urc > (UTLB_SIZE - 1))
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
#3 lore raw
Quoted 6 lines · Lionel Landwerlin

Still not happy with the fix ...

---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Sorry I missed this one when committing the first patch. I have applied it on top of it.

Quoted 25 lines
target-sh4/helper.c +1 -1
index cd0f392..8498d3f 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc > urb || urc > (UTLB_SIZE - 1))
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#4 lore raw
Quoted 11 lines · Aurelien Jarno
Quoted 6 lines · Lionel Landwerlin

Still not happy with the fix ...

---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Sorry I missed this one when committing the first patch. I have applied it on top of it.

Quoted 15 lines
Quoted 15 lines
target-sh4/helper.c +1 -1
index cd0f392..8498d3f 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc > urb || urc > (UTLB_SIZE - 1))
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 1 line
1.5.6.5

Hi Aurelien,

Thanks for applying my patches, but even with this version, I was still missing the real condition (according to SH4 datasheet) :

Random counter for indicating the UTLB entry for which replacement is to be performed with an LDTLB instruction. URC is incremented each time the UTLB is accessed. When URB > 0, URC is reset to 0 when the condition URC = URB occurs. Also note that, if a value is written to URC by software which results in
the condition URC > URB, incrementing is first performed in excess of URB until URC = 0x3F. URC is not incremented by an LDTLB instruction.

So the final version is :

[PATCH] SH4: Fixed last UTLB unused and URB/URC management

---
 target-sh4/helper.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
target-sh4/helper.c +0 -0
index cd0f392..54a3f1f 100644
@@ -297,7 +297,7 @@ static int same_tlb_entry_exists(const tlb_t *

haystack, uint8_t nbtlb,

     return 0;

}

static void increment_urc(CPUState * env)

 {
     uint8_t urb, urc;

@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)

     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if ((urb > 0 && urc > urb) || urc > (UTLB_SIZE - 1))
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);

}

Signature · 9 lines
1.5.6.5



Sorry for that mistake.


-- 
Lionel Landwerlin <[email protected]>
#5 lore raw
In reply to Lionel Landwerlin
Quoted 5 lines · Lionel Landwerlin

With my previous patch (the one monitoring tlb), I found that the last TLB entry was never use. Here a little fix.

Thanks, applied.

Quoted 29 lines
---
 target-sh4/helper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-sh4/helper.c +1 -1
index cd0f392..918a946 100644
@@ -305,7 +305,7 @@ static void increment_urc(CPUState * env)
     urb = ((env->mmucr) >> 18) & 0x3f;
     urc = ((env->mmucr) >> 10) & 0x3f;
     urc++;
-    if (urc == urb || urc == UTLB_SIZE - 1)
+    if (urc == urb || urc == UTLB_SIZE)
 	urc = 0;
     env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
 }
Signature · 7 lines
1.5.6.5


-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net