@@ -68,23 +68,6 @@ ModelImpl g_model;
6868
6969FILE *trace_log = stdout;
7070
71- bool config_print_instr = false ;
72- bool config_print_reg = false ;
73- bool config_print_mem_access = false ;
74- bool config_print_clint = false ;
75- bool config_print_exception = false ;
76- bool config_print_interrupt = false ;
77- bool config_print_htif = false ;
78- bool config_print_pma = false ;
79- bool config_print_rvfi = false ;
80- bool config_print_step = false ;
81- bool config_print_ptw = false ;
82-
83- bool config_use_abi_names = false ;
84- bool config_enable_rvfi = false ;
85-
86- bool config_enable_experimental_extensions = false ;
87-
8871static void print_dts () {
8972 char *dts = nullptr ;
9073 g_model.zgenerate_dts (&dts, UNIT);
@@ -140,6 +123,22 @@ struct CLIOptions {
140123#ifdef SAILCOV
141124 std::string sailcov_file;
142125#endif
126+
127+ bool config_print_instr = false ;
128+ bool config_print_reg = false ;
129+ bool config_print_mem_access = false ;
130+ bool config_print_clint = false ;
131+ bool config_print_exception = false ;
132+ bool config_print_interrupt = false ;
133+ bool config_print_htif = false ;
134+ bool config_print_pma = false ;
135+ bool config_print_rvfi = false ;
136+ bool config_print_step = false ;
137+ bool config_print_ptw = false ;
138+
139+ bool config_use_abi_names = false ;
140+
141+ bool config_enable_experimental_extensions = false ;
143142};
144143
145144// Parse CLI options. This calls `exit()` on failure.
@@ -164,10 +163,10 @@ static CLIOptions parse_cli(int argc, char **argv) {
164163 app.add_flag (" --print-isa-string" , opts.do_print_isa , " Print ISA string" );
165164 app.add_flag (
166165 " --enable-experimental-extensions" ,
167- config_enable_experimental_extensions,
166+ opts. config_enable_experimental_extensions ,
168167 " Enable experimental extensions"
169168 );
170- app.add_flag (" --use-abi-names" , config_use_abi_names, " Use ABI register names in trace log" );
169+ app.add_flag (" --use-abi-names" , opts. config_use_abi_names , " Use ABI register names in trace log" );
171170
172171 app.add_option (" --device-tree-blob" , opts.dtb_file , " Device tree blob file" )
173172 ->check (CLI::ExistingFile)
@@ -186,44 +185,44 @@ static CLIOptions parse_cli(int argc, char **argv) {
186185 app.add_option (" --sailcov-file" , sailcov_file, " Sail coverage output file" )->option_text (" <file>" );
187186#endif
188187
189- app.add_flag (" --trace-instr" , config_print_instr, " Enable trace output for instruction execution" );
190- app.add_flag (" --trace-ptw" , config_print_ptw, " Enable trace output for Page Table walk" );
191- app.add_flag (" --trace-reg" , config_print_reg, " Enable trace output for register access" );
192- app.add_flag (" --trace-mem" , config_print_mem_access, " Enable trace output for memory accesses" );
193- app.add_flag (" --trace-rvfi" , config_print_rvfi, " Enable trace output for RVFI" );
194- app.add_flag (" --trace-clint" , config_print_clint, " Enable trace output for CLINT memory accesses and status" );
195- app.add_flag (" --trace-exception" , config_print_exception, " Enable trace output for exceptions" );
196- app.add_flag (" --trace-interrupt" , config_print_interrupt, " Enable trace output for interrupts" );
197- app.add_flag (" --trace-htif" , config_print_htif, " Enable trace output for HTIF operations" );
198- app.add_flag (" --trace-pma" , config_print_pma, " Enable trace output for PMA checks" );
188+ app.add_flag (" --trace-instr" , opts. config_print_instr , " Enable trace output for instruction execution" );
189+ app.add_flag (" --trace-ptw" , opts. config_print_ptw , " Enable trace output for Page Table walk" );
190+ app.add_flag (" --trace-reg" , opts. config_print_reg , " Enable trace output for register access" );
191+ app.add_flag (" --trace-mem" , opts. config_print_mem_access , " Enable trace output for memory accesses" );
192+ app.add_flag (" --trace-rvfi" , opts. config_print_rvfi , " Enable trace output for RVFI" );
193+ app.add_flag (" --trace-clint" , opts. config_print_clint , " Enable trace output for CLINT memory accesses and status" );
194+ app.add_flag (" --trace-exception" , opts. config_print_exception , " Enable trace output for exceptions" );
195+ app.add_flag (" --trace-interrupt" , opts. config_print_interrupt , " Enable trace output for interrupts" );
196+ app.add_flag (" --trace-htif" , opts. config_print_htif , " Enable trace output for HTIF operations" );
197+ app.add_flag (" --trace-pma" , opts. config_print_pma , " Enable trace output for PMA checks" );
199198 app.add_flag_callback (
200199 " --trace-platform" ,
201- [] {
202- config_print_clint = true ;
203- config_print_exception = true ;
204- config_print_interrupt = true ;
205- config_print_htif = true ;
206- config_print_pma = true ;
200+ [&opts ] {
201+ opts. config_print_clint = true ;
202+ opts. config_print_exception = true ;
203+ opts. config_print_interrupt = true ;
204+ opts. config_print_htif = true ;
205+ opts. config_print_pma = true ;
207206 },
208207 " Enable trace output for platform-level events (MMIO, interrupts, "
209208 " exceptions, CLINT, HTIF, PMA)"
210209 );
211- app.add_flag (" --trace-step" , config_print_step, " Add a blank line between steps in the trace output" );
210+ app.add_flag (" --trace-step" , opts. config_print_step , " Add a blank line between steps in the trace output" );
212211
213212 app.add_flag_callback (
214213 " --trace-all" ,
215- [] {
216- config_print_instr = true ;
217- config_print_reg = true ;
218- config_print_mem_access = true ;
219- config_print_rvfi = true ;
220- config_print_clint = true ;
221- config_print_exception = true ;
222- config_print_interrupt = true ;
223- config_print_htif = true ;
224- config_print_pma = true ;
225- config_print_step = true ;
226- config_print_ptw = true ;
214+ [&opts ] {
215+ opts. config_print_instr = true ;
216+ opts. config_print_reg = true ;
217+ opts. config_print_mem_access = true ;
218+ opts. config_print_rvfi = true ;
219+ opts. config_print_clint = true ;
220+ opts. config_print_exception = true ;
221+ opts. config_print_interrupt = true ;
222+ opts. config_print_htif = true ;
223+ opts. config_print_pma = true ;
224+ opts. config_print_step = true ;
225+ opts. config_print_ptw = true ;
227226 },
228227 " Enable all trace output"
229228 );
@@ -433,11 +432,9 @@ void finish(const CLIOptions &opts) {
433432}
434433
435434void flush_logs () {
436- if (config_print_instr) {
437- fflush (stderr);
438- fflush (stdout);
439- fflush (trace_log);
440- }
435+ fflush (stderr);
436+ fflush (stdout);
437+ fflush (trace_log);
441438}
442439
443440void run_sail (const CLIOptions &opts) {
@@ -454,7 +451,7 @@ void run_sail(const CLIOptions &opts) {
454451
455452 while (!g_model.zhtif_done && (opts.insn_limit == 0 || total_insns < opts.insn_limit )) {
456453 if (rvfi.has_value ()) {
457- switch (rvfi->pre_step (config_print_rvfi)) {
454+ switch (rvfi->pre_step (opts. config_print_rvfi )) {
458455 case RVFI_prestep_continue:
459456 continue ;
460457 case RVFI_prestep_eof:
@@ -477,17 +474,19 @@ void run_sail(const CLIOptions &opts) {
477474 if (g_model.have_exception ) {
478475 break ;
479476 }
480- flush_logs ();
477+ if (opts.config_print_instr ) {
478+ flush_logs ();
479+ }
481480 KILL (sail_int)(&sail_step);
482481 if (rvfi) {
483- rvfi->send_trace (config_print_rvfi);
482+ rvfi->send_trace (opts. config_print_rvfi );
484483 }
485484 }
486485
487486 g_model.call_post_step_callbacks (is_waiting);
488487
489488 if (!is_waiting) {
490- if (config_print_step) {
489+ if (opts. config_print_step ) {
491490 fprintf (trace_log, " \n " );
492491 }
493492 step_no++;
@@ -569,7 +568,6 @@ int inner_main(int argc, char **argv) {
569568 return EXIT_SUCCESS;
570569 }
571570 if (opts.rvfi_dii_port != 0 ) {
572- config_enable_rvfi = true ;
573571 rvfi.emplace (opts.rvfi_dii_port , g_model);
574572 }
575573 if (opts.do_show_times ) {
@@ -584,14 +582,25 @@ int inner_main(int argc, char **argv) {
584582 if (opts.signature_granularity != DEFAULT_SIGNATURE_GRANULARITY) {
585583 fprintf (stderr, " setting signature-granularity to %d bytes\n " , opts.signature_granularity );
586584 }
587- if (config_enable_experimental_extensions) {
585+ if (opts. config_enable_experimental_extensions ) {
588586 fprintf (stderr, " enabling unratified extensions.\n " );
589587 g_model.set_enable_experimental_extensions (true );
590588 }
591589 if (!opts.trace_log_path .empty ()) {
592590 fprintf (stderr, " using %s for trace output.\n " , opts.trace_log_path .c_str ());
593591 }
594592
593+ g_model.set_config_print_instr (opts.config_print_instr );
594+ g_model.set_config_print_clint (opts.config_print_clint );
595+ g_model.set_config_print_exception (opts.config_print_exception );
596+ g_model.set_config_print_interrupt (opts.config_print_interrupt );
597+ g_model.set_config_print_htif (opts.config_print_htif );
598+ g_model.set_config_print_pma (opts.config_print_pma );
599+ g_model.set_config_rvfi (rvfi.has_value ());
600+ g_model.set_config_use_abi_names (opts.config_use_abi_names );
601+
602+ g_model.set_config_print_step (opts.config_print_step );
603+
595604 // Always validate the schema conformance of the config.
596605 validate_config_schema (opts.config_file );
597606
@@ -640,13 +649,19 @@ int inner_main(int argc, char **argv) {
640649 }
641650
642651 init_logs (opts);
643- log_callbacks log_cbs (config_print_reg, config_print_mem_access, config_print_ptw, config_use_abi_names, trace_log);
652+ log_callbacks log_cbs (
653+ opts.config_print_reg ,
654+ opts.config_print_mem_access ,
655+ opts.config_print_ptw ,
656+ opts.config_use_abi_names ,
657+ trace_log
658+ );
644659 g_model.register_callback (&log_cbs);
645660
646661 init_start = steady_clock::now ();
647662
648663 if (rvfi) {
649- if (!rvfi->setup_socket (config_print_rvfi)) {
664+ if (!rvfi->setup_socket (opts. config_print_rvfi )) {
650665 return 1 ;
651666 }
652667 g_model.register_callback (&rvfi_cbs);
0 commit comments