This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/6] RISC-V: Add nanosleep functionality


From c6fc637082264f816f86ed1bd04fa9b5d90e51ee Mon Sep 17 00:00:00 2001
From: Rishi Khan <rishi@extreme-scale.com>
Date: Fri, 27 Oct 2017 18:22:11 +0000
Subject: [PATCH 2/6] 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 2f03f44..de4ea8d 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 0000000..1a24710
--- /dev/null
+++ b/libgloss/riscv/nanosleep.c
@@ -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;
+}
diff --git a/newlib/configure.host b/newlib/configure.host
index 3e950d8..eb64586 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)
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]