1 /* $OpenBSD: asm.h,v 1.3 2020/06/25 09:03:01 kettenis Exp $ */ 2 3 /* 4 * Copyright (c) 2020 Dale Rahn <drahn@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _POWERPC64_ASM_H_ 20 #define _POWERPC64_ASM_H_ 21 22 #define _C_LABEL(x) x 23 #define _ASM_LABEL(x) x 24 25 #define _TMP_LABEL(x) .L_ ## x 26 #define _GEP_LABEL(x) .L_ ## x ## _gep0 27 #define _LEP_LABEL(x) .L_ ## x ## _lep0 28 29 #define _ENTRY(x) \ 30 .text; .align 2; .globl x; .type x,@function; x: \ 31 _GEP_LABEL(x): \ 32 addis %r2, %r12, .TOC.-_GEP_LABEL(x)@ha; \ 33 addi %r2, %r2, .TOC.-_GEP_LABEL(x)@l; \ 34 _LEP_LABEL(x): \ 35 .localentry _C_LABEL(x), _LEP_LABEL(x)-_GEP_LABEL(x); 36 37 #if defined(PROF) || defined(GPROF) 38 # define _PROF_PROLOGUE(y) \ 39 .section ".data"; \ 40 .align 2; \ 41 _TMP_LABEL(y):; \ 42 .long 0; \ 43 .section ".text"; \ 44 mflr %r0; \ 45 addis %r11, %r2, _TMP_LABEL(y)@toc@ha; \ 46 std %r0, 8(%r1); \ 47 addi %r0, %r11, _TMP_LABEL(y)@toc@l; \ 48 bl _mcount; 49 #else 50 # define _PROF_PROLOGUE(y) 51 #endif 52 53 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE(y) 54 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE(y) 55 #define END(y) .size y, . - y 56 57 #define STRONG_ALIAS(alias,sym) \ 58 .global alias; .set alias,sym 59 #define WEAK_ALIAS(alias,sym) \ 60 .weak alias; .set alias,sym 61 62 #endif /* !_POWERPC64_ASM_H_ */ 63