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

Generated on Wed Dec 21 2022 10:22:25 for gem5 by doxygen 1.9.1