xref: /netbsd-src/sys/arch/arm/include/profile.h (revision 17dd36da8292193180754d5047c0926dbb56818c)
1 /*	$NetBSD: profile.h,v 1.1 2001/02/23 21:23:48 reinoud Exp $	*/
2 
3 /*
4  * Copyright (c) 1995-1996 Mark Brinicombe
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. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by Mark Brinicombe.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #define	_MCOUNT_DECL void _mcount
33 
34 /*
35  * Cannot implement mcount in C as GCC will trash the ip register when it
36  * pushes a trapframe. Pity we cannot insert assembly before the function
37  * prologue.
38  */
39 #define	MCOUNT								\
40 	__asm__(".text");						\
41 	__asm__(".align	0");						\
42 	__asm__(".type	mcount,@function");				\
43 	__asm__(".global	mcount");				\
44 	__asm__("mcount:");						\
45 	/*								\
46 	 * Preserve registers that are trashed during mcount		\
47 	 */								\
48 	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
49 	/*								\
50 	 * find the return address for mcount,				\
51 	 * and the return address for mcount's caller.			\
52 	 *								\
53 	 * frompcindex = pc pushed by call into self.			\
54 	 */								\
55 	__asm__("mov	r0, ip");					\
56 	/*								\
57 	 * selfpc = pc pushed by mcount call				\
58 	 */								\
59 	__asm__("mov	r1, lr");					\
60 	/*								\
61 	 * Call the real mcount code					\
62 	 */								\
63 	__asm__("bl	__mcount");					\
64 	/*								\
65 	 * Restore registers that were trashed during mcount		\
66 	 */								\
67 	__asm__("ldmfd	sp!, {r0-r3, lr, pc}");
68 
69 #ifdef _KERNEL
70 #include <machine/cpufunc.h>
71 /*
72  * splhigh() and splx() are heavyweight, and call mcount().  Therefore
73  * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
74  *
75  * We're lucky that the CPSR and 's' both happen to be 'int's.
76  */
77 #define	MCOUNT_ENTER	s = SetCPSR(0x0080, 0x0080);	/* set IRQ disable bit */
78 #define	MCOUNT_EXIT	SetCPSR(0xffffffff, s);		/* restore old value */
79 #endif /* _KERNEL */
80