1*aa60921aSkettenis /* $OpenBSD: asm.h,v 1.12 2023/03/27 19:02:48 kettenis Exp $ */ 2f24071e5Spatrick /* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt Exp $ */ 3f24071e5Spatrick 4f24071e5Spatrick /* 5f24071e5Spatrick * Copyright (c) 1990 The Regents of the University of California. 6f24071e5Spatrick * All rights reserved. 7f24071e5Spatrick * 8f24071e5Spatrick * This code is derived from software contributed to Berkeley by 9f24071e5Spatrick * William Jolitz. 10f24071e5Spatrick * 11f24071e5Spatrick * Redistribution and use in source and binary forms, with or without 12f24071e5Spatrick * modification, are permitted provided that the following conditions 13f24071e5Spatrick * are met: 14f24071e5Spatrick * 1. Redistributions of source code must retain the above copyright 15f24071e5Spatrick * notice, this list of conditions and the following disclaimer. 16f24071e5Spatrick * 2. Redistributions in binary form must reproduce the above copyright 17f24071e5Spatrick * notice, this list of conditions and the following disclaimer in the 18f24071e5Spatrick * documentation and/or other materials provided with the distribution. 19f24071e5Spatrick * 3. Neither the name of the University nor the names of its contributors 20f24071e5Spatrick * may be used to endorse or promote products derived from this software 21f24071e5Spatrick * without specific prior written permission. 22f24071e5Spatrick * 23f24071e5Spatrick * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24f24071e5Spatrick * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25f24071e5Spatrick * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26f24071e5Spatrick * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27f24071e5Spatrick * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28f24071e5Spatrick * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29f24071e5Spatrick * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30f24071e5Spatrick * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31f24071e5Spatrick * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32f24071e5Spatrick * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33f24071e5Spatrick * SUCH DAMAGE. 34f24071e5Spatrick * 35f24071e5Spatrick * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 36f24071e5Spatrick */ 37f24071e5Spatrick 38f24071e5Spatrick #ifndef _MACHINE_ASM_H_ 39f24071e5Spatrick #define _MACHINE_ASM_H_ 40f24071e5Spatrick 41f24071e5Spatrick #define _C_LABEL(x) x 42f24071e5Spatrick #define _ASM_LABEL(x) x 43f24071e5Spatrick 44f24071e5Spatrick #ifdef __STDC__ 45f24071e5Spatrick # define __CONCAT(x,y) x ## y 46f24071e5Spatrick # define __STRING(x) #x 47f24071e5Spatrick #else 48f24071e5Spatrick # define __CONCAT(x,y) x/**/y 49f24071e5Spatrick # define __STRING(x) "x" 50f24071e5Spatrick #endif 51f24071e5Spatrick 52f24071e5Spatrick #ifndef _ALIGN_TEXT 53f24071e5Spatrick # define _ALIGN_TEXT .align 0 54f24071e5Spatrick #endif 55f24071e5Spatrick 56f24071e5Spatrick /* 57f24071e5Spatrick * gas/arm uses @ as a single comment character and thus cannot be used here 58f24071e5Spatrick * Instead it recognised the # instead of an @ symbols in .type directives 59f24071e5Spatrick * We define a couple of macros so that assembly code will not be dependant 60f24071e5Spatrick * on one or the other. 61f24071e5Spatrick */ 62f24071e5Spatrick #define _ASM_TYPE_FUNCTION #function 63f24071e5Spatrick #define _ASM_TYPE_OBJECT #object 643c890819Sguenther /* NB == No Binding: use .globl or .weak as necessary */ 653c890819Sguenther #define _ENTRY_NB(x) \ 663c890819Sguenther .text; _ALIGN_TEXT; .type x,_ASM_TYPE_FUNCTION; x: 673c890819Sguenther #define _ENTRY(x) .globl x; _ENTRY_NB(x) 68f24071e5Spatrick 69f5d1667bSmpi #if defined(PROF) || defined(GPROF) 70f24071e5Spatrick # define _PROF_PROLOGUE \ 71f24071e5Spatrick stp x29, x30, [sp, #-16]!; \ 72f24071e5Spatrick mov fp, sp; \ 73f24071e5Spatrick bl __mcount; \ 74f24071e5Spatrick ldp x29, x30, [sp], #16; 75f24071e5Spatrick #else 76f24071e5Spatrick # define _PROF_PROLOGUE 77f24071e5Spatrick #endif 78f24071e5Spatrick 79c03461ecSmortimer #if defined(_RET_PROTECTOR) 809237f5e2Smortimer # define RETGUARD_CALC_COOKIE(reg) \ 819237f5e2Smortimer eor reg, reg, x30 829237f5e2Smortimer 839237f5e2Smortimer # define RETGUARD_LOAD_RANDOM(x, reg) \ 849237f5e2Smortimer adrp reg, __CONCAT(__retguard_, x); \ 859237f5e2Smortimer ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)] 869237f5e2Smortimer 87c03461ecSmortimer # define RETGUARD_SETUP(x, reg) \ 88c03461ecSmortimer RETGUARD_SYMBOL(x); \ 899237f5e2Smortimer RETGUARD_LOAD_RANDOM(x, reg); \ 909237f5e2Smortimer RETGUARD_CALC_COOKIE(reg) 919237f5e2Smortimer 92c03461ecSmortimer # define RETGUARD_CHECK(x, reg) \ 939237f5e2Smortimer RETGUARD_CALC_COOKIE(reg); \ 949237f5e2Smortimer RETGUARD_LOAD_RANDOM(x, x9); \ 95c03461ecSmortimer subs reg, reg, x9; \ 96c03461ecSmortimer cbz reg, 66f; \ 97c03461ecSmortimer brk #0x1; \ 98c03461ecSmortimer 66: 999237f5e2Smortimer 100c03461ecSmortimer # define RETGUARD_PUSH(reg) \ 101c03461ecSmortimer str reg, [sp, #-16]! 1029237f5e2Smortimer 103c03461ecSmortimer # define RETGUARD_POP(reg) \ 104c03461ecSmortimer ldr reg, [sp, #16]! 1059237f5e2Smortimer 106c03461ecSmortimer # define RETGUARD_SYMBOL(x) \ 107c03461ecSmortimer .ifndef __CONCAT(__retguard_, x); \ 108c03461ecSmortimer .hidden __CONCAT(__retguard_, x); \ 109c03461ecSmortimer .type __CONCAT(__retguard_, x),@object; \ 110c03461ecSmortimer .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ 111c03461ecSmortimer .weak __CONCAT(__retguard_, x); \ 112c03461ecSmortimer .p2align 3; \ 113c03461ecSmortimer __CONCAT(__retguard_, x): ; \ 114c03461ecSmortimer .xword 0; \ 115c03461ecSmortimer .size __CONCAT(__retguard_, x), 8; \ 116c03461ecSmortimer .popsection; \ 117c03461ecSmortimer .endif 118c03461ecSmortimer #else 1199237f5e2Smortimer # define RETGUARD_CALC_COOKIE(reg) 1209237f5e2Smortimer # define RETGUARD_LOAD_RANDOM(x, reg) 121c03461ecSmortimer # define RETGUARD_SETUP(x, reg) 122c03461ecSmortimer # define RETGUARD_CHECK(x, reg) 123c03461ecSmortimer # define RETGUARD_PUSH(reg) 124c03461ecSmortimer # define RETGUARD_POP(reg) 125c03461ecSmortimer # define RETGUARD_SYMBOL(x) 126c03461ecSmortimer #endif 127c03461ecSmortimer 128*aa60921aSkettenis #define ENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE 129*aa60921aSkettenis #define ENTRY_NP(y) _ENTRY(y); bti c 130*aa60921aSkettenis #define ENTRY_NB(y) _ENTRY_NB(y); bti c; _PROF_PROLOGUE 131*aa60921aSkettenis #define ASENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE 132*aa60921aSkettenis #define ASENTRY_NP(y) _ENTRY(y); bti c 133f24071e5Spatrick #define END(y) .size y, . - y 134f24071e5Spatrick #define EENTRY(sym) .globl sym; sym: 135f24071e5Spatrick #define EEND(sym) 136f24071e5Spatrick 1377ba425baSjsg #ifdef __PIC__ 138fb956c4cSguenther #define PIC_SYM(x,y) x(y) 139f24071e5Spatrick #else 140f24071e5Spatrick #define PIC_SYM(x,y) x 141f24071e5Spatrick #endif 142f24071e5Spatrick 143f24071e5Spatrick #define STRONG_ALIAS(alias,sym) \ 144f24071e5Spatrick .global alias; \ 145f24071e5Spatrick alias = sym 146f24071e5Spatrick #define WEAK_ALIAS(alias,sym) \ 147f24071e5Spatrick .weak alias; \ 148f24071e5Spatrick alias = sym 149f24071e5Spatrick 150f24071e5Spatrick #endif /* !_MACHINE_ASM_H_ */ 151