summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/process.cc17
-rw-r--r--sim/process.hh7
-rw-r--r--sim/syscall_emul.cc67
-rw-r--r--sim/syscall_emul.hh82
4 files changed, 89 insertions, 84 deletions
diff --git a/sim/process.cc b/sim/process.cc
index acc6762f8..7111e8733 100644
--- a/sim/process.cc
+++ b/sim/process.cc
@@ -65,14 +65,14 @@ using namespace std;
// current number of allocated processes
int num_processes = 0;
-Process::Process(const string &name,
+Process::Process(const string &nm,
int stdin_fd, // initial I/O descriptors
int stdout_fd,
int stderr_fd)
- : SimObject(name)
+ : SimObject(nm)
{
// allocate memory space
- memory = new MainMemory(name + ".MainMem");
+ memory = new MainMemory(nm + ".MainMem");
// allocate initial register file
init_regs = new RegFile;
@@ -88,6 +88,7 @@ Process::Process(const string &name,
fd_map[i] = -1;
}
+ mmap_start = mmap_end = 0;
// other parameters will be initialized when the program is loaded
}
@@ -252,10 +253,10 @@ copyStringArray(vector<string> &strings, Addr array_ptr, Addr data_ptr,
memory->access(Write, array_ptr, &data_ptr, sizeof(Addr));
}
-LiveProcess::LiveProcess(const string &name, ObjectFile *objFile,
+LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile,
int stdin_fd, int stdout_fd, int stderr_fd,
vector<string> &argv, vector<string> &envp)
- : Process(name, stdin_fd, stdout_fd, stderr_fd)
+ : Process(nm, stdin_fd, stdout_fd, stderr_fd)
{
prog_fname = argv[0];
@@ -339,7 +340,7 @@ LiveProcess::LiveProcess(const string &name, ObjectFile *objFile,
LiveProcess *
-LiveProcess::create(const string &name,
+LiveProcess::create(const string &nm,
int stdin_fd, int stdout_fd, int stderr_fd,
vector<string> &argv, vector<string> &envp)
{
@@ -353,13 +354,13 @@ LiveProcess::create(const string &name,
if (objFile->getArch() == ObjectFile::Alpha) {
switch (objFile->getOpSys()) {
case ObjectFile::Tru64:
- process = new AlphaTru64Process(name, objFile,
+ process = new AlphaTru64Process(nm, objFile,
stdin_fd, stdout_fd, stderr_fd,
argv, envp);
break;
case ObjectFile::Linux:
- process = new AlphaLinuxProcess(name, objFile,
+ process = new AlphaLinuxProcess(nm, objFile,
stdin_fd, stdout_fd, stderr_fd,
argv, envp);
break;
diff --git a/sim/process.hh b/sim/process.hh
index 3bcc65da6..1ab43cd62 100644
--- a/sim/process.hh
+++ b/sim/process.hh
@@ -42,6 +42,7 @@
#include "sim/sim_object.hh"
#include "sim/stats.hh"
#include "base/statistics.hh"
+#include "base/trace.hh"
class ExecContext;
class FunctionalMemory;
@@ -104,7 +105,7 @@ class Process : public SimObject
protected:
// constructor
- Process(const std::string &name,
+ Process(const std::string &nm,
int stdin_fd, // initial I/O descriptors
int stdout_fd,
int stderr_fd);
@@ -175,7 +176,7 @@ class ObjectFile;
class LiveProcess : public Process
{
protected:
- LiveProcess(const std::string &name, ObjectFile *objFile,
+ LiveProcess(const std::string &nm, ObjectFile *objFile,
int stdin_fd, int stdout_fd, int stderr_fd,
std::vector<std::string> &argv,
std::vector<std::string> &envp);
@@ -184,7 +185,7 @@ class LiveProcess : public Process
// this function is used to create the LiveProcess object, since
// we can't tell which subclass of LiveProcess to use until we
// open and look at the object file.
- static LiveProcess *create(const std::string &name,
+ static LiveProcess *create(const std::string &nm,
int stdin_fd, int stdout_fd, int stderr_fd,
std::vector<std::string> &argv,
std::vector<std::string> &envp);
diff --git a/sim/syscall_emul.cc b/sim/syscall_emul.cc
index a0cbdf414..ae865be86 100644
--- a/sim/syscall_emul.cc
+++ b/sim/syscall_emul.cc
@@ -47,17 +47,17 @@ SyscallDesc::doSyscall(int callnum, Process *process, ExecContext *xc)
DPRINTFR(SyscallVerbose, "%s: syscall %s called\n",
xc->cpu->name(), name);
- int retval = (*funcPtr)(this, callnum, process, xc);
+ SyscallReturn retval = (*funcPtr)(this, callnum, process, xc);
DPRINTFR(SyscallVerbose, "%s: syscall %s returns %d\n",
- xc->cpu->name(), name, retval);
+ xc->cpu->name(), name, retval.value());
- if (!((flags & SyscallDesc::SuppressReturnValue) && retval == 0))
+ if (!(flags & SyscallDesc::SuppressReturnValue))
xc->setSyscallReturn(retval);
}
-int
+SyscallReturn
unimplementedFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -70,7 +70,7 @@ unimplementedFunc(SyscallDesc *desc, int callnum, Process *process,
}
-int
+SyscallReturn
ignoreFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -79,47 +79,49 @@ ignoreFunc(SyscallDesc *desc, int callnum, Process *process,
<< ", " << xc->getSyscallArg(1)
<< ", ...)" << endl;
- return 0;
+ return SyscallReturn(0);
}
-int
+SyscallReturn
exitFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
new SimExitEvent("syscall caused exit", xc->getSyscallArg(0) & 0xff);
- return 1;
+ return SyscallReturn(1);
}
-int
+SyscallReturn
getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
- return VMPageSize;
+ return SyscallReturn(VMPageSize);
}
-int
+SyscallReturn
obreakFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
// change brk addr to first arg
Addr new_brk = xc->getSyscallArg(0);
if (new_brk != 0)
+ {
p->brk_point = xc->getSyscallArg(0);
- return p->brk_point;
+ }
+ return SyscallReturn(p->brk_point);
}
-int
+SyscallReturn
closeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
int fd = p->sim_fd(xc->getSyscallArg(0));
- return close(fd);
+ return SyscallReturn(close(fd));
}
-int
+SyscallReturn
readFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
int fd = p->sim_fd(xc->getSyscallArg(0));
@@ -131,10 +133,10 @@ readFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
if (bytes_read != -1)
bufArg.copyOut(xc->mem);
- return bytes_read;
+ return SyscallReturn(bytes_read);
}
-int
+SyscallReturn
writeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
int fd = p->sim_fd(xc->getSyscallArg(0));
@@ -147,11 +149,11 @@ writeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
fsync(fd);
- return bytes_written;
+ return SyscallReturn(bytes_written);
}
-int
+SyscallReturn
lseekFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
int fd = p->sim_fd(xc->getSyscallArg(0));
@@ -160,21 +162,22 @@ lseekFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
off_t result = lseek(fd, offs, whence);
- return (result == (off_t)-1) ? -errno : result;
+ return (result == (off_t)-1) ? SyscallReturn(-errno) :
+ SyscallReturn(result);
}
-int
+SyscallReturn
munmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
// given that we don't really implement mmap, munmap is really easy
- return 0;
+ return SyscallReturn(0);
}
const char *hostname = "m5.eecs.umich.edu";
-int
+SyscallReturn
gethostnameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
int name_len = xc->getSyscallArg(1);
@@ -184,35 +187,35 @@ gethostnameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
name.copyOut(xc->mem);
- return 0;
+ return SyscallReturn(0);
}
-int
+SyscallReturn
unlinkFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
std::string path;
if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault)
- return -EFAULT;
+ return (TheISA::IntReg)-EFAULT;
int result = unlink(path.c_str());
- return (result == -1) ? -errno : result;
+ return (result == -1) ? SyscallReturn(-errno) : SyscallReturn(result);
}
-int
+SyscallReturn
renameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
std::string old_name;
if (xc->mem->readString(old_name, xc->getSyscallArg(0)) != No_Fault)
- return -EFAULT;
+ return SyscallReturn(-EFAULT);
std::string new_name;
if (xc->mem->readString(new_name, xc->getSyscallArg(1)) != No_Fault)
- return -EFAULT;
+ return SyscallReturn(-EFAULT);
- int result = rename(old_name.c_str(),new_name.c_str());
- return (result == -1) ? -errno : result;
+ int64_t result = rename(old_name.c_str(),new_name.c_str());
+ return (result == -1) ? SyscallReturn(-errno) : SyscallReturn(result);
}
diff --git a/sim/syscall_emul.hh b/sim/syscall_emul.hh
index 831708a21..5f1b8144e 100644
--- a/sim/syscall_emul.hh
+++ b/sim/syscall_emul.hh
@@ -54,7 +54,7 @@ class SyscallDesc {
public:
/// Typedef for target syscall handler functions.
- typedef int (*FuncPtr)(SyscallDesc *, int num,
+ typedef SyscallReturn (*FuncPtr)(SyscallDesc *, int num,
Process *, ExecContext *);
const char *name; //!< Syscall name (e.g., "open").
@@ -158,46 +158,46 @@ class TypedBufferArg : public BaseBufferArg
/// Handler for unimplemented syscalls that we haven't thought about.
-int unimplementedFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Handler for unimplemented syscalls that we never intend to
/// implement (signal handling, etc.) and should not affect the correct
/// behavior of the program. Print a warning only if the appropriate
/// trace flag is enabled. Return success to the target program.
-int ignoreFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn ignoreFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target exit() handler: terminate simulation.
-int exitFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn exitFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target getpagesize() handler.
-int getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target obreak() handler: set brk address.
-int obreakFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn obreakFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target close() handler.
-int closeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn closeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target read() handler.
-int readFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn readFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target write() handler.
-int writeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn writeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target lseek() handler.
-int lseekFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn lseekFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target munmap() handler.
-int munmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn munmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target gethostname() handler.
-int gethostnameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn gethostnameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target unlink() handler.
-int unlinkFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn unlinkFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// Target rename() handler.
-int renameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
+SyscallReturn renameFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc);
/// This struct is used to build an target-OS-dependent table that
/// maps the target's open() flags to the host open() flags.
@@ -240,7 +240,7 @@ getElapsedTime(T1 &sec, T2 &usec)
/// only to find out if their stdout is a tty, to determine whether to
/// do line or block buffering.
template <class OS>
-int
+SyscallReturn
ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -251,7 +251,7 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
if (fd < 0 || process->sim_fd(fd) < 0) {
// doesn't map to any simulator fd: not a valid target fd
- return -EBADF;
+ return SyscallReturn(-EBADF);
}
switch (req) {
@@ -263,7 +263,7 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
case OS::TIOCGETC:
case OS::TIOCGETS:
case OS::TIOCGETA:
- return -ENOTTY;
+ return SyscallReturn(-ENOTTY);
default:
fatal("Unsupported ioctl call: ioctl(%d, 0x%x, ...) @ 0x%llx\n", fd, req, xc->readPC());
@@ -272,20 +272,20 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *process,
/// Target open() handler.
template <class OS>
-int
+SyscallReturn
openFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
std::string path;
if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault)
- return -EFAULT;
+ return SyscallReturn(-EFAULT);
if (path == "/dev/sysdev0") {
// This is a memory-mapped high-resolution timer device on Alpha.
// We don't support it, so just punt.
DCOUT(SyscallWarnings) << "Ignoring open(" << path << ", ...)" << std::endl;
- return -ENOENT;
+ return SyscallReturn(-ENOENT);
}
int tgtFlags = xc->getSyscallArg(1);
@@ -311,58 +311,58 @@ openFunc(SyscallDesc *desc, int callnum, Process *process,
// open the file
int fd = open(path.c_str(), hostFlags, mode);
- return (fd == -1) ? -errno : process->open_fd(fd);
+ return (fd == -1) ? SyscallReturn(-errno) : SyscallReturn(process->open_fd(fd));
}
/// Target stat() handler.
template <class OS>
-int
+SyscallReturn
statFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
std::string path;
if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault)
- return -EFAULT;
+ return SyscallReturn(-EFAULT);
struct stat hostBuf;
int result = stat(path.c_str(), &hostBuf);
if (result < 0)
- return -errno;
+ return SyscallReturn(errno);
OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
- return 0;
+ return SyscallReturn(0);
}
/// Target lstat() handler.
template <class OS>
-int
+SyscallReturn
lstatFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
std::string path;
if (xc->mem->readString(path, xc->getSyscallArg(0)) != No_Fault)
- return -EFAULT;
+ return SyscallReturn(-EFAULT);
struct stat hostBuf;
int result = lstat(path.c_str(), &hostBuf);
if (result < 0)
- return -errno;
+ return SyscallReturn(-errno);
OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
- return 0;
+ return SyscallReturn(0);
}
/// Target fstat() handler.
template <class OS>
-int
+SyscallReturn
fstatFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -371,17 +371,17 @@ fstatFunc(SyscallDesc *desc, int callnum, Process *process,
// DPRINTFR(SyscallVerbose, "fstat(%d, ...)\n", fd);
if (fd < 0)
- return -EBADF;
+ return SyscallReturn(-EBADF);
struct stat hostBuf;
int result = fstat(fd, &hostBuf);
if (result < 0)
- return -errno;
+ return SyscallReturn(-errno);
OS::copyOutStatBuf(xc->mem, xc->getSyscallArg(1), &hostBuf);
- return 0;
+ return SyscallReturn(0);
}
@@ -398,7 +398,7 @@ fstatFunc(SyscallDesc *desc, int callnum, Process *process,
/// file descriptor, and fail (or implement!) a non-anonymous mmap to
/// anything else.
template <class OS>
-int
+SyscallReturn
mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
Addr start = xc->getSyscallArg(0);
@@ -419,12 +419,12 @@ mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
"This will break if not /dev/zero.", xc->getSyscallArg(4));
}
- return start;
+ return SyscallReturn(start);
}
/// Target getrlimit() handler.
template <class OS>
-int
+SyscallReturn
getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -444,12 +444,12 @@ getrlimitFunc(SyscallDesc *desc, int callnum, Process *process,
}
rlp.copyOut(xc->mem);
- return 0;
+ return SyscallReturn(0);
}
/// Target gettimeofday() handler.
template <class OS>
-int
+SyscallReturn
gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -460,13 +460,13 @@ gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process,
tp.copyOut(xc->mem);
- return 0;
+ return SyscallReturn(0);
}
/// Target getrusage() function.
template <class OS>
-int
+SyscallReturn
getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
ExecContext *xc)
{
@@ -501,7 +501,7 @@ getrusageFunc(SyscallDesc *desc, int callnum, Process *process,
rup.copyOut(xc->mem);
- return 0;
+ return SyscallReturn(0);
}
#endif // __SIM_SYSCALL_EMUL_HH__