112837Sgabeblack@google.com# Copyright 2018 Google, Inc.
212837Sgabeblack@google.com#
312837Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
412837Sgabeblack@google.com# modification, are permitted provided that the following conditions are
512837Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
612837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
712837Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
812837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
912837Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1012837Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1112837Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1212837Sgabeblack@google.com# this software without specific prior written permission.
1312837Sgabeblack@google.com#
1412837Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1512837Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1612837Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1712837Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1812837Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1912837Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2012837Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2112837Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2212837Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2312837Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2412837Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2512837Sgabeblack@google.com#
2612837Sgabeblack@google.com# Authors: Gabe Black
2712837Sgabeblack@google.com
2813785Sgabeblack@google.comfrom m5.SimObject import SimObject, cxxMethod
2912837Sgabeblack@google.com
3012837Sgabeblack@google.com# This class represents the systemc kernel. There should be exactly one in the
3112837Sgabeblack@google.com# simulation. It receives gem5 SimObject lifecycle callbacks (init, regStats,
3212837Sgabeblack@google.com# etc.) and manages the lifecycle of the systemc simulation accordingly.
3312837Sgabeblack@google.comclass SystemC_Kernel(SimObject):
3412837Sgabeblack@google.com    type = 'SystemC_Kernel'
3512982Sgabeblack@google.com    cxx_class = 'sc_gem5::Kernel'
3612837Sgabeblack@google.com    cxx_header = 'systemc/core/kernel.hh'
3712837Sgabeblack@google.com
3812837Sgabeblack@google.com# This class represents systemc sc_object instances in python config files. It
3912837Sgabeblack@google.com# inherits from SimObject in python, but the c++ version, sc_core::sc_object,
4012837Sgabeblack@google.com# doesn't inherit from gem5's c++ SimObject class.
4112837Sgabeblack@google.comclass SystemC_ScObject(SimObject):
4212837Sgabeblack@google.com    type = 'SystemC_ScObject'
4312837Sgabeblack@google.com    abstract = True
4412837Sgabeblack@google.com    cxx_class = 'sc_core::sc_object'
4512837Sgabeblack@google.com    cxx_header = 'systemc/ext/core/sc_object.hh'
4612837Sgabeblack@google.com
4712837Sgabeblack@google.com    # Clear cxx_base to stop the c++ binding code from assuming
4812837Sgabeblack@google.com    # sc_core::sc_object inherits from SimObject, even though SystemC_ScObject
4912837Sgabeblack@google.com    # does on the python side.
5012837Sgabeblack@google.com    cxx_base = None
5112837Sgabeblack@google.com
5212837Sgabeblack@google.com    # Hide the cxx_exports from SimObject since we don't inherit from
5312837Sgabeblack@google.com    # SimObject on the c++ side and so don't have those methods to call down
5412837Sgabeblack@google.com    # into.
5512837Sgabeblack@google.com    locals().update({
5612837Sgabeblack@google.com        method.name: (lambda *a, **k: None) for method in SimObject.cxx_exports
5712837Sgabeblack@google.com    })
5813038Sgabeblack@google.com
5913331Sgabeblack@google.comclass SystemC_ScModule(SystemC_ScObject):
6013331Sgabeblack@google.com    type = 'SystemC_ScModule'
6113331Sgabeblack@google.com    abstract = True
6213331Sgabeblack@google.com    cxx_class = 'sc_core::sc_module'
6313331Sgabeblack@google.com    cxx_header = 'systemc/ext/core/sc_module.hh'
6413331Sgabeblack@google.com
6513785Sgabeblack@google.com    @cxxMethod(return_value_policy="reference", cxx_name="gem5_getPort")
6613785Sgabeblack@google.com    def getPort(self, if_name, iex):
6713785Sgabeblack@google.com        return None
6813785Sgabeblack@google.com
6913038Sgabeblack@google.comtry:
7013038Sgabeblack@google.com    import _m5
7113038Sgabeblack@google.comexcept:
7213038Sgabeblack@google.com    pass
7313038Sgabeblack@google.comelse:
7413038Sgabeblack@google.com    import _m5.systemc
7513038Sgabeblack@google.com    _m5.systemc.python_ready()
76