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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [sh/] [syscalls.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
#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
_exit (n)
103
{
104
  return __trap34 (SYS_exit, n, 0, 0);
105
}
106
 
107
_kill (n, m)
108
{
109
  return __trap34 (SYS_exit, 0xdead, 0, 0);
110
}
111
 
112
_getpid (n)
113
{
114
  return 1;
115
}
116
 
117
_raise ()
118
{
119
}
120
 
121
int
122
_stat (const char *path, struct stat *st)
123
 
124
{
125
  return __trap34 (SYS_stat, path, st, 0);
126
}
127
 
128
int
129
_chmod (const char *path, short mode)
130
{
131
  return __trap34 (SYS_chmod, path, mode);
132
}
133
 
134
int
135
_chown (const char *path, short owner, short group)
136
{
137
  return __trap34 (SYS_chown, path, owner, group);
138
}
139
 
140
int
141
_utime (path, times)
142
     const char *path;
143
     char *times;
144
{
145
  return __trap34 (SYS_utime, path, times);
146
}
147
 
148
int
149
_fork ()
150
{
151
  return __trap34 (SYS_fork);
152
}
153
 
154
int
155
_wait (statusp)
156
     int *statusp;
157
{
158
  return __trap34 (SYS_wait);
159
}
160
 
161
int
162
_execve (const char *path, char *const argv[], char *const envp[])
163
{
164
  return __trap34 (SYS_execve, path, argv, envp);
165
}
166
 
167
int
168
_execv (const char *path, char *const argv[])
169
{
170
  return __trap34 (SYS_execv, path, argv);
171
}
172
 
173
int
174
_pipe (int *fd)
175
{
176
  return __trap34 (SYS_pipe, fd);
177
}
178
 
179
/* This is only provided because _gettimeofday_r and _times_r are
180
   defined in the same module, so we avoid a link error.  */
181
clock_t
182
_times (struct tms *tp)
183
{
184
  return -1;
185
}
186
 
187
int
188
_gettimeofday (struct timeval *tv, struct timezone *tz)
189
{
190
  tv->tv_usec = 0;
191
  tv->tv_sec = __trap34 (SYS_time);
192
  return 0;
193
}
194
 
195
static inline int
196
__setup_argv_for_main (int argc)
197
{
198
  char **argv;
199
  int i = argc;
200
 
201
  argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
202
 
203
  argv[i] = NULL;
204
  while (i--) {
205
    argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i));
206
    __trap34 (SYS_argn, i, argv[i]);
207
  }
208
 
209
  return main (argc, argv);
210
}
211
 
212
int
213
__setup_argv_and_call_main ()
214
{
215
  int argc = __trap34 (SYS_argc);
216
 
217
  if (argc <= 0)
218
    return main (argc, NULL);
219
  else
220
    return __setup_argv_for_main (argc);
221
}

powered by: WebSVN 2.1.0

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