2016-05-05 09:13:48 -04:00
|
|
|
// An extremely minimalist syscalls.c for newlib
|
2018-04-03 14:14:17 -04:00
|
|
|
// Based on riscv newlib libgloss/riscv/sys_*.c
|
2016-05-05 09:13:48 -04:00
|
|
|
// Written by Clifford Wolf.
|
2015-11-03 19:12:37 -05:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2016-05-05 09:13:48 -04:00
|
|
|
#include <errno.h>
|
2015-11-03 19:12:37 -05: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"
|
2018-04-03 14:14:17 -04:00
|
|
|
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)
|
2016-05-05 09:13:48 -04:00
|
|
|
"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();
|
2015-11-03 19:12:37 -05:00
|
|
|
}
|
|
|
|
|
2018-04-03 14:14:17 -04:00
|
|
|
ssize_t _read(int file, void *ptr, size_t len)
|
2015-11-03 19:12:37 -05:00
|
|
|
{
|
|
|
|
// always EOF
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-03 14:14:17 -04:00
|
|
|
ssize_t _write(int file, const void *ptr, size_t len)
|
2015-11-03 19:12:37 -05:00
|
|
|
{
|
|
|
|
const void *eptr = ptr + len;
|
|
|
|
while (ptr != eptr)
|
2016-05-05 09:13:48 -04:00
|
|
|
*(volatile int*)0x10000000 = *(char*)(ptr++);
|
2015-11-03 19:12:37 -05:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2018-04-03 14:14:17 -04:00
|
|
|
int _close(int file)
|
2015-11-03 19:12:37 -05:00
|
|
|
{
|
2016-05-05 09:13:48 -04:00
|
|
|
// close is called before _exit()
|
2015-11-03 19:12:37 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-03 14:14:17 -04:00
|
|
|
int _fstat(int file, struct stat *st)
|
2015-11-03 19:12:37 -05:00
|
|
|
{
|
2016-05-05 09:13:48 -04:00
|
|
|
// fstat is called during libc startup
|
2015-11-03 19:12:37 -05:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-03 14:14:17 -04:00
|
|
|
void *_sbrk(ptrdiff_t incr)
|
2015-11-03 19:12:37 -05:00
|
|
|
{
|
2020-04-23 11:58:32 -04:00
|
|
|
extern unsigned char _end[]; // Defined by linker
|
2015-11-03 19:12:37 -05:00
|
|
|
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");
|
2015-11-03 19:12:37 -05:00
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
2016-05-05 09:13:48 -04:00
|
|
|
|