X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fsim%2Fsyscall_emul.cc;h=dc8a9a5c884a9830cd26cb203c6643e62b7412a5;hb=0ed3c84c7b05d7d3c9d5f0e3f1c05c20afef93b9;hp=7cffffcf1c3b6fcf7649036d5276d15ed6dcae8a;hpb=2c5fe6f95e64a5a97d56cccc6b8b5417cdd981ae;p=gem5.git diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index 7cffffcf1..dc8a9a5c8 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -36,16 +36,18 @@ #include #include -#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; @@ -58,7 +60,7 @@ SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) #endif DPRINTFR(SyscallVerbose, "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n", - curTick, tc->getCpuPtr()->name(), name, + curTick(), tc->getCpuPtr()->name(), name, process->getSyscallArg(tc, index), process->getSyscallArg(tc, index), process->getSyscallArg(tc, index), @@ -67,7 +69,7 @@ SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc) SyscallReturn retval = (*funcPtr)(this, callnum, process, tc); DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n", - curTick,tc->getCpuPtr()->name(), name, retval.value()); + curTick(),tc->getCpuPtr()->name(), name, retval.value()); if (!(flags & SyscallDesc::SuppressReturnValue)) process->setSyscallReturn(tc, retval); @@ -96,6 +98,18 @@ ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process, } +SyscallReturn +ignoreWarnOnceFunc(SyscallDesc *desc, int callnum, LiveProcess *process, + ThreadContext *tc) +{ + int index = 0; + warn_once("ignoring syscall %s(%d, %d, ...)", desc->name, + process->getSyscallArg(tc, index), process->getSyscallArg(tc, index)); + + return 0; +} + + SyscallReturn exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) @@ -152,13 +166,12 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point, VMPageSize); !gen.done(); gen.next()) { if (!p->pTable->translate(gen.addr())) - p->pTable->allocate(roundDown(gen.addr(), VMPageSize), - VMPageSize); + p->allocateMem(roundDown(gen.addr(), VMPageSize), VMPageSize); // 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); @@ -186,7 +199,10 @@ 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 sim_fd = p->sim_fd(target_fd); + int status = 0; + if (sim_fd > 2) + status = close(sim_fd); if (status >= 0) p->free_fd(target_fd); return status; @@ -205,7 +221,7 @@ readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) int bytes_read = read(fd, bufArg.bufferPtr(), nbytes); if (bytes_read != -1) - bufArg.copyOut(tc->getMemPort()); + bufArg.copyOut(tc->getMemProxy()); return bytes_read; } @@ -219,7 +235,7 @@ writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) int nbytes = p->getSyscallArg(tc, index); BufferArg bufArg(bufPtr, nbytes); - bufArg.copyIn(tc->getMemPort()); + bufArg.copyIn(tc->getMemProxy()); int bytes_written = write(fd, bufArg.bufferPtr(), nbytes); @@ -268,7 +284,7 @@ _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; } @@ -297,7 +313,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; } @@ -306,7 +322,7 @@ SyscallReturn getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) { int result = 0; - int index; + int index = 0; Addr bufPtr = p->getSyscallArg(tc, index); unsigned long size = p->getSyscallArg(tc, index); BufferArg buf(bufPtr, size); @@ -330,7 +346,7 @@ getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) } } - buf.copyOut(tc->getMemPort()); + buf.copyOut(tc->getMemProxy()); return (result == -1) ? -errno : result; } @@ -342,7 +358,7 @@ readlinkFunc(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 (TheISA::IntReg)-EFAULT; // Adjust path for current working directory @@ -355,7 +371,7 @@ 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; } @@ -366,7 +382,7 @@ unlinkFunc(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 (TheISA::IntReg)-EFAULT; // Adjust path for current working directory @@ -383,7 +399,7 @@ mkdirFunc(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 (TheISA::IntReg)-EFAULT; // Adjust path for current working directory @@ -401,12 +417,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 +439,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); @@ -458,15 +474,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; } @@ -480,9 +500,13 @@ ftruncate64Func(SyscallDesc *desc, int num, if (fd < 0) return -EBADF; - loff_t length = process->getSyscallArg(tc, index, 64); + int64_t length = process->getSyscallArg(tc, index, 64); +#if NO_STAT64 + int result = ftruncate(fd, length); +#else int result = ftruncate64(fd, length); +#endif return (result == -1) ? -errno : result; } @@ -503,7 +527,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 */ @@ -790,6 +814,8 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 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 +838,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();