33#include " common/logging.h"
44#include " common/logging_format_colors.h"
55#include " machine/machineconfig.h"
6- #include " os_emulation/ossyscall.h"
76#include " msgreport.h"
7+ #include " os_emulation/ossyscall.h"
88#include " reporter.h"
99#include " tracer.h"
1010
@@ -34,23 +34,29 @@ void create_parser(QCommandLineParser &p) {
3434 p.addOption ({ " no-delay-slot" , " Disable jump delay slot." });
3535 p.addOption (
3636 { " hazard-unit" , " Specify hazard unit implementation [none|stall|forward]." , " HUKIND" });
37- p.addOption ({ { " trace-fetch" , " tr-fetch" },
38- " Trace fetched instruction (for both pipelined and not core)." });
39- p.addOption ({ { " trace-decode" , " tr-decode" },
40- " Trace instruction in decode stage. (only for pipelined core)" });
41- p.addOption ({ { " trace-execute" , " tr-execute" },
42- " Trace instruction in execute stage. (only for pipelined core)" });
43- p.addOption ({ { " trace-memory" , " tr-memory" },
44- " Trace instruction in memory stage. (only for pipelined core)" });
45- p.addOption ({ { " trace-writeback" , " tr-writeback" },
46- " Trace instruction in write back stage. (only for pipelined core)" });
37+ p.addOption (
38+ { { " trace-fetch" , " tr-fetch" },
39+ " Trace fetched instruction (for both pipelined and not core)." });
40+ p.addOption (
41+ { { " trace-decode" , " tr-decode" },
42+ " Trace instruction in decode stage. (only for pipelined core)" });
43+ p.addOption (
44+ { { " trace-execute" , " tr-execute" },
45+ " Trace instruction in execute stage. (only for pipelined core)" });
46+ p.addOption (
47+ { { " trace-memory" , " tr-memory" },
48+ " Trace instruction in memory stage. (only for pipelined core)" });
49+ p.addOption (
50+ { { " trace-writeback" , " tr-writeback" },
51+ " Trace instruction in write back stage. (only for pipelined core)" });
4752 p.addOption ({ { " trace-pc" , " tr-pc" }, " Print program counter register changes." });
4853 p.addOption ({ { " trace-wrmem" , " tr-wr" }, " Trace writes into memory." });
4954 p.addOption ({ { " trace-rdmem" , " tr-rd" }, " Trace reads from memory." });
50- p.addOption ({ { " trace-gp" , " tr-gp" },
51- " Print general purpose register changes. You can use * for "
52- " all registers." ,
53- " REG" });
55+ p.addOption (
56+ { { " trace-gp" , " tr-gp" },
57+ " Print general purpose register changes. You can use * for "
58+ " all registers." ,
59+ " REG" });
5460 p.addOption ({ " dump-to-json" , " Configure reportor dump to json file." , " FNAME" });
5561 p.addOption ({ " only-dump" , " Do not start the processor." });
5662 p.addOption ({ " disable-console-dump" , " Configure reporter not to dump to console." });
@@ -61,34 +67,41 @@ void create_parser(QCommandLineParser &p) {
6167 p.addOption ({ " dump-symbol-table" , " Dump the symbol table." });
6268 p.addOption ({ " load-range" , " Load memory range." , " START,FNAME" });
6369 p.addOption ({ " expect-fail" , " Expect that program causes CPU trap and fail if it doesn't." });
64- p.addOption ({ " fail-match" ,
65- " Program should exit with exactly this CPU TRAP. Possible values are "
66- " I(unsupported Instruction), A(Unsupported ALU operation), "
67- " O(Overflow/underflow) and J(Unaligned Jump). You can freely combine "
68- " them. Using this implies expect-fail option." ,
69- " TRAP" });
70- p.addOption ({ " d-cache" ,
71- " Data cache. Format policy,sets,words_in_blocks,associativity where "
72- " policy is random/lru/lfu" ,
73- " DCACHE" });
74- p.addOption ({ " i-cache" ,
75- " Instruction cache. Format policy,sets,words_in_blocks,associativity "
76- " where policy is random/lru/lfu" ,
77- " ICACHE" });
78- p.addOption ({ " l2-cache" ,
79- " L2 cache. Format policy,sets,words_in_blocks,associativity where "
80- " policy is random/lru/lfu" ,
81- " L2CACHE" });
70+ p.addOption (
71+ { " fail-match" ,
72+ " Program should exit with exactly this CPU TRAP. Possible values are "
73+ " I(unsupported Instruction), A(Unsupported ALU operation), "
74+ " O(Overflow/underflow) and J(Unaligned Jump). You can freely combine "
75+ " them. Using this implies expect-fail option." ,
76+ " TRAP" });
77+ p.addOption (
78+ { " d-cache" ,
79+ " Data cache. Format policy,sets,words_in_blocks,associativity where "
80+ " policy is random/lru/lfu" ,
81+ " DCACHE" });
82+ p.addOption (
83+ { " i-cache" ,
84+ " Instruction cache. Format policy,sets,words_in_blocks,associativity "
85+ " where policy is random/lru/lfu" ,
86+ " ICACHE" });
87+ p.addOption (
88+ { " l2-cache" ,
89+ " L2 cache. Format policy,sets,words_in_blocks,associativity where "
90+ " policy is random/lru/lfu" ,
91+ " L2CACHE" });
8292 p.addOption ({ " read-time" , " Memory read access time (cycles)." , " RTIME" });
8393 p.addOption ({ " write-time" , " Memory read access time (cycles)." , " WTIME" });
8494 p.addOption ({ " burst-time" , " Memory read access time (cycles)." , " BTIME" });
8595 p.addOption ({ { " serial-in" , " serin" }, " File connected to the serial port input." , " FNAME" });
8696 p.addOption (
8797 { { " serial-out" , " serout" }, " File connected to the serial port output." , " FNAME" });
8898 p.addOption ({ { " os-emulation" , " osemu" }, " Operating system emulation." });
89- p.addOption ({ { " std-out" , " stdout" }, " File connected to the syscall standard output." , " FNAME" });
90- p.addOption ({ { " os-fs-root" , " osfsroot" }, " Emulated system root/prefix for opened files" , " DIR" });
91- p.addOption ({ { " isa-variant" , " isavariant" }, " Instruction set to emulate (default RV32IMA)" , " STR" });
99+ p.addOption (
100+ { { " std-out" , " stdout" }, " File connected to the syscall standard output." , " FNAME" });
101+ p.addOption (
102+ { { " os-fs-root" , " osfsroot" }, " Emulated system root/prefix for opened files" , " DIR" });
103+ p.addOption (
104+ { { " isa-variant" , " isavariant" }, " Instruction set to emulate (default RV32IMA)" , " STR" });
92105 p.addOption ({ " cycle-limit" , " Limit execution to specified maximum clock cycles" , " NUMBER" });
93106}
94107
@@ -205,19 +218,18 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) {
205218 int siz = parser.values (" os-fs-root" ).size ();
206219 if (siz >= 1 ) {
207220 QString osemu_fs_root = parser.values (" os-fs-root" ).at (siz - 1 );
208- if (osemu_fs_root.length () > 0 )
209- config.set_osemu_fs_root (osemu_fs_root);
221+ if (osemu_fs_root.length () > 0 ) { config.set_osemu_fs_root (osemu_fs_root); }
210222 }
211223 siz = parser.values (" isa-variant" ).size ();
212224 for (int i = 0 ; i < siz; i++) {
213225 int pos = 0 ;
214226 bool first = true ;
215227 bool subtract = false ;
216228 QString isa_str = parser.values (" isa-variant" ).at (i).toUpper ();
217- if (isa_str.startsWith (" RV32" )) {
229+ if (isa_str.startsWith (" RV32" )) {
218230 config.set_simulated_xlen (machine::Xlen::_32);
219231 pos = 4 ;
220- } else if (isa_str.startsWith (" RV64" )) {
232+ } else if (isa_str.startsWith (" RV64" )) {
221233 config.set_simulated_xlen (machine::Xlen::_64);
222234 pos = 4 ;
223235 }
@@ -231,10 +243,10 @@ void configure_machine(QCommandLineParser &parser, MachineConfig &config) {
231243 continue ;
232244 }
233245 auto flag = machine::ConfigIsaWord::byChar (ch);
234- if (flag.isEmpty ())
235- continue ;
246+ if (flag.isEmpty ()) continue ;
236247 if (first)
237- config.modify_isa_word (~machine::ConfigIsaWord::empty (), machine::ConfigIsaWord::empty ());
248+ config.modify_isa_word (
249+ ~machine::ConfigIsaWord::empty (), machine::ConfigIsaWord::empty ());
238250 if (subtract)
239251 config.modify_isa_word (flag, machine::ConfigIsaWord::empty ());
240252 else
@@ -256,7 +268,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
256268 if (p.isSet (" trace-gp" )) { tr.trace_regs_gp = true ; }
257269
258270 QStringList gps = p.values (" trace-gp" );
259- for (const auto & gp : gps) {
271+ for (const auto &gp : gps) {
260272 if (gp == " *" ) {
261273 tr.regs_to_trace .fill (true );
262274 } else {
@@ -265,8 +277,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
265277 if (res && num <= machine::REGISTER_COUNT) {
266278 tr.regs_to_trace .at (num) = true ;
267279 } else {
268- fprintf (
269- stderr, " Unknown register number given for trace-gp: %s\n " , qPrintable (gp));
280+ fprintf (stderr, " Unknown register number given for trace-gp: %s\n " , qPrintable (gp));
270281 exit (EXIT_FAILURE);
271282 }
272283 }
@@ -280,8 +291,7 @@ void configure_tracer(QCommandLineParser &p, Tracer &tr) {
280291 bool ok;
281292 tr.cycle_limit = clim.at (clim.size () - 1 ).toLong (&ok);
282293 if (!ok) {
283- fprintf (
284- stderr, " Cycle limit parse error\n " );
294+ fprintf (stderr, " Cycle limit parse error\n " );
285295 exit (EXIT_FAILURE);
286296 }
287297 }
@@ -303,7 +313,7 @@ void configure_reporter(QCommandLineParser &p, Reporter &r, const SymbolTable *s
303313 if (p.isSet (" dump-symbol-table" )) { r.enable_symbol_table_reporting (); }
304314
305315 QStringList fail = p.values (" fail-match" );
306- for (const auto & i : fail) {
316+ for (const auto &i : fail) {
307317 for (int y = 0 ; y < i.length (); y++) {
308318 enum Reporter::FailReason reason;
309319 switch (tolower (i.toStdString ()[y])) {
@@ -420,17 +430,18 @@ void configure_osemu(QCommandLineParser &p, MachineConfig &config, Machine *mach
420430 exit (EXIT_FAILURE);
421431 }
422432 }
423- const static machine::ExceptionCause ecall_variats[] = {machine::EXCAUSE_ECALL_ANY,
424- machine::EXCAUSE_ECALL_M, machine::EXCAUSE_ECALL_S, machine::EXCAUSE_ECALL_U};
433+ const static machine::ExceptionCause ecall_variats[]
434+ = { machine::EXCAUSE_ECALL_ANY, machine::EXCAUSE_ECALL_M, machine::EXCAUSE_ECALL_S,
435+ machine::EXCAUSE_ECALL_U };
425436
426437 if (config.osemu_enable ()) {
427438 auto *osemu_handler = new osemu::OsSyscallExceptionHandler (
428439 config.osemu_known_syscall_stop (), config.osemu_unknown_syscall_stop (),
429440 config.osemu_fs_root ());
430441 if (std_out) {
431442 machine::Machine::connect (
432- osemu_handler, &osemu::OsSyscallExceptionHandler::char_written,
433- std_out, QOverload<int , unsigned >::of (&CharIOHandler::writeByte));
443+ osemu_handler, &osemu::OsSyscallExceptionHandler::char_written, std_out,
444+ QOverload<int , unsigned >::of (&CharIOHandler::writeByte));
434445 }
435446 /* connect(
436447 osemu_handler, &osemu::OsSyscallExceptionHandler::rx_byte_pool, terminal,
@@ -475,9 +486,7 @@ void load_ranges(Machine &machine, const QStringList &ranges) {
475486 Address addr = start;
476487 for (std::string line; getline (in, line);) {
477488 size_t end_pos = line.find_last_not_of (" \t\n " );
478- if (std::string::npos == end_pos) {
479- continue ;
480- }
489+ if (std::string::npos == end_pos) { continue ; }
481490
482491 size_t start_pos = line.find_first_not_of (" \t\n " );
483492 line = line.substr (0 , end_pos + 1 );
@@ -507,9 +516,7 @@ bool assemble(Machine &machine, MsgReport &msgrep, const QString &filename) {
507516
508517 assembler.setup (mem, &symbol_table_db, 0x00000200_addr, machine.core ()->get_xlen ());
509518
510- if (!assembler.process_file (filename)) {
511- return false ;
512- }
519+ if (!assembler.process_file (filename)) { return false ; }
513520
514521 return assembler.finish ();
515522}
0 commit comments