xref: /openbsd-src/lib/libc/arch/arm/SYS.h (revision 0b7734b3d77bb9b21afec6f4621cae6c805dbd45)
1 /*	$OpenBSD: SYS.h,v 1.15 2016/05/07 19:05:21 guenther Exp $	*/
2 /*	$NetBSD: SYS.h,v 1.8 2003/08/07 16:42:02 agc Exp $	*/
3 
4 /*-
5  * Copyright (c) 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * William Jolitz.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	from: @(#)SYS.h	5.5 (Berkeley) 5/7/91
36  */
37 
38 #include <machine/asm.h>
39 #include <sys/syscall.h>
40 
41 
42 /*
43  * We define a hidden alias with the prefix "_libc_" for each global symbol
44  * that may be used internally.  By referencing _libc_x instead of x, other
45  * parts of libc prevent overriding by the application and avoid unnecessary
46  * relocations.
47  */
48 #define _HIDDEN(x)		_libc_##x
49 #define _HIDDEN_ALIAS(x,y)			\
50 	STRONG_ALIAS(_HIDDEN(x),y);		\
51 	.hidden _HIDDEN(x)
52 #define _HIDDEN_FALIAS(x,y)			\
53 	_HIDDEN_ALIAS(x,y);			\
54 	.type _HIDDEN(x),#function
55 
56 /*
57  * For functions implemented in ASM that aren't syscalls.
58  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
59  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
60  */
61 #define	END_STRONG(x)	END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x))
62 #define	END_WEAK(x)	END_STRONG(x); .weak x
63 
64 
65 #define SYSENTRY(x)					\
66 	.weak _C_LABEL(x);				\
67 	_C_LABEL(x) = _C_LABEL(_thread_sys_ ## x);	\
68 	ENTRY(_thread_sys_ ## x)
69 #define SYSENTRY_HIDDEN(x)				\
70 	ENTRY(_thread_sys_ ## x)
71 #define __END_HIDDEN(x)					\
72 	END(_thread_sys_ ## x);				\
73 	_HIDDEN_FALIAS(x, _thread_sys_ ## x);		\
74 	END(_HIDDEN(x))
75 #define __END(x)					\
76 	__END_HIDDEN(x); END(x)
77 
78 #define SYSTRAP(x) \
79 	ldr	r12, =SYS_ ## x;		\
80 	swi	0
81 
82 #define	CERROR		_C_LABEL(__cerror)
83 
84 #define _SYSCALL_NOERROR(x,y)						\
85 	SYSENTRY(x);							\
86 	SYSTRAP(y)
87 #define _SYSCALL_HIDDEN_NOERROR(x,y)					\
88 	SYSENTRY_HIDDEN(x);						\
89 	SYSTRAP(y)
90 
91 #define _SYSCALL(x, y)							\
92 	_SYSCALL_NOERROR(x,y);						\
93 	bcs PIC_SYM(CERROR, PLT)
94 #define _SYSCALL_HIDDEN(x, y)						\
95 	_SYSCALL_HIDDEN_NOERROR(x,y);					\
96 	bcs PIC_SYM(CERROR, PLT)
97 
98 #define SYSCALL_NOERROR(x)						\
99 	_SYSCALL_NOERROR(x,x)
100 
101 #define SYSCALL(x)							\
102 	_SYSCALL(x,x)
103 
104 
105 #define PSEUDO_NOERROR(x,y)						\
106 	_SYSCALL_NOERROR(x,y);						\
107 	mov r15, r14;							\
108 	__END(x)
109 
110 #define PSEUDO(x,y)							\
111 	_SYSCALL(x,y);							\
112 	mov r15, r14;							\
113 	__END(x)
114 #define PSEUDO_HIDDEN(x,y)						\
115 	_SYSCALL_HIDDEN(x,y);						\
116 	mov r15, r14;							\
117 	__END_HIDDEN(x)
118 
119 
120 #define RSYSCALL_NOERROR(x)						\
121 	PSEUDO_NOERROR(x,x)
122 
123 #define RSYSCALL(x)							\
124 	PSEUDO(x,x)
125 #define RSYSCALL_HIDDEN(x)						\
126 	PSEUDO_HIDDEN(x,x)
127 #define SYSCALL_END(x)							\
128 	__END(x)
129 #define SYSCALL_END_HIDDEN(x)						\
130 	__END_HIDDEN(x)
131 
132 	.globl	CERROR
133