1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 */
30
31#include "arch/sparc/solaris/process.hh"
32
33#include "arch/sparc/isa_traits.hh"
34#include "arch/sparc/registers.hh"
35#include "base/loader/object_file.hh"
36#include "base/trace.hh"
37#include "cpu/thread_context.hh"
38#include "kern/solaris/solaris.hh"
39#include "sim/process.hh"
40#include "sim/syscall_desc.hh"
41#include "sim/syscall_emul.hh"
42
43using namespace std;
44using namespace SparcISA;
45
46namespace
47{
48
49class SparcSolarisObjectFileLoader : public ObjectFile::Loader
50{
51  public:
52    Process *
53    load(ProcessParams *params, ObjectFile *obj_file) override
54    {
55        auto arch = obj_file->getArch();
56        auto opsys = obj_file->getOpSys();
57
58        if (arch != ObjectFile::SPARC64 && arch != ObjectFile::SPARC32)
59            return nullptr;
60
61        if (opsys != ObjectFile::Solaris)
62            return nullptr;
63
64        return new SparcSolarisProcess(params, obj_file);
65    }
66};
67
68SparcSolarisObjectFileLoader loader;
69
70} // anonymous namespace
71
72
73/// Target uname() handler.
74static SyscallReturn
75unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
76{
77    int index = 0;
78    auto process = tc->getProcessPtr();
79    TypedBufferArg<Solaris::utsname> name(process->getSyscallArg(tc, index));
80
81    strcpy(name->sysname, "SunOS");
82    strcpy(name->nodename, "m5.eecs.umich.edu");
83    strcpy(name->release, process->release.c_str());
84    strcpy(name->version, "Generic_118558-21");
85    strcpy(name->machine, "sun4u");
86
87    name.copyOut(tc->getVirtProxy());
88
89    return 0;
90}
91
92
93SyscallDesc SparcSolarisProcess::syscallDescs[] = {
94    /* 0 */ SyscallDesc("syscall", unimplementedFunc),
95    /* 1 */ SyscallDesc("exit", exitFunc),
96    /* 2 */ SyscallDesc("fork", unimplementedFunc),
97    /* 3 */ SyscallDesc("read", readFunc<SparcSolaris>),
98    /* 4 */ SyscallDesc("write", writeFunc<SparcSolaris>),
99    /* 5 */ SyscallDesc("open", openFunc<SparcSolaris>),
100    /* 6 */ SyscallDesc("close", closeFunc),
101    /* 7 */ SyscallDesc("wait", unimplementedFunc),
102    /* 8 */ SyscallDesc("creat", unimplementedFunc),
103    /* 9 */ SyscallDesc("link", unimplementedFunc),
104    /* 10 */ SyscallDesc("unlink", unlinkFunc),
105    /* 11 */ SyscallDesc("exec", unimplementedFunc),
106    /* 12 */ SyscallDesc("chdir", unimplementedFunc),
107    /* 13 */ SyscallDesc("time", unimplementedFunc),
108    /* 14 */ SyscallDesc("mknod", unimplementedFunc),
109    /* 15 */ SyscallDesc("chmod", chmodFunc<Solaris>),
110    /* 16 */ SyscallDesc("chown", chownFunc),
111    /* 17 */ SyscallDesc("brk", brkFunc),
112    /* 18 */ SyscallDesc("stat", unimplementedFunc),
113    /* 19 */ SyscallDesc("lseek", lseekFunc),
114    /* 20 */ SyscallDesc("getpid", getpidFunc),
115    /* 21 */ SyscallDesc("mount", unimplementedFunc),
116    /* 22 */ SyscallDesc("umount", unimplementedFunc),
117    /* 23 */ SyscallDesc("setuid", setuidFunc),
118    /* 24 */ SyscallDesc("getuid", getuidFunc),
119    /* 25 */ SyscallDesc("stime", unimplementedFunc),
120    /* 26 */ SyscallDesc("pcsample", unimplementedFunc),
121    /* 27 */ SyscallDesc("alarm", unimplementedFunc),
122    /* 28 */ SyscallDesc("fstat", fstatFunc<SparcSolaris>),
123    /* 29 */ SyscallDesc("pause", unimplementedFunc),
124    /* 30 */ SyscallDesc("utime", unimplementedFunc),
125    /* 31 */ SyscallDesc("stty", unimplementedFunc),
126    /* 32 */ SyscallDesc("gtty", unimplementedFunc),
127    /* 33 */ SyscallDesc("access", unimplementedFunc),
128    /* 34 */ SyscallDesc("nice", unimplementedFunc),
129    /* 35 */ SyscallDesc("statfs", unimplementedFunc),
130    /* 36 */ SyscallDesc("sync", unimplementedFunc),
131    /* 37 */ SyscallDesc("kill", unimplementedFunc),
132    /* 38 */ SyscallDesc("fstatfs", unimplementedFunc),
133    /* 39 */ SyscallDesc("pgrpsys", unimplementedFunc),
134    /* 40 */ SyscallDesc("xenix", unimplementedFunc),
135    /* 41 */ SyscallDesc("dup", unimplementedFunc),
136    /* 42 */ SyscallDesc("pipe", pipePseudoFunc),
137    /* 43 */ SyscallDesc("times", unimplementedFunc),
138    /* 44 */ SyscallDesc("profil", unimplementedFunc),
139    /* 45 */ SyscallDesc("plock", unimplementedFunc),
140    /* 46 */ SyscallDesc("setgid", unimplementedFunc),
141    /* 47 */ SyscallDesc("getgid", getgidFunc),
142    /* 48 */ SyscallDesc("signal", unimplementedFunc),
143    /* 49 */ SyscallDesc("msgsys", unimplementedFunc),
144    /* 50 */ SyscallDesc("syssun", unimplementedFunc),
145    /* 51 */ SyscallDesc("acct", unimplementedFunc),
146    /* 52 */ SyscallDesc("shmsys", unimplementedFunc),
147    /* 53 */ SyscallDesc("semsys", unimplementedFunc),
148    /* 54 */ SyscallDesc("ioctl", unimplementedFunc),
149    /* 55 */ SyscallDesc("uadmin", unimplementedFunc),
150    /* 56 */ SyscallDesc("RESERVED", unimplementedFunc),
151    /* 57 */ SyscallDesc("utssys", unimplementedFunc),
152    /* 58 */ SyscallDesc("fdsync", unimplementedFunc),
153    /* 59 */ SyscallDesc("execve", unimplementedFunc),
154    /* 60 */ SyscallDesc("umask", umaskFunc),
155    /* 61 */ SyscallDesc("chroot", unimplementedFunc),
156    /* 62 */ SyscallDesc("fcntl", unimplementedFunc),
157    /* 63 */ SyscallDesc("ulimit", unimplementedFunc),
158    /* 64 */ SyscallDesc("reserved_64", unimplementedFunc),
159    /* 65 */ SyscallDesc("reserved_65", unimplementedFunc),
160    /* 66 */ SyscallDesc("reserved_66", unimplementedFunc),
161    /* 67 */ SyscallDesc("reserved_67", unimplementedFunc),
162    /* 68 */ SyscallDesc("reserved_68", unimplementedFunc),
163    /* 69 */ SyscallDesc("reserved_69", unimplementedFunc),
164    /* 70 */ SyscallDesc("tasksys", unimplementedFunc),
165    /* 71 */ SyscallDesc("acctctl", unimplementedFunc),
166    /* 72 */ SyscallDesc("reserved_72", unimplementedFunc),
167    /* 73 */ SyscallDesc("getpagesizes", unimplementedFunc),
168    /* 74 */ SyscallDesc("rctlsys", unimplementedFunc),
169    /* 75 */ SyscallDesc("issetugid", unimplementedFunc),
170    /* 76 */ SyscallDesc("fsat", unimplementedFunc),
171    /* 77 */ SyscallDesc("lwp_park", unimplementedFunc),
172    /* 78 */ SyscallDesc("sendfilev", unimplementedFunc),
173    /* 79 */ SyscallDesc("rmdir", unimplementedFunc),
174    /* 80 */ SyscallDesc("mkdir", unimplementedFunc),
175    /* 81 */ SyscallDesc("getdents", unimplementedFunc),
176    /* 82 */ SyscallDesc("reserved_82", unimplementedFunc),
177    /* 83 */ SyscallDesc("reserved_83", unimplementedFunc),
178    /* 84 */ SyscallDesc("sysfs", unimplementedFunc),
179    /* 85 */ SyscallDesc("getmsg", unimplementedFunc),
180    /* 86 */ SyscallDesc("putmsg", unimplementedFunc),
181    /* 87 */ SyscallDesc("poll", unimplementedFunc),
182    /* 88 */ SyscallDesc("lstat", unimplementedFunc),
183    /* 89 */ SyscallDesc("symlink", unimplementedFunc),
184    /* 90 */ SyscallDesc("readlink", readlinkFunc),
185    /* 91 */ SyscallDesc("setgroups", unimplementedFunc),
186    /* 92 */ SyscallDesc("getgroups", unimplementedFunc),
187    /* 93 */ SyscallDesc("fchmod", unimplementedFunc),
188    /* 94 */ SyscallDesc("fchown", unimplementedFunc),
189    /* 95 */ SyscallDesc("sigprocmask", unimplementedFunc),
190    /* 96 */ SyscallDesc("sigsuspend", unimplementedFunc),
191    /* 97 */ SyscallDesc("sigaltstack", unimplementedFunc),
192    /* 98 */ SyscallDesc("sigaction", unimplementedFunc),
193    /* 99 */ SyscallDesc("sigpending", unimplementedFunc),
194    /* 100 */ SyscallDesc("context", unimplementedFunc),
195    /* 101 */ SyscallDesc("evsys", unimplementedFunc),
196    /* 102 */ SyscallDesc("evtrapret", unimplementedFunc),
197    /* 103 */ SyscallDesc("statvfs", unimplementedFunc),
198    /* 104 */ SyscallDesc("fstatvfs", unimplementedFunc),
199    /* 105 */ SyscallDesc("getloadavg", unimplementedFunc),
200    /* 106 */ SyscallDesc("nfssys", unimplementedFunc),
201    /* 107 */ SyscallDesc("waitsys", unimplementedFunc),
202    /* 108 */ SyscallDesc("sigsendsys", unimplementedFunc),
203    /* 109 */ SyscallDesc("hrtsys", unimplementedFunc),
204    /* 110 */ SyscallDesc("acancel", unimplementedFunc),
205    /* 111 */ SyscallDesc("async", unimplementedFunc),
206    /* 112 */ SyscallDesc("priocntlsys", unimplementedFunc),
207    /* 113 */ SyscallDesc("pathconf", unimplementedFunc),
208    /* 114 */ SyscallDesc("mincore", unimplementedFunc),
209    /* 115 */ SyscallDesc("mmap", mmapFunc<SparcSolaris>),
210    /* 116 */ SyscallDesc("mprotect", unimplementedFunc),
211    /* 117 */ SyscallDesc("munmap", munmapFunc),
212    /* 118 */ SyscallDesc("fpathconf", unimplementedFunc),
213    /* 119 */ SyscallDesc("vfork", unimplementedFunc),
214    /* 120 */ SyscallDesc("fchdir", unimplementedFunc),
215    /* 121 */ SyscallDesc("readv", unimplementedFunc),
216    /* 122 */ SyscallDesc("writev", unimplementedFunc),
217    /* 123 */ SyscallDesc("xstat", unimplementedFunc),
218    /* 124 */ SyscallDesc("lxstat", unimplementedFunc),
219    /* 125 */ SyscallDesc("fxstat", unimplementedFunc),
220    /* 126 */ SyscallDesc("xmknod", unimplementedFunc),
221    /* 127 */ SyscallDesc("clocal", unimplementedFunc),
222    /* 128 */ SyscallDesc("setrlimit", unimplementedFunc),
223    /* 129 */ SyscallDesc("getrlimit", unimplementedFunc),
224    /* 130 */ SyscallDesc("lchown", unimplementedFunc),
225    /* 131 */ SyscallDesc("memcntl", unimplementedFunc),
226    /* 132 */ SyscallDesc("getpmsg", unimplementedFunc),
227    /* 133 */ SyscallDesc("putpmsg", unimplementedFunc),
228    /* 134 */ SyscallDesc("rename", unimplementedFunc),
229    /* 135 */ SyscallDesc("uname", unameFunc),
230    /* 136 */ SyscallDesc("setegid", unimplementedFunc),
231    /* 137 */ SyscallDesc("sysconfig", unimplementedFunc),
232    /* 138 */ SyscallDesc("adjtime", unimplementedFunc),
233    /* 139 */ SyscallDesc("systeminfo", unimplementedFunc),
234    /* 140 */ SyscallDesc("reserved_140", unimplementedFunc),
235    /* 141 */ SyscallDesc("seteuid", unimplementedFunc),
236    /* 142 */ SyscallDesc("vtrace", unimplementedFunc),
237    /* 143 */ SyscallDesc("fork1", unimplementedFunc),
238    /* 144 */ SyscallDesc("sigtimedwait", unimplementedFunc),
239    /* 145 */ SyscallDesc("lwp_info", unimplementedFunc),
240    /* 146 */ SyscallDesc("yield", unimplementedFunc),
241    /* 147 */ SyscallDesc("lwp_sema_wait", unimplementedFunc),
242    /* 148 */ SyscallDesc("lwp_sema_post", unimplementedFunc),
243    /* 149 */ SyscallDesc("lwp_sema_trywait", unimplementedFunc),
244    /* 150 */ SyscallDesc("lwp_detach", unimplementedFunc),
245    /* 151 */ SyscallDesc("corectl", unimplementedFunc),
246    /* 152 */ SyscallDesc("modctl", unimplementedFunc),
247    /* 153 */ SyscallDesc("fchroot", unimplementedFunc),
248    /* 154 */ SyscallDesc("utimes", unimplementedFunc),
249    /* 155 */ SyscallDesc("vhangup", unimplementedFunc),
250    /* 156 */ SyscallDesc("gettimeofday", unimplementedFunc),
251    /* 157 */ SyscallDesc("getitimer", unimplementedFunc),
252    /* 158 */ SyscallDesc("setitimer", unimplementedFunc),
253    /* 159 */ SyscallDesc("lwp_create", unimplementedFunc),
254    /* 160 */ SyscallDesc("lwp_exit", unimplementedFunc),
255    /* 161 */ SyscallDesc("lwp_suspend", unimplementedFunc),
256    /* 162 */ SyscallDesc("lwp_continue", unimplementedFunc),
257    /* 163 */ SyscallDesc("lwp_kill", unimplementedFunc),
258    /* 164 */ SyscallDesc("lwp_self", unimplementedFunc),
259    /* 165 */ SyscallDesc("lwp_setprivate", unimplementedFunc),
260    /* 166 */ SyscallDesc("lwp_getprivate", unimplementedFunc),
261    /* 167 */ SyscallDesc("lwp_wait", unimplementedFunc),
262    /* 168 */ SyscallDesc("lwp_mutex_wakeup", unimplementedFunc),
263    /* 169 */ SyscallDesc("lwp_mutex_lock", unimplementedFunc),
264    /* 170 */ SyscallDesc("lwp_cond_wait", unimplementedFunc),
265    /* 171 */ SyscallDesc("lwp_cond_signal", unimplementedFunc),
266    /* 172 */ SyscallDesc("lwp_cond_broadcast", unimplementedFunc),
267    /* 173 */ SyscallDesc("pread", unimplementedFunc),
268    /* 174 */ SyscallDesc("pwrite", unimplementedFunc),
269    /* 175 */ SyscallDesc("llseek", unimplementedFunc),
270    /* 176 */ SyscallDesc("inst_sync", unimplementedFunc),
271    /* 177 */ SyscallDesc("srmlimitsys", unimplementedFunc),
272    /* 178 */ SyscallDesc("kaio", unimplementedFunc),
273    /* 179 */ SyscallDesc("cpc", unimplementedFunc),
274    /* 180 */ SyscallDesc("lgrpsys_meminfosys", unimplementedFunc),
275    /* 181 */ SyscallDesc("rusagesys", unimplementedFunc),
276    /* 182 */ SyscallDesc("reserved_182", unimplementedFunc),
277    /* 183 */ SyscallDesc("reserved_183", unimplementedFunc),
278    /* 184 */ SyscallDesc("tsolsys", unimplementedFunc),
279    /* 185 */ SyscallDesc("acl", unimplementedFunc),
280    /* 186 */ SyscallDesc("auditsys", unimplementedFunc),
281    /* 187 */ SyscallDesc("processor_bind", unimplementedFunc),
282    /* 188 */ SyscallDesc("processor_info", unimplementedFunc),
283    /* 189 */ SyscallDesc("p_online", unimplementedFunc),
284    /* 190 */ SyscallDesc("sigqueue", unimplementedFunc),
285    /* 191 */ SyscallDesc("clock_gettime", unimplementedFunc),
286    /* 192 */ SyscallDesc("clock_settime", unimplementedFunc),
287    /* 193 */ SyscallDesc("clock_getres", unimplementedFunc),
288    /* 194 */ SyscallDesc("timer_create", unimplementedFunc),
289    /* 195 */ SyscallDesc("timer_delete", unimplementedFunc),
290    /* 196 */ SyscallDesc("timer_settime", unimplementedFunc),
291    /* 197 */ SyscallDesc("timer_gettime", unimplementedFunc),
292    /* 198 */ SyscallDesc("timer_getoverrun", unimplementedFunc),
293    /* 199 */ SyscallDesc("nanosleep", unimplementedFunc),
294    /* 200 */ SyscallDesc("facl", unimplementedFunc),
295    /* 201 */ SyscallDesc("door", unimplementedFunc),
296    /* 202 */ SyscallDesc("setreuid", unimplementedFunc),
297    /* 203 */ SyscallDesc("setregid", unimplementedFunc),
298    /* 204 */ SyscallDesc("install_utrap", unimplementedFunc),
299    /* 205 */ SyscallDesc("signotify", unimplementedFunc),
300    /* 206 */ SyscallDesc("schedctl", unimplementedFunc),
301    /* 207 */ SyscallDesc("pset", unimplementedFunc),
302    /* 208 */ SyscallDesc("sparc_utrap_install", unimplementedFunc),
303    /* 209 */ SyscallDesc("resolvepath", unimplementedFunc),
304    /* 210 */ SyscallDesc("signotifywait", unimplementedFunc),
305    /* 211 */ SyscallDesc("lwp_sigredirect", unimplementedFunc),
306    /* 212 */ SyscallDesc("lwp_alarm", unimplementedFunc),
307    /* 213 */ SyscallDesc("getdents64", unimplementedFunc),
308    /* 214 */ SyscallDesc("mmap64", unimplementedFunc),
309    /* 215 */ SyscallDesc("stat64", unimplementedFunc),
310    /* 216 */ SyscallDesc("lstat64", unimplementedFunc),
311    /* 217 */ SyscallDesc("fstat64", unimplementedFunc),
312    /* 218 */ SyscallDesc("statvfs64", unimplementedFunc),
313    /* 219 */ SyscallDesc("fstatvfs64", unimplementedFunc),
314    /* 220 */ SyscallDesc("setrlimit64", unimplementedFunc),
315    /* 221 */ SyscallDesc("getrlimit64", unimplementedFunc),
316    /* 222 */ SyscallDesc("pread64", unimplementedFunc),
317    /* 223 */ SyscallDesc("pwrite64", unimplementedFunc),
318    /* 224 */ SyscallDesc("creat64", unimplementedFunc),
319    /* 225 */ SyscallDesc("open64", unimplementedFunc),
320    /* 226 */ SyscallDesc("rpcsys", unimplementedFunc),
321    /* 227 */ SyscallDesc("reserved_227", unimplementedFunc),
322    /* 228 */ SyscallDesc("reserved_228", unimplementedFunc),
323    /* 229 */ SyscallDesc("reserved_229", unimplementedFunc),
324    /* 230 */ SyscallDesc("so_socket", unimplementedFunc),
325    /* 231 */ SyscallDesc("so_socketpair", unimplementedFunc),
326    /* 232 */ SyscallDesc("bind", unimplementedFunc),
327    /* 233 */ SyscallDesc("listen", unimplementedFunc),
328    /* 234 */ SyscallDesc("accept", unimplementedFunc),
329    /* 235 */ SyscallDesc("connect", unimplementedFunc),
330    /* 236 */ SyscallDesc("shutdown", unimplementedFunc),
331    /* 237 */ SyscallDesc("recv", unimplementedFunc),
332    /* 238 */ SyscallDesc("recvfrom", unimplementedFunc),
333    /* 239 */ SyscallDesc("recvmsg", unimplementedFunc),
334    /* 240 */ SyscallDesc("send", unimplementedFunc),
335    /* 241 */ SyscallDesc("sendmsg", unimplementedFunc),
336    /* 242 */ SyscallDesc("sendto", unimplementedFunc),
337    /* 243 */ SyscallDesc("getpeername", unimplementedFunc),
338    /* 244 */ SyscallDesc("getsockname", unimplementedFunc),
339    /* 245 */ SyscallDesc("getsockopt", unimplementedFunc),
340    /* 246 */ SyscallDesc("setsockopt", unimplementedFunc),
341    /* 247 */ SyscallDesc("sockconfig", unimplementedFunc),
342    /* 248 */ SyscallDesc("ntp_gettime", unimplementedFunc),
343    /* 249 */ SyscallDesc("ntp_adjtime", unimplementedFunc),
344    /* 250 */ SyscallDesc("lwp_mutex_unlock", unimplementedFunc),
345    /* 251 */ SyscallDesc("lwp_mutex_trylock", unimplementedFunc),
346    /* 252 */ SyscallDesc("lwp_mutex_init", unimplementedFunc),
347    /* 253 */ SyscallDesc("cladm", unimplementedFunc),
348    /* 254 */ SyscallDesc("lwp_sigtimedwait", unimplementedFunc),
349    /* 255 */ SyscallDesc("umount2", unimplementedFunc)
350};
351
352SparcSolarisProcess::SparcSolarisProcess(ProcessParams * params,
353                                         ObjectFile *objFile)
354    : Sparc64Process(params, objFile),
355     Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc))
356{
357    // The sparc syscall table must be <= 284 entries because that is all there
358    // is space for.
359    assert(Num_Syscall_Descs <= 284);
360}
361
362
363
364SyscallDesc*
365SparcSolarisProcess::getDesc(int callnum)
366{
367    if (callnum < 0 || callnum >= Num_Syscall_Descs)
368        return NULL;
369    return &syscallDescs[callnum];
370}
371