aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@eecs.berkeley.edu>2012-01-31 17:31:33 -0800
committerAndrew Waterman <waterman@eecs.berkeley.edu>2012-01-31 17:31:33 -0800
commit23688da201a3b668deaa3e7cc184060b678f2058 (patch)
tree935f8f3cf359fb023982a645e2880f4cbb3b15e3
parentace6db857d06e01e06677a4c1df6596dfe793677 (diff)
downloadspike-23688da201a3b668deaa3e7cc184060b678f2058.zip
spike-23688da201a3b668deaa3e7cc184060b678f2058.tar.gz
spike-23688da201a3b668deaa3e7cc184060b678f2058.tar.bz2
poll HTIF occasionally
-rw-r--r--riscv/htif.cc12
-rw-r--r--riscv/htif.h3
-rw-r--r--riscv/riscv-isa-run.cc1
-rw-r--r--riscv/sim.cc13
4 files changed, 25 insertions, 4 deletions
diff --git a/riscv/htif.cc b/riscv/htif.cc
index ab27f01..7de27c6 100644
--- a/riscv/htif.cc
+++ b/riscv/htif.cc
@@ -7,6 +7,7 @@
#include <errno.h>
#include <assert.h>
#include <stddef.h>
+#include <poll.h>
enum
{
@@ -79,6 +80,17 @@ void htif_t::nack(uint16_t nack_seqno)
send_packet(&p);
}
+void htif_t::poll()
+{
+ struct pollfd pfd;
+ pfd.fd = fromhost_fd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+
+ if (::poll(&pfd, 1, 0) > 0)
+ wait_for_packet();
+}
+
int htif_t::wait_for_packet()
{
while(1)
diff --git a/riscv/htif.h b/riscv/htif.h
index d7a8c89..805cc4f 100644
--- a/riscv/htif.h
+++ b/riscv/htif.h
@@ -22,6 +22,9 @@ public:
void wait_for_tohost_write();
void wait_for_fromhost_write();
+ // check to see if there's a pending packet and process it if so
+ void poll();
+
private:
sim_t* sim;
int tohost_fd;
diff --git a/riscv/riscv-isa-run.cc b/riscv/riscv-isa-run.cc
index f73cc55..9217be8 100644
--- a/riscv/riscv-isa-run.cc
+++ b/riscv/riscv-isa-run.cc
@@ -54,4 +54,5 @@ int main(int argc, char** argv)
// initalize simulator and run to completion
sim_t s(nprocs, &htif);
s.run(debug);
+ printf("graceful\n");
}
diff --git a/riscv/sim.cc b/riscv/sim.cc
index f1c1b3b..d61e600 100644
--- a/riscv/sim.cc
+++ b/riscv/sim.cc
@@ -87,10 +87,15 @@ void sim_t::run(bool debug)
for(running = true; running; )
{
- if(!debug)
- step_all(100,100,false);
- else
- interactive();
+ for (int i = 0; i < 1000; i++)
+ {
+ if(!debug)
+ step_all(100,100,false);
+ else
+ interactive();
+ }
+
+ htif->poll();
}
}