1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 #ifndef _IA32_SYS_ASM_LINKAGE_H 29 #define _IA32_SYS_ASM_LINKAGE_H 30 31 #if defined(_KERNEL) && defined(__linux__) 32 #include <linux/linkage.h> 33 #endif 34 35 #ifndef ENDBR 36 #if defined(__ELF__) && defined(__CET__) && defined(__has_include) 37 /* CSTYLED */ 38 #if __has_include(<cet.h>) 39 40 #include <cet.h> 41 42 #ifdef _CET_ENDBR 43 #define ENDBR _CET_ENDBR 44 #endif /* _CET_ENDBR */ 45 46 #endif /* <cet.h> */ 47 #endif /* __ELF__ && __CET__ && __has_include */ 48 #endif /* !ENDBR */ 49 50 #ifndef ENDBR 51 #define ENDBR 52 #endif 53 #ifndef RET 54 #define RET ret 55 #endif 56 57 /* You can set to nothing on Unix platforms */ 58 #undef ASMABI 59 #define ASMABI __attribute__((sysv_abi)) 60 61 #define SECTION_TEXT .text 62 #define SECTION_STATIC .section .rodata 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 #ifdef _ASM /* The remainder of this file is only for assembly files */ 69 70 /* 71 * make annoying differences in assembler syntax go away 72 */ 73 74 /* 75 * D16 and A16 are used to insert instructions prefixes; the 76 * macros help the assembler code be slightly more portable. 77 */ 78 #if !defined(__GNUC_AS__) 79 /* 80 * /usr/ccs/bin/as prefixes are parsed as separate instructions 81 */ 82 #define D16 data16; 83 #define A16 addr16; 84 85 /* 86 * (There are some weird constructs in constant expressions) 87 */ 88 #define _CONST(const) [const] 89 #define _BITNOT(const) -1!_CONST(const) 90 #define _MUL(a, b) _CONST(a \* b) 91 92 #else 93 /* 94 * Why not use the 'data16' and 'addr16' prefixes .. well, the 95 * assembler doesn't quite believe in real mode, and thus argues with 96 * us about what we're trying to do. 97 */ 98 #define D16 .byte 0x66; 99 #define A16 .byte 0x67; 100 101 #define _CONST(const) (const) 102 #define _BITNOT(const) ~_CONST(const) 103 #define _MUL(a, b) _CONST(a * b) 104 105 #endif 106 107 /* 108 * C pointers are different sizes between i386 and amd64. 109 * These constants can be used to compute offsets into pointer arrays. 110 */ 111 #if defined(__amd64) 112 #define CLONGSHIFT 3 113 #define CLONGSIZE 8 114 #define CLONGMASK 7 115 #elif defined(__i386) 116 #define CLONGSHIFT 2 117 #define CLONGSIZE 4 118 #define CLONGMASK 3 119 #endif 120 121 /* 122 * Since we know we're either ILP32 or LP64 .. 123 */ 124 #define CPTRSHIFT CLONGSHIFT 125 #define CPTRSIZE CLONGSIZE 126 #define CPTRMASK CLONGMASK 127 128 #if CPTRSIZE != (1 << CPTRSHIFT) || CLONGSIZE != (1 << CLONGSHIFT) 129 #error "inconsistent shift constants" 130 #endif 131 132 #if CPTRMASK != (CPTRSIZE - 1) || CLONGMASK != (CLONGSIZE - 1) 133 #error "inconsistent mask constants" 134 #endif 135 136 #define ASM_ENTRY_ALIGN 16 137 138 /* 139 * SSE register alignment and save areas 140 */ 141 142 #define XMM_SIZE 16 143 #define XMM_ALIGN 16 144 145 /* 146 * ENTRY provides the standard procedure entry code and an easy way to 147 * insert the calls to mcount for profiling. ENTRY_NP is identical, but 148 * never calls mcount. 149 */ 150 #undef ENTRY 151 #define ENTRY(x) \ 152 .text; \ 153 .balign ASM_ENTRY_ALIGN; \ 154 .globl x; \ 155 .type x, @function; \ 156 x: MCOUNT(x) 157 158 #define ENTRY_NP(x) \ 159 .text; \ 160 .balign ASM_ENTRY_ALIGN; \ 161 .globl x; \ 162 .type x, @function; \ 163 x: 164 165 #define ENTRY_ALIGN(x, a) \ 166 .text; \ 167 .balign a; \ 168 .globl x; \ 169 .type x, @function; \ 170 x: 171 172 #define FUNCTION(x) \ 173 .type x, @function; \ 174 x: 175 176 /* 177 * ENTRY2 is identical to ENTRY but provides two labels for the entry point. 178 */ 179 #define ENTRY2(x, y) \ 180 .text; \ 181 .balign ASM_ENTRY_ALIGN; \ 182 .globl x, y; \ 183 .type x, @function; \ 184 .type y, @function; \ 185 x:; \ 186 y: MCOUNT(x) 187 188 #define ENTRY_NP2(x, y) \ 189 .text; \ 190 .balign ASM_ENTRY_ALIGN; \ 191 .globl x, y; \ 192 .type x, @function; \ 193 .type y, @function; \ 194 x:; \ 195 y: 196 197 198 /* 199 * SET_SIZE trails a function and set the size for the ELF symbol table. 200 */ 201 #define SET_SIZE(x) \ 202 .size x, [.-x] 203 204 #define SET_OBJ(x) .type x, @object 205 206 207 #endif /* _ASM */ 208 209 #ifdef __cplusplus 210 } 211 #endif 212 213 #endif /* _IA32_SYS_ASM_LINKAGE_H */ 214