2 * include/asm-xtensa/unistd.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 #ifndef _XTENSA_UNISTD_H
12 #define _XTENSA_UNISTD_H
14 #include <linux/linkage.h>
16 //#define __NR_setup 0 /* used only by init, to get system going */
24 #define __NR_waitpid 7
27 #define __NR_unlink 10
28 #define __NR_execve 11
33 #define __NR_lchown 16
35 #define __NR_oldstat 18
37 #define __NR_getpid 20
39 #define __NR_oldumount 22
40 #define __NR_setuid 23
41 #define __NR_getuid 24
43 #define __NR_ptrace 26
45 #define __NR_oldfstat 28
50 #define __NR_access 33
55 #define __NR_rename 38
63 #define __NR_setgid 46
64 #define __NR_getgid 47
65 #define __NR_signal 48
66 #define __NR_geteuid 49
67 #define __NR_getegid 50
69 #define __NR_umount 52
74 #define __NR_setpgid 57
75 #define __NR_ulimit 58
76 #define __NR_oldolduname 59
78 #define __NR_chroot 61
81 #define __NR_getppid 64
82 #define __NR_getpgrp 65
83 #define __NR_setsid 66
84 #define __NR_sigaction 67
85 #define __NR_sgetmask 68
86 #define __NR_ssetmask 69
87 #define __NR_setreuid 70
88 #define __NR_setregid 71
89 #define __NR_sigsuspend 72
90 #define __NR_sigpending 73
91 #define __NR_sethostname 74
92 #define __NR_setrlimit 75
93 #define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */
94 #define __NR_getrusage 77
95 #define __NR_gettimeofday 78
96 #define __NR_settimeofday 79
97 #define __NR_getgroups 80
98 #define __NR_setgroups 81
99 #define __NR_select 82
100 #define __NR_symlink 83
101 #define __NR_oldlstat 84
102 #define __NR_readlink 85
103 #define __NR_uselib 86
104 #define __NR_swapon 87
105 #define __NR_reboot 88
106 #define __NR_readdir 89
108 #define __NR_munmap 91
109 #define __NR_truncate 92
110 #define __NR_ftruncate 93
111 #define __NR_fchmod 94
112 #define __NR_fchown 95
113 #define __NR_getpriority 96
114 #define __NR_setpriority 97
115 #define __NR_profil 98
116 #define __NR_statfs 99
117 #define __NR_fstatfs 100
118 #define __NR_ioperm 101
119 #define __NR_socketcall 102
120 #define __NR_syslog 103
121 #define __NR_setitimer 104
122 #define __NR_getitimer 105
123 #define __NR_stat 106
124 #define __NR_lstat 107
125 #define __NR_fstat 108
126 #define __NR_olduname 109
127 #define __NR_iopl 110
128 #define __NR_vhangup 111
129 #define __NR_idle 112
130 #define __NR_vm86 113
131 #define __NR_wait4 114
132 #define __NR_swapoff 115
133 #define __NR_sysinfo 116
135 #define __NR_fsync 118
136 #define __NR_sigreturn 119
137 #define __NR_clone 120
138 #define __NR_setdomainname 121
139 #define __NR_uname 122
140 #define __NR_modify_ldt 123
141 #define __NR_adjtimex 124
142 #define __NR_mprotect 125
143 #define __NR_sigprocmask 126
144 #define __NR_create_module 127
145 #define __NR_init_module 128
146 #define __NR_delete_module 129
147 #define __NR_get_kernel_syms 130
148 #define __NR_quotactl 131
149 #define __NR_getpgid 132
150 #define __NR_fchdir 133
151 #define __NR_bdflush 134
152 #define __NR_sysfs 135
153 #define __NR_personality 136
154 #define __NR_afs_syscall 137 /* Syscall for Andrew File System */
155 #define __NR_setfsuid 138
156 #define __NR_setfsgid 139
157 #define __NR__llseek 140
158 #define __NR_getdents 141
159 #define __NR__newselect 142
160 #define __NR_flock 143
161 #define __NR_msync 144
162 #define __NR_readv 145
163 #define __NR_writev 146
164 #define __NR_cacheflush 147
165 #define __NR_cachectl 148
166 #define __NR_sysxtensa 149
167 #define __NR_sysdummy 150
168 #define __NR_getsid 151
169 #define __NR_fdatasync 152
170 #define __NR__sysctl 153
171 #define __NR_mlock 154
172 #define __NR_munlock 155
173 #define __NR_mlockall 156
174 #define __NR_munlockall 157
175 #define __NR_sched_setparam 158
176 #define __NR_sched_getparam 159
177 #define __NR_sched_setscheduler 160
178 #define __NR_sched_getscheduler 161
179 #define __NR_sched_yield 162
180 #define __NR_sched_get_priority_max 163
181 #define __NR_sched_get_priority_min 164
182 #define __NR_sched_rr_get_interval 165
183 #define __NR_nanosleep 166
184 #define __NR_mremap 167
185 #define __NR_accept 168
186 #define __NR_bind 169
187 #define __NR_connect 170
188 #define __NR_getpeername 171
189 #define __NR_getsockname 172
190 #define __NR_getsockopt 173
191 #define __NR_listen 174
192 #define __NR_recv 175
193 #define __NR_recvfrom 176
194 #define __NR_recvmsg 177
195 #define __NR_send 178
196 #define __NR_sendmsg 179
197 #define __NR_sendto 180
198 #define __NR_setsockopt 181
199 #define __NR_shutdown 182
200 #define __NR_socket 183
201 #define __NR_socketpair 184
202 #define __NR_setresuid 185
203 #define __NR_getresuid 186
204 #define __NR_query_module 187
205 #define __NR_poll 188
206 #define __NR_nfsservctl 189
207 #define __NR_setresgid 190
208 #define __NR_getresgid 191
209 #define __NR_prctl 192
210 #define __NR_rt_sigreturn 193
211 #define __NR_rt_sigaction 194
212 #define __NR_rt_sigprocmask 195
213 #define __NR_rt_sigpending 196
214 #define __NR_rt_sigtimedwait 197
215 #define __NR_rt_sigqueueinfo 198
216 #define __NR_rt_sigsuspend 199
217 #define __NR_pread 200
218 #define __NR_pwrite 201
219 #define __NR_chown 202
220 #define __NR_getcwd 203
221 #define __NR_capget 204
222 #define __NR_capset 205
223 #define __NR_sigaltstack 206
224 #define __NR_sendfile 207
225 #define __NR_streams1 208 /* some people actually want it */
226 #define __NR_streams2 209 /* some people actually want it */
227 #define __NR_mmap2 210
228 #define __NR_truncate64 211
229 #define __NR_ftruncate64 212
230 #define __NR_stat64 213
231 #define __NR_lstat64 214
232 #define __NR_fstat64 215
233 #define __NR_pivot_root 216
234 #define __NR_mincore 217
235 #define __NR_madvise 218
236 #define __NR_getdents64 219
237 #define __NR_vfork 220
239 /* Keep this last; should always equal the last valid call number. */
240 #define __NR_Linux_syscalls 220
242 /* user-visible error numbers are in the range -1 - -125: see
243 * <asm-xtensa/errno.h> */
245 #define SYSXTENSA_RESERVED 0 /* don't use this */
246 #define SYSXTENSA_ATOMIC_SET 1 /* set variable */
247 #define SYSXTENSA_ATOMIC_EXG_ADD 2 /* exchange memory and add */
248 #define SYSXTENSA_ATOMIC_ADD 3 /* add to memory */
249 #define SYSXTENSA_ATOMIC_CMP_SWP 4 /* compare and swap */
251 #define SYSXTENSA_COUNT 5 /* count of syscall0 functions*/
254 #define __syscall_return(type, res) return ((type)(res))
256 #define __syscall_return(type, res) \
258 if ((unsigned long)(res) >= (unsigned long)(-125)) { \
259 /* Avoid using "res" which is declared to be in register r2; \
260 * errno might expand to a function call and clobber it. */ \
261 int __err = -(res); \
265 return (type) (res); \
270 /* Tensilica's xt-xcc compiler is much more agressive at code
271 * optimization than gcc. Multiple __asm__ statements are
272 * insufficient for xt-xcc because subsequent optimization passes
273 * (beyond the front-end that knows of __asm__ statements and other
274 * such GNU Extensions to C) can modify the register selection for
275 * containment of C variables.
277 * xt-xcc cannot modify the contents of a single __asm__ statement, so
278 * we create single-asm versions of the syscall macros that are
279 * suitable and optimal for both xt-xcc and gcc.
281 * Linux takes system-call arguments in registers. The following
282 * design is optimized for user-land apps (e.g., glibc) which
283 * typically have a function wrapper around the "syscall" assembly
284 * instruction. It satisfies the Xtensa ABI while minizing argument
287 * The Xtensa ABI and software conventions require the system-call
288 * number in a2. If an argument exists in a2, we move it to the next
289 * available register. Note that for improved efficiency, we do NOT
290 * shift all parameters down one register to maintain the original
293 * At best case (zero arguments), we just write the syscall number to
294 * a2. At worst case (1 to 6 arguments), we move the argument in a2
295 * to the next available register, then write the syscall number to
298 * For clarity, the following truth table enumerates all possibilities.
300 * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
301 * --------- -------------- ----------------------------------
306 * 4 a2 a6, a3, a4, a5
307 * 5 a2 a7, a3, a4, a5, a6
308 * 6 a2 a8, a3, a4, a5, a6, a7
311 #define _syscall0(type,name) \
315 __asm__ __volatile__ ( \
320 : "i" (__NR_##name) \
323 __syscall_return(type,__res); \
326 #define _syscall1(type,name,type0,arg0) \
327 type name(type0 arg0) \
330 __asm__ __volatile__ ( \
336 : "i" (__NR_##name), "a" (arg0) \
339 __syscall_return(type,__res); \
342 #define _syscall2(type,name,type0,arg0,type1,arg1) \
343 type name(type0 arg0,type1 arg1) \
346 __asm__ __volatile__ ( \
353 : "i" (__NR_##name), "a" (arg0), "a" (arg1) \
356 __syscall_return(type,__res); \
359 #define _syscall3(type,name,type0,arg0,type1,arg1,type2,arg2) \
360 type name(type0 arg0,type1 arg1,type2 arg2) \
363 __asm__ __volatile__ ( \
371 : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2) \
372 : "a2", "a3", "a4", "a5" \
374 __syscall_return(type,__res); \
377 #define _syscall4(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3) \
378 type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3) \
381 __asm__ __volatile__ ( \
390 : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), "a" (arg3) \
391 : "a2", "a3", "a4", "a5", "a6" \
393 __syscall_return(type,__res); \
396 /* Note that we save and restore the a7 frame pointer.
397 * Including a7 in the clobber list doesn't do what you'd expect.
399 #define _syscall5(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
400 type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
403 __asm__ __volatile__ ( \
415 : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), \
416 "a" (arg3), "a" (arg4) \
417 : "a2", "a3", "a4", "a5", "a6", "a9" \
419 __syscall_return(type,__res); \
422 /* Note that we save and restore the a7 frame pointer.
423 * Including a7 in the clobber list doesn't do what you'd expect.
425 #define _syscall6(type,name,type0,arg0,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \
426 type name(type0 arg0,type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
429 __asm__ __volatile__ ( \
442 : "i" (__NR_##name), "a" (arg0), "a" (arg1), "a" (arg2), \
443 "a" (arg3), "a" (arg4), "a" (arg5) \
444 : "a2", "a3", "a4", "a5", "a6", "a8", "a9" \
446 __syscall_return(type,__res); \
450 #ifdef __KERNEL_SYSCALLS__
452 #include <linux/compiler.h>
453 #include <linux/types.h>
454 #include <linux/syscalls.h>
457 * we need this inline - forking from kernel space will result
458 * in NO COPY ON WRITE (!!!), until an execve is executed. This
459 * is no problem, but for the stack. This is handled by not letting
460 * main() use the stack at all after fork(). Thus, no function
461 * calls - which means inline code for fork too, as otherwise we
462 * would use the stack upon exit from 'fork()'.
464 * Actually only pause and fork are needed inline, so that there
465 * won't be any messing with the stack from main(), but we define
469 #define __NR__exit __NR_exit
471 static __inline__
_syscall0(int,pause
)
472 //static __inline__ _syscall1(int,setup,int,magic) FIXME
473 static __inline__
_syscall0(int,sync
)
474 static __inline__
_syscall0(pid_t
,setsid
)
475 static __inline__
_syscall3(int,write
,int,fd
,const char *,buf
,off_t
,count
)
476 static __inline__
_syscall3(int,read
,int,fd
,char *,buf
,off_t
,count
)
477 static __inline__
_syscall3(off_t
,lseek
,int,fd
,off_t
,offset
,int,count
)
478 static __inline__
_syscall1(int,dup
,int,fd
)
479 static __inline__
_syscall3(int,execve
,const char*,file
,char**,argv
,char**,envp
)
480 static __inline__
_syscall3(int,open
,const char *,file
,int,flag
,int,mode
)
481 static __inline__
_syscall1(int,close
,int,fd
)
482 static __inline__
_syscall1(int,_exit
,int,exitcode
)
483 static __inline__
_syscall3(pid_t
,waitpid
,pid_t
,pid
,int *,wait_stat
,int,options
)
484 static __inline__
_syscall1(int,delete_module
,const char *,name
)
487 static __inline__
_syscall2(int,fstat
,int,fd
,struct stat
*,buf
)
488 static __inline__
_syscall0(pid_t
,getpid
)
489 static __inline__
_syscall2(int,kill
,int,pid
,int,sig
)
490 static __inline__
_syscall2(int,stat
,const char *, path
,struct stat
*,buf
)
491 static __inline__
_syscall1(int,unlink
,char *,pathname
)
495 extern pid_t
waitpid(int, int*, int );
496 static __inline__ pid_t
wait(int * wait_stat
)
498 return waitpid(-1,wait_stat
,0);
503 * "Conditional" syscalls
505 * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
506 * but it doesn't work on all toolchains, so we just do it by hand
508 #define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall");
511 #define __ARCH_WANT_IPC_PARSE_VERSION
512 #define __ARCH_WANT_OLD_READDIR
513 #define __ARCH_WANT_OLD_STAT
514 #define __ARCH_WANT_STAT64
515 #define __ARCH_WANT_SYS_ALARM
516 #define __ARCH_WANT_SYS_GETHOSTNAME
517 #define __ARCH_WANT_SYS_PAUSE
518 #define __ARCH_WANT_SYS_SGETMASK
519 #define __ARCH_WANT_SYS_SIGNAL
520 #define __ARCH_WANT_SYS_TIME
521 #define __ARCH_WANT_SYS_UTIME
522 #define __ARCH_WANT_SYS_WAITPID
523 #define __ARCH_WANT_SYS_SOCKETCALL
524 #define __ARCH_WANT_SYS_FADVISE64
525 #define __ARCH_WANT_SYS_GETPGRP
526 #define __ARCH_WANT_SYS_LLSEEK
527 #define __ARCH_WANT_SYS_NICE
528 #define __ARCH_WANT_SYS_OLD_GETRLIMIT
529 #define __ARCH_WANT_SYS_OLDUMOUNT
530 #define __ARCH_WANT_SYS_SIGPENDING
531 #define __ARCH_WANT_SYS_SIGPROCMASK
532 #define __ARCH_WANT_SYS_RT_SIGACTION
537 #endif /* _XTENSA_UNISTD_H */