gem5  v21.1.0.2
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__) || defined(__APPLE__))
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 gem5
48 {
49 
50 namespace
51 {
52 
53 class FreebsdLoader : public Process::Loader
54 {
55  public:
56  Process *
57  load(const ProcessParams &params, loader::ObjectFile *obj) override
58  {
59  auto arch = obj->getArch();
60  auto opsys = obj->getOpSys();
61 
62  if (arch != loader::Arm && arch != loader::Thumb &&
63  arch != loader::Arm64) {
64  return nullptr;
65  }
66 
67  if (opsys != loader::FreeBSD)
68  return nullptr;
69 
70  if (arch == loader::Arm64)
71  return new ArmProcess64(params, obj, arch);
72  else
73  return new ArmProcess32(params, obj, arch);
74  }
75 };
76 
77 FreebsdLoader freebsdLoader;
78 
79 } // anonymous namespace
80 
81 namespace ArmISA
82 {
83 
84 static SyscallReturn
86 {
87  return 0;
88 }
89 
90 #if !defined ( __GNU_LIBRARY__ )
91 static SyscallReturn
92 sysctlFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> namep, size_t nameLen,
93  VPtr<> oldp, VPtr<> oldlenp, VPtr<> newp, size_t newlen)
94 {
95  uint64_t ret;
96 
97  BufferArg buf(namep, sizeof(size_t));
98  BufferArg buf2(oldp, sizeof(size_t));
99  BufferArg buf3(oldlenp, sizeof(size_t));
100  BufferArg buf4(newp, sizeof(size_t));
101 
102  buf.copyIn(tc->getVirtProxy());
103  buf2.copyIn(tc->getVirtProxy());
104  buf3.copyIn(tc->getVirtProxy());
105 
106  void *hnewp = NULL;
107  if (newp) {
108  buf4.copyIn(tc->getVirtProxy());
109  hnewp = (void *)buf4.bufferPtr();
110  }
111 
112  uint32_t *hnamep = (uint32_t *)buf.bufferPtr();
113  void *holdp = (void *)buf2.bufferPtr();
114  size_t *holdlenp = (size_t *)buf3.bufferPtr();
115 
116  ret = sysctl((int *)hnamep, nameLen, holdp, holdlenp, hnewp, newlen);
117 
118  buf.copyOut(tc->getVirtProxy());
119  buf2.copyOut(tc->getVirtProxy());
120  buf3.copyOut(tc->getVirtProxy());
121  if (newp)
122  buf4.copyOut(tc->getVirtProxy());
123 
124  return (ret);
125 }
126 #endif
127 
129 
131  { 1, "exit", exitFunc },
132  { 3, "read", readFunc<ArmFreebsd64> },
133  { 4, "write", writeFunc<ArmFreebsd64> },
134  { 17, "obreak", brkFunc },
135  { 54, "ioctl", ioctlFunc<ArmFreebsd64> },
136  { 58, "readlink", readlinkFunc },
137  { 117, "getrusage", getrusageFunc<ArmFreebsd64> },
138  { 189, "fstat", fstatFunc<ArmFreebsd64> },
139 #if !defined ( __GNU_LIBRARY__ )
140  { 202, "sysctl", sysctlFunc },
141 #else
142  { 202, "sysctl" },
143 #endif
144  { 253, "issetugid", issetugidFunc },
145  { 477, "mmap", mmapFunc<ArmFreebsd64> }
146 };
147 
148 void
150 {
151  Process *process = tc->getProcessPtr();
152  // Call the syscall function in the base Process class to update stats.
153  // This will move into the base SEWorkload function at some point.
154  process->Process::syscall(tc);
155 
156  if (dynamic_cast<ArmProcess64 *>(process))
157  syscallDescs64.get(tc->readIntReg(INTREG_X8))->doSyscall(tc);
158  else
159  syscallDescs32.get(tc->readIntReg(INTREG_R7))->doSyscall(tc);
160 }
161 
162 } // namespace ArmISA
163 } // namespace gem5
gem5::SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:55
gem5::ArmISA::syscallDescs32
static SyscallDescTable< EmuFreebsd::SyscallABI32 > syscallDescs32({})
gem5::brkFunc
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> new_brk)
Target brk() handler: set brk address.
Definition: syscall_emul.cc:257
gem5::ArmISA::EmuFreebsd::syscall
void syscall(ThreadContext *tc) override
Definition: se_workload.cc:149
gem5::loader::Arm64
@ Arm64
Definition: object_file.hh:58
gem5::loader::FreeBSD
@ FreeBSD
Definition: object_file.hh:78
gem5::ArmISA::issetugidFunc
static SyscallReturn issetugidFunc(SyscallDesc *desc, ThreadContext *tc)
Definition: se_workload.cc:85
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::ThreadContext::getVirtProxy
virtual PortProxy & getVirtProxy()=0
gem5::BufferArg
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
Definition: syscall_emul_buf.hh:107
gem5::ArmProcess64
Definition: process.hh:91
gem5::ProxyPtr
Definition: proxy_ptr.hh:238
gem5::SyscallDescTable
Definition: syscall_desc.hh:184
gem5::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:92
gem5::readlinkFunc
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname, VPtr<> buf_ptr, size_t bufsiz)
Target readlink() handler.
Definition: syscall_emul.cc:401
gem5::ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
gem5::BaseBufferArg::copyIn
bool copyIn(const PortProxy &memproxy)
copy data into simulator space (read from target memory)
Definition: syscall_emul_buf.hh:81
gem5::Process
Definition: process.hh:67
gem5::ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
gem5::loader::Thumb
@ Thumb
Definition: object_file.hh:60
gem5::exitFunc
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
Definition: syscall_emul.cc:238
syscall_emul.hh
gem5::BaseBufferArg::copyOut
bool copyOut(const PortProxy &memproxy)
copy data out of simulator space (write to target memory)
Definition: syscall_emul_buf.hh:91
gem5::ArmISA::syscallDescs64
static SyscallDescTable< EmuFreebsd::SyscallABI64 > syscallDescs64
Definition: se_workload.cc:130
trace.hh
gem5::SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:69
gem5::BufferArg::bufferPtr
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
Definition: syscall_emul_buf.hh:119
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
process.hh
se_workload.hh
object_file.hh
gem5::loader::Arm
@ Arm
Definition: object_file.hh:59
thread_context.hh

Generated on Tue Sep 21 2021 12:24:34 for gem5 by doxygen 1.8.17