112047Schristian.menard@tu-dresden.de/*
212047Schristian.menard@tu-dresden.de * Copyright (c) 2015, University of Kaiserslautern
312047Schristian.menard@tu-dresden.de * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
412047Schristian.menard@tu-dresden.de * All rights reserved.
512047Schristian.menard@tu-dresden.de *
612047Schristian.menard@tu-dresden.de * Redistribution and use in source and binary forms, with or without
712047Schristian.menard@tu-dresden.de * modification, are permitted provided that the following conditions are
812047Schristian.menard@tu-dresden.de * met:
912047Schristian.menard@tu-dresden.de *
1012047Schristian.menard@tu-dresden.de * 1. Redistributions of source code must retain the above copyright notice,
1112047Schristian.menard@tu-dresden.de *    this list of conditions and the following disclaimer.
1212047Schristian.menard@tu-dresden.de *
1312047Schristian.menard@tu-dresden.de * 2. Redistributions in binary form must reproduce the above copyright
1412047Schristian.menard@tu-dresden.de *    notice, this list of conditions and the following disclaimer in the
1512047Schristian.menard@tu-dresden.de *    documentation and/or other materials provided with the distribution.
1612047Schristian.menard@tu-dresden.de *
1712047Schristian.menard@tu-dresden.de * 3. Neither the name of the copyright holder nor the names of its
1812047Schristian.menard@tu-dresden.de *    contributors may be used to endorse or promote products derived from
1912047Schristian.menard@tu-dresden.de *    this software without specific prior written permission.
2012047Schristian.menard@tu-dresden.de *
2112047Schristian.menard@tu-dresden.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2212047Schristian.menard@tu-dresden.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2312047Schristian.menard@tu-dresden.de * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2412047Schristian.menard@tu-dresden.de * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
2512047Schristian.menard@tu-dresden.de * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2612047Schristian.menard@tu-dresden.de * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2712047Schristian.menard@tu-dresden.de * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2812047Schristian.menard@tu-dresden.de * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2912047Schristian.menard@tu-dresden.de * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3012047Schristian.menard@tu-dresden.de * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3112047Schristian.menard@tu-dresden.de * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3212047Schristian.menard@tu-dresden.de *
3312047Schristian.menard@tu-dresden.de * Authors: Matthias Jung
3412047Schristian.menard@tu-dresden.de *          Christian Menard
3512047Schristian.menard@tu-dresden.de */
3612047Schristian.menard@tu-dresden.de
3712047Schristian.menard@tu-dresden.de#ifndef __SC_SIM_CONTROL_HH__
3812047Schristian.menard@tu-dresden.de#define __SC_SIM_CONTROL_HH__
3912047Schristian.menard@tu-dresden.de
4012047Schristian.menard@tu-dresden.de#include <tlm_utils/simple_target_socket.h>
4112047Schristian.menard@tu-dresden.de
4212047Schristian.menard@tu-dresden.de#include <systemc>
4312047Schristian.menard@tu-dresden.de#include <tlm>
4412047Schristian.menard@tu-dresden.de
4512047Schristian.menard@tu-dresden.de#include "sc_logger.hh"
4612047Schristian.menard@tu-dresden.de#include "sc_module.hh"
4712047Schristian.menard@tu-dresden.de#include "sim/cxx_manager.hh"
4812047Schristian.menard@tu-dresden.de#include "sim/system.hh"
4912047Schristian.menard@tu-dresden.de#include "sim_control_if.hh"
5012047Schristian.menard@tu-dresden.de
5112047Schristian.menard@tu-dresden.denamespace Gem5SystemC
5212047Schristian.menard@tu-dresden.de{
5312047Schristian.menard@tu-dresden.de
5412047Schristian.menard@tu-dresden.de/**
5512047Schristian.menard@tu-dresden.de * This is the central SystemC module that orchestrates the gem5 simulation.
5612047Schristian.menard@tu-dresden.de *
5712047Schristian.menard@tu-dresden.de * The module is responsible for loading the configuration file, setting up and
5812047Schristian.menard@tu-dresden.de * maintaining the event queues, as well as starting and ending the simulation.
5912047Schristian.menard@tu-dresden.de * While it is mandatory to have one instance of this class for running a gem5
6012047Schristian.menard@tu-dresden.de * simulation in SystemC, it is not allowed to have multiple instances!
6112047Schristian.menard@tu-dresden.de */
6212047Schristian.menard@tu-dresden.declass Gem5SimControl : public Module, public Gem5SimControlInterface
6312047Schristian.menard@tu-dresden.de{
6412047Schristian.menard@tu-dresden.de  protected:
6512047Schristian.menard@tu-dresden.de    CxxConfigManager* config_manager;
6612047Schristian.menard@tu-dresden.de    Gem5SystemC::Logger logger;
6712047Schristian.menard@tu-dresden.de
6812047Schristian.menard@tu-dresden.de    Tick simulationEnd;
6912047Schristian.menard@tu-dresden.de
7012047Schristian.menard@tu-dresden.de    /*
7112047Schristian.menard@tu-dresden.de     * Keep track of the slave and master ports that are created by gem5
7212047Schristian.menard@tu-dresden.de     * according to the config file.
7312047Schristian.menard@tu-dresden.de     */
7412047Schristian.menard@tu-dresden.de    std::map<const std::string, SCSlavePort*> slavePorts;
7512047Schristian.menard@tu-dresden.de    std::map<const std::string, SCMasterPort*> masterPorts;
7612047Schristian.menard@tu-dresden.de
7712047Schristian.menard@tu-dresden.de    /// Pointer to a previously created instance.
7812047Schristian.menard@tu-dresden.de    static Gem5SimControl* instance;
7912047Schristian.menard@tu-dresden.de
8012047Schristian.menard@tu-dresden.de    /** A callback that is called from the run thread before gem5 simulation is
8112047Schristian.menard@tu-dresden.de     * started.
8212047Schristian.menard@tu-dresden.de     *
8312047Schristian.menard@tu-dresden.de     * A derived class may use this to perform any additional initializations
8412047Schristian.menard@tu-dresden.de     * prior simulation.
8512047Schristian.menard@tu-dresden.de     */
8612047Schristian.menard@tu-dresden.de    virtual void beforeSimulate() {}
8712047Schristian.menard@tu-dresden.de
8812047Schristian.menard@tu-dresden.de    /** A callback that is called from the run thread after gem5 simulation
8912047Schristian.menard@tu-dresden.de     * completed.
9012047Schristian.menard@tu-dresden.de     *
9112047Schristian.menard@tu-dresden.de     * A derived class may use this to perform any additional tasks after gem5
9212047Schristian.menard@tu-dresden.de     * exits. For instance, a derived class could use this to call sc_stop().
9312047Schristian.menard@tu-dresden.de     */
9412047Schristian.menard@tu-dresden.de    virtual void afterSimulate() {}
9512047Schristian.menard@tu-dresden.de
9612047Schristian.menard@tu-dresden.de  public:
9712047Schristian.menard@tu-dresden.de    SC_HAS_PROCESS(Gem5SimControl);
9812047Schristian.menard@tu-dresden.de
9912047Schristian.menard@tu-dresden.de    /**
10012047Schristian.menard@tu-dresden.de     * Constructor.
10112047Schristian.menard@tu-dresden.de     *
10212047Schristian.menard@tu-dresden.de     * This class has a public constructor although the class is actually a
10312047Schristian.menard@tu-dresden.de     * singleton. The public constructor is required to ensure compatibility
10412047Schristian.menard@tu-dresden.de     * to external SystemC based tools. For the same reason, the constructor
10512047Schristian.menard@tu-dresden.de     * parameters are basic types (int, string).
10612047Schristian.menard@tu-dresden.de     *
10712047Schristian.menard@tu-dresden.de     * @param configFile     location of the gem5 configuration file
10812047Schristian.menard@tu-dresden.de     * @param simulationEnd  number of ticks to simulate
10912047Schristian.menard@tu-dresden.de     * @param gem5DebugFlags a space separated list of gem5 debug flags to be
11012047Schristian.menard@tu-dresden.de     *                       set, a prepended '-' clears the flag
11112047Schristian.menard@tu-dresden.de     */
11212047Schristian.menard@tu-dresden.de    Gem5SimControl(sc_core::sc_module_name name,
11312047Schristian.menard@tu-dresden.de                   const std::string& configFile,
11412047Schristian.menard@tu-dresden.de                   uint64_t simulationEnd,
11512047Schristian.menard@tu-dresden.de                   const std::string& gem5DebugFlags);
11612047Schristian.menard@tu-dresden.de
11712047Schristian.menard@tu-dresden.de    void registerSlavePort(const std::string& name, SCSlavePort* port);
11812047Schristian.menard@tu-dresden.de    void registerMasterPort(const std::string& name, SCMasterPort* port);
11912047Schristian.menard@tu-dresden.de    SCSlavePort* getSlavePort(const std::string& name) override;
12012047Schristian.menard@tu-dresden.de    SCMasterPort* getMasterPort(const std::string& name) override;
12112047Schristian.menard@tu-dresden.de
12212047Schristian.menard@tu-dresden.de    void end_of_elaboration();
12312047Schristian.menard@tu-dresden.de
12412047Schristian.menard@tu-dresden.de    void run();
12512047Schristian.menard@tu-dresden.de};
12612047Schristian.menard@tu-dresden.de
12712047Schristian.menard@tu-dresden.de}
12812047Schristian.menard@tu-dresden.de
12912047Schristian.menard@tu-dresden.de#endif
130