1 /* $OpenBSD: asm.h,v 1.13 2017/06/29 17:36:16 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 /* Pull in CCFSZ, CC64FSZ, and BIAS from frame.h */ 45 #ifndef _LOCORE 46 #define _LOCORE 47 #endif 48 #include <machine/frame.h> 49 50 #define _C_LABEL(name) name 51 #define _ASM_LABEL(name) name 52 53 #ifdef __PIC__ 54 /* 55 * PIC_PROLOGUE() is akin to the compiler generated function prologue for 56 * PIC code. It leaves the address of the Global Offset Table in DEST, 57 * clobbering register TMP in the process. Using the temporary enables us 58 * to work without a stack frame (doing so requires saving %o7) . 59 */ 60 #define PIC_PROLOGUE(dest,tmp) \ 61 sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \ 62 rd %pc, tmp; \ 63 or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \ 64 add dest,tmp,dest 65 66 /* 67 * PICCY_SET() does the equivalent of a `set var, %dest' instruction in 68 * a PIC-like way, but without involving the Global Offset Table. This 69 * only works for VARs defined in the same file *and* in the text segment. 70 */ 71 #define PICCY_SET(var,dest,tmp) \ 72 3: rd %pc, tmp; add tmp,(var-3b),dest 73 #else 74 #define PIC_PROLOGUE(dest,tmp) 75 #define PICCY_OFFSET(var,dest,tmp) 76 #endif 77 78 #define FTYPE(x) .type x,@function 79 #define OTYPE(x) .type x,@object 80 81 #define _ENTRY(name) \ 82 .align 4; .globl name; .proc 1; FTYPE(name); name: 83 84 #if defined(PROF) || defined(GPROF) 85 #define _PROF_PROLOGUE \ 86 .data; .align 8; 1: .uaword 0; .uaword 0; \ 87 .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \ 88 or %o0,%lo(1b),%o0; restore 89 #else 90 #define _PROF_PROLOGUE 91 #endif 92 93 #define ENTRY(name) _ENTRY(_C_LABEL(name)); _PROF_PROLOGUE 94 #define NENTRY(name) _ENTRY(_C_LABEL(name)) 95 #define ASENTRY(name) _ENTRY(_ASM_LABEL(name)); _PROF_PROLOGUE 96 #define FUNC(name) ASENTRY(name) 97 #define END(y) .size y, . - y 98 #define RODATA(name) .align 4; .text; .globl _C_LABEL(name); \ 99 OTYPE(_C_LABEL(name)); _C_LABEL(name): 100 101 #define STRONG_ALIAS(alias,sym) \ 102 .global alias; \ 103 alias = sym 104 #define WEAK_ALIAS(alias,sym) \ 105 .weak alias; \ 106 alias = sym 107 108 /* 109 * WARN_REFERENCES: create a warning if the specified symbol is referenced. 110 */ 111 #ifdef __STDC__ 112 #define WARN_REFERENCES(_sym,_msg) \ 113 .section .gnu.warning. ## _sym ; .ascii _msg ; .text 114 #else 115 #define WARN_REFERENCES(_sym,_msg) \ 116 .section .gnu.warning./**/_sym ; .ascii _msg ; .text 117 #endif /* __STDC__ */ 118 119 #endif /* _MACHINE_ASM_H_ */ 120