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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [sys/] [z8ksim/] [glue.c] - Diff between revs 39 and 40

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 39 Rev 40
#include "sys/syscall.h"
#include "sys/syscall.h"
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <_ansi.h>
#include <_ansi.h>
#include <errno.h>
#include <errno.h>
 
 
extern char _start_heap;
extern char _start_heap;
extern char _end_heap;
extern char _end_heap;
extern char _start_bss;
extern char _start_bss;
extern char _end_bss;
extern char _end_bss;
 
 
 
 
static int argl(long value)
static int argl(long value)
{
{
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
  asm("sc %0" : : "i" (SYS_ARG));
  asm("sc %0" : : "i" (SYS_ARG));
}
}
 
 
 
 
static int argw(value)
static int argw(value)
{
{
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld  r0,#0");
  asm("ld  r0,#0");
  asm("sc %0" : : "i" (SYS_ARG));
  asm("sc %0" : : "i" (SYS_ARG));
}
}
 
 
static int argp(void *value)
static int argp(void *value)
{
{
#ifdef __Z8001__  
#ifdef __Z8001__  
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
#else
#else
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld  r0,#0");
  asm("ld  r0,#0");
#endif
#endif
  asm("sc %0" : : "i" (SYS_ARG));
  asm("sc %0" : : "i" (SYS_ARG));
 
 
}
}
 
 
 
 
 
 
#define ARGL(n, value)  argl(value)
#define ARGL(n, value)  argl(value)
#define ARGW(n, value)  argw(value)
#define ARGW(n, value)  argw(value)
#define ARGP(n, value) argp(value)
#define ARGP(n, value) argp(value)
 
 
#define MACRO(n) asm("sc %0" : : "i" (n));
#define MACRO(n) asm("sc %0" : : "i" (n));
 
 
int _read (int fd, char *buf,size_t nbytes)
int _read (int fd, char *buf,size_t nbytes)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  ARGP(1,buf);
  ARGP(1,buf);
  ARGP(2,(void *)(nbytes));
  ARGP(2,(void *)(nbytes));
  MACRO(SYS_read);
  MACRO(SYS_read);
}
}
 
 
int _write (int fd, char *buf, size_t nbytes)
int _write (int fd, char *buf, size_t nbytes)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  ARGP(1,buf);
  ARGP(1,buf);
  ARGP(2,(void *)(nbytes));
  ARGP(2,(void *)(nbytes));
  MACRO(SYS_write);
  MACRO(SYS_write);
}
}
 
 
int _open (const char *buf, int flags, int mode)
int _open (const char *buf, int flags, int mode)
{
{
  ARGP(0, buf);
  ARGP(0, buf);
  ARGW(1, flags);
  ARGW(1, flags);
  ARGW(2, mode);
  ARGW(2, mode);
  MACRO(SYS_open);
  MACRO(SYS_open);
}
}
 
 
int _close (int fd)
int _close (int fd)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  MACRO(SYS_close );
  MACRO(SYS_close );
}
}
 
 
/*
/*
 * sbrk -- changes heap size size. Get nbytes more
 * sbrk -- changes heap size size. Get nbytes more
 *         RAM. We just increment a pointer in what's
 *         RAM. We just increment a pointer in what's
 *         left of memory on the board.
 *         left of memory on the board.
 */
 */
caddr_t _sbrk (size_t nbytes)
caddr_t _sbrk (size_t nbytes)
{
{
  static char* heap_ptr = NULL;
  static char* heap_ptr = NULL;
  caddr_t        base;
  caddr_t        base;
 
 
  if (heap_ptr == NULL) {
  if (heap_ptr == NULL) {
    heap_ptr = (caddr_t)&_start_heap;
    heap_ptr = (caddr_t)&_start_heap;
  }
  }
 
 
  if (heap_ptr + nbytes < &_end_heap) {
  if (heap_ptr + nbytes < &_end_heap) {
    base = heap_ptr;
    base = heap_ptr;
    heap_ptr += nbytes;
    heap_ptr += nbytes;
    return (heap_ptr);
    return (heap_ptr);
  } else {
  } else {
    errno = ENOMEM;
    errno = ENOMEM;
    return ((caddr_t)-1);
    return ((caddr_t)-1);
  }
  }
}
}
 
 
int isatty (int fd)
int isatty (int fd)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  MACRO(SYS_isatty);
  MACRO(SYS_isatty);
}
}
 
 
off_t _lseek (int fd,  off_t offset, int whence)
off_t _lseek (int fd,  off_t offset, int whence)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  ARGL(1,offset);
  ARGL(1,offset);
  ARGW(2, whence);
  ARGW(2, whence);
  MACRO(SYS_lseek);
  MACRO(SYS_lseek);
}
}
 
 
int _fstat (int fd, struct stat *buf)
int _fstat (int fd, struct stat *buf)
{
{
  ARGW(0,fd);
  ARGW(0,fd);
  ARGP(1,buf);
  ARGP(1,buf);
  MACRO(SYS_fstat);
  MACRO(SYS_fstat);
}
}
 
 
 
 
 
 
 
 
int
int
_exit(int val)
_exit(int val)
{
{
  ARGW(0,val);
  ARGW(0,val);
  MACRO(SYS_exit);
  MACRO(SYS_exit);
}
}
 
 
time_t _time(time_t *timer)
time_t _time(time_t *timer)
{
{
  ARGP(0,timer);
  ARGP(0,timer);
  MACRO(SYS_time);
  MACRO(SYS_time);
}
}
 
 
int
int
_creat (const char *path, int mode)
_creat (const char *path, int mode)
{
{
  ARGP(0, path);
  ARGP(0, path);
  ARGW(1, mode);
  ARGW(1, mode);
  MACRO(SYS_creat);
  MACRO(SYS_creat);
}
}
 
 
_kill(int pid, int val)
_kill(int pid, int val)
{
{
  _exit(val);
  _exit(val);
}
}
 
 
_getpid()
_getpid()
{
{
  return 1;
  return 1;
}
}
 
 

powered by: WebSVN 2.1.0

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