Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: profile.h,v 1.10 2021/11/02 11:22:03 ryo Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      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. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifdef _KERNEL_OPT
     30 #include "opt_ppcarch.h"
     31 #endif
     32 
     33 #define	_MCOUNT_DECL	void __mcount
     34 
     35 #ifdef _LP64
     36 
     37 #define MCOUNT				\
     38 __asm("	.globl	_mcount			\n" \
     39 "	.section \".opd\",\"aw\"	\n" \
     40 "	.align 3			\n" \
     41 "_mcount:				\n" \
     42 "	.quad	._mcount,.TOC.@tocbase,0\n" \
     43 "	.previous			\n" \
     44 "	.size	_mcount,24		\n" \
     45 "	.type	._mcount,@function	\n" \
     46 "	.globl	._mcount		\n" \
     47 "	.align	3			\n" \
     48 "._mcount:				\n" \
     49 "	frame=128			\n" \
     50 "	stdu	1,-frame(1)		\n" \
     51 "	std	2,120(1)		\n" \
     52 "	std	3,48+0(1)		\n" \
     53 "	std	4,48+8(1)		\n" \
     54 "	std	5,48+16(1)		\n" \
     55 "	std	6,48+24(1)		\n" \
     56 "	std	7,48+32(1)		\n" \
     57 "	std	8,48+40(1)		\n" \
     58 "	std	9,48+48(1)		\n" \
     59 "	std	10,48+56(1)		\n" \
     60 "					\n" \
     61 "	mflr	4			\n" \
     62 "	std	4,112(1)		\n" \
     63 "	ld	3,frame+16(1)		\n" \
     64 "	bl	.__mcount		\n" \
     65 "	ld	2,120(1)		\n" \
     66 "	ld	3,frame+16(1)		\n" \
     67 "	mtlr	3			\n" \
     68 "	ld	4,112(1)		\n" \
     69 "	mtctr	4			\n" \
     70 "					\n" \
     71 "	ld	3,16(1)			\n" \
     72 "	ld	4,20(1)			\n" \
     73 "	ld	5,24(1)			\n" \
     74 "	ld	6,28(1)			\n" \
     75 "	ld	7,32(1)			\n" \
     76 "	ld	8,36(1)			\n" \
     77 "	ld	9,40(1)			\n" \
     78 "	ld	10,44(1)		\n" \
     79 "	addi	1,1,frame		\n" \
     80 "	bctr");
     81 
     82 #else
     83 
     84 #ifdef __PIC__
     85 #define _PLT "@plt"
     86 #else
     87 #define _PLT
     88 #endif
     89 
     90 #define MCOUNT				\
     91 __asm("	.globl	_mcount			\n" \
     92 "	.type	_mcount,@function	\n" \
     93 "_mcount:				\n" \
     94 "	stwu	1,-64(1)		\n" \
     95 "	stw	3,16(1)			\n" \
     96 "	stw	4,20(1)			\n" \
     97 "	stw	5,24(1)			\n" \
     98 "	stw	6,28(1)			\n" \
     99 "	stw	7,32(1)			\n" \
    100 "	stw	8,36(1)			\n" \
    101 "	stw	9,40(1)			\n" \
    102 "	stw	10,44(1)		\n" \
    103 "					\n" \
    104 "	mflr	4			\n" \
    105 "	stw	4,48(1)			\n" \
    106 "	lwz	3,68(1)			\n" \
    107 "	bl	__mcount" _PLT "	\n" \
    108 "	lwz	3,68(1)			\n" \
    109 "	mtlr	3			\n" \
    110 "	lwz	4,48(1)			\n" \
    111 "	mtctr	4			\n" \
    112 "					\n" \
    113 "	lwz	3,16(1)			\n" \
    114 "	lwz	4,20(1)			\n" \
    115 "	lwz	5,24(1)			\n" \
    116 "	lwz	6,28(1)			\n" \
    117 "	lwz	7,32(1)			\n" \
    118 "	lwz	8,36(1)			\n" \
    119 "	lwz	9,40(1)			\n" \
    120 "	lwz	10,44(1)		\n" \
    121 "	addi	1,1,64			\n" \
    122 "	bctr				\n" \
    123 "_mcount_end:				\n" \
    124 "	.size	_mcount,_mcount_end-_mcount");
    125 
    126 #endif
    127 
    128 #ifdef _KERNEL
    129 #ifdef PPC_BOOKE
    130 #include <powerpc/booke/cpuvar.h>
    131 
    132 #define MCOUNT_ENTER	do s = wrtee(0); while (/*CONSTCOND*/ 0)
    133 #define MCOUNT_EXIT	wrtee(s)
    134 #else
    135 #include <powerpc/psl.h>
    136 #define MCOUNT_ENTER						\
    137 	__asm volatile("mfmsr %0" : "=r"(s));			\
    138 	if ((s & (PSL_IR | PSL_DR)) != (PSL_IR | PSL_DR))	\
    139 		return;		/* XXX */			\
    140 	s &= ~PSL_POW;						\
    141 	__asm volatile("mtmsr %0" :: "r"(s & ~PSL_EE))
    142 
    143 #define MCOUNT_EXIT						\
    144 	__asm volatile("mtmsr %0" :: "r"(s))
    145 #endif
    146 
    147 #endif
    148