2006-11-09 03:36:56 +08:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2011-06-22 12:18:45 +08:00
|
|
|
int result, result2, errcode;
|
|
|
|
asm volatile ("excpt 0;"
|
|
|
|
: "=q0" (result),
|
|
|
|
"=q1" (result2),
|
|
|
|
"=q2" (errcode)
|
|
|
|
: "qA" (reason),
|
|
|
|
"q0" (arg)
|
|
|
|
: "memory", "CC");
|
|
|
|
errno = errcode;
|
2006-11-09 03:36:56 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_read (int file, char *ptr, int len)
|
|
|
|
{
|
|
|
|
int block[3];
|
|
|
|
|
|
|
|
block[0] = file;
|
|
|
|
block[1] = (int) ptr;
|
|
|
|
block[2] = len;
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
return do_syscall (SYS_read, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-02 04:55:42 +08:00
|
|
|
_lseek (int file, int ptr, int whence)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
2011-07-02 04:55:42 +08:00
|
|
|
int block[3];
|
2006-11-09 03:36:56 +08:00
|
|
|
|
|
|
|
block[0] = file;
|
|
|
|
block[1] = ptr;
|
2011-07-02 04:55:42 +08:00
|
|
|
block[2] = whence;
|
2006-11-09 03:36:56 +08:00
|
|
|
|
|
|
|
return do_syscall (SYS_lseek, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_write (int file, char *ptr, int len)
|
|
|
|
{
|
|
|
|
int block[3];
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
block[0] = file;
|
|
|
|
block[1] = (int) ptr;
|
|
|
|
block[2] = len;
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
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)
|
|
|
|
{
|
2011-07-02 05:47:36 +08:00
|
|
|
return do_syscall (SYS_getpid, &n);
|
2006-11-09 03:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
prev_heap_end = heap_end;
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
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);
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
abort ();
|
|
|
|
#else
|
|
|
|
errno = ENOMEM;
|
|
|
|
return (caddr_t) -1;
|
|
|
|
#endif
|
|
|
|
}
|
2011-06-22 11:00:44 +08:00
|
|
|
|
2006-11-09 03:36:56 +08:00
|
|
|
heap_end += incr;
|
|
|
|
|
|
|
|
return (caddr_t) prev_heap_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void memset (struct stat *, int, unsigned int);
|
|
|
|
|
|
|
|
int
|
2011-07-02 05:47:36 +08:00
|
|
|
_fstat (int file, struct stat *st)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
2011-07-02 05:47:36 +08:00
|
|
|
int block[2];
|
|
|
|
|
|
|
|
block[0] = file;
|
|
|
|
block[1] = (int) st;
|
|
|
|
|
|
|
|
return do_syscall (SYS_fstat, block);
|
2006-11-09 03:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int _stat (const char *fname, struct stat *st)
|
|
|
|
{
|
2011-07-02 05:47:36 +08:00
|
|
|
int block[2];
|
|
|
|
|
|
|
|
block[0] = (int) fname;
|
|
|
|
block[1] = (int) st;
|
|
|
|
|
|
|
|
return do_syscall (SYS_stat, block);
|
2006-11-09 03:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-02 05:47:36 +08:00
|
|
|
_link (const char *existing, const char *new)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
2011-07-02 05:47:36 +08:00
|
|
|
int block[2];
|
|
|
|
|
|
|
|
block[0] = (int) existing;
|
|
|
|
block[1] = (int) new;
|
|
|
|
|
|
|
|
return do_syscall (SYS_link, block);
|
2006-11-09 03:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-02 05:47:36 +08:00
|
|
|
_unlink (const char *path)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
2011-07-02 05:47:36 +08:00
|
|
|
return do_syscall (SYS_unlink, path);
|
2006-11-09 03:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_raise (void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-07-07 01:00:13 +08:00
|
|
|
_gettimeofday (struct timeval *tv, void *tz)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
|
|
|
tv->tv_usec = 0;
|
|
|
|
tv->tv_sec = do_syscall (SYS_time, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a clock that ticks at 100Hz. */
|
2011-06-22 11:00:44 +08:00
|
|
|
clock_t
|
2006-11-09 03:36:56 +08:00
|
|
|
_times (struct tms * tp)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-01-04 06:38:31 +08:00
|
|
|
_isatty (int fd)
|
2006-11-09 03:36:56 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|