2016-05-05 09:13:48 -04:00
|
|
|
// An extremely minimalist syscalls.c for newlib
|
2016-05-03 10:53:22 -04:00
|
|
|
// Based on riscv newlib libgloss/riscv/machine/syscall.h
|
2016-05-05 09:13:48 -04:00
|
|
|
// Written by Clifford Wolf.
|
2016-05-03 10:53:22 -04:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2016-05-05 09:13:48 -04:00
|
|
|
#include <errno.h>
|
2016-05-03 10:53:22 -04:00
|
|
|
|
2016-05-05 09:13:48 -04:00
|
|
|
#define UNIMPL_FUNC(_f) ".globl " #_f "\n.type " #_f ", @function\n" #_f ":\n"
|
|
|
|
|
|
|
|
asm (
|
|
|
|
".text\n"
|
|
|
|
".align 2\n"
|
|
|
|
UNIMPL_FUNC(open)
|
|
|
|
UNIMPL_FUNC(openat)
|
|
|
|
UNIMPL_FUNC(lseek)
|
|
|
|
UNIMPL_FUNC(stat)
|
|
|
|
UNIMPL_FUNC(lstat)
|
|
|
|
UNIMPL_FUNC(fstatat)
|
|
|
|
UNIMPL_FUNC(isatty)
|
|
|
|
UNIMPL_FUNC(access)
|
|
|
|
UNIMPL_FUNC(faccessat)
|
|
|
|
UNIMPL_FUNC(link)
|
|
|
|
UNIMPL_FUNC(unlink)
|
|
|
|
UNIMPL_FUNC(execve)
|
|
|
|
UNIMPL_FUNC(getpid)
|
|
|
|
UNIMPL_FUNC(fork)
|
|
|
|
UNIMPL_FUNC(kill)
|
|
|
|
UNIMPL_FUNC(wait)
|
|
|
|
UNIMPL_FUNC(times)
|
|
|
|
UNIMPL_FUNC(gettimeofday)
|
|
|
|
UNIMPL_FUNC(ftime)
|
|
|
|
UNIMPL_FUNC(utime)
|
|
|
|
UNIMPL_FUNC(chown)
|
|
|
|
UNIMPL_FUNC(chmod)
|
|
|
|
UNIMPL_FUNC(chdir)
|
|
|
|
UNIMPL_FUNC(getcwd)
|
|
|
|
UNIMPL_FUNC(sysconf)
|
|
|
|
"j unimplemented_syscall\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
void unimplemented_syscall()
|
|
|
|
{
|
|
|
|
const char *p = "Unimplemented system call called!\n";
|
|
|
|
while (*p)
|
|
|
|
*(volatile int*)0x10000000 = *(p++);
|
2016-06-06 04:46:52 -04:00
|
|
|
asm volatile ("ebreak");
|
2016-05-05 09:13:48 -04:00
|
|
|
__builtin_unreachable();
|
2016-05-03 10:53:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t read(int file, void *ptr, size_t len)
|
|
|
|
{
|
|
|
|
// always EOF
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t write(int file, const void *ptr, size_t len)
|
|
|
|
{
|
|
|
|
const void *eptr = ptr + len;
|
|
|
|
while (ptr != eptr)
|
2016-05-05 09:13:48 -04:00
|
|
|
*(volatile int*)0x10000000 = *(char*)(ptr++);
|
2016-05-03 10:53:22 -04:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
int close(int file)
|
|
|
|
{
|
2016-05-05 09:13:48 -04:00
|
|
|
// close is called before _exit()
|
2016-05-03 10:53:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-05 09:13:48 -04:00
|
|
|
int fstat(int file, struct stat *st)
|
2016-05-03 10:53:22 -04:00
|
|
|
{
|
2016-05-05 09:13:48 -04:00
|
|
|
// fstat is called during libc startup
|
2016-05-03 10:53:22 -04:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *sbrk(ptrdiff_t incr)
|
|
|
|
{
|
|
|
|
extern unsigned char _end[]; // Defined by linker
|
|
|
|
static unsigned long heap_end;
|
|
|
|
|
|
|
|
if (heap_end == 0)
|
|
|
|
heap_end = (long)_end;
|
|
|
|
|
|
|
|
heap_end += incr;
|
|
|
|
return (void *)(heap_end - incr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _exit(int exit_status)
|
|
|
|
{
|
2016-06-06 04:46:52 -04:00
|
|
|
asm volatile ("ebreak");
|
2016-05-03 10:53:22 -04:00
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
2016-05-05 09:13:48 -04:00
|
|
|
|