2 * Copyright 2003-2005 The Regents of The University of Michigan
3 * Copyright 2007-2008 The Florida State University
4 * Copyright 2009 The University of Edinburgh
5 * Copyright 2020 Google Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "arch/power/linux/se_workload.hh"
33 #include <sys/syscall.h>
35 #include "arch/power/process.hh"
36 #include "base/loader/object_file.hh"
37 #include "base/trace.hh"
38 #include "cpu/thread_context.hh"
39 #include "sim/syscall_emul.hh"
44 class LinuxLoader
: public Process::Loader
48 load(const ProcessParams
¶ms
, ::Loader::ObjectFile
*obj
) override
50 auto arch
= obj
->getArch();
52 if (arch
!= ::Loader::Power
&& arch
!= ::Loader::Power64
)
55 auto opsys
= obj
->getOpSys();
57 if (opsys
== ::Loader::UnknownOpSys
) {
58 warn("Unknown operating system; assuming Linux.");
59 opsys
= ::Loader::Linux
;
62 if ((arch
== ::Loader::Power
&& opsys
!= ::Loader::Linux
) ||
63 (arch
== ::Loader::Power64
&&
64 opsys
!= ::Loader::LinuxPower64ABIv1
&&
65 opsys
!= ::Loader::LinuxPower64ABIv2
))
68 return new PowerProcess(params
, obj
);
74 } // anonymous namespace
80 EmuLinux::syscall(ThreadContext
*tc
)
82 Process
*process
= tc
->getProcessPtr();
83 // Call the syscall function in the base Process class to update stats.
84 // This will move into the base SEWorkload function at some point.
85 process
->Process::syscall(tc
);
87 syscallDescs
.get(tc
->readIntReg(0))->doSyscall(tc
);
90 /// Target uname() handler.
92 unameFunc(SyscallDesc
*desc
, ThreadContext
*tc
, VPtr
<Linux::utsname
> name
)
94 auto process
= tc
->getProcessPtr();
96 strcpy(name
->sysname
, "Linux");
97 strcpy(name
->nodename
, "sim.gem5.org");
98 strcpy(name
->release
, process
->release
.c_str());
99 strcpy(name
->version
, "#1 Mon Aug 18 11:32:15 EDT 2003");
100 strcpy(name
->machine
, "power");
105 SyscallDescTable
<PowerISA::SEWorkload::SyscallABI
> EmuLinux::syscallDescs
= {
107 { 1, "exit", exitFunc
},
109 { 3, "read", readFunc
<PowerLinux
> },
110 { 4, "write", writeFunc
<PowerLinux
> },
111 { 5, "open", openFunc
<PowerLinux
> },
112 { 6, "close", closeFunc
},
113 { 7, "waitpid" }, //???
116 { 10, "unlink", unlinkFunc
},
119 { 13, "time", timeFunc
<PowerLinux
> },
121 { 15, "chmod", chmodFunc
<PowerLinux
> },
122 { 16, "lchown", chownFunc
},
123 { 17, "break", brkFunc
}, //???
124 { 18, "unused#18" }, //???
125 { 19, "lseek", lseekFunc
},
126 { 20, "getpid", getpidFunc
},
129 { 23, "setuid", ignoreFunc
},
130 { 24, "getuid", getuidFunc
},
143 { 37, "kill", ignoreFunc
},
144 { 38, "rename", renameFunc
},
147 { 41, "dup", dupFunc
},
149 { 43, "times", timesFunc
<PowerLinux
> },
151 { 45, "brk", brkFunc
},
153 { 47, "getgid", getgidFunc
},
154 { 48, "signal", ignoreFunc
},
155 { 49, "geteuid", geteuidFunc
},
156 { 50, "getegid", getegidFunc
},
160 { 54, "ioctl", ioctlFunc
<PowerLinux
> },
161 { 55, "fcntl", fcntlFunc
},
166 { 60, "umask", umaskFunc
},
170 { 64, "getppid", getpagesizeFunc
},
178 { 72, "sigsuspend" },
179 { 73, "sigpending" },
180 { 74, "sethostname", ignoreFunc
},
181 { 75, "setrlimit", ignoreFunc
},
183 { 77, "getrusage", ignoreFunc
},
184 { 78, "gettimeofday" },
185 { 79, "settimeofday" },
188 { 82, "reserved#82" },
191 { 85, "readlink", readlinkFunc
},
193 { 87, "swapon", gethostnameFunc
},
196 { 90, "mmap", mmapFunc
<PowerLinux
> },
197 { 91, "munmap",munmapFunc
},
198 { 92, "truncate", truncateFunc
},
199 { 93, "ftruncate", ftruncateFunc
},
202 { 96, "getpriority" },
203 { 97, "setpriority" },
208 { 102, "socketcall" },
210 { 104, "setitimer" },
211 { 105, "getitimer" },
212 { 106, "stat", statFunc
<PowerLinux
> },
214 { 108, "fstat", fstatFunc
<PowerLinux
> },
215 { 109, "unused#109" },
218 { 112, "idle", ignoreFunc
},
225 { 119, "sigreturn" },
227 { 121, "setdomainname" },
228 { 122, "uname", unameFunc
},
229 { 123, "modify_ldt" },
231 { 125, "mprotect", ignoreFunc
},
232 { 126, "sigprocmask" },
233 { 127, "create_module" },
234 { 128, "init_module" },
235 { 129, "delete_module" },
236 { 130, "get_kernel_syms" },
242 { 136, "personality" },
243 { 137, "afs_syscall" },
246 { 140, "llseek", _llseekFunc
},
248 { 142, "newselect" },
252 { 146, "writev", writevFunc
<PowerLinux
> },
254 { 148, "fdatasync" },
259 { 153, "munlockall" },
260 { 154, "sched_setparam" },
261 { 155, "sched_getparam" },
262 { 156, "sched_setscheduler" },
263 { 157, "sched_getscheduler" },
264 { 158, "sched_yield" },
265 { 159, "sched_get_priority_max" },
266 { 160, "sched_get_priority_min" },
267 { 161, "sched_rr_get_interval" },
268 { 162, "nanosleep" },
270 { 164, "setresuid" },
271 { 165, "getresuid" },
273 { 167, "query_module" },
275 { 169, "nfsservctl" },
276 { 170, "setresgid" },
277 { 171, "getresgid" },
279 { 173, "rt_sigaction", ignoreFunc
},
280 { 174, "rt_sigprocmask" },
281 { 175, "unknown#175" },
282 { 176, "rt_sigpending" },
283 { 177, "rt_sigtimedwait" },
284 { 178, "rt_sigqueueinfo", ignoreFunc
},
285 { 179, "rt_sigsuspend" },
292 { 186, "sigaltstack" },
296 { 190, "ugetrlimit", ignoreFunc
},
297 { 191, "getrlimit" },
298 { 192, "mmap2", mmapFunc
<PowerLinux
> },
299 { 193, "truncate64" },
300 { 194, "ftruncate64", ftruncate64Func
},
301 { 195, "stat64", stat64Func
<PowerLinux
> },
302 { 196, "lstat64", lstat64Func
<PowerLinux
> },
303 { 197, "fstat64", fstat64Func
<PowerLinux
> },
305 { 199, "getuid", getuidFunc
},
306 { 200, "getgid", getgidFunc
},
307 { 201, "geteuid", geteuidFunc
},
308 { 202, "getegid", getegidFunc
},
310 { 204, "fcntl64", fcntl64Func
},
311 { 205, "getgroups" },
312 { 206, "setgroups" },
314 { 208, "setresuid" },
315 { 209, "getresuid" },
316 { 210, "setresgid" },
317 { 211, "getresgid" },
323 { 217, "getdents64" },
324 { 218, "pivot_root" },
327 { 221, "unknown#221" },
329 { 223, "unknown#223" },
331 { 225, "readahead" },
333 { 227, "lsetxattr" },
334 { 228, "fsetxattr" },
336 { 230, "lgetxattr" },
337 { 231, "fgetxattr" },
338 { 232, "listxattr" },
339 { 233, "llistxattr" },
340 { 234, "exit_group", exitGroupFunc
},
341 { 235, "removexattr" },
342 { 236, "lremovexattr" },
343 { 237, "fremovexattr" },
345 { 239, "sendfile64" },
347 { 241, "sched_setaffinity" },
348 { 242, "sched_getaffinity" },
350 { 244, "io_destory" },
351 { 245, "io_getevents" },
352 { 246, "io_submit" },
353 { 247, "io_cancel" },
354 { 248, "unknown#248" },
355 { 249, "lookup_dcookie" },
356 { 250, "epoll_create" },
357 { 251, "epoll_ctl" },
358 { 252, "epoll_wait" },
359 { 253, "remap_file_pages" },
360 { 254, "set_thread_area" },
361 { 255, "get_thread_area" },
362 { 256, "set_tid_address" },
363 { 257, "timer_create" },
364 { 258, "timer_settime" },
365 { 259, "timer_gettime" },
366 { 260, "timer_getoverrun" },
367 { 261, "timer_delete" },
368 { 262, "clock_settime" },
369 { 263, "clock_gettime" },
370 { 264, "clock_getres" },
371 { 265, "clock_nanosleep" },
373 { 267, "fstatfs64" },
376 { 270, "arm_fadvise64_64" },
377 { 271, "pciconfig_iobase" },
378 { 272, "pciconfig_read" },
379 { 273, "pciconfig_write" },
381 { 275, "mq_unlink" },
382 { 276, "mq_timedsend" },
383 { 277, "mq_timedreceive" },
384 { 278, "mq_notify" },
385 { 279, "mq_getsetattr" },
392 { 286, "getsockname" },
393 { 287, "getpeername" },
394 { 288, "socketpair" },
400 { 294, "setsockopt" },
401 { 295, "getsockopt" },
416 { 310, "request_key" },
418 { 312, "semtimedop" },
420 { 314, "ioprio_set" },
421 { 315, "ioprio_get" },
422 { 316, "inotify_init" },
423 { 317, "inotify_add_watch" },
424 { 318, "inotify_rm_watch" },
426 { 320, "get_mempolicy" },
427 { 321, "set_mempolicy" },
432 { 326, "futimesat" },
433 { 327, "fstatat64" },
437 { 331, "symlinkat" },
438 { 332, "readlinkat" },
440 { 334, "faccessat" },
444 { 338, "set_robust_list" },
445 { 339, "get_robust_list" },
447 { 341, "arm_sync_file_range" },
450 { 344, "move_pages" },
452 { 346, "epoll_pwait" },
455 } // namespace PowerISA