Module Name:    src
Committed By:   enami
Date:           Thu Apr  2 00:19:03 UTC 2009

Modified Files:
        src/common/lib/libc/arch/i386/atomic: atomic.S
        src/sys/arch/amd64/amd64: spl.S
        src/sys/arch/x86/x86: patch.c

Log Message:
So that profile kernel runs again,
- Adjust the size of functions used to patch.
- Fix the jump offset of mcount call when patching functions.

Approved by Andrew Doran.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/common/lib/libc/arch/i386/atomic/atomic.S
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/x86/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/arch/i386/atomic/atomic.S
diff -u src/common/lib/libc/arch/i386/atomic/atomic.S:1.16 src/common/lib/libc/arch/i386/atomic/atomic.S:1.17
--- src/common/lib/libc/arch/i386/atomic/atomic.S:1.16	Mon Jan 12 02:53:29 2009
+++ src/common/lib/libc/arch/i386/atomic/atomic.S	Thu Apr  2 00:19:02 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: atomic.S,v 1.16 2009/01/12 02:53:29 pooka Exp $	*/
+/*	$NetBSD: atomic.S,v 1.17 2009/04/02 00:19:02 enami Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -212,7 +212,11 @@
 	popl	%ebx
 	popl	%edi
 	ret
+#ifdef GPROF
+	.space	16, 0x90
+#else
 	.space	32, 0x90
+#endif
 ENDLABEL(_atomic_cas_cx8_end)
 
 ENTRY(sse2_lfence)

Index: src/sys/arch/amd64/amd64/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.20 src/sys/arch/amd64/amd64/spl.S:1.21
--- src/sys/arch/amd64/amd64/spl.S:1.20	Tue Jul  1 18:49:20 2008
+++ src/sys/arch/amd64/amd64/spl.S	Thu Apr  2 00:19:02 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.20 2008/07/01 18:49:20 bouyer Exp $	*/
+/*	$NetBSD: spl.S,v 1.21 2009/04/02 00:19:02 enami Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -209,6 +209,10 @@
 	nop
 	nop
 	.align	16
+#ifdef GPROF
+	nop
+	.align	16
+#endif
 LABEL(spllower_end)
 
 #endif /* !XEN */

Index: src/sys/arch/x86/x86/patch.c
diff -u src/sys/arch/x86/x86/patch.c:1.16 src/sys/arch/x86/x86/patch.c:1.17
--- src/sys/arch/x86/x86/patch.c:1.16	Tue Feb 17 21:20:49 2009
+++ src/sys/arch/x86/x86/patch.c	Thu Apr  2 00:19:03 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: patch.c,v 1.16 2009/02/17 21:20:49 ad Exp $	*/
+/*	$NetBSD: patch.c,v 1.17 2009/04/02 00:19:03 enami Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.16 2009/02/17 21:20:49 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.17 2009/04/02 00:19:03 enami Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -83,29 +83,44 @@
 #define	X86_DS		0x3e
 #define	X86_GROUP_0F	0x0f
 
+static void
+adjust_jumpoff(uint8_t *ptr, void *from_s, void *to_s)
+{
+
+	/* Branch hints */
+	if (ptr[0] == X86_CS || ptr[0] == X86_DS)
+		ptr++;
+	/* Conditional jumps */
+	if (ptr[0] == X86_GROUP_0F)
+		ptr++;		
+	/* 4-byte relative jump or call */
+	*(uint32_t *)(ptr + 1 - (uintptr_t)from_s + (uintptr_t)to_s) +=
+	    ((uint32_t)(uintptr_t)from_s - (uint32_t)(uintptr_t)to_s);
+}
+
 static void __unused
 patchfunc(void *from_s, void *from_e, void *to_s, void *to_e,
 	  void *pcrel)
 {
-	uint8_t *ptr;
 
 	if ((uintptr_t)from_e - (uintptr_t)from_s !=
 	    (uintptr_t)to_e - (uintptr_t)to_s)
 		panic("patchfunc: sizes do not match (from=%p)", from_s);
 
 	memcpy(to_s, from_s, (uintptr_t)to_e - (uintptr_t)to_s);
-	if (pcrel != NULL) {
-		ptr = pcrel;
-		/* Branch hints */
-		if (ptr[0] == X86_CS || ptr[0] == X86_DS)
-			ptr++;
-		/* Conditional jumps */
-		if (ptr[0] == X86_GROUP_0F)
-			ptr++;		
-		/* 4-byte relative jump or call */
-		*(uint32_t *)(ptr + 1 - (uintptr_t)from_s + (uintptr_t)to_s) +=
-		    ((uint32_t)(uintptr_t)from_s - (uint32_t)(uintptr_t)to_s);
-	}
+	if (pcrel != NULL)
+		adjust_jumpoff(pcrel, from_s, to_s);
+
+#ifdef GPROF
+#ifdef i386
+#define	MCOUNT_CALL_OFFSET	3
+#endif
+#ifdef __x86_64__
+#define	MCOUNT_CALL_OFFSET	5
+#endif
+	/* Patch mcount call offset */
+	adjust_jumpoff((uint8_t *)from_s + MCOUNT_CALL_OFFSET, from_s, to_s);
+#endif
 }
 
 static inline void __unused

Reply via email to