xref: /openbsd-src/libexec/ld.so/arm/SYS.h (revision 04459484ef65b24eeb35e1d5ee05aa2e814916db)
1*04459484Sderaadt /*	$OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:24 deraadt Exp $ */
2d6979ba5Sderaadt 
3d6979ba5Sderaadt /*
4d6979ba5Sderaadt  * Copyright (c) 2004 Dale Rahn
5d6979ba5Sderaadt  *
6d6979ba5Sderaadt  * Redistribution and use in source and binary forms, with or without
7d6979ba5Sderaadt  * modification, are permitted provided that the following conditions
8d6979ba5Sderaadt  * are met:
9d6979ba5Sderaadt  * 1. Redistributions of source code must retain the above copyright
10d6979ba5Sderaadt  *    notice, this list of conditions and the following disclaimer.
11d6979ba5Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
12d6979ba5Sderaadt  *    notice, this list of conditions and the following disclaimer in the
13d6979ba5Sderaadt  *    documentation and/or other materials provided with the distribution.
14d6979ba5Sderaadt  *
15d6979ba5Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16d6979ba5Sderaadt  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17d6979ba5Sderaadt  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18d6979ba5Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19d6979ba5Sderaadt  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20d6979ba5Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21d6979ba5Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22d6979ba5Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23d6979ba5Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24d6979ba5Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25d6979ba5Sderaadt  * SUCH DAMAGE.
26d6979ba5Sderaadt  *
27d6979ba5Sderaadt  */
28d6979ba5Sderaadt 
29d6979ba5Sderaadt #include <machine/asm.h>
30d6979ba5Sderaadt #include <sys/syscall.h>
31d6979ba5Sderaadt 
3283762a71Sderaadt #define PINSYSCALL(sysno, label)				\
33a0ef76c2Sderaadt 	.pushsection .openbsd.syscalls,"",%progbits		;\
34*04459484Sderaadt 	.p2align 2						;\
3583762a71Sderaadt 	.long label						;\
3683762a71Sderaadt 	.long sysno						;\
3783762a71Sderaadt 	.popsection
3883762a71Sderaadt 
39d6979ba5Sderaadt #define SYSTRAP(x) \
40d6979ba5Sderaadt 	ldr	r12, =SYS_ ## x					;\
4183762a71Sderaadt 99:	swi	0						;\
4283762a71Sderaadt 	PINSYSCALL(SYS_ ## x, 99b)				;\
43f74a2b77Sderaadt 	dsb	nsh						;\
44f74a2b77Sderaadt 	isb
45d6979ba5Sderaadt 
46d6979ba5Sderaadt #define DL_SYSCALL(n)						\
47d6979ba5Sderaadt 	.global		__CONCAT(_dl_,n)			;\
48d6979ba5Sderaadt 	.type		__CONCAT(_dl_,n)%function		;\
49d6979ba5Sderaadt __CONCAT(_dl_,n):						;\
50d6979ba5Sderaadt 	SYSTRAP(n)						;\
51d6979ba5Sderaadt 	bcs	.L_cerr						;\
52d6979ba5Sderaadt 	mov	pc, lr
53d6979ba5Sderaadt 
54d6979ba5Sderaadt .L_cerr:
55d6979ba5Sderaadt 	rsb	r0, r0, #0		/* r0 = -errno */
56d6979ba5Sderaadt 	mov	pc, lr
57