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

Generated on Mon Jan 13 2025 04:28:22 for gem5 by doxygen 1.9.8