public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] RISC-V: Add nanosleep functionality
@ 2017-12-26 20:26 Jim Wilson
  0 siblings, 0 replies; only message in thread
From: Jim Wilson @ 2017-12-26 20:26 UTC (permalink / raw)
  To: newlib-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a6633677b9152d02164a51ae9ba79cef9230e1d3

commit a6633677b9152d02164a51ae9ba79cef9230e1d3
Author: Jim Wilson <jimw@sifive.com>
Date:   Tue Dec 26 12:24:45 2017 -0800

    RISC-V: Add nanosleep functionality

Diff:
---
 libgloss/riscv/Makefile.in |  1 +
 libgloss/riscv/nanosleep.c | 12 ++++++++++++
 newlib/configure.host      |  2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-12-26 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-26 20:26 [newlib-cygwin] RISC-V: Add nanosleep functionality Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).