2017-09-21 13:13:01 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright 2017 eyck@minres.com
|
2017-09-22 11:23:23 +02:00
|
|
|
//
|
2017-09-21 13:13:01 +02:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
// use this file except in compliance with the License. You may obtain a copy
|
|
|
|
// of the License at
|
2017-09-22 11:23:23 +02:00
|
|
|
//
|
2017-09-21 13:13:01 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2017-09-22 11:23:23 +02:00
|
|
|
//
|
2017-09-21 13:13:01 +02:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*
|
|
|
|
* sc_main.cpp
|
|
|
|
*
|
|
|
|
* Created on: 17.09.2017
|
|
|
|
* Author: eyck@minres.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
2017-10-04 10:31:11 +02:00
|
|
|
#include <iss/jit/MCJIThelper.h>
|
|
|
|
#include <iss/log_categories.h>
|
2017-09-22 11:23:23 +02:00
|
|
|
#include <sr_report/sr_report.h>
|
2017-09-21 13:13:01 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <sysc/SiFive/platform.h>
|
2017-10-04 10:31:11 +02:00
|
|
|
#include <sysc/configurer.h>
|
2017-09-22 11:23:23 +02:00
|
|
|
#include <sysc/report.h>
|
|
|
|
#include <sysc/scv_tr_db.h>
|
|
|
|
#include <sysc/tracer.h>
|
2017-09-21 13:13:01 +02:00
|
|
|
|
|
|
|
using namespace sysc;
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const size_t ERROR_IN_COMMAND_LINE = 1;
|
|
|
|
const size_t SUCCESS = 0;
|
|
|
|
const size_t ERROR_UNHANDLED_EXCEPTION = 2;
|
|
|
|
} // namespace
|
|
|
|
|
2017-09-22 11:23:23 +02:00
|
|
|
int sc_main(int argc, char *argv[]) {
|
|
|
|
// sc_report_handler::set_handler(my_report_handler);
|
2017-10-04 10:31:11 +02:00
|
|
|
sysc::Logger<>::reporting_level() = log::ERROR;
|
2017-09-21 13:13:01 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// CLI argument parsing
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2017-09-22 11:23:23 +02:00
|
|
|
po::options_description desc("Options");
|
2017-10-04 10:31:11 +02:00
|
|
|
// clang-format off
|
|
|
|
desc.add_options()
|
|
|
|
("help,h", "Print help message")
|
|
|
|
("verbose,v", po::value<int>()->implicit_value(0), "Sets logging verbosity")
|
|
|
|
("log-file", po::value<std::string>(), "Sets default log file.")
|
|
|
|
("disass,d", po::value<std::string>()->implicit_value(""), "Enables disassembly")
|
|
|
|
// ("elf,l", po::value<std::vector<std::string>>(), "ELF file(s) to load")
|
|
|
|
("elf,l", po::value<std::string>(), "ELF file to load")
|
|
|
|
("gdb-port,g", po::value<unsigned short>()->default_value(0), "enable gdb server and specify port to use")
|
|
|
|
("dump-ir", "dump the intermediate representation")
|
|
|
|
("cycles,c", po::value<int64_t>()->default_value(-1), "number of cycles to run")
|
|
|
|
("quantum", po::value<unsigned>(), "SystemC quantum time in ns")
|
|
|
|
("reset,r", po::value<std::string>(), "reset address")
|
|
|
|
("trace,t", po::value<uint8_t>()->default_value(0), "enable tracing, or combintation of 1=signals and 2=TX text, 4=TX compressed text, 6=TX in SQLite")
|
|
|
|
("rv64", "run RV64")
|
|
|
|
("config-file,c", po::value<std::string>()->default_value(""), "configuration file");
|
|
|
|
// clang-format on
|
2017-09-21 13:13:01 +02:00
|
|
|
po::variables_map vm;
|
|
|
|
try {
|
|
|
|
po::store(po::parse_command_line(argc, argv, desc), vm); // can throw
|
|
|
|
// --help option
|
2017-09-22 11:23:23 +02:00
|
|
|
if (vm.count("help")) {
|
2017-10-04 10:31:11 +02:00
|
|
|
std::cout << "DBT-RISE-RiscV simulator for RISC-V" << std::endl << desc << std::endl;
|
2017-09-21 13:13:01 +02:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
po::notify(vm); // throws on error, so do after help in case
|
2017-09-22 11:23:23 +02:00
|
|
|
// there are any problems
|
|
|
|
} catch (po::error &e) {
|
2017-09-21 13:13:01 +02:00
|
|
|
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
|
|
|
|
std::cerr << desc << std::endl;
|
|
|
|
return ERROR_IN_COMMAND_LINE;
|
|
|
|
}
|
2017-10-04 10:31:11 +02:00
|
|
|
if (vm.count("verbose")) {
|
|
|
|
auto l = logging::as_log_level(vm["verbose"].as<int>());
|
|
|
|
LOGGER(DEFAULT)::reporting_level() = l;
|
|
|
|
LOGGER(connection)::reporting_level() = l;
|
|
|
|
LOGGER(SystemC)::reporting_level() = l;
|
|
|
|
sysc::Logger<>::reporting_level() = l;
|
|
|
|
}
|
|
|
|
if (vm.count("log-file")) {
|
|
|
|
// configure the connection logger
|
|
|
|
auto f = fopen(vm["log-file"].as<std::string>().c_str(), "w");
|
|
|
|
LOG_OUTPUT(DEFAULT)::stream() = f;
|
|
|
|
LOG_OUTPUT(connection)::stream() = f;
|
|
|
|
LOG_OUTPUT(SystemC)::stream() = f;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// set up infrastructure
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
iss::init_jit(argc, argv);
|
2017-09-21 13:13:01 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// set up tracing & transaction recording
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2017-10-04 10:31:11 +02:00
|
|
|
sysc::tracer trace("simple_system", static_cast<sysc::tracer::file_type>(vm["trace"].as<uint8_t>() >> 1),
|
|
|
|
vm["trace"].as<uint8_t>() != 0);
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// set up configuration
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
sysc::configurer cfg(vm["config-file"].as<std::string>());
|
2017-09-21 13:13:01 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// instantiate top level
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
platform i_simple_system("i_simple_system");
|
2017-09-22 11:23:23 +02:00
|
|
|
// sr_report_handler::add_sc_object_to_filter(&i_simple_system.i_master,
|
|
|
|
// sc_core::SC_WARNING, sc_core::SC_MEDIUM);
|
2017-10-04 10:31:11 +02:00
|
|
|
// cfg.dump_hierarchy();
|
|
|
|
if (vm.count("elf")) cfg.set_value("i_simple_system.i_core_complex.elf_file", vm["elf"].as<std::string>());
|
|
|
|
if (vm.count("reset")) {
|
|
|
|
auto str = vm["reset"].as<std::string>();
|
|
|
|
uint64_t start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), 0, 16) : std::stoull(str, 0, 10);
|
|
|
|
cfg.set_value("i_simple_system.i_core_complex.reset_address", start_address);
|
|
|
|
}
|
|
|
|
if (vm.count("disass")) {
|
|
|
|
cfg.set_value("i_simple_system.i_core_complex.enable_disass", true);
|
|
|
|
LOGGER(disass)::reporting_level() = logging::INFO;
|
|
|
|
auto file_name = vm["disass"].as<std::string>();
|
|
|
|
if (file_name.length() > 0) {
|
|
|
|
LOG_OUTPUT(disass)::stream() = fopen(file_name.c_str(), "w");
|
|
|
|
LOGGER(disass)::print_time() = false;
|
|
|
|
LOGGER(disass)::print_severity() = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cfg.set_value("i_simple_system.i_core_complex.gdb_server_port", vm["gdb-port"].as<unsigned short>());
|
|
|
|
cfg.set_value("i_simple_system.i_core_complex.dump_ir", vm.count("dump-ir") != 0);
|
|
|
|
if (vm.count("quantum")) {
|
|
|
|
tlm::tlm_global_quantum::instance().set(sc_core::sc_time(vm["quantum"].as<unsigned>(), sc_core::SC_NS));
|
|
|
|
}
|
2017-09-21 13:13:01 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// run simulation
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2017-10-04 10:31:11 +02:00
|
|
|
sc_start();
|
2017-09-22 11:23:23 +02:00
|
|
|
if (!sc_end_of_simulation_invoked()) sc_stop();
|
2017-09-21 13:13:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|