OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [sh/] [syscalls.c] - Blame information for rev 438

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#include <_ansi.h>
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
#include <sys/time.h>
5
#include "sys/syscall.h"
6
int errno;
7
 
8
/* This is used by _sbrk.  */
9
register char *stack_ptr asm ("r15");
10
 
11
int
12
_read (int file,
13
       char *ptr,
14
       int len)
15
{
16
  return __trap34 (SYS_read, file, ptr, len);
17
}
18
 
19
int
20
_lseek (int file,
21
        int ptr,
22
        int dir)
23
{
24
  return __trap34 (SYS_lseek, file, ptr, dir);
25
}
26
 
27
int
28
_write ( int file,
29
         char *ptr,
30
         int len)
31
{
32
  return __trap34 (SYS_write, file, ptr, len);
33
}
34
 
35
int
36
_close (int file)
37
{
38
  return __trap34 (SYS_close, file, 0, 0);
39
}
40
 
41
int
42
_link (char *old, char *new)
43
{
44
  return -1;
45
}
46
 
47
caddr_t
48
_sbrk (int incr)
49
{
50
  extern char end;              /* Defined by the linker */
51
  static char *heap_end;
52
  char *prev_heap_end;
53
 
54
  if (heap_end == 0)
55
    {
56
      heap_end = &end;
57
    }
58
  prev_heap_end = heap_end;
59
  if (heap_end + incr > stack_ptr)
60
    {
61
      _write (1, "Heap and stack collision\n", 25);
62
      abort ();
63
    }
64
  heap_end += incr;
65
  return (caddr_t) prev_heap_end;
66
}
67
 
68
int
69
_fstat (int file,
70
        struct stat *st)
71
{
72
  st->st_mode = S_IFCHR;
73
  return 0;
74
}
75
 
76
int
77
_open (const char *path,
78
        int flags)
79
{
80
  return __trap34 (SYS_open, path, flags, 0);
81
}
82
 
83
int
84
_creat (const char *path,
85
        int mode)
86
{
87
  return __trap34 (SYS_creat, path, mode, 0);
88
}
89
 
90
int
91
_unlink ()
92
{
93
  return -1;
94
}
95
 
96
isatty (fd)
97
     int fd;
98
{
99
  return 1;
100
}
101
 
102
_isatty (fd)
103
     int fd;
104
{
105
  return 1;
106
}
107
 
108
 
109
_exit (n)
110
{
111
  return __trap34 (SYS_exit, n, 0, 0);
112
}
113
 
114
_kill (n, m)
115
{
116
  return __trap34 (SYS_exit, 0xdead, 0, 0);
117
}
118
 
119
_getpid (n)
120
{
121
  return 1;
122
}
123
 
124
_raise ()
125
{
126
}
127
 
128
int
129
_stat (const char *path, struct stat *st)
130
 
131
{
132
  return __trap34 (SYS_stat, path, st, 0);
133
}
134
 
135
int
136
_chmod (const char *path, short mode)
137
{
138
  return __trap34 (SYS_chmod, path, mode);
139
}
140
 
141
int
142
_chown (const char *path, short owner, short group)
143
{
144
  return __trap34 (SYS_chown, path, owner, group);
145
}
146
 
147
int
148
_utime (path, times)
149
     const char *path;
150
     char *times;
151
{
152
  return __trap34 (SYS_utime, path, times);
153
}
154
 
155
int
156
_fork ()
157
{
158
  return __trap34 (SYS_fork);
159
}
160
 
161
int
162
_wait (statusp)
163
     int *statusp;
164
{
165
  return __trap34 (SYS_wait);
166
}
167
 
168
int
169
_execve (const char *path, char *const argv[], char *const envp[])
170
{
171
  return __trap34 (SYS_execve, path, argv, envp);
172
}
173
 
174
int
175
_execv (const char *path, char *const argv[])
176
{
177
  return __trap34 (SYS_execv, path, argv);
178
}
179
 
180
int
181
_pipe (int *fd)
182
{
183
  return __trap34 (SYS_pipe, fd);
184
}
185
 
186
/* This is only provided because _gettimeofday_r and _times_r are
187
   defined in the same module, so we avoid a link error.  */
188
clock_t
189
_times (struct tms *tp)
190
{
191
  return -1;
192
}
193
 
194
int
195
_gettimeofday (struct timeval *tv, void *tz)
196
{
197
  tv->tv_usec = 0;
198
  tv->tv_sec = __trap34 (SYS_time);
199
  return 0;
200
}
201
 
202
static inline int
203
__setup_argv_for_main (int argc)
204
{
205
  char **argv;
206
  int i = argc;
207
 
208
  argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
209
 
210
  argv[i] = NULL;
211
  while (i--) {
212
    argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i));
213
    __trap34 (SYS_argn, i, argv[i]);
214
  }
215
 
216
  return main (argc, argv);
217
}
218
 
219
int
220
__setup_argv_and_call_main ()
221
{
222
  int argc = __trap34 (SYS_argc);
223
 
224
  if (argc <= 0)
225
    return main (argc, NULL);
226
  else
227
    return __setup_argv_for_main (argc);
228
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.