1/*	$OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:24 deraadt Exp $	*/
2
3/*
4 * Copyright (c) 2013 Miodrag Vallat.
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 * Copyright (c) 2006 Dale Rahn
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
31 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
34 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include <machine/asm.h>
45#include <sys/syscall.h>
46
47#define PINSYSCALL(sysno, label)				\
48	.pushsection .openbsd.syscalls,"",@progbits		;\
49	.p2align 2						;\
50	.long label						;\
51	.long sysno						;\
52	.popsection
53
54#define	__CONCAT(p,x)		p##x
55#define	__ENTRY(p,x)		ENTRY(__CONCAT(p,x))
56#define	__SYSCALLNAME(p,x)	__CONCAT(p,x)
57
58#define	__DO_SYSCALL(x)						\
59	or %r13, %r0, __SYSCALLNAME(SYS_,x)			;\
6099:	tb0 0, %r0, 450						;\
61	PINSYSCALL(__SYSCALLNAME(SYS_,x), 99b)
62
63/*
64 * m88k syscall return ABI requires the same amount of ASM
65 * whether or not the syscall can possibly fail, so there's
66 * no benefit to a DL_SYSCALL_NOERR() macro.
67 */
68#define DL_SYSCALL(n)						\
69	__ENTRY(_dl_,n)						;\
70	__DO_SYSCALL(n)						;\
71	subu	%r2, %r0, %r2	/* return -errno; */		;\
72	jmp	%r1						;\
73	END(_dl_##n)
74