gem5  v21.0.1.0
se_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Ruslan Bukin <br@bsdpad.com>
3  *
4  * This software was developed by the University of Cambridge Computer
5  * Laboratory as part of the CTSRD Project, with support from the UK Higher
6  * Education Innovation Fund (HEIF).
7  *
8  * Copyright 2020 Google Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met: redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer;
14  * redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution;
17  * neither the name of the copyright holders nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 
36 #include <sys/syscall.h>
37 #if !defined ( __GNU_LIBRARY__ ) && defined(__FreeBSD__)
38 #include <sys/sysctl.h>
39 #endif
40 
41 #include "arch/arm/process.hh"
43 #include "base/trace.hh"
44 #include "cpu/thread_context.hh"
45 #include "sim/syscall_emul.hh"
46 
47 namespace
48 {
49 
50 class FreebsdLoader : public Process::Loader
51 {
52  public:
53  Process *
54  load(const ProcessParams &params, ::Loader::ObjectFile *obj) override
55  {
56  auto arch = obj->getArch();
57  auto opsys = obj->getOpSys();
58 
59  if (arch != ::Loader::Arm && arch != ::Loader::Thumb &&
60  arch != ::Loader::Arm64) {
61  return nullptr;
62  }
63 
64  if (opsys != ::Loader::FreeBSD)
65  return nullptr;
66 
67  if (arch == ::Loader::Arm64)
68  return new ArmProcess64(params, obj, arch);
69  else
70  return new ArmProcess32(params, obj, arch);
71  }
72 };
73 
74 FreebsdLoader loader;
75 
76 } // anonymous namespace
77 
78 namespace ArmISA
79 {
80 
81 static SyscallReturn
83 {
84  return 0;
85 }
86 
87 #if !defined ( __GNU_LIBRARY__ )
88 static SyscallReturn
89 sysctlFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> namep, size_t nameLen,
90  VPtr<> oldp, VPtr<> oldlenp, VPtr<> newp, size_t newlen)
91 {
92  uint64_t ret;
93 
94  BufferArg buf(namep, sizeof(size_t));
95  BufferArg buf2(oldp, sizeof(size_t));
96  BufferArg buf3(oldlenp, sizeof(size_t));
97  BufferArg buf4(newp, sizeof(size_t));
98 
99  buf.copyIn(tc->getVirtProxy());
100  buf2.copyIn(tc->getVirtProxy());
101  buf3.copyIn(tc->getVirtProxy());
102 
103  void *hnewp = NULL;
104  if (newp) {
105  buf4.copyIn(tc->getVirtProxy());
106  hnewp = (void *)buf4.bufferPtr();
107  }
108 
109  uint32_t *hnamep = (uint32_t *)buf.bufferPtr();
110  void *holdp = (void *)buf2.bufferPtr();
111  size_t *holdlenp = (size_t *)buf3.bufferPtr();
112 
113  ret = sysctl((int *)hnamep, nameLen, holdp, holdlenp, hnewp, newlen);
114 
115  buf.copyOut(tc->getVirtProxy());
116  buf2.copyOut(tc->getVirtProxy());
117  buf3.copyOut(tc->getVirtProxy());
118  if (newp)
119  buf4.copyOut(tc->getVirtProxy());
120 
121  return (ret);
122 }
123 #endif
124 
126 
128  { 1, "exit", exitFunc },
129  { 3, "read", readFunc<ArmFreebsd64> },
130  { 4, "write", writeFunc<ArmFreebsd64> },
131  { 17, "obreak", brkFunc },
132  { 54, "ioctl", ioctlFunc<ArmFreebsd64> },
133  { 58, "readlink", readlinkFunc },
134  { 117, "getrusage", getrusageFunc<ArmFreebsd64> },
135  { 189, "fstat", fstatFunc<ArmFreebsd64> },
136 #if !defined ( __GNU_LIBRARY__ )
137  { 202, "sysctl", sysctlFunc },
138 #else
139  { 202, "sysctl" },
140 #endif
141  { 253, "issetugid", issetugidFunc },
142  { 477, "mmap", mmapFunc<ArmFreebsd64> }
143 };
144 
145 void
147 {
148  Process *process = tc->getProcessPtr();
149  // Call the syscall function in the base Process class to update stats.
150  // This will move into the base SEWorkload function at some point.
151  process->Process::syscall(tc);
152 
153  if (dynamic_cast<ArmProcess64 *>(process))
154  syscallDescs64.get(tc->readIntReg(INTREG_X8))->doSyscall(tc);
155  else
156  syscallDescs32.get(tc->readIntReg(INTREG_R7))->doSyscall(tc);
157 }
158 
159 } // namespace ArmISA
Process::Loader
Each instance of a Loader subclass will have a chance to try to load an object file when tryLoaders i...
Definition: process.hh:180
brkFunc
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> new_brk)
Target brk() handler: set brk address.
Definition: syscall_emul.cc:246
ArmISA::issetugidFunc
static SyscallReturn issetugidFunc(SyscallDesc *desc, ThreadContext *tc)
Definition: se_workload.cc:82
Loader::Thumb
@ Thumb
Definition: object_file.hh:53
SyscallDescTable
Definition: syscall_desc.hh:180
Loader::Arm
@ Arm
Definition: object_file.hh:52
Process
Definition: process.hh:65
ArmProcess64
Definition: process.hh:88
readlinkFunc
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname, VPtr<> buf_ptr, size_t bufsiz)
Target readlink() handler.
Definition: syscall_emul.cc:390
ProxyPtr
Definition: proxy_ptr.hh:235
ArmISA::syscallDescs64
static SyscallDescTable< EmuFreebsd::SyscallABI64 > syscallDescs64
Definition: se_workload.cc:127
ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
ArmISA
Definition: ccregs.hh:41
exitFunc
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
Definition: syscall_emul.cc:227
Loader::ObjectFile
Definition: object_file.hh:74
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
ArmISA::syscallDescs32
static SyscallDescTable< EmuFreebsd::SyscallABI32 > syscallDescs32({})
ArmISA::INTREG_R7
@ INTREG_R7
Definition: intregs.hh:61
ArmProcess32
Definition: process.hh:75
SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:52
ArmISA::EmuFreebsd::syscall
void syscall(ThreadContext *tc) override
Definition: se_workload.cc:146
BaseBufferArg::copyIn
bool copyIn(PortProxy &memproxy)
copy data into simulator space (read from target memory)
Definition: syscall_emul_buf.hh:77
BufferArg::bufferPtr
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
Definition: syscall_emul_buf.hh:115
ThreadContext::getVirtProxy
virtual PortProxy & getVirtProxy()=0
Loader::FreeBSD
@ FreeBSD
Definition: object_file.hh:67
syscall_emul.hh
Loader::ObjectFile::getArch
Arch getArch() const
Definition: object_file.hh:103
Process::Loader::load
virtual Process * load(const ProcessParams &params, ::Loader::ObjectFile *obj_file)=0
Each subclass needs to implement this method.
Loader::ObjectFile::getOpSys
OpSys getOpSys() const
Definition: object_file.hh:104
ArmISA::INTREG_X8
@ INTREG_X8
Definition: intregs.hh:135
Loader::Arm64
@ Arm64
Definition: object_file.hh:51
trace.hh
BufferArg
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
Definition: syscall_emul_buf.hh:103
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
process.hh
se_workload.hh
object_file.hh
thread_context.hh
ArmISA::sysctlFunc
static SyscallReturn sysctlFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> namep, size_t nameLen, VPtr<> oldp, VPtr<> oldlenp, VPtr<> newp, size_t newlen)
Definition: se_workload.cc:89
SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66
BaseBufferArg::copyOut
bool copyOut(PortProxy &memproxy)
copy data out of simulator space (write to target memory)
Definition: syscall_emul_buf.hh:87

Generated on Tue Jun 22 2021 15:28:20 for gem5 by doxygen 1.8.17