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 _IA32_SYS_ASM_LINKAGE_H 287c478bd9Sstevel@tonic-gate #define _IA32_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 * make annoying differences in assembler syntax go away 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * D16 and A16 are used to insert instructions prefixes; the 477c478bd9Sstevel@tonic-gate * macros help the assembler code be slightly more portable. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate #if !defined(__GNUC_AS__) 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * /usr/ccs/bin/as prefixes are parsed as separate instructions 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #define D16 data16; 547c478bd9Sstevel@tonic-gate #define A16 addr16; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * (There are some weird constructs in constant expressions) 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate #define _CONST(const) [const] 607c478bd9Sstevel@tonic-gate #define _BITNOT(const) -1!_CONST(const) 617c478bd9Sstevel@tonic-gate #define _MUL(a, b) _CONST(a \* b) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #else 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Why not use the 'data16' and 'addr16' prefixes .. well, the 667c478bd9Sstevel@tonic-gate * assembler doesn't quite believe in real mode, and thus argues with 677c478bd9Sstevel@tonic-gate * us about what we're trying to do. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate #define D16 .byte 0x66; 707c478bd9Sstevel@tonic-gate #define A16 .byte 0x67; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #define _CONST(const) (const) 737c478bd9Sstevel@tonic-gate #define _BITNOT(const) ~_CONST(const) 747c478bd9Sstevel@tonic-gate #define _MUL(a, b) _CONST(a * b) 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #endif 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * C pointers are different sizes between i386 and amd64. 807c478bd9Sstevel@tonic-gate * These constants can be used to compute offsets into pointer arrays. 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate #if defined(__amd64) 837c478bd9Sstevel@tonic-gate #define CLONGSHIFT 3 847c478bd9Sstevel@tonic-gate #define CLONGSIZE 8 857c478bd9Sstevel@tonic-gate #define CLONGMASK 7 867c478bd9Sstevel@tonic-gate #elif defined(__i386) 877c478bd9Sstevel@tonic-gate #define CLONGSHIFT 2 887c478bd9Sstevel@tonic-gate #define CLONGSIZE 4 897c478bd9Sstevel@tonic-gate #define CLONGMASK 3 907c478bd9Sstevel@tonic-gate #endif 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * Since we know we're either ILP32 or LP64 .. 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate #define CPTRSHIFT CLONGSHIFT 967c478bd9Sstevel@tonic-gate #define CPTRSIZE CLONGSIZE 977c478bd9Sstevel@tonic-gate #define CPTRMASK CLONGMASK 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate #if CPTRSIZE != (1 << CPTRSHIFT) || CLONGSIZE != (1 << CLONGSHIFT) 1007c478bd9Sstevel@tonic-gate #error "inconsistent shift constants" 1017c478bd9Sstevel@tonic-gate #endif 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #if CPTRMASK != (CPTRSIZE - 1) || CLONGMASK != (CLONGSIZE - 1) 1047c478bd9Sstevel@tonic-gate #error "inconsistent mask constants" 1057c478bd9Sstevel@tonic-gate #endif 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #define ASM_ENTRY_ALIGN 16 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * SSE register alignment and save areas 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #define XMM_SIZE 16 1147c478bd9Sstevel@tonic-gate #define XMM_ALIGN 16 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #if defined(__amd64) 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #define SAVE_XMM_PROLOG(sreg, nreg) \ 1197c478bd9Sstevel@tonic-gate subq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp; \ 1207c478bd9Sstevel@tonic-gate movq %rsp, sreg 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #define RSTOR_XMM_EPILOG(sreg, nreg) \ 1237c478bd9Sstevel@tonic-gate addq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate #elif defined(__i386) 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define SAVE_XMM_PROLOG(sreg, nreg) \ 1287c478bd9Sstevel@tonic-gate subl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp; \ 1297c478bd9Sstevel@tonic-gate movl %esp, sreg; \ 1307c478bd9Sstevel@tonic-gate addl $XMM_ALIGN, sreg; \ 1317c478bd9Sstevel@tonic-gate andl $_BITNOT(XMM_ALIGN-1), sreg 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate #define RSTOR_XMM_EPILOG(sreg, nreg) \ 1347c478bd9Sstevel@tonic-gate addl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #endif /* __i386 */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * profiling causes definitions of the MCOUNT and RTMCOUNT 1407c478bd9Sstevel@tonic-gate * particular to the type 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate #ifdef GPROF 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate #define MCOUNT(x) \ 1457c478bd9Sstevel@tonic-gate pushl %ebp; \ 1467c478bd9Sstevel@tonic-gate movl %esp, %ebp; \ 1477c478bd9Sstevel@tonic-gate call _mcount; \ 1487c478bd9Sstevel@tonic-gate popl %ebp 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate #endif /* GPROF */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #ifdef PROF 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define MCOUNT(x) \ 1557c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1567c478bd9Sstevel@tonic-gate .lcomm .L_/**/x/**/1, 4, 4; \ 1577c478bd9Sstevel@tonic-gate pushl %ebp; \ 1587c478bd9Sstevel@tonic-gate movl %esp, %ebp; \ 1597c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 1607c478bd9Sstevel@tonic-gate movl $.L_/**/x/**/1, %edx; \ 1617c478bd9Sstevel@tonic-gate call _mcount; \ 1627c478bd9Sstevel@tonic-gate popl %ebp 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #endif /* PROF */ 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * if we are not profiling, MCOUNT should be defined to nothing 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate #if !defined(PROF) && !defined(GPROF) 1707c478bd9Sstevel@tonic-gate #define MCOUNT(x) 1717c478bd9Sstevel@tonic-gate #endif /* !defined(PROF) && !defined(GPROF) */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate #define RTMCOUNT(x) MCOUNT(x) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * Macro to define weak symbol aliases. These are similar to the ANSI-C 177*7257d1b4Sraf * #pragma weak _name = name 1787c478bd9Sstevel@tonic-gate * except a compiler can determine type. The assembler must be told. Hence, 1797c478bd9Sstevel@tonic-gate * the second parameter must be the type of the symbol (i.e.: function,...) 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate #define ANSI_PRAGMA_WEAK(sym, stype) \ 1827c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 183*7257d1b4Sraf .weak _/**/sym; \ 184*7257d1b4Sraf /* CSTYLED */ \ 185*7257d1b4Sraf .type _/**/sym, @stype; \ 186*7257d1b4Sraf /* CSTYLED */ \ 187*7257d1b4Sraf _/**/sym = sym 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* 1907c478bd9Sstevel@tonic-gate * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in: 1917c478bd9Sstevel@tonic-gate * #pragma weak sym1 = sym2 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate #define ANSI_PRAGMA_WEAK2(sym1, sym2, stype) \ 1947c478bd9Sstevel@tonic-gate .weak sym1; \ 1957c478bd9Sstevel@tonic-gate .type sym1, @stype; \ 1967c478bd9Sstevel@tonic-gate sym1 = sym2 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * ENTRY provides the standard procedure entry code and an easy way to 2007c478bd9Sstevel@tonic-gate * insert the calls to mcount for profiling. ENTRY_NP is identical, but 2017c478bd9Sstevel@tonic-gate * never calls mcount. 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate #define ENTRY(x) \ 2047c478bd9Sstevel@tonic-gate .text; \ 2057c478bd9Sstevel@tonic-gate .align ASM_ENTRY_ALIGN; \ 2067c478bd9Sstevel@tonic-gate .globl x; \ 2077c478bd9Sstevel@tonic-gate .type x, @function; \ 2087c478bd9Sstevel@tonic-gate x: MCOUNT(x) 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #define ENTRY_NP(x) \ 2117c478bd9Sstevel@tonic-gate .text; \ 2127c478bd9Sstevel@tonic-gate .align ASM_ENTRY_ALIGN; \ 2137c478bd9Sstevel@tonic-gate .globl x; \ 2147c478bd9Sstevel@tonic-gate .type x, @function; \ 2157c478bd9Sstevel@tonic-gate x: 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #define RTENTRY(x) \ 2187c478bd9Sstevel@tonic-gate .text; \ 2197c478bd9Sstevel@tonic-gate .align ASM_ENTRY_ALIGN; \ 2207c478bd9Sstevel@tonic-gate .globl x; \ 2217c478bd9Sstevel@tonic-gate .type x, @function; \ 2227c478bd9Sstevel@tonic-gate x: RTMCOUNT(x) 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * ENTRY2 is identical to ENTRY but provides two labels for the entry point. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate #define ENTRY2(x, y) \ 2287c478bd9Sstevel@tonic-gate .text; \ 2297c478bd9Sstevel@tonic-gate .align ASM_ENTRY_ALIGN; \ 2307c478bd9Sstevel@tonic-gate .globl x, y; \ 2317c478bd9Sstevel@tonic-gate .type x, @function; \ 2327c478bd9Sstevel@tonic-gate .type y, @function; \ 2337c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2347c478bd9Sstevel@tonic-gate x: ; \ 2357c478bd9Sstevel@tonic-gate y: MCOUNT(x) 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate #define ENTRY_NP2(x, y) \ 2387c478bd9Sstevel@tonic-gate .text; \ 2397c478bd9Sstevel@tonic-gate .align ASM_ENTRY_ALIGN; \ 2407c478bd9Sstevel@tonic-gate .globl x, y; \ 2417c478bd9Sstevel@tonic-gate .type x, @function; \ 2427c478bd9Sstevel@tonic-gate .type y, @function; \ 2437c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 2447c478bd9Sstevel@tonic-gate x: ; \ 2457c478bd9Sstevel@tonic-gate y: 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * ALTENTRY provides for additional entry points. 2507c478bd9Sstevel@tonic-gate */ 2517c478bd9Sstevel@tonic-gate #define ALTENTRY(x) \ 2527c478bd9Sstevel@tonic-gate .globl x; \ 2537c478bd9Sstevel@tonic-gate .type x, @function; \ 2547c478bd9Sstevel@tonic-gate x: 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * DGDEF and DGDEF2 provide global data declarations. 2587c478bd9Sstevel@tonic-gate * 2597c478bd9Sstevel@tonic-gate * DGDEF provides a word aligned word of storage. 2607c478bd9Sstevel@tonic-gate * 2617c478bd9Sstevel@tonic-gate * DGDEF2 allocates "sz" bytes of storage with **NO** alignment. This 2627c478bd9Sstevel@tonic-gate * implies this macro is best used for byte arrays. 2637c478bd9Sstevel@tonic-gate * 2647c478bd9Sstevel@tonic-gate * DGDEF3 allocates "sz" bytes of storage with "algn" alignment. 2657c478bd9Sstevel@tonic-gate */ 2667c478bd9Sstevel@tonic-gate #define DGDEF2(name, sz) \ 2677c478bd9Sstevel@tonic-gate .data; \ 2687c478bd9Sstevel@tonic-gate .globl name; \ 2697c478bd9Sstevel@tonic-gate .type name, @object; \ 2707c478bd9Sstevel@tonic-gate .size name, sz; \ 2717c478bd9Sstevel@tonic-gate name: 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #define DGDEF3(name, sz, algn) \ 2747c478bd9Sstevel@tonic-gate .data; \ 2757c478bd9Sstevel@tonic-gate .align algn; \ 2767c478bd9Sstevel@tonic-gate .globl name; \ 2777c478bd9Sstevel@tonic-gate .type name, @object; \ 2787c478bd9Sstevel@tonic-gate .size name, sz; \ 2797c478bd9Sstevel@tonic-gate name: 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate #define DGDEF(name) DGDEF3(name, 4, 4) 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * SET_SIZE trails a function and set the size for the ELF symbol table. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate #define SET_SIZE(x) \ 2877c478bd9Sstevel@tonic-gate .size x, [.-x] 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate /* 2907c478bd9Sstevel@tonic-gate * NWORD provides native word value. 2917c478bd9Sstevel@tonic-gate */ 2927c478bd9Sstevel@tonic-gate #if defined(__amd64) 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate /*CSTYLED*/ 2957c478bd9Sstevel@tonic-gate #define NWORD quad 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate #elif defined(__i386) 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate #define NWORD long 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate #endif /* __i386 */ 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate #endif /* _ASM */ 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate #endif 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate #endif /* _IA32_SYS_ASM_LINKAGE_H */ 310