xref: /openbsd/libexec/ld.so/sh/SYS.h (revision d415bd75)
1 /*	$OpenBSD: SYS.h,v 1.2 2022/09/02 06:19:05 miod Exp $ */
2 
3 /*
4  * Copyright (c) 2006 Dale Rahn
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #include <machine/asm.h>
30 #include <sys/syscall.h>
31 
32 #ifdef __ASSEMBLER__
33 /*
34  * If the system call number fits in a 8-bit signed value (i.e. fits in 7 bits),
35  * then we can use the #imm8 addressing mode.
36  */
37 
38 .macro systrap num
39 .iflt \num - 128
40 	mov	# \num, r0
41 	trapa	#0x80
42 .else
43 	mov.l	903f, r0
44 	trapa	#0x80
45 	bra	904f
46 	 nop
47 	.align	2
48  903:	.long	\num
49  904:
50 .endif
51 .endm
52 #endif
53 
54 #define SYSTRAP(x)					\
55 		systrap	SYS_ ## x
56 
57 #define DL_SYSCALL(n)					\
58 	.global		__CONCAT(_dl_,n)		;\
59 	.type		__CONCAT(_dl_,n)%function	;\
60 __CONCAT(_dl_,n):					;\
61 	SYSTRAP(n)					;\
62 	bf	.L_cerr					;\
63 	 nop						;\
64 	rts						;\
65 	 nop
66 
67 .L_cerr:
68 	neg	r0, r0
69 	rts
70 	 nop
71