cpu: implements vector registers
[gem5.git] / src / sim / syscall_emul.cc
index 4461e8b528c8510f5d3e4a3a1023cb974c0351b5..d628365328e88d57baf4373cbc6b0044519dcd67 100644 (file)
 #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;
@@ -53,23 +55,31 @@ using namespace TheISA;
 void
 SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
 {
-#if TRACING_ON
-    int index = 0;
-#endif
-    DPRINTFR(SyscallVerbose,
-             "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
-             curTick, tc->getCpuPtr()->name(), name,
-             process->getSyscallArg(tc, index),
-             process->getSyscallArg(tc, index),
-             process->getSyscallArg(tc, index),
-             process->getSyscallArg(tc, index));
+    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);
 }
 
@@ -89,8 +99,18 @@ ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
            ThreadContext *tc)
 {
     int index = 0;
-    warn("ignoring syscall %s(%d, %d, ...)", desc->name,
-         process->getSyscallArg(tc, index), process->getSyscallArg(tc, index));
+    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;
 }
@@ -118,11 +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...
-    int index = 0;
-    exitSimLoop("target called exit()",
-                process->getSyscallArg(tc, index) & 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;
 }
@@ -131,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;
 }
 
 
@@ -150,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);
                 }
             }
         }
@@ -185,10 +210,17 @@ SyscallReturn
 closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int index = 0;
-    int target_fd = p->getSyscallArg(tc, index);
-    int status = close(p->sim_fd(target_fd));
+    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;
 }
 
@@ -197,15 +229,19 @@ SyscallReturn
 readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int index = 0;
-    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    int tgt_fd = p->getSyscallArg(tc, index);
     Addr bufPtr = p->getSyscallArg(tc, index);
     int nbytes = p->getSyscallArg(tc, index);
     BufferArg bufArg(bufPtr, nbytes);
 
-    int bytes_read = read(fd, bufArg.bufferPtr(), nbytes);
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
+
+    int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
 
     if (bytes_read != -1)
-        bufArg.copyOut(tc->getMemPort());
+        bufArg.copyOut(tc->getMemProxy());
 
     return bytes_read;
 }
@@ -214,16 +250,20 @@ SyscallReturn
 writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int index = 0;
-    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    int tgt_fd = p->getSyscallArg(tc, index);
     Addr bufPtr = p->getSyscallArg(tc, index);
     int nbytes = p->getSyscallArg(tc, index);
     BufferArg bufArg(bufPtr, nbytes);
 
-    bufArg.copyIn(tc->getMemPort());
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
+
+    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;
 }
@@ -233,11 +273,15 @@ SyscallReturn
 lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int index = 0;
-    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    int tgt_fd = p->getSyscallArg(tc, index);
     uint64_t offs = p->getSyscallArg(tc, index);
     int whence = p->getSyscallArg(tc, index);
 
-    off_t result = lseek(fd, offs, whence);
+    int sim_fd = p->getSimFD(tgt_fd);
+    if (sim_fd < 0)
+        return -EBADF;
+
+    off_t result = lseek(sim_fd, offs, whence);
 
     return (result == (off_t)-1) ? -errno : result;
 }
@@ -247,15 +291,19 @@ SyscallReturn
 _llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 {
     int index = 0;
-    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    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) {
@@ -268,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;
 }
 
 
@@ -297,7 +342,7 @@ gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 
     strncpy((char *)name.bufferPtr(), hostname, name_len);
 
-    name.copyOut(tc->getMemPort());
+    name.copyOut(tc->getMemProxy());
 
     return 0;
 }
@@ -330,20 +375,27 @@ 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;
 
-    int index = 0;
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
-        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);
@@ -355,19 +407,25 @@ readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
 
     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;
 
-    int index = 0;
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
-        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);
@@ -383,8 +441,8 @@ mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
     string path;
 
     int index = 0;
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
-        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);
@@ -401,12 +459,12 @@ renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
     string old_name;
 
     int index = 0;
-    if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index)))
+    if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     string new_name;
 
-    if (!tc->getMemPort()->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
@@ -423,7 +481,7 @@ truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
     string path;
 
     int index = 0;
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     off_t length = p->getSyscallArg(tc, index);
@@ -440,14 +498,14 @@ ftruncateFunc(SyscallDesc *desc, int num,
               LiveProcess *process, ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->sim_fd(process->getSyscallArg(tc, index));
+    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, index);
-
-    int result = ftruncate(fd, length);
+    int result = ftruncate(sim_fd, length);
     return (result == -1) ? -errno : result;
 }
 
@@ -458,15 +516,19 @@ truncate64Func(SyscallDesc *desc, int num,
     int index = 0;
     string path;
 
-    if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, index)))
+    if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index)))
        return -EFAULT;
 
-    loff_t length = process->getSyscallArg(tc, index, 64);
+    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;
 }
 
@@ -475,14 +537,18 @@ ftruncate64Func(SyscallDesc *desc, int num,
                 LiveProcess *process, ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->sim_fd(process->getSyscallArg(tc, index));
+    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;
 
-    loff_t length = process->getSyscallArg(tc, index, 64);
-
-    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;
 }
 
@@ -503,7 +569,7 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
     string path;
 
     int index = 0;
-    if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
+    if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
         return -EFAULT;
 
     /* XXX endianess */
@@ -523,9 +589,10 @@ SyscallReturn
 fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->sim_fd(process->getSyscallArg(tc, index));
+    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 */
@@ -534,7 +601,7 @@ fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
     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;
 }
 
@@ -543,15 +610,17 @@ SyscallReturn
 dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->sim_fd(process->getSyscallArg(tc, index));
-    if (fd < 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(fd);
+    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);
 }
 
 
@@ -560,9 +629,10 @@ fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
           ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->getSyscallArg(tc, index);
+    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, index);
@@ -570,7 +640,7 @@ fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
       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)
@@ -581,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:
@@ -603,27 +673,29 @@ fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process,
             ThreadContext *tc)
 {
     int index = 0;
-    int fd = process->getSyscallArg(tc, index);
+    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, 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;
     }
 }
@@ -640,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
@@ -786,10 +858,12 @@ 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
@@ -812,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();
 
@@ -827,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);
+}
+