From 0b5ee2e8642f69a6f12ab58651967e6dc3e28685 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 8 Dec 2019 01:36:05 -0800 Subject: [PATCH] sim: Rework the SyscallDesc to use the dumpSimcall mechanism. This greatly simplifies the doSyscall method, removes a use of getSyscallArg, and will only print arguments the target syscall is going to use. Change-Id: Id8c9c995a2506468fd99fd865f2eb31c40db8b55 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23461 Tested-by: kokoro Reviewed-by: Bobby R. Bruce Maintainer: Gabe Black --- src/sim/syscall_desc.cc | 50 ++++++++--------------------------------- src/sim/syscall_desc.hh | 48 +++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 58 deletions(-) diff --git a/src/sim/syscall_desc.cc b/src/sim/syscall_desc.cc index d0c96b98e..6c7fae5e6 100644 --- a/src/sim/syscall_desc.cc +++ b/src/sim/syscall_desc.cc @@ -29,54 +29,22 @@ #include "sim/syscall_desc.hh" -#include - -#include "base/trace.hh" #include "base/types.hh" -#include "config/the_isa.hh" -#include "cpu/base.hh" -#include "cpu/thread_context.hh" -#include "sim/faults.hh" -#include "sim/process.hh" #include "sim/syscall_debug_macros.hh" +class ThreadContext; + void SyscallDesc::doSyscall(int callnum, ThreadContext *tc, Fault *fault) { - RegVal arg[6] M5_VAR_USED; - auto process = tc->getProcessPtr(); - - /** - * Step through the first six parameters for the system call and - * retrieve their values. Note that index is incremented as a - * side-effect of the getSyscallArg method. - */ - int index = 0; - for (int i = 0; i < 6; i++) - arg[i] = process->getSyscallArg(tc, index); + DPRINTF_SYSCALL(Base, "Calling %s...\n", dumper(name(), tc)); - /** - * Linux supports up to six system call arguments through registers - * so we want to print all six. Check to the relevant man page to - * verify how many are actually used by a given system call. - */ - DPRINTF_SYSCALL(Base, "%s called w/arguments %d, %d, %d, %d, %d, %d\n", - _name, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); - - /** Invoke the system call */ SyscallReturn retval = executor(this, callnum, tc); - /** - * If the system call needs to be restarted, most likely due to - * blocking behavior, warn that the system call will retry; - * alternatively, print the return value. - */ - if (retval.needsRetry()) { - *fault = std::make_shared(); - DPRINTF_SYSCALL(Base, "%s needs retry\n", _name); - } else - DPRINTF_SYSCALL(Base, "%s returns %d\n", _name, retval.encodedValue()); - - if (!retval.suppressed() && !retval.needsRetry()) - process->setSyscallReturn(tc, retval); + if (retval.needsRetry()) + DPRINTF_SYSCALL(Base, "Needs retry.\n", name()); + else if (retval.suppressed()) + DPRINTF_SYSCALL(Base, "No return value.\n", name()); + else + DPRINTF_SYSCALL(Base, "Returned %d.\n", retval.encodedValue()); } diff --git a/src/sim/syscall_desc.hh b/src/sim/syscall_desc.hh index a00b1f325..4f1aa1877 100644 --- a/src/sim/syscall_desc.hh +++ b/src/sim/syscall_desc.hh @@ -64,13 +64,6 @@ SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, */ class SyscallDesc { public: - using SyscallExecutor = - std::function; - - SyscallDesc(const char *name, SyscallExecutor sys_exec=unimplementedFunc) - : _name(name), executor(sys_exec) - {} - /** * Interface for invoking the system call funcion pointer. Note that * this acts as a gateway for all system calls and serves a good point @@ -83,12 +76,22 @@ class SyscallDesc { std::string name() { return _name; } + protected: + using Executor = + std::function; + using Dumper = std::function; + + SyscallDesc(const char *name, Executor exec, Dumper dump) : + _name(name), executor(exec), dumper(dump) + {} + private: /** System call name (e.g., open, mmap, clone, socket, etc.) */ std::string _name; /** Mechanism for ISAs to connect to the emul function definitions */ - SyscallExecutor executor; + Executor executor; + Dumper dumper; }; /* @@ -102,20 +105,20 @@ class SyscallDescABI : public SyscallDesc private: // Aliases to make the code below a little more concise. template - using SyscallABIExecutor = + using ABIExecutor = std::function; template - using SyscallABIExecutorPtr = + using ABIExecutorPtr = SyscallReturn (*)(SyscallDesc *, int, ThreadContext *, Args...); // Wrap an executor with guest arguments with a normal executor that gets // those additional arguments from the guest context. template - static inline SyscallExecutor - buildExecutor(SyscallABIExecutor target) + static inline Executor + buildExecutor(ABIExecutor target) { return [target](SyscallDesc *desc, int num, ThreadContext *tc) -> SyscallReturn { @@ -134,20 +137,31 @@ class SyscallDescABI : public SyscallDesc }; } + template + static inline Dumper + buildDumper() + { + return [](std::string name, ThreadContext *tc) -> std::string { + return dumpSimcall(name, tc); + }; + } public: // Constructors which plumb in buildExecutor. template - SyscallDescABI(const char *name, SyscallABIExecutor target) : - SyscallDesc(name, buildExecutor(target)) + SyscallDescABI(const char *name, ABIExecutor target) : + SyscallDesc(name, buildExecutor(target), + buildDumper()) {} template - SyscallDescABI(const char *name, SyscallABIExecutorPtr target) : - SyscallDescABI(name, SyscallABIExecutor(target)) + SyscallDescABI(const char *name, ABIExecutorPtr target) : + SyscallDescABI(name, ABIExecutor(target)) {} - using SyscallDesc::SyscallDesc; + SyscallDescABI(const char *name) : + SyscallDescABI(name, ABIExecutor<>(unimplementedFunc)) + {} }; #endif // __SIM_SYSCALL_DESC_HH__ -- 2.30.2