xref: /openbsd/sys/arch/sh/include/profile.h (revision a5cc6a2b)
1*a5cc6a2bSderaadt /*	$OpenBSD: profile.h,v 1.3 2016/05/27 16:32:38 deraadt Exp $	*/
23e3160c0Smiod /*	$NetBSD: profile.h,v 1.5 2006/10/26 23:54:28 uwe Exp $	*/
395c7671fSmiod 
495c7671fSmiod /*-
595c7671fSmiod  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
695c7671fSmiod  *
795c7671fSmiod  * Redistribution and use in source and binary forms, with or without
895c7671fSmiod  * modification, are permitted provided that the following conditions
995c7671fSmiod  * are met:
1095c7671fSmiod  * 1. Redistributions of source code must retain the above copyright
1195c7671fSmiod  *    notice, this list of conditions and the following disclaimer.
1295c7671fSmiod  * 2. Redistributions in binary form must reproduce the above copyright
1395c7671fSmiod  *    notice, this list of conditions and the following disclaimer in the
1495c7671fSmiod  *    documentation and/or other materials provided with the distribution.
1595c7671fSmiod  * 3. The name of the author may not be used to endorse or promote products
1695c7671fSmiod  *    derived from this software without specific prior written permission.
1795c7671fSmiod  *
1895c7671fSmiod  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1995c7671fSmiod  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2095c7671fSmiod  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2195c7671fSmiod  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2295c7671fSmiod  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2395c7671fSmiod  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2495c7671fSmiod  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2595c7671fSmiod  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2695c7671fSmiod  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2795c7671fSmiod  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2895c7671fSmiod  */
2995c7671fSmiod 
3095c7671fSmiod #define	_MCOUNT_DECL static void _mcount
3195c7671fSmiod 
3295c7671fSmiod #define	MCOUNT __asm ("				\n\
3395c7671fSmiod 	.text					\n\
3495c7671fSmiod 	.align	2				\n\
3595c7671fSmiod 	.globl	__mcount			\n\
3695c7671fSmiod __mcount:					\n\
3795c7671fSmiod 	mov.l	r4, @-r15			\n\
3895c7671fSmiod 	mov.l	r5, @-r15			\n\
3995c7671fSmiod 	mov.l	r6, @-r15			\n\
4095c7671fSmiod 	mov.l	r7, @-r15			\n\
413e3160c0Smiod 	mov.l	r0, @-r15			\n\
4295c7671fSmiod 	mov.l	r14, @-r15			\n\
4395c7671fSmiod 	sts.l	pr, @-r15			\n\
4495c7671fSmiod 	mov	r15, r14			\n\
4595c7671fSmiod 						\n\
4695c7671fSmiod 	mov.l	1f, r1		! _mcount	\n\
4795c7671fSmiod 	sts	pr, r4		! frompc	\n\
483e3160c0Smiod 0:	bsrf	r1				\n\
4995c7671fSmiod 	 mov	r0, r5		! selfpc	\n\
5095c7671fSmiod 						\n\
5195c7671fSmiod 	mov	r14, r15			\n\
5295c7671fSmiod 	lds.l	@r15+, pr			\n\
5395c7671fSmiod 	mov.l	@r15+, r14			\n\
543e3160c0Smiod 	mov.l	@r15+, r0			\n\
5595c7671fSmiod 	mov.l	@r15+, r7			\n\
5695c7671fSmiod 	mov.l	@r15+, r6			\n\
5795c7671fSmiod 	mov.l	@r15+, r5			\n\
583e3160c0Smiod 	jmp	@r0		! real function	\n\
5995c7671fSmiod 	 mov.l	@r15+, r4			\n\
6095c7671fSmiod 						\n\
6195c7671fSmiod 	.align	2				\n\
623e3160c0Smiod 1:	.long	_mcount - ((0b) + 4)		\n\
633e3160c0Smiod 						\n\
643e3160c0Smiod 	.size	__mcount, . - __mcount		");
6595c7671fSmiod 
6695c7671fSmiod #ifdef _KERNEL
6795c7671fSmiod #define	MCOUNT_ENTER	s = splhigh()
6895c7671fSmiod #define	MCOUNT_EXIT	splx(s)
6995c7671fSmiod #endif
70