2 * Copyright (c) 2005 The Regents of The University of Michigan
3 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
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.
30 #include "arch/mips/linux/process.hh"
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"
46 using namespace MipsISA
;
51 class MipsLinuxObjectFileLoader
: public Process::Loader
55 load(ProcessParams
*params
, ::Loader::ObjectFile
*obj_file
) override
57 if (obj_file
->getArch() != ::Loader::Mips
)
60 auto opsys
= obj_file
->getOpSys();
62 if (opsys
== ::Loader::UnknownOpSys
) {
63 warn("Unknown operating system; assuming Linux.");
64 opsys
= ::Loader::Linux
;
67 if (opsys
!= ::Loader::Linux
)
70 return new MipsLinuxProcess(params
, obj_file
);
74 MipsLinuxObjectFileLoader loader
;
76 } // anonymous namespace
78 /// Target uname() handler.
80 unameFunc(SyscallDesc
*desc
, ThreadContext
*tc
, VPtr
<Linux::utsname
> name
)
82 auto process
= tc
->getProcessPtr();
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");
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.
97 sys_getsysinfoFunc(SyscallDesc
*desc
, ThreadContext
*tc
, unsigned op
,
98 unsigned bufPtr
, unsigned nbytes
)
103 // GSI_IEEE_FP_CONTROL
104 VPtr
<uint64_t> fpcr(bufPtr
, tc
);
105 // I don't think this exactly matches the HW FPCR
110 cerr
<< "sys_getsysinfo: unknown op " << op
<< endl
;
118 /// Target sys_setsysinfo() handler.
120 sys_setsysinfoFunc(SyscallDesc
*desc
, ThreadContext
*tc
, unsigned op
,
121 Addr bufPtr
, unsigned nbytes
)
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
));
135 cerr
<< "sys_setsysinfo: unknown op " << op
<< endl
;
144 setThreadAreaFunc(SyscallDesc
*desc
, ThreadContext
*tc
, Addr addr
)
146 tc
->setMiscRegNoEffect(MISCREG_TP_VALUE
, addr
);
150 SyscallDescTable
<MipsProcess::SyscallABI
> MipsLinuxProcess::syscallDescs
= {
152 { 4001, "exit", exitFunc
},
154 { 4003, "read", readFunc
<MipsLinux
> },
155 { 4004, "write", writeFunc
<MipsLinux
> },
156 { 4005, "open", openFunc
<MipsLinux
> },
157 { 4006, "close", closeFunc
},
161 { 4010, "unlink", unlinkFunc
},
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
},
174 { 4023, "setuid", ignoreFunc
},
175 { 4024, "getuid", getuidFunc
},
179 { 4028, "unused#28" },
190 { 4039, "mkdir", mkdirFunc
},
193 { 4042, "pipe", pipePseudoFunc
},
196 { 4045, "brk", brkFunc
},
198 { 4047, "getgid", getgidFunc
},
199 { 4048, "signal", ignoreFunc
},
200 { 4049, "geteuid", geteuidFunc
},
201 { 4050, "getegid", getegidFunc
},
205 { 4054, "ioctl", ioctlFunc
<MipsLinux
> },
206 { 4055, "fcntl", fcntlFunc
},
210 { 4059, "unused#59" },
211 { 4060, "umask", umaskFunc
},
215 { 4064, "getppid", getpagesizeFunc
},
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" },
235 { 4084, "unused#84" },
236 { 4085, "readlink", readlinkFunc
},
238 { 4087, "swapon", gethostnameFunc
},
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" },
253 { 4102, "socketcall" },
255 { 4104, "setitimer" },
256 { 4105, "getitimer" },
257 { 4106, "stat", statFunc
<MipsLinux
> },
259 { 4108, "fstat", fstatFunc
<MipsLinux
> },
260 { 4109, "unused#109" },
263 { 4112, "idle", ignoreFunc
},
267 { 4116, "sysinfo", sysinfoFunc
<MipsLinux
> },
270 { 4119, "sigreturn" },
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" },
287 { 4136, "personality" },
288 { 4137, "afs_syscall" },
289 { 4138, "setfsuid" },
290 { 4139, "setfsgid" },
292 { 4141, "getdents" },
293 { 4142, "newselect" },
297 { 4146, "writev", writevFunc
<MipsLinux
> },
298 { 4147, "cacheflush" },
299 { 4148, "cachectl" },
301 { 4150, "unused#150" },
303 { 4152, "fdatasync" },
304 { 4153, "sysctl", ignoreFunc
},
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
> },
322 { 4171, "getpeername" },
323 { 4172, "getsockname" },
324 { 4173, "getsockopt" },
329 { 4178, "sendmsg", ignoreFunc
},
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" },
340 { 4189, "nfsservctl" },
341 { 4190, "setresgid" },
342 { 4191, "getresgid" },
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" },
352 { 4201, "pwrite64" },
354 { 4203, "getcwd", getcwdFunc
},
357 { 4206, "sigalstack" },
358 { 4207, "sendfile" },
362 { 4211, "truncate64" },
363 { 4212, "ftruncate64" },
365 { 4214, "lstat64", lstat64Func
<MipsLinux
> },
366 { 4215, "fstat64", fstat64Func
<MipsLinux
> },
367 { 4216, "pivot_root" },
370 { 4219, "getdents64" },
371 { 4220, "fcntl64", fcntl64Func
},
372 { 4221, "reserved#221" },
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
},
388 { 4237, "sendfile64" },
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" },
420 { 4269, "get_mempolicy" },
421 { 4270, "set_mempolicy" },
423 { 4272, "mq_unlink" },
424 { 4273, "mq_timedsend" },
425 { 4274, "mq_timedreceive" },
426 { 4275, "mq_notify" },
427 { 4276, "mq_getsetattr" },
430 { 4279, "unknown #279" },
432 { 4281, "request_key" },
434 { 4283, "set_thread_area", setThreadAreaFunc
},
435 { 4284, "inotify_init" },
436 { 4285, "inotify_add_watch" },
437 { 4286, "inotify_rm_watch" },
438 { 4287, "migrate_pages" },
442 { 4291, "fchownat" },
443 { 4292, "futimesat" },
444 { 4293, "fstatat64" },
445 { 4294, "unlinkat" },
446 { 4295, "renameat" },
448 { 4297, "symlinkat" },
449 { 4298, "readlinkat" },
450 { 4299, "fchmodat" },
451 { 4300, "faccessat" },
452 { 4301, "pselect6" },
456 { 4305, "sync_file_range" },
458 { 4307, "vmsplice" },
459 { 4308, "move_pages" },
460 { 4309, "set_robust_list" },
461 { 4310, "get_robust_list" },
462 { 4311, "kexec_load" },
464 { 4313, "epoll_pwait" },
465 { 4314, "ioprio_set" },
466 { 4315, "ioprio_get" },
467 { 4316, "utimensat" },
468 { 4317, "signalfd" },
473 MipsLinuxProcess::MipsLinuxProcess(ProcessParams
* params
,
474 ::Loader::ObjectFile
*objFile
) :
475 MipsProcess(params
, objFile
)
479 MipsLinuxProcess::syscall(ThreadContext
*tc
, Fault
*fault
)
481 MipsProcess::syscall(tc
, fault
);
482 syscallDescs
.get(tc
->readIntReg(2))->doSyscall(tc
, fault
);