asm.h revision 283812
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: head/sys/arm/include/asm.h 283812 2015-05-31 10:51:06Z andrew $ 37129198Scognet */ 38129198Scognet 39129198Scognet#ifndef _MACHINE_ASM_H_ 40129198Scognet#define _MACHINE_ASM_H_ 41129198Scognet#include <sys/cdefs.h> 42276247Sian#include <machine/acle-compat.h> 43276212Sian#include <machine/sysreg.h> 44129198Scognet 45251510Sandrew#define _C_LABEL(x) x 46129198Scognet#define _ASM_LABEL(x) x 47129198Scognet 48129198Scognet#ifndef _ALIGN_TEXT 49276596Sian# define _ALIGN_TEXT .align 2 50129198Scognet#endif 51129198Scognet 52283812Sandrew#ifndef _STANDALONE 53248361Sandrew#define STOP_UNWINDING .cantunwind 54248361Sandrew#define _FNSTART .fnstart 55248361Sandrew#define _FNEND .fnend 56248361Sandrew#else 57248361Sandrew#define STOP_UNWINDING 58248361Sandrew#define _FNSTART 59248361Sandrew#define _FNEND 60248361Sandrew#endif 61248361Sandrew 62129198Scognet/* 63276202Sian * gas/arm uses @ as a single comment character and thus cannot be used here. 64276202Sian * It recognises the # instead of an @ symbol in .type directives. 65276202Sian */ 66276202Sian#define _ASM_TYPE_FUNCTION #function 67276202Sian#define _ASM_TYPE_OBJECT #object 68276202Sian 69276202Sian/* XXX Is this still the right prologue for profiling? */ 70276202Sian#ifdef GPROF 71276202Sian#define _PROF_PROLOGUE \ 72276202Sian mov ip, lr; \ 73276202Sian bl __mcount 74276202Sian#else 75276202Sian#define _PROF_PROLOGUE 76276202Sian#endif 77276202Sian 78276202Sian/* 79275264Sandrew * EENTRY()/EEND() mark "extra" entry/exit points from a function. 80276204Sian * LEENTRY()/LEEND() are the the same for local symbols. 81275264Sandrew * The unwind info cannot handle the concept of a nested function, or a function 82275264Sandrew * with multiple .fnstart directives, but some of our assembler code is written 83275264Sandrew * with multiple labels to allow entry at several points. The EENTRY() macro 84275264Sandrew * defines such an extra entry point without a new .fnstart, so that it's 85275264Sandrew * basically just a label that you can jump to. The EEND() macro does nothing 86275264Sandrew * at all, except document the exit point associated with the same-named entry. 87275264Sandrew */ 88276203Sian#define GLOBAL(x) .global x 89276203Sian 90282778Sandrew#ifdef __thumb__ 91282778Sandrew#define _FUNC_MODE .code 16; .thumb_func 92282778Sandrew#else 93282778Sandrew#define _FUNC_MODE .code 32 94282778Sandrew#endif 95282778Sandrew 96282778Sandrew#define _LEENTRY(x) .type x,_ASM_TYPE_FUNCTION; _FUNC_MODE; x: 97276204Sian#define _LEEND(x) /* nothing */ 98276204Sian#define _EENTRY(x) GLOBAL(x); _LEENTRY(x) 99276204Sian#define _EEND(x) _LEEND(x) 100275264Sandrew 101276204Sian#define _LENTRY(x) .text; _ALIGN_TEXT; _LEENTRY(x); _FNSTART 102276204Sian#define _LEND(x) .size x, . - x; _FNEND 103276204Sian#define _ENTRY(x) .text; _ALIGN_TEXT; _EENTRY(x); _FNSTART 104276204Sian#define _END(x) _LEND(x) 105248361Sandrew 106129198Scognet#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE 107276198Sian#define EENTRY(y) _EENTRY(_C_LABEL(y)); 108129198Scognet#define ENTRY_NP(y) _ENTRY(_C_LABEL(y)) 109269390Sian#define EENTRY_NP(y) _EENTRY(_C_LABEL(y)) 110251510Sandrew#define END(y) _END(_C_LABEL(y)) 111276198Sian#define EEND(y) _EEND(_C_LABEL(y)) 112129198Scognet#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE 113276204Sian#define ASLENTRY(y) _LENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE 114276198Sian#define ASEENTRY(y) _EENTRY(_ASM_LABEL(y)); 115276204Sian#define ASLEENTRY(y) _LEENTRY(_ASM_LABEL(y)); 116129198Scognet#define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y)) 117276204Sian#define ASLENTRY_NP(y) _LENTRY(_ASM_LABEL(y)) 118269390Sian#define ASEENTRY_NP(y) _EENTRY(_ASM_LABEL(y)) 119276204Sian#define ASLEENTRY_NP(y) _LEENTRY(_ASM_LABEL(y)) 120251510Sandrew#define ASEND(y) _END(_ASM_LABEL(y)) 121276204Sian#define ASLEND(y) _LEND(_ASM_LABEL(y)) 122276198Sian#define ASEEND(y) _EEND(_ASM_LABEL(y)) 123276204Sian#define ASLEEND(y) _LEEND(_ASM_LABEL(y)) 124129198Scognet 125129198Scognet#define ASMSTR .asciz 126129198Scognet 127275004Semaste#if defined(PIC) 128251510Sandrew#define PLT_SYM(x) PIC_SYM(x, PLT) 129251510Sandrew#define GOT_SYM(x) PIC_SYM(x, GOT) 130251510Sandrew#define GOT_GET(x,got,sym) \ 131251510Sandrew ldr x, sym; \ 132251510Sandrew ldr x, [x, got] 133251510Sandrew#define GOT_INIT(got,gotsym,pclabel) \ 134251510Sandrew ldr got, gotsym; \ 135282777Sandrew pclabel: add got, pc 136275378Sandrew#ifdef __thumb__ 137251510Sandrew#define GOT_INITSYM(gotsym,pclabel) \ 138276596Sian .align 2; \ 139275378Sandrew gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4) 140275378Sandrew#else 141275378Sandrew#define GOT_INITSYM(gotsym,pclabel) \ 142276596Sian .align 2; \ 143275378Sandrew gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8) 144275378Sandrew#endif 145251510Sandrew 146129198Scognet#ifdef __STDC__ 147129198Scognet#define PIC_SYM(x,y) x ## ( ## y ## ) 148129198Scognet#else 149129198Scognet#define PIC_SYM(x,y) x/**/(/**/y/**/) 150129198Scognet#endif 151251510Sandrew 152129198Scognet#else 153251510Sandrew#define PLT_SYM(x) x 154251510Sandrew#define GOT_SYM(x) x 155251510Sandrew#define GOT_GET(x,got,sym) \ 156251510Sandrew ldr x, sym; 157251510Sandrew#define GOT_INIT(got,gotsym,pclabel) 158251510Sandrew#define GOT_INITSYM(gotsym,pclabel) 159129198Scognet#define PIC_SYM(x,y) x 160275004Semaste#endif /* PIC */ 161129198Scognet 162129198Scognet#undef __FBSDID 163129198Scognet#if !defined(lint) && !defined(STRIP_FBSDID) 164129198Scognet#define __FBSDID(s) .ident s 165129198Scognet#else 166129198Scognet#define __FBSDID(s) /* nothing */ 167129198Scognet#endif 168129198Scognet 169129198Scognet 170129198Scognet#define WEAK_ALIAS(alias,sym) \ 171129198Scognet .weak alias; \ 172129198Scognet alias = sym 173129198Scognet 174129198Scognet#ifdef __STDC__ 175129198Scognet#define WARN_REFERENCES(sym,msg) \ 176129198Scognet .stabs msg ## ,30,0,0,0 ; \ 177129198Scognet .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0 178251510Sandrew#else 179129198Scognet#define WARN_REFERENCES(sym,msg) \ 180129198Scognet .stabs msg,30,0,0,0 ; \ 181129198Scognet .stabs __STRING(sym),1,0,0,0 182129198Scognet#endif /* __STDC__ */ 183129198Scognet 184239268Sgonzo/* Exactly one of the __ARM_ARCH_*__ macros will be defined by the compiler. */ 185239268Sgonzo/* The _ARM_ARCH_* macros are deprecated and will be removed soon. */ 186239268Sgonzo/* This should be moved into another header so it can be used in 187239268Sgonzo * both asm and C code. machine/asm.h cannot be included in C code. */ 188239268Sgonzo#if defined (__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__) 189239268Sgonzo#define _ARM_ARCH_7 190239268Sgonzo#define _HAVE_ARMv7_INSTRUCTIONS 1 191239268Sgonzo#endif 192137462Scognet 193239268Sgonzo#if defined (_HAVE_ARMv7_INSTRUCTIONS) || defined (__ARM_ARCH_6__) || \ 194239268Sgonzo defined (__ARM_ARCH_6J__) || defined (__ARM_ARCH_6K__) || \ 195239268Sgonzo defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__) 196137462Scognet#define _ARM_ARCH_6 197239268Sgonzo#define _HAVE_ARMv6_INSTRUCTIONS 1 198137462Scognet#endif 199137462Scognet 200239268Sgonzo#if defined (_HAVE_ARMv6_INSTRUCTIONS) || defined (__ARM_ARCH_5TE__) || \ 201172613Scognet defined (__ARM_ARCH_5TEJ__) || defined (__ARM_ARCH_5E__) 202239268Sgonzo#define _ARM_ARCH_5E 203239268Sgonzo#define _HAVE_ARMv5E_INSTRUCTIONS 1 204137462Scognet#endif 205137462Scognet 206239268Sgonzo#if defined (_HAVE_ARMv5E_INSTRUCTIONS) || defined (__ARM_ARCH_5__) || \ 207239268Sgonzo defined (__ARM_ARCH_5T__) 208239268Sgonzo#define _ARM_ARCH_5 209239268Sgonzo#define _HAVE_ARMv5_INSTRUCTIONS 1 210172613Scognet#endif 211172613Scognet 212239268Sgonzo#if defined (_HAVE_ARMv5_INSTRUCTIONS) || defined (__ARM_ARCH_4T__) 213137462Scognet#define _ARM_ARCH_4T 214239268Sgonzo#define _HAVE_ARMv4T_INSTRUCTIONS 1 215137462Scognet#endif 216137462Scognet 217239268Sgonzo/* FreeBSD requires ARMv4, so this is always set. */ 218239268Sgonzo#define _HAVE_ARMv4_INSTRUCTIONS 1 219137462Scognet 220239268Sgonzo#if defined (_HAVE_ARMv4T_INSTRUCTIONS) 221137462Scognet# define RET bx lr 222137462Scognet# define RETeq bxeq lr 223137462Scognet# define RETne bxne lr 224239268Sgonzo# define RETc(c) bx##c lr 225137462Scognet#else 226137462Scognet# define RET mov pc, lr 227137462Scognet# define RETeq moveq pc, lr 228137462Scognet# define RETne movne pc, lr 229239268Sgonzo# define RETc(c) mov##c pc, lr 230137462Scognet#endif 231137462Scognet 232276212Sian#if __ARM_ARCH >= 7 233276212Sian#define ISB isb 234276212Sian#define DSB dsb 235276212Sian#define DMB dmb 236276519Sian#define WFI wfi 237276212Sian#elif __ARM_ARCH == 6 238276212Sian#define ISB mcr CP15_CP15ISB 239276212Sian#define DSB mcr CP15_CP15DSB 240276212Sian#define DMB mcr CP15_CP15DMB 241276519Sian#define WFI mcr CP15_CP15WFI 242276212Sian#else 243276212Sian#define ISB mcr CP15_CP15ISB 244276212Sian#define DSB mcr CP15_CP15DSB /* DSB and DMB are the */ 245276212Sian#define DMB mcr CP15_CP15DSB /* same prior to v6.*/ 246276519Sian/* No form of WFI available on v4, define nothing to get an error on use. */ 247276212Sian#endif 248276212Sian 249129198Scognet#endif /* !_MACHINE_ASM_H_ */ 250