xref: /illumos-gate/usr/src/uts/sparc/sys/asm_linkage.h (revision 7257d1b4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7257d1b4Sraf  * Common Development and Distribution License (the "License").
6*7257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*7257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_ASM_LINKAGE_H
287c478bd9Sstevel@tonic-gate #define	_SYS_ASM_LINKAGE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/stack.h>
337c478bd9Sstevel@tonic-gate #include <sys/trap.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef _ASM	/* The remainder of this file is only for assembly files */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * C pointers are different sizes between V8 and V9.
437c478bd9Sstevel@tonic-gate  * These constants can be used to compute offsets into pointer arrays.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate #ifdef __sparcv9
467c478bd9Sstevel@tonic-gate #define	CPTRSHIFT	3
477c478bd9Sstevel@tonic-gate #define	CLONGSHIFT	3
487c478bd9Sstevel@tonic-gate #else
497c478bd9Sstevel@tonic-gate #define	CPTRSHIFT	2
507c478bd9Sstevel@tonic-gate #define	CLONGSHIFT	2
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate #define	CPTRSIZE	(1<<CPTRSHIFT)
537c478bd9Sstevel@tonic-gate #define	CLONGSIZE	(1<<CLONGSHIFT)
547c478bd9Sstevel@tonic-gate #define	CPTRMASK	(CPTRSIZE - 1)
557c478bd9Sstevel@tonic-gate #define	CLONGMASK	(CLONGSIZE - 1)
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Symbolic section definitions.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate #define	RODATA	".rodata"
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * profiling causes defintions of the MCOUNT and RTMCOUNT
647c478bd9Sstevel@tonic-gate  * particular to the type
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate #ifdef GPROF
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(4*4)	/* 4 instructions */
697c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
707c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
717c478bd9Sstevel@tonic-gate 	call	_mcount; \
727c478bd9Sstevel@tonic-gate 	nop; \
737c478bd9Sstevel@tonic-gate 	restore;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #endif /* GPROF */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifdef PROF
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #if defined(__sparcv9)
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(9*4)	/* 9 instructions */
827c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
837c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
847c478bd9Sstevel@tonic-gate /* CSTYLED */ \
857c478bd9Sstevel@tonic-gate 	sethi	%hh(.L_/**/x/**/1), %o0; \
867c478bd9Sstevel@tonic-gate /* CSTYLED */ \
877c478bd9Sstevel@tonic-gate 	sethi	%lm(.L_/**/x/**/1), %o1; \
887c478bd9Sstevel@tonic-gate /* CSTYLED */ \
897c478bd9Sstevel@tonic-gate 	or	%o0, %hm(.L_/**/x/**/1), %o0; \
907c478bd9Sstevel@tonic-gate /* CSTYLED */ \
917c478bd9Sstevel@tonic-gate 	or	%o1, %lo(.L_/**/x/**/1), %o1; \
927c478bd9Sstevel@tonic-gate 	sllx	%o0, 32, %o0; \
937c478bd9Sstevel@tonic-gate 	call	_mcount; \
947c478bd9Sstevel@tonic-gate 	or	%o0, %o1, %o0; \
957c478bd9Sstevel@tonic-gate 	restore; \
967c478bd9Sstevel@tonic-gate /* CSTYLED */ \
977c478bd9Sstevel@tonic-gate 	.common .L_/**/x/**/1, 8, 8
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #else	/* __sparcv9 */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(5*4)	/* 5 instructions */
1027c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
1037c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
1047c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1057c478bd9Sstevel@tonic-gate 	sethi	%hi(.L_/**/x/**/1), %o0; \
1067c478bd9Sstevel@tonic-gate 	call	_mcount; \
1077c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1087c478bd9Sstevel@tonic-gate 	or	%o0, %lo(.L_/**/x/**/1), %o0; \
1097c478bd9Sstevel@tonic-gate 	restore; \
1107c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1117c478bd9Sstevel@tonic-gate 	.common .L_/**/x/**/1, 4, 4
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #endif	/* __sparcv9 */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #endif /* PROF */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * if we are not profiling, MCOUNT should be defined to nothing
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate #if !defined(PROF) && !defined(GPROF)
1217c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	0	/* no instructions inserted */
1227c478bd9Sstevel@tonic-gate #define	MCOUNT(x)
1237c478bd9Sstevel@tonic-gate #endif /* !defined(PROF) && !defined(GPROF) */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #define	RTMCOUNT(x)	MCOUNT(x)
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Macro to define weak symbol aliases. These are similar to the ANSI-C
129*7257d1b4Sraf  *	#pragma weak _name = name
1307c478bd9Sstevel@tonic-gate  * except a compiler can determine type. The assembler must be told. Hence,
1317c478bd9Sstevel@tonic-gate  * the second parameter must be the type of the symbol (i.e.: function,...)
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate #define	ANSI_PRAGMA_WEAK(sym, stype)	\
1347c478bd9Sstevel@tonic-gate /* CSTYLED */ \
135*7257d1b4Sraf 	.weak	_/**/sym; \
136*7257d1b4Sraf /* CSTYLED */ \
137*7257d1b4Sraf 	.type	_/**/sym, #stype; \
138*7257d1b4Sraf /* CSTYLED */ \
139*7257d1b4Sraf _/**/sym = sym
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in:
1437c478bd9Sstevel@tonic-gate  *	#pragma weak sym1 = sym2
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate #define	ANSI_PRAGMA_WEAK2(sym1, sym2, stype)	\
1467c478bd9Sstevel@tonic-gate 	.weak	sym1; \
1477c478bd9Sstevel@tonic-gate 	.type sym1, #stype; \
1487c478bd9Sstevel@tonic-gate sym1	= sym2
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * ENTRY provides the standard procedure entry code and an easy way to
1527c478bd9Sstevel@tonic-gate  * insert the calls to mcount for profiling. ENTRY_NP is identical, but
1537c478bd9Sstevel@tonic-gate  * never calls mcount.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	ENTRY(x) \
1567c478bd9Sstevel@tonic-gate 	.section	".text"; \
1577c478bd9Sstevel@tonic-gate 	.align	4; \
1587c478bd9Sstevel@tonic-gate 	.global	x; \
1597c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1607c478bd9Sstevel@tonic-gate x:	MCOUNT(x)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #define	ENTRY_SIZE	MCOUNT_SIZE
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #define	ENTRY_NP(x) \
1657c478bd9Sstevel@tonic-gate 	.section	".text"; \
1667c478bd9Sstevel@tonic-gate 	.align	4; \
1677c478bd9Sstevel@tonic-gate 	.global	x; \
1687c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1697c478bd9Sstevel@tonic-gate x:
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #define	RTENTRY(x) \
1727c478bd9Sstevel@tonic-gate 	.section	".text"; \
1737c478bd9Sstevel@tonic-gate 	.align	4; \
1747c478bd9Sstevel@tonic-gate 	.global	x; \
1757c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1767c478bd9Sstevel@tonic-gate x:	RTMCOUNT(x)
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * ENTRY2 is identical to ENTRY but provides two labels for the entry point.
1807c478bd9Sstevel@tonic-gate  */
1817c478bd9Sstevel@tonic-gate #define	ENTRY2(x, y) \
1827c478bd9Sstevel@tonic-gate 	.section	".text"; \
1837c478bd9Sstevel@tonic-gate 	.align	4; \
1847c478bd9Sstevel@tonic-gate 	.global	x, y; \
1857c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1867c478bd9Sstevel@tonic-gate 	.type	y, #function; \
1877c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1887c478bd9Sstevel@tonic-gate x:	; \
1897c478bd9Sstevel@tonic-gate y:	MCOUNT(x)
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #define	ENTRY_NP2(x, y) \
1927c478bd9Sstevel@tonic-gate 	.section	".text"; \
1937c478bd9Sstevel@tonic-gate 	.align	4; \
1947c478bd9Sstevel@tonic-gate 	.global	x, y; \
1957c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1967c478bd9Sstevel@tonic-gate 	.type	y, #function; \
1977c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1987c478bd9Sstevel@tonic-gate x:	; \
1997c478bd9Sstevel@tonic-gate y:
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * ALTENTRY provides for additional entry points.
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate #define	ALTENTRY(x) \
2067c478bd9Sstevel@tonic-gate 	.global x; \
2077c478bd9Sstevel@tonic-gate 	.type	x, #function; \
2087c478bd9Sstevel@tonic-gate x:
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * DGDEF and DGDEF2 provide global data declarations.
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  * DGDEF provides a word aligned word of storage.
2147c478bd9Sstevel@tonic-gate  *
2157c478bd9Sstevel@tonic-gate  * DGDEF2 allocates "sz" bytes of storage with **NO** alignment.  This
2167c478bd9Sstevel@tonic-gate  * implies this macro is best used for byte arrays.
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  * DGDEF3 allocates "sz" bytes of storage with "algn" alignment.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate #define	DGDEF2(name, sz) \
2217c478bd9Sstevel@tonic-gate 	.section	".data"; \
2227c478bd9Sstevel@tonic-gate 	.global name; \
2237c478bd9Sstevel@tonic-gate 	.type	name, #object; \
2247c478bd9Sstevel@tonic-gate 	.size	name, sz; \
2257c478bd9Sstevel@tonic-gate name:
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #define	DGDEF3(name, sz, algn) \
2287c478bd9Sstevel@tonic-gate 	.section	".data"; \
2297c478bd9Sstevel@tonic-gate 	.align	algn; \
2307c478bd9Sstevel@tonic-gate 	.global name; \
2317c478bd9Sstevel@tonic-gate 	.type	name, #object; \
2327c478bd9Sstevel@tonic-gate 	.size	name, sz; \
2337c478bd9Sstevel@tonic-gate name:
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate #define	DGDEF(name)	DGDEF3(name, 4, 4)
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * SET_SIZE trails a function and set the size for the ELF symbol table.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate #define	SET_SIZE(x) \
2417c478bd9Sstevel@tonic-gate 	.size	x, (.-x)
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate #endif /* _ASM */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate #endif	/* _SYS_ASM_LINKAGE_H */
250