xref: /openbsd/libexec/ld.so/riscv64/SYS.h (revision 04459484)
1*04459484Sderaadt /*	$OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:25 deraadt Exp $ */
26d91b5a8Sdrahn 
36d91b5a8Sdrahn /*
46d91b5a8Sdrahn  * Copyright (c) 2016 Dale Rahn <drahn@openbsd.org>
56d91b5a8Sdrahn  *
66d91b5a8Sdrahn  * Redistribution and use in source and binary forms, with or without
76d91b5a8Sdrahn  * modification, are permitted provided that the following conditions
86d91b5a8Sdrahn  * are met:
96d91b5a8Sdrahn  * 1. Redistributions of source code must retain the above copyright
106d91b5a8Sdrahn  *    notice, this list of conditions and the following disclaimer.
116d91b5a8Sdrahn  * 2. Redistributions in binary form must reproduce the above copyright
126d91b5a8Sdrahn  *    notice, this list of conditions and the following disclaimer in the
136d91b5a8Sdrahn  *    documentation and/or other materials provided with the distribution.
146d91b5a8Sdrahn  *
156d91b5a8Sdrahn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
166d91b5a8Sdrahn  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
176d91b5a8Sdrahn  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
186d91b5a8Sdrahn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
196d91b5a8Sdrahn  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
206d91b5a8Sdrahn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
216d91b5a8Sdrahn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
226d91b5a8Sdrahn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
236d91b5a8Sdrahn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
246d91b5a8Sdrahn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
256d91b5a8Sdrahn  * SUCH DAMAGE.
266d91b5a8Sdrahn  *
276d91b5a8Sdrahn  */
286d91b5a8Sdrahn 
296d91b5a8Sdrahn #include <machine/asm.h>
306d91b5a8Sdrahn #include <sys/syscall.h>
316d91b5a8Sdrahn 
3283762a71Sderaadt #define PINSYSCALL(sysno, label)				\
3383762a71Sderaadt 	.pushsection .openbsd.syscalls,"",@progbits		;\
34*04459484Sderaadt 	.p2align 2						;\
3583762a71Sderaadt 	.long label						;\
3683762a71Sderaadt 	.long sysno						;\
3783762a71Sderaadt 	.popsection
3883762a71Sderaadt 
396d91b5a8Sdrahn #define SYSTRAP(x)						\
406d91b5a8Sdrahn 	li	t0, SYS_ ## x					;\
4183762a71Sderaadt 99:	ecall							;\
4283762a71Sderaadt 	PINSYSCALL(SYS_ ## x, 99b)
436d91b5a8Sdrahn 	/* XXX fence */
446d91b5a8Sdrahn 
456d91b5a8Sdrahn #define DL_SYSCALL(n)						\
466d91b5a8Sdrahn 	.global		__CONCAT(_dl_,n)			;\
476d91b5a8Sdrahn 	.type		__CONCAT(_dl_,n)%function		;\
486d91b5a8Sdrahn __CONCAT(_dl_,n):						;\
496d91b5a8Sdrahn 	RETGUARD_SETUP(__CONCAT(_dl_,n), x15)			;\
506d91b5a8Sdrahn 	SYSTRAP(n)						;\
516d91b5a8Sdrahn 	beqz	t0, 1f						;\
526d91b5a8Sdrahn 	sub	a0, zero, a0	/* r0 = -errno */		;\
536d91b5a8Sdrahn 1:								;\
546d91b5a8Sdrahn 	RETGUARD_CHECK(__CONCAT(_dl_,n), x15)	 		;\
556d91b5a8Sdrahn 	ret
56