Add the bus and connector objects to scons

change getPort parameter from char* to string
Add an extra phase between construction and init called connect

SConscript:
    Add the bus and connector objects to scons
cpu/simple/cpu.cc:
cpu/simple/cpu.hh:
    the connection to memory shouldn't be made until we know the memory
    object exists (e.g. after construction)
dev/io_device.hh:
    change to const string
mem/bus.hh:
    change getPort parameter from char* to string
    initialize num_interfaces
mem/mem_object.hh:
    change getPort parameter from char* to string
mem/physical.cc:
mem/physical.hh:
    change getPort parameter from char* to string
    get rid of the bus object I created last time
python/m5/objects/PhysicalMemory.py:
    get rid of the bus object I created last time
sim/main.cc:
sim/sim_object.cc:
sim/sim_object.hh:
    Add an extra phase between construction and init called connect

--HG--
extra : convert_revision : 0e994f93374fa72a06d291655c440ff1b8e155a9
This commit is contained in:
Ali Saidi 2006-03-26 21:44:22 -05:00
parent 4973a16b34
commit c27c122afc
12 changed files with 58 additions and 38 deletions

View file

@ -88,11 +88,13 @@ base_sources = Split('''
cpu/static_inst.cc cpu/static_inst.cc
cpu/sampler/sampler.cc cpu/sampler/sampler.cc
mem/connector.cc
mem/mem_object.cc mem/mem_object.cc
mem/page_table.cc mem/page_table.cc
mem/physical.cc mem/physical.cc
mem/port.cc mem/port.cc
mem/translating_port.cc mem/translating_port.cc
mem/bus.cc
python/pyconfig.cc python/pyconfig.cc
python/embedded_py.cc python/embedded_py.cc

View file

@ -86,6 +86,15 @@ SimpleCPU::TickEvent::TickEvent(SimpleCPU *c, int w)
void void
SimpleCPU::init() SimpleCPU::init()
{ {
//Create Memory Ports (conect them up)
Port *mem_dport = mem->getPort("");
dcachePort.setPeer(mem_dport);
mem_dport->setPeer(&dcachePort);
Port *mem_iport = mem->getPort("");
icachePort.setPeer(mem_iport);
mem_iport->setPeer(&icachePort);
BaseCPU::init(); BaseCPU::init();
#if FULL_SYSTEM #if FULL_SYSTEM
for (int i = 0; i < execContexts.size(); ++i) { for (int i = 0; i < execContexts.size(); ++i) {
@ -146,20 +155,11 @@ SimpleCPU::CpuPort::recvRetry()
} }
SimpleCPU::SimpleCPU(Params *p) SimpleCPU::SimpleCPU(Params *p)
: BaseCPU(p), icachePort(this), : BaseCPU(p), mem(p->mem), icachePort(this),
dcachePort(this), tickEvent(this, p->width), cpuXC(NULL) dcachePort(this), tickEvent(this, p->width), cpuXC(NULL)
{ {
_status = Idle; _status = Idle;
//Create Memory Ports (conect them up)
Port *mem_dport = p->mem->getPort();
dcachePort.setPeer(mem_dport);
mem_dport->setPeer(&dcachePort);
Port *mem_iport = p->mem->getPort();
icachePort.setPeer(mem_iport);
mem_iport->setPeer(&icachePort);
#if FULL_SYSTEM #if FULL_SYSTEM
cpuXC = new CPUExecContext(this, 0, p->system, p->itb, p->dtb, p->mem); cpuXC = new CPUExecContext(this, 0, p->system, p->itb, p->dtb, p->mem);
#else #else

View file

@ -105,6 +105,7 @@ class SimpleCPU : public BaseCPU
virtual Packet *recvRetry(); virtual Packet *recvRetry();
}; };
MemObject *mem;
CpuPort icachePort; CpuPort icachePort;
CpuPort dcachePort; CpuPort dcachePort;

View file

@ -203,7 +203,7 @@ class PioDevice : public SimObject
virtual ~PioDevice(); virtual ~PioDevice();
virtual Port *getPort(std::string if_name) virtual Port *getPort(const std::string &if_name)
{ {
if (if_name == "pio") if (if_name == "pio")
return pioPort; return pioPort;
@ -223,7 +223,7 @@ class DmaDevice : public PioDevice
DmaDevice(const std::string &name, Platform *p); DmaDevice(const std::string &name, Platform *p);
virtual ~DmaDevice(); virtual ~DmaDevice();
virtual Port *getPort(std::string if_name) virtual Port *getPort(const std::string &if_name)
{ {
if (if_name == "pio") if (if_name == "pio")
return pioPort; return pioPort;

View file

@ -137,7 +137,7 @@ class Bus : public MemObject
public: public:
/** A function used to return the port associated with this bus object. */ /** A function used to return the port associated with this bus object. */
virtual Port *getPort(const char *if_name) virtual Port *getPort(const std::string &if_name)
{ {
// if_name ignored? forced to be empty? // if_name ignored? forced to be empty?
int id = num_interfaces++; int id = num_interfaces++;
@ -145,7 +145,7 @@ class Bus : public MemObject
return interfaces[id]; return interfaces[id];
} }
Bus(const std::string &n) Bus(const std::string &n)
: MemObject(n) {} : MemObject(n), num_interfaces(0) {}
}; };

View file

@ -48,7 +48,7 @@ class MemObject : public SimObject
public: public:
/** Additional function to return the Port of a memory object. */ /** Additional function to return the Port of a memory object. */
virtual Port *getPort(const char *if_name = NULL) = 0; virtual Port *getPort(const std::string &if_name) = 0;
}; };
#endif //__MEM_MEM_OBJECT_HH__ #endif //__MEM_MEM_OBJECT_HH__

View file

@ -69,8 +69,8 @@ PhysicalMemory::MemResponseEvent::description()
return "Physical Memory Timing Access respnse event"; return "Physical Memory Timing Access respnse event";
} }
PhysicalMemory::PhysicalMemory(const string &n, MemObject *bus) PhysicalMemory::PhysicalMemory(const string &n)
: MemObject(n), memPort(this), base_addr(0), pmem_addr(NULL) : MemObject(n), base_addr(0), pmem_addr(NULL)
{ {
// Hardcoded to 128 MB for now. // Hardcoded to 128 MB for now.
pmem_size = 1 << 27; pmem_size = 1 << 27;
@ -88,14 +88,6 @@ PhysicalMemory::PhysicalMemory(const string &n, MemObject *bus)
} }
page_ptr = 0; page_ptr = 0;
Port *peer_port;
peer_port = bus->getPort();
memPort.setPeer(peer_port);
peer_port->setPeer(&memPort);
} }
PhysicalMemory::~PhysicalMemory() PhysicalMemory::~PhysicalMemory()
@ -160,10 +152,13 @@ PhysicalMemory::doFunctionalAccess(Packet &pkt)
} }
Port * Port *
PhysicalMemory::getPort(const char *if_name) PhysicalMemory::getPort(const std::string &if_name)
{ {
if (if_name == NULL) { if (if_name == "") {
return new MemoryPort(this); if (port != NULL)
panic("PhysicalMemory::getPort: additional port requested to memory!");
port = new MemoryPort(this);
return port;
} else { } else {
panic("PhysicalMemory::getPort: unknown port %s requested", if_name); panic("PhysicalMemory::getPort: unknown port %s requested", if_name);
} }
@ -341,7 +336,6 @@ BEGIN_DECLARE_SIM_OBJECT_PARAMS(PhysicalMemory)
SimObjectParam<MemoryController *> mmu; SimObjectParam<MemoryController *> mmu;
#endif #endif
Param<Range<Addr> > range; Param<Range<Addr> > range;
SimObjectParam<MemObject*> bus;
END_DECLARE_SIM_OBJECT_PARAMS(PhysicalMemory) END_DECLARE_SIM_OBJECT_PARAMS(PhysicalMemory)
@ -351,8 +345,7 @@ BEGIN_INIT_SIM_OBJECT_PARAMS(PhysicalMemory)
#if FULL_SYSTEM #if FULL_SYSTEM
INIT_PARAM(mmu, "Memory Controller"), INIT_PARAM(mmu, "Memory Controller"),
#endif #endif
INIT_PARAM(range, "Device Address Range"), INIT_PARAM(range, "Device Address Range")
INIT_PARAM(bus, "bus object memory connects to")
END_INIT_SIM_OBJECT_PARAMS(PhysicalMemory) END_INIT_SIM_OBJECT_PARAMS(PhysicalMemory)
@ -364,7 +357,7 @@ CREATE_SIM_OBJECT(PhysicalMemory)
} }
#endif #endif
return new PhysicalMemory(getInstanceName(), bus); return new PhysicalMemory(getInstanceName());
} }
REGISTER_SIM_OBJECT("PhysicalMemory", PhysicalMemory) REGISTER_SIM_OBJECT("PhysicalMemory", PhysicalMemory)

View file

@ -69,9 +69,7 @@ class PhysicalMemory : public MemObject
virtual int deviceBlockSize(); virtual int deviceBlockSize();
}; };
MemoryPort memPort; virtual Port *getPort(const std::string &if_name);
virtual Port * getPort(const char *if_name);
int numPorts; int numPorts;
@ -96,6 +94,7 @@ class PhysicalMemory : public MemObject
Addr base_addr; Addr base_addr;
Addr pmem_size; Addr pmem_size;
uint8_t *pmem_addr; uint8_t *pmem_addr;
MemoryPort *port;
int page_ptr; int page_ptr;
public: public:
@ -103,13 +102,13 @@ class PhysicalMemory : public MemObject
uint64_t size() { return pmem_size; } uint64_t size() { return pmem_size; }
public: public:
PhysicalMemory(const std::string &n, MemObject *bus); PhysicalMemory(const std::string &n);
virtual ~PhysicalMemory(); virtual ~PhysicalMemory();
public: public:
int deviceBlockSize(); int deviceBlockSize();
void getAddressRanges(AddrRangeList &rangeList, bool &owner); void getAddressRanges(AddrRangeList &rangeList, bool &owner);
void virtual init() { memPort.sendStatusChange(Port::RangeChange); } void virtual init() { port->sendStatusChange(Port::RangeChange); }
// fast back-door memory access for vtophys(), remote gdb, etc. // fast back-door memory access for vtophys(), remote gdb, etc.
// uint64_t phys_read_qword(Addr addr) const; // uint64_t phys_read_qword(Addr addr) const;

View file

@ -5,6 +5,5 @@ class PhysicalMemory(Memory):
type = 'PhysicalMemory' type = 'PhysicalMemory'
range = Param.AddrRange("Device Address") range = Param.AddrRange("Device Address")
file = Param.String('', "memory mapped file") file = Param.String('', "memory mapped file")
bus = Param.MemObject("Bus to attach to")
if build_env['FULL_SYSTEM']: if build_env['FULL_SYSTEM']:
mmu = Param.MemoryController(Parent.any, "Memory Controller") mmu = Param.MemoryController(Parent.any, "Memory Controller")

View file

@ -355,6 +355,10 @@ main(int argc, char **argv)
echoCommandLine(argc, argv, *outputStream); echoCommandLine(argc, argv, *outputStream);
ParamContext::showAllContexts(*configStream); ParamContext::showAllContexts(*configStream);
// Any objects that can't connect themselves until after construction should
// do so now
SimObject::connectAll();
// Do a second pass to finish initializing the sim objects // Do a second pass to finish initializing the sim objects
SimObject::initAll(); SimObject::initAll();

View file

@ -87,6 +87,11 @@ SimObject::SimObject(const string &_name)
simObjectList.push_back(this); simObjectList.push_back(this);
} }
void
SimObject::connect()
{
}
void void
SimObject::init() SimObject::init()
{ {
@ -150,6 +155,21 @@ SimObject::regAllStats()
Stats::registerResetCallback(&StatResetCB); Stats::registerResetCallback(&StatResetCB);
} }
//
// static function: call connect() on all SimObjects.
//
void
SimObject::connectAll()
{
SimObjectList::iterator i = simObjectList.begin();
SimObjectList::iterator end = simObjectList.end();
for (; i != end; ++i) {
SimObject *obj = *i;
obj->connect();
}
}
// //
// static function: call init() on all SimObjects. // static function: call init() on all SimObjects.
// //

View file

@ -78,7 +78,9 @@ class SimObject : public Serializable, protected StartupCallback
// initialization pass of all objects. // initialization pass of all objects.
// Gets invoked after construction, before unserialize. // Gets invoked after construction, before unserialize.
virtual void init(); virtual void init();
virtual void connect();
static void initAll(); static void initAll();
static void connectAll();
// register statistics for this object // register statistics for this object
virtual void regStats(); virtual void regStats();