gem5 v24.0.0.0
Loading...
Searching...
No Matches
dispatch.hh
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef __SIM_GUEST_ABI_DISPATCH_HH__
29#define __SIM_GUEST_ABI_DISPATCH_HH__
30
31#include <functional>
32#include <sstream>
33#include <tuple>
34#include <type_traits>
35#include <utility>
36
37#include "base/compiler.hh"
40
41namespace gem5
42{
43
44class ThreadContext;
45
46namespace guest_abi
47{
48
49/*
50 * These functions will likely be common among all ABIs and implement the
51 * mechanism of gathering arguments, calling the target function, and then
52 * storing the result. They might need to be overridden if, for instance,
53 * the location of arguments need to be determined in a different order.
54 * For example, there might be an ABI which gathers arguments starting
55 * from the last in the list instead of the first. This is unlikely but
56 * still possible to support by redefining these functions..
57 */
58
59template <typename ABI, typename Ret, bool store_ret, typename Target,
60 typename State, typename Args, std::size_t... I>
61static inline typename std::enable_if_t<!store_ret, Ret>
62callFromHelper(Target &target, ThreadContext *tc, State &state, Args &&args,
63 std::index_sequence<I...>)
64{
65 return target(tc, std::get<I>(args)...);
66}
67
68template <typename ABI, typename Ret, bool store_ret, typename Target,
69 typename State, typename Args, std::size_t... I>
70static inline typename std::enable_if_t<store_ret, Ret>
71callFromHelper(Target &target, ThreadContext *tc, State &state, Args &&args,
72 std::index_sequence<I...>)
73{
74 Ret ret = target(tc, std::get<I>(args)...);
76 return ret;
77}
78
79template <typename ABI, typename Ret, bool store_ret, typename ...Args>
80static inline Ret
81callFrom(ThreadContext *tc, typename ABI::State &state,
82 std::function<Ret(ThreadContext *, Args...)> target)
83{
84 // Extract all the arguments from the thread context. Braced initializers
85 // are evaluated from left to right.
86 auto args = std::tuple<Args...>{getArgument<ABI, Args>(tc, state)...};
87
88 // Call the wrapper which will call target.
90 target, tc, state, std::move(args),
91 std::make_index_sequence<sizeof...(Args)>{});
92}
93
94
95/*
96 * This function is like the ones above, except it prints the arguments
97 * a target function would be called with instead of actually calling it.
98 */
99
100template <typename ABI, typename Ret, typename ...Args>
101static void
102dumpArgsFrom(std::ostream &os, [[maybe_unused]] ThreadContext *tc,
103 typename ABI::State &state)
104{
105 int count = 0;
106 // Extract all the arguments from the thread context and print them,
107 // prefixed with either a ( or a , as appropriate.
108 GEM5_FOR_EACH_IN_PACK(os << (count++ ? ", " : "("),
110 os << ")";
111}
112
113} // namespace guest_abi
114} // namespace gem5
115
116#endif // __SIM_GUEST_ABI_DISPATCH_HH__
ThreadContext is the external interface to all thread state for anything outside of the CPU.
atomic_var_t state
Definition helpers.cc:211
Bitfield< 17 > os
Definition misc.hh:838
static void storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition layout.hh:163
static std::enable_if_t<!store_ret, Ret > callFromHelper(Target &target, ThreadContext *tc, State &state, Args &&args, std::index_sequence< I... >)
Definition dispatch.hh:62
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:170
static void dumpArgsFrom(std::ostream &os, ThreadContext *tc, typename ABI::State &state)
Definition dispatch.hh:102
static Ret callFrom(ThreadContext *tc, typename ABI::State &state, std::function< Ret(ThreadContext *, Args...)> target)
Definition dispatch.hh:81
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0