source: trunk/libs/newlib/src/libgloss/cris/gensyscalls @ 514

Last change on this file since 514 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 7.2 KB
RevLine 
[444]1#! /bin/sh
2#  Copyright (C) 2005 Axis Communications.
3#  All rights reserved.
4#
5#  Redistribution and use in source and binary forms, with or without
6#  modification, are permitted provided that the following conditions
7#  are met:
8#
9#  1. Redistributions of source code must retain the above copyright
10#     notice, this list of conditions and the following disclaimer.
11#
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.
15#
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.
28
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 > \([^ ]*\).*".
35
36lu='/* -*- buffer-read-only: t -*-
37   THIS FILE IS AUTOMATICALLY GENERATED
38   FROM "'$0'".  */
39#include "linunistd.h"
40#define R(x) return (x); }
41'
42lui="$lu int"
43r=") { R (_Sys_"
44
45cat > close.c <<EOF
46$lui _close (int fd${r}close (fd))
47EOF
48cat > execve.c <<EOF
49$lui _execve (char *path, char **argv, char **env${r}execve (path, argv, env))
50EOF
51cat > exit.c <<EOF
52$lu void _exit (int val) { _Sys_exit (val); /* Appease GCC: */ while (1) ; }
53EOF
54cat > fcntl.c <<EOF
55$lui _fcntl (int fd, int cmd, long arg${r}fcntl (fd, cmd, arg))
56EOF
57cat > fork.c <<EOF
58$lui _fork (void${r}fork ())
59EOF
60cat > fstat.c <<EOF
61$lu#include <string.h>
62#include <sys/stat.h>
63int
64_fstat (int fd, struct stat *buf)
65{
66  struct new_stat ks;
67  int retval = _Sys_fstat (fd, &ks);
68
69  /* Blank before filling it in.  */
70  memset (buf, 0, sizeof (*buf));
71
72  /* We have to translate from the linux struct new_stat.
73     It seems we don't have to translate the contents, though.  */
74  buf->st_dev = ks.st_dev;
75  buf->st_ino = ks.st_ino;
76  buf->st_mode = ks.st_mode;
77  buf->st_nlink = ks.st_nlink;
78  buf->st_uid = ks.st_uid;
79  buf->st_gid = ks.st_gid;
80  buf->st_rdev = ks.st_rdev;
81  buf->st_size = ks.st_size;
82  buf->st_blksize = ks.st_blksize;
83  buf->st_blocks = ks.st_blocks;
84  buf->st_atime = ks.st_atime;
85  buf->st_mtime = ks.st_mtime;
86  buf->st_ctime = ks.st_ctime;
87  R (retval)
88EOF
89cat > getpid.c <<EOF
90$lui _getpid (void${r}getpid ())
91EOF
92cat > gettod.c <<EOF
93$lu#include <sys/time.h>
94#include <sys/times.h>
95int
96_gettimeofday (struct timeval *tp, void *tzp
97${r}gettimeofday (tp, tzp))
98EOF
99cat > isatty.c <<EOF
100$lu
101typedef unsigned int tcflag_t;
102typedef unsigned char cc_t;
103#define NCCS 19
104
105struct termios {
106        tcflag_t c_iflag;               /* input mode flags */
107        tcflag_t c_oflag;               /* output mode flags */
108        tcflag_t c_cflag;               /* control mode flags */
109        tcflag_t c_lflag;               /* local mode flags */
110        cc_t c_line;                    /* line discipline */
111        cc_t c_cc[NCCS];                /* control characters */
112};
113
114/* From asm-etrax100/ioctls.h: beware of updates.  */
115#define TCGETS          0x5401
116
117int
118_isatty (int fd)
119{
120  struct termios dummy;
121  int save_errno = errno;
122  int ret = _Sys_ioctl (fd, TCGETS, (unsigned long) &dummy);
123  errno = save_errno;
124  R (ret == 0)
125EOF
126cat > kill.c <<EOF
127$lui _kill (int pid, int sig${r}kill (pid, sig))
128EOF
129cat > link.c <<EOF
130$lui _link (const char *old, const char *new${r}link (old, new))
131EOF
132cat > lseek.c <<EOF
133$lui _lseek (int fd, int offset, int whence${r}lseek (fd, offset, whence))
134EOF
135cat > open.c <<EOF
136$lui _open (const char *fnam, int flags, int mode${r}open (fnam, flags, mode))
137EOF
138cat > read.c <<EOF
139$lui _read (int fd, char *buf, int nbytes${r}read (fd, buf, nbytes))
140EOF
141cat > rename.c <<EOF
142$lui _rename (const char *old, const char *new${r}rename (old, new))
143EOF
144cat > sbrk.c <<EOF
145$lu
146/* From asm-etrax100/mman.h: beware of updates.  */
147#define PROT_READ       0x1             /* page can be read */
148#define PROT_WRITE      0x2             /* page can be written */
149#define MAP_ANONYMOUS   0x20            /* don't use a file */
150char *
151_sbrk (int d)
152{
153  static long last_alloc = 0;
154
155  /* FIXME: Things are a whole lot different than elinux.  */
156#ifdef __elinux__
157
158  /* We can't promise linear memory from a predetermined location.
159     We're NO_MM.  We're paria.  We have to rely on tweaks and unclean
160     behavior.  We abuse the fact that the malloc function in newlib
161     accepts nonlinear chunks in return to its sbrk calls (with a minor
162     patch).  */
163
164  /* We use an "old" type mmap, which takes a pointer to a vector of 6
165     longs where the parameters are stored.  */
166  long buffer[6];
167
168  /* We can't return memory.  Well we could, but we would have to keep a
169     list of previous allocations.  FIXME:  Seems reasonable to do that
170     later.  */
171  if (d < 0)
172    return (char *) last_alloc;
173
174  buffer[3] = MAP_ANONYMOUS;    /* Not associated with a file.  */
175  buffer[4] = -1;               /* No file.  */
176  buffer[0] = 0;                /* Address 0: let mmap pick one.  */
177  buffer[1] = d;                /* Length.  */
178  buffer[2] = (PROT_READ | PROT_WRITE); /* Protection flags.  */
179  buffer[5] = 0;                /* Offset into file.  */
180
181  last_alloc = _Sys_mmap (buffer);
182
183  return (char *) last_alloc;
184
185#else /* not __elinux__ */
186
187  long prev_brk;
188
189  if (last_alloc == 0)
190  {
191    last_alloc = _Sys_brk (0);
192
193    if (last_alloc < 0)
194      return (char *) -1;
195  }
196
197  prev_brk = last_alloc;
198
199  if (_Sys_brk (last_alloc + d) < last_alloc + d)
200    return (char *) -1;
201
202  last_alloc += d;
203
204  return (char *) prev_brk;
205#endif
206}
207EOF
208cat > stat.c <<EOF
209$lu#include <string.h>
210#include <sys/stat.h>
211int
212_stat (const char *path, struct stat *buf)
213{
214  struct new_stat ks;
215  int retval = _Sys_stat (path, &ks);
216
217  /* Blank before filling it in.  */
218  memset (buf, 0, sizeof (*buf));
219
220  /* We have to translate from the linux struct new_stat.
221     It seems we don't have to translate the contents, though.  */
222  buf->st_dev = ks.st_dev;
223  buf->st_ino = ks.st_ino;
224  buf->st_mode = ks.st_mode;
225  buf->st_nlink = ks.st_nlink;
226  buf->st_uid = ks.st_uid;
227  buf->st_gid = ks.st_gid;
228  buf->st_rdev = ks.st_rdev;
229  buf->st_size = ks.st_size;
230  buf->st_blksize = ks.st_blksize;
231  buf->st_blocks = ks.st_blocks;
232  buf->st_atime = ks.st_atime;
233  buf->st_mtime = ks.st_mtime;
234  buf->st_ctime = ks.st_ctime;
235  R (retval)
236EOF
237cat > times.c <<EOF
238$lu#include <sys/times.h>
239clock_t
240_times (struct tms * tp${r}times (tp))
241EOF
242cat > unlink.c <<EOF
243$lui _unlink (const char *f${r}unlink (f))
244EOF
245cat > wait.c <<EOF
246$lui _wait (int *status${r}wait4 (_getpid(), status, 0, 0))
247EOF
248cat > write.c <<EOF
249$lui _write (int fd, char *buf, int nbytes${r}write (fd, buf, nbytes))
250EOF
251exit 0
Note: See TracBrowser for help on using the repository browser.