Skip to contentSkip to conversation

linux-user: Handle compressed ISA encodings when processing MIPS exceptions

PATCH In review Kwok Cheung Yeung 3 participants 4 messages Jul 19, 2013 – Aug 14, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 linux-user: Handle compressed ISA encodings when processing MIPS exceptions

Decode trap instructions during the handling of an EXCP_BREAK or EXCP_TRAP according to the current ISA mode.

---
 linux-user/main.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

v2->v3: Handle microMIPS and MIPS16e instructions when processing EXCP_BREAK.

linux-user/main.c +43 -3
index 7f15d3d..b137216 100644
@@ -2348,7 +2348,31 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code;
 
-                ret = get_user_ual(trap_instr, env->active_tc.PC);
+                if (env->hflags & MIPS_HFLAG_M16) {
+                    if (env->insn_flags & ASE_MICROMIPS) {
+                        /* microMIPS mode */
+                        abi_ulong instr[2];
+
+                        ret = get_user_u16(instr[0], env->active_tc.PC) ||
+                              get_user_u16(instr[1], env->active_tc.PC + 2);
+
+                        trap_instr = (instr[0] << 16) | instr[1];
+                    } else {
+                        /* MIPS16e mode */
+                        ret = get_user_u16(trap_instr, env->active_tc.PC);
+                        if (ret != 0) {
+                            goto error;
+                        }
+                        code = (trap_instr >> 6) & 0x3f;
+                        if (do_break(env, &info, code) != 0) {
+                            goto error;
+                        }
+                        break;
+                    }
+                } else {
+                    ret = get_user_ual(trap_instr, env->active_tc.PC);
+                }
+
                 if (ret != 0) {
                     goto error;
                 }
@@ -2372,14 +2396,30 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code = 0;
 
-                ret = get_user_ual(trap_instr, env->active_tc.PC);
+                if (env->hflags & MIPS_HFLAG_M16) {
+                    /* microMIPS mode */
+                    abi_ulong instr[2];
+
+                    ret = get_user_u16(instr[0], env->active_tc.PC) ||
+                          get_user_u16(instr[1], env->active_tc.PC + 2);
+
+                    trap_instr = (instr[0] << 16) | instr[1];
+                } else {
+                    ret = get_user_ual(trap_instr, env->active_tc.PC);
+                }
+
                 if (ret != 0) {
                     goto error;
                 }
 
                 /* 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
#2 lore raw
In reply to Kwok Cheung Yeung
Quoted 18 lines · Kwok Cheung Yeung

Decode trap instructions during the handling of an EXCP_BREAK or EXCP_TRAP according to the current ISA mode.

---
 linux-user/main.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

v2->v3: Handle microMIPS and MIPS16e instructions when processing EXCP_BREAK.

linux-user/main.c +0 -0
index 7f15d3d..b137216 100644
@@ -2348,7 +2348,31 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code;
 

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

Quoted 10 lines
linux-user/main.c +9 -1
-                ret = get_user_ual(trap_instr, env->active_tc.PC);
+                if (env->hflags & MIPS_HFLAG_M16) {
+                    if (env->insn_flags & ASE_MICROMIPS) {
+                        /* microMIPS mode */
+                        abi_ulong instr[2];
+
+                        ret = get_user_u16(instr[0], env->active_tc.PC) ||
+                              get_user_u16(instr[1], env->active_tc.PC + 2);
+
+                        trap_instr = (instr[0] << 16) | instr[1];

You need to tell 16-bit and 32-bit microMIPS BREAK instructions apart
somehow.

Maciej

#3 lore raw
Quoted 18 lines · Maciej W. Rozycki
Quoted 18 lines

Decode trap instructions during the handling of an EXCP_BREAK or EXCP_TRAP according to the current ISA mode.

---
 linux-user/main.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

v2->v3: Handle microMIPS and MIPS16e instructions when processing EXCP_BREAK.

linux-user/main.c +0 -0
index 7f15d3d..b137216 100644
@@ -2348,7 +2348,31 @@ done_syscall:
                 abi_ulong trap_instr;
                 unsigned int code;
 
Quoted 13 lines

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

Quoted 10 lines
linux-user/main.c +9 -1
-                ret = get_user_ual(trap_instr, env->active_tc.PC);
+                if (env->hflags & MIPS_HFLAG_M16) {
+                    if (env->insn_flags & ASE_MICROMIPS) {
+                        /* microMIPS mode */
+                        abi_ulong instr[2];
+
+                        ret = get_user_u16(instr[0], env->active_tc.PC) ||
+                              get_user_u16(instr[1], env->active_tc.PC + 2);
+
+                        trap_instr = (instr[0] << 16) | instr[1];

You need to tell 16-bit and 32-bit microMIPS BREAK instructions apart
somehow.

I can see the broken change was actually applied -- Kwok, did you have a
chance to have a look at making a fix?

Maciej