From: Vincent Hanquez <[email-masked]>

Add 2 macros to set and get debugreg on x86_64.  This is useful for Xen
because it will need only to redefine each macro to a hypervisor call.  

Signed-off-by: Vincent Hanquez <[email-masked]>
Cc: Ian Pratt <[email-masked]>
Cc: Andi Kleen <[email-masked]>
Signed-off-by: Andrew Morton <[email-masked]>
---

 arch/x86_64/kernel/signal.c    |    2 +-
 arch/x86_64/kernel/traps.c     |    4 ++--
 include/asm-x86_64/processor.h |    8 ++++++++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff -puN arch/x86_64/kernel/signal.c~xen-x86_64-add-macro-for-debugreg arch/x86_64/kernel/signal.c
--- 25/arch/x86_64/kernel/signal.c~xen-x86_64-add-macro-for-debugreg	2005-04-26 20:58:26.506650952 -0700
+++ 25-akpm/arch/x86_64/kernel/signal.c	2005-04-26 20:58:26.526647912 -0700
@@ -433,7 +433,7 @@ int do_signal(struct pt_regs *regs, sigs
 		 * inside the kernel.
 		 */
 		if (current->thread.debugreg7)
-			asm volatile("movq %0,%%db7"	: : "r" (current->thread.debugreg7));
+			set_debugreg(current->thread.debugreg7, 7);
 
 		/* Whee!  Actually deliver the signal.  */
 		handle_signal(signr, &info, &ka, oldset, regs);
diff -puN arch/x86_64/kernel/traps.c~xen-x86_64-add-macro-for-debugreg arch/x86_64/kernel/traps.c
--- 25/arch/x86_64/kernel/traps.c~xen-x86_64-add-macro-for-debugreg	2005-04-26 20:58:26.507650800 -0700
+++ 25-akpm/arch/x86_64/kernel/traps.c	2005-04-26 20:58:26.526647912 -0700
@@ -667,7 +667,7 @@ asmlinkage void do_debug(struct pt_regs 
        }
 #endif
 
-	asm("movq %%db6,%0" : "=r" (condition));
+	get_debugreg(condition, 6);
 
 	if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
 						SIGTRAP) == NOTIFY_STOP)
@@ -719,7 +719,7 @@ asmlinkage void do_debug(struct pt_regs 
 	info.si_addr = (void __user *)regs->rip;
 	force_sig_info(SIGTRAP, &info, tsk);	
 clear_dr7:
-	asm volatile("movq %0,%%db7"::"r"(0UL));
+	set_debugreg(0UL, 7);
 	return;
 
 clear_TF_reenable:
diff -puN include/asm-x86_64/processor.h~xen-x86_64-add-macro-for-debugreg include/asm-x86_64/processor.h
--- 25/include/asm-x86_64/processor.h~xen-x86_64-add-macro-for-debugreg	2005-04-26 20:58:26.522648520 -0700
+++ 25-akpm/include/asm-x86_64/processor.h	2005-04-26 20:58:26.527647760 -0700
@@ -280,6 +280,14 @@ struct thread_struct {
 	set_fs(USER_DS);							 \
 } while(0) 
 
+#define get_debugreg(var, register)				\
+		__asm__("movq %%db" #register ", %0"		\
+			:"=r" (var))
+#define set_debugreg(value, register)			\
+		__asm__("movq %0,%%db" #register		\
+			: /* no output */			\
+			:"r" (value))
+
 struct task_struct;
 struct mm_struct;
 
_