diff --git a/src/emu.h b/src/emu.h index ee1e9995..5bc2589c 100644 --- a/src/emu.h +++ b/src/emu.h @@ -10,6 +10,8 @@ #include "trap.h" #include "csr.h" +static bool allow_ecall_exit = false; + #define AS_SIGNED(val) (*(int32_t*)&val) #define AS_UNSIGNED(val) (*(uint*)&val) const uint ZERO = 0; @@ -203,12 +205,12 @@ DEF(ebreak, FormatEmpty, { // system SINGLE_STEP=1; }) DEF(ecall, FormatEmpty, { // system - /* if (cpu->xreg[17] == 93) { */ - /* // EXIT CALL */ - /* uint status = cpu->xreg[10] >> 1; */ - /* printf("ecall EXIT = %d (0x%x)\n", status, status); */ - /* exit(status); */ - /* } */ + if (allow_ecall_exit && cpu->xreg[17] == 93) { + // EXIT CALL + uint status = cpu->xreg[10] >> 1; + printf("ecall EXIT = %d (0x%x)\n", status, status); + exit(status); + } ret->trap.en = true; ret->trap.value = cpu->pc; diff --git a/src/main.c b/src/main.c index 0b3fb18c..5701a50e 100644 --- a/src/main.c +++ b/src/main.c @@ -58,7 +58,7 @@ uint8_t* get_mmap_ptr(const char* filename) { } void usage() { - printf("Usage: rvc (-e |-b ) [-d ] [-i ] [-v (0|1|2|3|4)] [-s] [-t]\n"); + printf("Usage: rvc (-e |-b ) [-d ] [-i ] [-v (0|1|2|3|4)] [-s] [-t] [-x]\n"); exit(EXIT_FAILURE); } @@ -92,9 +92,12 @@ int main(int argc, char *argv[]) { int c; bool trace = false; - while ((c = getopt (argc, argv, "e:b:d:v:i:st")) != -1) { + while ((c = getopt (argc, argv, "e:b:d:v:i:stx")) != -1) { switch (c) { + case 'x': + allow_ecall_exit = true; + break; case 'e': elf = optarg; break; @@ -163,7 +166,7 @@ int main(int argc, char *argv[]) { setvbuf(stdin, NULL, _IONBF, 0); buf_off(); - // LIMITER + // LIMITER (set to high number to ignore) const unsigned long restr = 200000*1000; unsigned long cur = 0; unsigned long t = time(NULL); @@ -204,13 +207,13 @@ int main(int argc, char *argv[]) { /* printf("else if (cpu.clock == %d && arb != 0x%08x) ARB_FAIL\n", cpu.clock, arb_f); */ /* } */ - if (cpu.pc == 0x80000118) { + /* if (cpu.pc == 0x80000118) { */ /* if (cpu.clock == 6350505) { // divergence: 6350908 */ /* if (cpu.clock == 6400000) { */ - printf("BREAKPOINT HIT\n"); - SINGLE_STEP = 1; - VERBOSE = 4; - } + /* printf("BREAKPOINT HIT\n"); */ + /* SINGLE_STEP = 1; */ + /* VERBOSE = 4; */ + /* } */ if (VERBOSE >= 4) cpu_dump(&cpu); diff --git a/test.sh b/test.sh index 3a62cbd9..ade7588a 100755 --- a/test.sh +++ b/test.sh @@ -19,8 +19,8 @@ function run_test { popd - echo "Running: ./rvc -e \"./riscv-tests/isa/$1\" -v 1" - timeout 5s ./rvc -e "./riscv-tests/isa/$1" -v 1 + echo "Running: ./rvc -x -e \"./riscv-tests/isa/$1\" -v 1" + ./rvc -x -e "./riscv-tests/isa/$1" -v 1 if [ $? -gt 0 ]; then echo "Test failed!"