1 /* $NetBSD: asm.h,v 1.25 2003/05/02 18:05:46 yamt Exp $ */ 2 3 /*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * William Jolitz. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)asm.h 5.5 (Berkeley) 5/7/91 39 */ 40 41 #ifndef _I386_ASM_H_ 42 #define _I386_ASM_H_ 43 44 #ifdef _KERNEL_OPT 45 #include "opt_multiprocessor.h" 46 #endif 47 48 #ifdef PIC 49 #define PIC_PROLOGUE \ 50 pushl %ebx; \ 51 call 1f; \ 52 1: \ 53 popl %ebx; \ 54 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx 55 #define PIC_EPILOGUE \ 56 popl %ebx 57 #define PIC_PLT(x) x@PLT 58 #define PIC_GOT(x) x@GOT(%ebx) 59 #define PIC_GOTOFF(x) x@GOTOFF(%ebx) 60 #else 61 #define PIC_PROLOGUE 62 #define PIC_EPILOGUE 63 #define PIC_PLT(x) x 64 #define PIC_GOT(x) x 65 #define PIC_GOTOFF(x) x 66 #endif 67 68 #ifdef __ELF__ 69 # define _C_LABEL(x) x 70 #else 71 # ifdef __STDC__ 72 # define _C_LABEL(x) _ ## x 73 # else 74 # define _C_LABEL(x) _/**/x 75 # endif 76 #endif 77 #define _ASM_LABEL(x) x 78 79 #define CVAROFF(x, y) _C_LABEL(x) + y 80 81 #ifdef __STDC__ 82 # define __CONCAT(x,y) x ## y 83 # define __STRING(x) #x 84 #else 85 # define __CONCAT(x,y) x/**/y 86 # define __STRING(x) "x" 87 #endif 88 89 /* let kernels and others override entrypoint alignment */ 90 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL) 91 # ifdef __ELF__ 92 # define _ALIGN_TEXT .align 4 93 # else 94 # define _ALIGN_TEXT .align 2 95 # endif 96 #endif 97 98 #define _ENTRY(x) \ 99 .text; _ALIGN_TEXT; .globl x; .type x,@function; x: 100 101 #ifdef _KERNEL 102 103 #if defined(MULTIPROCESSOR) 104 #define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off) 105 #else 106 #define CPUVAR(off) _C_LABEL(cpu_info_primary)+__CONCAT(CPU_INFO_,off) 107 #endif /* MULTIPROCESSOR */ 108 109 /* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */ 110 #ifdef __ELF__ 111 #ifdef __STDC__ 112 #define IDTVEC(name) \ 113 ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name: 114 #else 115 #define IDTVEC(name) \ 116 ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name: 117 #endif /* __STDC__ */ 118 #else 119 #ifdef __STDC__ 120 #define IDTVEC(name) \ 121 ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name: 122 #else 123 #define IDTVEC(name) \ 124 ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name: 125 #endif /* __STDC__ */ 126 #endif /* __ELF__ */ 127 128 #ifdef __ELF__ 129 #define ALIGN_DATA .align 4 130 #define ALIGN_TEXT .align 4,0x90 /* 4-byte boundaries, NOP-filled */ 131 #define SUPERALIGN_TEXT .align 16,0x90 /* 16-byte boundaries better for 486 */ 132 #else 133 #define ALIGN_DATA .align 2 134 #define ALIGN_TEXT .align 2,0x90 /* 4-byte boundaries, NOP-filled */ 135 #define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte boundaries better for 486 */ 136 #endif /* __ELF__ */ 137 138 #define _ALIGN_TEXT ALIGN_TEXT 139 140 #endif /* _KERNEL */ 141 142 143 144 #ifdef GPROF 145 # ifdef __ELF__ 146 # define _PROF_PROLOGUE \ 147 pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp 148 # else 149 # define _PROF_PROLOGUE \ 150 pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp 151 # endif 152 #else 153 # define _PROF_PROLOGUE 154 #endif 155 156 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE 157 #define NENTRY(y) _ENTRY(_C_LABEL(y)) 158 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE 159 160 #define ASMSTR .asciz 161 162 #ifdef __ELF__ 163 #define RCSID(x) .section ".ident"; .asciz x 164 #else 165 #define RCSID(x) .text; .asciz x 166 #endif 167 168 #ifdef NO_KERNEL_RCSIDS 169 #define __KERNEL_RCSID(_n, _s) /* nothing */ 170 #else 171 #define __KERNEL_RCSID(_n, _s) RCSID(_s) 172 #endif 173 174 #ifdef __ELF__ 175 #define WEAK_ALIAS(alias,sym) \ 176 .weak alias; \ 177 alias = sym 178 #endif 179 180 #ifdef __STDC__ 181 #define WARN_REFERENCES(sym,msg) \ 182 .stabs msg ## ,30,0,0,0 ; \ 183 .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0 184 #elif defined(__ELF__) 185 #define WARN_REFERENCES(sym,msg) \ 186 .stabs msg,30,0,0,0 ; \ 187 .stabs __STRING(sym),1,0,0,0 188 #else 189 #define WARN_REFERENCES(sym,msg) \ 190 .stabs msg,30,0,0,0 ; \ 191 .stabs __STRING(_/**/sym),1,0,0,0 192 #endif /* __STDC__ */ 193 194 195 196 #endif /* !_I386_ASM_H_ */ 197