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