summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-06-15 21:39:29 -0700
committerNathan Binkert <nate@binkert.org>2008-06-15 21:39:29 -0700
commitfa8f91fdc0609fb9cb8bcde22b440b40e52f1cc8 (patch)
treeac35da562aef0061f19a2960f9e88884d91d5332 /src
parente3c267a3dbe628516777dd74662c786ef4eedceb (diff)
downloadgem5-fa8f91fdc0609fb9cb8bcde22b440b40e52f1cc8.tar.xz
physmem: Add a null option to physical memory so it doesn't store data.
Diffstat (limited to 'src')
-rw-r--r--src/mem/PhysicalMemory.py1
-rw-r--r--src/mem/physical.cc35
2 files changed, 23 insertions, 13 deletions
diff --git a/src/mem/PhysicalMemory.py b/src/mem/PhysicalMemory.py
index 4e8a830de..e512cea1c 100644
--- a/src/mem/PhysicalMemory.py
+++ b/src/mem/PhysicalMemory.py
@@ -38,6 +38,7 @@ class PhysicalMemory(MemObject):
latency = Param.Latency('1t', "latency of an access")
latency_var = Param.Latency('0ns', "access variablity")
zero = Param.Bool(False, "zero initialize memory")
+ null = Param.Bool(False, "do not store data, always return zero")
class DRAMMemory(PhysicalMemory):
type = 'DRAMMemory'
diff --git a/src/mem/physical.cc b/src/mem/physical.cc
index c06dd3170..325606eb1 100644
--- a/src/mem/physical.cc
+++ b/src/mem/physical.cc
@@ -52,12 +52,16 @@ using namespace std;
using namespace TheISA;
PhysicalMemory::PhysicalMemory(const Params *p)
- : MemObject(p), pmemAddr(NULL), lat(p->latency),
- lat_var(p->latency_var)
+ : MemObject(p), pmemAddr(NULL), pagePtr(0),
+ lat(p->latency), lat_var(p->latency_var),
+ cachedSize(params()->range.size()), cachedStart(params()->range.start)
{
if (params()->range.size() % TheISA::PageBytes != 0)
panic("Memory Size not divisible by page size\n");
+ if (params()->null)
+ return;
+
int map_flags = MAP_ANON | MAP_PRIVATE;
pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(),
PROT_READ | PROT_WRITE, map_flags, -1, 0);
@@ -70,12 +74,6 @@ PhysicalMemory::PhysicalMemory(const Params *p)
//If requested, initialize all the memory to 0
if (p->zero)
memset(pmemAddr, 0, p->range.size());
-
- pagePtr = 0;
-
- cachedSize = params()->range.size();
- cachedStart = params()->range.start;
-
}
void
@@ -257,6 +255,8 @@ PhysicalMemory::doAtomicAccess(PacketPtr pkt)
uint64_t condition_val64;
uint32_t condition_val32;
+ if (!pmemAddr)
+ panic("Swap only works if there is real memory (i.e. null=False)");
assert(sizeof(IntReg) >= pkt->getSize());
overwrite_mem = true;
@@ -287,11 +287,13 @@ PhysicalMemory::doAtomicAccess(PacketPtr pkt)
if (pkt->isLocked()) {
trackLoadLocked(pkt);
}
- memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
+ if (pmemAddr)
+ memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
TRACE_PACKET("Read");
} else if (pkt->isWrite()) {
if (writeOK(pkt)) {
- memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
+ if (pmemAddr)
+ memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
TRACE_PACKET("Write");
}
} else if (pkt->isInvalidate()) {
@@ -320,11 +322,13 @@ PhysicalMemory::doFunctionalAccess(PacketPtr pkt)
uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
if (pkt->isRead()) {
- memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
+ if (pmemAddr)
+ memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
TRACE_PACKET("Read");
pkt->makeAtomicResponse();
} else if (pkt->isWrite()) {
- memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
+ if (pmemAddr)
+ memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
TRACE_PACKET("Write");
pkt->makeAtomicResponse();
} else if (pkt->isPrint()) {
@@ -448,6 +452,9 @@ PhysicalMemory::drain(Event *de)
void
PhysicalMemory::serialize(ostream &os)
{
+ if (!pmemAddr)
+ return;
+
gzFile compressedMem;
string filename = name() + ".physmem";
@@ -480,6 +487,9 @@ PhysicalMemory::serialize(ostream &os)
void
PhysicalMemory::unserialize(Checkpoint *cp, const string &section)
{
+ if (!pmemAddr)
+ return;
+
gzFile compressedMem;
long *tempPage;
long *pmem_current;
@@ -487,7 +497,6 @@ PhysicalMemory::unserialize(Checkpoint *cp, const string &section)
uint32_t bytesRead;
const int chunkSize = 16384;
-
string filename;
UNSERIALIZE_SCALAR(filename);