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