16fc729afSOlivier Houchard /* $NetBSD: asm.h,v 1.5 2003/08/07 16:26:53 agc Exp $ */ 26fc729afSOlivier Houchard 3d8315c79SWarner Losh /*- 451369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 551369649SPedro F. Giffuni * 66fc729afSOlivier Houchard * Copyright (c) 1990 The Regents of the University of California. 76fc729afSOlivier Houchard * All rights reserved. 86fc729afSOlivier Houchard * 96fc729afSOlivier Houchard * This code is derived from software contributed to Berkeley by 106fc729afSOlivier Houchard * William Jolitz. 116fc729afSOlivier Houchard * 126fc729afSOlivier Houchard * Redistribution and use in source and binary forms, with or without 136fc729afSOlivier Houchard * modification, are permitted provided that the following conditions 146fc729afSOlivier Houchard * are met: 156fc729afSOlivier Houchard * 1. Redistributions of source code must retain the above copyright 166fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer. 176fc729afSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright 186fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer in the 196fc729afSOlivier Houchard * documentation and/or other materials provided with the distribution. 206fc729afSOlivier Houchard * 3. Neither the name of the University nor the names of its contributors 216fc729afSOlivier Houchard * may be used to endorse or promote products derived from this software 226fc729afSOlivier Houchard * without specific prior written permission. 236fc729afSOlivier Houchard * 246fc729afSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 256fc729afSOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 266fc729afSOlivier Houchard * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 276fc729afSOlivier Houchard * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 286fc729afSOlivier Houchard * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 296fc729afSOlivier Houchard * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 306fc729afSOlivier Houchard * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 316fc729afSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 326fc729afSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 336fc729afSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 346fc729afSOlivier Houchard * SUCH DAMAGE. 356fc729afSOlivier Houchard * 366fc729afSOlivier Houchard * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 376fc729afSOlivier Houchard * 386fc729afSOlivier Houchard * $FreeBSD$ 396fc729afSOlivier Houchard */ 406fc729afSOlivier Houchard 416fc729afSOlivier Houchard #ifndef _MACHINE_ASM_H_ 426fc729afSOlivier Houchard #define _MACHINE_ASM_H_ 436fc729afSOlivier Houchard #include <sys/cdefs.h> 44eb4585bcSIan Lepore #include <machine/sysreg.h> 456fc729afSOlivier Houchard 466fc729afSOlivier Houchard #define _C_LABEL(x) x 476fc729afSOlivier Houchard #define _ASM_LABEL(x) x 486fc729afSOlivier Houchard 496fc729afSOlivier Houchard #ifndef _ALIGN_TEXT 50301e1601SIan Lepore # define _ALIGN_TEXT .align 2 516fc729afSOlivier Houchard #endif 526fc729afSOlivier Houchard 53ae160b23SAndrew Turner #ifndef _STANDALONE 54573447b6SAndrew Turner #define STOP_UNWINDING .cantunwind 55573447b6SAndrew Turner #define _FNSTART .fnstart 56573447b6SAndrew Turner #define _FNEND .fnend 57ba2f5f5eSRobert Watson #define _SAVE(...) .save __VA_ARGS__ 58573447b6SAndrew Turner #else 59573447b6SAndrew Turner #define STOP_UNWINDING 60573447b6SAndrew Turner #define _FNSTART 61573447b6SAndrew Turner #define _FNEND 62ba2f5f5eSRobert Watson #define _SAVE(...) 63573447b6SAndrew Turner #endif 64573447b6SAndrew Turner 656fc729afSOlivier Houchard /* 66de064ce4SIan Lepore * gas/arm uses @ as a single comment character and thus cannot be used here. 67de064ce4SIan Lepore * It recognises the # instead of an @ symbol in .type directives. 68de064ce4SIan Lepore */ 69de064ce4SIan Lepore #define _ASM_TYPE_FUNCTION #function 70de064ce4SIan Lepore #define _ASM_TYPE_OBJECT #object 71de064ce4SIan Lepore 72de064ce4SIan Lepore /* 7325166187SIan Lepore * EENTRY()/EEND() mark "extra" entry/exit points from a function. 74cef367e6SEitan Adler * LEENTRY()/LEEND() are the same for local symbols. 7525166187SIan Lepore * The unwind info cannot handle the concept of a nested function, or a function 7625166187SIan Lepore * with multiple .fnstart directives, but some of our assembler code is written 7725166187SIan Lepore * with multiple labels to allow entry at several points. The EENTRY() macro 7825166187SIan Lepore * defines such an extra entry point without a new .fnstart, so that it's 7925166187SIan Lepore * basically just a label that you can jump to. The EEND() macro does nothing 8025166187SIan Lepore * at all, except document the exit point associated with the same-named entry. 8125166187SIan Lepore */ 8271442935SIan Lepore #define GLOBAL(x) .global x 8371442935SIan Lepore 848465de8eSAndrew Turner #ifdef __thumb__ 858465de8eSAndrew Turner #define _FUNC_MODE .code 16; .thumb_func 868465de8eSAndrew Turner #else 878465de8eSAndrew Turner #define _FUNC_MODE .code 32 888465de8eSAndrew Turner #endif 898465de8eSAndrew Turner 908465de8eSAndrew Turner #define _LEENTRY(x) .type x,_ASM_TYPE_FUNCTION; _FUNC_MODE; x: 91b05d247eSIan Lepore #define _LEEND(x) /* nothing */ 92b05d247eSIan Lepore #define _EENTRY(x) GLOBAL(x); _LEENTRY(x) 93b05d247eSIan Lepore #define _EEND(x) _LEEND(x) 9425166187SIan Lepore 95b05d247eSIan Lepore #define _LENTRY(x) .text; _ALIGN_TEXT; _LEENTRY(x); _FNSTART 96b05d247eSIan Lepore #define _LEND(x) .size x, . - x; _FNEND 97b05d247eSIan Lepore #define _ENTRY(x) .text; _ALIGN_TEXT; _EENTRY(x); _FNSTART 98b05d247eSIan Lepore #define _END(x) _LEND(x) 99b643b934SAndrew Turner 100*c3f1a139SMateusz Guzik #define ENTRY(y) _ENTRY(_C_LABEL(y)); 101be483be8SIan Lepore #define EENTRY(y) _EENTRY(_C_LABEL(y)); 1026fc729afSOlivier Houchard #define ENTRY_NP(y) _ENTRY(_C_LABEL(y)) 10325166187SIan Lepore #define EENTRY_NP(y) _EENTRY(_C_LABEL(y)) 1040a794529SAndrew Turner #define END(y) _END(_C_LABEL(y)) 105be483be8SIan Lepore #define EEND(y) _EEND(_C_LABEL(y)) 106*c3f1a139SMateusz Guzik #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); 107*c3f1a139SMateusz Guzik #define ASLENTRY(y) _LENTRY(_ASM_LABEL(y)); 108be483be8SIan Lepore #define ASEENTRY(y) _EENTRY(_ASM_LABEL(y)); 109b05d247eSIan Lepore #define ASLEENTRY(y) _LEENTRY(_ASM_LABEL(y)); 1106fc729afSOlivier Houchard #define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y)) 111b05d247eSIan Lepore #define ASLENTRY_NP(y) _LENTRY(_ASM_LABEL(y)) 11225166187SIan Lepore #define ASEENTRY_NP(y) _EENTRY(_ASM_LABEL(y)) 113b05d247eSIan Lepore #define ASLEENTRY_NP(y) _LEENTRY(_ASM_LABEL(y)) 1140a794529SAndrew Turner #define ASEND(y) _END(_ASM_LABEL(y)) 115b05d247eSIan Lepore #define ASLEND(y) _LEND(_ASM_LABEL(y)) 116be483be8SIan Lepore #define ASEEND(y) _EEND(_ASM_LABEL(y)) 117b05d247eSIan Lepore #define ASLEEND(y) _LEEND(_ASM_LABEL(y)) 1186fc729afSOlivier Houchard 1196fc729afSOlivier Houchard #define ASMSTR .asciz 1206fc729afSOlivier Houchard 121294246bbSEd Maste #if defined(PIC) 1220a794529SAndrew Turner #define PLT_SYM(x) PIC_SYM(x, PLT) 1230a794529SAndrew Turner #define GOT_SYM(x) PIC_SYM(x, GOT) 1240a794529SAndrew Turner #define GOT_GET(x,got,sym) \ 1250a794529SAndrew Turner ldr x, sym; \ 1260a794529SAndrew Turner ldr x, [x, got] 1270a794529SAndrew Turner #define GOT_INIT(got,gotsym,pclabel) \ 1280a794529SAndrew Turner ldr got, gotsym; \ 129827422e3SAndrew Turner pclabel: add got, pc 1307f9b314fSAndrew Turner #ifdef __thumb__ 1310a794529SAndrew Turner #define GOT_INITSYM(gotsym,pclabel) \ 132301e1601SIan Lepore .align 2; \ 1337f9b314fSAndrew Turner gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4) 1347f9b314fSAndrew Turner #else 1357f9b314fSAndrew Turner #define GOT_INITSYM(gotsym,pclabel) \ 136301e1601SIan Lepore .align 2; \ 1377f9b314fSAndrew Turner gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8) 1387f9b314fSAndrew Turner #endif 1390a794529SAndrew Turner 1406fc729afSOlivier Houchard #ifdef __STDC__ 1416fc729afSOlivier Houchard #define PIC_SYM(x,y) x ## ( ## y ## ) 1426fc729afSOlivier Houchard #else 1436fc729afSOlivier Houchard #define PIC_SYM(x,y) x/**/(/**/y/**/) 1446fc729afSOlivier Houchard #endif 1450a794529SAndrew Turner 1466fc729afSOlivier Houchard #else 1470a794529SAndrew Turner #define PLT_SYM(x) x 1480a794529SAndrew Turner #define GOT_SYM(x) x 1490a794529SAndrew Turner #define GOT_GET(x,got,sym) \ 1500a794529SAndrew Turner ldr x, sym; 1510a794529SAndrew Turner #define GOT_INIT(got,gotsym,pclabel) 1520a794529SAndrew Turner #define GOT_INITSYM(gotsym,pclabel) 1536fc729afSOlivier Houchard #define PIC_SYM(x,y) x 154294246bbSEd Maste #endif /* PIC */ 1556fc729afSOlivier Houchard 1566fc729afSOlivier Houchard #undef __FBSDID 1576fc729afSOlivier Houchard #if !defined(lint) && !defined(STRIP_FBSDID) 1586fc729afSOlivier Houchard #define __FBSDID(s) .ident s 1596fc729afSOlivier Houchard #else 1606fc729afSOlivier Houchard #define __FBSDID(s) /* nothing */ 1616fc729afSOlivier Houchard #endif 1626fc729afSOlivier Houchard 1636fc729afSOlivier Houchard #define WEAK_ALIAS(alias,sym) \ 1646fc729afSOlivier Houchard .weak alias; \ 1656fc729afSOlivier Houchard alias = sym 1666fc729afSOlivier Houchard 1676fc729afSOlivier Houchard #ifdef __STDC__ 1686fc729afSOlivier Houchard #define WARN_REFERENCES(sym,msg) \ 1696fc729afSOlivier Houchard .stabs msg ## ,30,0,0,0 ; \ 1706fc729afSOlivier Houchard .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0 1716fc729afSOlivier Houchard #else 1726fc729afSOlivier Houchard #define WARN_REFERENCES(sym,msg) \ 1736fc729afSOlivier Houchard .stabs msg,30,0,0,0 ; \ 1740a794529SAndrew Turner .stabs __STRING(sym),1,0,0,0 1756fc729afSOlivier Houchard #endif /* __STDC__ */ 1766fc729afSOlivier Houchard 1775f2c6402SOlivier Houchard # define RET bx lr 1785f2c6402SOlivier Houchard # define RETeq bxeq lr 1795f2c6402SOlivier Houchard # define RETne bxne lr 1805f2c6402SOlivier Houchard # define RETc(c) bx##c lr 1815f2c6402SOlivier Houchard 182eb4585bcSIan Lepore #if __ARM_ARCH >= 7 183eb4585bcSIan Lepore #define ISB isb 184eb4585bcSIan Lepore #define DSB dsb 185eb4585bcSIan Lepore #define DMB dmb 18654f9ec88SIan Lepore #define WFI wfi 187e336138cSAndrew Turner 188e336138cSAndrew Turner #if defined(__ARM_ARCH_7VE__) || defined(__clang__) 189e336138cSAndrew Turner #define MSR_ELR_HYP(regnum) msr elr_hyp, lr 190e336138cSAndrew Turner #define ERET eret 191e336138cSAndrew Turner #else 192e336138cSAndrew Turner #define MSR_ELR_HYP(regnum) .word (0xe12ef300 | regnum) 193e336138cSAndrew Turner #define ERET .word 0xe160006e 194e336138cSAndrew Turner #endif 195e336138cSAndrew Turner 196eb4585bcSIan Lepore #elif __ARM_ARCH == 6 197eb4585bcSIan Lepore #define ISB mcr CP15_CP15ISB 198eb4585bcSIan Lepore #define DSB mcr CP15_CP15DSB 199eb4585bcSIan Lepore #define DMB mcr CP15_CP15DMB 20054f9ec88SIan Lepore #define WFI mcr CP15_CP15WFI 201eb4585bcSIan Lepore #endif 202eb4585bcSIan Lepore 2036fc729afSOlivier Houchard #endif /* !_MACHINE_ASM_H_ */ 204