xref: /openbsd/sys/arch/arm/include/profile.h (revision 5af055cd)
1 /*	$OpenBSD: profile.h,v 1.3 2012/08/22 17:19:35 pascal Exp $	*/
2 /*	$NetBSD: profile.h,v 1.5 2002/03/24 15:49:40 bjh21 Exp $	*/
3 
4 /*
5  * Copyright (c) 2001 Ben Harris
6  * Copyright (c) 1995-1996 Mark Brinicombe
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Mark Brinicombe.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #define	_MCOUNT_DECL void _mcount
35 
36 /*
37  * Cannot implement mcount in C as GCC will trash the ip register when it
38  * pushes a trapframe. Pity we cannot insert assembly before the function
39  * prologue.
40  */
41 
42 #ifdef __ELF__
43 #define MCOUNT_ASM_NAME "__mcount"
44 #ifdef __PIC__
45 #define	PLTSYM		"(PLT)"
46 #endif
47 #else
48 #define MCOUNT_ASM_NAME "mcount"
49 #endif
50 
51 #ifndef PLTSYM
52 #define	PLTSYM
53 #endif
54 
55 #define	MCOUNT								\
56 	__asm__(".text");						\
57 	__asm__(".align	0");						\
58 	__asm__(".type	" MCOUNT_ASM_NAME ",%function");		\
59 	__asm__(".global	" MCOUNT_ASM_NAME);			\
60 	__asm__(MCOUNT_ASM_NAME ":");					\
61 	/*								\
62 	 * Preserve registers that are trashed during mcount		\
63 	 */								\
64 	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
65 	/*								\
66 	 * find the return address for mcount,				\
67 	 * and the return address for mcount's caller.			\
68 	 *								\
69 	 * frompcindex = pc pushed by call into self.			\
70 	 */								\
71 	__asm__("mov	r0, ip");					\
72 	/*								\
73 	 * selfpc = pc pushed by mcount call				\
74 	 */								\
75 	__asm__("mov	r1, lr");					\
76 	/*								\
77 	 * Call the real mcount code					\
78 	 */								\
79 	__asm__("bl	" __STRING(_mcount) PLTSYM);		\
80 	/*								\
81 	 * Restore registers that were trashed during mcount		\
82 	 */								\
83 	__asm__("ldmfd	sp!, {r0-r3, lr, pc}");
84 
85 #ifdef _KERNEL
86 #include <arm/cpufunc.h>
87 /*
88  * splhigh() and splx() are heavyweight, and call mcount().  Therefore
89  * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
90  *
91  * We're lucky that the CPSR and 's' both happen to be 'int's.
92  */
93 #define	MCOUNT_ENTER	s = __set_cpsr_c(0x0080, 0x0080);	/* kill IRQ */
94 #define	MCOUNT_EXIT	__set_cpsr_c(0xffffffff, s);	/* restore old value */
95 #endif /* _KERNEL */
96