misc: Updated the RELEASE-NOTES and version number
[gem5.git] / src / arch / arm / freebsd / process.cc
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
33 #include "arch/arm/freebsd/process.hh"
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
44 #include "arch/arm/freebsd/freebsd.hh"
45 #include "arch/arm/isa_traits.hh"
46 #include "base/loader/object_file.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
90 issetugidFunc(SyscallDesc *desc, ThreadContext *tc)
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
133 static SyscallDescTable<ArmFreebsdProcess32::SyscallABI> syscallDescs32({});
134
135 static SyscallDescTable<ArmFreebsdProcess64::SyscallABI> syscallDescs64 = {
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
153 ArmFreebsdProcess32::ArmFreebsdProcess32(ProcessParams * params,
154 ::Loader::ObjectFile *objFile, ::Loader::Arch _arch) :
155 ArmProcess32(params, objFile, _arch)
156 {}
157
158 ArmFreebsdProcess64::ArmFreebsdProcess64(ProcessParams * params,
159 ::Loader::ObjectFile *objFile, ::Loader::Arch _arch) :
160 ArmProcess64(params, objFile, _arch)
161 {}
162
163 void
164 ArmFreebsdProcess32::initState()
165 {
166 ArmProcess32::initState();
167 // The 32 bit equivalent of the comm page would be set up here.
168 }
169
170 void
171 ArmFreebsdProcess64::initState()
172 {
173 ArmProcess64::initState();
174 // The 64 bit equivalent of the comm page would be set up here.
175 }
176
177 void
178 ArmFreebsdProcess32::syscall(ThreadContext *tc)
179 {
180 ArmProcess32::syscall(tc);
181 syscallDescs32.get(tc->readIntReg(INTREG_R7))->doSyscall(tc);
182 }
183
184 void
185 ArmFreebsdProcess64::syscall(ThreadContext *tc)
186 {
187 ArmProcess64::syscall(tc);
188 syscallDescs64.get(tc->readIntReg(INTREG_X8))->doSyscall(tc);
189 }