SYS.h revision 1.25 1 1.25 uebayasi /* $NetBSD: SYS.h,v 1.25 2014/05/23 02:17:43 uebayasi Exp $ */
2 1.21 ad
3 1.21 ad /*-
4 1.21 ad * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.21 ad * All rights reserved.
6 1.21 ad *
7 1.21 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.21 ad * by Andrew Doran.
9 1.21 ad *
10 1.21 ad * Redistribution and use in source and binary forms, with or without
11 1.21 ad * modification, are permitted provided that the following conditions
12 1.21 ad * are met:
13 1.21 ad * 1. Redistributions of source code must retain the above copyright
14 1.21 ad * notice, this list of conditions and the following disclaimer.
15 1.21 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.21 ad * notice, this list of conditions and the following disclaimer in the
17 1.21 ad * documentation and/or other materials provided with the distribution.
18 1.21 ad *
19 1.21 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.21 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.21 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.21 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.21 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.21 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.21 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.21 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.21 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.21 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.21 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.21 ad */
31 1.21 ad
32 1.1 cgd /*-
33 1.1 cgd * Copyright (c) 1990 The Regents of the University of California.
34 1.1 cgd * All rights reserved.
35 1.1 cgd *
36 1.1 cgd * This code is derived from software contributed to Berkeley by
37 1.1 cgd * William Jolitz.
38 1.1 cgd *
39 1.1 cgd * Redistribution and use in source and binary forms, with or without
40 1.1 cgd * modification, are permitted provided that the following conditions
41 1.1 cgd * are met:
42 1.1 cgd * 1. Redistributions of source code must retain the above copyright
43 1.1 cgd * notice, this list of conditions and the following disclaimer.
44 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
45 1.1 cgd * notice, this list of conditions and the following disclaimer in the
46 1.1 cgd * documentation and/or other materials provided with the distribution.
47 1.20 agc * 3. Neither the name of the University nor the names of its contributors
48 1.1 cgd * may be used to endorse or promote products derived from this software
49 1.1 cgd * without specific prior written permission.
50 1.1 cgd *
51 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 1.1 cgd * SUCH DAMAGE.
62 1.1 cgd *
63 1.1 cgd * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
64 1.1 cgd */
65 1.1 cgd
66 1.1 cgd #include <machine/asm.h>
67 1.1 cgd #include <sys/syscall.h>
68 1.1 cgd
69 1.19 wiz #ifdef __STDC__
70 1.21 ad #define _SYSNAM(x) $(SYS_ ## x)
71 1.19 wiz #else
72 1.21 ad #define _SYSNAM(x) $(SYS_/**/x)
73 1.19 wiz #endif
74 1.8 jtc
75 1.21 ad #define OSYSTRAP(x) \
76 1.21 ad movl _SYSNAM(x),%eax ;\
77 1.21 ad int $0x80
78 1.21 ad
79 1.21 ad #ifdef I686_LIBC
80 1.21 ad #define SYSTRAP(x) \
81 1.21 ad pushl %ebx ;\
82 1.21 ad movl _SYSNAM(x),%eax ;\
83 1.21 ad movl $123f,%edx ;\
84 1.21 ad movl %esp,%ecx ;\
85 1.21 ad sysenter ;\
86 1.21 ad 123: movl %ebx,%edx ;\
87 1.21 ad popl %ebx
88 1.21 ad #else /* I686_LIBC */
89 1.21 ad #define SYSTRAP(x) OSYSTRAP(x)
90 1.21 ad #endif /* I686_LIBC */
91 1.21 ad
92 1.12 kleink #ifdef __ELF__
93 1.12 kleink #define CERROR _C_LABEL(__cerror)
94 1.12 kleink #define CURBRK _C_LABEL(__curbrk)
95 1.12 kleink #else
96 1.12 kleink #define CERROR _ASM_LABEL(cerror)
97 1.12 kleink #define CURBRK _ASM_LABEL(curbrk)
98 1.12 kleink #endif
99 1.8 jtc
100 1.11 kleink #define _SYSCALL_NOERROR(x,y) \
101 1.11 kleink ENTRY(x); \
102 1.11 kleink SYSTRAP(y)
103 1.11 kleink
104 1.24 joerg #ifdef __PIC__
105 1.22 dsl #define _SYSCALL_ERR \
106 1.22 dsl PIC_PROLOGUE; \
107 1.22 dsl mov PIC_GOT(CERROR), %ecx; \
108 1.22 dsl PIC_EPILOGUE; \
109 1.22 dsl jmp *%ecx
110 1.15 mycroft #else
111 1.22 dsl #define _SYSCALL_ERR \
112 1.22 dsl jmp CERROR
113 1.22 dsl #endif
114 1.22 dsl
115 1.15 mycroft #define _SYSCALL(x,y) \
116 1.15 mycroft .text; _ALIGN_TEXT; \
117 1.22 dsl 2: _SYSCALL_ERR; \
118 1.15 mycroft _SYSCALL_NOERROR(x,y); \
119 1.15 mycroft jc 2b
120 1.10 jtc
121 1.11 kleink #define SYSCALL_NOERROR(x) \
122 1.11 kleink _SYSCALL_NOERROR(x,x)
123 1.11 kleink
124 1.11 kleink #define SYSCALL(x) \
125 1.11 kleink _SYSCALL(x,x)
126 1.11 kleink
127 1.11 kleink #define PSEUDO_NOERROR(x,y) \
128 1.11 kleink _SYSCALL_NOERROR(x,y); \
129 1.25 uebayasi ret; \
130 1.25 uebayasi END(x)
131 1.10 jtc
132 1.11 kleink #define PSEUDO(x,y) \
133 1.22 dsl _SYSCALL_NOERROR(x,y); \
134 1.22 dsl jc 2f; \
135 1.22 dsl ret; \
136 1.25 uebayasi 2: _SYSCALL_ERR; \
137 1.25 uebayasi END(x)
138 1.10 jtc
139 1.11 kleink #define RSYSCALL_NOERROR(x) \
140 1.11 kleink PSEUDO_NOERROR(x,x)
141 1.11 kleink
142 1.11 kleink #define RSYSCALL(x) \
143 1.11 kleink PSEUDO(x,x)
144 1.11 kleink
145 1.16 thorpej #ifdef WEAK_ALIAS
146 1.16 thorpej #define WSYSCALL(weak,strong) \
147 1.16 thorpej WEAK_ALIAS(weak,strong); \
148 1.16 thorpej PSEUDO(strong,weak)
149 1.16 thorpej #else
150 1.16 thorpej #define WSYSCALL(weak,strong) \
151 1.16 thorpej PSEUDO(weak,weak)
152 1.16 thorpej #endif
153 1.1 cgd
154 1.12 kleink .globl CERROR
155