diff options
author | Christian Menard <Christian.Menard@tu-dresden.de> | 2017-02-09 19:15:30 -0500 |
---|---|---|
committer | Christian Menard <Christian.Menard@tu-dresden.de> | 2017-02-09 19:15:30 -0500 |
commit | b25ea094d4350b8257d5f383a123ea620b614adf (patch) | |
tree | bf2be24b719fb45325012542bb77288f18ccb66e /util/tlm/sim_control.cc | |
parent | 41a61589545c284d109019c3cb528762b8345aa0 (diff) | |
download | gem5-b25ea094d4350b8257d5f383a123ea620b614adf.tar.xz |
misc: Clean up and complete the gem5<->SystemC-TLM bridge [1/10]
The current TLM bridge only provides a Slave Port that allows the gem5
world to send request to the SystemC world. This patch series refractors
and cleans up the existing code, and adds a Master Port that allows the
SystemC world to send requests to the gem5 world.
This patch:
* Restructure the existing sources in preparation of the addition of the
* new
Master Port.
* Refractor names to allow for distinction of the slave and master port.
* Replace the Makefile by a SConstruct.
Testing Done: The examples provided in util/tlm (now
util/tlm/examples/slave_port) still compile and run error free.
Reviewed at http://reviews.gem5.org/r/3527/
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'util/tlm/sim_control.cc')
-rw-r--r-- | util/tlm/sim_control.cc | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/util/tlm/sim_control.cc b/util/tlm/sim_control.cc new file mode 100644 index 000000000..ef04c6bbd --- /dev/null +++ b/util/tlm/sim_control.cc @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2015, University of Kaiserslautern + * Copyright (c) 2016, Dresden University of Technology (TU Dresden) + * 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 + * Abdul Mutaal Ahmad + * Christian Menard + */ + +/** + * @file + * + * Example top level file for SystemC-TLM integration with C++-only + * instantiation. + * + */ + +#include <systemc> +#include <tlm> + +#include "sc_slave_port.hh" +#include "sim/cxx_config_ini.hh" +#include "sim/init_signals.hh" +#include "sim/stat_control.hh" +#include "sim_control.hh" +#include "stats.hh" + +void +usage(const std::string& prog_name) +{ + 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"); + std::exit(EXIT_FAILURE); +} + +SimControl::SimControl(sc_core::sc_module_name name, int argc_, char** argv_) + : Gem5SystemC::Module(name), + argc(argc_), + argv(argv_) +{ + SC_THREAD(run); + + std::string prog_name(argv[0]); + unsigned int arg_ptr = 1; + + if (argc == 1) { + usage(prog_name); + } + + cxxConfigInit(); + Gem5SystemC::SCSlavePort::registerPortHandler(); + + 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); + + Trace::enable(); + + 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; + + if (sim_end == 0) { + 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 +} |