2 * Copyright (c) 2015, University of Kaiserslautern
3 * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Authors: Matthias Jung
41 * Example top level file for SystemC-TLM integration with C++-only
49 #include "sc_master_port.hh"
50 #include "sc_slave_port.hh"
51 #include "sim/cxx_config_ini.hh"
52 #include "sim/init_signals.hh"
53 #include "sim/stat_control.hh"
54 #include "sim_control.hh"
58 usage(const std::string
& prog_name
)
61 << "Usage: " << prog_name
62 << (" <config_file.ini> [ <option> ]\n\n"
65 " -o <offset> -- set memory offset\n"
66 " -p <object> <param> <value> -- set a parameter\n"
67 " -v <object> <param> <values> -- set a vector parameter from a\n"
68 " comma separated values string\n"
69 " -d <flag> -- set a debug flag\n"
70 " (-<flag> clear a flag)\n"
72 " -e <ticks> -- end of simulation after a \n"
73 " given number of ticks\n"
75 std::exit(EXIT_FAILURE
);
78 SimControl::SimControl(sc_core::sc_module_name name
, int argc_
, char** argv_
)
79 : Gem5SystemC::Module(name
),
85 std::string
prog_name(argv
[0]);
86 unsigned int arg_ptr
= 1;
93 Gem5SystemC::SCSlavePort::registerPortHandler();
94 Gem5SystemC::SCMasterPort::registerPortHandler(*this);
96 Trace::setDebugLogger(&logger
);
98 Gem5SystemC::setTickFrequency();
99 sc_core::sc_set_time_resolution(1, sc_core::SC_PS
);
101 Gem5SystemC::Module::setupEventQueues(*this);
104 Stats::initSimStats();
105 Stats::registerHandlers(CxxConfig::statsReset
, CxxConfig::statsDump
);
113 const std::string
config_file(argv
[arg_ptr
]);
115 CxxConfigFileBase
*conf
= new CxxIniFile();
117 if (!conf
->load(config_file
.c_str())) {
118 std::cerr
<< "Can't open config file: " << config_file
<< '\n';
119 std::exit(EXIT_FAILURE
);
123 config_manager
= new CxxConfigManager(*conf
);
126 while (arg_ptr
< argc
) {
127 std::string
option(argv
[arg_ptr
]);
129 unsigned num_args
= argc
- arg_ptr
;
131 if (option
== "-p") {
136 config_manager
->setParam(argv
[arg_ptr
], argv
[arg_ptr
+ 1],
139 } else if (option
== "-v") {
140 std::vector
<std::string
> values
;
145 tokenize(values
, argv
[2], ',');
146 config_manager
->setParamVector(argv
[arg_ptr
],
150 } else if (option
== "-d") {
154 if (argv
[arg_ptr
][0] == '-') {
155 clearDebugFlag(argv
[arg_ptr
] + 1);
157 setDebugFlag(argv
[arg_ptr
]);
160 } else if (option
== "-e") {
164 std::istringstream(argv
[arg_ptr
]) >> sim_end
;
166 } else if (option
== "-D") {
168 } else if (option
== "-o") {
172 std::istringstream(argv
[arg_ptr
]) >> offset
;
179 } catch (CxxConfigManager::Exception
&e
) {
180 std::cerr
<< e
.name
<< ": " << e
.message
<< "\n";
181 std::exit(EXIT_FAILURE
);
184 CxxConfig::statsEnable();
185 getEventQueue(0)->dump();
188 config_manager
->instantiate();
189 } catch (CxxConfigManager::Exception
&e
) {
190 std::cerr
<< "Config problem in sim object "
191 << e
.name
<< ": " << e
.message
<< "\n";
192 std::exit(EXIT_FAILURE
);
197 SimControl::before_end_of_elaboration()
200 config_manager
->initState();
201 config_manager
->startup();
202 } catch (CxxConfigManager::Exception
&e
) {
203 std::cerr
<< "Config problem in sim object "
204 << e
.name
<< ": " << e
.message
<< "\n";
205 std::exit(EXIT_FAILURE
);
212 GlobalSimLoopExitEvent
*exit_event
= NULL
;
215 exit_event
= simulate();
217 exit_event
= simulate(sim_end
);
220 std::cerr
<< "Exit at tick " << curTick()
221 << ", cause: " << exit_event
->getCause() << '\n';
223 getEventQueue(0)->dump();
226 config_manager
->deleteObjects();