diff options
Diffstat (limited to 'mem')
-rw-r--r-- | mem/mem_object.cc | 37 | ||||
-rw-r--r-- | mem/mem_object.hh | 6 | ||||
-rw-r--r-- | mem/physical.cc | 18 | ||||
-rw-r--r-- | mem/physical.hh | 9 | ||||
-rw-r--r-- | mem/port.cc | 6 | ||||
-rw-r--r-- | mem/port.hh | 11 | ||||
-rw-r--r-- | mem/translating_port.cc | 54 | ||||
-rw-r--r-- | mem/translating_port.hh | 28 |
8 files changed, 91 insertions, 78 deletions
diff --git a/mem/mem_object.cc b/mem/mem_object.cc new file mode 100644 index 000000000..f579a0727 --- /dev/null +++ b/mem/mem_object.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2002-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "mem/mem_object.hh" +#include "sim/param.hh" + +MemObject::MemObject(const std::string &name) + : SimObject(name) +{ +} + +DEFINE_SIM_OBJECT_CLASS_NAME("MemObject", MemObject) diff --git a/mem/mem_object.hh b/mem/mem_object.hh index 634fb164a..7b3d942a4 100644 --- a/mem/mem_object.hh +++ b/mem/mem_object.hh @@ -44,13 +44,11 @@ class MemObject : public SimObject { public: - MemObject(const std::string &name) - : SimObject(name) - {}; + MemObject(const std::string &name); public: /** Additional function to return the Port of a memory object. */ - virtual Port *getPort(const char *if_name) = 0; + virtual Port *getPort(const char *if_name = NULL) = 0; }; #endif //__MEM_MEM_OBJECT_HH__ diff --git a/mem/physical.cc b/mem/physical.cc index a00c59139..c1e83fb9e 100644 --- a/mem/physical.cc +++ b/mem/physical.cc @@ -70,7 +70,7 @@ PhysicalMemory::MemResponseEvent::description() } PhysicalMemory::PhysicalMemory(const string &n) - : Memory(n), base_addr(0), pmem_addr(NULL) + : MemObject(n), base_addr(0), pmem_addr(NULL) { // Hardcoded to 128 MB for now. pmem_size = 1 << 27; @@ -107,13 +107,6 @@ PhysicalMemory::new_page() return return_addr; } -Port * -PhysicalMemory::addPort(std::string portName) -{ - memoryPortList[portName] = new MemoryPort(this); - return memoryPortList[portName]; -} - int PhysicalMemory::deviceBlockSize() { @@ -161,10 +154,11 @@ PhysicalMemory::doFunctionalAccess(Packet &pkt) Port * PhysicalMemory::getPort(const char *if_name) { - if (memoryPortList.find(if_name) != memoryPortList.end()) - return memoryPortList[if_name]; - else - panic("Looking for a port that didn't exist\n"); + if (if_name == NULL) { + return new MemoryPort(this); + } else { + panic("PhysicalMemory::getPort: unknown port %s requested", if_name); + } } void diff --git a/mem/physical.hh b/mem/physical.hh index 658ba18ff..b066d3dfc 100644 --- a/mem/physical.hh +++ b/mem/physical.hh @@ -33,16 +33,17 @@ #define __PHYSICAL_MEMORY_HH__ #include "base/range.hh" -#include "mem/memory.hh" +#include "mem/mem_object.hh" #include "mem/packet.hh" #include "mem/port.hh" #include "sim/eventq.hh" #include <map> #include <string> + // // Functional model for a contiguous block of physical memory. (i.e. RAM) // -class PhysicalMemory : public Memory +class PhysicalMemory : public MemObject { class MemoryPort : public Port { @@ -68,12 +69,8 @@ class PhysicalMemory : public Memory virtual int deviceBlockSize(); }; - std::map<std::string, MemoryPort*> memoryPortList; - virtual Port * getPort(const char *if_name); - virtual Port * addPort(std::string portName); - int numPorts; int lat; diff --git a/mem/port.cc b/mem/port.cc index 75362b472..fb4f3b4e0 100644 --- a/mem/port.cc +++ b/mem/port.cc @@ -52,19 +52,19 @@ Port::blobHelper(Addr addr, uint8_t *p, int size, Command cmd) } void -Port::writeBlobFunctional(Addr addr, uint8_t *p, int size) +Port::writeBlob(Addr addr, uint8_t *p, int size) { blobHelper(addr, p, size, Write); } void -Port::readBlobFunctional(Addr addr, uint8_t *p, int size) +Port::readBlob(Addr addr, uint8_t *p, int size) { blobHelper(addr, p, size, Read); } void -Port::memsetBlobFunctional(Addr addr, uint8_t val, int size) +Port::memsetBlob(Addr addr, uint8_t val, int size) { // quick and dirty... uint8_t *buf = new uint8_t[size]; diff --git a/mem/port.hh b/mem/port.hh index 5c89c74a5..ea2929a81 100644 --- a/mem/port.hh +++ b/mem/port.hh @@ -191,29 +191,26 @@ class Port void getPeerAddressRanges(AddrRangeList &range_list, bool &owner) { peer->getDeviceAddressRanges(range_list, owner); } - // Do we need similar wrappers for sendAtomic()? If not, should - // we drop the "Functional" from the names? - /** This function is a wrapper around sendFunctional() that breaks a larger, arbitrarily aligned access into appropriate chunks. The default implementation can use getBlockSize() to determine the block size and go from there. */ - void readBlobFunctional(Addr addr, uint8_t *p, int size); + void readBlob(Addr addr, uint8_t *p, int size); /** This function is a wrapper around sendFunctional() that breaks a larger, arbitrarily aligned access into appropriate chunks. The default implementation can use getBlockSize() to determine the block size and go from there. */ - void writeBlobFunctional(Addr addr, uint8_t *p, int size); + void writeBlob(Addr addr, uint8_t *p, int size); /** Fill size bytes starting at addr with byte value val. This should not need to be virtual, since it can be implemented in - terms of writeBlobFunctional(). However, it shouldn't be + terms of writeBlob(). However, it shouldn't be performance-critical either, so it could be if we wanted to. */ - void memsetBlobFunctional(Addr addr, uint8_t val, int size); + void memsetBlob(Addr addr, uint8_t val, int size); private: diff --git a/mem/translating_port.cc b/mem/translating_port.cc index a3bf1baa7..f0059fc08 100644 --- a/mem/translating_port.cc +++ b/mem/translating_port.cc @@ -42,7 +42,7 @@ TranslatingPort::~TranslatingPort() { } bool -TranslatingPort::tryReadBlobFunctional(Addr addr, uint8_t *p, int size) +TranslatingPort::tryReadBlob(Addr addr, uint8_t *p, int size) { Addr paddr; int prevSize = 0; @@ -52,7 +52,7 @@ TranslatingPort::tryReadBlobFunctional(Addr addr, uint8_t *p, int size) if (!pTable->translate(gen.addr(),paddr)) return false; - port->readBlobFunctional(paddr, p + prevSize, gen.size()); + port->readBlob(paddr, p + prevSize, gen.size()); prevSize += gen.size(); } @@ -60,16 +60,15 @@ TranslatingPort::tryReadBlobFunctional(Addr addr, uint8_t *p, int size) } void -TranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size) +TranslatingPort::readBlob(Addr addr, uint8_t *p, int size) { - if (!tryReadBlobFunctional(addr, p, size)) - fatal("readBlobFunctional(0x%x, ...) failed", addr); + if (!tryReadBlob(addr, p, size)) + fatal("readBlob(0x%x, ...) failed", addr); } bool -TranslatingPort::tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc) +TranslatingPort::tryWriteBlob(Addr addr, uint8_t *p, int size, bool alloc) { Addr paddr; @@ -87,7 +86,7 @@ TranslatingPort::tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, } } - port->writeBlobFunctional(paddr, p + prevSize, gen.size()); + port->writeBlob(paddr, p + prevSize, gen.size()); prevSize += gen.size(); } @@ -96,16 +95,14 @@ TranslatingPort::tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, void -TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc) +TranslatingPort::writeBlob(Addr addr, uint8_t *p, int size, bool alloc) { - if (!tryWriteBlobFunctional(addr, p, size, alloc)) - fatal("writeBlobFunctional(0x%x, ...) failed", addr); + if (!tryWriteBlob(addr, p, size, alloc)) + fatal("writeBlob(0x%x, ...) failed", addr); } bool -TranslatingPort::tryMemsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc) +TranslatingPort::tryMemsetBlob(Addr addr, uint8_t val, int size, bool alloc) { Addr paddr; @@ -121,23 +118,22 @@ TranslatingPort::tryMemsetBlobFunctional(Addr addr, uint8_t val, int size, } } - port->memsetBlobFunctional(paddr, val, gen.size()); + port->memsetBlob(paddr, val, gen.size()); } return true; } void -TranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc) +TranslatingPort::memsetBlob(Addr addr, uint8_t val, int size, bool alloc) { - if (!tryMemsetBlobFunctional(addr, val, size, alloc)) - fatal("memsetBlobFunctional(0x%x, ...) failed", addr); + if (!tryMemsetBlob(addr, val, size, alloc)) + fatal("memsetBlob(0x%x, ...) failed", addr); } bool -TranslatingPort::tryWriteStringFunctional(Addr addr, const char *str) +TranslatingPort::tryWriteString(Addr addr, const char *str) { Addr paddr,vaddr; uint8_t c; @@ -149,21 +145,21 @@ TranslatingPort::tryWriteStringFunctional(Addr addr, const char *str) if (!pTable->translate(vaddr++,paddr)) return false; - port->writeBlobFunctional(paddr, &c, 1); + port->writeBlob(paddr, &c, 1); } while (c); return true; } void -TranslatingPort::writeStringFunctional(Addr addr, const char *str) +TranslatingPort::writeString(Addr addr, const char *str) { - if (!tryWriteStringFunctional(addr, str)) - fatal("writeStringFunctional(0x%x, ...) failed", addr); + if (!tryWriteString(addr, str)) + fatal("writeString(0x%x, ...) failed", addr); } bool -TranslatingPort::tryReadStringFunctional(std::string &str, Addr addr) +TranslatingPort::tryReadString(std::string &str, Addr addr) { Addr paddr,vaddr; uint8_t c; @@ -174,7 +170,7 @@ TranslatingPort::tryReadStringFunctional(std::string &str, Addr addr) if (!pTable->translate(vaddr++,paddr)) return false; - port->readBlobFunctional(paddr, &c, 1); + port->readBlob(paddr, &c, 1); str += c; } while (c); @@ -182,9 +178,9 @@ TranslatingPort::tryReadStringFunctional(std::string &str, Addr addr) } void -TranslatingPort::readStringFunctional(std::string &str, Addr addr) +TranslatingPort::readString(std::string &str, Addr addr) { - if (!tryReadStringFunctional(str, addr)) - fatal("readStringFunctional(0x%x, ...) failed", addr); + if (!tryReadString(str, addr)) + fatal("readString(0x%x, ...) failed", addr); } diff --git a/mem/translating_port.hh b/mem/translating_port.hh index eaecff35a..2ba3d68e2 100644 --- a/mem/translating_port.hh +++ b/mem/translating_port.hh @@ -29,8 +29,6 @@ #ifndef __MEM_TRANSLATING_PROT_HH__ #define __MEM_TRANSLATING_PROT_HH__ -#include "mem/memory.hh" - class Port; class PageTable; @@ -48,21 +46,17 @@ class TranslatingPort virtual ~TranslatingPort(); public: - bool tryReadBlobFunctional(Addr addr, uint8_t *p, int size); - bool tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc = false); - bool tryMemsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc = false); - bool tryWriteStringFunctional(Addr addr, const char *str); - bool tryReadStringFunctional(std::string &str, Addr addr); - - void readBlobFunctional(Addr addr, uint8_t *p, int size); - void writeBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc = false); - void memsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc = false); - void writeStringFunctional(Addr addr, const char *str); - void readStringFunctional(std::string &str, Addr addr); + bool tryReadBlob(Addr addr, uint8_t *p, int size); + bool tryWriteBlob(Addr addr, uint8_t *p, int size, bool alloc = false); + bool tryMemsetBlob(Addr addr, uint8_t val, int size, bool alloc = false); + bool tryWriteString(Addr addr, const char *str); + bool tryReadString(std::string &str, Addr addr); + + void readBlob(Addr addr, uint8_t *p, int size); + void writeBlob(Addr addr, uint8_t *p, int size, bool alloc = false); + void memsetBlob(Addr addr, uint8_t val, int size, bool alloc = false); + void writeString(Addr addr, const char *str); + void readString(std::string &str, Addr addr); }; #endif |