gem5  v22.1.0.0
se_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2005 The Regents of The University of Michigan
3  * Copyright 2007 MIPS Technologies, Inc.
4  * Copyright 2020 Google Inc.
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 
31 
32 #include <sys/syscall.h>
33 
34 #include "arch/mips/process.hh"
35 #include "arch/mips/regs/misc.hh"
37 #include "base/trace.hh"
38 #include "cpu/thread_context.hh"
39 #include "sim/syscall_emul.hh"
40 
41 namespace gem5
42 {
43 
44 namespace
45 {
46 
47 class LinuxLoader : public Process::Loader
48 {
49  public:
50  Process *
51  load(const ProcessParams &params, loader::ObjectFile *obj) override
52  {
53  if (obj->getArch() != loader::Mips)
54  return nullptr;
55 
56  auto opsys = obj->getOpSys();
57 
58  if (opsys == loader::UnknownOpSys) {
59  warn("Unknown operating system; assuming Linux.");
60  opsys = loader::Linux;
61  }
62 
63  if (opsys != loader::Linux)
64  return nullptr;
65 
66  return new MipsProcess(params, obj);
67  }
68 };
69 
70 LinuxLoader linuxLoader;
71 
72 } // anonymous namespace
73 
74 namespace MipsISA
75 {
76 
77 void
79 {
80  Process *process = tc->getProcessPtr();
81  // Call the syscall function in the base Process class to update stats.
82  // This will move into the base SEWorkload function at some point.
83  process->Process::syscall(tc);
84 
86 }
87 
89 static SyscallReturn
91 {
92  auto process = tc->getProcessPtr();
93 
94  strcpy(name->sysname, "Linux");
95  strcpy(name->nodename,"sim.gem5.org");
96  strcpy(name->release, process->release.c_str());
97  strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
98  strcpy(name->machine, "mips");
99 
100  return 0;
101 }
102 
106 static SyscallReturn
108  unsigned bufPtr, unsigned nbytes)
109 {
110  switch (op) {
111  case 45:
112  {
113  // GSI_IEEE_FP_CONTROL
114  VPtr<uint64_t> fpcr(bufPtr, tc);
115  // I don't think this exactly matches the HW FPCR
116  *fpcr = 0;
117  return 0;
118  }
119  default:
120  std::cerr << "sys_getsysinfo: unknown op " << op << std::endl;
121  abort();
122  break;
123  }
124 
125  return 1;
126 }
127 
129 static SyscallReturn
131  VPtr<> bufPtr, unsigned nbytes)
132 {
133  switch (op) {
134 
135  case 14:
136  {
137  // SSI_IEEE_FP_CONTROL
138  ConstVPtr<uint64_t> fpcr(bufPtr, tc);
139  // I don't think this exactly matches the HW FPCR
140  DPRINTFR(SyscallVerbose, "sys_setsysinfo(SSI_IEEE_FP_CONTROL): "
141  " setting FPCR to 0x%x\n", letoh(*fpcr));
142  return 0;
143  }
144  default:
145  std::cerr << "sys_setsysinfo: unknown op " << op << std::endl;
146  abort();
147  break;
148  }
149 
150  return 1;
151 }
152 
153 static SyscallReturn
155 {
157  return 0;
158 }
159 
161  { 4000, "syscall" },
162  { 4001, "exit", exitFunc },
163  { 4002, "fork" },
164  { 4003, "read", readFunc<MipsLinux> },
165  { 4004, "write", writeFunc<MipsLinux> },
166  { 4005, "open", openFunc<MipsLinux> },
167  { 4006, "close", closeFunc },
168  { 4007, "waitpid" },
169  { 4008, "creat" },
170  { 4009, "link" },
171  { 4010, "unlink", unlinkFunc },
172  { 4011, "execve" },
173  { 4012, "chdir" },
174  { 4013, "time" },
175  { 4014, "mknod" },
176  { 4015, "chmod", chmodFunc<MipsLinux> },
177  { 4016, "lchown", chownFunc },
178  { 4017, "break", brkFunc },
179  { 4018, "unused#18" },
180  { 4019, "lseek", lseekFunc },
181  { 4020, "getpid", getpidFunc },
182  { 4021, "mount" },
183  { 4022, "umount" },
184  { 4023, "setuid", ignoreFunc },
185  { 4024, "getuid", getuidFunc },
186  { 4025, "stime" },
187  { 4026, "ptrace" },
188  { 4027, "alarm" },
189  { 4028, "unused#28" },
190  { 4029, "pause" },
191  { 4030, "utime" },
192  { 4031, "stty" },
193  { 4032, "gtty" },
194  { 4033, "access" },
195  { 4034, "nice" },
196  { 4035, "ftime" },
197  { 4036, "sync" },
198  { 4037, "kill" },
199  { 4038, "rename" },
200  { 4039, "mkdir", mkdirFunc },
201  { 4040, "rmdir" },
202  { 4041, "dup" },
203  { 4042, "pipe", pipePseudoFunc },
204  { 4043, "times" },
205  { 4044, "prof" },
206  { 4045, "brk", brkFunc },
207  { 4046, "setgid" },
208  { 4047, "getgid", getgidFunc },
209  { 4048, "signal", ignoreFunc },
210  { 4049, "geteuid", geteuidFunc },
211  { 4050, "getegid", getegidFunc },
212  { 4051, "acct" },
213  { 4052, "umount2" },
214  { 4053, "lock" },
215  { 4054, "ioctl", ioctlFunc<MipsLinux> },
216  { 4055, "fcntl", fcntlFunc },
217  { 4056, "mpx" },
218  { 4057, "setpgid" },
219  { 4058, "ulimit" },
220  { 4059, "unused#59" },
221  { 4060, "umask", umaskFunc },
222  { 4061, "chroot" },
223  { 4062, "ustat" },
224  { 4063, "dup2" },
225  { 4064, "getppid", getpagesizeFunc },
226  { 4065, "getpgrp" },
227  { 4066, "setsid" },
228  { 4067, "sigaction" },
229  { 4068, "sgetmask" },
230  { 4069, "ssetmask" },
231  { 4070, "setreuid" },
232  { 4071, "setregid" },
233  { 4072, "sigsuspend" },
234  { 4073, "sigpending" },
235  { 4074, "sethostname", ignoreFunc },
236  { 4075, "setrlimit" },
237  { 4076, "getrlimit" },
238  { 4077, "getrusage", getrusageFunc<MipsLinux> },
239  { 4078, "gettimeofday" },
240  { 4079, "settimeofday" },
241  { 4080, "getgroups" },
242  { 4081, "setgroups" },
243  { 4082, "reserved#82" },
244  { 4083, "symlink" },
245  { 4084, "unused#84" },
246  { 4085, "readlink", readlinkFunc<MipsLinux> },
247  { 4086, "uselib" },
248  { 4087, "swapon", gethostnameFunc },
249  { 4088, "reboot" },
250  { 4089, "readdir" },
251  { 4090, "mmap", mmapFunc<MipsLinux> },
252  { 4091, "munmap",munmapFunc<MipsLinux> },
253  { 4092, "truncate", truncateFunc<MipsLinux> },
254  { 4093, "ftruncate", ftruncateFunc<MipsLinux> },
255  { 4094, "fchmod", fchmodFunc<MipsLinux> },
256  { 4095, "fchown", fchownFunc },
257  { 4096, "getpriority" },
258  { 4097, "setpriority" },
259  { 4098, "profil" },
260  { 4099, "statfs" },
261  { 4100, "fstatfs" },
262  { 4101, "ioperm" },
263  { 4102, "socketcall" },
264  { 4103, "syslog" },
265  { 4104, "setitimer" },
266  { 4105, "getitimer" },
267  { 4106, "stat", statFunc<MipsLinux> },
268  { 4107, "lstat" },
269  { 4108, "fstat", fstatFunc<MipsLinux> },
270  { 4109, "unused#109" },
271  { 4110, "iopl" },
272  { 4111, "vhangup" },
273  { 4112, "idle", ignoreFunc },
274  { 4113, "vm86" },
275  { 4114, "wait4" },
276  { 4115, "swapoff" },
277  { 4116, "sysinfo", sysinfoFunc<MipsLinux> },
278  { 4117, "ipc" },
279  { 4118, "fsync" },
280  { 4119, "sigreturn" },
281  { 4120, "clone" },
282  { 4121, "setdomainname" },
283  { 4122, "uname", unameFunc },
284  { 4123, "modify_ldt" },
285  { 4124, "adjtimex" },
286  { 4125, "mprotect", ignoreFunc },
287  { 4126, "sigprocmask" },
288  { 4127, "create_module" },
289  { 4128, "init_module" },
290  { 4129, "delete_module" },
291  { 4130, "get_kernel_syms" },
292  { 4131, "quotactl" },
293  { 4132, "getpgid" },
294  { 4133, "fchdir" },
295  { 4134, "bdflush" },
296  { 4135, "sysfs" },
297  { 4136, "personality" },
298  { 4137, "afs_syscall" },
299  { 4138, "setfsuid" },
300  { 4139, "setfsgid" },
301  { 4140, "llseek" },
302  { 4141, "getdents" },
303  { 4142, "newselect" },
304  { 4143, "flock" },
305  { 4144, "msync" },
306  { 4145, "readv" },
307  { 4146, "writev", writevFunc<MipsLinux> },
308  { 4147, "cacheflush" },
309  { 4148, "cachectl" },
310  { 4149, "sysmips" },
311  { 4150, "unused#150" },
312  { 4151, "getsid" },
313  { 4152, "fdatasync" },
314  { 4153, "sysctl", ignoreFunc },
315  { 4154, "mlock" },
316  { 4155, "munlock" },
317  { 4156, "mlockall" },
318  { 4157, "munlockall" },
319  { 4158, "sched_setparam" },
320  { 4159, "sched_getparam" },
321  { 4160, "sched_setscheduler" },
322  { 4161, "sched_getscheduler" },
323  { 4162, "sched_yield" },
324  { 4163, "sched_get_prioritymax" },
325  { 4164, "sched_get_priority_min" },
326  { 4165, "sched_rr_get_interval" },
327  { 4166, "nanosleep" },
328  { 4167, "mremap", mremapFunc<MipsLinux> },
329  { 4168, "accept" },
330  { 4169, "bind" },
331  { 4170, "connect" },
332  { 4171, "getpeername" },
333  { 4172, "getsockname" },
334  { 4173, "getsockopt" },
335  { 4174, "listen" },
336  { 4175, "recv" },
337  { 4176, "recvmsg" },
338  { 4177, "send" },
339  { 4178, "sendmsg", ignoreFunc },
340  { 4179, "sendto" },
341  { 4180, "setsockopt" },
342  { 4181, "shutdown" },
343  { 4182, "unknown #182" },
344  { 4183, "socket", ignoreFunc },
345  { 4184, "socketpair" },
346  { 4185, "setresuid" },
347  { 4186, "getresuid" },
348  { 4187, "query_module" },
349  { 4188, "poll" },
350  { 4189, "nfsservctl" },
351  { 4190, "setresgid" },
352  { 4191, "getresgid" },
353  { 4192, "prctl" },
354  { 4193, "rt_sigreturn" },
355  { 4194, "rt_sigaction" },
356  { 4195, "rt_sigprocmask" },
357  { 4196, "rt_sigpending" },
358  { 4197, "rt_sigtimedwait" },
359  { 4198, "rt_sigqueueinfo", ignoreFunc },
360  { 4199, "rt_sigsuspend" },
361  { 4200, "pread64" },
362  { 4201, "pwrite64" },
363  { 4202, "chown" },
364  { 4203, "getcwd", getcwdFunc },
365  { 4204, "capget" },
366  { 4205, "capset" },
367  { 4206, "sigalstack" },
368  { 4207, "sendfile" },
369  { 4208, "getpmsg" },
370  { 4209, "putpmsg" },
371  { 4210, "mmap2" },
372  { 4211, "truncate64" },
373  { 4212, "ftruncate64" },
374  { 4213, "stat64" },
375  { 4214, "lstat64", lstat64Func<MipsLinux> },
376  { 4215, "fstat64", fstat64Func<MipsLinux> },
377  { 4216, "pivot_root" },
378  { 4217, "mincore" },
379  { 4218, "madvise" },
380  { 4219, "getdents64" },
381  { 4220, "fcntl64", fcntl64Func },
382  { 4221, "reserved#221" },
383  { 4222, "gettid" },
384  { 4223, "readahead" },
385  { 4224, "setxattr" },
386  { 4225, "lsetxattr" },
387  { 4226, "fsetxattr" },
388  { 4227, "getxattr" },
389  { 4228, "lgetxattr" },
390  { 4229, "fgetxattr" },
391  { 4230, "listxattr" },
392  { 4231, "llistxattr" },
393  { 4232, "flistxattr" },
394  { 4233, "removexattr" },
395  { 4234, "lremovexattr" },
396  { 4235, "fremovexattr", ignoreFunc },
397  { 4236, "tkill" },
398  { 4237, "sendfile64" },
399  { 4238, "futex" },
400  { 4239, "sched_setaffinity" },
401  { 4240, "sched_getaffinity" },
402  { 4241, "io_setup" },
403  { 4242, "io_destroy" },
404  { 4243, "io_getevents" },
405  { 4244, "io_submit" },
406  { 4245, "io_cancel" },
407  { 4246, "exit_group", exitFunc },
408  { 4247, "lookup_dcookie" },
409  { 4248, "epoll_create" },
410  { 4249, "epoll_ctl" },
411  { 4250, "epoll_wait" },
412  { 4251, "remap_file_pages" },
413  { 4252, "set_tid_address" },
414  { 4253, "restart_syscall" },
415  { 4254, "fadvise64" },
416  { 4255, "statfs64" },
417  { 4256, "fstafs64" },
418  { 4257, "timer_create", sys_getsysinfoFunc },
419  { 4258, "timer_settime", sys_setsysinfoFunc },
420  { 4259, "timer_gettime" },
421  { 4260, "timer_getoverrun" },
422  { 4261, "timer_delete" },
423  { 4262, "clock_settime" },
424  { 4263, "clock_gettime" },
425  { 4264, "clock_getres" },
426  { 4265, "clock_nanosleep" },
427  { 4266, "tgkill" },
428  { 4267, "utimes" },
429  { 4268, "mbind" },
430  { 4269, "get_mempolicy" },
431  { 4270, "set_mempolicy" },
432  { 4271, "mq_open" },
433  { 4272, "mq_unlink" },
434  { 4273, "mq_timedsend" },
435  { 4274, "mq_timedreceive" },
436  { 4275, "mq_notify" },
437  { 4276, "mq_getsetattr" },
438  { 4277, "vserver" },
439  { 4278, "waitid" },
440  { 4279, "unknown #279" },
441  { 4280, "add_key" },
442  { 4281, "request_key" },
443  { 4282, "keyctl" },
444  { 4283, "set_thread_area", setThreadAreaFunc },
445  { 4284, "inotify_init" },
446  { 4285, "inotify_add_watch" },
447  { 4286, "inotify_rm_watch" },
448  { 4287, "migrate_pages" },
449  { 4288, "openat" },
450  { 4289, "mkdirat" },
451  { 4290, "mknodat" },
452  { 4291, "fchownat" },
453  { 4292, "futimesat" },
454  { 4293, "fstatat64" },
455  { 4294, "unlinkat" },
456  { 4295, "renameat" },
457  { 4296, "linkat" },
458  { 4297, "symlinkat" },
459  { 4298, "readlinkat" },
460  { 4299, "fchmodat" },
461  { 4300, "faccessat" },
462  { 4301, "pselect6" },
463  { 4302, "ppoll" },
464  { 4303, "unshare" },
465  { 4304, "splice" },
466  { 4305, "sync_file_range" },
467  { 4306, "tee" },
468  { 4307, "vmsplice" },
469  { 4308, "move_pages" },
470  { 4309, "set_robust_list" },
471  { 4310, "get_robust_list" },
472  { 4311, "kexec_load" },
473  { 4312, "getcpu" },
474  { 4313, "epoll_pwait" },
475  { 4314, "ioprio_set" },
476  { 4315, "ioprio_get" },
477  { 4316, "utimensat" },
478  { 4317, "signalfd" },
479  { 4318, "timerfd" },
480  { 4319, "eventfd" }
481 };
482 
483 } // namespace MipsISA
484 } // namespace gem5
#define DPRINTFR(x,...)
Definition: trace.hh:200
void syscall(ThreadContext *tc) override
Definition: se_workload.cc:78
static SyscallDescTable< SyscallABI > syscallDescs
Syscall descriptors, indexed by call number.
Definition: se_workload.hh:48
SyscallDesc * get(int num, bool fatal_if_missing=true)
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:70
void doSyscall(ThreadContext *tc)
Interface for invoking the system call funcion pointer.
Definition: syscall_desc.cc:42
This class represents the return value from an emulated system call, including any errno setting.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId &reg) const
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual Process * getProcessPtr()=0
#define warn(...)
Definition: logging.hh:246
constexpr RegId V0
Definition: int.hh:136
static SyscallReturn sys_getsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op, unsigned bufPtr, unsigned nbytes)
Target sys_getsysyinfo() handler.
Definition: se_workload.cc:107
static SyscallReturn unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< Linux::utsname > name)
Target uname() handler.
Definition: se_workload.cc:90
static SyscallReturn setThreadAreaFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> addr)
Definition: se_workload.cc:154
static SyscallReturn sys_setsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op, VPtr<> bufPtr, unsigned nbytes)
Target sys_setsysinfo() handler.
Definition: se_workload.cc:130
Bitfield< 4 > op
Definition: types.hh:83
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
T letoh(T value)
Definition: byteswap.hh:173
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> new_brk)
Target brk() handler: set brk address.
SyscallReturn getpidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpid() handler.
SyscallReturn getuidFunc(SyscallDesc *desc, ThreadContext *tc)
SyscallReturn pipePseudoFunc(SyscallDesc *desc, ThreadContext *tc)
Pseudo Funcs - These functions use a different return convension, returning a second value in a regis...
SyscallReturn chownFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname, uint32_t owner, uint32_t group)
Target chown() handler.
SyscallReturn geteuidFunc(SyscallDesc *desc, ThreadContext *tc)
Target geteuid() handler.
SyscallReturn getcwdFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> buf_ptr, unsigned long size)
Target getcwd() handler.
SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname)
Target unlink() handler.
SyscallReturn fcntl64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd)
Target fcntl64() handler.
SyscallReturn getpagesizeFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpagesize() handler.
SyscallReturn mkdirFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> pathname, mode_t mode)
Target mkdir() handler.
SyscallReturn fchownFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t owner, uint32_t group)
Target fchown() handler.
SyscallReturn fcntlFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd, guest_abi::VarArgs< int > varargs)
Target fcntl() handler.
SyscallReturn getegidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getegid() handler.
SyscallReturn lseekFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
Target lseek() handler.
SyscallReturn gethostnameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<> buf_ptr, int name_len)
Target gethostname() handler.
SyscallReturn ignoreFunc(SyscallDesc *desc, ThreadContext *tc)
Handler for unimplemented syscalls that we never intend to implement (signal handling,...
Definition: syscall_emul.cc:72
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
SyscallReturn getgidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getgid() handler.
SyscallReturn closeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
Target close() handler.
SyscallReturn umaskFunc(SyscallDesc *desc, ThreadContext *tc)
Target umask() handler.
This file defines objects used to emulate syscalls from the target application on the host machine.
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:25 for gem5 by doxygen 1.9.1