From: Gabe Black Date: Wed, 21 Oct 2020 00:37:03 +0000 (-0700) Subject: riscv: Implement an SE workload for Linux. X-Git-Tag: develop-gem5-snapshot~547 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a78abf07b7568589a2585397f4c17799626664e8;p=gem5.git riscv: Implement an SE workload for Linux. Change-Id: Ieb7058007e56ce0c8d153c1853e4b92237e98ab8 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34156 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/arch/riscv/RiscvSeWorkload.py b/src/arch/riscv/RiscvSeWorkload.py new file mode 100644 index 000000000..c4f61bf83 --- /dev/null +++ b/src/arch/riscv/RiscvSeWorkload.py @@ -0,0 +1,44 @@ +# Copyright 2020 Google Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from m5.params import * + +from m5.objects.Workload import SEWorkload + +class RiscvSEWorkload(SEWorkload): + type = 'RiscvSEWorkload' + cxx_header = "arch/riscv/se_workload.hh" + cxx_class = 'RiscvISA::SEWorkload' + abstract = True + +class RiscvEmuLinux(RiscvSEWorkload): + type = 'RiscvEmuLinux' + cxx_header = "arch/riscv/linux/se_workload.hh" + cxx_class = 'RiscvISA::EmuLinux' + + @classmethod + def _is_compatible_with(cls, obj): + return obj.get_arch() in ('riscv64', 'riscv32') and \ + obj.get_op_sys() in ('linux', 'unknown') diff --git a/src/arch/riscv/SConscript b/src/arch/riscv/SConscript index 3fddd3123..5f1aedc9b 100644 --- a/src/arch/riscv/SConscript +++ b/src/arch/riscv/SConscript @@ -53,9 +53,10 @@ if env['TARGET_ISA'] == 'riscv': Source('pagetable.cc') Source('pagetable_walker.cc') Source('remote_gdb.cc') + Source('se_workload.cc') Source('tlb.cc') - Source('linux/process.cc') + Source('linux/se_workload.cc') Source('linux/linux.cc') Source('bare_metal/fs_workload.cc') @@ -64,6 +65,7 @@ if env['TARGET_ISA'] == 'riscv': SimObject('RiscvInterrupts.py') SimObject('RiscvISA.py') SimObject('RiscvMMU.py') + SimObject('RiscvSeWorkload.py') SimObject('RiscvTLB.py') DebugFlag('RiscvMisc') diff --git a/src/arch/riscv/linux/process.cc b/src/arch/riscv/linux/process.cc deleted file mode 100644 index 5c0624de5..000000000 --- a/src/arch/riscv/linux/process.cc +++ /dev/null @@ -1,799 +0,0 @@ -/* - * Copyright (c) 2005 The Regents of The University of Michigan - * Copyright (c) 2007 MIPS Technologies, Inc. - * Copyright (c) 2016 The University of Virginia - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "arch/riscv/linux/process.hh" - -#include - -#include "arch/riscv/isa_traits.hh" -#include "arch/riscv/linux/linux.hh" -#include "base/loader/object_file.hh" -#include "base/trace.hh" -#include "cpu/thread_context.hh" -#include "debug/SyscallVerbose.hh" -#include "kern/linux/linux.hh" -#include "sim/eventq.hh" -#include "sim/process.hh" -#include "sim/syscall_desc.hh" -#include "sim/syscall_emul.hh" -#include "sim/system.hh" - -using namespace std; -using namespace RiscvISA; - -namespace -{ - -class RiscvLinuxObjectFileLoader : public Process::Loader -{ - public: - Process * - load(const ProcessParams ¶ms, ::Loader::ObjectFile *obj_file) override - { - auto arch = obj_file->getArch(); - auto opsys = obj_file->getOpSys(); - - if (arch != ::Loader::Riscv64 && arch != ::Loader::Riscv32) - return nullptr; - - if (opsys == ::Loader::UnknownOpSys) { - warn("Unknown operating system; assuming Linux."); - opsys = ::Loader::Linux; - } - - if (opsys != ::Loader::Linux) - return nullptr; - - if (arch == ::Loader::Riscv64) - return new RiscvLinuxProcess64(params, obj_file); - else - return new RiscvLinuxProcess32(params, obj_file); - } -}; - -RiscvLinuxObjectFileLoader loader; - -} // anonymous namespace - -/// Target uname() handler. -static SyscallReturn -unameFunc64(SyscallDesc *desc, ThreadContext *tc, VPtr name) -{ - auto process = tc->getProcessPtr(); - - strcpy(name->sysname, "Linux"); - strcpy(name->nodename,"sim.gem5.org"); - strcpy(name->release, process->release.c_str()); - strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); - strcpy(name->machine, "riscv64"); - - return 0; -} - -/// Target uname() handler. -static SyscallReturn -unameFunc32(SyscallDesc *desc, ThreadContext *tc, VPtr name) -{ - auto process = tc->getProcessPtr(); - - strcpy(name->sysname, "Linux"); - strcpy(name->nodename,"sim.gem5.org"); - strcpy(name->release, process->release.c_str()); - strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); - strcpy(name->machine, "riscv32"); - - return 0; -} - -SyscallDescTable - RiscvLinuxProcess64::syscallDescs = { - { 0, "io_setup" }, - { 1, "io_destroy" }, - { 2, "io_submit" }, - { 3, "io_cancel" }, - { 4, "io_getevents" }, - { 5, "setxattr" }, - { 6, "lsetxattr" }, - { 7, "fsetxattr" }, - { 8, "getxattr" }, - { 9, "lgetxattr" }, - { 10, "fgetxattr" }, - { 11, "listxattr" }, - { 12, "llistxattr" }, - { 13, "flistxattr" }, - { 14, "removexattr" }, - { 15, "lremovexattr" }, - { 16, "fremovexattr" }, - { 17, "getcwd", getcwdFunc }, - { 18, "lookup_dcookie" }, - { 19, "eventfd2" }, - { 20, "epoll_create1" }, - { 21, "epoll_ctl" }, - { 22, "epoll_pwait" }, - { 23, "dup", dupFunc }, - { 24, "dup3" }, - { 25, "fcntl", fcntl64Func }, - { 26, "inotify_init1" }, - { 27, "inotify_add_watch" }, - { 28, "inotify_rm_watch" }, - { 29, "ioctl", ioctlFunc }, - { 30, "ioprio_get" }, - { 31, "ioprio_set" }, - { 32, "flock" }, - { 33, "mknodat" }, - { 34, "mkdirat" }, - { 35, "unlinkat", unlinkatFunc }, - { 36, "symlinkat" }, - { 37, "linkat" }, - { 38, "renameat", renameatFunc }, - { 39, "umount2" }, - { 40, "mount" }, - { 41, "pivot_root" }, - { 42, "nfsservctl" }, - { 43, "statfs", statfsFunc }, - { 44, "fstatfs", fstatfsFunc }, - { 45, "truncate", truncateFunc }, - { 46, "ftruncate", ftruncate64Func }, - { 47, "fallocate", fallocateFunc }, - { 48, "faccessat", faccessatFunc }, - { 49, "chdir" }, - { 50, "fchdir" }, - { 51, "chroot" }, - { 52, "fchmod", fchmodFunc }, - { 53, "fchmodat" }, - { 54, "fchownat" }, - { 55, "fchown", fchownFunc }, - { 56, "openat", openatFunc }, - { 57, "close", closeFunc }, - { 58, "vhangup" }, - { 59, "pipe2" }, - { 60, "quotactl" }, - { 61, "getdents64" }, - { 62, "lseek", lseekFunc }, - { 63, "read", readFunc }, - { 64, "write", writeFunc }, - { 66, "writev", writevFunc }, - { 67, "pread64" }, - { 68, "pwrite64", pwrite64Func }, - { 69, "preadv" }, - { 70, "pwritev" }, - { 71, "sendfile" }, - { 72, "pselect6" }, - { 73, "ppoll" }, - { 74, "signalfd64" }, - { 75, "vmsplice" }, - { 76, "splice" }, - { 77, "tee" }, - { 78, "readlinkat", readlinkatFunc }, - { 79, "fstatat", fstatat64Func }, - { 80, "fstat", fstat64Func }, - { 81, "sync" }, - { 82, "fsync" }, - { 83, "fdatasync" }, - { 84, "sync_file_range2" }, - { 85, "timerfd_create" }, - { 86, "timerfd_settime" }, - { 87, "timerfd_gettime" }, - { 88, "utimensat" }, - { 89, "acct" }, - { 90, "capget" }, - { 91, "capset" }, - { 92, "personality" }, - { 93, "exit", exitFunc }, - { 94, "exit_group", exitGroupFunc }, - { 95, "waitid" }, - { 96, "set_tid_address", setTidAddressFunc }, - { 97, "unshare" }, - { 98, "futex", futexFunc }, - { 99, "set_robust_list", ignoreWarnOnceFunc }, - { 100, "get_robust_list", ignoreWarnOnceFunc }, - { 101, "nanosleep", ignoreWarnOnceFunc }, - { 102, "getitimer" }, - { 103, "setitimer" }, - { 104, "kexec_load" }, - { 105, "init_module" }, - { 106, "delete_module" }, - { 107, "timer_create" }, - { 108, "timer_gettime" }, - { 109, "timer_getoverrun" }, - { 110, "timer_settime" }, - { 111, "timer_delete" }, - { 112, "clock_settime" }, - { 113, "clock_gettime", clock_gettimeFunc }, - { 114, "clock_getres", clock_getresFunc }, - { 115, "clock_nanosleep" }, - { 116, "syslog" }, - { 117, "ptrace" }, - { 118, "sched_setparam" }, - { 119, "sched_setscheduler" }, - { 120, "sched_getscheduler" }, - { 121, "sched_getparam" }, - { 122, "sched_setaffinity" }, - { 123, "sched_getaffinity" }, - { 124, "sched_yield", ignoreWarnOnceFunc }, - { 125, "sched_get_priority_max" }, - { 126, "sched_get_priority_min" }, - { 127, "scheD_rr_get_interval" }, - { 128, "restart_syscall" }, - { 129, "kill" }, - { 130, "tkill" }, - { 131, "tgkill", tgkillFunc }, - { 132, "sigaltstack" }, - { 133, "rt_sigsuspend", ignoreWarnOnceFunc }, - { 134, "rt_sigaction", ignoreWarnOnceFunc }, - { 135, "rt_sigprocmask", ignoreWarnOnceFunc }, - { 136, "rt_sigpending", ignoreWarnOnceFunc }, - { 137, "rt_sigtimedwait", ignoreWarnOnceFunc }, - { 138, "rt_sigqueueinfo", ignoreWarnOnceFunc }, - { 139, "rt_sigreturn", ignoreWarnOnceFunc }, - { 140, "setpriority" }, - { 141, "getpriority" }, - { 142, "reboot" }, - { 143, "setregid" }, - { 144, "setgid" }, - { 145, "setreuid" }, - { 146, "setuid", ignoreFunc }, - { 147, "setresuid" }, - { 148, "getresuid" }, - { 149, "getresgid" }, - { 150, "getresgid" }, - { 151, "setfsuid" }, - { 152, "setfsgid" }, - { 153, "times", timesFunc }, - { 154, "setpgid", setpgidFunc }, - { 155, "getpgid" }, - { 156, "getsid" }, - { 157, "setsid" }, - { 158, "getgroups" }, - { 159, "setgroups" }, - { 160, "uname", unameFunc64 }, - { 161, "sethostname" }, - { 162, "setdomainname" }, - { 163, "getrlimit", getrlimitFunc }, - { 164, "setrlimit", ignoreFunc }, - { 165, "getrusage", getrusageFunc }, - { 166, "umask", umaskFunc }, - { 167, "prctl" }, - { 168, "getcpu" }, - { 169, "gettimeofday", gettimeofdayFunc }, - { 170, "settimeofday" }, - { 171, "adjtimex" }, - { 172, "getpid", getpidFunc }, - { 173, "getppid", getppidFunc }, - { 174, "getuid", getuidFunc }, - { 175, "geteuid", geteuidFunc }, - { 176, "getgid", getgidFunc }, - { 177, "getegid", getegidFunc }, - { 178, "gettid", gettidFunc }, - { 179, "sysinfo", sysinfoFunc }, - { 180, "mq_open" }, - { 181, "mq_unlink" }, - { 182, "mq_timedsend" }, - { 183, "mq_timedrecieve" }, - { 184, "mq_notify" }, - { 185, "mq_getsetattr" }, - { 186, "msgget" }, - { 187, "msgctl" }, - { 188, "msgrcv" }, - { 189, "msgsnd" }, - { 190, "semget" }, - { 191, "semctl" }, - { 192, "semtimedop" }, - { 193, "semop" }, - { 194, "shmget" }, - { 195, "shmctl" }, - { 196, "shmat" }, - { 197, "shmdt" }, - { 198, "socket" }, - { 199, "socketpair" }, - { 200, "bind" }, - { 201, "listen" }, - { 202, "accept" }, - { 203, "connect" }, - { 204, "getsockname" }, - { 205, "getpeername" }, - { 206, "sendo" }, - { 207, "recvfrom" }, - { 208, "setsockopt" }, - { 209, "getsockopt" }, - { 210, "shutdown" }, - { 211, "sendmsg" }, - { 212, "recvmsg" }, - { 213, "readahead" }, - { 214, "brk", brkFunc }, - { 215, "munmap", munmapFunc }, - { 216, "mremap", mremapFunc }, - { 217, "add_key" }, - { 218, "request_key" }, - { 219, "keyctl" }, - { 220, "clone", cloneBackwardsFunc }, - { 221, "execve", execveFunc }, - { 222, "mmap", mmapFunc }, - { 223, "fadvise64" }, - { 224, "swapon" }, - { 225, "swapoff" }, - { 226, "mprotect", ignoreFunc }, - { 227, "msync", ignoreFunc }, - { 228, "mlock", ignoreFunc }, - { 229, "munlock", ignoreFunc }, - { 230, "mlockall", ignoreFunc }, - { 231, "munlockall", ignoreFunc }, - { 232, "mincore", ignoreFunc }, - { 233, "madvise", ignoreFunc }, - { 234, "remap_file_pages" }, - { 235, "mbind", ignoreFunc }, - { 236, "get_mempolicy" }, - { 237, "set_mempolicy" }, - { 238, "migrate_pages" }, - { 239, "move_pages" }, - { 240, "tgsigqueueinfo" }, - { 241, "perf_event_open" }, - { 242, "accept4" }, - { 243, "recvmmsg" }, - { 260, "wait4" }, - { 261, "prlimit64", prlimitFunc }, - { 262, "fanotify_init" }, - { 263, "fanotify_mark" }, - { 264, "name_to_handle_at" }, - { 265, "open_by_handle_at" }, - { 266, "clock_adjtime" }, - { 267, "syncfs" }, - { 268, "setns" }, - { 269, "sendmmsg" }, - { 270, "process_vm_ready" }, - { 271, "process_vm_writev" }, - { 272, "kcmp" }, - { 273, "finit_module" }, - { 274, "sched_setattr" }, - { 275, "sched_getattr" }, - { 276, "renameat2" }, - { 277, "seccomp" }, - { 278, "getrandom" }, - { 279, "memfd_create" }, - { 280, "bpf" }, - { 281, "execveat" }, - { 282, "userfaultid" }, - { 283, "membarrier" }, - { 284, "mlock2" }, - { 285, "copy_file_range" }, - { 286, "preadv2" }, - { 287, "pwritev2" }, - { 1024, "open", openFunc }, - { 1025, "link" }, - { 1026, "unlink", unlinkFunc }, - { 1027, "mknod" }, - { 1028, "chmod", chmodFunc }, - { 1029, "chown", chownFunc }, - { 1030, "mkdir", mkdirFunc }, - { 1031, "rmdir" }, - { 1032, "lchown" }, - { 1033, "access", accessFunc }, - { 1034, "rename", renameFunc }, - { 1035, "readlink", readlinkFunc }, - { 1036, "symlink" }, - { 1037, "utimes", utimesFunc }, - { 1038, "stat", stat64Func }, - { 1039, "lstat", lstat64Func }, - { 1040, "pipe", pipeFunc }, - { 1041, "dup2", dup2Func }, - { 1042, "epoll_create" }, - { 1043, "inotifiy_init" }, - { 1044, "eventfd" }, - { 1045, "signalfd" }, - { 1046, "sendfile" }, - { 1047, "ftruncate", ftruncate64Func }, - { 1048, "truncate", truncate64Func }, - { 1049, "stat", stat64Func }, - { 1050, "lstat", lstat64Func }, - { 1051, "fstat", fstat64Func }, - { 1052, "fcntl", fcntl64Func }, - { 1053, "fadvise64" }, - { 1054, "newfstatat" }, - { 1055, "fstatfs", fstatfsFunc }, - { 1056, "statfs", statfsFunc }, - { 1057, "lseek", lseekFunc }, - { 1058, "mmap", mmapFunc }, - { 1059, "alarm" }, - { 1060, "getpgrp" }, - { 1061, "pause" }, - { 1062, "time", timeFunc }, - { 1063, "utime" }, - { 1064, "creat" }, - { 1065, "getdents" }, - { 1066, "futimesat" }, - { 1067, "select" }, - { 1068, "poll" }, - { 1069, "epoll_wait" }, - { 1070, "ustat" }, - { 1071, "vfork" }, - { 1072, "oldwait4" }, - { 1073, "recv" }, - { 1074, "send" }, - { 1075, "bdflush" }, - { 1076, "umount" }, - { 1077, "uselib" }, - { 1078, "sysctl" }, - { 1079, "fork" }, - { 2011, "getmainvars" } -}; - -SyscallDescTable - RiscvLinuxProcess32::syscallDescs = { - { 0, "io_setup" }, - { 1, "io_destroy" }, - { 2, "io_submit" }, - { 3, "io_cancel" }, - { 4, "io_getevents" }, - { 5, "setxattr" }, - { 6, "lsetxattr" }, - { 7, "fsetxattr" }, - { 8, "getxattr" }, - { 9, "lgetxattr" }, - { 10, "fgetxattr" }, - { 11, "listxattr" }, - { 12, "llistxattr" }, - { 13, "flistxattr" }, - { 14, "removexattr" }, - { 15, "lremovexattr" }, - { 16, "fremovexattr" }, - { 17, "getcwd", getcwdFunc }, - { 18, "lookup_dcookie" }, - { 19, "eventfd2" }, - { 20, "epoll_create1" }, - { 21, "epoll_ctl" }, - { 22, "epoll_pwait" }, - { 23, "dup", dupFunc }, - { 24, "dup3" }, - { 25, "fcntl", fcntlFunc }, - { 26, "inotify_init1" }, - { 27, "inotify_add_watch" }, - { 28, "inotify_rm_watch" }, - { 29, "ioctl", ioctlFunc }, - { 30, "ioprio_get" }, - { 31, "ioprio_set" }, - { 32, "flock" }, - { 33, "mknodat" }, - { 34, "mkdirat" }, - { 35, "unlinkat", unlinkatFunc }, - { 36, "symlinkat" }, - { 37, "linkat" }, - { 38, "renameat", renameatFunc }, - { 39, "umount2" }, - { 40, "mount" }, - { 41, "pivot_root" }, - { 42, "nfsservctl" }, - { 43, "statfs", statfsFunc }, - { 44, "fstatfs", fstatfsFunc }, - { 45, "truncate", truncateFunc }, - { 46, "ftruncate", ftruncateFunc }, - { 47, "fallocate", fallocateFunc }, - { 48, "faccessat", faccessatFunc }, - { 49, "chdir" }, - { 50, "fchdir" }, - { 51, "chroot" }, - { 52, "fchmod", fchmodFunc }, - { 53, "fchmodat" }, - { 54, "fchownat" }, - { 55, "fchown", fchownFunc }, - { 56, "openat", openatFunc }, - { 57, "close", closeFunc }, - { 58, "vhangup" }, - { 59, "pipe2" }, - { 60, "quotactl" }, - { 61, "getdents64" }, - { 62, "lseek", lseekFunc }, - { 63, "read", readFunc }, - { 64, "write", writeFunc }, - { 66, "writev", writevFunc }, - { 67, "pread64" }, - { 68, "pwrite64", pwrite64Func }, - { 69, "preadv" }, - { 70, "pwritev" }, - { 71, "sendfile" }, - { 72, "pselect6" }, - { 73, "ppoll" }, - { 74, "signalfd64" }, - { 75, "vmsplice" }, - { 76, "splice" }, - { 77, "tee" }, - { 78, "readlinkat", readlinkatFunc }, - { 79, "fstatat" }, - { 80, "fstat", fstatFunc }, - { 81, "sync" }, - { 82, "fsync" }, - { 83, "fdatasync" }, - { 84, "sync_file_range2" }, - { 85, "timerfd_create" }, - { 86, "timerfd_settime" }, - { 87, "timerfd_gettime" }, - { 88, "utimensat" }, - { 89, "acct" }, - { 90, "capget" }, - { 91, "capset" }, - { 92, "personality" }, - { 93, "exit", exitFunc }, - { 94, "exit_group", exitGroupFunc }, - { 95, "waitid" }, - { 96, "set_tid_address", setTidAddressFunc }, - { 97, "unshare" }, - { 98, "futex", futexFunc }, - { 99, "set_robust_list", ignoreWarnOnceFunc }, - { 100, "get_robust_list", ignoreWarnOnceFunc }, - { 101, "nanosleep" }, - { 102, "getitimer" }, - { 103, "setitimer" }, - { 104, "kexec_load" }, - { 105, "init_module" }, - { 106, "delete_module" }, - { 107, "timer_create" }, - { 108, "timer_gettime" }, - { 109, "timer_getoverrun" }, - { 110, "timer_settime" }, - { 111, "timer_delete" }, - { 112, "clock_settime" }, - { 113, "clock_gettime", clock_gettimeFunc }, - { 114, "clock_getres", clock_getresFunc }, - { 115, "clock_nanosleep" }, - { 116, "syslog" }, - { 117, "ptrace" }, - { 118, "sched_setparam" }, - { 119, "sched_setscheduler" }, - { 120, "sched_getscheduler" }, - { 121, "sched_getparam" }, - { 122, "sched_setaffinity" }, - { 123, "sched_getaffinity" }, - { 124, "sched_yield", ignoreWarnOnceFunc }, - { 125, "sched_get_priority_max" }, - { 126, "sched_get_priority_min" }, - { 127, "scheD_rr_get_interval" }, - { 128, "restart_syscall" }, - { 129, "kill" }, - { 130, "tkill" }, - { 131, "tgkill", tgkillFunc }, - { 132, "sigaltstack" }, - { 133, "rt_sigsuspend", ignoreWarnOnceFunc }, - { 134, "rt_sigaction", ignoreWarnOnceFunc }, - { 135, "rt_sigprocmask", ignoreWarnOnceFunc }, - { 136, "rt_sigpending", ignoreWarnOnceFunc }, - { 137, "rt_sigtimedwait", ignoreWarnOnceFunc }, - { 138, "rt_sigqueueinfo", ignoreWarnOnceFunc }, - { 139, "rt_sigreturn", ignoreWarnOnceFunc }, - { 140, "setpriority" }, - { 141, "getpriority" }, - { 142, "reboot" }, - { 143, "setregid" }, - { 144, "setgid" }, - { 145, "setreuid" }, - { 146, "setuid", ignoreFunc }, - { 147, "setresuid" }, - { 148, "getresuid" }, - { 149, "getresgid" }, - { 150, "getresgid" }, - { 151, "setfsuid" }, - { 152, "setfsgid" }, - { 153, "times", timesFunc }, - { 154, "setpgid", setpgidFunc }, - { 155, "getpgid" }, - { 156, "getsid" }, - { 157, "setsid" }, - { 158, "getgroups" }, - { 159, "setgroups" }, - { 160, "uname", unameFunc32 }, - { 161, "sethostname" }, - { 162, "setdomainname" }, - { 163, "getrlimit", getrlimitFunc }, - { 164, "setrlimit", ignoreFunc }, - { 165, "getrusage", getrusageFunc }, - { 166, "umask", umaskFunc }, - { 167, "prctl" }, - { 168, "getcpu" }, - { 169, "gettimeofday", gettimeofdayFunc }, - { 170, "settimeofday" }, - { 171, "adjtimex" }, - { 172, "getpid", getpidFunc }, - { 173, "getppid", getppidFunc }, - { 174, "getuid", getuidFunc }, - { 175, "geteuid", geteuidFunc }, - { 176, "getgid", getgidFunc }, - { 177, "getegid", getegidFunc }, - { 178, "gettid", gettidFunc }, - { 179, "sysinfo", sysinfoFunc }, - { 180, "mq_open" }, - { 181, "mq_unlink" }, - { 182, "mq_timedsend" }, - { 183, "mq_timedrecieve" }, - { 184, "mq_notify" }, - { 185, "mq_getsetattr" }, - { 186, "msgget" }, - { 187, "msgctl" }, - { 188, "msgrcv" }, - { 189, "msgsnd" }, - { 190, "semget" }, - { 191, "semctl" }, - { 192, "semtimedop" }, - { 193, "semop" }, - { 194, "shmget" }, - { 195, "shmctl" }, - { 196, "shmat" }, - { 197, "shmdt" }, - { 198, "socket" }, - { 199, "socketpair" }, - { 200, "bind" }, - { 201, "listen" }, - { 202, "accept" }, - { 203, "connect" }, - { 204, "getsockname" }, - { 205, "getpeername" }, - { 206, "sendo" }, - { 207, "recvfrom" }, - { 208, "setsockopt" }, - { 209, "getsockopt" }, - { 210, "shutdown" }, - { 211, "sendmsg" }, - { 212, "recvmsg" }, - { 213, "readahead" }, - { 214, "brk", brkFunc }, - { 215, "munmap", munmapFunc }, - { 216, "mremap", mremapFunc }, - { 217, "add_key" }, - { 218, "request_key" }, - { 219, "keyctl" }, - { 220, "clone", cloneBackwardsFunc }, - { 221, "execve", execveFunc }, - { 222, "mmap", mmapFunc }, - { 223, "fadvise64" }, - { 224, "swapon" }, - { 225, "swapoff" }, - { 226, "mprotect", ignoreFunc }, - { 227, "msync", ignoreFunc }, - { 228, "mlock", ignoreFunc }, - { 229, "munlock", ignoreFunc }, - { 230, "mlockall", ignoreFunc }, - { 231, "munlockall", ignoreFunc }, - { 232, "mincore", ignoreFunc }, - { 233, "madvise", ignoreFunc }, - { 234, "remap_file_pages" }, - { 235, "mbind", ignoreFunc }, - { 236, "get_mempolicy" }, - { 237, "set_mempolicy" }, - { 238, "migrate_pages" }, - { 239, "move_pages" }, - { 240, "tgsigqueueinfo" }, - { 241, "perf_event_open" }, - { 242, "accept4" }, - { 243, "recvmmsg" }, - { 260, "wait4" }, - { 261, "prlimit64", prlimitFunc }, - { 262, "fanotify_init" }, - { 263, "fanotify_mark" }, - { 264, "name_to_handle_at" }, - { 265, "open_by_handle_at" }, - { 266, "clock_adjtime" }, - { 267, "syncfs" }, - { 268, "setns" }, - { 269, "sendmmsg" }, - { 270, "process_vm_ready" }, - { 271, "process_vm_writev" }, - { 272, "kcmp" }, - { 273, "finit_module" }, - { 274, "sched_setattr" }, - { 275, "sched_getattr" }, - { 276, "renameat2" }, - { 277, "seccomp" }, - { 278, "getrandom" }, - { 279, "memfd_create" }, - { 280, "bpf" }, - { 281, "execveat" }, - { 282, "userfaultid" }, - { 283, "membarrier" }, - { 284, "mlock2" }, - { 285, "copy_file_range" }, - { 286, "preadv2" }, - { 287, "pwritev2" }, - { 1024, "open", openFunc }, - { 1025, "link" }, - { 1026, "unlink", unlinkFunc }, - { 1027, "mknod" }, - { 1028, "chmod", chmodFunc }, - { 1029, "chown", chownFunc }, - { 1030, "mkdir", mkdirFunc }, - { 1031, "rmdir" }, - { 1032, "lchown" }, - { 1033, "access", accessFunc }, - { 1034, "rename", renameFunc }, - { 1035, "readlink", readlinkFunc }, - { 1036, "symlink" }, - { 1037, "utimes", utimesFunc }, - { 1038, "stat", statFunc }, - { 1039, "lstat", lstatFunc }, - { 1040, "pipe", pipeFunc }, - { 1041, "dup2", dup2Func }, - { 1042, "epoll_create" }, - { 1043, "inotifiy_init" }, - { 1044, "eventfd" }, - { 1045, "signalfd" }, - { 1046, "sendfile" }, - { 1047, "ftruncate", ftruncateFunc }, - { 1048, "truncate", truncateFunc }, - { 1049, "stat", statFunc }, - { 1050, "lstat", lstatFunc }, - { 1051, "fstat", fstatFunc }, - { 1052, "fcntl", fcntlFunc }, - { 1053, "fadvise64" }, - { 1054, "newfstatat" }, - { 1055, "fstatfs", fstatfsFunc }, - { 1056, "statfs", statfsFunc }, - { 1057, "lseek", lseekFunc }, - { 1058, "mmap", mmapFunc }, - { 1059, "alarm" }, - { 1060, "getpgrp" }, - { 1061, "pause" }, - { 1062, "time", timeFunc }, - { 1063, "utime" }, - { 1064, "creat" }, - { 1065, "getdents" }, - { 1066, "futimesat" }, - { 1067, "select" }, - { 1068, "poll" }, - { 1069, "epoll_wait" }, - { 1070, "ustat" }, - { 1071, "vfork" }, - { 1072, "oldwait4" }, - { 1073, "recv" }, - { 1074, "send" }, - { 1075, "bdflush" }, - { 1076, "umount" }, - { 1077, "uselib" }, - { 1078, "sysctl" }, - { 1079, "fork" }, - { 2011, "getmainvars" } -}; - -RiscvLinuxProcess64::RiscvLinuxProcess64(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile) : RiscvProcess64(params, objFile) -{} - -void -RiscvLinuxProcess64::syscall(ThreadContext *tc) -{ - RiscvProcess64::syscall(tc); - syscallDescs.get(tc->readIntReg(SyscallNumReg))->doSyscall(tc); -} - -RiscvLinuxProcess32::RiscvLinuxProcess32(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile) : RiscvProcess32(params, objFile) -{} - -void -RiscvLinuxProcess32::syscall(ThreadContext *tc) -{ - RiscvProcess32::syscall(tc); - syscallDescs.get(tc->readIntReg(SyscallNumReg))->doSyscall(tc); -} diff --git a/src/arch/riscv/linux/process.hh b/src/arch/riscv/linux/process.hh deleted file mode 100644 index dd9157cbd..000000000 --- a/src/arch/riscv/linux/process.hh +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2004 The Regents of The University of Michigan - * Copyright (c) 2016 The University of Virginia - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __RISCV_LINUX_PROCESS_HH__ -#define __RISCV_LINUX_PROCESS_HH__ - -#include - -#include "arch/riscv/linux/linux.hh" -#include "arch/riscv/process.hh" -#include "sim/eventq.hh" -#include "sim/syscall_desc.hh" - -/// A process with emulated Riscv/Linux syscalls. -class RiscvLinuxProcess64 : public RiscvProcess64 -{ - public: - /// Constructor. - RiscvLinuxProcess64(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile); - - /// The target system's hostname. - static const char *hostname; - - /// ID of the thread group leader for the process - uint64_t __tgid; - - void syscall(ThreadContext *tc) override; - - /// Syscall descriptors, indexed by call number. - static SyscallDescTable syscallDescs; -}; - -class RiscvLinuxProcess32 : public RiscvProcess32 -{ - public: - /// Constructor. - RiscvLinuxProcess32(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile); - - /// The target system's hostname. - static const char *hostname; - - /// ID of the thread group leader for the process - uint64_t __tgid; - - void syscall(ThreadContext *tc) override; - - /// Array of syscall descriptors, indexed by call number. - static SyscallDescTable syscallDescs; -}; - -#endif // __RISCV_LINUX_PROCESS_HH__ diff --git a/src/arch/riscv/linux/se_workload.cc b/src/arch/riscv/linux/se_workload.cc new file mode 100644 index 000000000..03a61d6d6 --- /dev/null +++ b/src/arch/riscv/linux/se_workload.cc @@ -0,0 +1,791 @@ +/* + * Copyright 2005 The Regents of The University of Michigan + * Copyright 2007 MIPS Technologies, Inc. + * Copyright 2016 The University of Virginia + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "arch/riscv/linux/se_workload.hh" + +#include + +#include "arch/riscv/process.hh" +#include "base/loader/object_file.hh" +#include "base/trace.hh" +#include "cpu/thread_context.hh" +#include "sim/syscall_emul.hh" + +namespace +{ + +class LinuxLoader : public Process::Loader +{ + public: + Process * + load(const ProcessParams ¶ms, ::Loader::ObjectFile *obj) override + { + auto arch = obj->getArch(); + auto opsys = obj->getOpSys(); + + if (arch != ::Loader::Riscv64 && arch != ::Loader::Riscv32) + return nullptr; + + if (opsys == ::Loader::UnknownOpSys) { + warn("Unknown operating system; assuming Linux."); + opsys = ::Loader::Linux; + } + + if (opsys != ::Loader::Linux) + return nullptr; + + if (arch == ::Loader::Riscv64) + return new RiscvProcess64(params, obj); + else + return new RiscvProcess32(params, obj); + } +}; + +LinuxLoader loader; + +} // anonymous namespace + +namespace RiscvISA +{ + +void +EmuLinux::syscall(ThreadContext *tc) +{ + Process *process = tc->getProcessPtr(); + // Call the syscall function in the base Process class to update stats. + // This will move into the base SEWorkload function at some point. + process->Process::syscall(tc); + + RegVal num = tc->readIntReg(RiscvISA::SyscallNumReg); + if (dynamic_cast(process)) + syscallDescs64.get(num)->doSyscall(tc); + else + syscallDescs32.get(num)->doSyscall(tc); +} + +/// Target uname() handler. +static SyscallReturn +unameFunc64(SyscallDesc *desc, ThreadContext *tc, VPtr name) +{ + auto process = tc->getProcessPtr(); + + strcpy(name->sysname, "Linux"); + strcpy(name->nodename,"sim.gem5.org"); + strcpy(name->release, process->release.c_str()); + strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); + strcpy(name->machine, "riscv64"); + + return 0; +} + +/// Target uname() handler. +static SyscallReturn +unameFunc32(SyscallDesc *desc, ThreadContext *tc, VPtr name) +{ + auto process = tc->getProcessPtr(); + + strcpy(name->sysname, "Linux"); + strcpy(name->nodename,"sim.gem5.org"); + strcpy(name->release, process->release.c_str()); + strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003"); + strcpy(name->machine, "riscv32"); + + return 0; +} + +SyscallDescTable EmuLinux::syscallDescs64 = { + { 0, "io_setup" }, + { 1, "io_destroy" }, + { 2, "io_submit" }, + { 3, "io_cancel" }, + { 4, "io_getevents" }, + { 5, "setxattr" }, + { 6, "lsetxattr" }, + { 7, "fsetxattr" }, + { 8, "getxattr" }, + { 9, "lgetxattr" }, + { 10, "fgetxattr" }, + { 11, "listxattr" }, + { 12, "llistxattr" }, + { 13, "flistxattr" }, + { 14, "removexattr" }, + { 15, "lremovexattr" }, + { 16, "fremovexattr" }, + { 17, "getcwd", getcwdFunc }, + { 18, "lookup_dcookie" }, + { 19, "eventfd2" }, + { 20, "epoll_create1" }, + { 21, "epoll_ctl" }, + { 22, "epoll_pwait" }, + { 23, "dup", dupFunc }, + { 24, "dup3" }, + { 25, "fcntl", fcntl64Func }, + { 26, "inotify_init1" }, + { 27, "inotify_add_watch" }, + { 28, "inotify_rm_watch" }, + { 29, "ioctl", ioctlFunc }, + { 30, "ioprio_get" }, + { 31, "ioprio_set" }, + { 32, "flock" }, + { 33, "mknodat" }, + { 34, "mkdirat" }, + { 35, "unlinkat", unlinkatFunc }, + { 36, "symlinkat" }, + { 37, "linkat" }, + { 38, "renameat", renameatFunc }, + { 39, "umount2" }, + { 40, "mount" }, + { 41, "pivot_root" }, + { 42, "nfsservctl" }, + { 43, "statfs", statfsFunc }, + { 44, "fstatfs", fstatfsFunc }, + { 45, "truncate", truncateFunc }, + { 46, "ftruncate", ftruncate64Func }, + { 47, "fallocate", fallocateFunc }, + { 48, "faccessat", faccessatFunc }, + { 49, "chdir" }, + { 50, "fchdir" }, + { 51, "chroot" }, + { 52, "fchmod", fchmodFunc }, + { 53, "fchmodat" }, + { 54, "fchownat" }, + { 55, "fchown", fchownFunc }, + { 56, "openat", openatFunc }, + { 57, "close", closeFunc }, + { 58, "vhangup" }, + { 59, "pipe2" }, + { 60, "quotactl" }, + { 61, "getdents64" }, + { 62, "lseek", lseekFunc }, + { 63, "read", readFunc }, + { 64, "write", writeFunc }, + { 66, "writev", writevFunc }, + { 67, "pread64" }, + { 68, "pwrite64", pwrite64Func }, + { 69, "preadv" }, + { 70, "pwritev" }, + { 71, "sendfile" }, + { 72, "pselect6" }, + { 73, "ppoll" }, + { 74, "signalfd64" }, + { 75, "vmsplice" }, + { 76, "splice" }, + { 77, "tee" }, + { 78, "readlinkat", readlinkatFunc }, + { 79, "fstatat", fstatat64Func }, + { 80, "fstat", fstat64Func }, + { 81, "sync" }, + { 82, "fsync" }, + { 83, "fdatasync" }, + { 84, "sync_file_range2" }, + { 85, "timerfd_create" }, + { 86, "timerfd_settime" }, + { 87, "timerfd_gettime" }, + { 88, "utimensat" }, + { 89, "acct" }, + { 90, "capget" }, + { 91, "capset" }, + { 92, "personality" }, + { 93, "exit", exitFunc }, + { 94, "exit_group", exitGroupFunc }, + { 95, "waitid" }, + { 96, "set_tid_address", setTidAddressFunc }, + { 97, "unshare" }, + { 98, "futex", futexFunc }, + { 99, "set_robust_list", ignoreWarnOnceFunc }, + { 100, "get_robust_list", ignoreWarnOnceFunc }, + { 101, "nanosleep", ignoreWarnOnceFunc }, + { 102, "getitimer" }, + { 103, "setitimer" }, + { 104, "kexec_load" }, + { 105, "init_module" }, + { 106, "delete_module" }, + { 107, "timer_create" }, + { 108, "timer_gettime" }, + { 109, "timer_getoverrun" }, + { 110, "timer_settime" }, + { 111, "timer_delete" }, + { 112, "clock_settime" }, + { 113, "clock_gettime", clock_gettimeFunc }, + { 114, "clock_getres", clock_getresFunc }, + { 115, "clock_nanosleep" }, + { 116, "syslog" }, + { 117, "ptrace" }, + { 118, "sched_setparam" }, + { 119, "sched_setscheduler" }, + { 120, "sched_getscheduler" }, + { 121, "sched_getparam" }, + { 122, "sched_setaffinity" }, + { 123, "sched_getaffinity" }, + { 124, "sched_yield", ignoreWarnOnceFunc }, + { 125, "sched_get_priority_max" }, + { 126, "sched_get_priority_min" }, + { 127, "scheD_rr_get_interval" }, + { 128, "restart_syscall" }, + { 129, "kill" }, + { 130, "tkill" }, + { 131, "tgkill", tgkillFunc }, + { 132, "sigaltstack" }, + { 133, "rt_sigsuspend", ignoreWarnOnceFunc }, + { 134, "rt_sigaction", ignoreWarnOnceFunc }, + { 135, "rt_sigprocmask", ignoreWarnOnceFunc }, + { 136, "rt_sigpending", ignoreWarnOnceFunc }, + { 137, "rt_sigtimedwait", ignoreWarnOnceFunc }, + { 138, "rt_sigqueueinfo", ignoreWarnOnceFunc }, + { 139, "rt_sigreturn", ignoreWarnOnceFunc }, + { 140, "setpriority" }, + { 141, "getpriority" }, + { 142, "reboot" }, + { 143, "setregid" }, + { 144, "setgid" }, + { 145, "setreuid" }, + { 146, "setuid", ignoreFunc }, + { 147, "setresuid" }, + { 148, "getresuid" }, + { 149, "getresgid" }, + { 150, "getresgid" }, + { 151, "setfsuid" }, + { 152, "setfsgid" }, + { 153, "times", timesFunc }, + { 154, "setpgid", setpgidFunc }, + { 155, "getpgid" }, + { 156, "getsid" }, + { 157, "setsid" }, + { 158, "getgroups" }, + { 159, "setgroups" }, + { 160, "uname", unameFunc64 }, + { 161, "sethostname" }, + { 162, "setdomainname" }, + { 163, "getrlimit", getrlimitFunc }, + { 164, "setrlimit", ignoreFunc }, + { 165, "getrusage", getrusageFunc }, + { 166, "umask", umaskFunc }, + { 167, "prctl" }, + { 168, "getcpu" }, + { 169, "gettimeofday", gettimeofdayFunc }, + { 170, "settimeofday" }, + { 171, "adjtimex" }, + { 172, "getpid", getpidFunc }, + { 173, "getppid", getppidFunc }, + { 174, "getuid", getuidFunc }, + { 175, "geteuid", geteuidFunc }, + { 176, "getgid", getgidFunc }, + { 177, "getegid", getegidFunc }, + { 178, "gettid", gettidFunc }, + { 179, "sysinfo", sysinfoFunc }, + { 180, "mq_open" }, + { 181, "mq_unlink" }, + { 182, "mq_timedsend" }, + { 183, "mq_timedrecieve" }, + { 184, "mq_notify" }, + { 185, "mq_getsetattr" }, + { 186, "msgget" }, + { 187, "msgctl" }, + { 188, "msgrcv" }, + { 189, "msgsnd" }, + { 190, "semget" }, + { 191, "semctl" }, + { 192, "semtimedop" }, + { 193, "semop" }, + { 194, "shmget" }, + { 195, "shmctl" }, + { 196, "shmat" }, + { 197, "shmdt" }, + { 198, "socket" }, + { 199, "socketpair" }, + { 200, "bind" }, + { 201, "listen" }, + { 202, "accept" }, + { 203, "connect" }, + { 204, "getsockname" }, + { 205, "getpeername" }, + { 206, "sendo" }, + { 207, "recvfrom" }, + { 208, "setsockopt" }, + { 209, "getsockopt" }, + { 210, "shutdown" }, + { 211, "sendmsg" }, + { 212, "recvmsg" }, + { 213, "readahead" }, + { 214, "brk", brkFunc }, + { 215, "munmap", munmapFunc }, + { 216, "mremap", mremapFunc }, + { 217, "add_key" }, + { 218, "request_key" }, + { 219, "keyctl" }, + { 220, "clone", cloneBackwardsFunc }, + { 221, "execve", execveFunc }, + { 222, "mmap", mmapFunc }, + { 223, "fadvise64" }, + { 224, "swapon" }, + { 225, "swapoff" }, + { 226, "mprotect", ignoreFunc }, + { 227, "msync", ignoreFunc }, + { 228, "mlock", ignoreFunc }, + { 229, "munlock", ignoreFunc }, + { 230, "mlockall", ignoreFunc }, + { 231, "munlockall", ignoreFunc }, + { 232, "mincore", ignoreFunc }, + { 233, "madvise", ignoreFunc }, + { 234, "remap_file_pages" }, + { 235, "mbind", ignoreFunc }, + { 236, "get_mempolicy" }, + { 237, "set_mempolicy" }, + { 238, "migrate_pages" }, + { 239, "move_pages" }, + { 240, "tgsigqueueinfo" }, + { 241, "perf_event_open" }, + { 242, "accept4" }, + { 243, "recvmmsg" }, + { 260, "wait4" }, + { 261, "prlimit64", prlimitFunc }, + { 262, "fanotify_init" }, + { 263, "fanotify_mark" }, + { 264, "name_to_handle_at" }, + { 265, "open_by_handle_at" }, + { 266, "clock_adjtime" }, + { 267, "syncfs" }, + { 268, "setns" }, + { 269, "sendmmsg" }, + { 270, "process_vm_ready" }, + { 271, "process_vm_writev" }, + { 272, "kcmp" }, + { 273, "finit_module" }, + { 274, "sched_setattr" }, + { 275, "sched_getattr" }, + { 276, "renameat2" }, + { 277, "seccomp" }, + { 278, "getrandom" }, + { 279, "memfd_create" }, + { 280, "bpf" }, + { 281, "execveat" }, + { 282, "userfaultid" }, + { 283, "membarrier" }, + { 284, "mlock2" }, + { 285, "copy_file_range" }, + { 286, "preadv2" }, + { 287, "pwritev2" }, + { 1024, "open", openFunc }, + { 1025, "link" }, + { 1026, "unlink", unlinkFunc }, + { 1027, "mknod" }, + { 1028, "chmod", chmodFunc }, + { 1029, "chown", chownFunc }, + { 1030, "mkdir", mkdirFunc }, + { 1031, "rmdir" }, + { 1032, "lchown" }, + { 1033, "access", accessFunc }, + { 1034, "rename", renameFunc }, + { 1035, "readlink", readlinkFunc }, + { 1036, "symlink" }, + { 1037, "utimes", utimesFunc }, + { 1038, "stat", stat64Func }, + { 1039, "lstat", lstat64Func }, + { 1040, "pipe", pipeFunc }, + { 1041, "dup2", dup2Func }, + { 1042, "epoll_create" }, + { 1043, "inotifiy_init" }, + { 1044, "eventfd" }, + { 1045, "signalfd" }, + { 1046, "sendfile" }, + { 1047, "ftruncate", ftruncate64Func }, + { 1048, "truncate", truncate64Func }, + { 1049, "stat", stat64Func }, + { 1050, "lstat", lstat64Func }, + { 1051, "fstat", fstat64Func }, + { 1052, "fcntl", fcntl64Func }, + { 1053, "fadvise64" }, + { 1054, "newfstatat" }, + { 1055, "fstatfs", fstatfsFunc }, + { 1056, "statfs", statfsFunc }, + { 1057, "lseek", lseekFunc }, + { 1058, "mmap", mmapFunc }, + { 1059, "alarm" }, + { 1060, "getpgrp" }, + { 1061, "pause" }, + { 1062, "time", timeFunc }, + { 1063, "utime" }, + { 1064, "creat" }, + { 1065, "getdents" }, + { 1066, "futimesat" }, + { 1067, "select" }, + { 1068, "poll" }, + { 1069, "epoll_wait" }, + { 1070, "ustat" }, + { 1071, "vfork" }, + { 1072, "oldwait4" }, + { 1073, "recv" }, + { 1074, "send" }, + { 1075, "bdflush" }, + { 1076, "umount" }, + { 1077, "uselib" }, + { 1078, "sysctl" }, + { 1079, "fork" }, + { 2011, "getmainvars" } +}; + +SyscallDescTable EmuLinux::syscallDescs32 = { + { 0, "io_setup" }, + { 1, "io_destroy" }, + { 2, "io_submit" }, + { 3, "io_cancel" }, + { 4, "io_getevents" }, + { 5, "setxattr" }, + { 6, "lsetxattr" }, + { 7, "fsetxattr" }, + { 8, "getxattr" }, + { 9, "lgetxattr" }, + { 10, "fgetxattr" }, + { 11, "listxattr" }, + { 12, "llistxattr" }, + { 13, "flistxattr" }, + { 14, "removexattr" }, + { 15, "lremovexattr" }, + { 16, "fremovexattr" }, + { 17, "getcwd", getcwdFunc }, + { 18, "lookup_dcookie" }, + { 19, "eventfd2" }, + { 20, "epoll_create1" }, + { 21, "epoll_ctl" }, + { 22, "epoll_pwait" }, + { 23, "dup", dupFunc }, + { 24, "dup3" }, + { 25, "fcntl", fcntlFunc }, + { 26, "inotify_init1" }, + { 27, "inotify_add_watch" }, + { 28, "inotify_rm_watch" }, + { 29, "ioctl", ioctlFunc }, + { 30, "ioprio_get" }, + { 31, "ioprio_set" }, + { 32, "flock" }, + { 33, "mknodat" }, + { 34, "mkdirat" }, + { 35, "unlinkat", unlinkatFunc }, + { 36, "symlinkat" }, + { 37, "linkat" }, + { 38, "renameat", renameatFunc }, + { 39, "umount2" }, + { 40, "mount" }, + { 41, "pivot_root" }, + { 42, "nfsservctl" }, + { 43, "statfs", statfsFunc }, + { 44, "fstatfs", fstatfsFunc }, + { 45, "truncate", truncateFunc }, + { 46, "ftruncate", ftruncateFunc }, + { 47, "fallocate", fallocateFunc }, + { 48, "faccessat", faccessatFunc }, + { 49, "chdir" }, + { 50, "fchdir" }, + { 51, "chroot" }, + { 52, "fchmod", fchmodFunc }, + { 53, "fchmodat" }, + { 54, "fchownat" }, + { 55, "fchown", fchownFunc }, + { 56, "openat", openatFunc }, + { 57, "close", closeFunc }, + { 58, "vhangup" }, + { 59, "pipe2" }, + { 60, "quotactl" }, + { 61, "getdents64" }, + { 62, "lseek", lseekFunc }, + { 63, "read", readFunc }, + { 64, "write", writeFunc }, + { 66, "writev", writevFunc }, + { 67, "pread64" }, + { 68, "pwrite64", pwrite64Func }, + { 69, "preadv" }, + { 70, "pwritev" }, + { 71, "sendfile" }, + { 72, "pselect6" }, + { 73, "ppoll" }, + { 74, "signalfd64" }, + { 75, "vmsplice" }, + { 76, "splice" }, + { 77, "tee" }, + { 78, "readlinkat", readlinkatFunc }, + { 79, "fstatat" }, + { 80, "fstat", fstatFunc }, + { 81, "sync" }, + { 82, "fsync" }, + { 83, "fdatasync" }, + { 84, "sync_file_range2" }, + { 85, "timerfd_create" }, + { 86, "timerfd_settime" }, + { 87, "timerfd_gettime" }, + { 88, "utimensat" }, + { 89, "acct" }, + { 90, "capget" }, + { 91, "capset" }, + { 92, "personality" }, + { 93, "exit", exitFunc }, + { 94, "exit_group", exitGroupFunc }, + { 95, "waitid" }, + { 96, "set_tid_address", setTidAddressFunc }, + { 97, "unshare" }, + { 98, "futex", futexFunc }, + { 99, "set_robust_list", ignoreWarnOnceFunc }, + { 100, "get_robust_list", ignoreWarnOnceFunc }, + { 101, "nanosleep" }, + { 102, "getitimer" }, + { 103, "setitimer" }, + { 104, "kexec_load" }, + { 105, "init_module" }, + { 106, "delete_module" }, + { 107, "timer_create" }, + { 108, "timer_gettime" }, + { 109, "timer_getoverrun" }, + { 110, "timer_settime" }, + { 111, "timer_delete" }, + { 112, "clock_settime" }, + { 113, "clock_gettime", clock_gettimeFunc }, + { 114, "clock_getres", clock_getresFunc }, + { 115, "clock_nanosleep" }, + { 116, "syslog" }, + { 117, "ptrace" }, + { 118, "sched_setparam" }, + { 119, "sched_setscheduler" }, + { 120, "sched_getscheduler" }, + { 121, "sched_getparam" }, + { 122, "sched_setaffinity" }, + { 123, "sched_getaffinity" }, + { 124, "sched_yield", ignoreWarnOnceFunc }, + { 125, "sched_get_priority_max" }, + { 126, "sched_get_priority_min" }, + { 127, "scheD_rr_get_interval" }, + { 128, "restart_syscall" }, + { 129, "kill" }, + { 130, "tkill" }, + { 131, "tgkill", tgkillFunc }, + { 132, "sigaltstack" }, + { 133, "rt_sigsuspend", ignoreWarnOnceFunc }, + { 134, "rt_sigaction", ignoreWarnOnceFunc }, + { 135, "rt_sigprocmask", ignoreWarnOnceFunc }, + { 136, "rt_sigpending", ignoreWarnOnceFunc }, + { 137, "rt_sigtimedwait", ignoreWarnOnceFunc }, + { 138, "rt_sigqueueinfo", ignoreWarnOnceFunc }, + { 139, "rt_sigreturn", ignoreWarnOnceFunc }, + { 140, "setpriority" }, + { 141, "getpriority" }, + { 142, "reboot" }, + { 143, "setregid" }, + { 144, "setgid" }, + { 145, "setreuid" }, + { 146, "setuid", ignoreFunc }, + { 147, "setresuid" }, + { 148, "getresuid" }, + { 149, "getresgid" }, + { 150, "getresgid" }, + { 151, "setfsuid" }, + { 152, "setfsgid" }, + { 153, "times", timesFunc }, + { 154, "setpgid", setpgidFunc }, + { 155, "getpgid" }, + { 156, "getsid" }, + { 157, "setsid" }, + { 158, "getgroups" }, + { 159, "setgroups" }, + { 160, "uname", unameFunc32 }, + { 161, "sethostname" }, + { 162, "setdomainname" }, + { 163, "getrlimit", getrlimitFunc }, + { 164, "setrlimit", ignoreFunc }, + { 165, "getrusage", getrusageFunc }, + { 166, "umask", umaskFunc }, + { 167, "prctl" }, + { 168, "getcpu" }, + { 169, "gettimeofday", gettimeofdayFunc }, + { 170, "settimeofday" }, + { 171, "adjtimex" }, + { 172, "getpid", getpidFunc }, + { 173, "getppid", getppidFunc }, + { 174, "getuid", getuidFunc }, + { 175, "geteuid", geteuidFunc }, + { 176, "getgid", getgidFunc }, + { 177, "getegid", getegidFunc }, + { 178, "gettid", gettidFunc }, + { 179, "sysinfo", sysinfoFunc }, + { 180, "mq_open" }, + { 181, "mq_unlink" }, + { 182, "mq_timedsend" }, + { 183, "mq_timedrecieve" }, + { 184, "mq_notify" }, + { 185, "mq_getsetattr" }, + { 186, "msgget" }, + { 187, "msgctl" }, + { 188, "msgrcv" }, + { 189, "msgsnd" }, + { 190, "semget" }, + { 191, "semctl" }, + { 192, "semtimedop" }, + { 193, "semop" }, + { 194, "shmget" }, + { 195, "shmctl" }, + { 196, "shmat" }, + { 197, "shmdt" }, + { 198, "socket" }, + { 199, "socketpair" }, + { 200, "bind" }, + { 201, "listen" }, + { 202, "accept" }, + { 203, "connect" }, + { 204, "getsockname" }, + { 205, "getpeername" }, + { 206, "sendo" }, + { 207, "recvfrom" }, + { 208, "setsockopt" }, + { 209, "getsockopt" }, + { 210, "shutdown" }, + { 211, "sendmsg" }, + { 212, "recvmsg" }, + { 213, "readahead" }, + { 214, "brk", brkFunc }, + { 215, "munmap", munmapFunc }, + { 216, "mremap", mremapFunc }, + { 217, "add_key" }, + { 218, "request_key" }, + { 219, "keyctl" }, + { 220, "clone", cloneBackwardsFunc }, + { 221, "execve", execveFunc }, + { 222, "mmap", mmapFunc }, + { 223, "fadvise64" }, + { 224, "swapon" }, + { 225, "swapoff" }, + { 226, "mprotect", ignoreFunc }, + { 227, "msync", ignoreFunc }, + { 228, "mlock", ignoreFunc }, + { 229, "munlock", ignoreFunc }, + { 230, "mlockall", ignoreFunc }, + { 231, "munlockall", ignoreFunc }, + { 232, "mincore", ignoreFunc }, + { 233, "madvise", ignoreFunc }, + { 234, "remap_file_pages" }, + { 235, "mbind", ignoreFunc }, + { 236, "get_mempolicy" }, + { 237, "set_mempolicy" }, + { 238, "migrate_pages" }, + { 239, "move_pages" }, + { 240, "tgsigqueueinfo" }, + { 241, "perf_event_open" }, + { 242, "accept4" }, + { 243, "recvmmsg" }, + { 260, "wait4" }, + { 261, "prlimit64", prlimitFunc }, + { 262, "fanotify_init" }, + { 263, "fanotify_mark" }, + { 264, "name_to_handle_at" }, + { 265, "open_by_handle_at" }, + { 266, "clock_adjtime" }, + { 267, "syncfs" }, + { 268, "setns" }, + { 269, "sendmmsg" }, + { 270, "process_vm_ready" }, + { 271, "process_vm_writev" }, + { 272, "kcmp" }, + { 273, "finit_module" }, + { 274, "sched_setattr" }, + { 275, "sched_getattr" }, + { 276, "renameat2" }, + { 277, "seccomp" }, + { 278, "getrandom" }, + { 279, "memfd_create" }, + { 280, "bpf" }, + { 281, "execveat" }, + { 282, "userfaultid" }, + { 283, "membarrier" }, + { 284, "mlock2" }, + { 285, "copy_file_range" }, + { 286, "preadv2" }, + { 287, "pwritev2" }, + { 1024, "open", openFunc }, + { 1025, "link" }, + { 1026, "unlink", unlinkFunc }, + { 1027, "mknod" }, + { 1028, "chmod", chmodFunc }, + { 1029, "chown", chownFunc }, + { 1030, "mkdir", mkdirFunc }, + { 1031, "rmdir" }, + { 1032, "lchown" }, + { 1033, "access", accessFunc }, + { 1034, "rename", renameFunc }, + { 1035, "readlink", readlinkFunc }, + { 1036, "symlink" }, + { 1037, "utimes", utimesFunc }, + { 1038, "stat", statFunc }, + { 1039, "lstat", lstatFunc }, + { 1040, "pipe", pipeFunc }, + { 1041, "dup2", dup2Func }, + { 1042, "epoll_create" }, + { 1043, "inotifiy_init" }, + { 1044, "eventfd" }, + { 1045, "signalfd" }, + { 1046, "sendfile" }, + { 1047, "ftruncate", ftruncateFunc }, + { 1048, "truncate", truncateFunc }, + { 1049, "stat", statFunc }, + { 1050, "lstat", lstatFunc }, + { 1051, "fstat", fstatFunc }, + { 1052, "fcntl", fcntlFunc }, + { 1053, "fadvise64" }, + { 1054, "newfstatat" }, + { 1055, "fstatfs", fstatfsFunc }, + { 1056, "statfs", statfsFunc }, + { 1057, "lseek", lseekFunc }, + { 1058, "mmap", mmapFunc }, + { 1059, "alarm" }, + { 1060, "getpgrp" }, + { 1061, "pause" }, + { 1062, "time", timeFunc }, + { 1063, "utime" }, + { 1064, "creat" }, + { 1065, "getdents" }, + { 1066, "futimesat" }, + { 1067, "select" }, + { 1068, "poll" }, + { 1069, "epoll_wait" }, + { 1070, "ustat" }, + { 1071, "vfork" }, + { 1072, "oldwait4" }, + { 1073, "recv" }, + { 1074, "send" }, + { 1075, "bdflush" }, + { 1076, "umount" }, + { 1077, "uselib" }, + { 1078, "sysctl" }, + { 1079, "fork" }, + { 2011, "getmainvars" } +}; + +} // namespace RiscvISA + +RiscvISA::EmuLinux * +RiscvEmuLinuxParams::create() const +{ + return new RiscvISA::EmuLinux(*this); +} diff --git a/src/arch/riscv/linux/se_workload.hh b/src/arch/riscv/linux/se_workload.hh new file mode 100644 index 000000000..881ba3346 --- /dev/null +++ b/src/arch/riscv/linux/se_workload.hh @@ -0,0 +1,65 @@ +/* + * Copyright 2004 The Regents of The University of Michigan + * Copyright 2016 The University of Virginia + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ARCH_RISCV_LINUX_SE_WORKLOAD_HH__ +#define __ARCH_RISCV_LINUX_SE_WORKLOAD_HH__ + +#include "arch/riscv/linux/linux.hh" +#include "arch/riscv/se_workload.hh" +#include "params/RiscvEmuLinux.hh" +#include "sim/syscall_desc.hh" + +namespace RiscvISA +{ + +class EmuLinux : public SEWorkload +{ + public: + using Params = RiscvEmuLinuxParams; + + protected: + const Params &_params; + + /// 64 bit syscall descriptors, indexed by call number. + static SyscallDescTable syscallDescs64; + + /// 32 bit syscall descriptors, indexed by call number. + static SyscallDescTable syscallDescs32; + + public: + const Params ¶ms() const { return _params; } + + EmuLinux(const Params &p) : SEWorkload(p), _params(p) {} + + void syscall(ThreadContext *tc) override; +}; + +} // namespace RiscvISA + +#endif // __ARCH_RISCV_LINUX_SE_WORKLOAD_HH__ diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index 3dd157a1c..10c1378a5 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -246,7 +246,3 @@ RiscvProcess::argsInit(int pageSize) memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); } - -const std::vector RiscvProcess::SyscallABI::ArgumentRegs = { - 10, 11, 12, 13, 14, 15, 16 -}; diff --git a/src/arch/riscv/process.hh b/src/arch/riscv/process.hh index 03f106e66..105d1eb7f 100644 --- a/src/arch/riscv/process.hh +++ b/src/arch/riscv/process.hh @@ -53,49 +53,23 @@ class RiscvProcess : public Process public: virtual bool mmapGrowsDown() const override { return false; } - - //FIXME RISCV needs to handle 64 bit arguments in its 32 bit ISA. - struct SyscallABI : public GenericSyscallABI64 - { - static const std::vector ArgumentRegs; - }; -}; - -namespace GuestABI -{ - -template <> -struct Result -{ - static void - store(ThreadContext *tc, const SyscallReturn &ret) - { - if (ret.suppressed() || ret.needsRetry()) - return; - - if (ret.successful()) { - // no error - tc->setIntReg(RiscvISA::ReturnValueReg, ret.returnValue()); - } else { - // got an error, return details - tc->setIntReg(RiscvISA::ReturnValueReg, ret.encodedValue()); - } - } -}; - }; class RiscvProcess64 : public RiscvProcess { - protected: + public: RiscvProcess64(const ProcessParams ¶ms, ::Loader::ObjectFile *objFile); + + protected: void initState() override; }; class RiscvProcess32 : public RiscvProcess { - protected: + public: RiscvProcess32(const ProcessParams ¶ms, ::Loader::ObjectFile *objFile); + + protected: void initState() override; }; diff --git a/src/arch/riscv/se_workload.cc b/src/arch/riscv/se_workload.cc new file mode 100644 index 000000000..ce4679c69 --- /dev/null +++ b/src/arch/riscv/se_workload.cc @@ -0,0 +1,37 @@ +/* + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "arch/riscv/se_workload.hh" + +namespace RiscvISA +{ + +const std::vector SEWorkload::SyscallABI::ArgumentRegs = { + 10, 11, 12, 13, 14, 15, 16 +}; + +} // namespace RiscvISA diff --git a/src/arch/riscv/se_workload.hh b/src/arch/riscv/se_workload.hh new file mode 100644 index 000000000..e0be5a14a --- /dev/null +++ b/src/arch/riscv/se_workload.hh @@ -0,0 +1,88 @@ +/* + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ARCH_RISCV_SE_WORKLOAD_HH__ +#define __ARCH_RISCV_SE_WORKLOAD_HH__ + +#include "arch/riscv/registers.hh" +#include "params/RiscvSEWorkload.hh" +#include "sim/se_workload.hh" +#include "sim/syscall_abi.hh" +#include "sim/syscall_desc.hh" + +namespace RiscvISA +{ + +class SEWorkload : public ::SEWorkload +{ + public: + using Params = RiscvSEWorkloadParams; + + protected: + const Params &_params; + + public: + const Params ¶ms() const { return _params; } + + SEWorkload(const Params &p) : ::SEWorkload(p), _params(p) {} + + ::Loader::Arch getArch() const override { return ::Loader::Riscv64; } + + //FIXME RISCV needs to handle 64 bit arguments in its 32 bit ISA. + struct SyscallABI : public GenericSyscallABI64 + { + static const std::vector ArgumentRegs; + }; +}; + +} // namespace RiscvISA + +namespace GuestABI +{ + +template <> +struct Result +{ + static void + store(ThreadContext *tc, const SyscallReturn &ret) + { + if (ret.suppressed() || ret.needsRetry()) + return; + + if (ret.successful()) { + // no error + tc->setIntReg(RiscvISA::ReturnValueReg, ret.returnValue()); + } else { + // got an error, return details + tc->setIntReg(RiscvISA::ReturnValueReg, ret.encodedValue()); + } + } +}; + +} // namespace GuestABI + +#endif // __ARCH_RISCV_SE_WORKLOAD_HH__