gem5 v24.0.0.0
Loading...
Searching...
No Matches
layout.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_LAYOUT_HH__
29#define __SIM_GUEST_ABI_LAYOUT_HH__
30
31#include <type_traits>
32
33#include "base/compiler.hh"
35
36namespace gem5
37{
38
39class ThreadContext;
40
41namespace guest_abi
42{
43
44/*
45 * State may need to be initialized based on the ThreadContext, for instance
46 * to find out where the stack pointer is initially.
47 */
48template <typename ABI, typename Enabled=void>
50{
51 static typename ABI::State
53 {
54 return typename ABI::State();
55 }
56};
57
58template <typename ABI>
59struct StateInitializer<ABI, typename std::enable_if_t<
60 std::is_constructible_v<typename ABI::State, const ThreadContext *>>>
61{
62 static typename ABI::State
64 {
65 return typename ABI::State(tc);
66 }
67};
68
69template <typename ABI>
70static typename ABI::State
75
76/*
77 * This struct template provides a default prepare() method in case the
78 * Result or Argument template doesn't provide one. This is the default in
79 * cases where the return or argument type doesn't affect where things are
80 * stored.
81 */
82template <typename ABI, template <class ...> class Role,
83 typename Type, typename Enabled=void>
85{
86 static void
87 prepare(ThreadContext *tc, typename ABI::State &state)
88 {}
89};
90
91/*
92 * If the return or argument type isn't void and does affect where things
93 * are stored, the ABI can implement a prepare() method for the various
94 * argument and/or return types, and this specialization will call into it.
95 */
96template <typename ABI, template <class ...> class Role, typename Type>
97struct Preparer<ABI, Role, Type, decltype((void)&Role<ABI, Type>::prepare)>
98{
99 static void
100 prepare(ThreadContext *tc, typename ABI::State &state)
101 {
102 Role<ABI, Type>::prepare(tc, state);
103 }
104};
105
106template <typename ABI, typename Ret, typename Enabled=void>
107static inline void
108prepareForResult(ThreadContext *tc, typename ABI::State &state)
109{
111}
112
113template <typename ABI, typename ...Args>
114static inline void
116 typename ABI::State &state)
117{
118 GEM5_FOR_EACH_IN_PACK(Preparer<ABI, Argument, Args>::prepare(tc, state));
119}
120
121template <typename ABI, typename Ret, typename ...Args>
122static inline void
123prepareForFunction(ThreadContext *tc, typename ABI::State &state)
124{
126 prepareForArguments<ABI, Args...>(tc, state);
127}
128
129/*
130 * This struct template provides a way to call the Result store method and
131 * optionally pass it the state.
132 */
133
134template <typename ABI, typename Ret, typename Enabled=void>
136{
137 static void
138 store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
139 {
141 }
142};
143
144template <typename ABI, typename Ret>
145struct ResultStorer<ABI, Ret, typename std::enable_if_t<
146 std::is_same_v<void (*)(ThreadContext *, const Ret &,
147 typename ABI::State &),
148 decltype(&Result<ABI, Ret>::store)>>>
149{
150 static void
151 store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
152 {
154 }
155};
156
157/*
158 * Function templates to wrap the Result::store and Argument::get methods.
159 */
160
161template <typename ABI, typename Ret>
162static void
163storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
164{
166}
167
168template <typename ABI, typename Arg>
169static Arg
170getArgument(ThreadContext *tc, typename ABI::State &state)
171{
172 return (Arg)Argument<ABI, Arg>::get(tc, state);
173}
174
175} // namespace guest_abi
176} // namespace gem5
177
178#endif // __SIM_GUEST_ABI_LAYOUT_HH__
ThreadContext is the external interface to all thread state for anything outside of the CPU.
atomic_var_t state
Definition helpers.cc:211
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 storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition layout.hh:163
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:170
static void prepareForResult(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:108
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
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:100
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition layout.hh:87
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition layout.hh:138
static ABI::State init(const ThreadContext *tc)
Definition layout.hh:52

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