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