source: trunk/libs/newlib/src/libgloss/d30v/syscalls.c @ 444

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

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

File size: 2.8 KB
Line 
1/*
2 * syscalls.c -- provide system call support via trap 31
3 *
4 * Copyright (c) 1997 Cygnus Support
5 *
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
15 *
16 * Read bytes, using simulator trap 31.
17 */
18
19#include <stdlib.h>
20#include <time.h>
21#include "syscall.h"
22
23extern int *__errno(), errno;
24
25__asm__ (
26"       .globl  __syscall                                       \n\
27        .type   __syscall,@function                             \n\
28__syscall:                                                      \n\
29        trap    31              || nop                          \n\
30        cmpge   f0,r2,0         -> jmp/tx       link            \n\
31        bra     __set_errno                                     \n\
32        .size   __syscall,.-__syscall                           \n\
33");
34
35int
36__set_errno (int new_errno)
37{
38  errno = new_errno;
39  *(__errno)() = errno;
40  return -1;
41}
42
43void
44_exit (int status)
45{
46  __syscall (status, 0, 0, 0, SYS_exit);
47}
48
49int
50open (const char *filename, int flags, int mode)
51{
52  return __syscall (filename, flags, mode, 0, SYS_open);
53}
54
55int
56close (int filedes)
57{
58  return __syscall (filedes, 0, 0, 0, SYS_close);
59}
60
61int
62read (int filedes, void *buffer, size_t length)
63{
64  return __syscall (filedes, buffer, length, 0, SYS_read);
65}
66
67int
68write (int filedes, void *buffer, size_t length)
69{
70  return __syscall (filedes, buffer, length, 0, SYS_write);
71}
72
73long
74lseek (int filedes, long offset, int whence)
75{
76  return __syscall (filedes, offset, whence, 0, SYS_lseek);
77}
78
79int
80unlink (const char *filename)
81{
82  return __syscall (filename, 0, 0, 0, SYS_unlink);
83}
84
85int
86getpid (void)
87{
88  return __syscall (0, 0, 0, 0, SYS_getpid);
89}
90
91int
92kill (int signal, int pid)
93{
94  return __syscall (signal, pid, 0, 0, SYS_kill);
95}
96
97int
98fstat (int filedes, void *info)
99{
100  return __syscall (filedes, info, 0, 0, SYS_fstat);
101}
102
103int
104__argvlen (void)
105{
106  return __syscall (0, 0, 0, 0, SYS_argvlen);
107}
108
109int
110__argv (void)
111{
112  return __syscall (0, 0, 0, 0, SYS_argv);
113}
114
115int
116chdir (char *dir)
117{
118  return __syscall (dir, 0, 0, 0, SYS_chdir);
119}
120
121int
122stat (const char *__restrict filename, void *__restrict info)
123{
124  return __syscall (filename, info, 0, 0, SYS_stat);
125}
126
127int
128chmod (const char *filename, int mode)
129{
130  return __syscall (filename, mode, 0, 0, SYS_chmod);
131}
132
133int
134utime (const char *filename, void *packet)
135{
136  return __syscall (filename, packet, 0, 0, SYS_utime);
137}
138
139time_t
140time (time_t *time_ptr)
141{
142  time_t result;       
143  result = (time_t) __syscall (time_ptr, 0, 0, 0, SYS_time);
144  if (time_ptr != NULL)
145    *time_ptr = result;
146  return result;
147}
Note: See TracBrowser for help on using the repository browser.