port: Clean up default port setup and port switchover code.

This commit is contained in:
Nathan Binkert 2008-06-15 21:34:32 -07:00
parent b429b1759d
commit e3c267a3db
4 changed files with 29 additions and 25 deletions

View file

@ -351,22 +351,17 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU, Port *ic, Port *dc)
// Connect new CPU to old CPU's memory only if new CPU isn't
// connected to anything. Also connect old CPU's memory to new
// CPU.
Port *peer;
if (ic->getPeer() == NULL || ic->getPeer()->isDefaultPort()) {
peer = oldCPU->getPort("icache_port")->getPeer();
if (!ic->isConnected()) {
Port *peer = oldCPU->getPort("icache_port")->getPeer();
ic->setPeer(peer);
} else {
peer = ic->getPeer();
peer->setPeer(ic);
}
peer->setPeer(ic);
if (dc->getPeer() == NULL || dc->getPeer()->isDefaultPort()) {
peer = oldCPU->getPort("dcache_port")->getPeer();
if (!dc->isConnected()) {
Port *peer = oldCPU->getPort("dcache_port")->getPeer();
dc->setPeer(peer);
} else {
peer = dc->getPeer();
peer->setPeer(dc);
}
peer->setPeer(dc);
}

View file

@ -89,7 +89,7 @@ void
Bridge::init()
{
// Make sure that both sides are connected to.
if (portA.getPeer() == NULL || portB.getPeer() == NULL)
if (!portA.isConnected() || !portB.isConnected())
fatal("Both ports of bus bridge are not connected to a bus.\n");
if (portA.peerBlockSize() != portB.peerBlockSize())

View file

@ -39,17 +39,18 @@
#include "mem/mem_object.hh"
#include "mem/port.hh"
class defaultPeerPortClass: public Port
class DefaultPeerPort : public Port
{
protected:
void blowUp()
{
fatal("Unconnected port!");
fatal("%s: Unconnected port!", peer->name());
}
public:
defaultPeerPortClass() : Port("default_port")
{}
DefaultPeerPort()
: Port("default_port")
{ }
bool recvTiming(PacketPtr)
{
@ -84,16 +85,22 @@ class defaultPeerPortClass: public Port
blowUp();
}
bool isDefaultPort() { return true; }
bool isDefaultPort() const { return true; }
};
} defaultPeerPort;
DefaultPeerPort defaultPeerPort;
Port::Port() : peer(&defaultPeerPort), owner(NULL)
Port::Port()
: peer(&defaultPeerPort), owner(NULL)
{
}
Port::Port(const std::string &_name, MemObject *_owner) :
portName(_name), peer(&defaultPeerPort), owner(_owner)
Port::Port(const std::string &_name, MemObject *_owner)
: portName(_name), peer(&defaultPeerPort), owner(_owner)
{
}
Port::~Port()
{
}
@ -101,6 +108,7 @@ void
Port::setPeer(Port *port)
{
DPRINTF(Config, "setting peer to %s\n", port->name());
peer = port;
}

View file

@ -73,8 +73,7 @@ class MemObject;
*/
class Port
{
private:
protected:
/** Descriptive name (for DPRINTF output) */
mutable std::string portName;
@ -103,7 +102,7 @@ class Port
/** Return port name (for DPRINTF). */
const std::string &name() const { return portName; }
virtual ~Port() {};
virtual ~Port();
// mey be better to use subclasses & RTTI?
/** Holds the ports status. Currently just that a range recomputation needs
@ -131,7 +130,9 @@ class Port
* demise. */
void removeConn();
virtual bool isDefaultPort() { return false; }
virtual bool isDefaultPort() const { return false; }
bool isConnected() { return peer && !peer->isDefaultPort(); }
protected: