Skip to contentSkip to conversation

target-i386: define dr7 bit filed and change dr7 related functions

PATCH In review liguang 2 participants 4 messages Jan 15, 2013

lore
Share & tools
lore

liguang

author
#0 lore raw

v5 cover target-i386: define dr7 bit filed and change dr7 related functions

the breakpoint related functions are a little hard to read for their implicit dr7 bit filed and not well organized logic, so try to define more readable bit filed for dr7 and clarify the breakpoint logic.

changes v4->v5

- fix some not well formated changes.
- split functional and non-functional changes for cherry-picking suggested by Andreas Färber <[email protected]>

changes v3->v4

- fix wrong logic of hw_{global,local}_breakpoint_enabled usage suggested by Peter Maydell <[email protected]>

changes v2->v3

- split hw_breakpoint_enabled into hw_{global,local}_breakpoint_enabled

changes v1->v2

- add _TYPE_ to the name of dr7 bit field
- fix some coding styles
suggested by Peter Maydell <[email protected]>

 target-i386/cpu.h         |    19 ++++++
 target-i386/helper.c      |    76 +++++++++++++++++++++++++++++++++----------------
 target-i386/machine.c     |    5 +++--
 target-i386/misc_helper.c |    4 ++--
 target-i386/seg_helper.c  |    9 +++++----
 5 files changed, 79 insertions(+), 34 deletions(-)
author
#1 lore raw

PATCH v5 1/2 target-i386: define dr7 bit field

implictly use of dr7 bit field is a little hard
to understand, so try to define them and use the
defined name.

---
 target-i386/cpu.h         |    6 ++++++
 target-i386/machine.c     |    5 +++--
 target-i386/misc_helper.c |    4 ++--
 target-i386/seg_helper.c  |    9 +++++----
 4 files changed, 16 insertions(+), 8 deletions(-)
target-i386/cpu.h +6 -0
index 1283537..64fd7a5 100644
@@ -231,6 +231,12 @@
 #define DR7_TYPE_SHIFT  16
 #define DR7_LEN_SHIFT   18
 #define DR7_FIXED_1     0x00000400
+#define DR7_LOCAL_BP_MASK    0x55
+#define DR7_MAX_BP           4
+#define DR7_TYPE_BP_INST     0x0
+#define DR7_TYPE_DATA_WR     0x1
+#define DR7_TYPE_IO_RW       0x2
+#define DR7_TYPE_DATA_RW     0x3
 
 #define PG_PRESENT_BIT	0
 #define PG_RW_BIT	1
target-i386/machine.c +3 -2
index 8354572..8df6a6b 100644
@@ -265,10 +265,11 @@ static int cpu_post_load(void *opaque, int version_id)
 
     cpu_breakpoint_remove_all(env, BP_CPU);
     cpu_watchpoint_remove_all(env, BP_CPU);
-    for (i = 0; i < 4; i++)
+    for (i = 0; i < DR7_MAX_BP; i++) {
         hw_breakpoint_insert(env, i);
-
+    }
     tlb_flush(env, 1);
+
     return 0;
 }
 
target-i386/misc_helper.c +2 -2
index db3126b..9b0f7b3 100644
@@ -197,11 +197,11 @@ void helper_movl_drN_T0(CPUX86State *env, int reg, target_ulong t0)
         env->dr[reg] = t0;
         hw_breakpoint_insert(env, reg);
     } else if (reg == 7) {
-        for (i = 0; i < 4; i++) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
             hw_breakpoint_remove(env, i);
         }
         env->dr[7] = t0;
-        for (i = 0; i < 4; i++) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
             hw_breakpoint_insert(env, i);
         }
     } else {
target-i386/seg_helper.c +5 -4
index c2a99ee..3247dee 100644
@@ -465,13 +465,14 @@ static void switch_tss(CPUX86State *env, int tss_selector,
 
 #ifndef CONFIG_USER_ONLY
     /* reset local breakpoints */
-    if (env->dr[7] & 0x55) {
-        for (i = 0; i < 4; i++) {
-            if (hw_breakpoint_enabled(env->dr[7], i) == 0x1) {
+    if (env->dr[7] & DR7_LOCAL_BP_MASK) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            if (hw_local_breakpoint_enabled(env->dr[7], i) &&
+                !hw_global_breakpoint_enabled(env->dr[7], i)) {
                 hw_breakpoint_remove(env, i);
             }
         }
-        env->dr[7] &= ~0x55;
+        env->dr[7] &= ~DR7_LOCAL_BP_MASK;
     }
 #endif
 }
Signature · 1 line
1.7.2.5
#2 lore raw

Re: [Qemu-devel] [PATCH v5 1/2] target-i386: define dr7 bit field

Am 15.01.2013 06:39, schrieb liguang:

Quoted 70 lines

implictly use of dr7 bit field is a little hard
to understand, so try to define them and use the
defined name.

---
 target-i386/cpu.h         |    6 ++++++
 target-i386/machine.c     |    5 +++--
 target-i386/misc_helper.c |    4 ++--
 target-i386/seg_helper.c  |    9 +++++----
 4 files changed, 16 insertions(+), 8 deletions(-)
target-i386/cpu.h +6 -0
index 1283537..64fd7a5 100644
@@ -231,6 +231,12 @@
 #define DR7_TYPE_SHIFT  16
 #define DR7_LEN_SHIFT   18
 #define DR7_FIXED_1     0x00000400
+#define DR7_LOCAL_BP_MASK    0x55
+#define DR7_MAX_BP           4
+#define DR7_TYPE_BP_INST     0x0
+#define DR7_TYPE_DATA_WR     0x1
+#define DR7_TYPE_IO_RW       0x2
+#define DR7_TYPE_DATA_RW     0x3
 
 #define PG_PRESENT_BIT	0
 #define PG_RW_BIT	1
target-i386/machine.c +3 -2
index 8354572..8df6a6b 100644
@@ -265,10 +265,11 @@ static int cpu_post_load(void *opaque, int version_id)
 
     cpu_breakpoint_remove_all(env, BP_CPU);
     cpu_watchpoint_remove_all(env, BP_CPU);
-    for (i = 0; i < 4; i++)
+    for (i = 0; i < DR7_MAX_BP; i++) {
         hw_breakpoint_insert(env, i);
-
+    }
     tlb_flush(env, 1);
+
     return 0;
 }
 
target-i386/misc_helper.c +2 -2
index db3126b..9b0f7b3 100644
@@ -197,11 +197,11 @@ void helper_movl_drN_T0(CPUX86State *env, int reg, target_ulong t0)
         env->dr[reg] = t0;
         hw_breakpoint_insert(env, reg);
     } else if (reg == 7) {
-        for (i = 0; i < 4; i++) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
             hw_breakpoint_remove(env, i);
         }
         env->dr[7] = t0;
-        for (i = 0; i < 4; i++) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
             hw_breakpoint_insert(env, i);
         }
     } else {
target-i386/seg_helper.c +0 -0
index c2a99ee..3247dee 100644

target-i386/seg_helper.c static void switch_tss(CPUX86State *env, int tss_selector, · line 471

Quoted 10 lines
target-i386/seg_helper.c +4 -3
@@ -465,13 +465,14 @@ static void switch_tss(CPUX86State *env, int tss_selector,
 
 #ifndef CONFIG_USER_ONLY
     /* reset local breakpoints */
-    if (env->dr[7] & 0x55) {
-        for (i = 0; i < 4; i++) {
-            if (hw_breakpoint_enabled(env->dr[7], i) == 0x1) {
+    if (env->dr[7] & DR7_LOCAL_BP_MASK) {
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            if (hw_local_breakpoint_enabled(env->dr[7], i) &&
+                !hw_global_breakpoint_enabled(env->dr[7], i)) {

Does not build.

Quoted 9 lines
target-i386/seg_helper.c +1 -1
                 hw_breakpoint_remove(env, i);
             }
         }
-        env->dr[7] &= ~0x55;
+        env->dr[7] &= ~DR7_LOCAL_BP_MASK;
     }
 #endif
 }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
author
#3 lore raw

PATCH v5 2/2 target-i386: change some dr7 related functions

In reply to liguang

logic of some original dr7 related functions
are not so readable, so try to clearify them.

---
 target-i386/cpu.h    |   13 ++++++++-
 target-i386/helper.c |   76 +++++++++++++++++++++++++++++++++----------------
 2 files changed, 63 insertions(+), 26 deletions(-)
target-i386/cpu.h +12 -1
index 64fd7a5..cee1cdd 100644
@@ -999,9 +999,20 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
 #define cpu_handle_mmu_fault cpu_x86_handle_mmu_fault
 void cpu_x86_set_a20(CPUX86State *env, int a20_state);
 
+static inline bool hw_local_breakpoint_enabled(unsigned long dr7, int index)
+{
+    return (dr7 >> (index * 2)) & 1;
+}
+
+static inline bool hw_global_breakpoint_enabled(unsigned long dr7, int index)
+{
+    return (dr7 >> (index * 2)) & 2;
+
+}
 static inline int hw_breakpoint_enabled(unsigned long dr7, int index)
 {
-    return (dr7 >> (index * 2)) & 3;
+    return hw_global_breakpoint_enabled(dr7, index) ||
+        hw_local_breakpoint_enabled(dr7, index);
 }
 
 static inline int hw_breakpoint_type(unsigned long dr7, int index)
target-i386/helper.c +51 -25

118 lines not on this page · raw message

Signature · 1 line
1.7.2.5