diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/common/report_handler.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/tlm/examples/common/report_handler.cc Wed Nov 09 14:02:55 2016 +0100 @@ -0,0 +1,86 @@ +/* + * 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: Christian Menard + */ + +#include +#include + +#include + +#include "report_handler.hh" + +using namespace sc_core; + +void +reportHandler(const sc_report &report, const sc_actions &actions) +{ + uint64_t systemc_time = report.get_time().value(); + uint64_t gem5_time = curTick(); + + if (actions & SC_DO_NOTHING) + return; + + if (actions & SC_DISPLAY || actions & SC_LOG) + { + std::ostream& stream = actions & SC_DISPLAY ? std::cout : std::cerr; + + stream << report.get_time(); + + if (gem5_time < systemc_time) { + stream << " (<) "; + } else if (gem5_time > systemc_time) { + stream << " (!) "; + } else { + stream << " (=) "; + } + + stream << ": " << report.get_msg_type() + << ' ' << report.get_msg() << '\n'; + } + + if (actions & SC_THROW) { + std::cerr << "warning: the report handler ignored a SC_THROW action\n"; + } else if (actions & SC_INTERRUPT) { + std::cerr << "warning: the report handler ignored a SC_INTERRUPT" + << "action\n"; + } else if (actions & SC_CACHE_REPORT) { + std::cerr << "warning: the report handler ignored a SC_CACHE_REPORT" + << "action\n"; + } + + if (actions & SC_STOP) + sc_stop(); + + if (actions & SC_ABORT) + abort(); +} diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/master_port/SConstruct --- a/util/tlm/examples/master_port/SConstruct Wed Nov 09 14:01:46 2016 +0100 +++ b/util/tlm/examples/master_port/SConstruct Wed Nov 09 14:02:55 2016 +0100 @@ -32,6 +32,8 @@ # # Authors: Christian Menard +import os + gem5_arch = 'ARM' gem5_variant = 'opt' #gem5_variant = 'debug' @@ -41,6 +43,8 @@ target = 'gem5.' + gem5_variant + '.sc' env = Environment() +# Import PKG_CONFIG_PATH from the external environment +env['ENV']['PKG_CONFIG_PATH'] = os.environ['PKG_CONFIG_PATH'] # search for SystemC env.ParseConfig('pkg-config --cflags --libs systemc') @@ -48,7 +52,8 @@ # add include dirs env.Append(CPPPATH=[gem5_root + '/build/' + gem5_arch, gem5_root + '/util/systemc', - gem5_root + '/util/tlm']) + gem5_root + '/util/tlm', + '../common']) env.Append(LIBS=['gem5_' + gem5_variant]) env.Append(LIBPATH=[gem5_root + '/build/' + gem5_arch]) @@ -66,6 +71,6 @@ gem5_root + '/util/systemc/stats.cc'] src_tlm = Glob(gem5_root + '/util/tlm/*.cc') -src_main = Glob('*.cc') +src_main = Glob('*.cc') + Glob('../common/*.cc') main = env.Program(target, src_systemc + src_tlm + src_main) diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/master_port/main.cc --- a/util/tlm/examples/master_port/main.cc Wed Nov 09 14:01:46 2016 +0100 +++ b/util/tlm/examples/master_port/main.cc Wed Nov 09 14:02:55 2016 +0100 @@ -35,7 +35,9 @@ #include #include -#include "sc_master_port.hh" +#include "cli_parser.hh" +#include "gem5_master_transactor.hh" +#include "report_handler.hh" #include "sim_control.hh" #include "stats.hh" #include "traffic_generator.hh" @@ -43,48 +45,26 @@ // Defining global string variable decalred in stats.hh std::string filename; -void -reportHandler(const sc_core::sc_report& report, - const sc_core::sc_actions& actions) -{ - uint64_t systemc_time = report.get_time().value(); - uint64_t gem5_time = curTick(); - - std::cerr << report.get_time(); - - if (gem5_time < systemc_time) { - std::cerr << " (<) "; - } else if (gem5_time > systemc_time) { - std::cerr << " (!) "; - } else { - std::cerr << " (=) "; - } - - std::cerr << ": " << report.get_msg_type() << ' ' << report.get_msg() - << '\n'; -} - int sc_main(int argc, char** argv) { - sc_core::sc_report_handler::set_handler(reportHandler); - - SimControl simControl("gem5", argc, argv); - TrafficGenerator trafficGenerator("traffic_generator"); + CliParser parser; + parser.parse(argc, argv); filename = "m5out/stats-systemc.txt"; - tlm::tlm_target_socket<>* mem_port = - dynamic_cast*>( - sc_core::sc_find_object("gem5.memory")); + sc_core::sc_report_handler::set_handler(reportHandler); - if (mem_port) { - SC_REPORT_INFO("sc_main", "Port Found"); - trafficGenerator.socket.bind(*mem_port); - } else { - SC_REPORT_FATAL("sc_main", "Port Not Found"); - std::exit(EXIT_FAILURE); - } + // We need one instance of the Gem5SimControl. + Gem5SystemC::Gem5SimControl simControl("gem5", + parser.getConfigFile(), + parser.getSimulationEnd(), + parser.getDebugFlags()); + + TrafficGenerator trafficGenerator("traffic_generator"); + Gem5SystemC::Gem5MasterTransactor transactor("transactor", "transactor"); + + trafficGenerator.socket.bind(transactor.socket); std::cout << "Starting sc_main" << std::endl; diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/master_port/tlm.py --- a/util/tlm/examples/master_port/tlm.py Wed Nov 09 14:01:46 2016 +0100 +++ b/util/tlm/examples/master_port/tlm.py Wed Nov 09 14:02:55 2016 +0100 @@ -61,7 +61,7 @@ # Create a external TLM port: system.tlm = ExternalMaster() system.tlm.port_type = "tlm_master" -system.tlm.port_data = "memory" +system.tlm.port_data = "transactor" # Route the connections: system.system_port = system.membus.slave diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/common/cli_parser.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/tlm/examples/common/cli_parser.hh Wed Nov 09 14:02:55 2016 +0100 @@ -0,0 +1,70 @@ +/* + * 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: Christian Menard + */ + +#ifndef __CLI_PARSER_HH__ +#define __CLI_PARSER_HH__ + +#include +#include +#include + +class CliParser +{ + private: + int argc; + char** argv; + + bool parsed; + + uint64_t memoryOffset; + uint64_t simulationEnd; + bool verboseFlag; + std::vector debugFlags; + std::string configFile; + + void usage(const std::string& prog_name); + public: + + CliParser() : parsed(false) {} + + void parse(int argc, char** argv); + + uint64_t getMemoryOffset() { assert(parsed); return memoryOffset; } + uint64_t getSimulationEnd() { assert(parsed); return simulationEnd; } + bool getVerboseFlag() { assert(parsed); return verboseFlag; } + std::string getConfigFile() { assert(parsed); return configFile; } + std::string getDebugFlags(); +}; + +#endif diff -r 668120c36f3b -r 97644a2264f0 util/tlm/examples/common/cli_parser.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/tlm/examples/common/cli_parser.cc Wed Nov 09 14:02:55 2016 +0100 @@ -0,0 +1,126 @@ +/* + * 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: Christian Menard + */ + +#include +#include + +#include "cli_parser.hh" +#include "sim/cxx_manager.hh" + +void +CliParser::usage(const std::string& prog_name) +{ + std::cerr + << "Usage: " << prog_name + << (" [