arch-power: Add multi-mode support
[gem5.git] / src / arch / power / linux / se_workload.cc
1 /*
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.
6 *
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.
17 *
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.
29 */
30
31 #include "arch/power/linux/se_workload.hh"
32
33 #include <sys/syscall.h>
34
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"
40
41 namespace
42 {
43
44 class LinuxLoader : public Process::Loader
45 {
46 public:
47 Process *
48 load(const ProcessParams &params, ::Loader::ObjectFile *obj) override
49 {
50 auto arch = obj->getArch();
51
52 if (arch != ::Loader::Power && arch != ::Loader::Power64)
53 return nullptr;
54
55 auto opsys = obj->getOpSys();
56
57 if (opsys == ::Loader::UnknownOpSys) {
58 warn("Unknown operating system; assuming Linux.");
59 opsys = ::Loader::Linux;
60 }
61
62 if ((arch == ::Loader::Power && opsys != ::Loader::Linux) ||
63 (arch == ::Loader::Power64 &&
64 opsys != ::Loader::LinuxPower64ABIv1 &&
65 opsys != ::Loader::LinuxPower64ABIv2))
66 return nullptr;
67
68 return new PowerProcess(params, obj);
69 }
70 };
71
72 LinuxLoader loader;
73
74 } // anonymous namespace
75
76 namespace PowerISA
77 {
78
79 void
80 EmuLinux::syscall(ThreadContext *tc)
81 {
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);
86
87 syscallDescs.get(tc->readIntReg(0))->doSyscall(tc);
88 }
89
90 /// Target uname() handler.
91 static SyscallReturn
92 unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<Linux::utsname> name)
93 {
94 auto process = tc->getProcessPtr();
95
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");
101
102 return 0;
103 }
104
105 SyscallDescTable<PowerISA::SEWorkload::SyscallABI> EmuLinux::syscallDescs = {
106 { 0, "syscall" },
107 { 1, "exit", exitFunc },
108 { 2, "fork" },
109 { 3, "read", readFunc<PowerLinux> },
110 { 4, "write", writeFunc<PowerLinux> },
111 { 5, "open", openFunc<PowerLinux> },
112 { 6, "close", closeFunc },
113 { 7, "waitpid" }, //???
114 { 8, "creat" },
115 { 9, "link" },
116 { 10, "unlink", unlinkFunc },
117 { 11, "execve" },
118 { 12, "chdir" },
119 { 13, "time", timeFunc<PowerLinux> },
120 { 14, "mknod" },
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 },
127 { 21, "mount" },
128 { 22, "umount" },
129 { 23, "setuid", ignoreFunc },
130 { 24, "getuid", getuidFunc },
131 { 25, "stime" },
132 { 26, "ptrace" },
133 { 27, "alarm" },
134 { 28, "unused#28" },
135 { 29, "pause" },
136 { 30, "utime" },
137 { 31, "stty" },
138 { 32, "gtty" },
139 { 33, "access" },
140 { 34, "nice" },
141 { 35, "ftime" },
142 { 36, "sync" },
143 { 37, "kill", ignoreFunc },
144 { 38, "rename", renameFunc },
145 { 39, "mkdir" },
146 { 40, "rmdir" },
147 { 41, "dup", dupFunc },
148 { 42, "pipe" },
149 { 43, "times", timesFunc<PowerLinux> },
150 { 44, "prof" },
151 { 45, "brk", brkFunc },
152 { 46, "setgid" },
153 { 47, "getgid", getgidFunc },
154 { 48, "signal", ignoreFunc },
155 { 49, "geteuid", geteuidFunc },
156 { 50, "getegid", getegidFunc },
157 { 51, "acct" },
158 { 52, "umount2" },
159 { 53, "lock" },
160 { 54, "ioctl", ioctlFunc<PowerLinux> },
161 { 55, "fcntl", fcntlFunc },
162 { 56, "mpx" },
163 { 57, "setpgid" },
164 { 58, "ulimit" },
165 { 59, "unused#59" },
166 { 60, "umask", umaskFunc },
167 { 61, "chroot" },
168 { 62, "ustat" },
169 { 63, "dup2" },
170 { 64, "getppid", getpagesizeFunc },
171 { 65, "getpgrp" },
172 { 66, "setsid" },
173 { 67, "sigaction" },
174 { 68, "sgetmask" },
175 { 69, "ssetmask" },
176 { 70, "setreuid" },
177 { 71, "setregid" },
178 { 72, "sigsuspend" },
179 { 73, "sigpending" },
180 { 74, "sethostname", ignoreFunc },
181 { 75, "setrlimit", ignoreFunc },
182 { 76, "getrlimit" },
183 { 77, "getrusage", ignoreFunc },
184 { 78, "gettimeofday" },
185 { 79, "settimeofday" },
186 { 80, "getgroups" },
187 { 81, "setgroups" },
188 { 82, "reserved#82" },
189 { 83, "symlink" },
190 { 84, "unused#84" },
191 { 85, "readlink", readlinkFunc },
192 { 86, "uselib" },
193 { 87, "swapon", gethostnameFunc },
194 { 88, "reboot" },
195 { 89, "readdir" },
196 { 90, "mmap", mmapFunc<PowerLinux> },
197 { 91, "munmap",munmapFunc },
198 { 92, "truncate", truncateFunc },
199 { 93, "ftruncate", ftruncateFunc },
200 { 94, "fchmod" },
201 { 95, "fchown" },
202 { 96, "getpriority" },
203 { 97, "setpriority" },
204 { 98, "profil" },
205 { 99, "statfs" },
206 { 100, "fstatfs" },
207 { 101, "ioperm" },
208 { 102, "socketcall" },
209 { 103, "syslog" },
210 { 104, "setitimer" },
211 { 105, "getitimer" },
212 { 106, "stat", statFunc<PowerLinux> },
213 { 107, "lstat" },
214 { 108, "fstat", fstatFunc<PowerLinux> },
215 { 109, "unused#109" },
216 { 110, "iopl" },
217 { 111, "vhangup" },
218 { 112, "idle", ignoreFunc },
219 { 113, "vm86" },
220 { 114, "wait4" },
221 { 115, "swapoff" },
222 { 116, "sysinfo" },
223 { 117, "ipc" },
224 { 118, "fsync" },
225 { 119, "sigreturn" },
226 { 120, "clone" },
227 { 121, "setdomainname" },
228 { 122, "uname", unameFunc },
229 { 123, "modify_ldt" },
230 { 124, "adjtimex" },
231 { 125, "mprotect", ignoreFunc },
232 { 126, "sigprocmask" },
233 { 127, "create_module" },
234 { 128, "init_module" },
235 { 129, "delete_module" },
236 { 130, "get_kernel_syms" },
237 { 131, "quotactl" },
238 { 132, "getpgid" },
239 { 133, "fchdir" },
240 { 134, "bdflush" },
241 { 135, "sysfs" },
242 { 136, "personality" },
243 { 137, "afs_syscall" },
244 { 138, "setfsuid" },
245 { 139, "setfsgid" },
246 { 140, "llseek", _llseekFunc },
247 { 141, "getdents" },
248 { 142, "newselect" },
249 { 143, "flock" },
250 { 144, "msync" },
251 { 145, "readv" },
252 { 146, "writev", writevFunc<PowerLinux> },
253 { 147, "getsid" },
254 { 148, "fdatasync" },
255 { 149, "sysctl" },
256 { 150, "mlock" },
257 { 151, "munlock" },
258 { 152, "mlockall" },
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" },
269 { 163, "mremap" },
270 { 164, "setresuid" },
271 { 165, "getresuid" },
272 { 166, "vm862" },
273 { 167, "query_module" },
274 { 168, "poll" },
275 { 169, "nfsservctl" },
276 { 170, "setresgid" },
277 { 171, "getresgid" },
278 { 172, "prctl" },
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" },
286 { 180, "pread64" },
287 { 181, "pwrite64" },
288 { 182, "chown" },
289 { 183, "getcwd" },
290 { 184, "capget" },
291 { 185, "capset" },
292 { 186, "sigaltstack" },
293 { 187, "sendfile" },
294 { 188, "getpmsg" },
295 { 189, "putpmsg" },
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> },
304 { 198, "lchown" },
305 { 199, "getuid", getuidFunc },
306 { 200, "getgid", getgidFunc },
307 { 201, "geteuid", geteuidFunc },
308 { 202, "getegid", getegidFunc },
309 { 203, "setreuid" },
310 { 204, "fcntl64", fcntl64Func },
311 { 205, "getgroups" },
312 { 206, "setgroups" },
313 { 207, "fchown" },
314 { 208, "setresuid" },
315 { 209, "getresuid" },
316 { 210, "setresgid" },
317 { 211, "getresgid" },
318 { 212, "chown" },
319 { 213, "setuid" },
320 { 214, "setgid" },
321 { 215, "setfsuid" },
322 { 216, "setfsgid" },
323 { 217, "getdents64" },
324 { 218, "pivot_root" },
325 { 219, "mincore" },
326 { 220, "madvise" },
327 { 221, "unknown#221" },
328 { 222, "tux" },
329 { 223, "unknown#223" },
330 { 224, "gettid" },
331 { 225, "readahead" },
332 { 226, "setxattr" },
333 { 227, "lsetxattr" },
334 { 228, "fsetxattr" },
335 { 229, "getxattr" },
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" },
344 { 238, "tkill" },
345 { 239, "sendfile64" },
346 { 240, "futex" },
347 { 241, "sched_setaffinity" },
348 { 242, "sched_getaffinity" },
349 { 243, "io_setup" },
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" },
372 { 266, "statfs64" },
373 { 267, "fstatfs64" },
374 { 268, "tgkill" },
375 { 269, "utimes" },
376 { 270, "arm_fadvise64_64" },
377 { 271, "pciconfig_iobase" },
378 { 272, "pciconfig_read" },
379 { 273, "pciconfig_write" },
380 { 274, "mq_open" },
381 { 275, "mq_unlink" },
382 { 276, "mq_timedsend" },
383 { 277, "mq_timedreceive" },
384 { 278, "mq_notify" },
385 { 279, "mq_getsetattr" },
386 { 280, "waitid" },
387 { 281, "socket" },
388 { 282, "bind" },
389 { 283, "connect" },
390 { 284, "listen" },
391 { 285, "accept" },
392 { 286, "getsockname" },
393 { 287, "getpeername" },
394 { 288, "socketpair" },
395 { 289, "send" },
396 { 290, "sendto" },
397 { 291, "recv" },
398 { 292, "recvfrom" },
399 { 293, "shutdown" },
400 { 294, "setsockopt" },
401 { 295, "getsockopt" },
402 { 296, "sendmsg" },
403 { 297, "rcvmsg" },
404 { 298, "semop" },
405 { 299, "semget" },
406 { 300, "semctl" },
407 { 301, "msgsend" },
408 { 302, "msgrcv" },
409 { 303, "msgget" },
410 { 304, "msgctl" },
411 { 305, "shmat" },
412 { 306, "shmdt" },
413 { 307, "shmget" },
414 { 308, "shmctl" },
415 { 309, "add_key" },
416 { 310, "request_key" },
417 { 311, "keyctl" },
418 { 312, "semtimedop" },
419 { 313, "vserver" },
420 { 314, "ioprio_set" },
421 { 315, "ioprio_get" },
422 { 316, "inotify_init" },
423 { 317, "inotify_add_watch" },
424 { 318, "inotify_rm_watch" },
425 { 319, "mbind" },
426 { 320, "get_mempolicy" },
427 { 321, "set_mempolicy" },
428 { 322, "openat" },
429 { 323, "mkdirat" },
430 { 324, "mknodat" },
431 { 325, "fchownat" },
432 { 326, "futimesat" },
433 { 327, "fstatat64" },
434 { 328, "unlinkat" },
435 { 329, "renameat" },
436 { 330, "linkat" },
437 { 331, "symlinkat" },
438 { 332, "readlinkat" },
439 { 333, "fchmodat" },
440 { 334, "faccessat" },
441 { 335, "pselect6" },
442 { 336, "ppoll" },
443 { 337, "unshare" },
444 { 338, "set_robust_list" },
445 { 339, "get_robust_list" },
446 { 340, "splice" },
447 { 341, "arm_sync_file_range" },
448 { 342, "tee" },
449 { 343, "vmsplice" },
450 { 344, "move_pages" },
451 { 345, "getcpu" },
452 { 346, "epoll_pwait" },
453 };
454
455 } // namespace PowerISA