diff --git a/src/cpu/rv32cpu.c b/src/cpu/rv32cpu.c index 1d1be22..a917c05 100644 --- a/src/cpu/rv32cpu.c +++ b/src/cpu/rv32cpu.c @@ -676,8 +676,11 @@ void cpu_loop(rv32_cpu_t* cpu) instruction_t instruction; cpu_decode(raw_instruction, &instruction); - printf("0x%x: ", cpu->pc); - cpu_print_instruction(&instruction); + if(trace) + { + printf("0x%x: ", cpu->pc); + cpu_print_instruction(&instruction); + } // Execute cpu_execute(cpu, &instruction); diff --git a/src/option.c b/src/option.c index 8acfdee..0f51d91 100644 --- a/src/option.c +++ b/src/option.c @@ -8,6 +8,7 @@ uint64_t memory_size = 512 * 1024 * 1024; char* file_path; bool gdbstub = false; +bool trace = false; static void print_usage(); static void print_help(); @@ -100,6 +101,11 @@ void parse_options(int argc, char** argv) gdbstub = true; break; } + case 't': + { + trace = true; + break; + } default: { fprintf(stderr, "Error: Unknown short option -%c\n", argv[i][k]); @@ -161,6 +167,11 @@ static int parse_long_option(char* str, char* argq) gdbstub = true; return 0; } + else if(strcmp(str, "trace") == 0) + { + trace = true; + return 0; + } else { fprintf(stderr, "Error: Unknown long option " OPTION_SEPARATOR OPTION_SEPARATOR "%s\n", str); @@ -181,6 +192,7 @@ static void print_help() printf(" " OPTION_SEPARATOR "h, " OPTION_SEPARATOR "?, --help\t\tPrint this help message\n"); printf(" " OPTION_SEPARATOR "v, --version\t\t\tPrint version information\n"); printf(" " OPTION_SEPARATOR "m, --memory\t\t\tSet the simulated memory size, in MiB (max 4096)\n"); + printf(" " OPTION_SEPARATOR "t, --trace\t\t\tTrace executed instructions in stdout\n"); printf(" " OPTION_SEPARATOR "s, --gdb-stub\t\tLaunch a gdb stub server (remote gdb debugging)\n"); } diff --git a/src/vriscv.h b/src/vriscv.h index b34c4b7..3b06fe1 100644 --- a/src/vriscv.h +++ b/src/vriscv.h @@ -15,6 +15,7 @@ extern char* CURRENT_NAME; extern size_t memory_size; extern char* file_path; extern bool gdbstub; +extern bool trace; void parse_options(int argc, char** argv); #endif