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.
13 void _exit (int n
); /* in trap.S */
15 extern int _write (int fd
, const void *ptr
, size_t len
);
19 register char *stack_ptr
asm ("sp");
24 extern char end
; /* Defined by the linker */
25 static char *heap_end
;
27 char *sp
= (char *)stack_ptr
;
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);
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);
48 return (caddr_t
) prev_heap_end
;
55 st
->st_mode
= S_IFCHR
;
77 /* If this library is compiled with -mint32, provide conversion functions for
78 the system call traps. */
81 extern short _read16 (short fd
, void *ptr
, short len
);
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
);
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
);
97 _lseek (int fd
, off_t offset
, int whence
)
99 return _lseek16 ((short)fd
, offset
, (short)whence
);
102 extern short _close16 (short 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
);
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);
158 extern short _wait16 (short *status
);
165 short ret
= _wait16 (&status16
);
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
[]);
193 short ret
= _pipe16 (fds16
);
203 extern short _getpid16 (void);
210 extern short _kill16 (short pid
, short sig
);
212 _kill (int pid
, int sig
)
214 return _kill16 ((short)pid
, (short)sig
);