xref: /netbsd-src/sys/arch/powerpc/include/profile.h (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: profile.h,v 1.5 2000/04/18 17:06:01 tsubai Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #define	_MCOUNT_DECL	void mcount
30 
31 #ifdef PIC
32 #define _PLT "@plt"
33 #else
34 #define _PLT
35 #endif
36 
37 #define MCOUNT __asm("		\
38 	.globl _mcount;		\
39 _mcount:			\
40 	stwu	1,-64(1);	\
41 	stw	3,16(1);	\
42 	stw	4,20(1);	\
43 	stw	5,24(1);	\
44 	stw	6,28(1);	\
45 	stw	7,32(1);	\
46 	stw	8,36(1);	\
47 	stw	9,40(1);	\
48 	stw	10,44(1);	\
49 				\
50 	mflr	4;		\
51 	stw	4,48(1);	\
52 	lwz	3,68(1);	\
53 	bl	mcount" _PLT ";	\
54 	lwz	3,68(1);	\
55 	mtlr	3;		\
56 	lwz	4,48(1);	\
57 	mtctr	4;		\
58 				\
59 	lwz	3,16(1);	\
60 	lwz	4,20(1);	\
61 	lwz	5,24(1);	\
62 	lwz	6,28(1);	\
63 	lwz	7,32(1);	\
64 	lwz	8,36(1);	\
65 	lwz	9,40(1);	\
66 	lwz	10,44(1);	\
67 	addi	1,1,64;		\
68 	bctr;			");
69 
70 #ifdef _KERNEL
71 #define MCOUNT_ENTER						\
72 	__asm volatile("mfmsr %0" : "=r"(s));			\
73 	if ((s & (PSL_IR | PSL_DR)) != (PSL_IR | PSL_DR))	\
74 		return;		/* XXX */			\
75 	s &= ~PSL_POW;						\
76 	__asm volatile("mtmsr %0" :: "r"(s & ~PSL_EE))
77 
78 #define MCOUNT_EXIT						\
79 	__asm volatile("mtmsr %0" :: "r"(s))
80 #endif
81