Commit 1308c464 authored by Kwok Cheung Yeung's avatar Kwok Cheung Yeung Committed by Riku Voipio
Browse files

linux-user: Check type of microMIPS break instruction



microMIPS instructions that cause breakpoint exceptions come in
16-bit and 32-bit variants.  When handling exceptions caused by
such instructions, the instruction type needs to be taken into
account when extracting the break code.

The code has also been restructured for better clarity.

Signed-off-by: default avatarKwok Cheung Yeung <kcy@codesourcery.com>
Signed-off-by: default avatarRiku Voipio <riku.voipio@linaro.org>
parent dbf4f796
Loading
Loading
Loading
Loading
+35 −21
Original line number Diff line number Diff line
@@ -2400,12 +2400,31 @@ done_syscall:
                if (env->hflags & MIPS_HFLAG_M16) {
                    if (env->insn_flags & ASE_MICROMIPS) {
                        /* microMIPS mode */
                        abi_ulong instr[2];
                        ret = get_user_u16(trap_instr, env->active_tc.PC);
                        if (ret != 0) {
                            goto error;
                        }

                        ret = get_user_u16(instr[0], env->active_tc.PC) ||
                              get_user_u16(instr[1], env->active_tc.PC + 2);
                        if ((trap_instr >> 10) == 0x11) {
                            /* 16-bit instruction */
                            code = trap_instr & 0xf;
                        } else {
                            /* 32-bit instruction */
                            abi_ulong instr_lo;

                        trap_instr = (instr[0] << 16) | instr[1];
                            ret = get_user_u16(instr_lo,
                                               env->active_tc.PC + 2);
                            if (ret != 0) {
                                goto error;
                            }
                            trap_instr = (trap_instr << 16) | instr_lo;
                            code = ((trap_instr >> 6) & ((1 << 20) - 1));
                            /* Unfortunately, microMIPS also suffers from
                               the old assembler bug...  */
                            if (code >= (1 << 10)) {
                                code >>= 10;
                            }
                        }
                    } else {
                        /* MIPS16e mode */
                        ret = get_user_u16(trap_instr, env->active_tc.PC);
@@ -2413,15 +2432,9 @@ done_syscall:
                            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;
                    }
@@ -2434,6 +2447,7 @@ done_syscall:
                    if (code >= (1 << 10)) {
                        code >>= 10;
                    }
                }

                if (do_break(env, &info, code) != 0) {
                    goto error;