xref: /minix/lib/libc/arch/arm/SYS.h (revision 84d9c625)
1 /*	$NetBSD: SYS.h,v 1.15 2013/08/19 22:13:34 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	from: @(#)SYS.h	5.5 (Berkeley) 5/7/91
35  */
36 
37 #define _TEXT_SECTION	.section .text.hot, "ax"
38 
39 #include <machine/asm.h>
40 #include <sys/syscall.h>
41 #include <arm/swi.h>
42 
43 #ifndef __STDC__
44 #error __STDC__ not defined
45 #endif
46 
47 #if !defined(__thumb__)
48 #define SYSTRAP(x)	svc #SWI_OS_NETBSD | SYS_ ## x
49 #else
50 .macro	emitsvc	x
51 	mov	ip, r0
52 .ifeq	\x / 256
53 	movs	r0, #\x
54 .else
55 #if defined(_ARM_ARCH_7)
56 	movw	r0, #\x
57 #else
58 .ifeq (\x & 3)
59 	movs	r0, #(\x / 4)
60 	lsls	r0, r0, #3
61 .else
62 .ifeq (\x & 1)
63 	movs	r0, #(\x / 2)
64 	lsls	r0, r0, #1
65 .else
66 	movs	r0, #(\x / 256)
67 	lsls	r0, r0, #8
68 	adds	r0, r0, #(\x & 255)
69 .endif
70 .endif
71 #endif /* !_ARM_ARCH_7 */
72 .endif
73 	svc	#255
74 .endm
75 #define SYSTRAP(x)	emitsvc SYS_ ## x
76 #endif /* __thumb__ */
77 
78 #define	CERROR		_C_LABEL(__cerror)
79 #define	CURBRK		_C_LABEL(__curbrk)
80 
81 #define _SYSCALL_NOERROR(x,y)						\
82 	ENTRY(x);							\
83 	SYSTRAP(y)
84 
85 #if  !defined(__thumb__) || defined(_ARM_ARCH_T2)
86 #define	_INVOKE_CERROR()	bcs CERROR
87 #else
88 #define	_INVOKE_CERROR()	\
89 	bcc 86f; push {r3,lr}; bl CERROR; pop {r3,pc}; 86:
90 #endif
91 #define _SYSCALL(x, y)							\
92 	_SYSCALL_NOERROR(x,y);						\
93 	_INVOKE_CERROR()
94 
95 #define SYSCALL_NOERROR(x)						\
96 	_SYSCALL_NOERROR(x,x)
97 
98 #define SYSCALL(x)							\
99 	_SYSCALL(x,x)
100 
101 
102 #define PSEUDO_NOERROR(x,y)						\
103 	_SYSCALL_NOERROR(x,y);						\
104 	RET;								\
105 	END(x)
106 
107 #define PSEUDO(x,y)							\
108 	_SYSCALL(x,y);							\
109 	RET;								\
110 	END(x)
111 
112 
113 #define RSYSCALL_NOERROR(x)						\
114 	PSEUDO_NOERROR(x,x)
115 
116 #define RSYSCALL(x)							\
117 	PSEUDO(x,x)
118 
119 #ifdef WEAK_ALIAS
120 #define	WSYSCALL(weak,strong)						\
121 	WEAK_ALIAS(weak,strong);					\
122 	PSEUDO(strong,weak)
123 #else
124 #define	WSYSCALL(weak,strong)						\
125 	PSEUDO(weak,weak)
126 #endif
127 
128 	.hidden	CERROR
129 	.globl	CERROR
130