All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: Handle new ARM breakpoint instruction
@ 2014-06-25  4:08 Hunter Laux
  2014-06-25  9:18 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Hunter Laux @ 2014-06-25  4:08 UTC (permalink / raw)
  To: qemu-devel, peter.maydell, riku.voipio; +Cc: Hunter Laux

This instruction space is guaranteed to be undefined.
ARM:   xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
Thumb: 1101 1110 xxxx xxxx

The breakpoint instructions were selected from this instruction space.
Linux traps the illegal instruction and sends a SIGTRAP if it is a breakpoint.

Here is the Linux implementation:
http://lxr.free-electrons.com/source/arch/arm/kernel/ptrace.c#L221

Signed-off-by: Hunter Laux <hunterlaux@gmail.com>
---
 linux-user/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/linux-user/main.c b/linux-user/main.c
index 900a17f..91f2681 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -688,11 +688,29 @@ void cpu_loop(CPUARMState *env)
                 uint32_t opcode;
                 int rc;
 
+                const uint32_t arm_bkpt_mask        = 0x0FFFFFFF;
+                const uint32_t arm_bkpt             = 0x07F001F0;
+                const uint32_t arm_bkpt_thumb_mask  = 0x0000FFFF;
+                const uint32_t arm_bkpt_thumb       = 0x0000DE01;
+                const uint32_t arm_bkpt_thumb2_mask = 0xFFFFFFFF;
+                const uint32_t arm_bkpt_thumb2      = 0xF7F0A000;
+
                 /* we handle the FPU emulation here, as Linux */
                 /* we get the opcode */
                 /* FIXME - what to do if get_user() fails? */
                 get_user_code_u32(opcode, env->regs[15], env->bswap_code);
 
+                if (env->thumb) {
+                    if ((opcode & arm_bkpt_thumb_mask) == arm_bkpt_thumb
+                        || (opcode & arm_bkpt_thumb2_mask) == arm_bkpt_thumb2) {
+                        goto excp_debug;
+                    }
+                } else {
+                    if ((opcode & arm_bkpt_mask) == arm_bkpt) {
+                        goto excp_debug;
+                    }
+                }
+
                 rc = EmulateAll(opcode, &ts->fpa, env);
                 if (rc == 0) { /* illegal instruction */
                     info.si_signo = SIGILL;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-25 18:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-25  4:08 [Qemu-devel] [PATCH] linux-user: Handle new ARM breakpoint instruction Hunter Laux
2014-06-25  9:18 ` Peter Maydell
2014-06-25 16:11   ` Hunter Laux
2014-06-25 18:07     ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.