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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [libgloss/] [bfin/] [syscalls.c] - Blame information for rev 455

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

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * C library support files for the Blackfin processor
3
 *
4
 * Copyright (C) 2006 Analog Devices, Inc.
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
 
17
#include <_ansi.h>
18
#include <sys/types.h>
19
#include <sys/stat.h>
20
#include <sys/fcntl.h>
21
#include <stdio.h>
22
#include <time.h>
23
#include <sys/time.h>
24
#include <sys/times.h>
25
#include "syscall.h"
26
#include <errno.h>
27
#include <reent.h>
28
#include <unistd.h>
29
 
30
register char *stack_ptr asm ("SP");
31
 
32
static inline int
33
do_syscall (int reason, void *arg)
34
{
35
  register int r asm ("P0") = reason;
36
  register void *a asm ("R0") = arg;
37
  register int result asm ("R0");
38
  asm volatile ("excpt 0;" : "=r" (result) : "a" (r), "r" (a) : "memory", "CC");
39
  return result;
40
}
41
 
42
int
43
_read (int file, char *ptr, int len)
44
{
45
  int block[3];
46
 
47
  block[0] = file;
48
  block[1] = (int) ptr;
49
  block[2] = len;
50
 
51
  return do_syscall (SYS_read, block);
52
}
53
 
54
int
55
_lseek (int file, int ptr, int dir)
56
{
57
  int block[2];
58
 
59
  block[0] = file;
60
  block[1] = ptr;
61
 
62
  return do_syscall (SYS_lseek, block);
63
}
64
 
65
int
66
_write (int file, char *ptr, int len)
67
{
68
  int block[3];
69
 
70
  block[0] = file;
71
  block[1] = (int) ptr;
72
  block[2] = len;
73
 
74
  return do_syscall (SYS_write, block);
75
}
76
 
77
int
78
_open (const char *path, int flags)
79
{
80
  int block[2];
81
 
82
  block[0] = (int) path;
83
  block[1] = flags;
84
 
85
  return do_syscall (SYS_open, block);
86
}
87
 
88
int
89
_close (int file)
90
{
91
  return do_syscall (SYS_close, &file);
92
}
93
 
94
void
95
_exit (int n)
96
{
97
  do_syscall (SYS_exit, &n);
98
}
99
 
100
int
101
_kill (int n, int m)
102
{
103
  int block[2];
104
 
105
  block[0] = n;
106
  block[1] = m;
107
 
108
  return do_syscall (SYS_kill, block);
109
}
110
 
111
int
112
_getpid (int n)
113
{
114
  return 1;
115
}
116
 
117
caddr_t
118
_sbrk (int incr)
119
{
120
  extern char end;              /* Defined by the linker.  */
121
  static char *heap_end;
122
  char *prev_heap_end;
123
 
124
  if (heap_end == NULL)
125
    heap_end = &end;
126
 
127
  prev_heap_end = heap_end;
128
 
129
  if (heap_end + incr > stack_ptr)
130
    {
131
      /* Some of the libstdc++-v3 tests rely upon detecting
132
         out of memory errors, so do not abort here.  */
133
#if 0
134
      extern void abort (void);
135
 
136
      _write (1, "_sbrk: Heap and stack collision\n", 32);
137
 
138
      abort ();
139
#else
140
      errno = ENOMEM;
141
      return (caddr_t) -1;
142
#endif
143
    }
144
 
145
  heap_end += incr;
146
 
147
  return (caddr_t) prev_heap_end;
148
}
149
 
150
extern void memset (struct stat *, int, unsigned int);
151
 
152
int
153
_fstat (int file, struct stat * st)
154
{
155
  memset (st, 0, sizeof (* st));
156
  st->st_mode = S_IFCHR;
157
  st->st_blksize = 1024;
158
  return 0;
159
}
160
 
161
int _stat (const char *fname, struct stat *st)
162
{
163
  int file;
164
 
165
  /* The best we can do is try to open the file readonly.  If it exists,
166
     then we can guess a few things about it.  */
167
  if ((file = _open (fname, O_RDONLY)) < 0)
168
    return -1;
169
 
170
  memset (st, 0, sizeof (* st));
171
  st->st_mode = S_IFREG | S_IREAD;
172
  st->st_blksize = 1024;
173
  _close (file); /* Not interested in the error.  */
174
  return 0;
175
}
176
 
177
int
178
_link (void)
179
{
180
  return -1;
181
}
182
 
183
int
184
_unlink (void)
185
{
186
  return -1;
187
}
188
 
189
void
190
_raise (void)
191
{
192
  return;
193
}
194
 
195
int
196
_gettimeofday (struct timeval *tv, void *tz)
197
{
198
  tv->tv_usec = 0;
199
  tv->tv_sec = do_syscall (SYS_time, 0);
200
  return 0;
201
}
202
 
203
/* Return a clock that ticks at 100Hz.  */
204
clock_t
205
_times (struct tms * tp)
206
{
207
  return -1;
208
}
209
 
210
int
211
_isatty (int fd)
212
{
213
  return 1;
214
}
215
 
216
int
217
_system (const char *s)
218
{
219
  if (s == NULL)
220
    return 0;
221
  errno = ENOSYS;
222
  return -1;
223
}
224
 
225
int
226
_rename (const char * oldpath, const char * newpath)
227
{
228
  errno = ENOSYS;
229
  return -1;
230
}
231
 
232
static inline int
233
__setup_argv_for_main (int argc)
234
{
235
  int block[2];
236
  char **argv;
237
  int i = argc;
238
 
239
  argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
240
 
241
  argv[i] = NULL;
242
  while (i--) {
243
    block[0] = i;
244
    argv[i] = __builtin_alloca (1 + do_syscall (SYS_argnlen, (void *)block));
245
    block[1] = (int) argv[i];
246
    do_syscall (SYS_argn, (void *)block);
247
  }
248
 
249
  return main (argc, argv);
250
}
251
 
252
int
253
__setup_argv_and_call_main ()
254
{
255
  int argc = do_syscall (SYS_argc, 0);
256
 
257
  if (argc <= 0)
258
    return main (argc, NULL);
259
  else
260
    return __setup_argv_for_main (argc);
261
}

powered by: WebSVN 2.1.0

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