xref: /openbsd/sys/arch/arm/include/profile.h (revision 73471bf0)
1 /*	$OpenBSD: profile.h,v 1.5 2016/09/21 11:33:05 kettenis 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 #define MCOUNT_ASM_NAME "__mcount"
43 #ifdef __PIC__
44 #define	PLTSYM		"(PLT)"
45 #endif
46 
47 #ifndef PLTSYM
48 #define	PLTSYM
49 #endif
50 
51 #define	MCOUNT								\
52 	__asm__(".text");						\
53 	__asm__(".align	2");						\
54 	__asm__(".type	" MCOUNT_ASM_NAME ",%function");		\
55 	__asm__(".global	" MCOUNT_ASM_NAME);			\
56 	__asm__(MCOUNT_ASM_NAME ":");					\
57 	/*								\
58 	 * Preserve registers that are trashed during mcount		\
59 	 */								\
60 	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
61 	/*								\
62 	 * find the return address for mcount,				\
63 	 * and the return address for mcount's caller.			\
64 	 *								\
65 	 * frompcindex = pc pushed by call into self.			\
66 	 */								\
67 	__asm__("mov	r0, ip");					\
68 	/*								\
69 	 * selfpc = pc pushed by mcount call				\
70 	 */								\
71 	__asm__("mov	r1, lr");					\
72 	/*								\
73 	 * Call the real mcount code					\
74 	 */								\
75 	__asm__("bl	" __STRING(_mcount) PLTSYM);		\
76 	/*								\
77 	 * Restore registers that were trashed during mcount		\
78 	 */								\
79 	__asm__("ldmfd	sp!, {r0-r3, lr, pc}");
80 
81 #ifdef _KERNEL
82 #include <arm/cpufunc.h>
83 /*
84  * splhigh() and splx() are heavyweight, and call mcount().  Therefore
85  * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
86  *
87  * We're lucky that the CPSR and 's' both happen to be 'int's.
88  */
89 #define	MCOUNT_ENTER	s = __set_cpsr_c(0x0080, 0x0080);	/* kill IRQ */
90 #define	MCOUNT_EXIT	__set_cpsr_c(0xffffffff, s);	/* restore old value */
91 #endif /* _KERNEL */
92