From a6633677b9152d02164a51ae9ba79cef9230e1d3 Mon Sep 17 00:00:00 2001 From: Jim Wilson Date: Tue, 26 Dec 2017 12:24:45 -0800 Subject: [PATCH] RISC-V: Add nanosleep functionality --- libgloss/riscv/Makefile.in | 1 + libgloss/riscv/nanosleep.c | 12 ++++++++++++ newlib/configure.host | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 libgloss/riscv/nanosleep.c diff --git a/libgloss/riscv/Makefile.in b/libgloss/riscv/Makefile.in index 2f03f4402..de4ea8d83 100644 --- a/libgloss/riscv/Makefile.in +++ b/libgloss/riscv/Makefile.in @@ -7,6 +7,7 @@ gloss_hdrs = \ gloss_srcs = \ syscalls.c \ + nanosleep.c # Extra files diff --git a/libgloss/riscv/nanosleep.c b/libgloss/riscv/nanosleep.c new file mode 100644 index 000000000..1a247109c --- /dev/null +++ b/libgloss/riscv/nanosleep.c @@ -0,0 +1,12 @@ +#include +#include + +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; +} diff --git a/newlib/configure.host b/newlib/configure.host index 3e950d8a5..eb645868b 100644 --- a/newlib/configure.host +++ b/newlib/configure.host @@ -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)