1129198Scognet/* $NetBSD: asm.h,v 1.5 2003/08/07 16:26:53 agc Exp $ */ 2129198Scognet 3139735Simp/*- 4129198Scognet * Copyright (c) 1990 The Regents of the University of California. 5129198Scognet * All rights reserved. 6129198Scognet * 7129198Scognet * This code is derived from software contributed to Berkeley by 8129198Scognet * William Jolitz. 9129198Scognet * 10129198Scognet * Redistribution and use in source and binary forms, with or without 11129198Scognet * modification, are permitted provided that the following conditions 12129198Scognet * are met: 13129198Scognet * 1. Redistributions of source code must retain the above copyright 14129198Scognet * notice, this list of conditions and the following disclaimer. 15129198Scognet * 2. Redistributions in binary form must reproduce the above copyright 16129198Scognet * notice, this list of conditions and the following disclaimer in the 17129198Scognet * documentation and/or other materials provided with the distribution. 18129198Scognet * 3. Neither the name of the University nor the names of its contributors 19129198Scognet * may be used to endorse or promote products derived from this software 20129198Scognet * without specific prior written permission. 21129198Scognet * 22129198Scognet * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23129198Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24129198Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25129198Scognet * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26129198Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27129198Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28129198Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32129198Scognet * SUCH DAMAGE. 33129198Scognet * 34129198Scognet * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 35129198Scognet * 36129198Scognet * $FreeBSD$ 37129198Scognet */ 38129198Scognet 39129198Scognet#ifndef _MACHINE_ASM_H_ 40129198Scognet#define _MACHINE_ASM_H_ 41129198Scognet#include <sys/cdefs.h> 42276212Sian#include <machine/sysreg.h> 43129198Scognet 44251510Sandrew#define _C_LABEL(x) x 45129198Scognet#define _ASM_LABEL(x) x 46129198Scognet 47129198Scognet#ifndef _ALIGN_TEXT 48276596Sian# define _ALIGN_TEXT .align 2 49129198Scognet#endif 50129198Scognet 51283812Sandrew#ifndef _STANDALONE 52248361Sandrew#define STOP_UNWINDING .cantunwind 53248361Sandrew#define _FNSTART .fnstart 54248361Sandrew#define _FNEND .fnend 55288662Srwatson#define _SAVE(...) .save __VA_ARGS__ 56248361Sandrew#else 57248361Sandrew#define STOP_UNWINDING 58248361Sandrew#define _FNSTART 59248361Sandrew#define _FNEND 60288662Srwatson#define _SAVE(...) 61248361Sandrew#endif 62248361Sandrew 63129198Scognet/* 64276202Sian * gas/arm uses @ as a single comment character and thus cannot be used here. 65276202Sian * It recognises the # instead of an @ symbol in .type directives. 66276202Sian */ 67276202Sian#define _ASM_TYPE_FUNCTION #function 68276202Sian#define _ASM_TYPE_OBJECT #object 69276202Sian 70276202Sian/* XXX Is this still the right prologue for profiling? */ 71276202Sian#ifdef GPROF 72276202Sian#define _PROF_PROLOGUE \ 73276202Sian mov ip, lr; \ 74276202Sian bl __mcount 75276202Sian#else 76276202Sian#define _PROF_PROLOGUE 77276202Sian#endif 78276202Sian 79276202Sian/* 80275264Sandrew * EENTRY()/EEND() mark "extra" entry/exit points from a function. 81300050Seadler * LEENTRY()/LEEND() are the same for local symbols. 82275264Sandrew * The unwind info cannot handle the concept of a nested function, or a function 83275264Sandrew * with multiple .fnstart directives, but some of our assembler code is written 84275264Sandrew * with multiple labels to allow entry at several points. The EENTRY() macro 85275264Sandrew * defines such an extra entry point without a new .fnstart, so that it's 86275264Sandrew * basically just a label that you can jump to. The EEND() macro does nothing 87275264Sandrew * at all, except document the exit point associated with the same-named entry. 88275264Sandrew */ 89276203Sian#define GLOBAL(x) .global x 90276203Sian 91282778Sandrew#ifdef __thumb__ 92282778Sandrew#define _FUNC_MODE .code 16; .thumb_func 93282778Sandrew#else 94282778Sandrew#define _FUNC_MODE .code 32 95282778Sandrew#endif 96282778Sandrew 97282778Sandrew#define _LEENTRY(x) .type x,_ASM_TYPE_FUNCTION; _FUNC_MODE; x: 98276204Sian#define _LEEND(x) /* nothing */ 99276204Sian#define _EENTRY(x) GLOBAL(x); _LEENTRY(x) 100276204Sian#define _EEND(x) _LEEND(x) 101275264Sandrew 102276204Sian#define _LENTRY(x) .text; _ALIGN_TEXT; _LEENTRY(x); _FNSTART 103276204Sian#define _LEND(x) .size x, . - x; _FNEND 104276204Sian#define _ENTRY(x) .text; _ALIGN_TEXT; _EENTRY(x); _FNSTART 105276204Sian#define _END(x) _LEND(x) 106248361Sandrew 107129198Scognet#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE 108276198Sian#define EENTRY(y) _EENTRY(_C_LABEL(y)); 109129198Scognet#define ENTRY_NP(y) _ENTRY(_C_LABEL(y)) 110269390Sian#define EENTRY_NP(y) _EENTRY(_C_LABEL(y)) 111251510Sandrew#define END(y) _END(_C_LABEL(y)) 112276198Sian#define EEND(y) _EEND(_C_LABEL(y)) 113129198Scognet#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE 114276204Sian#define ASLENTRY(y) _LENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE 115276198Sian#define ASEENTRY(y) _EENTRY(_ASM_LABEL(y)); 116276204Sian#define ASLEENTRY(y) _LEENTRY(_ASM_LABEL(y)); 117129198Scognet#define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y)) 118276204Sian#define ASLENTRY_NP(y) _LENTRY(_ASM_LABEL(y)) 119269390Sian#define ASEENTRY_NP(y) _EENTRY(_ASM_LABEL(y)) 120276204Sian#define ASLEENTRY_NP(y) _LEENTRY(_ASM_LABEL(y)) 121251510Sandrew#define ASEND(y) _END(_ASM_LABEL(y)) 122276204Sian#define ASLEND(y) _LEND(_ASM_LABEL(y)) 123276198Sian#define ASEEND(y) _EEND(_ASM_LABEL(y)) 124276204Sian#define ASLEEND(y) _LEEND(_ASM_LABEL(y)) 125129198Scognet 126129198Scognet#define ASMSTR .asciz 127129198Scognet 128275004Semaste#if defined(PIC) 129251510Sandrew#define PLT_SYM(x) PIC_SYM(x, PLT) 130251510Sandrew#define GOT_SYM(x) PIC_SYM(x, GOT) 131251510Sandrew#define GOT_GET(x,got,sym) \ 132251510Sandrew ldr x, sym; \ 133251510Sandrew ldr x, [x, got] 134251510Sandrew#define GOT_INIT(got,gotsym,pclabel) \ 135251510Sandrew ldr got, gotsym; \ 136282777Sandrew pclabel: add got, pc 137275378Sandrew#ifdef __thumb__ 138251510Sandrew#define GOT_INITSYM(gotsym,pclabel) \ 139276596Sian .align 2; \ 140275378Sandrew gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4) 141275378Sandrew#else 142275378Sandrew#define GOT_INITSYM(gotsym,pclabel) \ 143276596Sian .align 2; \ 144275378Sandrew gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8) 145275378Sandrew#endif 146251510Sandrew 147129198Scognet#ifdef __STDC__ 148129198Scognet#define PIC_SYM(x,y) x ## ( ## y ## ) 149129198Scognet#else 150129198Scognet#define PIC_SYM(x,y) x/**/(/**/y/**/) 151129198Scognet#endif 152251510Sandrew 153129198Scognet#else 154251510Sandrew#define PLT_SYM(x) x 155251510Sandrew#define GOT_SYM(x) x 156251510Sandrew#define GOT_GET(x,got,sym) \ 157251510Sandrew ldr x, sym; 158251510Sandrew#define GOT_INIT(got,gotsym,pclabel) 159251510Sandrew#define GOT_INITSYM(gotsym,pclabel) 160129198Scognet#define PIC_SYM(x,y) x 161275004Semaste#endif /* PIC */ 162129198Scognet 163129198Scognet#undef __FBSDID 164129198Scognet#if !defined(lint) && !defined(STRIP_FBSDID) 165129198Scognet#define __FBSDID(s) .ident s 166129198Scognet#else 167129198Scognet#define __FBSDID(s) /* nothing */ 168129198Scognet#endif 169129198Scognet 170290648Smmel 171129198Scognet#define WEAK_ALIAS(alias,sym) \ 172129198Scognet .weak alias; \ 173129198Scognet alias = sym 174129198Scognet 175129198Scognet#ifdef __STDC__ 176129198Scognet#define WARN_REFERENCES(sym,msg) \ 177129198Scognet .stabs msg ## ,30,0,0,0 ; \ 178129198Scognet .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0 179251510Sandrew#else 180129198Scognet#define WARN_REFERENCES(sym,msg) \ 181129198Scognet .stabs msg,30,0,0,0 ; \ 182129198Scognet .stabs __STRING(sym),1,0,0,0 183129198Scognet#endif /* __STDC__ */ 184129198Scognet 185239268Sgonzo/* Exactly one of the __ARM_ARCH_*__ macros will be defined by the compiler. */ 186239268Sgonzo/* The _ARM_ARCH_* macros are deprecated and will be removed soon. */ 187239268Sgonzo/* This should be moved into another header so it can be used in 188239268Sgonzo * both asm and C code. machine/asm.h cannot be included in C code. */ 189239268Sgonzo#if defined (__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__) 190239268Sgonzo#define _ARM_ARCH_7 191239268Sgonzo#define _HAVE_ARMv7_INSTRUCTIONS 1 192239268Sgonzo#endif 193137462Scognet 194239268Sgonzo#if defined (_HAVE_ARMv7_INSTRUCTIONS) || defined (__ARM_ARCH_6__) || \ 195239268Sgonzo defined (__ARM_ARCH_6J__) || defined (__ARM_ARCH_6K__) || \ 196239268Sgonzo defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__) 197137462Scognet#define _ARM_ARCH_6 198239268Sgonzo#define _HAVE_ARMv6_INSTRUCTIONS 1 199137462Scognet#endif 200137462Scognet 201239268Sgonzo#if defined (_HAVE_ARMv6_INSTRUCTIONS) || defined (__ARM_ARCH_5TE__) || \ 202172613Scognet defined (__ARM_ARCH_5TEJ__) || defined (__ARM_ARCH_5E__) 203239268Sgonzo#define _ARM_ARCH_5E 204239268Sgonzo#define _HAVE_ARMv5E_INSTRUCTIONS 1 205137462Scognet#endif 206137462Scognet 207239268Sgonzo#if defined (_HAVE_ARMv5E_INSTRUCTIONS) || defined (__ARM_ARCH_5__) || \ 208239268Sgonzo defined (__ARM_ARCH_5T__) 209239268Sgonzo#define _ARM_ARCH_5 210239268Sgonzo#define _HAVE_ARMv5_INSTRUCTIONS 1 211172613Scognet#endif 212172613Scognet 213239268Sgonzo#if defined (_HAVE_ARMv5_INSTRUCTIONS) || defined (__ARM_ARCH_4T__) 214137462Scognet#define _ARM_ARCH_4T 215239268Sgonzo#define _HAVE_ARMv4T_INSTRUCTIONS 1 216137462Scognet#endif 217137462Scognet 218239268Sgonzo/* FreeBSD requires ARMv4, so this is always set. */ 219239268Sgonzo#define _HAVE_ARMv4_INSTRUCTIONS 1 220137462Scognet 221239268Sgonzo#if defined (_HAVE_ARMv4T_INSTRUCTIONS) 222137462Scognet# define RET bx lr 223137462Scognet# define RETeq bxeq lr 224137462Scognet# define RETne bxne lr 225239268Sgonzo# define RETc(c) bx##c lr 226137462Scognet#else 227137462Scognet# define RET mov pc, lr 228137462Scognet# define RETeq moveq pc, lr 229137462Scognet# define RETne movne pc, lr 230239268Sgonzo# define RETc(c) mov##c pc, lr 231137462Scognet#endif 232137462Scognet 233276212Sian#if __ARM_ARCH >= 7 234276212Sian#define ISB isb 235276212Sian#define DSB dsb 236276212Sian#define DMB dmb 237276519Sian#define WFI wfi 238276212Sian#elif __ARM_ARCH == 6 239276212Sian#define ISB mcr CP15_CP15ISB 240276212Sian#define DSB mcr CP15_CP15DSB 241276212Sian#define DMB mcr CP15_CP15DMB 242276519Sian#define WFI mcr CP15_CP15WFI 243276212Sian#else 244276212Sian#define ISB mcr CP15_CP15ISB 245276212Sian#define DSB mcr CP15_CP15DSB /* DSB and DMB are the */ 246276212Sian#define DMB mcr CP15_CP15DSB /* same prior to v6.*/ 247276519Sian/* No form of WFI available on v4, define nothing to get an error on use. */ 248276212Sian#endif 249276212Sian 250129198Scognet#endif /* !_MACHINE_ASM_H_ */ 251