Helper functions for test-suite
This commit is contained in:
parent
89f9293ff3
commit
0e2f1f7874
|
@ -48,12 +48,14 @@ public:
|
||||||
riscv_tlm::peripherals::Trace *trace;
|
riscv_tlm::peripherals::Trace *trace;
|
||||||
riscv_tlm::peripherals::Timer *timer;
|
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;
|
std::uint32_t start_PC;
|
||||||
|
|
||||||
MainMemory = new riscv_tlm::Memory("Main_Memory", filename);
|
MainMemory = new riscv_tlm::Memory("Main_Memory", filename);
|
||||||
start_PC = MainMemory->getPCfromHEX();
|
start_PC = MainMemory->getPCfromHEX();
|
||||||
|
|
||||||
|
cpu_type = cpu_type_m;
|
||||||
|
|
||||||
if (cpu_type == RV32) {
|
if (cpu_type == RV32) {
|
||||||
cpu = new riscv_tlm::RV32("cpu", start_PC, debug_session);
|
cpu = new riscv_tlm::RV32("cpu", start_PC, debug_session);
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,6 +94,16 @@ public:
|
||||||
private:
|
private:
|
||||||
void MemoryDump() const {
|
void MemoryDump() const {
|
||||||
std::cout << "********** MEMORY DUMP ***********\n";
|
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;
|
tlm::tlm_generic_payload trans;
|
||||||
sc_core::sc_time delay;
|
sc_core::sc_time delay;
|
||||||
std::uint32_t data[4];
|
std::uint32_t data[4];
|
||||||
|
@ -122,6 +134,9 @@ private:
|
||||||
|
|
||||||
signature_file.close();
|
signature_file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
cpu_types_t cpu_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
Simulator *top;
|
Simulator *top;
|
||||||
|
@ -181,7 +196,7 @@ void process_arguments(int argc, char *argv[]) {
|
||||||
filename = std::string(optarg);
|
filename = std::string(optarg);
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
if (strcmp(optarg, "RV32") == 0) {
|
if (strcmp(optarg, "32") == 0) {
|
||||||
cpu_type_opt = RV32;
|
cpu_type_opt = RV32;
|
||||||
} else {
|
} else {
|
||||||
cpu_type_opt = RV64;
|
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);
|
sc_core::sc_set_time_resolution(1, sc_core::SC_NS);
|
||||||
|
|
||||||
spdlog::filename_t log_filename = SPDLOG_FILENAME_T("newlog.txt");
|
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_pattern("%v");
|
||||||
logger->set_level(spdlog::level::info);
|
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 << "Total elapsed time: " << elapsed_seconds.count() << "s" << std::endl;
|
||||||
std::cout << "Simulated " << int(std::round(instructions)) << " instr/sec" << 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::cout << "Press Enter to finish" << std::endl;
|
||||||
std::cin.ignore();
|
std::cin.ignore();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue