1 /* $OpenBSD: asm.h,v 1.5 2016/05/27 16:32:38 deraadt Exp $ */ 2 /* $NetBSD: asm.h,v 1.25 2006/01/20 22:02:40 christos Exp $ */ 3 4 /*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * William Jolitz. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)asm.h 5.5 (Berkeley) 5/7/91 36 */ 37 38 #ifndef _SH_ASM_H_ 39 #define _SH_ASM_H_ 40 41 #define _C_LABEL(x) x 42 #define _ASM_LABEL(x) x 43 44 #ifdef __STDC__ 45 # define __CONCAT(x,y) x ## y 46 # define __STRING(x) #x 47 #else 48 # define __CONCAT(x,y) x/**/y 49 # define __STRING(x) "x" 50 #endif 51 52 /* let kernels and others override entrypoint alignment */ 53 #ifndef _ALIGN_TEXT 54 # define _ALIGN_TEXT .align 2 55 #endif 56 57 #define _ENTRY(x) \ 58 .text ;\ 59 _ALIGN_TEXT ;\ 60 .globl x ;\ 61 .type x,@function ;\ 62 x: 63 64 #ifdef GPROF 65 #define _PROF_PROLOGUE \ 66 mov.l 1f,r1 ; \ 67 mova 2f,r0 ; \ 68 jmp @r1 ; \ 69 nop ; \ 70 .align 2 ; \ 71 1: .long __mcount ; \ 72 2: 73 #else /* !GPROF */ 74 #define _PROF_PROLOGUE 75 #endif /* !GPROF */ 76 77 #define ENTRY(y) _ENTRY(_C_LABEL(y)) _PROF_PROLOGUE 78 #define NENTRY(y) _ENTRY(_C_LABEL(y)) 79 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)) _PROF_PROLOGUE 80 81 #define SET_ENTRY_SIZE(y) \ 82 .size _C_LABEL(y), . - _C_LABEL(y) 83 84 #define SET_ASENTRY_SIZE(y) \ 85 .size _ASM_LABEL(y), . - _ASM_LABEL(y) 86 87 #define ALTENTRY(name) \ 88 .globl _C_LABEL(name) ;\ 89 .type _C_LABEL(name),@function ;\ 90 _C_LABEL(name): 91 92 /* 93 * Hide the gory details of PIC calls vs. normal calls. Use as in the 94 * following example: 95 * 96 * sts.l pr, @-sp 97 * PIC_PROLOGUE(.L_got, r0) ! saves old r12 on stack 98 * ... 99 * mov.l .L_function_1, r0 100 * 1: CALL r0 ! each call site needs a label 101 * nop 102 * ... 103 * mov.l .L_function_2, r0 104 * 2: CALL r0 105 * nop 106 * ... 107 * PIC_EPILOGUE ! restores r12 from stack 108 * lds.l @sp+, pr ! so call in right order 109 * rts 110 * nop 111 * 112 * .align 2 113 * .L_got: 114 * PIC_GOT_DATUM 115 * .L_function_1: ! if you call the same function twice 116 * CALL_DATUM(function, 1b) ! provide call datum for each call 117 * .L_function_2: 118 * CALL_DATUM(function, 2b) 119 */ 120 121 #ifdef __PIC__ 122 123 #define PIC_PLT(x) x@PLT 124 #define PIC_GOT(x) x@GOT 125 #define PIC_GOTOFF(x) x@GOTOFF 126 127 #define PIC_PROLOGUE(got) \ 128 mov.l r12, @-sp; \ 129 PIC_PROLOGUE_NOSAVE(got) 130 131 /* 132 * Functions that do non local jumps don't need to preserve r12, 133 * so we can shave off two instructions to save/restore it. 134 */ 135 #define PIC_PROLOGUE_NOSAVE(got) \ 136 mov.l got, r12; \ 137 mova got, r0; \ 138 add r0, r12 139 140 #define PIC_EPILOGUE \ 141 mov.l @sp+, r12 142 143 #define PIC_EPILOGUE_SLOT \ 144 PIC_EPILOGUE 145 146 #define PIC_GOT_DATUM \ 147 .long _GLOBAL_OFFSET_TABLE_ 148 149 #define CALL bsrf 150 #define JUMP braf 151 152 #define CALL_DATUM(function, lpcs) \ 153 .long PIC_PLT(function) - ((lpcs) + 4 - (.)) 154 155 /* 156 * This will result in text relocations in the shared library, 157 * unless the function is local or has hidden or protected visibility. 158 * Does not require PIC prologue. 159 */ 160 #define CALL_DATUM_LOCAL(function, lpcs) \ 161 .long function - ((lpcs) + 4) 162 163 #else /* !PIC */ 164 165 #define PIC_PROLOGUE(label) 166 #define PIC_PROLOGUE_NOSAVE(label) 167 #define PIC_EPILOGUE 168 #define PIC_EPILOGUE_SLOT nop 169 #define PIC_GOT_DATUM 170 171 #define CALL jsr @ 172 #define JUMP jmp @ 173 174 #define CALL_DATUM(function, lpcs) \ 175 .long function 176 177 #define CALL_DATUM_LOCAL(function, lpcs) \ 178 .long function 179 180 #endif /* !PIC */ 181 182 183 #define ASMSTR .asciz 184 185 #define STRONG_ALIAS(alias,sym) \ 186 .global _C_LABEL(alias); \ 187 _C_LABEL(alias) = _C_LABEL(sym) 188 #define WEAK_ALIAS(alias,sym) \ 189 .weak _C_LABEL(alias); \ 190 _C_LABEL(alias) = _C_LABEL(sym) 191 192 #define WARN_REFERENCES(_sym,_msg) \ 193 .section .gnu.warning._sym; .ascii _msg; .previous 194 195 #endif /* !_SH_ASM_H_ */ 196