113372Sgabeblack@google.com/* 213372Sgabeblack@google.com * Copyright (c) 2014 ARM Limited 313372Sgabeblack@google.com * All rights reserved 413372Sgabeblack@google.com * 513372Sgabeblack@google.com * The license below extends only to copyright in the software and shall 613372Sgabeblack@google.com * not be construed as granting a license to any other intellectual 713372Sgabeblack@google.com * property including but not limited to intellectual property relating 813372Sgabeblack@google.com * to a hardware implementation of the functionality of the software 913372Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1013372Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1113372Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1213372Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1313372Sgabeblack@google.com * 1413372Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1513372Sgabeblack@google.com * modification, are permitted provided that the following conditions are 1613372Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 1713372Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1813372Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1913372Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2013372Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2113372Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2213372Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2313372Sgabeblack@google.com * this software without specific prior written permission. 2413372Sgabeblack@google.com * 2513372Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2613372Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2713372Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2813372Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2913372Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3013372Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3113372Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3213372Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3313372Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3413372Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3513372Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3613372Sgabeblack@google.com * 3713372Sgabeblack@google.com * Authors: Andrew Bardsley 3813372Sgabeblack@google.com */ 3913372Sgabeblack@google.com 4013372Sgabeblack@google.com/** 4113372Sgabeblack@google.com * @file 4213372Sgabeblack@google.com * 4313372Sgabeblack@google.com * Top level definitions for exporting gem5 across a dlopen interface. 4413372Sgabeblack@google.com * 4513372Sgabeblack@google.com * Gem5Control should be instantiated once to build the gem5 root. 4613372Sgabeblack@google.com * Systems from that root's config file can then be instantiated as 4713372Sgabeblack@google.com * Gem5System's using Gem5Control::makeSystem. 4813372Sgabeblack@google.com * 4913372Sgabeblack@google.com * Gem5Control contains a Gem5TopLevelModule which is a SystemC 5013372Sgabeblack@google.com * module providing the gem5 `simulate' function as its sole 5113372Sgabeblack@google.com * thread action. 5213372Sgabeblack@google.com */ 5313372Sgabeblack@google.com 5413372Sgabeblack@google.com#ifndef __SIM_SC_GEM5_CONTROL_HH__ 5513372Sgabeblack@google.com#define __SIM_SC_GEM5_CONTROL_HH__ 5613372Sgabeblack@google.com 5713372Sgabeblack@google.com#include <string> 5813372Sgabeblack@google.com#include <vector> 5913372Sgabeblack@google.com 6013372Sgabeblack@google.comclass CxxConfigManager; 6113372Sgabeblack@google.com 6213372Sgabeblack@google.comnamespace Gem5SystemC 6313372Sgabeblack@google.com{ 6413372Sgabeblack@google.com 6513372Sgabeblack@google.comclass Gem5TopLevelModule; 6613372Sgabeblack@google.comclass Gem5Control; 6713372Sgabeblack@google.com 6813372Sgabeblack@google.com/** Gem5System's wrap CxxConfigManager's instantiating a gem5 System 6913372Sgabeblack@google.com * object (and its children). New Gem5Systems are created by 7013372Sgabeblack@google.com * Gem5Control::makeSystem. A new system can have its parameters 7113372Sgabeblack@google.com * tweaked using setParam{,Vector} before being instantiated using 7213372Sgabeblack@google.com * Gem5System::instantiate. After instantiation, any external ports 7313372Sgabeblack@google.com * declared by the system should be visible in SystemC. 7413372Sgabeblack@google.com * 7513372Sgabeblack@google.com * It is recommended that a SystemC wrapper sc_module is declared to 7613372Sgabeblack@google.com * own each Gem5System with the call to Gem5System::instantiate being 7713372Sgabeblack@google.com * made in that wrapper's constructor 7813372Sgabeblack@google.com * 7913372Sgabeblack@google.com * Note that *every* `normal' member function in this class *must* 8013372Sgabeblack@google.com * be virtual to ensure that references to the functions go through 8113372Sgabeblack@google.com * the pointer acquired using makeSystem and not looked up as 8213372Sgabeblack@google.com * name-mangled symbols 8313372Sgabeblack@google.com * 8413372Sgabeblack@google.com * */ 8513372Sgabeblack@google.comclass Gem5System 8613372Sgabeblack@google.com{ 8713372Sgabeblack@google.com private: 8813372Sgabeblack@google.com /** Config management for *just* this system's objects (notably 8913372Sgabeblack@google.com * excluding root */ 9013372Sgabeblack@google.com CxxConfigManager *manager; 9113372Sgabeblack@google.com 9213372Sgabeblack@google.com /** The config file prototype for the system */ 9313372Sgabeblack@google.com std::string systemName; 9413372Sgabeblack@google.com 9513372Sgabeblack@google.com /** The instantiated (in gem5) name of the system */ 9613372Sgabeblack@google.com std::string instanceName; 9713372Sgabeblack@google.com 9813372Sgabeblack@google.com public: 9913372Sgabeblack@google.com /** A constructor only used by Gem5Control */ 10013372Sgabeblack@google.com Gem5System(CxxConfigManager *manager_, 10113372Sgabeblack@google.com const std::string &system_name, const std::string &instance_name); 10213372Sgabeblack@google.com 10313372Sgabeblack@google.com virtual ~Gem5System(); 10413372Sgabeblack@google.com 10513372Sgabeblack@google.com /** Parameter setting functions callable before instantiate */ 10613372Sgabeblack@google.com virtual void setParam(const std::string &object, 10713372Sgabeblack@google.com const std::string ¶m_name, const std::string ¶m_value); 10813372Sgabeblack@google.com 10913372Sgabeblack@google.com virtual void setParamVector(const std::string &system_name, 11013372Sgabeblack@google.com const std::string ¶m_name, 11113372Sgabeblack@google.com const std::vector<std::string> ¶m_values); 11213372Sgabeblack@google.com 11313372Sgabeblack@google.com /** Build the system's gem5 infrastructure, bind its ports (note 11413372Sgabeblack@google.com * that all ports *must* be internal to the system), init and 11513372Sgabeblack@google.com * SimObject::startup the system */ 11613372Sgabeblack@google.com virtual void instantiate(); 11713372Sgabeblack@google.com}; 11813372Sgabeblack@google.com 11913372Sgabeblack@google.com/** Singleton class containing gem5 simulation control. 12013372Sgabeblack@google.com * 12113372Sgabeblack@google.com * Note that *every* `normal' member function in this class *must* 12213372Sgabeblack@google.com * be virtual to ensure that references to the functions go through 12313372Sgabeblack@google.com * the pointer acquired using makeGem5Control and not looked up as 12413372Sgabeblack@google.com * name-mangled symbols 12513372Sgabeblack@google.com */ 12613372Sgabeblack@google.comclass Gem5Control 12713372Sgabeblack@google.com{ 12813372Sgabeblack@google.com private: 12913372Sgabeblack@google.com /** Private SystemC module containing top level simulation control */ 13013372Sgabeblack@google.com Gem5TopLevelModule *module; 13113372Sgabeblack@google.com 13213372Sgabeblack@google.com /** One-time-settable version string */ 13313372Sgabeblack@google.com std::string version; 13413372Sgabeblack@google.com 13513372Sgabeblack@google.com public: 13613372Sgabeblack@google.com Gem5Control(const std::string &config_filename); 13713372Sgabeblack@google.com 13813372Sgabeblack@google.com virtual ~Gem5Control(); 13913372Sgabeblack@google.com 14013372Sgabeblack@google.com /** Set/clear a gem5 debug flag */ 14113372Sgabeblack@google.com virtual void setDebugFlag(const char *flag); 14213372Sgabeblack@google.com virtual void clearDebugFlag(const char *flag); 14313372Sgabeblack@google.com 14413372Sgabeblack@google.com /** Choose a base port number for GDB to connect to the model 14513372Sgabeblack@google.com * (0 disables connections) */ 14613372Sgabeblack@google.com virtual void setRemoteGDBPort(unsigned int port); 14713372Sgabeblack@google.com 14813372Sgabeblack@google.com /* Register an action to happen at the end of elaboration */ 14913372Sgabeblack@google.com virtual void registerEndOfElaboration(void (*func)()); 15013372Sgabeblack@google.com 15113372Sgabeblack@google.com /** Make a System from the config file description for system 15213372Sgabeblack@google.com * system_name and call it instance_name in gem5 */ 15313372Sgabeblack@google.com virtual Gem5System *makeSystem(const std::string &system_name, 15413372Sgabeblack@google.com const std::string &top_instance); 15513372Sgabeblack@google.com 15613372Sgabeblack@google.com /** set/get version string */ 15713372Sgabeblack@google.com virtual const std::string &getVersion() const; 15813372Sgabeblack@google.com virtual void setVersion(const std::string &new_version); 15913372Sgabeblack@google.com}; 16013372Sgabeblack@google.com 16113372Sgabeblack@google.com} 16213372Sgabeblack@google.com 16313372Sgabeblack@google.com/** Instantiate a Gem5Control. This can be called using dlopen/dlsym 16413372Sgabeblack@google.com * to kick-start gem5 */ 16513372Sgabeblack@google.comextern "C" Gem5SystemC::Gem5Control *makeGem5Control( 16613372Sgabeblack@google.com const std::string &config_filename); 16713372Sgabeblack@google.com 16813372Sgabeblack@google.com#endif // __SIM_SC_GEM5_CONTROL_HH__ 169