arch-mips: Remove old TypeBufferArg call
[gem5.git] / src / arch / mips / linux / process.cc
1 /*
2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * Copyright (c) 2007 MIPS Technologies, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "arch/mips/linux/process.hh"
31
32 #include "arch/mips/isa_traits.hh"
33 #include "arch/mips/linux/linux.hh"
34 #include "base/loader/object_file.hh"
35 #include "base/trace.hh"
36 #include "cpu/thread_context.hh"
37 #include "debug/SyscallVerbose.hh"
38 #include "kern/linux/linux.hh"
39 #include "sim/eventq.hh"
40 #include "sim/process.hh"
41 #include "sim/syscall_desc.hh"
42 #include "sim/syscall_emul.hh"
43 #include "sim/system.hh"
44
45 using namespace std;
46 using namespace MipsISA;
47
48 namespace
49 {
50
51 class MipsLinuxObjectFileLoader : public Process::Loader
52 {
53 public:
54 Process *
55 load(ProcessParams *params, ::Loader::ObjectFile *obj_file) override
56 {
57 if (obj_file->getArch() != ::Loader::Mips)
58 return nullptr;
59
60 auto opsys = obj_file->getOpSys();
61
62 if (opsys == ::Loader::UnknownOpSys) {
63 warn("Unknown operating system; assuming Linux.");
64 opsys = ::Loader::Linux;
65 }
66
67 if (opsys != ::Loader::Linux)
68 return nullptr;
69
70 return new MipsLinuxProcess(params, obj_file);
71 }
72 };
73
74 MipsLinuxObjectFileLoader loader;
75
76 } // anonymous namespace
77
78 /// Target uname() handler.
79 static SyscallReturn
80 unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<Linux::utsname> name)
81 {
82 auto process = tc->getProcessPtr();
83
84 strcpy(name->sysname, "Linux");
85 strcpy(name->nodename,"sim.gem5.org");
86 strcpy(name->release, process->release.c_str());
87 strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
88 strcpy(name->machine, "mips");
89
90 return 0;
91 }
92
93 /// Target sys_getsysyinfo() handler. Even though this call is
94 /// borrowed from Tru64, the subcases that get used appear to be
95 /// different in practice from those used by Tru64 processes.
96 static SyscallReturn
97 sys_getsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op,
98 unsigned bufPtr, unsigned nbytes)
99 {
100 switch (op) {
101 case 45:
102 {
103 // GSI_IEEE_FP_CONTROL
104 VPtr<uint64_t> fpcr(bufPtr, tc);
105 // I don't think this exactly matches the HW FPCR
106 *fpcr = 0;
107 return 0;
108 }
109 default:
110 cerr << "sys_getsysinfo: unknown op " << op << endl;
111 abort();
112 break;
113 }
114
115 return 1;
116 }
117
118 /// Target sys_setsysinfo() handler.
119 static SyscallReturn
120 sys_setsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op,
121 Addr bufPtr, unsigned nbytes)
122 {
123 switch (op) {
124
125 case 14:
126 {
127 // SSI_IEEE_FP_CONTROL
128 ConstVPtr<uint64_t> fpcr(bufPtr, tc);
129 // I don't think this exactly matches the HW FPCR
130 DPRINTFR(SyscallVerbose, "sys_setsysinfo(SSI_IEEE_FP_CONTROL): "
131 " setting FPCR to 0x%x\n", letoh(*fpcr));
132 return 0;
133 }
134 default:
135 cerr << "sys_setsysinfo: unknown op " << op << endl;
136 abort();
137 break;
138 }
139
140 return 1;
141 }
142
143 static SyscallReturn
144 setThreadAreaFunc(SyscallDesc *desc, ThreadContext *tc, Addr addr)
145 {
146 tc->setMiscRegNoEffect(MISCREG_TP_VALUE, addr);
147 return 0;
148 }
149
150 SyscallDescTable<MipsProcess::SyscallABI> MipsLinuxProcess::syscallDescs = {
151 { 4000, "syscall" },
152 { 4001, "exit", exitFunc },
153 { 4002, "fork" },
154 { 4003, "read", readFunc<MipsLinux> },
155 { 4004, "write", writeFunc<MipsLinux> },
156 { 4005, "open", openFunc<MipsLinux> },
157 { 4006, "close", closeFunc },
158 { 4007, "waitpid" },
159 { 4008, "creat" },
160 { 4009, "link" },
161 { 4010, "unlink", unlinkFunc },
162 { 4011, "execve" },
163 { 4012, "chdir" },
164 { 4013, "time" },
165 { 4014, "mknod" },
166 { 4015, "chmod", chmodFunc<MipsLinux> },
167 { 4016, "lchown", chownFunc },
168 { 4017, "break", brkFunc },
169 { 4018, "unused#18" },
170 { 4019, "lseek", lseekFunc },
171 { 4020, "getpid", getpidFunc },
172 { 4021, "mount" },
173 { 4022, "umount" },
174 { 4023, "setuid", ignoreFunc },
175 { 4024, "getuid", getuidFunc },
176 { 4025, "stime" },
177 { 4026, "ptrace" },
178 { 4027, "alarm" },
179 { 4028, "unused#28" },
180 { 4029, "pause" },
181 { 4030, "utime" },
182 { 4031, "stty" },
183 { 4032, "gtty" },
184 { 4033, "access" },
185 { 4034, "nice" },
186 { 4035, "ftime" },
187 { 4036, "sync" },
188 { 4037, "kill" },
189 { 4038, "rename" },
190 { 4039, "mkdir", mkdirFunc },
191 { 4040, "rmdir" },
192 { 4041, "dup" },
193 { 4042, "pipe", pipePseudoFunc },
194 { 4043, "times" },
195 { 4044, "prof" },
196 { 4045, "brk", brkFunc },
197 { 4046, "setgid" },
198 { 4047, "getgid", getgidFunc },
199 { 4048, "signal", ignoreFunc },
200 { 4049, "geteuid", geteuidFunc },
201 { 4050, "getegid", getegidFunc },
202 { 4051, "acct" },
203 { 4052, "umount2" },
204 { 4053, "lock" },
205 { 4054, "ioctl", ioctlFunc<MipsLinux> },
206 { 4055, "fcntl", fcntlFunc },
207 { 4056, "mpx" },
208 { 4057, "setpgid" },
209 { 4058, "ulimit" },
210 { 4059, "unused#59" },
211 { 4060, "umask", umaskFunc },
212 { 4061, "chroot" },
213 { 4062, "ustat" },
214 { 4063, "dup2" },
215 { 4064, "getppid", getpagesizeFunc },
216 { 4065, "getpgrp" },
217 { 4066, "setsid" },
218 { 4067, "sigaction" },
219 { 4068, "sgetmask" },
220 { 4069, "ssetmask" },
221 { 4070, "setreuid" },
222 { 4071, "setregid" },
223 { 4072, "sigsuspend" },
224 { 4073, "sigpending" },
225 { 4074, "sethostname", ignoreFunc },
226 { 4075, "setrlimit" },
227 { 4076, "getrlimit" },
228 { 4077, "getrusage", getrusageFunc<MipsLinux> },
229 { 4078, "gettimeofday" },
230 { 4079, "settimeofday" },
231 { 4080, "getgroups" },
232 { 4081, "setgroups" },
233 { 4082, "reserved#82" },
234 { 4083, "symlink" },
235 { 4084, "unused#84" },
236 { 4085, "readlink", readlinkFunc },
237 { 4086, "uselib" },
238 { 4087, "swapon", gethostnameFunc },
239 { 4088, "reboot" },
240 { 4089, "readdir" },
241 { 4090, "mmap", mmapFunc<MipsLinux> },
242 { 4091, "munmap",munmapFunc },
243 { 4092, "truncate", truncateFunc },
244 { 4093, "ftruncate", ftruncateFunc },
245 { 4094, "fchmod", fchmodFunc<MipsLinux> },
246 { 4095, "fchown", fchownFunc },
247 { 4096, "getpriority" },
248 { 4097, "setpriority" },
249 { 4098, "profil" },
250 { 4099, "statfs" },
251 { 4100, "fstatfs" },
252 { 4101, "ioperm" },
253 { 4102, "socketcall" },
254 { 4103, "syslog" },
255 { 4104, "setitimer" },
256 { 4105, "getitimer" },
257 { 4106, "stat", statFunc<MipsLinux> },
258 { 4107, "lstat" },
259 { 4108, "fstat", fstatFunc<MipsLinux> },
260 { 4109, "unused#109" },
261 { 4110, "iopl" },
262 { 4111, "vhangup" },
263 { 4112, "idle", ignoreFunc },
264 { 4113, "vm86" },
265 { 4114, "wait4" },
266 { 4115, "swapoff" },
267 { 4116, "sysinfo", sysinfoFunc<MipsLinux> },
268 { 4117, "ipc" },
269 { 4118, "fsync" },
270 { 4119, "sigreturn" },
271 { 4120, "clone" },
272 { 4121, "setdomainname" },
273 { 4122, "uname", unameFunc },
274 { 4123, "modify_ldt" },
275 { 4124, "adjtimex" },
276 { 4125, "mprotect", ignoreFunc },
277 { 4126, "sigprocmask" },
278 { 4127, "create_module" },
279 { 4128, "init_module" },
280 { 4129, "delete_module" },
281 { 4130, "get_kernel_syms" },
282 { 4131, "quotactl" },
283 { 4132, "getpgid" },
284 { 4133, "fchdir" },
285 { 4134, "bdflush" },
286 { 4135, "sysfs" },
287 { 4136, "personality" },
288 { 4137, "afs_syscall" },
289 { 4138, "setfsuid" },
290 { 4139, "setfsgid" },
291 { 4140, "llseek" },
292 { 4141, "getdents" },
293 { 4142, "newselect" },
294 { 4143, "flock" },
295 { 4144, "msync" },
296 { 4145, "readv" },
297 { 4146, "writev", writevFunc<MipsLinux> },
298 { 4147, "cacheflush" },
299 { 4148, "cachectl" },
300 { 4149, "sysmips" },
301 { 4150, "unused#150" },
302 { 4151, "getsid" },
303 { 4152, "fdatasync" },
304 { 4153, "sysctl", ignoreFunc },
305 { 4154, "mlock" },
306 { 4155, "munlock" },
307 { 4156, "mlockall" },
308 { 4157, "munlockall" },
309 { 4158, "sched_setparam" },
310 { 4159, "sched_getparam" },
311 { 4160, "sched_setscheduler" },
312 { 4161, "sched_getscheduler" },
313 { 4162, "sched_yield" },
314 { 4163, "sched_get_prioritymax" },
315 { 4164, "sched_get_priority_min" },
316 { 4165, "sched_rr_get_interval" },
317 { 4166, "nanosleep" },
318 { 4167, "mremap", mremapFunc<MipsLinux> },
319 { 4168, "accept" },
320 { 4169, "bind" },
321 { 4170, "connect" },
322 { 4171, "getpeername" },
323 { 4172, "getsockname" },
324 { 4173, "getsockopt" },
325 { 4174, "listen" },
326 { 4175, "recv" },
327 { 4176, "recvmsg" },
328 { 4177, "send" },
329 { 4178, "sendmsg", ignoreFunc },
330 { 4179, "sendto" },
331 { 4180, "setsockopt" },
332 { 4181, "shutdown" },
333 { 4182, "unknown #182" },
334 { 4183, "socket", ignoreFunc },
335 { 4184, "socketpair" },
336 { 4185, "setresuid" },
337 { 4186, "getresuid" },
338 { 4187, "query_module" },
339 { 4188, "poll" },
340 { 4189, "nfsservctl" },
341 { 4190, "setresgid" },
342 { 4191, "getresgid" },
343 { 4192, "prctl" },
344 { 4193, "rt_sigreturn" },
345 { 4194, "rt_sigaction" },
346 { 4195, "rt_sigprocmask" },
347 { 4196, "rt_sigpending" },
348 { 4197, "rt_sigtimedwait" },
349 { 4198, "rt_sigqueueinfo", ignoreFunc },
350 { 4199, "rt_sigsuspend" },
351 { 4200, "pread64" },
352 { 4201, "pwrite64" },
353 { 4202, "chown" },
354 { 4203, "getcwd", getcwdFunc },
355 { 4204, "capget" },
356 { 4205, "capset" },
357 { 4206, "sigalstack" },
358 { 4207, "sendfile" },
359 { 4208, "getpmsg" },
360 { 4209, "putpmsg" },
361 { 4210, "mmap2" },
362 { 4211, "truncate64" },
363 { 4212, "ftruncate64" },
364 { 4213, "stat64" },
365 { 4214, "lstat64", lstat64Func<MipsLinux> },
366 { 4215, "fstat64", fstat64Func<MipsLinux> },
367 { 4216, "pivot_root" },
368 { 4217, "mincore" },
369 { 4218, "madvise" },
370 { 4219, "getdents64" },
371 { 4220, "fcntl64", fcntl64Func },
372 { 4221, "reserved#221" },
373 { 4222, "gettid" },
374 { 4223, "readahead" },
375 { 4224, "setxattr" },
376 { 4225, "lsetxattr" },
377 { 4226, "fsetxattr" },
378 { 4227, "getxattr" },
379 { 4228, "lgetxattr" },
380 { 4229, "fgetxattr" },
381 { 4230, "listxattr" },
382 { 4231, "llistxattr" },
383 { 4232, "flistxattr" },
384 { 4233, "removexattr" },
385 { 4234, "lremovexattr" },
386 { 4235, "fremovexattr", ignoreFunc },
387 { 4236, "tkill" },
388 { 4237, "sendfile64" },
389 { 4238, "futex" },
390 { 4239, "sched_setaffinity" },
391 { 4240, "sched_getaffinity" },
392 { 4241, "io_setup" },
393 { 4242, "io_destroy" },
394 { 4243, "io_getevents" },
395 { 4244, "io_submit" },
396 { 4245, "io_cancel" },
397 { 4246, "exit_group", exitFunc },
398 { 4247, "lookup_dcookie" },
399 { 4248, "epoll_create" },
400 { 4249, "epoll_ctl" },
401 { 4250, "epoll_wait" },
402 { 4251, "remap_file_pages" },
403 { 4252, "set_tid_address" },
404 { 4253, "restart_syscall" },
405 { 4254, "fadvise64" },
406 { 4255, "statfs64" },
407 { 4256, "fstafs64" },
408 { 4257, "timer_create", sys_getsysinfoFunc },
409 { 4258, "timer_settime", sys_setsysinfoFunc },
410 { 4259, "timer_gettime" },
411 { 4260, "timer_getoverrun" },
412 { 4261, "timer_delete" },
413 { 4262, "clock_settime" },
414 { 4263, "clock_gettime" },
415 { 4264, "clock_getres" },
416 { 4265, "clock_nanosleep" },
417 { 4266, "tgkill" },
418 { 4267, "utimes" },
419 { 4268, "mbind" },
420 { 4269, "get_mempolicy" },
421 { 4270, "set_mempolicy" },
422 { 4271, "mq_open" },
423 { 4272, "mq_unlink" },
424 { 4273, "mq_timedsend" },
425 { 4274, "mq_timedreceive" },
426 { 4275, "mq_notify" },
427 { 4276, "mq_getsetattr" },
428 { 4277, "vserver" },
429 { 4278, "waitid" },
430 { 4279, "unknown #279" },
431 { 4280, "add_key" },
432 { 4281, "request_key" },
433 { 4282, "keyctl" },
434 { 4283, "set_thread_area", setThreadAreaFunc },
435 { 4284, "inotify_init" },
436 { 4285, "inotify_add_watch" },
437 { 4286, "inotify_rm_watch" },
438 { 4287, "migrate_pages" },
439 { 4288, "openat" },
440 { 4289, "mkdirat" },
441 { 4290, "mknodat" },
442 { 4291, "fchownat" },
443 { 4292, "futimesat" },
444 { 4293, "fstatat64" },
445 { 4294, "unlinkat" },
446 { 4295, "renameat" },
447 { 4296, "linkat" },
448 { 4297, "symlinkat" },
449 { 4298, "readlinkat" },
450 { 4299, "fchmodat" },
451 { 4300, "faccessat" },
452 { 4301, "pselect6" },
453 { 4302, "ppoll" },
454 { 4303, "unshare" },
455 { 4304, "splice" },
456 { 4305, "sync_file_range" },
457 { 4306, "tee" },
458 { 4307, "vmsplice" },
459 { 4308, "move_pages" },
460 { 4309, "set_robust_list" },
461 { 4310, "get_robust_list" },
462 { 4311, "kexec_load" },
463 { 4312, "getcpu" },
464 { 4313, "epoll_pwait" },
465 { 4314, "ioprio_set" },
466 { 4315, "ioprio_get" },
467 { 4316, "utimensat" },
468 { 4317, "signalfd" },
469 { 4318, "timerfd" },
470 { 4319, "eventfd" }
471 };
472
473 MipsLinuxProcess::MipsLinuxProcess(ProcessParams * params,
474 ::Loader::ObjectFile *objFile) :
475 MipsProcess(params, objFile)
476 {}
477
478 void
479 MipsLinuxProcess::syscall(ThreadContext *tc, Fault *fault)
480 {
481 MipsProcess::syscall(tc, fault);
482 syscallDescs.get(tc->readIntReg(2))->doSyscall(tc, fault);
483 }