newlib/libgloss/bfin/syscalls.c
Jeff Johnston 84132c9d9f 2008-08-14 Jie Zhang <jie.zhang@analog.com>
* bfin/Makefile.in: (top_srcdir): Define.
        (mkinstalldirs): Define.
        (BOARD_SCRIPTS): Define.
        (BOARD_LDFLAGS): Define.
        (BOARD_BSP): Define.
        (BOARD_CRT0S): Define.
        (BOARD_OBJS): Define.
        (BOARD_TEST): Define.
        (BOARD_INSTALL): Define.
        (INCLUDES): Add -I$(srcdir)/include.
        (all): Add ${BOARD_CRT0S} and ${BOARD_BSP}.
        (.c.S): Remove target.
        (crt0.o): New target.
        (basiccrt.o): Likewise.
        (basiccrtb.o): Likewise.
        (basiccrts.o): Likewise.
        (basiccrt561.o, basiccrt561s.o, basiccrt561b.o): Likewise
        (clean mostlyclean): Remove ${BOARD_BSP}.
        (install): Depend on ${BOARD_INSTALL}.
        (install-sim): Reformat.
        (install-board): New target.
        * bfin/basiccrt.S: Remove useless __ADSPBF561_COREB__ in
        workaround code for 05000229.
        * bfin/syscalls.c (do_syscall): Use `EXCPT 0' instead of
        `RAISE 0' for syscall.
        * bfin/basiccrt.S: New file.
        * bfin/bf5*ld: New file.
        * bfin/bfin-common-mc.ld: New file.
        * bfin/bfin-common-sc.ld: New file.
        * bfin/include/blackfin.h: New file.
        * bfin/include/cdefBF5*.h: New file.
        * bfin/include/cdef_LPBlackfin.h: New file.
        * bfin/include/cdefblackfin.h: New file.
        * bfin/include/cplb.h: New file.
        * bfin/include/cplbtab.h: New file.
        * bfin/include/defBF5*.h: New files.
        * bfin/include/def_LPBlackfin.h: New files.
        * bfin/include/defblackfin.h: New file.
        * bfin/include/sys/_adi_platform.h: New file.
        * bfin/include/sys/anomaly_macros_rtl.h: New file.
        * bfin/include/sys/excause.h: New file.
        * bfin/include/sys/exception.h: New file.
        * bfin/include/sys/mc_typedef.h: New file.
        * bfin/include/sys/platform.h: New file.
        * bfin/include/sys/pll.h: New file.
        * bfin/include/sysreg.h: New file.
        * libnosys/configure.in (MISSING_SYSCALL_NAMES): Don't define
        for bfin.
        * libnosys/configure: Regenerate.
2008-08-14 22:00:47 +00:00

262 lines
4.4 KiB
C

/*
* 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)
{
register int r asm ("P0") = reason;
register void *a asm ("R0") = arg;
register int result asm ("R0");
asm volatile ("excpt 0;" : "=r" (result) : "a" (r), "r" (a) : "memory", "CC");
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 dir)
{
int block[2];
block[0] = file;
block[1] = ptr;
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 1;
}
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)
{
memset (st, 0, sizeof (* st));
st->st_mode = S_IFCHR;
st->st_blksize = 1024;
return 0;
}
int _stat (const char *fname, struct stat *st)
{
int file;
/* The best we can do is try to open the file readonly. If it exists,
then we can guess a few things about it. */
if ((file = _open (fname, O_RDONLY)) < 0)
return -1;
memset (st, 0, sizeof (* st));
st->st_mode = S_IFREG | S_IREAD;
st->st_blksize = 1024;
_close (file); /* Not interested in the error. */
return 0;
}
int
_link (void)
{
return -1;
}
int
_unlink (void)
{
return -1;
}
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);
}