xref: /titanic_44/usr/src/uts/sparc/sys/asm_linkage.h (revision 843e19887f64dde75055cf8842fc4db2171eff45)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_ASM_LINKAGE_H
28 #define	_SYS_ASM_LINKAGE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/stack.h>
33 #include <sys/trap.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef _ASM	/* The remainder of this file is only for assembly files */
40 
41 /*
42  * C pointers are different sizes between V8 and V9.
43  * These constants can be used to compute offsets into pointer arrays.
44  */
45 #ifdef __sparcv9
46 #define	CPTRSHIFT	3
47 #define	CLONGSHIFT	3
48 #else
49 #define	CPTRSHIFT	2
50 #define	CLONGSHIFT	2
51 #endif
52 #define	CPTRSIZE	(1<<CPTRSHIFT)
53 #define	CLONGSIZE	(1<<CLONGSHIFT)
54 #define	CPTRMASK	(CPTRSIZE - 1)
55 #define	CLONGMASK	(CLONGSIZE - 1)
56 
57 /*
58  * Symbolic section definitions.
59  */
60 #define	RODATA	".rodata"
61 
62 /*
63  * profiling causes defintions of the MCOUNT and RTMCOUNT
64  * particular to the type
65  */
66 #ifdef GPROF
67 
68 #define	MCOUNT_SIZE	(4*4)	/* 4 instructions */
69 #define	MCOUNT(x) \
70 	save	%sp, -SA(MINFRAME), %sp; \
71 	call	_mcount; \
72 	nop; \
73 	restore;
74 
75 #endif /* GPROF */
76 
77 #ifdef PROF
78 
79 #if defined(__sparcv9)
80 
81 #define	MCOUNT_SIZE	(9*4)	/* 9 instructions */
82 #define	MCOUNT(x) \
83 	save	%sp, -SA(MINFRAME), %sp; \
84 /* CSTYLED */ \
85 	sethi	%hh(.L_/**/x/**/1), %o0; \
86 /* CSTYLED */ \
87 	sethi	%lm(.L_/**/x/**/1), %o1; \
88 /* CSTYLED */ \
89 	or	%o0, %hm(.L_/**/x/**/1), %o0; \
90 /* CSTYLED */ \
91 	or	%o1, %lo(.L_/**/x/**/1), %o1; \
92 	sllx	%o0, 32, %o0; \
93 	call	_mcount; \
94 	or	%o0, %o1, %o0; \
95 	restore; \
96 /* CSTYLED */ \
97 	.common .L_/**/x/**/1, 8, 8
98 
99 #else	/* __sparcv9 */
100 
101 #define	MCOUNT_SIZE	(5*4)	/* 5 instructions */
102 #define	MCOUNT(x) \
103 	save	%sp, -SA(MINFRAME), %sp; \
104 /* CSTYLED */ \
105 	sethi	%hi(.L_/**/x/**/1), %o0; \
106 	call	_mcount; \
107 /* CSTYLED */ \
108 	or	%o0, %lo(.L_/**/x/**/1), %o0; \
109 	restore; \
110 /* CSTYLED */ \
111 	.common .L_/**/x/**/1, 4, 4
112 
113 #endif	/* __sparcv9 */
114 
115 #endif /* PROF */
116 
117 /*
118  * if we are not profiling, MCOUNT should be defined to nothing
119  */
120 #if !defined(PROF) && !defined(GPROF)
121 #define	MCOUNT_SIZE	0	/* no instructions inserted */
122 #define	MCOUNT(x)
123 #endif /* !defined(PROF) && !defined(GPROF) */
124 
125 #define	RTMCOUNT(x)	MCOUNT(x)
126 
127 /*
128  * Macro to define weak symbol aliases. These are similar to the ANSI-C
129  *	#pragma weak name = _name
130  * except a compiler can determine type. The assembler must be told. Hence,
131  * the second parameter must be the type of the symbol (i.e.: function,...)
132  */
133 #define	ANSI_PRAGMA_WEAK(sym, stype)	\
134 	.weak	sym; \
135 	.type sym, #stype; \
136 /* CSTYLED */ \
137 sym	= _/**/sym
138 
139 /*
140  * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in:
141  *	#pragma weak sym1 = sym2
142  */
143 #define	ANSI_PRAGMA_WEAK2(sym1, sym2, stype)	\
144 	.weak	sym1; \
145 	.type sym1, #stype; \
146 sym1	= sym2
147 
148 /*
149  * ENTRY provides the standard procedure entry code and an easy way to
150  * insert the calls to mcount for profiling. ENTRY_NP is identical, but
151  * never calls mcount.
152  */
153 #define	ENTRY(x) \
154 	.section	".text"; \
155 	.align	4; \
156 	.global	x; \
157 	.type	x, #function; \
158 x:	MCOUNT(x)
159 
160 #define	ENTRY_SIZE	MCOUNT_SIZE
161 
162 #define	ENTRY_NP(x) \
163 	.section	".text"; \
164 	.align	4; \
165 	.global	x; \
166 	.type	x, #function; \
167 x:
168 
169 #define	RTENTRY(x) \
170 	.section	".text"; \
171 	.align	4; \
172 	.global	x; \
173 	.type	x, #function; \
174 x:	RTMCOUNT(x)
175 
176 /*
177  * ENTRY2 is identical to ENTRY but provides two labels for the entry point.
178  */
179 #define	ENTRY2(x, y) \
180 	.section	".text"; \
181 	.align	4; \
182 	.global	x, y; \
183 	.type	x, #function; \
184 	.type	y, #function; \
185 /* CSTYLED */ \
186 x:	; \
187 y:	MCOUNT(x)
188 
189 #define	ENTRY_NP2(x, y) \
190 	.section	".text"; \
191 	.align	4; \
192 	.global	x, y; \
193 	.type	x, #function; \
194 	.type	y, #function; \
195 /* CSTYLED */ \
196 x:	; \
197 y:
198 
199 
200 /*
201  * ALTENTRY provides for additional entry points.
202  */
203 #define	ALTENTRY(x) \
204 	.global x; \
205 	.type	x, #function; \
206 x:
207 
208 /*
209  * DGDEF and DGDEF2 provide global data declarations.
210  *
211  * DGDEF provides a word aligned word of storage.
212  *
213  * DGDEF2 allocates "sz" bytes of storage with **NO** alignment.  This
214  * implies this macro is best used for byte arrays.
215  *
216  * DGDEF3 allocates "sz" bytes of storage with "algn" alignment.
217  */
218 #define	DGDEF2(name, sz) \
219 	.section	".data"; \
220 	.global name; \
221 	.type	name, #object; \
222 	.size	name, sz; \
223 name:
224 
225 #define	DGDEF3(name, sz, algn) \
226 	.section	".data"; \
227 	.align	algn; \
228 	.global name; \
229 	.type	name, #object; \
230 	.size	name, sz; \
231 name:
232 
233 #define	DGDEF(name)	DGDEF3(name, 4, 4)
234 
235 /*
236  * SET_SIZE trails a function and set the size for the ELF symbol table.
237  */
238 #define	SET_SIZE(x) \
239 	.size	x, (.-x)
240 
241 #endif /* _ASM */
242 
243 #ifdef	__cplusplus
244 }
245 #endif
246 
247 #endif	/* _SYS_ASM_LINKAGE_H */
248