1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*
* C library support files for the Blackfin processor
*
* Copyright (C) 2006 Analog Devices, Inc.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <_ansi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
#include "syscall.h"
#include <errno.h>
#include <reent.h>
#include <unistd.h>
register char *stack_ptr asm ("SP");
static inline int
do_syscall (int reason, void *arg)
{
int result, result2, errcode;
asm volatile ("excpt 0;"
: "=q0" (result),
"=q1" (result2),
"=q2" (errcode)
: "qA" (reason),
"q0" (arg)
: "memory", "CC");
errno = errcode;
return result;
}
int
_read (int file, char *ptr, int len)
{
int block[3];
block[0] = file;
block[1] = (int) ptr;
block[2] = len;
return do_syscall (SYS_read, block);
}
int
_lseek (int file, int ptr, int whence)
{
int block[3];
block[0] = file;
block[1] = ptr;
block[2] = whence;
return do_syscall (SYS_lseek, block);
}
int
_write (int file, char *ptr, int len)
{
int block[3];
block[0] = file;
block[1] = (int) ptr;
block[2] = len;
return do_syscall (SYS_write, block);
}
int
_open (const char *path, int flags)
{
int block[2];
block[0] = (int) path;
block[1] = flags;
return do_syscall (SYS_open, block);
}
int
_close (int file)
{
return do_syscall (SYS_close, &file);
}
void
_exit (int n)
{
do_syscall (SYS_exit, &n);
}
int
_kill (int n, int m)
{
int block[2];
block[0] = n;
block[1] = m;
return do_syscall (SYS_kill, block);
}
int
_getpid (int n)
{
return do_syscall (SYS_getpid, &n);
}
caddr_t
_sbrk (int incr)
{
extern char end; /* Defined by the linker. */
static char *heap_end;
char *prev_heap_end;
if (heap_end == NULL)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
/* Some of the libstdc++-v3 tests rely upon detecting
out of memory errors, so do not abort here. */
#if 0
extern void abort (void);
_write (1, "_sbrk: Heap and stack collision\n", 32);
abort ();
#else
errno = ENOMEM;
return (caddr_t) -1;
#endif
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
extern void memset (struct stat *, int, unsigned int);
int
_fstat (int file, struct stat *st)
{
int block[2];
block[0] = file;
block[1] = (int) st;
return do_syscall (SYS_fstat, block);
}
int _stat (const char *fname, struct stat *st)
{
int block[2];
block[0] = (int) fname;
block[1] = (int) st;
return do_syscall (SYS_stat, block);
}
int
_link (const char *existing, const char *new)
{
int block[2];
block[0] = (int) existing;
block[1] = (int) new;
return do_syscall (SYS_link, block);
}
int
_unlink (const char *path)
{
return do_syscall (SYS_unlink, path);
}
void
_raise (void)
{
return;
}
int
_gettimeofday (struct timeval *tv, void *tz)
{
tv->tv_usec = 0;
tv->tv_sec = do_syscall (SYS_time, 0);
return 0;
}
/* Return a clock that ticks at 100Hz. */
clock_t
_times (struct tms * tp)
{
return -1;
}
int
_isatty (int fd)
{
return 1;
}
int
_system (const char *s)
{
if (s == NULL)
return 0;
errno = ENOSYS;
return -1;
}
int
_rename (const char * oldpath, const char * newpath)
{
errno = ENOSYS;
return -1;
}
static inline int
__setup_argv_for_main (int argc)
{
int block[2];
char **argv;
int i = argc;
argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
argv[i] = NULL;
while (i--) {
block[0] = i;
argv[i] = __builtin_alloca (1 + do_syscall (SYS_argnlen, (void *)block));
block[1] = (int) argv[i];
do_syscall (SYS_argn, (void *)block);
}
return main (argc, argv);
}
int
__setup_argv_and_call_main ()
{
int argc = do_syscall (SYS_argc, 0);
if (argc <= 0)
return main (argc, NULL);
else
return __setup_argv_for_main (argc);
}
|