gem5  v20.1.0.0
process.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
3  * All rights reserved.
4  *
5  * This software was developed by the University of Cambridge Computer
6  * Laboratory as part of the CTSRD Project, with support from the UK Higher
7  * Education Innovation Fund (HEIF).
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are
11  * met: redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer;
13  * redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution;
16  * neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
34 
35 #include <sys/mman.h>
36 #include <sys/param.h>
37 #include <sys/syscall.h>
38 #if !defined ( __GNU_LIBRARY__ )
39 #include <sys/sysctl.h>
40 #endif
41 #include <sys/types.h>
42 #include <utime.h>
43 
45 #include "arch/arm/isa_traits.hh"
47 #include "base/trace.hh"
48 #include "cpu/thread_context.hh"
49 #include "kern/freebsd/freebsd.hh"
50 #include "sim/process.hh"
51 #include "sim/syscall_desc.hh"
52 #include "sim/syscall_emul.hh"
53 #include "sim/system.hh"
54 
55 using namespace std;
56 using namespace ArmISA;
57 
58 namespace
59 {
60 
61 class ArmFreebsdObjectFileLoader : public Process::Loader
62 {
63  public:
64  Process *
65  load(ProcessParams *params, ::Loader::ObjectFile *obj_file) override
66  {
67  auto arch = obj_file->getArch();
68  auto opsys = obj_file->getOpSys();
69 
70  if (arch != ::Loader::Arm && arch != ::Loader::Thumb &&
71  arch != ::Loader::Arm64) {
72  return nullptr;
73  }
74 
75  if (opsys != ::Loader::FreeBSD)
76  return nullptr;
77 
78  if (arch == ::Loader::Arm64)
79  return new ArmFreebsdProcess64(params, obj_file, arch);
80  else
81  return new ArmFreebsdProcess32(params, obj_file, arch);
82  }
83 };
84 
85 ArmFreebsdObjectFileLoader loader;
86 
87 } // anonymous namespace
88 
89 static SyscallReturn
91 {
92  return 0;
93 }
94 
95 #if !defined ( __GNU_LIBRARY__ )
96 static SyscallReturn
97 sysctlFunc(SyscallDesc *desc, ThreadContext *tc, Addr namep, size_t nameLen,
98  Addr oldp, Addr oldlenp, Addr newp, size_t newlen)
99 {
100  uint64_t ret;
101 
102  BufferArg buf(namep, sizeof(size_t));
103  BufferArg buf2(oldp, sizeof(size_t));
104  BufferArg buf3(oldlenp, sizeof(size_t));
105  BufferArg buf4(newp, sizeof(size_t));
106 
107  buf.copyIn(tc->getVirtProxy());
108  buf2.copyIn(tc->getVirtProxy());
109  buf3.copyIn(tc->getVirtProxy());
110 
111  void *hnewp = NULL;
112  if (newp) {
113  buf4.copyIn(tc->getVirtProxy());
114  hnewp = (void *)buf4.bufferPtr();
115  }
116 
117  uint32_t *hnamep = (uint32_t *)buf.bufferPtr();
118  void *holdp = (void *)buf2.bufferPtr();
119  size_t *holdlenp = (size_t *)buf3.bufferPtr();
120 
121  ret = sysctl((int *)hnamep, nameLen, holdp, holdlenp, hnewp, newlen);
122 
123  buf.copyOut(tc->getVirtProxy());
124  buf2.copyOut(tc->getVirtProxy());
125  buf3.copyOut(tc->getVirtProxy());
126  if (newp)
127  buf4.copyOut(tc->getVirtProxy());
128 
129  return (ret);
130 }
131 #endif
132 
134 
136  { 1, "exit", exitFunc },
137  { 3, "read", readFunc<ArmFreebsd64> },
138  { 4, "write", writeFunc<ArmFreebsd64> },
139  { 17, "obreak", brkFunc },
140  { 54, "ioctl", ioctlFunc<ArmFreebsd64> },
141  { 58, "readlink", readlinkFunc },
142  { 117, "getrusage", getrusageFunc<ArmFreebsd64> },
143  { 189, "fstat", fstatFunc<ArmFreebsd64> },
144 #if !defined ( __GNU_LIBRARY__ )
145  { 202, "sysctl", sysctlFunc },
146 #else
147  { 202, "sysctl" },
148 #endif
149  { 253, "issetugid", issetugidFunc },
150  { 477, "mmap", mmapFunc<ArmFreebsd64> }
151 };
152 
154  ::Loader::ObjectFile *objFile, ::Loader::Arch _arch) :
155  ArmProcess32(params, objFile, _arch)
156 {}
157 
159  ::Loader::ObjectFile *objFile, ::Loader::Arch _arch) :
160  ArmProcess64(params, objFile, _arch)
161 {}
162 
163 void
165 {
167  // The 32 bit equivalent of the comm page would be set up here.
168 }
169 
170 void
172 {
174  // The 64 bit equivalent of the comm page would be set up here.
175 }
176 
177 void
179 {
181  syscallDescs32.get(tc->readIntReg(INTREG_R7))->doSyscall(tc);
182 }
183 
184 void
186 {
188  syscallDescs64.get(tc->readIntReg(INTREG_X8))->doSyscall(tc);
189 }
ArmFreebsdProcess32::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:164
ArmProcess64::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:122
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:185
freebsd.hh
ArmFreebsdProcess32::ArmFreebsdProcess32
ArmFreebsdProcess32(ProcessParams *params, ::Loader::ObjectFile *objFile, ::Loader::Arch _arch)
Definition: process.cc:153
system.hh
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:117
syscallDescs32
static SyscallDescTable< ArmFreebsdProcess32::SyscallABI > syscallDescs32({})
Process::syscall
virtual void syscall(ThreadContext *tc)
Definition: process.hh:78
ArmISA
Definition: ccregs.hh:41
exitFunc
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
Definition: syscall_emul.cc:230
ArmProcess32::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:103
syscallDescs64
static SyscallDescTable< ArmFreebsdProcess64::SyscallABI > syscallDescs64
Definition: process.cc:135
Loader::ObjectFile
Definition: object_file.hh:70
brkFunc
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, Addr new_brk)
Target brk() handler: set brk address.
Definition: syscall_emul.cc:249
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
readlinkFunc
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr buf_ptr, size_t bufsiz)
Target readlink() handler.
Definition: syscall_emul.cc:394
ArmFreebsdProcess32::syscall
void syscall(ThreadContext *tc) override
Definition: process.cc:178
process.hh
ArmFreebsdProcess32
A process with emulated Arm/Freebsd syscalls.
Definition: process.hh:77
ArmISA::INTREG_R7
@ INTREG_R7
Definition: intregs.hh:61
sysctlFunc
static SyscallReturn sysctlFunc(SyscallDesc *desc, ThreadContext *tc, Addr namep, size_t nameLen, Addr oldp, Addr oldlenp, Addr newp, size_t newlen)
Definition: process.cc:97
ArmProcess32
Definition: process.hh:74
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:52
issetugidFunc
static SyscallReturn issetugidFunc(SyscallDesc *desc, ThreadContext *tc)
Definition: process.cc:90
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
ArmFreebsdProcess64::syscall
void syscall(ThreadContext *tc) override
Definition: process.cc:185
process.hh
ThreadContext::getVirtProxy
virtual PortProxy & getVirtProxy()=0
Loader::FreeBSD
@ FreeBSD
Definition: object_file.hh:65
Loader::Arch
Arch
Definition: object_file.hh:44
syscall_emul.hh
Loader::ObjectFile::getArch
Arch getArch() const
Definition: object_file.hh:99
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Loader::ObjectFile::getOpSys
OpSys getOpSys() const
Definition: object_file.hh:100
isa_traits.hh
ArmISA::INTREG_X8
@ INTREG_X8
Definition: intregs.hh:135
Loader::Arm64
@ Arm64
Definition: object_file.hh:51
ArmFreebsdProcess64
A process with emulated Arm/Freebsd syscalls.
Definition: process.hh:96
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
freebsd.hh
object_file.hh
thread_context.hh
SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66
syscall_desc.hh
ArmFreebsdProcess64::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:171
BaseBufferArg::copyOut
bool copyOut(PortProxy &memproxy)
copy data out of simulator space (write to target memory)
Definition: syscall_emul_buf.hh:87
ArmFreebsdProcess64::ArmFreebsdProcess64
ArmFreebsdProcess64(ProcessParams *params, ::Loader::ObjectFile *objFile, ::Loader::Arch _arch)
Definition: process.cc:158

Generated on Wed Sep 30 2020 14:01:59 for gem5 by doxygen 1.8.17