process.cc revision 11851:824055fe6b30
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_desc.hh"
48#include "sim/syscall_emul.hh"
49#include "sim/system.hh"
50
51using namespace std;
52using namespace RiscvISA;
53
54/// Target uname() handler.
55static SyscallReturn
56unameFunc(SyscallDesc *desc, int callnum, Process *process,
57          ThreadContext *tc)
58{
59    int index = 0;
60    TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
61
62    strcpy(name->sysname, "Linux");
63    strcpy(name->nodename,"sim.gem5.org");
64    strcpy(name->release, "3.0.0");
65    strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
66    strcpy(name->machine, "riscv");
67
68    name.copyOut(tc->getMemProxy());
69    return 0;
70}
71
72std::map<int, SyscallDesc> RiscvLinuxProcess::syscallDescs = {
73    {17, SyscallDesc("getcwd", getcwdFunc)},
74    {23, SyscallDesc("dup", dupFunc)},
75    {25, SyscallDesc("fcntl", fcntl64Func)},
76    {29, SyscallDesc("ioctl", ioctlFunc<RiscvLinux>)},
77    {34, SyscallDesc("mkdirat", unimplementedFunc)},
78    {35, SyscallDesc("unlinkat", unlinkatFunc<RiscvLinux>)},
79    {37, SyscallDesc("linkat", unimplementedFunc)},
80    {38, SyscallDesc("renameat", renameatFunc<RiscvLinux>)},
81    {46, SyscallDesc("ftruncate", ftruncate64Func)},
82    {48, SyscallDesc("faccessat", faccessatFunc<RiscvLinux>)},
83    {49, SyscallDesc("chdir", unimplementedFunc)},
84    {56, SyscallDesc("openat", openatFunc<RiscvLinux>)},
85    {57, SyscallDesc("close", closeFunc)},
86    {61, SyscallDesc("getdents", unimplementedFunc)},
87    {62, SyscallDesc("lseek", lseekFunc)},
88    {63, SyscallDesc("read", readFunc)},
89    {64, SyscallDesc("write", writeFunc)},
90    {66, SyscallDesc("writev", writevFunc<RiscvLinux>)},
91    {67, SyscallDesc("pread", unimplementedFunc)},
92    {68, SyscallDesc("pwrite", pwrite64Func<RiscvLinux>)},
93    {78, SyscallDesc("readlinkat", readlinkatFunc<RiscvLinux>)},
94    {79, SyscallDesc("fstatat", fstatat64Func<RiscvLinux>)},
95    {80, SyscallDesc("fstat", fstat64Func<RiscvLinux>)},
96    {93, SyscallDesc("exit", exitFunc)},
97    {94, SyscallDesc("exit_group", exitGroupFunc)},
98    {113, SyscallDesc("clock_gettime", clock_gettimeFunc<RiscvLinux>)},
99    {129, SyscallDesc("kill", unimplementedFunc)},
100    {134, SyscallDesc("rt_sigaction", ignoreFunc, SyscallDesc::WarnOnce)},
101    {135, SyscallDesc("rt_sigprocmask", ignoreFunc, SyscallDesc::WarnOnce)},
102    {153, SyscallDesc("times", timesFunc<RiscvLinux>)},
103    {160, SyscallDesc("uname", unameFunc)},
104    {163, SyscallDesc("getrlimit", getrlimitFunc<RiscvLinux>)},
105    {164, SyscallDesc("setrlimit", ignoreFunc)},
106    {165, SyscallDesc("getrusage", getrusageFunc<RiscvLinux>)},
107    {169, SyscallDesc("gettimeofday", gettimeofdayFunc<RiscvLinux>)},
108    {172, SyscallDesc("getpid", getpidFunc)},
109    {174, SyscallDesc("getuid", getuidFunc)},
110    {175, SyscallDesc("geteuid", geteuidFunc)},
111    {176, SyscallDesc("getgid", getgidFunc)},
112    {177, SyscallDesc("getegid", getegidFunc)},
113    {214, SyscallDesc("brk", brkFunc)},
114    {215, SyscallDesc("munmap", munmapFunc)},
115    {216, SyscallDesc("mremap", mremapFunc<RiscvLinux>)},
116    {222, SyscallDesc("mmap", mmapFunc<RiscvLinux>)},
117    {226, SyscallDesc("mprotect", ignoreFunc)},
118    {1024, SyscallDesc("open", openFunc<RiscvLinux>)},
119    {1025, SyscallDesc("link", unimplementedFunc)},
120    {1026, SyscallDesc("unlink", unlinkFunc)},
121    {1030, SyscallDesc("mkdir", mkdirFunc)},
122    {1033, SyscallDesc("access", accessFunc)},
123    {1038, SyscallDesc("stat", stat64Func<RiscvLinux>)},
124    {1039, SyscallDesc("lstat", lstat64Func<RiscvLinux>)},
125    {1062, SyscallDesc("time", timeFunc<RiscvLinux>)},
126    {2011, SyscallDesc("getmainvars", unimplementedFunc)},
127};
128
129RiscvLinuxProcess::RiscvLinuxProcess(ProcessParams * params,
130    ObjectFile *objFile) : RiscvProcess(params, objFile)
131{}
132
133SyscallDesc*
134RiscvLinuxProcess::getDesc(int callnum)
135{
136    return syscallDescs.find(callnum) != syscallDescs.end() ?
137        &syscallDescs.at(callnum) : nullptr;
138}
139