Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 May 2004 15:39:32 -0700 (PDT)
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 53013 for review
Message-ID:  <200405182239.i4IMdWR5043848@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=53013

Change 53013 by peter@peter_daintree on 2004/05/18 15:39:14

	make profiling actually work.  It seems that gcc isn't prepared for
	mcount to trash any of the scratch registers.

Affected files ...

.. //depot/projects/hammer/sys/amd64/include/profile.h#14 edit

Differences ...

==== //depot/projects/hammer/sys/amd64/include/profile.h#14 (text+ko) ====

@@ -76,9 +76,43 @@
 
 #define	FUNCTION_ALIGNMENT	4
 
-#define	_MCOUNT_DECL static __inline void _mcount
+#define	_MCOUNT_DECL \
+static void _mcount(uintfptr_t frompc, uintfptr_t selfpc) __unused; \
+static void _mcount
 
 #ifdef	__GNUC__
+#define	MCOUNT __asm ("			\n\
+	.globl	.mcount			\n\
+	.type	.mcount @function	\n\
+.mcount:				\n\
+	pushq	%rbp			\n\
+	movq	%rsp, %rbp		\n\
+	pushq	%rdi			\n\
+	pushq	%rsi			\n\
+	pushq	%rdx			\n\
+	pushq	%rcx			\n\
+	pushq	%r8			\n\
+	pushq	%r9			\n\
+	movq	8(%rbp),%rsi		\n\
+	movq	(%rbp),%rdi		\n\
+	movq	8(%rdi),%rdi		\n\
+	call	_mcount			\n\
+	popq	%r9			\n\
+	popq	%r8			\n\
+	popq	%rcx			\n\
+	popq	%rdx			\n\
+	popq	%rsi			\n\
+	popq	%rdi			\n\
+	leave				\n\
+	ret				\n\
+	.size	.mcount, . - .mcount");
+#if 0
+/*
+ * We could use this, except it doesn't preserve the registers that were
+ * being passed with arguments to the function that we were inserted
+ * into.  I've left it here as documentation of what the code above is
+ * supposed to do.
+ */
 #define	MCOUNT								\
 void									\
 mcount()								\
@@ -97,10 +131,11 @@
 	 * the caller's frame pointer.  The caller's raddr is in the	\
 	 * caller's frame following the caller's caller's frame pointer.\
 	 */								\
-	__asm("movq (%%rbp),%0" : "=r" (frompc));				\
+	__asm("movq (%%rbp),%0" : "=r" (frompc));			\
 	frompc = ((uintfptr_t *)frompc)[1];				\
 	_mcount(frompc, selfpc);					\
 }
+#endif
 #else	/* __GNUC__ */
 #define	MCOUNT		\
 void			\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200405182239.i4IMdWR5043848>