process.cc revision 11728:f099627c6750
1/* 2 * Copyright (c) 2005 The Regents of The University of Michigan 3 * Copyright (c) 2007 MIPS Technologies, Inc. 4 * Copyright (c) 2016 The University of Virginia 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer; 11 * redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution; 14 * neither the name of the copyright holders nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Authors: Gabe Black 31 * Korey Sewell 32 * Alec Roelke 33 */ 34 35#include "arch/riscv/linux/process.hh" 36 37#include <map> 38 39#include "arch/riscv/isa_traits.hh" 40#include "arch/riscv/linux/linux.hh" 41#include "base/trace.hh" 42#include "cpu/thread_context.hh" 43#include "debug/SyscallVerbose.hh" 44#include "kern/linux/linux.hh" 45#include "sim/eventq.hh" 46#include "sim/process.hh" 47#include "sim/syscall_emul.hh" 48#include "sim/system.hh" 49 50using namespace std; 51using namespace RiscvISA; 52 53/// Target uname() handler. 54static SyscallReturn 55unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process, 56 ThreadContext *tc) 57{ 58 int index = 0; 59 TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index)); 60 61 strcpy(name->sysname, "Linux"); 62 strcpy(name->nodename,"sim.gem5.org"); 63 strcpy(name->release, "3.0.0"); 64 strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); 65 strcpy(name->machine, "riscv"); 66 67 name.copyOut(tc->getMemProxy()); 68 return 0; 69} 70 71std::map<int, SyscallDesc> RiscvLinuxProcess::syscallDescs = { 72 {17, SyscallDesc("getcwd", getcwdFunc)}, 73 {23, SyscallDesc("dup", dupFunc)}, 74 {25, SyscallDesc("fcntl", fcntl64Func)}, 75 {29, SyscallDesc("ioctl", ioctlFunc<RiscvLinux>)}, 76 {34, SyscallDesc("mkdirat", unimplementedFunc)}, 77 {35, SyscallDesc("unlinkat", unlinkatFunc<RiscvLinux>)}, 78 {37, SyscallDesc("linkat", unimplementedFunc)}, 79 {38, SyscallDesc("renameat", renameatFunc<RiscvLinux>)}, 80 {46, SyscallDesc("ftruncate", ftruncate64Func)}, 81 {48, SyscallDesc("faccessat", faccessatFunc<RiscvLinux>)}, 82 {49, SyscallDesc("chdir", unimplementedFunc)}, 83 {56, SyscallDesc("openat", openatFunc<RiscvLinux>)}, 84 {57, SyscallDesc("close", closeFunc)}, 85 {61, SyscallDesc("getdents", unimplementedFunc)}, 86 {62, SyscallDesc("lseek", lseekFunc)}, 87 {63, SyscallDesc("read", readFunc)}, 88 {64, SyscallDesc("write", writeFunc)}, 89 {66, SyscallDesc("writev", writevFunc<RiscvLinux>)}, 90 {67, SyscallDesc("pread", unimplementedFunc)}, 91 {68, SyscallDesc("pwrite", pwrite64Func<RiscvLinux>)}, 92 {78, SyscallDesc("readlinkat", readlinkatFunc<RiscvLinux>)}, 93 {79, SyscallDesc("fstatat", fstatat64Func<RiscvLinux>)}, 94 {80, SyscallDesc("fstat", fstat64Func<RiscvLinux>)}, 95 {93, SyscallDesc("exit", exitFunc)}, 96 {94, SyscallDesc("exit_group", exitGroupFunc)}, 97 {113, SyscallDesc("clock_gettime", clock_gettimeFunc<RiscvLinux>)}, 98 {129, SyscallDesc("kill", unimplementedFunc)}, 99 {134, SyscallDesc("rt_sigaction", ignoreFunc, SyscallDesc::WarnOnce)}, 100 {135, SyscallDesc("rt_sigprocmask", ignoreFunc, SyscallDesc::WarnOnce)}, 101 {153, SyscallDesc("times", timesFunc<RiscvLinux>)}, 102 {160, SyscallDesc("uname", unameFunc)}, 103 {163, SyscallDesc("getrlimit", getrlimitFunc<RiscvLinux>)}, 104 {164, SyscallDesc("setrlimit", ignoreFunc)}, 105 {165, SyscallDesc("getrusage", getrusageFunc<RiscvLinux>)}, 106 {169, SyscallDesc("gettimeofday", gettimeofdayFunc<RiscvLinux>)}, 107 {172, SyscallDesc("getpid", getpidFunc)}, 108 {174, SyscallDesc("getuid", getuidFunc)}, 109 {175, SyscallDesc("geteuid", geteuidFunc)}, 110 {176, SyscallDesc("getgid", getgidFunc)}, 111 {177, SyscallDesc("getegid", getegidFunc)}, 112 {214, SyscallDesc("brk", brkFunc)}, 113 {215, SyscallDesc("munmap", munmapFunc)}, 114 {216, SyscallDesc("mremap", mremapFunc<RiscvLinux>)}, 115 {222, SyscallDesc("mmap", mmapFunc<RiscvLinux>)}, 116 {226, SyscallDesc("mprotect", ignoreFunc)}, 117 {1024, SyscallDesc("open", openFunc<RiscvLinux>)}, 118 {1025, SyscallDesc("link", unimplementedFunc)}, 119 {1026, SyscallDesc("unlink", unlinkFunc)}, 120 {1030, SyscallDesc("mkdir", mkdirFunc)}, 121 {1033, SyscallDesc("access", accessFunc)}, 122 {1038, SyscallDesc("stat", stat64Func<RiscvLinux>)}, 123 {1039, SyscallDesc("lstat", lstat64Func<RiscvLinux>)}, 124 {1062, SyscallDesc("time", timeFunc<RiscvLinux>)}, 125 {2011, SyscallDesc("getmainvars", unimplementedFunc)}, 126}; 127 128RiscvLinuxProcess::RiscvLinuxProcess(LiveProcessParams * params, 129 ObjectFile *objFile) : RiscvLiveProcess(params, objFile) 130{} 131 132SyscallDesc* 133RiscvLinuxProcess::getDesc(int callnum) 134{ 135 return syscallDescs.find(callnum) != syscallDescs.end() ? 136 &syscallDescs.at(callnum) : nullptr; 137} 138