diff options
-rw-r--r-- | c_emulator/riscv_prelude.c | 20 | ||||
-rw-r--r-- | c_emulator/riscv_prelude.h | 5 | ||||
-rw-r--r-- | c_emulator/riscv_sim.c | 40 | ||||
-rw-r--r-- | model/prelude.sail | 12 | ||||
-rw-r--r-- | model/riscv_step.sail | 8 | ||||
-rw-r--r-- | ocaml_emulator/platform.ml | 5 |
6 files changed, 83 insertions, 7 deletions
diff --git a/c_emulator/riscv_prelude.c b/c_emulator/riscv_prelude.c index 1621913..92f8415 100644 --- a/c_emulator/riscv_prelude.c +++ b/c_emulator/riscv_prelude.c @@ -30,3 +30,23 @@ unit print_platform(sail_string s) if (config_print_platform) printf("%s\n", s); return UNIT; } + +bool get_config_print_instr(unit u) +{ + return (config_print_instr) ? true : false; +} + +bool get_config_print_reg(unit u) +{ + return (config_print_reg) ? true : false; +} + +bool get_config_print_mem(unit u) +{ + return (config_print_mem_access) ? true : false; +} + +bool get_config_print_platform(unit u) +{ + return (config_print_platform) ? true : false; +} diff --git a/c_emulator/riscv_prelude.h b/c_emulator/riscv_prelude.h index a296c7e..da292fe 100644 --- a/c_emulator/riscv_prelude.h +++ b/c_emulator/riscv_prelude.h @@ -8,3 +8,8 @@ unit print_instr(sail_string s); unit print_reg(sail_string s); unit print_mem_access(sail_string s); unit print_platform(sail_string s); + +bool get_config_print_instr(unit u); +bool get_config_print_reg(unit u); +bool get_config_print_mem(unit u); +bool get_config_print_platform(unit u); diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 864e2b7..c9cf011 100644 --- a/c_emulator/riscv_sim.c +++ b/c_emulator/riscv_sim.c @@ -69,6 +69,26 @@ bool config_print_reg = true; bool config_print_mem_access = true; bool config_print_platform = true; +void set_config_print(char *var, bool val) { + if (strcmp("instr", optarg) == 0) { + config_print_instr = val; + } else if (strcmp("reg", optarg) == 0) { + config_print_reg = val; + } else if (strcmp("mem", optarg) == 0) { + config_print_mem_access = val; + } else if (strcmp("platform", optarg) == 0) { + config_print_platform = val; + } else if (strcmp("all", optarg) == 0) { + config_print_instr = val; + config_print_mem_access = val; + config_print_reg = val; + config_print_platform = val; + } else { + fprintf(stderr, "Unknown trace category: %s (should be instr|reg|mem|platform|all)\n", var); + exit(1); + } +} + struct timeval init_start, init_end, run_end; int total_insns = 0; @@ -88,6 +108,8 @@ static struct option options[] = { {"rvfi-dii", required_argument, 0, 'r'}, #endif {"help", no_argument, 0, 'h'}, + {"trace", required_argument, 0, 'v'}, + {"no-trace", required_argument, 0, 'V'}, {0, 0, 0, 0} }; @@ -171,7 +193,7 @@ char *process_args(int argc, char **argv) int c, idx = 1; uint64_t ram_size = 0; while(true) { - c = getopt_long(argc, argv, "admCIispz:b:t:v:hr:T:", options, &idx); + c = getopt_long(argc, argv, "admCIispz:b:t:v:hr:T:V:v:", options, &idx); if (c == -1) break; switch (c) { case 'a': @@ -236,6 +258,12 @@ char *process_args(int argc, char **argv) fprintf(stderr, "using %d as RVFI port.\n", rvfi_dii_port); break; #endif + case 'V': + set_config_print(optarg, false); + break; + case 'v': + set_config_print(optarg, true); + break; } } if (do_dump_dts) dump_dts(); @@ -574,10 +602,12 @@ int compare_states(struct tv_spike_t *s) void flush_logs(void) { - fprintf(stderr, "\n"); - fflush(stderr); - fprintf(stdout, "\n"); - fflush(stdout); + if(config_print_instr) { + fprintf(stderr, "\n"); + fflush(stderr); + fprintf(stdout, "\n"); + fflush(stdout); + } } #ifdef RVFI_DII diff --git a/model/prelude.sail b/model/prelude.sail index 54f7d03..9f8ad37 100644 --- a/model/prelude.sail +++ b/model/prelude.sail @@ -101,6 +101,18 @@ val print_reg = {ocaml: "Platform.print_reg", interpreter: "print_endline", val print_mem = {ocaml: "Platform.print_mem_access", interpreter: "print_endline", c: "print_mem_access", lem: "print_dbg", _: "print_endline"} : string -> unit val print_platform = {ocaml: "Platform.print_platform", interpreter: "print_endline", c: "print_platform", lem: "print_dbg", _: "print_endline"} : string -> unit +val get_config_print_instr = {ocaml: "Platform.get_config_print_instr", c:"get_config_print_instr"} : unit -> bool +function get_config_print_instr () -> bool = false + +val get_config_print_reg = {ocaml: "Platform.get_config_print_reg", c:"get_config_print_reg"} : unit -> bool +function get_config_print_reg () -> bool = false + +val get_config_print_mem = {ocaml: "Platform.get_config_print_mem", c:"get_config_print_mem"} : unit -> bool +function get_config_print_mem () -> bool = false + +val get_config_print_platform = {ocaml: "Platform.get_config_print_platform", c:"get_config_print_platform"} : unit -> bool +function get_config_print_platform () -> bool = false + $ifndef FEATURE_IMPLICITS val EXTS : forall 'n 'm , 'm >= 'n . bits('n) -> bits('m) val EXTZ : forall 'n 'm , 'm >= 'n . bits('n) -> bits('m) diff --git a/model/riscv_step.sail b/model/riscv_step.sail index 4b5c1c5..12c8522 100644 --- a/model/riscv_step.sail +++ b/model/riscv_step.sail @@ -31,7 +31,9 @@ function step(step_no) = { /* non-error cases: */ F_RVC(h) => { let ast = decodeCompressed(h); - print_instr("[" ^ string_of_int(step_no) ^ "] [" ^ cur_privilege ^ "]: " ^ BitStr(PC) ^ " (" ^ BitStr(h) ^ ") " ^ ast); + if get_config_print_instr() then { + print_instr("[" ^ string_of_int(step_no) ^ "] [" ^ cur_privilege ^ "]: " ^ BitStr(PC) ^ " (" ^ BitStr(h) ^ ") " ^ ast); + }; /* check for RVC once here instead of every RVC execute clause. */ if haveRVC() then { nextPC = PC + 2; @@ -43,7 +45,9 @@ function step(step_no) = { }, F_Base(w) => { let ast = decode(w); - print_instr("[" ^ string_of_int(step_no) ^ "] [" ^ cur_privilege ^ "]: " ^ BitStr(PC) ^ " (" ^ BitStr(w) ^ ") " ^ ast); + if get_config_print_instr() then { + print_instr("[" ^ string_of_int(step_no) ^ "] [" ^ cur_privilege ^ "]: " ^ BitStr(PC) ^ " (" ^ BitStr(w) ^ ") " ^ ast); + }; nextPC = PC + 4; (execute(ext_post_decode_hook(ast)), true) } diff --git a/ocaml_emulator/platform.ml b/ocaml_emulator/platform.ml index 11abaf1..a5c01ba 100644 --- a/ocaml_emulator/platform.ml +++ b/ocaml_emulator/platform.ml @@ -39,6 +39,11 @@ let print_platform s = then print_endline s else () +let get_config_print_instr () = !config_print_instr +let get_config_print_reg () = !config_print_reg +let get_config_print_mem () = !config_print_mem_access +let get_config_print_platform () = !config_print_platform + (* Mapping to Sail externs *) let cur_arch_bitwidth () = match !platform_arch with |