1168054Sflz/*	$OpenBSD: SYS.h,v 1.7 2023/12/11 22:29:23 deraadt Exp $ */
2168054Sflz
3168266Sgabor/*
4168266Sgabor * Copyright (c) 2016 Dale Rahn
5168266Sgabor *
6168266Sgabor * Redistribution and use in source and binary forms, with or without
7168266Sgabor * modification, are permitted provided that the following conditions
8168266Sgabor * are met:
9168266Sgabor * 1. Redistributions of source code must retain the above copyright
10168266Sgabor *    notice, this list of conditions and the following disclaimer.
11168054Sflz * 2. Redistributions in binary form must reproduce the above copyright
12168054Sflz *    notice, this list of conditions and the following disclaimer in the
13168064Sflz *    documentation and/or other materials provided with the distribution.
14168064Sflz *
15168064Sflz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16168064Sflz * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17168064Sflz * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18168064Sflz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19168064Sflz * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20168064Sflz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21168064Sflz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22168064Sflz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23168064Sflz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24168064Sflz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25168064Sflz * SUCH DAMAGE.
26168064Sflz *
27168054Sflz */
28168054Sflz
29168064Sflz#include <machine/asm.h>
30168054Sflz#include <sys/syscall.h>
31168064Sflz
32171129Sobrien#define PINSYSCALL(sysno, label)				\
33168939Stmclaugh	.pushsection .openbsd.syscalls,"",@progbits		;\
34168131Sbmah	.p2align 2						;\
35168113Smarcus	.long label						;\
36180225Smarcel	.long sysno						;\
37168123Snetchild	.popsection
38168939Stmclaugh
39168064Sflz#define SYSTRAP(x)						\
40168054Sflz	ldr	x8, =SYS_ ## x					;\
41168054Sflz99:	svc	0						;\
42168054Sflz	PINSYSCALL(SYS_ ## x, 99b)				;\
43168054Sflz	dsb	nsh						;\
44168261Sache	isb
45168077Sflz
46168077Sflz#define DL_SYSCALL(n)						\
47168126Sale	.global		__CONCAT(_dl_,n)			;\
48168069Sgarga	.type		__CONCAT(_dl_,n)%function		;\
49168472Snovel__CONCAT(_dl_,n):						;\
50179877Samdmi3	RETGUARD_SETUP(__CONCAT(_dl_,n), x15)			;\
51168274Ssem	SYSTRAP(n)						;\
52169073Saraujo	cneg	x0, x0, cs	/* r0 = -errno */		;\
53168667Sstefan	RETGUARD_CHECK(__CONCAT(_dl_,n), x15)	 		;\
54168274Ssem	ret
55188692Sbeat