summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2012-02-24 11:45:30 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2012-02-24 11:45:30 -0500
commit9e3c8de30bafe33f35e4b9e82fb49418941f8cb7 (patch)
tree016c65f8060c49b31d3fd3c064b97ae09279d689 /src/sim
parent1031b824b975cec999c37cabc8c05c485a4ae5ca (diff)
downloadgem5-9e3c8de30bafe33f35e4b9e82fb49418941f8cb7.tar.xz
MEM: Make port proxies use references rather than pointers
This patch is adding a clearer design intent to all objects that would not be complete without a port proxy by making the proxies members rathen than dynamically allocated. In essence, if NULL would not be a valid value for the proxy, then we avoid using a pointer to make this clear. The same approach is used for the methods using these proxies, such as loadSections, that now use references rather than pointers to better reflect the fact that NULL would not be an acceptable value (in fact the code would break and that is how this patch started out). Overall the concept of "using a reference to express unconditional composition where a NULL pointer is never valid" could be done on a much broader scale throughout the code base, but for now it is only done in the locations affected by the proxies.
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/process.cc24
-rw-r--r--src/sim/process.hh13
-rw-r--r--src/sim/process_impl.hh8
-rw-r--r--src/sim/syscall_emul.cc22
-rw-r--r--src/sim/syscall_emul.hh42
-rw-r--r--src/sim/system.cc10
-rw-r--r--src/sim/system.hh14
-rw-r--r--src/sim/vptr.hh4
8 files changed, 70 insertions, 67 deletions
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 8f3b3be79..39b2d0777 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -1,4 +1,16 @@
/*
+ * Copyright (c) 2012 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2001-2005 The Regents of The University of Michigan
* All rights reserved.
*
@@ -43,7 +55,6 @@
#include "config/the_isa.hh"
#include "cpu/thread_context.hh"
#include "mem/page_table.hh"
-#include "mem/physical.hh"
#include "mem/se_translating_port_proxy.hh"
#include "params/LiveProcess.hh"
#include "params/Process.hh"
@@ -91,7 +102,11 @@ template struct AuxVector<uint64_t>;
Process::Process(ProcessParams * params)
: SimObject(params), system(params->system),
- max_stack_size(params->max_stack_size)
+ max_stack_size(params->max_stack_size),
+ M5_pid(system->allocatePID()),
+ pTable(new PageTable(name(), M5_pid)),
+ initVirtMem(system->getSystemPort(), this,
+ SETranslatingPortProxy::Always)
{
string in = params->input;
string out = params->output;
@@ -127,7 +142,6 @@ Process::Process(ProcessParams * params)
else
stderr_fd = Process::openOutputFile(err);
- M5_pid = system->allocatePID();
// initialize first 3 fds (stdin, stdout, stderr)
Process::FdMap *fdo = &fd_map[STDIN_FILENO];
fdo->fd = stdin_fd;
@@ -159,7 +173,6 @@ Process::Process(ProcessParams * params)
mmap_start = mmap_end = 0;
nxm_start = nxm_end = 0;
- pTable = new PageTable(name(), M5_pid);
// other parameters will be initialized when the program is loaded
}
@@ -233,9 +246,6 @@ Process::initState()
// mark this context as active so it will start ticking.
tc->activate(0);
-
- initVirtMem = new SETranslatingPortProxy(*system->getSystemPort(), this,
- SETranslatingPortProxy::Always);
}
// map simulator fd sim_fd to target fd tgt_fd
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 17b530ab8..a5265f5b0 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -39,6 +39,7 @@
#include "base/statistics.hh"
#include "base/types.hh"
#include "config/the_isa.hh"
+#include "mem/se_translating_port_proxy.hh"
#include "sim/sim_object.hh"
#include "sim/syscallreturn.hh"
@@ -48,7 +49,6 @@ struct LiveProcessParams;
class SyscallDesc;
class System;
class ThreadContext;
-class SETranslatingPortProxy;
template<class IntType>
struct AuxVector
@@ -121,17 +121,14 @@ class Process : public SimObject
virtual void initState();
- protected:
- /// Memory object for initialization (image loading)
- SETranslatingPortProxy *initVirtMem;
-
public:
- PageTable *pTable;
//This id is assigned by m5 and is used to keep process' tlb entries
//separated.
uint64_t M5_pid;
+ PageTable* pTable;
+
class FdMap
{
public:
@@ -152,6 +149,10 @@ class Process : public SimObject
void unserialize(Checkpoint *cp, const std::string &section);
};
+ protected:
+ /// Memory proxy for initialization (image loading)
+ SETranslatingPortProxy initVirtMem;
+
private:
// file descriptor remapping support
static const int MAX_FD = 256; // max legal fd value
diff --git a/src/sim/process_impl.hh b/src/sim/process_impl.hh
index 0fb827498..b1905834b 100644
--- a/src/sim/process_impl.hh
+++ b/src/sim/process_impl.hh
@@ -43,21 +43,21 @@ template<class AddrType>
void
copyStringArray(std::vector<std::string> &strings,
AddrType array_ptr, AddrType data_ptr,
- SETranslatingPortProxy* memProxy)
+ SETranslatingPortProxy& memProxy)
{
AddrType data_ptr_swap;
for (std::vector<std::string>::size_type i = 0; i < strings.size(); ++i) {
data_ptr_swap = TheISA::htog(data_ptr);
- memProxy->writeBlob(array_ptr, (uint8_t*)&data_ptr_swap,
+ memProxy.writeBlob(array_ptr, (uint8_t*)&data_ptr_swap,
sizeof(AddrType));
- memProxy->writeString(data_ptr, strings[i].c_str());
+ memProxy.writeString(data_ptr, strings[i].c_str());
array_ptr += sizeof(AddrType);
data_ptr += strings[i].size() + 1;
}
// add NULL terminator
data_ptr = 0;
- memProxy->writeBlob(array_ptr, (uint8_t*)&data_ptr, sizeof(AddrType));
+ memProxy.writeBlob(array_ptr, (uint8_t*)&data_ptr, sizeof(AddrType));
}
#endif
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index dc8a9a5c8..9e53645f5 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -171,18 +171,18 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
// if the address is already there, zero it out
else {
uint8_t zero = 0;
- SETranslatingPortProxy *tp = tc->getMemProxy();
+ SETranslatingPortProxy &tp = tc->getMemProxy();
// split non-page aligned accesses
Addr next_page = roundUp(gen.addr(), VMPageSize);
uint32_t size_needed = next_page - gen.addr();
- tp->memsetBlob(gen.addr(), zero, size_needed);
+ tp.memsetBlob(gen.addr(), zero, size_needed);
if (gen.addr() + VMPageSize > next_page &&
next_page < new_brk &&
p->pTable->translate(next_page))
{
size_needed = VMPageSize - size_needed;
- tp->memsetBlob(next_page, zero, size_needed);
+ tp.memsetBlob(next_page, zero, size_needed);
}
}
}
@@ -358,7 +358,7 @@ readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
@@ -382,7 +382,7 @@ unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
@@ -399,7 +399,7 @@ mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
@@ -417,12 +417,12 @@ renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string old_name;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(old_name, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index)))
return -EFAULT;
string new_name;
- if (!tc->getMemProxy()->tryReadString(new_name, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index)))
return -EFAULT;
// Adjust path for current working directory
@@ -439,7 +439,7 @@ truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
off_t length = p->getSyscallArg(tc, index);
@@ -474,7 +474,7 @@ truncate64Func(SyscallDesc *desc, int num,
int index = 0;
string path;
- if (!tc->getMemProxy()->tryReadString(path, process->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index)))
return -EFAULT;
int64_t length = process->getSyscallArg(tc, index, 64);
@@ -527,7 +527,7 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
/* XXX endianess */
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index ad00f6e3d..504add35f 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -121,18 +121,18 @@ class BaseBufferArg {
//
// copy data into simulator space (read from target memory)
//
- virtual bool copyIn(SETranslatingPortProxy* memproxy)
+ virtual bool copyIn(SETranslatingPortProxy &memproxy)
{
- memproxy->readBlob(addr, bufPtr, size);
+ memproxy.readBlob(addr, bufPtr, size);
return true; // no EFAULT detection for now
}
//
// copy data out of simulator space (write to target memory)
//
- virtual bool copyOut(SETranslatingPortProxy* memproxy)
+ virtual bool copyOut(SETranslatingPortProxy &memproxy)
{
- memproxy->writeBlob(addr, bufPtr, size);
+ memproxy.writeBlob(addr, bufPtr, size);
return true; // no EFAULT detection for now
}
@@ -464,7 +464,7 @@ convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY = false)
//Here are a couple convenience functions
template<class OS>
static void
-copyOutStatBuf(SETranslatingPortProxy* mem, Addr addr,
+copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
hst_stat *host, bool fakeTTY = false)
{
typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
@@ -475,7 +475,7 @@ copyOutStatBuf(SETranslatingPortProxy* mem, Addr addr,
template<class OS>
static void
-copyOutStat64Buf(SETranslatingPortProxy* mem, Addr addr,
+copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
hst_stat64 *host, bool fakeTTY = false)
{
typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
@@ -530,7 +530,7 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index)))
return -EFAULT;
@@ -608,7 +608,7 @@ chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -714,7 +714,7 @@ statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -744,7 +744,7 @@ stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index)))
return -EFAULT;
Addr bufPtr = process->getSyscallArg(tc, index);
@@ -809,7 +809,7 @@ lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -838,7 +838,7 @@ lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -899,7 +899,7 @@ statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -958,19 +958,19 @@ writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
return -EBADF;
}
- SETranslatingPortProxy *p = tc->getMemProxy();
+ SETranslatingPortProxy &p = tc->getMemProxy();
uint64_t tiov_base = process->getSyscallArg(tc, index);
size_t count = process->getSyscallArg(tc, index);
struct iovec hiov[count];
for (size_t i = 0; i < count; ++i) {
typename OS::tgt_iovec tiov;
- p->readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
- (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
+ p.readBlob(tiov_base + i*sizeof(typename OS::tgt_iovec),
+ (uint8_t*)&tiov, sizeof(typename OS::tgt_iovec));
hiov[i].iov_len = TheISA::gtoh(tiov.iov_len);
hiov[i].iov_base = new char [hiov[i].iov_len];
- p->readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
- hiov[i].iov_len);
+ p.readBlob(TheISA::gtoh(tiov.iov_base), (uint8_t *)hiov[i].iov_base,
+ hiov[i].iov_len);
}
int result = writev(process->sim_fd(fd), hiov, count);
@@ -1136,7 +1136,7 @@ utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
std::string path;
int index = 0;
- if (!tc->getMemProxy()->tryReadString(path,
+ if (!tc->getMemProxy().tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
@@ -1255,8 +1255,8 @@ timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if(taddr != 0) {
typename OS::time_t t = sec;
t = TheISA::htog(t);
- SETranslatingPortProxy *p = tc->getMemProxy();
- p->writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
+ SETranslatingPortProxy &p = tc->getMemProxy();
+ p.writeBlob(taddr, (uint8_t*)&t, (int)sizeof(typename OS::time_t));
}
return sec;
}
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 1f7527426..36d4447ff 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -57,8 +57,6 @@
#include "debug/Loader.hh"
#include "debug/WorkItems.hh"
#include "kern/kernel_stats.hh"
-#include "mem/fs_translating_port_proxy.hh"
-#include "mem/mem_object.hh"
#include "mem/physical.hh"
#include "params/System.hh"
#include "sim/byteswap.hh"
@@ -79,6 +77,8 @@ System::System(Params *p)
_numContexts(0),
pagePtr(0),
init_param(p->init_param),
+ physProxy(_systemPort),
+ virtProxy(_systemPort),
loadAddrMask(p->load_addr_mask),
nextPID(0),
memoryMode(p->mem_mode),
@@ -106,12 +106,6 @@ System::System(Params *p)
kernelSymtab = new SymbolTable;
if (!debugSymbolTable)
debugSymbolTable = new SymbolTable;
-
- /**
- * Get a port proxy to memory
- */
- physProxy = new PortProxy(*getSystemPort());
- virtProxy = new FSTranslatingPortProxy(*getSystemPort());
}
// Get the generic system master IDs
diff --git a/src/sim/system.hh b/src/sim/system.hh
index 9d11132e5..dd122161d 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -56,20 +56,18 @@
#include "cpu/pc_event.hh"
#include "enums/MemoryMode.hh"
#include "kern/system_events.hh"
+#include "mem/fs_translating_port_proxy.hh"
#include "mem/mem_object.hh"
#include "mem/port.hh"
#include "params/System.hh"
class BaseCPU;
class BaseRemoteGDB;
-class FSTranslatingPortProxy;
class GDBListener;
class ObjectFile;
class PhysicalMemory;
class Platform;
-class PortProxy;
class ThreadContext;
-class VirtualPort;
class System : public MemObject
{
@@ -117,14 +115,14 @@ class System : public MemObject
virtual void init();
/**
- * Get a pointer to the system port that can be used by
+ * Get a reference to the system port that can be used by
* non-structural simulation objects like processes or threads, or
* external entities like loaders and debuggers, etc, to access
* the memory system.
*
- * @return a pointer to the system port we own
+ * @return a reference to the system port we own
*/
- Port* getSystemPort() { return &_systemPort; }
+ Port& getSystemPort() { return _systemPort; }
/**
* Additional function to return the Port of a memory object.
@@ -181,8 +179,8 @@ class System : public MemObject
/** Port to physical memory used for writing object files into ram at
* boot.*/
- PortProxy* physProxy;
- FSTranslatingPortProxy* virtProxy;
+ PortProxy physProxy;
+ FSTranslatingPortProxy virtProxy;
/** kernel symbol table */
SymbolTable *kernelSymtab;
diff --git a/src/sim/vptr.hh b/src/sim/vptr.hh
index eee575b6b..658959a90 100644
--- a/src/sim/vptr.hh
+++ b/src/sim/vptr.hh
@@ -71,8 +71,8 @@ class VPtr
if (!ptr)
return;
- FSTranslatingPortProxy* proxy = tc->getVirtProxy();
- proxy->readBlob(ptr, buffer, sizeof(T));
+ FSTranslatingPortProxy &proxy = tc->getVirtProxy();
+ proxy.readBlob(ptr, buffer, sizeof(T));
}
bool