1 /* $OpenBSD: asm.h,v 1.8 2018/11/11 20:15:24 guenther 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 #if defined(PROF) || defined(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 END(y) .size y, . - y 82 83 #define SET_ENTRY_SIZE(y) \ 84 .size _C_LABEL(y), . - _C_LABEL(y) 85 86 #define SET_ASENTRY_SIZE(y) \ 87 .size _ASM_LABEL(y), . - _ASM_LABEL(y) 88 89 #define ALTENTRY(name) \ 90 .globl _C_LABEL(name) ;\ 91 .type _C_LABEL(name),@function ;\ 92 _C_LABEL(name): 93 94 /* 95 * Hide the gory details of PIC calls vs. normal calls. Use as in the 96 * following example: 97 * 98 * sts.l pr, @-sp 99 * PIC_PROLOGUE(.L_got, r0) ! saves old r12 on stack 100 * ... 101 * mov.l .L_function_1, r0 102 * 1: CALL r0 ! each call site needs a label 103 * nop 104 * ... 105 * mov.l .L_function_2, r0 106 * 2: CALL r0 107 * nop 108 * ... 109 * PIC_EPILOGUE ! restores r12 from stack 110 * lds.l @sp+, pr ! so call in right order 111 * rts 112 * nop 113 * 114 * .align 2 115 * .L_got: 116 * PIC_GOT_DATUM 117 * .L_function_1: ! if you call the same function twice 118 * CALL_DATUM(function, 1b) ! provide call datum for each call 119 * .L_function_2: 120 * CALL_DATUM(function, 2b) 121 */ 122 123 #ifdef __PIC__ 124 125 #define PIC_PLT(x) x@PLT 126 #define PIC_GOT(x) x@GOT 127 #define PIC_GOTOFF(x) x@GOTOFF 128 129 #define PIC_PROLOGUE(got) \ 130 mov.l r12, @-sp; \ 131 PIC_PROLOGUE_NOSAVE(got) 132 133 /* 134 * Functions that do non local jumps don't need to preserve r12, 135 * so we can shave off two instructions to save/restore it. 136 */ 137 #define PIC_PROLOGUE_NOSAVE(got) \ 138 mov.l got, r12; \ 139 mova got, r0; \ 140 add r0, r12 141 142 #define PIC_EPILOGUE \ 143 mov.l @sp+, r12 144 145 #define PIC_EPILOGUE_SLOT \ 146 PIC_EPILOGUE 147 148 #define PIC_GOT_DATUM \ 149 .long _GLOBAL_OFFSET_TABLE_ 150 151 #define CALL bsrf 152 #define JUMP braf 153 154 #define CALL_DATUM(function, lpcs) \ 155 .long PIC_PLT(function) - ((lpcs) + 4 - (.)) 156 157 /* 158 * This will result in text relocations in the shared library, 159 * unless the function is local or has hidden or protected visibility. 160 * Does not require PIC prologue. 161 */ 162 #define CALL_DATUM_LOCAL(function, lpcs) \ 163 .long function - ((lpcs) + 4) 164 165 #else /* !PIC */ 166 167 #define PIC_PROLOGUE(label) 168 #define PIC_PROLOGUE_NOSAVE(label) 169 #define PIC_EPILOGUE 170 #define PIC_EPILOGUE_SLOT nop 171 #define PIC_GOT_DATUM 172 173 #define CALL jsr @ 174 #define JUMP jmp @ 175 176 #define CALL_DATUM(function, lpcs) \ 177 .long function 178 179 #define CALL_DATUM_LOCAL(function, lpcs) \ 180 .long function 181 182 #endif /* !PIC */ 183 184 #define STRONG_ALIAS(alias,sym) \ 185 .global _C_LABEL(alias); \ 186 _C_LABEL(alias) = _C_LABEL(sym) 187 #define WEAK_ALIAS(alias,sym) \ 188 .weak _C_LABEL(alias); \ 189 _C_LABEL(alias) = _C_LABEL(sym) 190 191 #define WARN_REFERENCES(_sym,_msg) \ 192 .section .gnu.warning._sym; .ascii _msg; .previous 193 194 #endif /* !_SH_ASM_H_ */ 195