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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 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 #include <sys/stack.h> 31 #include <sys/trap.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #ifdef _ASM /* The remainder of this file is only for assembly files */ 38 39 /* 40 * C pointers are different sizes between V8 and V9. 41 * These constants can be used to compute offsets into pointer arrays. 42 */ 43 #ifdef __sparcv9 44 #define CPTRSHIFT 3 45 #define CLONGSHIFT 3 46 #else 47 #define CPTRSHIFT 2 48 #define CLONGSHIFT 2 49 #endif 50 #define CPTRSIZE (1<<CPTRSHIFT) 51 #define CLONGSIZE (1<<CLONGSHIFT) 52 #define CPTRMASK (CPTRSIZE - 1) 53 #define CLONGMASK (CLONGSIZE - 1) 54 55 /* 56 * Symbolic section definitions. 57 */ 58 #define RODATA ".rodata" 59 60 /* 61 * profiling causes defintions of the MCOUNT and RTMCOUNT 62 * particular to the type 63 */ 64 #ifdef GPROF 65 66 #define MCOUNT_SIZE (4*4) /* 4 instructions */ 67 #define MCOUNT(x) \ 68 save %sp, -SA(MINFRAME), %sp; \ 69 call _mcount; \ 70 nop; \ 71 restore; 72 73 #endif /* GPROF */ 74 75 #ifdef PROF 76 77 #if defined(__sparcv9) 78 79 #define MCOUNT_SIZE (9*4) /* 9 instructions */ 80 #define MCOUNT(x) \ 81 save %sp, -SA(MINFRAME), %sp; \ 82 /* CSTYLED */ \ 83 sethi %hh(.L_##x##1), %o0; \ 84 /* CSTYLED */ \ 85 sethi %lm(.L_##x##1), %o1; \ 86 /* CSTYLED */ \ 87 or %o0, %hm(.L_##x##1), %o0; \ 88 /* CSTYLED */ \ 89 or %o1, %lo(.L_##x##1), %o1; \ 90 sllx %o0, 32, %o0; \ 91 call _mcount; \ 92 or %o0, %o1, %o0; \ 93 restore; \ 94 /* CSTYLED */ \ 95 .common .L_##x##1, 8, 8 96 97 #else /* __sparcv9 */ 98 99 #define MCOUNT_SIZE (5*4) /* 5 instructions */ 100 #define MCOUNT(x) \ 101 save %sp, -SA(MINFRAME), %sp; \ 102 /* CSTYLED */ \ 103 sethi %hi(.L_##x##1), %o0; \ 104 call _mcount; \ 105 /* CSTYLED */ \ 106 or %o0, %lo(.L_##x##1), %o0; \ 107 restore; \ 108 /* CSTYLED */ \ 109 .common .L_##x##1, 4, 4 110 111 #endif /* __sparcv9 */ 112 113 #endif /* PROF */ 114 115 /* 116 * if we are not profiling, MCOUNT should be defined to nothing 117 */ 118 #if !defined(PROF) && !defined(GPROF) 119 #define MCOUNT_SIZE 0 /* no instructions inserted */ 120 #define MCOUNT(x) 121 #endif /* !defined(PROF) && !defined(GPROF) */ 122 123 #define RTMCOUNT(x) MCOUNT(x) 124 125 /* 126 * Macro to define weak symbol aliases. These are similar to the ANSI-C 127 * #pragma weak _name = name 128 * except a compiler can determine type. The assembler must be told. Hence, 129 * the second parameter must be the type of the symbol (i.e.: function,...) 130 */ 131 #define ANSI_PRAGMA_WEAK(sym, stype) \ 132 /* CSTYLED */ \ 133 .weak _##sym; \ 134 /* CSTYLED */ \ 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