Skip to contentSkip to conversation

target-mips: fix detection of the end of the page during translation

PATCH In review Leon Alrae 3 participants 4 messages Jan 26, 2015 – Feb 2, 2015

lore
Share & tools
lore

Leon Alrae

author
#0 lore raw

PATCH 1/1 target-mips: fix detection of the end of the page during translation

The test is supposed to terminate TB if the end of the page is reached. However, with current implementation it may never succeed for microMIPS or mips16.

---
 target-mips/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target-mips/translate.c +4 -1
index e9d86b2..f33c10c 100644
@@ -19091,6 +19091,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
     CPUMIPSState *env = &cpu->env;
     DisasContext ctx;
     target_ulong pc_start;
+    target_ulong next_page_start;
     uint16_t *gen_opc_end;
     CPUBreakpoint *bp;
     int j, lj = -1;
@@ -19103,6 +19104,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
         qemu_log("search pc %d\n", search_pc);
 
     pc_start = tb->pc;
+    next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
     gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
     ctx.pc = pc_start;
     ctx.saved_pc = -1;
@@ -19202,8 +19204,9 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
             break;
         }
 
-        if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
+        if (ctx.pc >= next_page_start) {
             break;
+        }
 
         if (tcg_ctx.gen_opc_ptr >= gen_opc_end) {
             break;
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Leon Alrae

The test is supposed to terminate TB if the end of the page is reached. However, with current implementation it may never succeed for microMIPS or mips16.

---

I'm not sure if you need this, but just in case it helps anyhow.

target-mips/translate.c gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, · line 19107

Quoted 9 lines
target-mips/translate.c +1 -0
index e9d86b2..f33c10c 100644
@@ -19103,6 +19104,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
         qemu_log("search pc %d\n", search_pc);
 
     pc_start = tb->pc;
+    next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;

As a related issue -- I don't know offhand how far we are with small page
support, but we may have to revise these macros -- or specifically how TARGET_PAGE_BITS these build on has been defined -- once we get there, to avoid surprises. Just a heads-up!

Maciej

author
#2 lore raw
Quoted 11 lines · Maciej W. Rozycki
Quoted 7 lines · Leon Alrae

The test is supposed to terminate TB if the end of the page is reached. However, with current implementation it may never succeed for microMIPS or mips16.

---

I'm not sure if you need this, but just in case it helps anyhow.

Reviewed by line is always welcome, thanks!

Quoted 10 lines
Quoted 7 lines
target-mips/translate.c +0 -0
index e9d86b2..f33c10c 100644
@@ -19103,6 +19104,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
         qemu_log("search pc %d\n", search_pc);
 
Quoted 7 lines

target-mips/translate.c gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, · line 19107

Quoted 2 lines
target-mips/translate.c +1 -0
     pc_start = tb->pc;
+    next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;

As a related issue -- I don't know offhand how far we are with small page
support, but we may have to revise these macros -- or specifically how TARGET_PAGE_BITS these build on has been defined -- once we get there, to avoid surprises. Just a heads-up!

At first glance we aren't missing much to have small pages supported in target-mips. But yes, before we change TARGET_PAGE_BITS we have also to double check that these macros are correctly used in existing code and there is no place where it was assumed that page size is always 4K.

Leon

Reviewed-by on v1 1/1
#3 lore raw
In reply to Leon Alrae
Quoted 9 lines · Leon Alrae

The test is supposed to terminate TB if the end of the page is reached. However, with current implementation it may never succeed for microMIPS or mips16.

---
 target-mips/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

r~