Skip to contentSkip to conversation

[5747] x86: Debug register emulation (Jan Kiszka)

Qemu-devel Anthony Liguori 1 participant 1 message Nov 18, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5747

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5747
Author:   aliguori
Date:     2008-11-18 21:08:15 +0000 (Tue, 18 Nov 2008)

Log Message:
-----------
x86: Debug register emulation (Jan Kiszka)

Built on top of previously enhanced breakpoint/watchpoint support, this patch adds full debug register emulation for the x86 architecture.

Many corner cases were considered, and the result was successfully tested inside a Linux guest with gdb, but I won't be surprised if one or two scenarios still behave differently in reality.

Modified Paths:
--------------

    trunk/linux-user/main.c
    trunk/target-i386/cpu.h
    trunk/target-i386/helper.c
    trunk/target-i386/machine.c
    trunk/target-i386/op_helper.c

Modified: trunk/linux-user/main.c
===================================================================

linux-user/main.c +2 -2
@@ -403,7 +403,7 @@
                 queue_signal(env, info.si_signo, &info);
             }
             break;
-        case EXCP01_SSTP:
+        case EXCP01_DB:
         case EXCP03_INT3:
 #ifndef TARGET_X86_64
             if (env->eflags & VM_MASK) {
@@ -413,7 +413,7 @@
             {
                 info.si_signo = SIGTRAP;
                 info.si_errno = 0;
-                if (trapnr == EXCP01_SSTP) {
+                if (trapnr == EXCP01_DB) {
                     info.si_code = TARGET_TRAP_BRKPT;
                     info._sifields._sigfault._addr = env->eip;
                 } else {

Modified: trunk/target-i386/cpu.h
===================================================================

target-i386/cpu.h +35 -1
@@ -205,6 +205,16 @@
 #define CR4_OSFXSR_MASK (1 << CR4_OSFXSR_SHIFT)
 #define CR4_OSXMMEXCPT_MASK  (1 << 10)
 
+#define DR6_BD          (1 << 13)
+#define DR6_BS          (1 << 14)
+#define DR6_BT          (1 << 15)
+#define DR6_FIXED_1     0xffff0ff0
+
+#define DR7_GD          (1 << 13)
+#define DR7_TYPE_SHIFT  16
+#define DR7_LEN_SHIFT   18
+#define DR7_FIXED_1     0x00000400
+
 #define PG_PRESENT_BIT	0
 #define PG_RW_BIT	1
 #define PG_USER_BIT	2
@@ -362,7 +372,7 @@
 #define CPUID_MWAIT_EMX     (1 << 0) /* enumeration supported */
 
 #define EXCP00_DIVZ	0
-#define EXCP01_SSTP	1
+#define EXCP01_DB	1
 #define EXCP02_NMI	2
 #define EXCP03_INT3	3
 #define EXCP04_INTO	4
@@ -596,6 +606,10 @@
     int exception_is_int;
     target_ulong exception_next_eip;
     target_ulong dr[8]; /* debug registers */
+    union {
+        CPUBreakpoint *cpu_breakpoint[4];
+        CPUWatchpoint *cpu_watchpoint[4];
+    }; /* break/watchpoints for dr[0..3] */
     uint32_t smbase;
     int old_exception;  /* exception in flight */
 
@@ -789,6 +803,26 @@
 }
 #endif
 
+static inline int hw_breakpoint_enabled(unsigned long dr7, int index)
+{
+    return (dr7 >> (index * 2)) & 3;
+}
+
+static inline int hw_breakpoint_type(unsigned long dr7, int index)
+{
+    return (dr7 >> (DR7_TYPE_SHIFT + (index * 2))) & 3;
+}
+
+static inline int hw_breakpoint_len(unsigned long dr7, int index)
+{
+    int len = ((dr7 >> (DR7_LEN_SHIFT + (index * 2))) & 3);
+    return (len == 2) ? 8 : len + 1;
+}
+
+void hw_breakpoint_insert(CPUState *env, int index);
+void hw_breakpoint_remove(CPUState *env, int index);
+int check_hw_breakpoints(CPUState *env, int force_dr6_update);
+
 #include "cpu-all.h"
 #include "exec-all.h"
 

Modified: trunk/target-i386/helper.c
===================================================================

target-i386/helper.c +138 -31

196 lines not on this page · raw message

Modified: trunk/target-i386/machine.c
===================================================================

target-i386/machine.c +4 -0
@@ -259,6 +259,10 @@
 
     for(i = 0; i < 8; i++)
         qemu_get_betls(f, &env->dr[i]);
+    cpu_breakpoint_remove_all(env, BP_CPU);
+    cpu_watchpoint_remove_all(env, BP_CPU);
+    for (i = 0; i < 4; i++)
+        hw_breakpoint_insert(env, i);
 
     /* MMU */
     qemu_get_sbe32s(f, &a20_mask);

Modified: trunk/target-i386/op_helper.c
===================================================================

target-i386/op_helper.c +38 -8

76 lines not on this page · raw message