public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jim Wilson <wilson@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] RISC-V: Add nanosleep functionality
Date: Tue, 26 Dec 2017 20:26:00 -0000	[thread overview]
Message-ID: <20171226202607.114650.qmail@sourceware.org> (raw)

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)


                 reply	other threads:[~2017-12-26 20:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171226202607.114650.qmail@sourceware.org \
    --to=wilson@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).