RISC-V: Add nanosleep functionality

This commit is contained in:
Jim Wilson 2017-12-26 12:24:45 -08:00
parent e807c51d78
commit a6633677b9
3 changed files with 14 additions and 1 deletions

View File

@ -7,6 +7,7 @@ gloss_hdrs = \
gloss_srcs = \
syscalls.c \
nanosleep.c
# Extra files

View File

@ -0,0 +1,12 @@
#include <machine/syscall.h>
#include <sys/time.h>
int
nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
unsigned long current_time, end_time;
asm ("rdtime %0" : "+r" (current_time));
end_time = current_time + rqtp->tv_sec * 1000000000ULL + rqtp->tv_nsec;
while (current_time <= end_time) asm ("rdtime %0" : "+r" (current_time));
return 0;
}

View File

@ -258,7 +258,7 @@ case "${host_cpu}" in
riscv*)
libm_machine_dir=riscv
machine_dir=riscv
newlib_cflags="${newlib_cflags}"
newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP"
default_newlib_atexit_dynamic_alloc="no"
;;
rl78)