2015-08-04 06:08:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, University of Kaiserslautern
|
2017-02-10 01:15:30 +01:00
|
|
|
* Copyright (c) 2016, Dresden University of Technology (TU Dresden)
|
2015-08-04 06:08:40 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Matthias Jung
|
2016-07-01 16:30:15 +02:00
|
|
|
* Abdul Mutaal Ahmad
|
2017-02-10 01:15:30 +01:00
|
|
|
* Christian Menard
|
2015-08-04 06:08:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Example top level file for SystemC-TLM integration with C++-only
|
|
|
|
* instantiation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <systemc>
|
|
|
|
#include <tlm>
|
|
|
|
|
2017-02-10 01:15:33 +01:00
|
|
|
#include "sc_master_port.hh"
|
2017-02-10 01:15:30 +01:00
|
|
|
#include "sc_slave_port.hh"
|
2015-08-04 06:08:40 +02:00
|
|
|
#include "sim/cxx_config_ini.hh"
|
|
|
|
#include "sim/init_signals.hh"
|
|
|
|
#include "sim/stat_control.hh"
|
2017-02-10 01:15:30 +01:00
|
|
|
#include "sim_control.hh"
|
2015-08-04 06:08:40 +02:00
|
|
|
#include "stats.hh"
|
|
|
|
|
2017-02-10 01:15:30 +01:00
|
|
|
void
|
|
|
|
usage(const std::string& prog_name)
|
2015-08-04 06:08:40 +02:00
|
|
|
{
|
2017-02-10 01:15:30 +01:00
|
|
|
std::cerr
|
|
|
|
<< "Usage: " << prog_name
|
|
|
|
<< (" <config_file.ini> [ <option> ]\n\n"
|
|
|
|
"OPTIONS:\n"
|
|
|
|
|
|
|
|
" -o <offset> -- set memory offset\n"
|
|
|
|
" -p <object> <param> <value> -- set a parameter\n"
|
|
|
|
" -v <object> <param> <values> -- set a vector parameter from a\n"
|
|
|
|
" comma separated values string\n"
|
|
|
|
" -d <flag> -- set a debug flag\n"
|
|
|
|
" (-<flag> clear a flag)\n"
|
|
|
|
" -D -- debug on\n"
|
|
|
|
" -e <ticks> -- end of simulation after a \n"
|
|
|
|
" given number of ticks\n"
|
|
|
|
"\n");
|
2015-08-04 06:08:40 +02:00
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-02-10 01:15:30 +01:00
|
|
|
SimControl::SimControl(sc_core::sc_module_name name, int argc_, char** argv_)
|
|
|
|
: Gem5SystemC::Module(name),
|
|
|
|
argc(argc_),
|
|
|
|
argv(argv_)
|
2015-08-04 06:08:40 +02:00
|
|
|
{
|
|
|
|
SC_THREAD(run);
|
|
|
|
|
|
|
|
std::string prog_name(argv[0]);
|
|
|
|
unsigned int arg_ptr = 1;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
cxxConfigInit();
|
2017-02-10 01:15:30 +01:00
|
|
|
Gem5SystemC::SCSlavePort::registerPortHandler();
|
2017-02-10 01:15:33 +01:00
|
|
|
Gem5SystemC::SCMasterPort::registerPortHandler(*this);
|
2015-08-04 06:08:40 +02:00
|
|
|
|
|
|
|
Trace::setDebugLogger(&logger);
|
|
|
|
|
|
|
|
Gem5SystemC::setTickFrequency();
|
|
|
|
sc_core::sc_set_time_resolution(1, sc_core::SC_PS);
|
|
|
|
|
|
|
|
Gem5SystemC::Module::setupEventQueues(*this);
|
|
|
|
initSignals();
|
|
|
|
|
|
|
|
Stats::initSimStats();
|
|
|
|
Stats::registerHandlers(CxxConfig::statsReset, CxxConfig::statsDump);
|
|
|
|
|
2015-09-30 22:21:55 +02:00
|
|
|
Trace::enable();
|
2015-08-04 06:08:40 +02:00
|
|
|
|
|
|
|
sim_end = 0;
|
|
|
|
debug = false;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
const std::string config_file(argv[arg_ptr]);
|
|
|
|
|
|
|
|
CxxConfigFileBase *conf = new CxxIniFile();
|
|
|
|
|
|
|
|
if (!conf->load(config_file.c_str())) {
|
|
|
|
std::cerr << "Can't open config file: " << config_file << '\n';
|
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
arg_ptr++;
|
|
|
|
|
|
|
|
config_manager = new CxxConfigManager(*conf);
|
|
|
|
|
|
|
|
try {
|
|
|
|
while (arg_ptr < argc) {
|
|
|
|
std::string option(argv[arg_ptr]);
|
|
|
|
arg_ptr++;
|
|
|
|
unsigned num_args = argc - arg_ptr;
|
|
|
|
|
|
|
|
if (option == "-p") {
|
|
|
|
if (num_args < 3) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
config_manager->setParam(argv[arg_ptr], argv[arg_ptr + 1],
|
|
|
|
argv[arg_ptr + 2]);
|
|
|
|
arg_ptr += 3;
|
|
|
|
} else if (option == "-v") {
|
|
|
|
std::vector<std::string> values;
|
|
|
|
|
|
|
|
if (num_args < 3) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
tokenize(values, argv[2], ',');
|
|
|
|
config_manager->setParamVector(argv[arg_ptr],
|
|
|
|
argv[arg_ptr],
|
|
|
|
values);
|
|
|
|
arg_ptr += 3;
|
|
|
|
} else if (option == "-d") {
|
|
|
|
if (num_args < 1) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
if (argv[arg_ptr][0] == '-') {
|
|
|
|
clearDebugFlag(argv[arg_ptr] + 1);
|
|
|
|
} else {
|
|
|
|
setDebugFlag(argv[arg_ptr]);
|
|
|
|
}
|
|
|
|
arg_ptr++;
|
|
|
|
} else if (option == "-e") {
|
|
|
|
if (num_args < 1) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
std::istringstream(argv[arg_ptr]) >> sim_end;
|
|
|
|
arg_ptr++;
|
|
|
|
} else if (option == "-D") {
|
|
|
|
debug = true;
|
|
|
|
} else if (option == "-o") {
|
|
|
|
if (num_args < 1) {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
std::istringstream(argv[arg_ptr]) >> offset;
|
|
|
|
arg_ptr++;
|
|
|
|
/* code */
|
|
|
|
} else {
|
|
|
|
usage(prog_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (CxxConfigManager::Exception &e) {
|
|
|
|
std::cerr << e.name << ": " << e.message << "\n";
|
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CxxConfig::statsEnable();
|
|
|
|
getEventQueue(0)->dump();
|
|
|
|
|
|
|
|
try {
|
|
|
|
config_manager->instantiate();
|
|
|
|
} catch (CxxConfigManager::Exception &e) {
|
|
|
|
std::cerr << "Config problem in sim object "
|
|
|
|
<< e.name << ": " << e.message << "\n";
|
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SimControl::before_end_of_elaboration()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
config_manager->initState();
|
|
|
|
config_manager->startup();
|
|
|
|
} catch (CxxConfigManager::Exception &e) {
|
|
|
|
std::cerr << "Config problem in sim object "
|
|
|
|
<< e.name << ": " << e.message << "\n";
|
|
|
|
std::exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SimControl::run()
|
|
|
|
{
|
|
|
|
GlobalSimLoopExitEvent *exit_event = NULL;
|
|
|
|
|
2016-02-07 02:21:19 +01:00
|
|
|
if (sim_end == 0) {
|
2015-08-04 06:08:40 +02:00
|
|
|
exit_event = simulate();
|
|
|
|
} else {
|
|
|
|
exit_event = simulate(sim_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Exit at tick " << curTick()
|
|
|
|
<< ", cause: " << exit_event->getCause() << '\n';
|
|
|
|
|
|
|
|
getEventQueue(0)->dump();
|
|
|
|
|
|
|
|
#if TRY_CLEAN_DELETE
|
|
|
|
config_manager->deleteObjects();
|
|
|
|
#endif
|
|
|
|
}
|