cpu: implements vector registers
[gem5.git] / src / sim / syscall_emul.cc
index 13ad043111c53ea5cd8533de331d757b0c1e4db9..d628365328e88d57baf4373cbc6b0044519dcd67 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <string>
+#include <cstdio>
 #include <iostream>
+#include <string>
 
-#include "sim/syscall_emul.hh"
+#include "arch/utility.hh"
 #include "base/chunk_generator.hh"
 #include "base/trace.hh"
 #include "config/the_isa.hh"
-#include "cpu/thread_context.hh"
 #include "cpu/base.hh"
+#include "cpu/thread_context.hh"
+#include "debug/SyscallVerbose.hh"
 #include "mem/page_table.hh"
 #include "sim/process.hh"
-#include "sim/system.hh"
 #include "sim/sim_exit.hh"
+#include "sim/syscall_emul.hh"
+#include "sim/system.hh"
 
 using namespace std;
 using namespace TheISA;
@@ -52,18 +55,31 @@ using namespace TheISA;
 void
 SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
 {
-    DPRINTFR(SyscallVerbose,
-             "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
-             curTick, tc->getCpuPtr()->name(), name,
-             process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1),
-             process->getSyscallArg(tc, 2), process->getSyscallArg(tc, 3));
+    if (DTRACE(SyscallVerbose)) {
+        int index = 0;
+        IntReg arg[4] M5_VAR_USED;
+
+        // we can't just put the calls to getSyscallArg() in the
+        // DPRINTF arg list, because C++ doesn't guarantee their order
+        for (int i = 0; i < 4; ++i)
+            arg[i] = process->getSyscallArg(tc, index);
+
+        DPRINTFNR("%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
+                  curTick(), tc->getCpuPtr()->name(), name,
+                  arg[0], arg[1], arg[2], arg[3]);
+    }
 
     SyscallReturn retval = (*funcPtr)(this, callnum, process, tc);
 
-    DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n",
-             curTick,tc->getCpuPtr()->name(), name, retval.value());
+    if (retval.needsRetry()) {
+        DPRINTFS(SyscallVerbose, tc->getCpuPtr(), "syscall %s needs retry\n",
+                 name);
+    } else {
+        DPRINTFS(SyscallVerbose, tc->getCpuPtr(), "syscall %s returns %d\n",
+                 name, retval.encodedValue());
+    }
 
-    if (!(flags & SyscallDesc::SuppressReturnValue))
+    if (!(flags & SyscallDesc::SuppressReturnValue) && !retval.needsRetry())
         process->setSyscallReturn(tc, retval);
 }
 
@@ -82,8 +98,19 @@ SyscallReturn
 ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
            ThreadContext *tc)
 {
-    warn("ignoring syscall %s(%d, %d, ...)", desc->name,
-         process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1));
+    int index = 0;
+    const char *extra_text = "";
+
+    if (desc->warnOnce()) {
+        if (desc->warned)
+            return 0;
+
+        desc->warned = true;
+        extra_text = "\n      (further warnings will be suppressed)";
+    }
+
+    warn("ignoring syscall %s(%d, ...)%s", desc->name,
+         process->getSyscallArg(tc, index), extra_text);
 
     return 0;
 }
@@ -95,8 +122,9 @@ exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
 {
     if (process->system->numRunningContexts() == 1) {
         // Last running context... exit simulator
+        int index = 0;
         exitSimLoop("target called exit()",
-                    process->getSyscallArg(tc, 0) & 0xff);
+                    process->getSyscallArg(tc, index) & 0xff);
     } else {
         // other running threads... just halt this one
         tc->halt();
@@ -110,10 +138,17 @@ SyscallReturn
 exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
               ThreadContext *tc)
 {
-    // really should just halt all thread contexts belonging to this
-    // process in case there's another process running...
-    exitSimLoop("target called exit()",
-                process->getSyscallArg(tc, 0) & 0xff);
+    // halt all threads belonging to this process
+    for (auto i: process->contextIds) {
+        process->system->getThreadContext(i)->halt();
+    }
+
+    if (!process->system->numRunningContexts()) {
+        // all threads belonged to this process... exit simulator
+        int index = 0;
+        exitSimLoop("target called exit()",
+                    process->getSyscallArg(tc, index) & 0xff);
+    }
 
     return 1;
 }
@@ -122,7 +157,7 @@ exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
 SyscallReturn
 getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    return (int)VMPageSize;
+    return (int)PageBytes;
 }
 
 
@@ -130,7 +165,8 @@ SyscallReturn
 brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     // change brk addr to first arg
-    Addr new_brk = p->getSyscallArg(tc, 0);
+    int index = 0;
+    Addr new_brk = p->getSyscallArg(tc, index);
 
     // in Linux at least, brk(0) returns the current break value
     // (note that the syscall and the glibc function have different behavior)
@@ -140,26 +176,25 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
     if (new_brk > p->brk_point) {
         // might need to allocate some new pages
         for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
-                                VMPageSize); !gen.done(); gen.next()) {
+                                PageBytes); !gen.done(); gen.next()) {
             if (!p->pTable->translate(gen.addr()))
-                p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
-                                    VMPageSize);
+                p->allocateMem(roundDown(gen.addr(), PageBytes), PageBytes);
 
             // if the address is already there, zero it out
             else {
                 uint8_t zero  = 0;
-                TranslatingPort *tp = tc->getMemPort();
+                SETranslatingPortProxy &tp = tc->getMemProxy();
 
                 // split non-page aligned accesses
-                Addr next_page = roundUp(gen.addr(), VMPageSize);
+                Addr next_page = roundUp(gen.addr(), PageBytes);
                 uint32_t size_needed = next_page - gen.addr();
-                tp->memsetBlob(gen.addr(), zero, size_needed);
-                if (gen.addr() + VMPageSize > next_page &&
+                tp.memsetBlob(gen.addr(), zero, size_needed);
+                if (gen.addr() + PageBytes > next_page &&
                     next_page < new_brk &&
                     p->pTable->translate(next_page))
                 {
-                    size_needed = VMPageSize - size_needed;
-                    tp->memsetBlob(next_page, zero, size_needed);
+                    size_needed = PageBytes - size_needed;
+                    tp.memsetBlob(next_page, zero, size_needed);
                 }
             }
         }
@@ -174,10 +209,18 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int target_fd = p->getSyscallArg(tc, 0);
-    int status = close(p->sim_fd(target_fd));
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
+
+    int status = 0;
+    if (sim_fd > 2)
+        status = close(sim_fd);
     if (status >= 0)
-        p->free_fd(target_fd);
+        p->resetFDEntry(tgt_fd);
     return status;
 }
 
@@ -185,14 +228,20 @@ closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int fd = p->sim_fd(p->getSyscallArg(tc, 0));
-    int nbytes = p->getSyscallArg(tc, 2);
-    BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    int nbytes = p->getSyscallArg(tc, index);
+    BufferArg bufArg(bufPtr, nbytes);
+
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
 
-    int bytes_read = read(fd, bufArg.bufferPtr(), nbytes);
+    int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
 
     if (bytes_read != -1)
-        bufArg.copyOut(tc->getMemPort());
+        bufArg.copyOut(tc->getMemProxy());
 
     return bytes_read;
 }
@@ -200,15 +249,21 @@ readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int fd = p->sim_fd(p->getSyscallArg(tc, 0));
-    int nbytes = p->getSyscallArg(tc, 2);
-    BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    int nbytes = p->getSyscallArg(tc, index);
+    BufferArg bufArg(bufPtr, nbytes);
+
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
 
-    bufArg.copyIn(tc->getMemPort());
+    bufArg.copyIn(tc->getMemProxy());
 
-    int bytes_written = write(fd, bufArg.bufferPtr(), nbytes);
+    int bytes_written = write(sim_fd, bufArg.bufferPtr(), nbytes);
 
-    fsync(fd);
+    fsync(sim_fd);
 
     return bytes_written;
 }
@@ -217,11 +272,16 @@ writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int fd = p->sim_fd(p->getSyscallArg(tc, 0));
-    uint64_t offs = p->getSyscallArg(tc, 1);
-    int whence = p->getSyscallArg(tc, 2);
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+    uint64_t offs = p->getSyscallArg(tc, index);
+    int whence = p->getSyscallArg(tc, index);
+
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
 
-    off_t result = lseek(fd, offs, whence);
+    off_t result = lseek(sim_fd, offs, whence);
 
     return (result == (off_t)-1) ? -errno : result;
 }
@@ -230,15 +290,20 @@ lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 _llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int fd = p->sim_fd(p->getSyscallArg(tc, 0));
-    uint64_t offset_high = p->getSyscallArg(tc, 1);
-    uint32_t offset_low = p->getSyscallArg(tc, 2);
-    Addr result_ptr = p->getSyscallArg(tc, 3);
-    int whence = p->getSyscallArg(tc, 4);
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+    uint64_t offset_high = p->getSyscallArg(tc, index);
+    uint32_t offset_low = p->getSyscallArg(tc, index);
+    Addr result_ptr = p->getSyscallArg(tc, index);
+    int whence = p->getSyscallArg(tc, index);
+
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
 
     uint64_t offset = (offset_high << 32) | offset_low;
 
-    uint64_t result = lseek(fd, offset, whence);
+    uint64_t result = lseek(sim_fd, offset, whence);
     result = TheISA::htog(result);
 
     if (result == (off_t)-1) {
@@ -251,12 +316,9 @@ _llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
         // target platform
         BufferArg result_buf(result_ptr, sizeof(result));
         memcpy(result_buf.bufferPtr(), &result, sizeof(result));
-        result_buf.copyOut(tc->getMemPort());
+        result_buf.copyOut(tc->getMemProxy());
         return 0;
     }
-
-
-    return (result == (off_t)-1) ? -errno : result;
 }
 
 
@@ -273,12 +335,14 @@ const char *hostname = "m5.eecs.umich.edu";
 SyscallReturn
 gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
-    int name_len = p->getSyscallArg(tc, 1);
-    BufferArg name(p->getSyscallArg(tc, 0), name_len);
+    int index = 0;
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    int name_len = p->getSyscallArg(tc, index);
+    BufferArg name(bufPtr, name_len);
 
     strncpy((char *)name.bufferPtr(), hostname, name_len);
 
-    name.copyOut(tc->getMemPort());
+    name.copyOut(tc->getMemProxy());
 
     return 0;
 }
@@ -287,8 +351,10 @@ SyscallReturn
 getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int result = 0;
-    unsigned long size = p->getSyscallArg(tc, 1);
-    BufferArg buf(p->getSyscallArg(tc, 0), size);
+    int index = 0;
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    unsigned long size = p->getSyscallArg(tc, index);
+    BufferArg buf(bufPtr, size);
 
     // Is current working directory defined?
     string cwd = p->getcwd();
@@ -309,40 +375,57 @@ getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
         }
     }
 
-    buf.copyOut(tc->getMemPort());
+    buf.copyOut(tc->getMemProxy());
 
     return (result == -1) ? -errno : result;
 }
 
+/// Target open() handler.
+SyscallReturn
+readlinkFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+         ThreadContext *tc)
+{
+    return readlinkFunc(desc, callnum, process, tc, 0);
+}
 
 SyscallReturn
-readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
+        int index)
 {
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
-        return (TheISA::IntReg)-EFAULT;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
 
     // Adjust path for current working directory
     path = p->fullPath(path);
 
-    size_t bufsiz = p->getSyscallArg(tc, 2);
-    BufferArg buf(p->getSyscallArg(tc, 1), bufsiz);
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    size_t bufsiz = p->getSyscallArg(tc, index);
+
+    BufferArg buf(bufPtr, bufsiz);
 
     int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
 
-    buf.copyOut(tc->getMemPort());
+    buf.copyOut(tc->getMemProxy());
 
     return (result == -1) ? -errno : result;
 }
 
 SyscallReturn
 unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+{
+    return unlinkHelper(desc, num, p, tc, 0);
+}
+
+SyscallReturn
+unlinkHelper(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
+           int index)
 {
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
-        return (TheISA::IntReg)-EFAULT;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
 
     // Adjust path for current working directory
     path = p->fullPath(path);
@@ -357,13 +440,14 @@ mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
-        return (TheISA::IntReg)-EFAULT;
+    int index = 0;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
 
     // Adjust path for current working directory
     path = p->fullPath(path);
 
-    mode_t mode = p->getSyscallArg(tc, 1);
+    mode_t mode = p->getSyscallArg(tc, index);
 
     int result = mkdir(path.c_str(), mode);
     return (result == -1) ? -errno : result;
@@ -374,12 +458,13 @@ renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     string old_name;
 
-    if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, 0)))
+    int index = 0;
+    if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     string new_name;
 
-    if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, 1)))
+    if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     // Adjust path for current working directory
@@ -395,10 +480,11 @@ truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
+    int index = 0;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
-    off_t length = p->getSyscallArg(tc, 1);
+    off_t length = p->getSyscallArg(tc, index);
 
     // Adjust path for current working directory
     path = p->fullPath(path);
@@ -411,14 +497,38 @@ SyscallReturn
 ftruncateFunc(SyscallDesc *desc, int num,
               LiveProcess *process, ThreadContext *tc)
 {
-    int fd = process->sim_fd(process->getSyscallArg(tc, 0));
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
+    off_t length = process->getSyscallArg(tc, index);
 
-    if (fd < 0)
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    off_t length = process->getSyscallArg(tc, 1);
+    int result = ftruncate(sim_fd, length);
+    return (result == -1) ? -errno : result;
+}
+
+SyscallReturn
+truncate64Func(SyscallDesc *desc, int num,
+                LiveProcess *process, ThreadContext *tc)
+{
+    int index = 0;
+    string path;
+
+    if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index)))
+       return -EFAULT;
 
-    int result = ftruncate(fd, length);
+    int64_t length = process->getSyscallArg(tc, index, 64);
+
+    // Adjust path for current working directory
+    path = process->fullPath(path);
+
+#if NO_STAT64
+    int result = truncate(path.c_str(), length);
+#else
+    int result = truncate64(path.c_str(), length);
+#endif
     return (result == -1) ? -errno : result;
 }
 
@@ -426,15 +536,19 @@ SyscallReturn
 ftruncate64Func(SyscallDesc *desc, int num,
                 LiveProcess *process, ThreadContext *tc)
 {
-    int fd = process->sim_fd(process->getSyscallArg(tc, 0));
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
+    int64_t length = process->getSyscallArg(tc, index, 64);
 
-    if (fd < 0)
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    // I'm not sure why, but the length argument is in arg reg 3
-    loff_t length = process->getSyscallArg(tc, 3);
-
-    int result = ftruncate64(fd, length);
+#if NO_STAT64
+    int result = ftruncate(sim_fd, length);
+#else
+    int result = ftruncate64(sim_fd, length);
+#endif
     return (result == -1) ? -errno : result;
 }
 
@@ -454,13 +568,14 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
+    int index = 0;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     /* XXX endianess */
-    uint32_t owner = p->getSyscallArg(tc, 1);
+    uint32_t owner = p->getSyscallArg(tc, index);
     uid_t hostOwner = owner;
-    uint32_t group = p->getSyscallArg(tc, 2);
+    uint32_t group = p->getSyscallArg(tc, index);
     gid_t hostGroup = group;
 
     // Adjust path for current working directory
@@ -473,18 +588,20 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 SyscallReturn
 fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 {
-    int fd = process->sim_fd(process->getSyscallArg(tc, 0));
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
 
-    if (fd < 0)
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
     /* XXX endianess */
-    uint32_t owner = process->getSyscallArg(tc, 1);
+    uint32_t owner = process->getSyscallArg(tc, index);
     uid_t hostOwner = owner;
-    uint32_t group = process->getSyscallArg(tc, 2);
+    uint32_t group = process->getSyscallArg(tc, index);
     gid_t hostGroup = group;
 
-    int result = fchown(fd, hostOwner, hostGroup);
+    int result = fchown(sim_fd, hostOwner, hostGroup);
     return (result == -1) ? -errno : result;
 }
 
@@ -492,15 +609,18 @@ fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 SyscallReturn
 dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 {
-    int fd = process->sim_fd(process->getSyscallArg(tc, 0));
-    if (fd < 0)
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
+
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    Process::FdMap *fdo = process->sim_fd_obj(process->getSyscallArg(tc, 0));
+    FDEntry *fde = process->getFDEntry(tgt_fd);
 
-    int result = dup(fd);
+    int result = dup(sim_fd);
     return (result == -1) ? -errno :
-        process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false);
+        process->allocFD(result, fde->filename, fde->flags, fde->mode, false);
 }
 
 
@@ -508,17 +628,19 @@ SyscallReturn
 fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
           ThreadContext *tc)
 {
-    int fd = process->getSyscallArg(tc, 0);
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
 
-    if (fd < 0 || process->sim_fd(fd) < 0)
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    int cmd = process->getSyscallArg(tc, 1);
+    int cmd = process->getSyscallArg(tc, index);
     switch (cmd) {
       case 0: // F_DUPFD
         // if we really wanted to support this, we'd need to do it
         // in the target fd space.
-        warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
+        warn("fcntl(%d, F_DUPFD) not supported, error returned\n", tgt_fd);
         return -EMFILE;
 
       case 1: // F_GETFD (get close-on-exec flag)
@@ -529,15 +651,15 @@ fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
       case 4: // F_SETFL (set file flags)
         // not sure if this is totally valid, but we'll pass it through
         // to the underlying OS
-        warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
-        return fcntl(process->sim_fd(fd), cmd);
+        warn("fcntl(%d, %d) passed through to host\n", tgt_fd, cmd);
+        return fcntl(sim_fd, cmd);
         // return 0;
 
       case 7: // F_GETLK  (get lock)
       case 8: // F_SETLK  (set lock)
       case 9: // F_SETLKW (set lock and wait)
         // don't mess with file locking... just act like it's OK
-        warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
+        warn("File lock call (fcntl(%d, %d)) ignored.\n", tgt_fd, cmd);
         return 0;
 
       default:
@@ -550,27 +672,30 @@ SyscallReturn
 fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process,
             ThreadContext *tc)
 {
-    int fd = process->getSyscallArg(tc, 0);
+    int index = 0;
+    int tgt_fd = process->getSyscallArg(tc, index);
 
-    if (fd < 0 || process->sim_fd(fd) < 0)
+    int sim_fd = process->getSimFD(tgt_fd);
+    if (sim_fd < 0)
         return -EBADF;
 
-    int cmd = process->getSyscallArg(tc, 1);
+    int cmd = process->getSyscallArg(tc, index);
     switch (cmd) {
       case 33: //F_GETLK64
-        warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd);
+        warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", tgt_fd);
         return -EMFILE;
 
       case 34: // F_SETLK64
       case 35: // F_SETLKW64
-        warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd);
+        warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n",
+             tgt_fd);
         return -EMFILE;
 
       default:
         // not sure if this is totally valid, but we'll pass it through
         // to the underlying OS
-        warn("fcntl64(%d, %d) passed through to host\n", fd, cmd);
-        return fcntl(process->sim_fd(fd), cmd);
+        warn("fcntl64(%d, %d) passed through to host\n", tgt_fd, cmd);
+        return fcntl(sim_fd, cmd);
         // return 0;
     }
 }
@@ -587,8 +712,8 @@ pipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
         return pipe_retval;
     }
 
-    sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true);
-    sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
+    sim_fds[0] = process->allocFD(fds[0], "PIPE-READ", O_WRONLY, -1, true);
+    sim_fds[1] = process->allocFD(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
 
     process->setReadPipeSource(sim_fds[0], sim_fds[1]);
     // Alpha Linux convention for pipe() is that fd[0] is returned as
@@ -639,7 +764,8 @@ setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
            ThreadContext *tc)
 {
     // can't fathom why a benchmark would call this.
-    warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, 0));
+    int index = 0;
+    warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index));
     return 0;
 }
 
@@ -695,17 +821,20 @@ SyscallReturn
 cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
            ThreadContext *tc)
 {
+    int index = 0;
+    IntReg flags = process->getSyscallArg(tc, index);
+    IntReg newStack = process->getSyscallArg(tc, index);
+
     DPRINTF(SyscallVerbose, "In sys_clone:\n");
-    DPRINTF(SyscallVerbose, " Flags=%llx\n", process->getSyscallArg(tc, 0));
-    DPRINTF(SyscallVerbose, " Child stack=%llx\n",
-            process->getSyscallArg(tc, 1));
+    DPRINTF(SyscallVerbose, " Flags=%llx\n", flags);
+    DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack);
 
 
-    if (process->getSyscallArg(tc, 0) != 0x10f00) {
+    if (flags != 0x10f00) {
         warn("This sys_clone implementation assumes flags "
              "CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD "
              "(0x10f00), and may not work correctly with given flags "
-             "0x%llx\n", process->getSyscallArg(tc, 0));
+             "0x%llx\n", flags);
     }
 
     ThreadContext* ctc; // child thread context
@@ -729,16 +858,18 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
             ctc->setMiscReg(MISCREG_CWP, 0);
             ctc->setIntReg(NumIntArchRegs + 7, 0);
             ctc->setMiscRegNoEffect(MISCREG_TL, 0);
-            ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
+            ctc->setMiscReg(MISCREG_ASI, ASI_PRIMARY);
 
             for (int y = 8; y < 32; y++)
                 ctc->setIntReg(y, tc->readIntReg(y));
+        #elif THE_ISA == ARM_ISA
+            TheISA::copyRegs(tc, ctc);
         #else
             fatal("sys_clone is not implemented for this ISA\n");
         #endif
 
         // Set up stack register
-        ctc->setIntReg(TheISA::StackPointerReg, process->getSyscallArg(tc, 1));
+        ctc->setIntReg(TheISA::StackPointerReg, newStack);
 
         // Set up syscall return values in parent and child
         ctc->setIntReg(ReturnValueReg, 0); // return value, child
@@ -755,9 +886,7 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
             ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1);
         #endif
 
-        ctc->setPC(tc->readNextPC());
-        ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst));
-        ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst));
+        ctc->pcState(tc->nextInstAddr());
 
         ctc->activate();
 
@@ -770,3 +899,26 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
     }
 }
 
+SyscallReturn
+accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc,
+        int index)
+{
+    string path;
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
+
+    // Adjust path for current working directory
+    path = p->fullPath(path);
+
+    mode_t mode = p->getSyscallArg(tc, index);
+
+    int result = access(path.c_str(), mode);
+    return (result == -1) ? -errno : result;
+}
+
+SyscallReturn
+accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc)
+{
+    return accessFunc(desc, callnum, p, tc, 0);
+}
+