xref: /openbsd-src/lib/libc/arch/hppa/DEFS.h (revision b247cc180091d8af1ee36708f2f8076965851bb9)
1 /*	$OpenBSD: DEFS.h,v 1.2 2023/12/13 09:01:25 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 1998-2002 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND
22  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <machine/asm.h>
29 
30 #define	END(x)	EXIT(x)
31 
32 /*
33  * We define a hidden alias with the prefix "_libc_" for each global symbol
34  * that may be used internally.  By referencing _libc_x instead of x, other
35  * parts of libc prevent overriding by the application and avoid unnecessary
36  * relocations.
37  */
38 #define _HIDDEN(x)		_libc_##x
39 #define _HIDDEN_ALIAS(x,y)			\
40 	STRONG_ALIAS(_HIDDEN(x),y)		!\
41 	.hidden _HIDDEN(x)
42 #define _HIDDEN_FALIAS(x,y)			\
43 	_HIDDEN_ALIAS(x,y)			!\
44 	.type _HIDDEN(x),@function
45 
46 /*
47  * For functions implemented in ASM that aren't syscalls.
48  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
49  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
50  *   ALTEND_STRONG(x) and ALTEND_WEAK()
51  *			Matching macros for ALTENTRY functions
52  *   END_BUILTIN(x)	If compiling with clang, then just END() and
53  *			mark it .protected, else be like END_STRONG();
54  *			for clang builtins like memcpy
55  *
56  * If a 'BUILTIN' function needs be referenced by other ASM code, then use
57  *   _BUILTIN(x)	If compiled with clang, then just x, otherwise
58  *			_HIDDEN(x)
59  *
60  *   _END(x)		Set a size on a symbol, like END(), but even for
61  *			symbols with no matching ENTRY().  (On alpha and
62  *			mips64, END() generates .end which requires a
63  *			matching .ent from ENTRY())
64  */
65 #define	END_STRONG(x)	END(x) ! _HIDDEN_FALIAS(x,x) ! _END(_HIDDEN(x))
66 #define	END_WEAK(x)	END_STRONG(x) ! .weak x
67 #define	ALTEND_STRONG(x) _HIDDEN_FALIAS(x,x) ! _END(_HIDDEN(x))
68 #define	ALTEND_WEAK(x)	ALTEND_STRONG(x) ! .weak x
69 
70 #ifdef __clang__
71 #define	END_BUILTIN(x)	END(x) ! .protected x
72 #define	_BUILTIN(x)	x
73 #else
74 #define	END_BUILTIN(x)	END_STRONG(x)
75 #define	_BUILTIN(x)	_HIDDEN(x)
76 #endif
77 
78 #define _END(x)		.size x, . - x
79 
80 #define PINSYSCALL(sysno, label)			\
81 	.pushsection .openbsd.syscalls,"",@progbits	!\
82 	.p2align 2					!\
83 	.long label					!\
84 	.long sysno					!\
85 	.popsection
86