xref: /illumos-gate/usr/src/uts/sparc/sys/asm_linkage.h (revision 5d9d9091)
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
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * 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  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf  * 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 #include <sys/stack.h>
317c478bd9Sstevel@tonic-gate #include <sys/trap.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef _ASM	/* The remainder of this file is only for assembly files */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * C pointers are different sizes between V8 and V9.
417c478bd9Sstevel@tonic-gate  * These constants can be used to compute offsets into pointer arrays.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate #ifdef __sparcv9
447c478bd9Sstevel@tonic-gate #define	CPTRSHIFT	3
457c478bd9Sstevel@tonic-gate #define	CLONGSHIFT	3
467c478bd9Sstevel@tonic-gate #else
477c478bd9Sstevel@tonic-gate #define	CPTRSHIFT	2
487c478bd9Sstevel@tonic-gate #define	CLONGSHIFT	2
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate #define	CPTRSIZE	(1<<CPTRSHIFT)
517c478bd9Sstevel@tonic-gate #define	CLONGSIZE	(1<<CLONGSHIFT)
527c478bd9Sstevel@tonic-gate #define	CPTRMASK	(CPTRSIZE - 1)
537c478bd9Sstevel@tonic-gate #define	CLONGMASK	(CLONGSIZE - 1)
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Symbolic section definitions.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	RODATA	".rodata"
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * profiling causes defintions of the MCOUNT and RTMCOUNT
627c478bd9Sstevel@tonic-gate  * particular to the type
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate #ifdef GPROF
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(4*4)	/* 4 instructions */
677c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
687c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
697c478bd9Sstevel@tonic-gate 	call	_mcount; \
707c478bd9Sstevel@tonic-gate 	nop; \
717c478bd9Sstevel@tonic-gate 	restore;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #endif /* GPROF */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #ifdef PROF
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #if defined(__sparcv9)
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(9*4)	/* 9 instructions */
807c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
817c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
827c478bd9Sstevel@tonic-gate /* CSTYLED */ \
83*5d9d9091SRichard Lowe 	sethi	%hh(.L_##x##1), %o0; \
847c478bd9Sstevel@tonic-gate /* CSTYLED */ \
85*5d9d9091SRichard Lowe 	sethi	%lm(.L_##x##1), %o1; \
867c478bd9Sstevel@tonic-gate /* CSTYLED */ \
87*5d9d9091SRichard Lowe 	or	%o0, %hm(.L_##x##1), %o0; \
887c478bd9Sstevel@tonic-gate /* CSTYLED */ \
89*5d9d9091SRichard Lowe 	or	%o1, %lo(.L_##x##1), %o1; \
907c478bd9Sstevel@tonic-gate 	sllx	%o0, 32, %o0; \
917c478bd9Sstevel@tonic-gate 	call	_mcount; \
927c478bd9Sstevel@tonic-gate 	or	%o0, %o1, %o0; \
937c478bd9Sstevel@tonic-gate 	restore; \
947c478bd9Sstevel@tonic-gate /* CSTYLED */ \
95*5d9d9091SRichard Lowe 	.common .L_##x##1, 8, 8
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #else	/* __sparcv9 */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	(5*4)	/* 5 instructions */
1007c478bd9Sstevel@tonic-gate #define	MCOUNT(x) \
1017c478bd9Sstevel@tonic-gate 	save	%sp, -SA(MINFRAME), %sp; \
1027c478bd9Sstevel@tonic-gate /* CSTYLED */ \
103*5d9d9091SRichard Lowe 	sethi	%hi(.L_##x##1), %o0; \
1047c478bd9Sstevel@tonic-gate 	call	_mcount; \
1057c478bd9Sstevel@tonic-gate /* CSTYLED */ \
106*5d9d9091SRichard Lowe 	or	%o0, %lo(.L_##x##1), %o0; \
1077c478bd9Sstevel@tonic-gate 	restore; \
1087c478bd9Sstevel@tonic-gate /* CSTYLED */ \
109*5d9d9091SRichard Lowe 	.common .L_##x##1, 4, 4
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #endif	/* __sparcv9 */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #endif /* PROF */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * if we are not profiling, MCOUNT should be defined to nothing
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate #if !defined(PROF) && !defined(GPROF)
1197c478bd9Sstevel@tonic-gate #define	MCOUNT_SIZE	0	/* no instructions inserted */
1207c478bd9Sstevel@tonic-gate #define	MCOUNT(x)
1217c478bd9Sstevel@tonic-gate #endif /* !defined(PROF) && !defined(GPROF) */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define	RTMCOUNT(x)	MCOUNT(x)
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * Macro to define weak symbol aliases. These are similar to the ANSI-C
1277257d1b4Sraf  *	#pragma weak _name = name
1287c478bd9Sstevel@tonic-gate  * except a compiler can determine type. The assembler must be told. Hence,
1297c478bd9Sstevel@tonic-gate  * the second parameter must be the type of the symbol (i.e.: function,...)
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	ANSI_PRAGMA_WEAK(sym, stype)	\
1327c478bd9Sstevel@tonic-gate /* CSTYLED */ \
133*5d9d9091SRichard Lowe 	.weak	_##sym; \
1347257d1b4Sraf /* CSTYLED */ \
135*5d9d9091SRichard Lowe 	.type	_##sym, #stype; \
1367257d1b4Sraf /* CSTYLED */ \
137*5d9d9091SRichard Lowe _##sym = sym
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate  * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in:
1417c478bd9Sstevel@tonic-gate  *	#pragma weak sym1 = sym2
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate #define	ANSI_PRAGMA_WEAK2(sym1, sym2, stype)	\
1447c478bd9Sstevel@tonic-gate 	.weak	sym1; \
1457c478bd9Sstevel@tonic-gate 	.type sym1, #stype; \
1467c478bd9Sstevel@tonic-gate sym1	= sym2
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * ENTRY provides the standard procedure entry code and an easy way to
1507c478bd9Sstevel@tonic-gate  * insert the calls to mcount for profiling. ENTRY_NP is identical, but
1517c478bd9Sstevel@tonic-gate  * never calls mcount.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	ENTRY(x) \
1547c478bd9Sstevel@tonic-gate 	.section	".text"; \
1557c478bd9Sstevel@tonic-gate 	.align	4; \
1567c478bd9Sstevel@tonic-gate 	.global	x; \
1577c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1587c478bd9Sstevel@tonic-gate x:	MCOUNT(x)
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	ENTRY_SIZE	MCOUNT_SIZE
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #define	ENTRY_NP(x) \
1637c478bd9Sstevel@tonic-gate 	.section	".text"; \
1647c478bd9Sstevel@tonic-gate 	.align	4; \
1657c478bd9Sstevel@tonic-gate 	.global	x; \
1667c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1677c478bd9Sstevel@tonic-gate x:
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	RTENTRY(x) \
1707c478bd9Sstevel@tonic-gate 	.section	".text"; \
1717c478bd9Sstevel@tonic-gate 	.align	4; \
1727c478bd9Sstevel@tonic-gate 	.global	x; \
1737c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1747c478bd9Sstevel@tonic-gate x:	RTMCOUNT(x)
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * ENTRY2 is identical to ENTRY but provides two labels for the entry point.
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate #define	ENTRY2(x, y) \
1807c478bd9Sstevel@tonic-gate 	.section	".text"; \
1817c478bd9Sstevel@tonic-gate 	.align	4; \
1827c478bd9Sstevel@tonic-gate 	.global	x, y; \
1837c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1847c478bd9Sstevel@tonic-gate 	.type	y, #function; \
1857c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1867c478bd9Sstevel@tonic-gate x:	; \
1877c478bd9Sstevel@tonic-gate y:	MCOUNT(x)
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	ENTRY_NP2(x, y) \
1907c478bd9Sstevel@tonic-gate 	.section	".text"; \
1917c478bd9Sstevel@tonic-gate 	.align	4; \
1927c478bd9Sstevel@tonic-gate 	.global	x, y; \
1937c478bd9Sstevel@tonic-gate 	.type	x, #function; \
1947c478bd9Sstevel@tonic-gate 	.type	y, #function; \
1957c478bd9Sstevel@tonic-gate /* CSTYLED */ \
1967c478bd9Sstevel@tonic-gate x:	; \
1977c478bd9Sstevel@tonic-gate y:
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * ALTENTRY provides for additional entry points.
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate #define	ALTENTRY(x) \
2047c478bd9Sstevel@tonic-gate 	.global x; \
2057c478bd9Sstevel@tonic-gate 	.type	x, #function; \
2067c478bd9Sstevel@tonic-gate x:
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * DGDEF and DGDEF2 provide global data declarations.
2107c478bd9Sstevel@tonic-gate  *
2117c478bd9Sstevel@tonic-gate  * DGDEF provides a word aligned word of storage.
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  * DGDEF2 allocates "sz" bytes of storage with **NO** alignment.  This
2147c478bd9Sstevel@tonic-gate  * implies this macro is best used for byte arrays.
2157c478bd9Sstevel@tonic-gate  *
2167c478bd9Sstevel@tonic-gate  * DGDEF3 allocates "sz" bytes of storage with "algn" alignment.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate #define	DGDEF2(name, sz) \
2197c478bd9Sstevel@tonic-gate 	.section	".data"; \
2207c478bd9Sstevel@tonic-gate 	.global name; \
2217c478bd9Sstevel@tonic-gate 	.type	name, #object; \
2227c478bd9Sstevel@tonic-gate 	.size	name, sz; \
2237c478bd9Sstevel@tonic-gate name:
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #define	DGDEF3(name, sz, algn) \
2267c478bd9Sstevel@tonic-gate 	.section	".data"; \
2277c478bd9Sstevel@tonic-gate 	.align	algn; \
2287c478bd9Sstevel@tonic-gate 	.global name; \
2297c478bd9Sstevel@tonic-gate 	.type	name, #object; \
2307c478bd9Sstevel@tonic-gate 	.size	name, sz; \
2317c478bd9Sstevel@tonic-gate name:
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #define	DGDEF(name)	DGDEF3(name, 4, 4)
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * SET_SIZE trails a function and set the size for the ELF symbol table.
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate #define	SET_SIZE(x) \
2397c478bd9Sstevel@tonic-gate 	.size	x, (.-x)
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate #endif /* _ASM */
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate #endif
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate #endif	/* _SYS_ASM_LINKAGE_H */
248