Changes for 4.5.0 snapshot
[newlib-cygwin.git] / libgloss / cris / linunistd.h
blobb627670f5ba1d06e11271d45cb047e3deb3f4c44
1 /* Support for syscalls for cris*-axis-linux-gnu and simulators
2 Copyright (C) 1998-2005, 2018, 2023 Axis Communications.
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Neither the name of Axis Communications nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS
17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS
20 COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
29 /* Derived from asm-etrax100/unistd.h with minor modifications to fit as
30 LOSS for newlib. */
32 #ifndef _ASM_ELINUX_UNISTD_H_
33 #define _ASM_ELINUX_UNISTD_H_
35 #define _LIBC
37 /* Our callers might want to use link_warning, so provide it from here. */
38 #include "../config.h"
39 #include "libnosys/warning.h"
41 #include <unistd.h>
42 #include <errno.h>
45 * This file contains the system call numbers, and stub macros for libc.
48 #define __NR_setup 0 /* used only by init, to get system going */
49 #define __NR_exit 1
50 #define __NR_fork 2
51 #define __NR_read 3
52 #define __NR_write 4
53 #define __NR_open 5
54 #define __NR_close 6
55 #define __NR_waitpid 7
56 #define __NR_creat 8
57 #define __NR_link 9
58 #define __NR_unlink 10
59 #define __NR_execve 11
60 #define __NR_chdir 12
61 #define __NR_time 13
62 #define __NR_mknod 14
63 #define __NR_chmod 15
64 #define __NR_chown 16
65 #define __NR_break 17
66 #define __NR_oldstat 18
67 #define __NR_lseek 19
68 #define __NR_getpid 20
69 #define __NR_mount 21
70 #define __NR_umount 22
71 #define __NR_setuid 23
72 #define __NR_getuid 24
73 #define __NR_stime 25
74 #define __NR_ptrace 26
75 #define __NR_alarm 27
76 #define __NR_oldfstat 28
77 #define __NR_pause 29
78 #define __NR_utime 30
79 #define __NR_stty 31
80 #define __NR_gtty 32
81 #define __NR_access 33
82 #define __NR_nice 34
83 #define __NR_ftime 35
84 #define __NR_sync 36
85 #define __NR_kill 37
86 #define __NR_rename 38
87 #define __NR_mkdir 39
88 #define __NR_rmdir 40
89 #define __NR_dup 41
90 #define __NR_pipe 42
91 #define __NR_times 43
92 #define __NR_prof 44
93 #define __NR_brk 45
94 #define __NR_setgid 46
95 #define __NR_getgid 47
96 #define __NR_signal 48
97 #define __NR_geteuid 49
98 #define __NR_getegid 50
99 #define __NR_acct 51
100 #define __NR_phys 52
101 #define __NR_lock 53
102 #define __NR_ioctl 54
103 #define __NR_fcntl 55
104 #define __NR_mpx 56
105 #define __NR_setpgid 57
106 #define __NR_ulimit 58
107 #define __NR_oldolduname 59
108 #define __NR_umask 60
109 #define __NR_chroot 61
110 #define __NR_ustat 62
111 #define __NR_dup2 63
112 #define __NR_getppid 64
113 #define __NR_getpgrp 65
114 #define __NR_setsid 66
115 #define __NR_sigaction 67
116 #define __NR_sgetmask 68
117 #define __NR_ssetmask 69
118 #define __NR_setreuid 70
119 #define __NR_setregid 71
120 #define __NR_sigsuspend 72
121 #define __NR_sigpending 73
122 #define __NR_sethostname 74
123 #define __NR_setrlimit 75
124 #define __NR_getrlimit 76
125 #define __NR_getrusage 77
126 #define __NR_gettimeofday 78
127 #define __NR_settimeofday 79
128 #define __NR_getgroups 80
129 #define __NR_setgroups 81
130 #define __NR_select 82
131 #define __NR_symlink 83
132 #define __NR_oldlstat 84
133 #define __NR_readlink 85
134 #define __NR_uselib 86
135 #define __NR_swapon 87
136 #define __NR_reboot 88
137 #define __NR_readdir 89
138 #define __NR_mmap 90
139 #define __NR_munmap 91
140 #define __NR_truncate 92
141 #define __NR_ftruncate 93
142 #define __NR_fchmod 94
143 #define __NR_fchown 95
144 #define __NR_getpriority 96
145 #define __NR_setpriority 97
146 #define __NR_profil 98
147 #define __NR_statfs 99
148 #define __NR_fstatfs 100
149 #define __NR_ioperm 101
150 #define __NR_socketcall 102
151 #define __NR_syslog 103
152 #define __NR_setitimer 104
153 #define __NR_getitimer 105
154 #define __NR_stat 106
155 #define __NR_lstat 107
156 #define __NR_fstat 108
157 #define __NR_olduname 109
158 #define __NR_iopl 110
159 #define __NR_vhangup 111
160 #define __NR_idle 112
161 #define __NR_vm86 113
162 #define __NR_wait4 114
163 #define __NR_swapoff 115
164 #define __NR_sysinfo 116
165 #define __NR_ipc 117
166 #define __NR_fsync 118
167 #define __NR_sigreturn 119
168 #define __NR_clone 120
169 #define __NR_setdomainname 121
170 #define __NR_uname 122
171 #define __NR_modify_ldt 123
172 #define __NR_adjtimex 124
173 #define __NR_mprotect 125
174 #define __NR_sigprocmask 126
175 #define __NR_create_module 127
176 #define __NR_init_module 128
177 #define __NR_delete_module 129
178 #define __NR_get_kernel_syms 130
179 #define __NR_quotactl 131
180 #define __NR_getpgid 132
181 #define __NR_fchdir 133
182 #define __NR_bdflush 134
183 #define __NR_sysfs 135
184 #define __NR_personality 136
185 #define __NR_afs_syscall 137 /* Syscall for Andrew File System */
186 #define __NR_setfsuid 138
187 #define __NR_setfsgid 139
188 #define __NR__llseek 140
189 #define __NR_getdents 141
190 #define __NR__newselect 142
191 #define __NR_flock 143
192 #define __NR_msync 144
193 #define __NR_readv 145
194 #define __NR_writev 146
195 #define __NR_getsid 147
196 #define __NR_fdatasync 148
197 #define __NR__sysctl 149
198 #define __NR_mlock 150
199 #define __NR_munlock 151
200 #define __NR_mlockall 152
201 #define __NR_munlockall 153
202 #define __NR_sched_setparam 154
203 #define __NR_sched_getparam 155
204 #define __NR_sched_setscheduler 156
205 #define __NR_sched_getscheduler 157
206 #define __NR_sched_yield 158
207 #define __NR_sched_get_priority_max 159
208 #define __NR_sched_get_priority_min 160
209 #define __NR_sched_rr_get_interval 161
210 #define __NR_nanosleep 162
211 #define __NR_mremap 163
213 #define __NR_mmap2 192
215 #define PASTE(x,y) x##y
216 #define XSTR(x) # x
217 #define STR(x) XSTR (x)
219 #ifdef __elinux__
220 # define CRIS_SYSCALL "jir .$System.call"
221 # define CALLNO_REG r1
222 # define ARG5_REG r0
223 # define MOVE_ARG5 "move.d"
224 # define COLON_ARG5_CLOBBER : "r0"
225 #else
226 # define CRIS_SYSCALL "break 13"
227 # define CALLNO_REG r9
228 # define ARG5_REG srp
229 # define MOVE_ARG5 "move"
230 # define COLON_ARG5_CLOBBER
231 #endif
233 /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
234 #define _syscall0(type,name) \
235 type PASTE(_Sys_,name) (void) \
237 register long __a __asm__ ("r10"); \
238 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
239 __asm__ __volatile__ (CRIS_SYSCALL \
240 : "=r" (__a) \
241 : "r" (__n_)); \
242 if (__a >= 0) \
243 return (type) __a; \
244 errno = -__a; \
245 return -1; \
248 #define _syscall1(type,name,type1,arg1) \
249 type PASTE(_Sys_,name) (type1 arg1) \
251 register long __a __asm__ ("r10") = (long) arg1; \
252 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
253 __asm__ __volatile__ (CRIS_SYSCALL \
254 : "=r" (__a) \
255 : "r" (__n_), "0" (__a)); \
256 if (__a >= 0) \
257 return (type) __a; \
258 errno = -__a; \
259 return -1; \
262 #define _syscall2(type,name,type1,arg1,type2,arg2) \
263 type PASTE(_Sys_,name) (type1 arg1,type2 arg2) \
265 register long __a __asm__ ("r10") = (long) arg1; \
266 register long __b __asm__ ("r11") = (long) arg2; \
267 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
268 __asm__ __volatile__ (CRIS_SYSCALL \
269 : "=r" (__a) \
270 : "r" (__n_), "0" (__a), "r" (__b)); \
271 if (__a >= 0) \
272 return (type) __a; \
273 errno = -__a; \
274 return -1; \
277 #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
278 type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3) \
280 register long __a __asm__ ("r10") = (long) arg1; \
281 register long __b __asm__ ("r11") = (long) arg2; \
282 register long __c __asm__ ("r12") = (long) arg3; \
283 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
284 __asm__ __volatile__ (CRIS_SYSCALL \
285 : "=r" (__a) \
286 : "r" (__n_), "0" (__a), "r" (__b), "r" (__c)); \
287 if (__a >= 0) \
288 return (type) __a; \
289 errno = -__a; \
290 return -1; \
293 #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
294 type PASTE(_Sys_,name) (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
296 register long __a __asm__ ("r10") = (long) arg1; \
297 register long __b __asm__ ("r11") = (long) arg2; \
298 register long __c __asm__ ("r12") = (long) arg3; \
299 register long __d __asm__ ("r13") = (long) arg4; \
300 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
301 __asm__ __volatile__ (CRIS_SYSCALL \
302 : "=r" (__a) \
303 : "r" (__n_), "0" (__a), "r" (__b), \
304 "r" (__c), "r" (__d)); \
305 if (__a >= 0) \
306 return (type) __a; \
307 errno = -__a; \
308 return -1; \
311 #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
312 type5,arg5) \
313 type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
315 register long __a __asm__ ("r10") = (long) arg1; \
316 register long __b __asm__ ("r11") = (long) arg2; \
317 register long __c __asm__ ("r12") = (long) arg3; \
318 register long __d __asm__ ("r13") = (long) arg4; \
319 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
320 __asm__ __volatile__ (MOVE_ARG5 " %6,$" STR (ARG5_REG) "\n\t" \
321 CRIS_SYSCALL \
322 : "=r" (__a) \
323 : "r" (__n_), "0" (__a), "r" (__b), \
324 "r" (__c), "r" (__d), "g" (arg5) \
325 COLON_ARG5_CLOBBER); \
326 if (__a >= 0) \
327 return (type) __a; \
328 errno = -__a; \
329 return -1; \
332 #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
333 type5,arg5,type6,arg6) \
334 type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
336 register long __a __asm__ ("r10") = (long) arg1; \
337 register long __b __asm__ ("r11") = (long) arg2; \
338 register long __c __asm__ ("r12") = (long) arg3; \
339 register long __d __asm__ ("r13") = (long) arg4; \
340 register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
341 __asm__ __volatile__ (MOVE_ARG5 " %6,$" STR (ARG5_REG) "\n\t" \
342 "move %7,$mof\n\t" \
343 CRIS_SYSCALL \
344 : "=r" (__a) \
345 : "r" (__n_), "0" (__a), "r" (__b), \
346 "r" (__c), "r" (__d), "g" (arg5), "g" (arg6) \
347 COLON_ARG5_CLOBBER); \
348 if (__a >= 0) \
349 return (type) __a; \
350 errno = -__a; \
351 return -1; \
354 #define __NR__exit __NR_exit
355 static inline _syscall0(int,idle)
356 static inline _syscall0(int,fork)
357 static inline _syscall2(int,clone,unsigned long,flags,char *,esp)
358 static inline _syscall0(int,pause)
359 static inline _syscall0(int,setup)
360 static inline _syscall0(int,sync)
361 static inline _syscall3(int,write,int,fd,const char *,buf,unsigned,count)
362 static inline _syscall1(int,dup,int,fd)
363 static inline _syscall3(int,execve,const char *,file,char *const *,argv,char *const *,envp)
364 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
365 static inline _syscall1(int,close,int,fd)
366 static inline _syscall1(int,_exit,int,exitcode)
367 static inline _syscall1(int,exit,int,exitcode)
368 static inline _syscall3(int,waitpid,int,pid,int *,wait_stat,int,options)
369 static inline _syscall3(int,read,int,fd,char *,buf,unsigned,count)
370 static inline _syscall2(int,socketcall,int,call,unsigned long *,args)
371 static inline _syscall3(int,ioctl,unsigned int,fd,unsigned int,cmd,unsigned long,arg)
372 static inline _syscall3(int,fcntl,unsigned int,fd,unsigned int,cmd,unsigned long,arg)
373 static inline _syscall5(int,mount,const char *,a,const char *,b,const char *,c,unsigned long,rwflag,const void *,data)
374 static inline _syscall2(int,rename,const char *,a,const char*,b)
376 #ifndef __elinux__
377 /* Make sure these are only used where they are supported. */
378 static inline _syscall6(int,mmap2,unsigned long, addr, unsigned long, len,
379 unsigned long, prot, unsigned long, flags,
380 unsigned long, fd, unsigned long, pgoff)
381 static inline _syscall1(long,brk,long,addr)
382 #endif
384 /* This structure is ripped from asm-etrax100/stat.h: beware of updates. */
385 struct new_stat {
386 unsigned short st_dev;
387 unsigned short __pad1;
388 unsigned long st_ino;
389 unsigned short st_mode;
390 unsigned short st_nlink;
391 unsigned short st_uid;
392 unsigned short st_gid;
393 unsigned short st_rdev;
394 unsigned short __pad2;
395 unsigned long st_size;
396 unsigned long st_blksize;
397 unsigned long st_blocks;
398 unsigned long st_atime;
399 unsigned long __unused1;
400 unsigned long st_mtime;
401 unsigned long __unused2;
402 unsigned long st_ctime;
403 unsigned long __unused3;
404 unsigned long __unused4;
405 unsigned long __unused5;
408 typedef long int kernel_time_t;
409 typedef long int kernel_suseconds_t;
411 struct kernel_timeval {
412 kernel_time_t tv_sec;
413 kernel_suseconds_t tv_usec;
416 static inline _syscall2(int,stat,const char *,path,struct new_stat *,statbuf)
417 static inline _syscall2(int,fstat,int,fd,struct new_stat *,statbuf)
418 static inline _syscall0(int,getpid)
419 static inline _syscall2(int,kill,int,pid,int,sig)
420 static inline _syscall3(int,lseek,int,fd,int,offset,int,whence)
421 struct tms;
422 static inline _syscall1(long,times,struct tms *,tbuf)
423 static inline _syscall1(long,mmap,long *, buf)
424 struct timeval;
425 struct timezone;
426 static inline _syscall2(int,gettimeofday,struct kernel_timeval *,tp,
427 void *, tzp)
428 static inline _syscall2(int,link,const char *,old,const char *,new)
429 static inline _syscall1(int,unlink,const char *, f)
430 struct rusage;
431 static inline _syscall4(int,wait4,int,pid,int *,sa,int,op,struct rusage *,ru)
432 #endif /* _ASM_ELINUX_UNISTD_H_ */