fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / sys / d10v / syscalls.c
blob11192074a75a72b32aad0b78fa6e2bac30d46c04
1 /* syscalls.c - non-trap system calls for D10V
3 * This file contains system calls that cannot be implemented with
4 * a simple "trap 15" instruction. The ones that can are in trap.S.
5 */
7 #include <_ansi.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <errno.h>
11 #undef errno
13 void _exit (int n); /* in trap.S */
15 extern int _write (int fd, const void *ptr, size_t len);
17 int errno;
19 register char *stack_ptr asm ("sp");
21 caddr_t
22 _sbrk (int incr)
24 extern char end; /* Defined by the linker */
25 static char *heap_end;
26 char *prev_heap_end;
27 char *sp = (char *)stack_ptr;
29 if (heap_end == 0)
31 heap_end = (char *)((((unsigned short) &end) + 7) & ~7);
33 prev_heap_end = heap_end;
34 if (heap_end + incr > sp)
36 _write (2, "Heap and stack collision\n", sizeof ("Heap and stack collision\n")-1);
37 abort ();
39 heap_end += incr;
40 if ((unsigned short)heap_end > 0xbfff
41 || (heap_end < prev_heap_end && incr > 0)
42 || (heap_end < (char *)((((unsigned short) &end) + 7) & ~7)))
44 _write (2, "Too much memory was allocated\n", sizeof ("Too much memory was allocated\n")-1);
45 abort ();
48 return (caddr_t) prev_heap_end;
51 int
52 _fstat (int file,
53 struct stat *st)
55 st->st_mode = S_IFCHR;
56 return 0;
59 int
60 _unlink ()
62 errno = ENOSYS;
63 return -1;
66 int
67 isatty (int fd)
69 return 1;
72 void
73 _raise ()
77 /* If this library is compiled with -mint32, provide conversion functions for
78 the system call traps. */
80 #if __INT__==32
81 extern short _read16 (short fd, void *ptr, short len);
82 int
83 _read (int fd, void *ptr, size_t len)
85 return _read16 ((short)fd, ptr, (short)len);
88 extern short _write16 (short fd, const void *ptr, short len);
89 int
90 _write (int fd, const void *ptr, size_t len)
92 return _write16 ((short)fd, ptr, (short)len);
95 extern short _lseek16 (short fd, long offset, short whence);
96 int
97 _lseek (int fd, off_t offset, int whence)
99 return _lseek16 ((short)fd, offset, (short)whence);
102 extern short _close16 (short fd);
104 _close (int fd)
106 return _close16 ((short)fd);
109 extern short _open16 (const char *name, short flags, short mode);
111 _open (const char *name, int flags, mode_t mode)
113 return _open16 (name, (short)flags, (short)mode);
116 extern short _creat16 (const char *name, mode_t mode);
118 _creat (const char *name, mode_t mode)
120 return _creat16 (name, mode);
123 extern void _exit16 (short status);
124 void
125 _exit (int status)
127 _exit16 ((short)status);
130 extern short _stat16 (const char *name, struct stat *stat_pkt);
132 _stat (const char *name, struct stat *stat_pkt)
134 return _stat16 (name, stat_pkt);
137 extern short _chmod16 (const char *name, short mode);
139 _chmod (const char *name, mode_t mode)
141 return _chmod16 (name, (short)mode);
144 extern short _chown16 (const char *name, short uid, short gid);
146 _chown (const char *name, uid_t uid, gid_t gid)
148 return _chown16 (name, (short)uid, (short)gid);
151 extern short _fork16 (void);
153 _fork (void)
155 return _fork16 ();
158 extern short _wait16 (short *status);
160 _wait (int *status)
162 if (status)
164 short status16;
165 short ret = _wait16 (&status16);
166 if (ret >= 0)
167 *status = status16;
168 return ret;
170 else
171 return _wait16 ((short *)0);
174 extern short _execve16 (const char *filename, const char *argv [], const char *envp[]);
176 _execve (const char *filename, const char *argv [], const char *envp[])
178 return _execve16 (filename, argv, envp);
181 extern short _execv16 (const char *filename, const char *argv []);
183 _execv (const char *filename, const char *argv [])
185 return _execv16 (filename, argv);
188 extern short _pipe16 (short fds[]);
190 _pipe (int fds[])
192 short fds16[2];
193 short ret = _pipe16 (fds16);
194 if (ret >= 0)
196 fds[0] = fds16[0];
197 fds[1] = fds16[1];
200 return ret;
203 extern short _getpid16 (void);
205 _getpid (void)
207 return _getpid16 ();
210 extern short _kill16 (short pid, short sig);
212 _kill (int pid, int sig)
214 return _kill16 ((short)pid, (short)sig);
216 #endif