gem5 v24.0.0.0
Loading...
Searching...
No Matches
guest_abi.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_HH__
29#define __SIM_GUEST_ABI_HH__
30
31#include <functional>
32
37
38namespace gem5
39{
40
41class ThreadContext;
42
43// These functions wrap a simulator level function with the given signature.
44// The wrapper takes one argument, a thread context to extract arguments from
45// and write a result (if any) back to. For convenience, the wrapper also
46// returns the result of the wrapped function.
47
48template <typename ABI, bool store_ret, typename Ret, typename ...Args>
49Ret
51 std::function<Ret(ThreadContext *, Args...)> target)
52{
53 // Default construct a State to track consumed resources. Built in
54 // types will be zero initialized.
56 guest_abi::prepareForFunction<ABI, Ret, Args...>(tc, state);
57 return guest_abi::callFrom<ABI, Ret, store_ret, Args...>(tc, state,
58 target);
59}
60
61template <typename ABI, typename Ret, typename ...Args>
62Ret
64 std::function<Ret(ThreadContext *, Args...)> target)
65{
66 return invokeSimcall<ABI, true>(tc, target);
67}
68
69template <typename ABI, bool store_ret, typename Ret, typename ...Args>
70Ret
71invokeSimcall(ThreadContext *tc, Ret (*target)(ThreadContext *, Args...))
72{
74 tc, std::function<Ret(ThreadContext *, Args...)>(target));
75}
76
77template <typename ABI, typename Ret, typename ...Args>
78Ret
79invokeSimcall(ThreadContext *tc, Ret (*target)(ThreadContext *, Args...))
80{
81 return invokeSimcall<ABI, true>(tc, target);
82}
83
84template <typename ABI, typename ...Args>
85void
87 std::function<void(ThreadContext *, Args...)> target)
88{
89 // Default construct a State to track consumed resources. Built in
90 // types will be zero initialized.
92 guest_abi::prepareForArguments<ABI, Args...>(tc, state);
93 guest_abi::callFrom<ABI, void, false, Args...>(tc, state, target);
94}
95
96template <typename ABI, typename ...Args>
97void
98invokeSimcall(ThreadContext *tc, void (*target)(ThreadContext *, Args...))
99{
101 tc, std::function<void(ThreadContext *, Args...)>(target));
102}
103
104
105// These functions also wrap a simulator level function. Instead of running the
106// function, they return a string which shows what arguments the function would
107// be invoked with if it were called from the given context.
108
109template <typename ABI, typename Ret, typename ...Args>
110std::string
112 std::function<Ret(ThreadContext *, Args...)> target=
113 std::function<Ret(ThreadContext *, Args...)>())
114{
116 std::ostringstream ss;
117
118 guest_abi::prepareForFunction<ABI, Ret, Args...>(tc, state);
119 ss << name;
120 guest_abi::dumpArgsFrom<ABI, Ret, Args...>(ss, tc, state);
121 return ss.str();
122}
123
124template <typename ABI, typename Ret, typename ...Args>
125std::string
127 Ret (*target)(ThreadContext *, Args...))
128{
129 return dumpSimcall<ABI>(
130 name, tc, std::function<Ret(ThreadContext *, Args...)>(target));
131}
132
133} // namespace gem5
134
135#endif // __SIM_GUEST_ABI_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< 21 > ss
Definition misc_types.hh:60
static ABI::State initializeState(const ThreadContext *tc)
Definition layout.hh:71
static void prepareForFunction(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:123
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
static void prepareForArguments(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:115
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::string dumpSimcall(std::string name, ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target=std::function< Ret(ThreadContext *, Args...)>())
Definition guest_abi.hh:111
Ret invokeSimcall(ThreadContext *tc, std::function< Ret(ThreadContext *, Args...)> target)
Definition guest_abi.hh:50
const std::string & name()
Definition trace.cc:48

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