gem5  v22.1.0.0
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 
36 namespace gem5
37 {
38 
39 class ThreadContext;
40 
41 GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi);
42 namespace guest_abi
43 {
44 
45 /*
46  * State may need to be initialized based on the ThreadContext, for instance
47  * to find out where the stack pointer is initially.
48  */
49 template <typename ABI, typename Enabled=void>
51 {
52  static typename ABI::State
53  init(const ThreadContext *tc)
54  {
55  return typename ABI::State();
56  }
57 };
58 
59 template <typename ABI>
60 struct StateInitializer<ABI, typename std::enable_if_t<
61  std::is_constructible_v<typename ABI::State, const ThreadContext *>>>
62 {
63  static typename ABI::State
64  init(const ThreadContext *tc)
65  {
66  return typename ABI::State(tc);
67  }
68 };
69 
70 template <typename ABI>
71 static typename ABI::State
73 {
74  return StateInitializer<ABI>::init(tc);
75 }
76 
77 /*
78  * This struct template provides a default prepare() method in case the
79  * Result or Argument template doesn't provide one. This is the default in
80  * cases where the return or argument type doesn't affect where things are
81  * stored.
82  */
83 template <typename ABI, template <class ...> class Role,
84  typename Type, typename Enabled=void>
85 struct Preparer
86 {
87  static void
88  prepare(ThreadContext *tc, typename ABI::State &state)
89  {}
90 };
91 
92 /*
93  * If the return or argument type isn't void and does affect where things
94  * are stored, the ABI can implement a prepare() method for the various
95  * argument and/or return types, and this specialization will call into it.
96  */
97 template <typename ABI, template <class ...> class Role, typename Type>
98 struct Preparer<ABI, Role, Type, decltype((void)&Role<ABI, Type>::prepare)>
99 {
100  static void
101  prepare(ThreadContext *tc, typename ABI::State &state)
102  {
103  Role<ABI, Type>::prepare(tc, state);
104  }
105 };
106 
107 template <typename ABI, typename Ret, typename Enabled=void>
108 static inline void
109 prepareForResult(ThreadContext *tc, typename ABI::State &state)
110 {
112 }
113 
114 template <typename ABI, typename ...Args>
115 static inline void
116 prepareForArguments([[maybe_unused]] ThreadContext *tc,
117  typename ABI::State &state)
118 {
119  GEM5_FOR_EACH_IN_PACK(Preparer<ABI, Argument, Args>::prepare(tc, state));
120 }
121 
122 template <typename ABI, typename Ret, typename ...Args>
123 static inline void
124 prepareForFunction(ThreadContext *tc, typename ABI::State &state)
125 {
126  prepareForResult<ABI, Ret>(tc, state);
127  prepareForArguments<ABI, Args...>(tc, state);
128 }
129 
130 /*
131  * This struct template provides a way to call the Result store method and
132  * optionally pass it the state.
133  */
134 
135 template <typename ABI, typename Ret, typename Enabled=void>
137 {
138  static void
139  store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
140  {
141  Result<ABI, Ret>::store(tc, ret);
142  }
143 };
144 
145 template <typename ABI, typename Ret>
146 struct ResultStorer<ABI, Ret, typename std::enable_if_t<
147  std::is_same_v<void (*)(ThreadContext *, const Ret &,
148  typename ABI::State &),
149  decltype(&Result<ABI, Ret>::store)>>>
150 {
151  static void
152  store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
153  {
154  Result<ABI, Ret>::store(tc, ret, state);
155  }
156 };
157 
158 /*
159  * Function templates to wrap the Result::store and Argument::get methods.
160  */
161 
162 template <typename ABI, typename Ret>
163 static void
164 storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
165 {
167 }
168 
169 template <typename ABI, typename Arg>
170 static Arg
171 getArgument(ThreadContext *tc, typename ABI::State &state)
172 {
173  return Argument<ABI, Arg>::get(tc, state);
174 }
175 
176 } // namespace guest_abi
177 } // namespace gem5
178 
179 #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:188
static ABI::State initializeState(const ThreadContext *tc)
Definition: layout.hh:72
static void prepareForFunction(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:124
static void prepareForArguments([[maybe_unused]] ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:116
static void storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:164
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:171
static void prepareForResult(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:109
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2826
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:101
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:88
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:139
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:53

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1