Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES defined
[newlib-cygwin.git] / libgloss / cris / gensyscalls
blob0b5b0731a72592e41b6db0308c087fc2bf6a86f0
1 #! /bin/sh
2 # Copyright (C) 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 # To avoid an abundance of copyright/license messages for boilerplate
30 # code, we instead generate them from this file. Generating the
31 # function code could also be done automatically, but at the cost of
32 # slightly more intricate build machinery and/or scattered syscall
33 # information. Beware that the cat-lines must match the sed regexp
34 # "^cat > \([^ ]*\).*".
36 lu='/* -*- buffer-read-only: t -*-
37 THIS FILE IS AUTOMATICALLY GENERATED
38 FROM "'$0'". */
39 #include "linunistd.h"
40 #define R(x) return (x); }
42 lui="$lu int"
43 lul="$lu long int"
44 r=") { R (_Sys_"
46 cat > close.c <<EOF
47 $lui _close (int fd${r}close (fd))
48 EOF
49 cat > execve.c <<EOF
50 $lui _execve (const char *path, char * const *argv, char *const *env${r}execve (path, argv, env))
51 EOF
52 cat > exit.c <<EOF
53 $lu void _exit (int val) { _Sys_exit (val); /* Appease GCC: */ while (1) ; }
54 EOF
55 cat > fcntl.c <<EOF
56 $lui _fcntl (int fd, int cmd, long arg${r}fcntl (fd, cmd, arg))
57 EOF
58 cat > fork.c <<EOF
59 $lui _fork (void${r}fork ())
60 EOF
61 cat > fstat.c <<EOF
62 $lu#include <string.h>
63 #include <sys/stat.h>
64 #undef st_atime
65 #undef st_mtime
66 #undef st_ctime
67 int
68 _fstat (int fd, struct stat *buf)
70 struct new_stat ks;
71 int retval = _Sys_fstat (fd, &ks);
73 /* Blank before filling it in. */
74 memset (buf, 0, sizeof (*buf));
76 /* We have to translate from the linux struct new_stat.
77 It seems we don't have to translate the contents, though. */
78 buf->st_dev = ks.st_dev;
79 buf->st_ino = ks.st_ino;
80 buf->st_mode = ks.st_mode;
81 buf->st_nlink = ks.st_nlink;
82 buf->st_uid = ks.st_uid;
83 buf->st_gid = ks.st_gid;
84 buf->st_rdev = ks.st_rdev;
85 buf->st_size = ks.st_size;
86 buf->st_blksize = ks.st_blksize;
87 buf->st_blocks = ks.st_blocks;
88 buf->st_atim.tv_sec = ks.st_atime;
89 buf->st_mtim.tv_sec = ks.st_mtime;
90 buf->st_ctim.tv_sec = ks.st_ctime;
91 R (retval)
92 EOF
93 cat > getpid.c <<EOF
94 $lui _getpid (void${r}getpid ())
95 EOF
96 cat > gettod.c <<EOF
97 $lu#include <sys/time.h>
98 #include <sys/times.h>
99 int
100 _gettimeofday (struct timeval *tp, void *tzp)
102 struct kernel_timeval kt;
103 int retval = _Sys_gettimeofday(&kt, tzp);
104 if (retval == 0)
106 tp->tv_sec = kt.tv_sec;
107 tp->tv_usec = kt.tv_usec;
109 R (retval)
111 cat > isatty.c <<EOF
113 typedef unsigned int tcflag_t;
114 typedef unsigned char cc_t;
115 #define NCCS 19
117 struct termios {
118 tcflag_t c_iflag; /* input mode flags */
119 tcflag_t c_oflag; /* output mode flags */
120 tcflag_t c_cflag; /* control mode flags */
121 tcflag_t c_lflag; /* local mode flags */
122 cc_t c_line; /* line discipline */
123 cc_t c_cc[NCCS]; /* control characters */
126 /* From asm-etrax100/ioctls.h: beware of updates. */
127 #define TCGETS 0x5401
130 _isatty (int fd)
132 struct termios dummy;
133 int save_errno = errno;
134 int ret = _Sys_ioctl (fd, TCGETS, (unsigned long) &dummy);
135 errno = save_errno;
136 R (ret == 0)
138 cat > kill.c <<EOF
139 $lui _kill (int pid, int sig${r}kill (pid, sig))
141 cat > link.c <<EOF
142 $lui _link (const char *old, const char *new${r}link (old, new))
144 cat > lseek.c <<EOF
145 $lul _lseek (int fd, long int offset, int whence${r}lseek (fd, offset, whence))
147 cat > open.c <<EOF
148 $lui _open (const char *fnam, int flags, int mode${r}open (fnam, flags, mode))
150 cat > read.c <<EOF
151 $lui _read (int fd, void *buf, unsigned long int nbytes${r}read (fd, buf, nbytes))
153 cat > rename.c <<EOF
154 $lui _rename (const char *old, const char *new${r}rename (old, new))
156 cat > sbrk.c <<EOF
158 /* From asm-etrax100/mman.h: beware of updates. */
159 #define PROT_READ 0x1 /* page can be read */
160 #define PROT_WRITE 0x2 /* page can be written */
161 #define MAP_ANONYMOUS 0x20 /* don't use a file */
162 void *
163 _sbrk (long int d)
165 static long last_alloc = 0;
167 /* FIXME: Things are a whole lot different than elinux. */
168 #ifdef __elinux__
170 /* We can't promise linear memory from a predetermined location.
171 We're NO_MM. We're paria. We have to rely on tweaks and unclean
172 behavior. We abuse the fact that the malloc function in newlib
173 accepts nonlinear chunks in return to its sbrk calls (with a minor
174 patch). */
176 /* We use an "old" type mmap, which takes a pointer to a vector of 6
177 longs where the parameters are stored. */
178 long buffer[6];
180 /* We can't return memory. Well we could, but we would have to keep a
181 list of previous allocations. FIXME: Seems reasonable to do that
182 later. */
183 if (d < 0)
184 return (char *) last_alloc;
186 buffer[3] = MAP_ANONYMOUS; /* Not associated with a file. */
187 buffer[4] = -1; /* No file. */
188 buffer[0] = 0; /* Address 0: let mmap pick one. */
189 buffer[1] = d; /* Length. */
190 buffer[2] = (PROT_READ | PROT_WRITE); /* Protection flags. */
191 buffer[5] = 0; /* Offset into file. */
193 last_alloc = _Sys_mmap (buffer);
195 return (char *) last_alloc;
197 #else /* not __elinux__ */
199 long prev_brk;
201 if (last_alloc == 0)
203 last_alloc = _Sys_brk (0);
205 if (last_alloc < 0)
206 return (char *) -1;
209 prev_brk = last_alloc;
211 if (_Sys_brk (last_alloc + d) < last_alloc + d)
212 return (char *) -1;
214 last_alloc += d;
216 return (char *) prev_brk;
217 #endif
220 cat > stat.c <<EOF
221 $lu#include <string.h>
222 #include <sys/stat.h>
223 #undef st_atime
224 #undef st_mtime
225 #undef st_ctime
227 _stat (const char *path, struct stat *buf)
229 struct new_stat ks;
230 int retval = _Sys_stat (path, &ks);
232 /* Blank before filling it in. */
233 memset (buf, 0, sizeof (*buf));
235 /* We have to translate from the linux struct new_stat.
236 It seems we don't have to translate the contents, though. */
237 buf->st_dev = ks.st_dev;
238 buf->st_ino = ks.st_ino;
239 buf->st_mode = ks.st_mode;
240 buf->st_nlink = ks.st_nlink;
241 buf->st_uid = ks.st_uid;
242 buf->st_gid = ks.st_gid;
243 buf->st_rdev = ks.st_rdev;
244 buf->st_size = ks.st_size;
245 buf->st_blksize = ks.st_blksize;
246 buf->st_blocks = ks.st_blocks;
247 buf->st_atim.tv_sec = ks.st_atime;
248 buf->st_mtim.tv_sec = ks.st_mtime;
249 buf->st_ctim.tv_sec = ks.st_ctime;
250 R (retval)
252 cat > times.c <<EOF
253 $lu#include <sys/times.h>
254 clock_t
255 _times (struct tms * tp${r}times (tp))
257 cat > unlink.c <<EOF
258 $lui _unlink (const char *f${r}unlink (f))
260 cat > wait.c <<EOF
261 $lui _wait (int *status${r}wait4 (_getpid(), status, 0, 0))
263 cat > write.c <<EOF
264 $lui _write (int fd, const void *buf, unsigned long int nbytes${r}write (fd, buf, nbytes))
266 exit 0