1 /*        $NetBSD: profile.h,v 1.25 2021/02/18 20:37:02 skrll Exp $   */
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *        The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Ralph Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *        @(#)profile.h       8.1 (Berkeley) 6/10/93
35  */
36 
37 #ifndef _MIPS_PROFILE_H_
38 #define   _MIPS_PROFILE_H_
39 
40 #if defined(_KERNEL_OPT)
41 #include "opt_gprof.h"
42 #endif
43 
44 #ifdef _KERNEL
45  /*
46   *  Declare non-profiled _splhigh() /_splx() entrypoints for _mcount.
47   *  see MCOUNT_ENTER and MCOUNT_EXIT.
48   */
49 #define   _KERNEL_MCOUNT_DECL           \
50           int splhigh_noprof(void);     \
51           void splx_noprof(int);
52 #else   /* !_KERNEL */
53 /* Make __mcount static. */
54 #define   _KERNEL_MCOUNT_DECL static
55 #endif    /* !_KERNEL */
56 
57 #ifdef _KERNEL
58 # define _PROF_CPLOAD         ""
59 #else
60 # define _PROF_CPLOAD         ".cpload $25;"
61 #endif
62 
63 
64 #define   _MCOUNT_DECL \
65     _KERNEL_MCOUNT_DECL \
66     void __attribute__((unused)) __mcount
67 
68 #ifdef __mips_o32   /* 32-bit version */
69 #define   MCOUNT \
70           __asm(".globl _mcount;" \
71                 ".type _mcount,@function;" \
72                 "_mcount:;" \
73                 ".set noreorder;" \
74                 ".set noat;" \
75                 _PROF_CPLOAD \
76                 "addu $29,$29,-16;" \
77                 "sw $4,8($29);" \
78                 "sw $5,12($29);" \
79                 "sw $6,16($29);" \
80                 "sw $7,20($29);" \
81                 "sw $1,0($29);" \
82                 "sw $31,4($29);" \
83                 "move $5,$31;" \
84                 "move $4,$1;" \
85                 "jal __mcount;" \
86                 " nop;" \
87                 "lw $4,8($29);" \
88                 "lw $5,12($29);" \
89                 "lw $6,16($29);" \
90                 "lw $7,20($29);" \
91                 "lw $31,4($29);" \
92                 "lw $1,0($29);" \
93                 "addu $29,$29,24;" \
94                 "j $31;" \
95                 " move $31,$1;" \
96                 ".set reorder;" \
97                 ".set at");
98 #else /* 64-bit */
99 #ifdef __mips_o64
100 # error yeahnah
101 #endif
102 #define   MCOUNT \
103           __asm(".globl _mcount;" \
104                 ".type _mcount,@function;" \
105                 "_mcount:;" \
106                 ".set noreorder;" \
107                 ".set noat;" \
108                 _PROF_CPLOAD \
109                 "daddu $29,$29,-80;"\
110                 "sd $4,16($29);" \
111                 "sd $5,24($29);" \
112                 "sd $6,32($29);" \
113                 "sd $7,40($29);" \
114                 "sd $8,48($29);" \
115                 "sd $9,56($29);" \
116                 "sd $10,64($29);" \
117                 "sd $11,72($29);" \
118                 "sd $1,0($29);" \
119                 "sd $31,8($29);" \
120                 "move $5,$31;" \
121                 "move $4,$1;" \
122                 "jal __mcount;" \
123                 " nop;" \
124                 "ld $4,16($29);" \
125                 "ld $5,24($29);" \
126                 "ld $6,32($29);" \
127                 "ld $7,40($29);" \
128                 "ld $8,48($29);" \
129                 "ld $9,56($29);" \
130                 "ld $10,64($29);" \
131                 "ld $11,72($29);" \
132                 "ld $31,8($29);" \
133                 "ld $1,0($29);" \
134                 "daddu $29,$29,80;" \
135                 "j $31;" \
136                 " move $31,$1;" \
137                 ".set reorder;" \
138                 ".set at");
139 #endif /* 64-bit */
140 
141 #ifdef _KERNEL
142 /*
143  * The following two macros do splhigh and splx respectively.
144  * We use versions of _splraise() and _splset that don't
145  * including profiling support.
146  */
147 
148 #define   MCOUNT_ENTER        s = splhigh_noprof()
149 
150 #define   MCOUNT_EXIT         splx_noprof(s)
151 #endif /* _KERNEL */
152 
153 #endif /* _MIPS_PROFILE_H_ */
154