Moving some code for reading/writing drs to processor.h. The names of the
functions are changed to be consistent with others.  While we are at it, fixing
lldt so it would work.

Signed-off-by: Nadav Amit <[email protected]>
---
 lib/x86/processor.h | 19 ++++++++++++++++++-
 x86/debug.c         | 36 +++++++-----------------------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index 7973879..47f8d2c 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -232,7 +232,7 @@ static inline void sidt(struct descriptor_table_ptr *ptr)
 
 static inline void lldt(unsigned val)
 {
-    asm volatile ("lldt %0" : : "rm"(val));
+    asm volatile ("lldt %0" : : "m"(val));
 }
 
 static inline u16 sldt(void)
@@ -254,6 +254,23 @@ static inline u16 str(void)
     return val;
 }
 
+static inline ulong read_dr0(void)
+{
+    ulong val;
+    asm volatile ("mov %%dr0, %0" : "=r"(val));
+    return val;
+}
+
+static inline void write_dr0(ulong val)
+{
+       asm volatile("mov %0,%%dr0" : : "r" (val));
+}
+
+static inline void write_dr1(ulong val)
+{
+       asm volatile("mov %0,%%dr1" : : "r" (val));
+}
+
 static inline void write_dr6(ulong val)
 {
     asm volatile ("mov %0, %%dr6" : : "r"(val) : "memory");
diff --git a/x86/debug.c b/x86/debug.c
index 34e56fb..68cac20 100644
--- a/x86/debug.c
+++ b/x86/debug.c
@@ -11,45 +11,23 @@
 
 #include "libcflat.h"
 #include "desc.h"
+#include "processor.h"
 
 static volatile unsigned long bp_addr[10], dr6[10];
 static volatile unsigned int n;
 static volatile unsigned long value;
 
-static unsigned long get_dr6(void)
-{
-       unsigned long value;
-
-       asm volatile("mov %%dr6,%0" : "=r" (value));
-       return value;
-}
-
-static void set_dr0(void *value)
-{
-       asm volatile("mov %0,%%dr0" : : "r" (value));
-}
-
-static void set_dr1(void *value)
-{
-       asm volatile("mov %0,%%dr1" : : "r" (value));
-}
-
-static void set_dr7(unsigned long value)
-{
-       asm volatile("mov %0,%%dr7" : : "r" (value));
-}
-
 static void handle_db(struct ex_regs *regs)
 {
        bp_addr[n] = regs->rip;
-       dr6[n] = get_dr6();
+       dr6[n] = read_dr6();
 
        if (dr6[n] & 0x1)
                regs->rflags |= (1 << 16);
 
        if (++n >= 10) {
                regs->rflags &= ~(1 << 8);
-               set_dr7(0x00000400);
+               write_dr7(0x00000400);
        }
 }
 
@@ -70,8 +48,8 @@ sw_bp:
        asm volatile("int3");
        report("#BP", bp_addr[0] == (unsigned long)&&sw_bp + 1);
 
-       set_dr0(&&hw_bp);
-       set_dr7(0x00000402);
+       write_dr0((ulong)&&hw_bp);
+       write_dr7(0x00000402);
 hw_bp:
        asm volatile("nop");
        report("hw breakpoint",
@@ -97,8 +75,8 @@ hw_bp:
               bp_addr[2] == start+1+6+1+1 && dr6[2] == 0xffff4ff0);
 
        n = 0;
-       set_dr1((void *)&value);
-       set_dr7(0x00d0040a);
+       write_dr1((ulong)&value);
+       write_dr7(0x00d0040a);
 
        asm volatile(
                "mov $42,%%rax\n\t"
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to