From 10c46f0996b50415a160cfa7079166bdf99d327e Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 22 Dec 2019 03:59:46 -0500 Subject: [PATCH] sim: Optionally pass "position" to GuestABI::Result::store. This will let it get at information about the signature as a whole. Also, put result storing and argument getting behind functions to hide some of the templating involved in those mechanisms. Change-Id: Ib9f26ff69495f8891435f68d3d2f9dfa761a0274 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24105 Tested-by: kokoro Reviewed-by: Bobby R. Bruce Maintainer: Gabe Black --- src/sim/guest_abi/definition.hh | 5 +++- src/sim/guest_abi/dispatch.hh | 9 +++--- src/sim/guest_abi/layout.hh | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/sim/guest_abi/definition.hh b/src/sim/guest_abi/definition.hh index ccebcc510..c61d1aef9 100644 --- a/src/sim/guest_abi/definition.hh +++ b/src/sim/guest_abi/definition.hh @@ -59,7 +59,8 @@ struct Result { private: /* - * Store result "ret" into the state accessible through tc. + * Store result "ret" into the state accessible through tc. Optionally + * accept "position" in case it holds some signature wide information. * * Note that the declaration below is only to document the expected * signature and is private so it won't be used by accident. @@ -67,6 +68,8 @@ struct Result * of this method which actually does something and is public. */ static void store(ThreadContext *tc, const Ret &ret); + static void store(ThreadContext *tc, const Ret &ret, + typename ABI::Position &position); /* * Adjust the position of arguments based on the return type, if necessary. diff --git a/src/sim/guest_abi/dispatch.hh b/src/sim/guest_abi/dispatch.hh index c817f632c..eb703a5fd 100644 --- a/src/sim/guest_abi/dispatch.hh +++ b/src/sim/guest_abi/dispatch.hh @@ -33,6 +33,7 @@ #include #include "sim/guest_abi/definition.hh" +#include "sim/guest_abi/layout.hh" class ThreadContext; @@ -57,7 +58,7 @@ callFrom(ThreadContext *tc, typename ABI::Position &position, std::function target) { Ret ret = target(tc); - Result::store(tc, ret); + storeResult(tc, ret, position); return ret; } @@ -78,7 +79,7 @@ callFrom(ThreadContext *tc, typename ABI::Position &position, std::function target) { // Extract the next argument from the thread context. - NextArg next = Argument::get(tc, position); + NextArg next = getArgument(tc, position); // Build a partial function which adds the next argument to the call. std::function partial = @@ -98,7 +99,7 @@ callFrom(ThreadContext *tc, typename ABI::Position &position, std::function target) { // Extract the next argument from the thread context. - NextArg next = Argument::get(tc, position); + NextArg next = getArgument(tc, position); // Build a partial function which adds the next argument to the call. std::function partial = @@ -139,7 +140,7 @@ dumpArgsFrom(int count, std::ostream &os, ThreadContext *tc, os << (count ? ", " : "("); // Extract the next argument from the thread context. - NextArg next = Argument::get(tc, position); + NextArg next = getArgument(tc, position); // Add this argument to the list. os << next; diff --git a/src/sim/guest_abi/layout.hh b/src/sim/guest_abi/layout.hh index e7941f807..562f3ee33 100644 --- a/src/sim/guest_abi/layout.hh +++ b/src/sim/guest_abi/layout.hh @@ -130,6 +130,59 @@ allocateSignature(ThreadContext *tc, typename ABI::Position &position) allocateArguments(tc, position); } +/* + * This struct template provides a way to call the Result store method and + * optionally pass it the position. + */ + +template +struct ResultStorer +{ + static void + store(ThreadContext *tc, const Ret &ret, typename ABI::Position &position) + { + Result::store(tc, ret); + } +}; + +template +std::true_type foo(void (*)(ThreadContext *, const Ret &ret, State &state)); + +template +std::false_type foo(void (*)(ThreadContext *, const Ret &ret)); + +template +struct ResultStorer::store)>::value>::type> +{ + static void + store(ThreadContext *tc, const Ret &ret, typename ABI::Position &position) + { + Result::store(tc, ret, position); + } +}; + +/* + * Function templates to wrap the Result::store and Argument::get methods. + */ + +template +static void +storeResult(ThreadContext *tc, const Ret &ret, + typename ABI::Position &position) +{ + ResultStorer::store(tc, ret, position); +} + +template +static Arg +getArgument(ThreadContext *tc, typename ABI::Position &position) +{ + return Argument::get(tc, position); +} + } // namespace GuestABI #endif // __SIM_GUEST_ABI_LAYOUT_HH__ -- 2.30.2