/* $NetBSD: asm.h,v 1.5 2003/08/07 16:26:53 agc Exp $ */12/*-3* SPDX-License-Identifier: BSD-3-Clause4*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 by9* William Jolitz.10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19* 3. Neither the name of the University nor the names of its contributors20* may be used to endorse or promote products derived from this software21* without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#ifndef _MACHINE_ASM_H_37#define _MACHINE_ASM_H_38#include <sys/cdefs.h>3940#define _C_LABEL(x) x41#define _ASM_LABEL(x) x4243#ifndef _ALIGN_TEXT44# define _ALIGN_TEXT .align 245#endif4647#ifndef _STANDALONE48#define STOP_UNWINDING .cantunwind49#define _FNSTART .fnstart50#define _FNEND .fnend51#define _SAVE(...) .save __VA_ARGS__52#else53#define STOP_UNWINDING54#define _FNSTART55#define _FNEND56#define _SAVE(...)57#endif5859/*60* gas/arm uses @ as a single comment character and thus cannot be used here.61* It recognises the # instead of an @ symbol in .type directives.62*/63#define _ASM_TYPE_FUNCTION #function64#define _ASM_TYPE_OBJECT #object6566/*67* EENTRY()/EEND() mark "extra" entry/exit points from a function.68* LEENTRY()/LEEND() are the same for local symbols.69* The unwind info cannot handle the concept of a nested function, or a function70* with multiple .fnstart directives, but some of our assembler code is written71* with multiple labels to allow entry at several points. The EENTRY() macro72* defines such an extra entry point without a new .fnstart, so that it's73* basically just a label that you can jump to. The EEND() macro does nothing74* at all, except document the exit point associated with the same-named entry.75*/76#define GLOBAL(x) .global x7778#ifdef __thumb__79#define _FUNC_MODE .code 16; .thumb_func80#else81#define _FUNC_MODE .code 3282#endif8384#define _LEENTRY(x) .type x,_ASM_TYPE_FUNCTION; _FUNC_MODE; x:85#define _LEEND(x) /* nothing */86#define _EENTRY(x) GLOBAL(x); _LEENTRY(x)87#define _EEND(x) _LEEND(x)8889#define _LENTRY(x) .text; _ALIGN_TEXT; _LEENTRY(x); _FNSTART90#define _LEND(x) .size x, . - x; _FNEND91#define _ENTRY(x) .text; _ALIGN_TEXT; _EENTRY(x); _FNSTART92#define _END(x) _LEND(x)9394#define ENTRY(y) _ENTRY(_C_LABEL(y));95#define EENTRY(y) _EENTRY(_C_LABEL(y));96#define ENTRY_NP(y) _ENTRY(_C_LABEL(y))97#define EENTRY_NP(y) _EENTRY(_C_LABEL(y))98#define END(y) _END(_C_LABEL(y))99#define EEND(y) _EEND(_C_LABEL(y))100#define ASENTRY(y) _ENTRY(_ASM_LABEL(y));101#define ASLENTRY(y) _LENTRY(_ASM_LABEL(y));102#define ASEENTRY(y) _EENTRY(_ASM_LABEL(y));103#define ASLEENTRY(y) _LEENTRY(_ASM_LABEL(y));104#define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y))105#define ASLENTRY_NP(y) _LENTRY(_ASM_LABEL(y))106#define ASEENTRY_NP(y) _EENTRY(_ASM_LABEL(y))107#define ASLEENTRY_NP(y) _LEENTRY(_ASM_LABEL(y))108#define ASEND(y) _END(_ASM_LABEL(y))109#define ASLEND(y) _LEND(_ASM_LABEL(y))110#define ASEEND(y) _EEND(_ASM_LABEL(y))111#define ASLEEND(y) _LEEND(_ASM_LABEL(y))112113#define ASMSTR .asciz114115#if defined(PIC)116#define PLT_SYM(x) PIC_SYM(x, PLT)117#define GOT_SYM(x) PIC_SYM(x, GOT)118#define GOT_GET(x,got,sym) \119ldr x, sym; \120ldr x, [x, got]121#define GOT_INIT(got,gotsym,pclabel) \122ldr got, gotsym; \123pclabel: add got, pc124#ifdef __thumb__125#define GOT_INITSYM(gotsym,pclabel) \126.align 2; \127gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4)128#else129#define GOT_INITSYM(gotsym,pclabel) \130.align 2; \131gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8)132#endif133134#ifdef __STDC__135#define PIC_SYM(x,y) x ## ( ## y ## )136#else137#define PIC_SYM(x,y) x/**/(/**/y/**/)138#endif139140#else141#define PLT_SYM(x) x142#define GOT_SYM(x) x143#define GOT_GET(x,got,sym) \144ldr x, sym;145#define GOT_INIT(got,gotsym,pclabel)146#define GOT_INITSYM(gotsym,pclabel)147#define PIC_SYM(x,y) x148#endif /* PIC */149150#undef __FBSDID151#if !defined(lint) && !defined(STRIP_FBSDID)152#define __FBSDID(s) .ident s153#else154#define __FBSDID(s) /* nothing */155#endif156157#define WEAK_ALIAS(alias,sym) \158.weak alias; \159alias = sym160161#ifdef __STDC__162#define WARN_REFERENCES(sym,msg) \163.stabs msg ## ,30,0,0,0 ; \164.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0165#else166#define WARN_REFERENCES(sym,msg) \167.stabs msg,30,0,0,0 ; \168.stabs __STRING(sym),1,0,0,0169#endif /* __STDC__ */170171# define RET bx lr172# define RETeq bxeq lr173# define RETne bxne lr174# define RETc(c) bx##c lr175176#define ISB isb177#define DSB dsb178#define DMB dmb179#define WFI wfi180181#if defined(__ARM_ARCH_7VE__) || defined(__clang__)182#define MSR_ELR_HYP(regnum) msr elr_hyp, lr183#define ERET eret184#else185#define MSR_ELR_HYP(regnum) .word (0xe12ef300 | regnum)186#define ERET .word 0xe160006e187#endif188189190#endif /* !_MACHINE_ASM_H_ */191192193