1 /* $OpenBSD: asm.h,v 1.10 2016/05/27 16:32:39 deraadt Exp $ */ 2 /* $NetBSD: asm.h,v 1.15 2000/08/02 22:24:39 eeh Exp $ */ 3 4 /* 5 * Copyright (c) 1994 Allen Briggs 6 * All rights reserved. 7 * 8 * Gleaned from locore.s and sun3 asm.h which had the following copyrights: 9 * locore.s: 10 * Copyright (c) 1988 University of Utah. 11 * Copyright (c) 1982, 1990 The Regents of the University of California. 12 * sun3/include/asm.h: 13 * Copyright (c) 1993 Adam Glass 14 * Copyright (c) 1990 The Regents of the University of California. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution. 24 * 3. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 */ 40 41 #ifndef _MACHINE_ASM_H_ 42 #define _MACHINE_ASM_H_ 43 44 #ifndef _LOCORE 45 #define _LOCORE 46 #endif 47 #include <machine/frame.h> 48 49 /* Pull in CCFSZ, CC64FSZ, and BIAS from frame.h */ 50 #ifndef _LOCORE 51 #define _LOCORE 52 #endif 53 #include <machine/frame.h> 54 55 #define _C_LABEL(name) name 56 #define _ASM_LABEL(name) name 57 58 #ifdef __PIC__ 59 /* 60 * PIC_PROLOGUE() is akin to the compiler generated function prologue for 61 * PIC code. It leaves the address of the Global Offset Table in DEST, 62 * clobbering register TMP in the process. Using the temporary enables us 63 * to work without a stack frame (doing so requires saving %o7) . 64 */ 65 #define PIC_PROLOGUE(dest,tmp) \ 66 sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \ 67 rd %pc, tmp; \ 68 or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \ 69 add dest,tmp,dest 70 71 /* 72 * PICCY_SET() does the equivalent of a `set var, %dest' instruction in 73 * a PIC-like way, but without involving the Global Offset Table. This 74 * only works for VARs defined in the same file *and* in the text segment. 75 */ 76 #define PICCY_SET(var,dest,tmp) \ 77 3: rd %pc, tmp; add tmp,(var-3b),dest 78 #else 79 #define PIC_PROLOGUE(dest,tmp) 80 #define PICCY_OFFSET(var,dest,tmp) 81 #endif 82 83 #define FTYPE(x) .type x,@function 84 #define OTYPE(x) .type x,@object 85 86 #define _ENTRY(name) \ 87 .align 4; .globl name; .proc 1; FTYPE(name); name: 88 89 #ifdef GPROF 90 #define _PROF_PROLOGUE \ 91 .data; .align 8; 1: .uaword 0; .uaword 0; \ 92 .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \ 93 or %o0,%lo(1b),%o0; restore 94 #else 95 #define _PROF_PROLOGUE 96 #endif 97 98 #define ENTRY(name) _ENTRY(_C_LABEL(name)); _PROF_PROLOGUE 99 #define NENTRY(name) _ENTRY(_C_LABEL(name)) 100 #define ASENTRY(name) _ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE 101 #define FUNC(name) ASENTRY(name) 102 #define END(y) .size y, . - y 103 #define RODATA(name) .align 4; .text; .globl _C_LABEL(name); \ 104 OTYPE(_C_LABEL(name)); _C_LABEL(name): 105 106 107 #define ASMSTR .asciz 108 109 #define RCSID(name) .asciz name 110 111 #define STRONG_ALIAS(alias,sym) \ 112 .global alias; \ 113 alias = sym 114 #define WEAK_ALIAS(alias,sym) \ 115 .weak alias; \ 116 alias = sym 117 118 /* 119 * WARN_REFERENCES: create a warning if the specified symbol is referenced. 120 */ 121 #ifdef __STDC__ 122 #define WARN_REFERENCES(_sym,_msg) \ 123 .section .gnu.warning. ## _sym ; .ascii _msg ; .text 124 #else 125 #define WARN_REFERENCES(_sym,_msg) \ 126 .section .gnu.warning./**/_sym ; .ascii _msg ; .text 127 #endif /* __STDC__ */ 128 129 #endif /* _MACHINE_ASM_H_ */ 130