Helper functions for test-suite

This commit is contained in:
Màrius Montón 2022-09-14 20:03:01 +02:00
parent 89f9293ff3
commit 0e2f1f7874
No known key found for this signature in database
GPG Key ID: FA199E7A752699F0
1 changed files with 20 additions and 4 deletions

View File

@ -48,12 +48,14 @@ public:
riscv_tlm::peripherals::Trace *trace;
riscv_tlm::peripherals::Timer *timer;
explicit Simulator(sc_core::sc_module_name const &name, cpu_types_t cpu_type): sc_module(name) {
explicit Simulator(sc_core::sc_module_name const &name, cpu_types_t cpu_type_m): sc_module(name) {
std::uint32_t start_PC;
MainMemory = new riscv_tlm::Memory("Main_Memory", filename);
start_PC = MainMemory->getPCfromHEX();
cpu_type = cpu_type_m;
if (cpu_type == RV32) {
cpu = new riscv_tlm::RV32("cpu", start_PC, debug_session);
} else {
@ -92,6 +94,16 @@ public:
private:
void MemoryDump() const {
std::cout << "********** MEMORY DUMP ***********\n";
if (dump_addr_st == 0) {
dump_addr_st = cpu->getStartDumpAddress();
}
if (dump_addr_end == 0) {
dump_addr_end = cpu->getEndDumpAddress();
}
std::cout << "from 0x" << std::hex << dump_addr_st << " to 0x" << dump_addr_end << "\n";
tlm::tlm_generic_payload trans;
sc_core::sc_time delay;
std::uint32_t data[4];
@ -122,6 +134,9 @@ private:
signature_file.close();
}
private:
cpu_types_t cpu_type;
};
Simulator *top;
@ -181,7 +196,7 @@ void process_arguments(int argc, char *argv[]) {
filename = std::string(optarg);
break;
case 'R':
if (strcmp(optarg, "RV32") == 0) {
if (strcmp(optarg, "32") == 0) {
cpu_type_opt = RV32;
} else {
cpu_type_opt = RV64;
@ -214,7 +229,7 @@ int sc_main(int argc, char *argv[]) {
sc_core::sc_set_time_resolution(1, sc_core::SC_NS);
spdlog::filename_t log_filename = SPDLOG_FILENAME_T("newlog.txt");
logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("my_logger", log_filename);
logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("my_logger", log_filename, true);
logger->set_pattern("%v");
logger->set_level(spdlog::level::info);
@ -233,7 +248,8 @@ int sc_main(int argc, char *argv[]) {
std::cout << "Total elapsed time: " << elapsed_seconds.count() << "s" << std::endl;
std::cout << "Simulated " << int(std::round(instructions)) << " instr/sec" << std::endl;
if (!mem_dump) {
if (!mem_dump)
{
std::cout << "Press Enter to finish" << std::endl;
std::cin.ignore();
}