1/* $OpenBSD: asm.h,v 1.19 2023/02/03 06:13:08 miod Exp $ */
2/* $NetBSD: asm.h,v 1.1 1996/09/30 16:34:20 ws Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
6 * Copyright (C) 1995, 1996 TooLs GmbH.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by TooLs GmbH.
20 * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef _POWERPC_ASM_H_
36#define _POWERPC_ASM_H_
37
38#define _C_LABEL(x) x
39#define _ASM_LABEL(x) x
40
41#ifdef __STDC__
42# define _TMP_LABEL(x) .L_ ## x
43#else
44# define _TMP_LABEL(x) .L_/**/x
45#endif
46
47#define _ENTRY_NB(x) \
48 .text; .align 2; .type x,@function; x:
49#define _ENTRY(x) .globl x; _ENTRY_NB(x)
50
51#if defined(PROF) || defined(GPROF)
52# define _PROF_PROLOGUE(y) \
53 .section ".data"; \
54 .align 2; \
55_TMP_LABEL(y):; \
56 .long 0; \
57 .section ".text"; \
58 mflr 0; \
59 addis 11, 11, _TMP_LABEL(y)@ha; \
60 stw 0, 4(1); \
61 addi 0, 11,_TMP_LABEL(y)@l; \
62 bl _mcount;
63#else
64# define _PROF_PROLOGUE(y)
65#endif
66
67#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y)
68#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE(y)
69#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y)
70#define END(y) .size y, . - y
71
72#define STRONG_ALIAS(alias,sym) \
73 .global alias; .set alias,sym
74#define WEAK_ALIAS(alias,sym) \
75 .weak alias; .set alias,sym
76
77#if defined(_RET_PROTECTOR)
78# if defined(__PIC__)
79# define RETGUARD_LOAD_RANDOM(x, reg) \
80 bcl 20, 31, 66f; \
8166: mflr reg; \
82 addis reg, reg, (__retguard_ ## x - 66b)@ha; \
83 lwz reg, ((__retguard_ ## x - 66b)@l)(reg)
84# else
85# define RETGUARD_LOAD_RANDOM(x, reg) \
86 lis reg, (__retguard_ ## x)@ha; \
87 lwz reg, ((__retguard_ ## x)@l)(reg)
88# endif
89# define RETGUARD_SETUP(x, reg, retreg) \
90 mflr retreg; \
91 RETGUARD_SETUP_LATE(x, reg, retreg)
92# define RETGUARD_SETUP_LATE(x, reg, retreg) \
93 RETGUARD_SYMBOL(x); \
94 RETGUARD_LOAD_RANDOM(x, reg); \
95 xor reg, reg, retreg
96# define RETGUARD_CHECK(x, reg, retreg) \
97 xor reg, reg, retreg; \
98 RETGUARD_LOAD_RANDOM(x, %r10); \
99 mtlr retreg; \
100 twne reg, %r10
101# define RETGUARD_SAVE(reg, loc) \
102 stw reg, loc
103# define RETGUARD_LOAD(reg, loc) \
104 lwz reg, loc
105# define RETGUARD_SYMBOL(x) \
106 .ifndef __retguard_ ## x; \
107 .hidden __retguard_ ## x; \
108 .type __retguard_ ## x,@object; \
109 .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \
110 .weak __retguard_ ## x; \
111 .p2align 2; \
112 __retguard_ ## x: ; \
113 .long 0; \
114 .size __retguard_ ## x, 4; \
115 .popsection; \
116 .endif
117#else
118# define RETGUARD_LOAD_RANDOM(x, reg)
119# define RETGUARD_SETUP(x, reg, retreg)
120# define RETGUARD_SETUP_LATE(x, reg, retreg)
121# define RETGUARD_CHECK(x, reg, retreg)
122# define RETGUARD_SAVE(reg, loc)
123# define RETGUARD_LOAD(reg, loc)
124# define RETGUARD_SYMBOL(x)
125#endif
126
127#endif /* !_POWERPC_ASM_H_ */