2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
35 #include "base/inifile.hh"
36 #include "base/output.hh"
37 #include "config/the_isa.hh"
38 #if THE_ISA != NULL_ISA
39 #include "dev/net/etherdevice.hh"
40 #include "dev/net/etherobject.hh"
42 #include "mem/ruby/slicc_interface/AbstractController.hh"
43 #include "mem/mem_object.hh"
44 #include "python/swig/pyobject.hh"
45 #include "sim/full_system.hh"
46 #include "sim/sim_object.hh"
50 #if THE_ISA != NULL_ISA
52 lookupEthPort(SimObject
*so
, const std::string
&name
, int i
)
54 EtherObject
*eo
= dynamic_cast<EtherObject
*>(so
);
55 EtherDevice
*ed
= dynamic_cast<EtherDevice
*>(so
);
56 if (eo
== NULL
&& ed
== NULL
) {
57 warn("error casting SimObject %s", so
->name());
63 p
= eo
->getEthPort(name
, i
);
65 p
= ed
->getEthPort(name
, i
);
71 * Connect the described MemObject ports. Called from Python via SWIG.
72 * The indices i1 & i2 will be -1 for regular ports, >= 0 for vector ports.
73 * SimObject1 is the master, and SimObject2 is the slave
76 connectPorts(SimObject
*o1
, const std::string
&name1
, int i1
,
77 SimObject
*o2
, const std::string
&name2
, int i2
)
79 #if THE_ISA != NULL_ISA
81 EtherObject
*eo1
, *eo2
;
82 EtherDevice
*ed1
, *ed2
;
83 eo1
= dynamic_cast<EtherObject
*>(o1
);
84 ed1
= dynamic_cast<EtherDevice
*>(o1
);
85 eo2
= dynamic_cast<EtherObject
*>(o2
);
86 ed2
= dynamic_cast<EtherDevice
*>(o2
);
88 if ((eo1
|| ed1
) && (eo2
|| ed2
)) {
89 EtherInt
*p1
= lookupEthPort(o1
, name1
, i1
);
90 EtherInt
*p2
= lookupEthPort(o2
, name2
, i2
);
92 if (p1
!= NULL
&& p2
!= NULL
) {
103 // These could be MessageBuffers from the ruby memory system. If so, they
104 // need not be connected to anything currently.
105 MessageBuffer
*mb1
, *mb2
;
106 mb1
= dynamic_cast<MessageBuffer
*>(o1
);
107 mb2
= dynamic_cast<MessageBuffer
*>(o2
);
110 // No need to connect anything here currently. MessageBuffer
111 // connections in Python only serve to print the connections in
112 // the config output.
113 // TODO: Add real ports to MessageBuffers and use MemObject connect
114 // code below to bind MessageBuffer senders and receivers
118 MemObject
*mo1
, *mo2
;
119 mo1
= dynamic_cast<MemObject
*>(o1
);
120 mo2
= dynamic_cast<MemObject
*>(o2
);
122 if(mo1
== NULL
|| mo2
== NULL
) {
123 panic ("Error casting SimObjects %s and %s to MemObject", o1
->name(),
127 // generic master/slave port connection
128 BaseMasterPort
& masterPort
= mo1
->getMasterPort(name1
, i1
);
129 BaseSlavePort
& slavePort
= mo2
->getSlavePort(name2
, i2
);
131 masterPort
.bind(slavePort
);
139 static IniFile inifile
;
144 * Convert a pointer to the Python object that SWIG wraps around a C++
145 * SimObject pointer back to the actual C++ pointer. See main.i.
147 extern "C" SimObject
*convertSwigSimObjectPtr(PyObject
*);
149 // Python.h is notoriously not const-correct (for 2.4, anyway)... make
150 // a little define here to reduce the noise and make it easier to
151 // #ifdef away if Python.h gets fixed. Note there are a couple of
152 // these in sim/main.cc as well that are handled without this define.
153 #define PCC(s) const_cast<char *>(s)
155 /** Single instance of PythonSimObjectResolver as its action is effectively
156 * static but SimObjectResolver can use a non-persistent object */
157 PythonSimObjectResolver pythonSimObjectResolver
;
160 PythonSimObjectResolver::resolveSimObject(const string
&name
)
162 PyObject
*module
= PyImport_ImportModule(PCC("m5.SimObject"));
164 panic("Could not import m5.SimObject");
167 PyObject_GetAttrString(module
, PCC("resolveSimObject"));
168 if (resolver
== NULL
) {
170 panic("resolveSimObject: failed to find resolveSimObject");
173 PyObject
*ptr
= PyObject_CallFunction(resolver
, PCC("(s)"), name
.c_str());
176 panic("resolveSimObject: failure on call to Python for %s", name
);
179 SimObject
*obj
= convertSwigSimObjectPtr(ptr
);
181 panic("resolveSimObject: failure on pointer conversion for %s", name
);
191 getCheckpoint(const std::string
&cpt_dir
)
193 return new CheckpointIn(cpt_dir
, pythonSimObjectResolver
);