Skip to contentSkip to conversation

linux-user: Handle microMIPS encoding when processing trap exceptions

PATCH Superseded Kwok Cheung Yeung 2 participants 2 messages Jul 17, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Handle microMIPS encoding when processing trap exceptions

Decode trap instructions during the handling of a EXCP_TRAP according to the current ISA mode.

---
 linux-user/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
linux-user/main.c +4 -1
index 7f15d3d..c417e26 100644
@@ -2379,7 +2379,10 @@ done_syscall:
 
                 /* The immediate versions don't provide a code.  */
                 if (!(trap_instr & 0xFC000000)) {
-                    code = ((trap_instr >> 6) & ((1 << 10) - 1));
+                    if (env->hflags & MIPS_HFLAG_M16)   /* microMIPS mode */
+                        code = ((trap_instr >> 12) & ((1 << 4) - 1));
+                    else
+                        code = ((trap_instr >> 6) & ((1 << 10) - 1));
                 }
 
                 if (do_break(env, &info, code) != 0) {
Signature · 1 line
1.8.3.3
#1 lore raw
Quoted 13 lines · Kwok Cheung Yeung

Decode trap instructions during the handling of a EXCP_TRAP according to the current ISA mode.

---
 linux-user/main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
linux-user/main.c +0 -0
index 7f15d3d..c417e26 100644

linux-user/main.c done_syscall: · line 2381

Quoted 3 lines
linux-user/main.c +0 -0
@@ -2379,7 +2379,10 @@ done_syscall:
 
                 /* The immediate versions don't provide a code.  */
                 if (!(trap_instr & 0xFC000000)) {

So this trap_instr is read in QEMU via a simple get_user_ual(), whereas if you look at the Linux kernel:
http://lxr.linux.no/#linux+v3.10.1/arch/mips/kernel/traps.c#L904

it specifically does two 16 bit loads for the microMIPS case. Are you sure this code is correct for both big and little endian MIPS configs?

(Similar remarks apply for EXCP_BREAK.)

linux-user/main.c done_syscall: · line 2385

Quoted 5 lines
linux-user/main.c +4 -1
-                    code = ((trap_instr >> 6) & ((1 << 10) - 1));
+                    if (env->hflags & MIPS_HFLAG_M16)   /* microMIPS mode */
+                        code = ((trap_instr >> 12) & ((1 << 4) - 1));
+                    else
+                        code = ((trap_instr >> 6) & ((1 << 10) - 1));

This if statement needs braces to fit QEMU coding style. scripts/checkpatch.pl will tell you about this sort of thing.

thanks
-- PMM