Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/23172 )

Change subject: sim: Add a wrapper/subclass for SyscallDesc which uses GuestABI.
......................................................................

sim: Add a wrapper/subclass for SyscallDesc which uses GuestABI.

This will let system call implementations take arguments naturally,
and centrally defined, potentially complex, and ISA/context specific
mechanisms will automatically gather the arguments and store any
result.

Jira Issue: https://gem5.atlassian.net/browse/GEM5-187

Change-Id: I68d265e0bab5de372ba975e4c7e9bb2d968c80af
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23172
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
---
M src/sim/syscall_desc.hh
1 file changed, 60 insertions(+), 0 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/syscall_desc.hh b/src/sim/syscall_desc.hh
index 9a28591..e5adf8b 100644
--- a/src/sim/syscall_desc.hh
+++ b/src/sim/syscall_desc.hh
@@ -50,6 +50,7 @@
 #include <string>

 #include "base/types.hh"
+#include "sim/guest_abi.hh"
 #include "sim/syscall_return.hh"

 class Process;
@@ -94,4 +95,63 @@
     SyscallExecutor executor;
 };

+/*
+ * This SyscallDesc subclass template adapts a given syscall implementation so + * that some arguments can come from the simulator (desc, num and tc) while the
+ * rest can come from the guest using the GuestABI mechanism.
+ */
+template <typename ABI>
+class SyscallDescABI : public SyscallDesc
+{
+  private:
+    // Aliases to make the code below a little more concise.
+    template <typename ...Args>
+    using SyscallABIExecutor =
+        std::function<SyscallReturn(SyscallDesc *, int,
+                                    ThreadContext *, Args...)>;
+
+    template <typename ...Args>
+    using SyscallABIExecutorPtr =
+        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 <typename ...Args>
+    static inline SyscallExecutor
+    buildExecutor(SyscallABIExecutor<Args...> target)
+    {
+        return [target](SyscallDesc *desc, int num,
+                        ThreadContext *tc) -> SyscallReturn {
+ // Create a partial function which will stick desc and num to the
+            // front of the parameter list.
+            auto partial = [target,desc,num](
+                    ThreadContext *tc, Args... args) -> SyscallReturn {
+                return target(desc, num, tc, args...);
+            };
+
+            // Use invokeSimcall to gather the other arguments based on the
+            // given ABI and pass them to the syscall implementation.
+            return invokeSimcall<ABI, SyscallReturn, Args...>(tc,
+                    std::function<SyscallReturn(ThreadContext *, Args...)>(
+                        partial));
+        };
+    }
+
+
+  public:
+    // Constructors which plumb in buildExecutor.
+    template <typename ...Args>
+    SyscallDescABI(const char *name, SyscallABIExecutor<Args...> target) :
+        SyscallDesc(name, buildExecutor<Args...>(target))
+    {}
+
+    template <typename ...Args>
+ SyscallDescABI(const char *name, SyscallABIExecutorPtr<Args...> target) :
+        SyscallDescABI(name, SyscallABIExecutor<Args...>(target))
+    {}
+
+    using SyscallDesc::SyscallDesc;
+};
+
 #endif // __SIM_SYSCALL_DESC_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23172
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I68d265e0bab5de372ba975e4c7e9bb2d968c80af
Gerrit-Change-Number: 23172
Gerrit-PatchSet: 5
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Brandon Potter <brandon.pot...@amd.com>
Gerrit-Reviewer: Brandon Potter <ambitiousc...@gmail.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to