sc_gem5_control.hh revision 13372:28982dc45b17
16657Snate@binkert.org/* 26657Snate@binkert.org * Copyright (c) 2014 ARM Limited 310972Sdavid.hashe@amd.com * All rights reserved 46657Snate@binkert.org * 56657Snate@binkert.org * The license below extends only to copyright in the software and shall 66657Snate@binkert.org * not be construed as granting a license to any other intellectual 76657Snate@binkert.org * property including but not limited to intellectual property relating 86657Snate@binkert.org * to a hardware implementation of the functionality of the software 96657Snate@binkert.org * licensed hereunder. You may use the software subject to the license 106657Snate@binkert.org * terms below provided that you ensure that this notice is replicated 116657Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 126657Snate@binkert.org * modified or unmodified, in source code or in binary form. 136657Snate@binkert.org * 146657Snate@binkert.org * Redistribution and use in source and binary forms, with or without 156657Snate@binkert.org * modification, are permitted provided that the following conditions are 166657Snate@binkert.org * met: redistributions of source code must retain the above copyright 176657Snate@binkert.org * notice, this list of conditions and the following disclaimer; 186657Snate@binkert.org * redistributions in binary form must reproduce the above copyright 196657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 206657Snate@binkert.org * documentation and/or other materials provided with the distribution; 216657Snate@binkert.org * neither the name of the copyright holders nor the names of its 226657Snate@binkert.org * contributors may be used to endorse or promote products derived from 236657Snate@binkert.org * this software without specific prior written permission. 246657Snate@binkert.org * 256657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 266657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 276657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 286657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 296999Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 306657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 316657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 326657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 336657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 348189SLisa.Hsu@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 356657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 369499Snilay@cs.wisc.edu * 379499Snilay@cs.wisc.edu * Authors: Andrew Bardsley 3811308Santhony.gutierrez@amd.com */ 399364Snilay@cs.wisc.edu 407055Snate@binkert.org/** 416882SBrad.Beckmann@amd.com * @file 426882SBrad.Beckmann@amd.com * 438191SLisa.Hsu@amd.com * Top level definitions for exporting gem5 across a dlopen interface. 446882SBrad.Beckmann@amd.com * 4511308Santhony.gutierrez@amd.com * Gem5Control should be instantiated once to build the gem5 root. 4611308Santhony.gutierrez@amd.com * Systems from that root's config file can then be instantiated as 476882SBrad.Beckmann@amd.com * Gem5System's using Gem5Control::makeSystem. 4811308Santhony.gutierrez@amd.com * 499102SNuwan.Jayasena@amd.com * Gem5Control contains a Gem5TopLevelModule which is a SystemC 5011084Snilay@cs.wisc.edu * module providing the gem5 `simulate' function as its sole 519366Snilay@cs.wisc.edu * thread action. 529499Snilay@cs.wisc.edu */ 539499Snilay@cs.wisc.edu 549499Snilay@cs.wisc.edu#ifndef __SIM_SC_GEM5_CONTROL_HH__ 556882SBrad.Beckmann@amd.com#define __SIM_SC_GEM5_CONTROL_HH__ 566657Snate@binkert.org 576657Snate@binkert.org#include <string> 586657Snate@binkert.org#include <vector> 596657Snate@binkert.org 6010311Snilay@cs.wisc.educlass CxxConfigManager; 6110311Snilay@cs.wisc.edu 6210311Snilay@cs.wisc.edunamespace Gem5SystemC 6310311Snilay@cs.wisc.edu{ 646657Snate@binkert.org 6510311Snilay@cs.wisc.educlass Gem5TopLevelModule; 669366Snilay@cs.wisc.educlass Gem5Control; 677839Snilay@cs.wisc.edu 686657Snate@binkert.org/** Gem5System's wrap CxxConfigManager's instantiating a gem5 System 696882SBrad.Beckmann@amd.com * object (and its children). New Gem5Systems are created by 7010308Snilay@cs.wisc.edu * Gem5Control::makeSystem. A new system can have its parameters 7110308Snilay@cs.wisc.edu * tweaked using setParam{,Vector} before being instantiated using 726882SBrad.Beckmann@amd.com * Gem5System::instantiate. After instantiation, any external ports 7310308Snilay@cs.wisc.edu * declared by the system should be visible in SystemC. 7410308Snilay@cs.wisc.edu * 7510308Snilay@cs.wisc.edu * It is recommended that a SystemC wrapper sc_module is declared to 7610308Snilay@cs.wisc.edu * own each Gem5System with the call to Gem5System::instantiate being 7710308Snilay@cs.wisc.edu * made in that wrapper's constructor 789366Snilay@cs.wisc.edu * 799366Snilay@cs.wisc.edu * Note that *every* `normal' member function in this class *must* 806657Snate@binkert.org * be virtual to ensure that references to the functions go through 816657Snate@binkert.org * the pointer acquired using makeSystem and not looked up as 826657Snate@binkert.org * name-mangled symbols 836657Snate@binkert.org * 849104Shestness@cs.utexas.edu * */ 856657Snate@binkert.orgclass Gem5System 866657Snate@binkert.org{ 876657Snate@binkert.org private: 8810311Snilay@cs.wisc.edu /** Config management for *just* this system's objects (notably 8910311Snilay@cs.wisc.edu * excluding root */ 9010311Snilay@cs.wisc.edu CxxConfigManager *manager; 9110311Snilay@cs.wisc.edu 926657Snate@binkert.org /** The config file prototype for the system */ 937839Snilay@cs.wisc.edu std::string systemName; 947839Snilay@cs.wisc.edu 9510972Sdavid.hashe@amd.com /** The instantiated (in gem5) name of the system */ 9610972Sdavid.hashe@amd.com std::string instanceName; 9710972Sdavid.hashe@amd.com 986657Snate@binkert.org public: 996657Snate@binkert.org /** A constructor only used by Gem5Control */ 1006657Snate@binkert.org Gem5System(CxxConfigManager *manager_, 1016657Snate@binkert.org const std::string &system_name, const std::string &instance_name); 1026657Snate@binkert.org 1036657Snate@binkert.org virtual ~Gem5System(); 1046657Snate@binkert.org 1056657Snate@binkert.org /** Parameter setting functions callable before instantiate */ 1066657Snate@binkert.org virtual void setParam(const std::string &object, 1076657Snate@binkert.org const std::string ¶m_name, const std::string ¶m_value); 1086657Snate@binkert.org 1096657Snate@binkert.org virtual void setParamVector(const std::string &system_name, 1106657Snate@binkert.org const std::string ¶m_name, 1116657Snate@binkert.org const std::vector<std::string> ¶m_values); 1126657Snate@binkert.org 1136657Snate@binkert.org /** Build the system's gem5 infrastructure, bind its ports (note 1146657Snate@binkert.org * that all ports *must* be internal to the system), init and 1156657Snate@binkert.org * SimObject::startup the system */ 1166779SBrad.Beckmann@amd.com virtual void instantiate(); 1176657Snate@binkert.org}; 1186657Snate@binkert.org 1196657Snate@binkert.org/** Singleton class containing gem5 simulation control. 1206657Snate@binkert.org * 1216657Snate@binkert.org * Note that *every* `normal' member function in this class *must* 1226657Snate@binkert.org * be virtual to ensure that references to the functions go through 1236657Snate@binkert.org * the pointer acquired using makeGem5Control and not looked up as 1246657Snate@binkert.org * name-mangled symbols 1256657Snate@binkert.org */ 12610972Sdavid.hashe@amd.comclass Gem5Control 12710972Sdavid.hashe@amd.com{ 12810972Sdavid.hashe@amd.com private: 1299104Shestness@cs.utexas.edu /** Private SystemC module containing top level simulation control */ 1309104Shestness@cs.utexas.edu Gem5TopLevelModule *module; 1319104Shestness@cs.utexas.edu 1329104Shestness@cs.utexas.edu /** One-time-settable version string */ 1336657Snate@binkert.org std::string version; 1346657Snate@binkert.org 1356657Snate@binkert.org public: 1366657Snate@binkert.org Gem5Control(const std::string &config_filename); 1376657Snate@binkert.org 1386657Snate@binkert.org virtual ~Gem5Control(); 1396657Snate@binkert.org 1406657Snate@binkert.org /** Set/clear a gem5 debug flag */ 1416657Snate@binkert.org virtual void setDebugFlag(const char *flag); 1426657Snate@binkert.org virtual void clearDebugFlag(const char *flag); 1436657Snate@binkert.org 1446657Snate@binkert.org /** Choose a base port number for GDB to connect to the model 1456657Snate@binkert.org * (0 disables connections) */ 14610307Snilay@cs.wisc.edu virtual void setRemoteGDBPort(unsigned int port); 1476657Snate@binkert.org 1486657Snate@binkert.org /* Register an action to happen at the end of elaboration */ 1497839Snilay@cs.wisc.edu virtual void registerEndOfElaboration(void (*func)()); 1507839Snilay@cs.wisc.edu 1517839Snilay@cs.wisc.edu /** Make a System from the config file description for system 1527839Snilay@cs.wisc.edu * system_name and call it instance_name in gem5 */ 1537839Snilay@cs.wisc.edu virtual Gem5System *makeSystem(const std::string &system_name, 1547839Snilay@cs.wisc.edu const std::string &top_instance); 1557839Snilay@cs.wisc.edu 1567839Snilay@cs.wisc.edu /** set/get version string */ 1577839Snilay@cs.wisc.edu virtual const std::string &getVersion() const; 1587839Snilay@cs.wisc.edu virtual void setVersion(const std::string &new_version); 15910968Sdavid.hashe@amd.com}; 16010968Sdavid.hashe@amd.com 16110968Sdavid.hashe@amd.com} 16210968Sdavid.hashe@amd.com 16310968Sdavid.hashe@amd.com/** Instantiate a Gem5Control. This can be called using dlopen/dlsym 16410968Sdavid.hashe@amd.com * to kick-start gem5 */ 16510968Sdavid.hashe@amd.comextern "C" Gem5SystemC::Gem5Control *makeGem5Control( 1667839Snilay@cs.wisc.edu const std::string &config_filename); 1676657Snate@binkert.org 1686657Snate@binkert.org#endif // __SIM_SC_GEM5_CONTROL_HH__ 1696657Snate@binkert.org