From 6d47d18c2b5dee9a80ae117937222328140f7966 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Tue, 20 Nov 2012 05:40:44 -0800 Subject: [PATCH] catch sigterm to gracefully exit (fixes vcd) --- csrc/emulator.cc | 13 +++++++++++-- emulator/Makefile | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/csrc/emulator.cc b/csrc/emulator.cc index 0ea79a42..40a32d4e 100644 --- a/csrc/emulator.cc +++ b/csrc/emulator.cc @@ -1,5 +1,6 @@ #include "htif_phy.h" #include +#include #include #include #include @@ -10,6 +11,12 @@ #include "Top.h" // chisel-generated code... #include "disasm.h" +static bool exit_now = false; +void handle_sigterm(int signum) +{ + exit_now = true; +} + int main(int argc, char** argv) { int fromhost_fd = -1, tohost_fd = -1; @@ -25,6 +32,8 @@ int main(int argc, char** argv) const char* failure = NULL; disassembler disasm; + signal(SIGTERM, handle_sigterm); + for (int i = 1; i < argc; i++) { std::string arg = argv[i]; @@ -90,7 +99,7 @@ int main(int argc, char** argv) htif_phy_t htif_phy(tile.Top__io_host_in_bits.width(), fromhost_fd, tohost_fd); - while (max_cycles == 0 || trace_count < max_cycles) + while (!exit_now) { // fprintf(stderr, "trace count: %ld\n", trace_count); // memory model @@ -169,7 +178,7 @@ int main(int argc, char** argv) tile.clock_hi(LIT<1>(0)); trace_count++; - if (trace_count == max_cycles) + if (max_cycles != 0 && trace_count == max_cycles) { failure = "timeout"; break; diff --git a/emulator/Makefile b/emulator/Makefile index 5ff1e59a..90c21f8b 100644 --- a/emulator/Makefile +++ b/emulator/Makefile @@ -79,7 +79,7 @@ output/%.out: output/%.hex emulator fesvr -c -testrun -m3000000 -l +loadmem=$< none 2> $@ output/%.vpd: output/%.hex emulator-debug - fesvr -c./emulator-debug -testrun -m3000000 -l -v- +loadmem=$< none 2> $(patsubst %.vpd,%.out,$@) | vcd2vpd - $@ > /dev/null + fesvr -c./emulator-debug -testrun -m3000000 -l -v- +loadmem=$< none 2> $(patsubst %.vpd,%.out,$@) | vcd2vpd - $@ > /dev/null && [ $$PIPESTATUS -eq 0 ] run-asm-tests: $(addprefix output/, $(addsuffix .out, $(global_asm_tests) $(global_asm_vm_tests))) @echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' $^; echo;