gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 namespace 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  */
48 template <typename ABI, typename Enabled=void>
50 {
51  static typename ABI::State
52  init(const ThreadContext *tc)
53  {
54  return typename ABI::State();
55  }
56 };
57 
58 template <typename ABI>
59 struct StateInitializer<ABI, typename std::enable_if_t<
60  std::is_constructible_v<typename ABI::State, const ThreadContext *>>>
61 {
62  static typename ABI::State
63  init(const ThreadContext *tc)
64  {
65  return typename ABI::State(tc);
66  }
67 };
68 
69 template <typename ABI>
70 static typename ABI::State
72 {
73  return StateInitializer<ABI>::init(tc);
74 }
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  */
82 template <typename ABI, template <class ...> class Role,
83  typename Type, typename Enabled=void>
84 struct Preparer
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  */
96 template <typename ABI, template <class ...> class Role, typename Type>
97 struct 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 
106 template <typename ABI, typename Ret, typename Enabled=void>
107 static inline void
108 prepareForResult(ThreadContext *tc, typename ABI::State &state)
109 {
111 }
112 
113 template <typename ABI, typename ...Args>
114 static inline void
115 prepareForArguments([[maybe_unused]] ThreadContext *tc,
116  typename ABI::State &state)
117 {
118  GEM5_FOR_EACH_IN_PACK(Preparer<ABI, Argument, Args>::prepare(tc, state));
119 }
120 
121 template <typename ABI, typename Ret, typename ...Args>
122 static inline void
123 prepareForFunction(ThreadContext *tc, typename ABI::State &state)
124 {
125  prepareForResult<ABI, Ret>(tc, state);
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 
134 template <typename ABI, typename Ret, typename Enabled=void>
136 {
137  static void
138  store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
139  {
140  Result<ABI, Ret>::store(tc, ret);
141  }
142 };
143 
144 template <typename ABI, typename Ret>
145 struct 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  {
153  Result<ABI, Ret>::store(tc, ret, state);
154  }
155 };
156 
157 /*
158  * Function templates to wrap the Result::store and Argument::get methods.
159  */
160 
161 template <typename ABI, typename Ret>
162 static void
163 storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
164 {
166 }
167 
168 template <typename ABI, typename Arg>
169 static Arg
170 getArgument(ThreadContext *tc, typename ABI::State &state)
171 {
172  return Argument<ABI, Arg>::get(tc, state);
173 }
174 
175 } // namespace guest_abi
176 } // namespace gem5
177 
178 #endif // __SIM_GUEST_ABI_LAYOUT_HH__
gem5::guest_abi::ResultStorer::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:138
gem5::guest_abi::Preparer
Definition: layout.hh:84
gem5::guest_abi::getArgument
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:170
gem5::guest_abi::prepareForArguments
static void prepareForArguments([[maybe_unused]] ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:115
gem5::guest_abi::StateInitializer< ABI, typename std::enable_if_t< std::is_constructible_v< typename ABI::State, const ThreadContext * > > >::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:63
gem5::guest_abi::ResultStorer< ABI, Ret, typename std::enable_if_t< std::is_same_v< void(*)(ThreadContext *, const Ret &, typename ABI::State &), decltype(&Result< ABI, Ret >::store)> > >::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:151
definition.hh
gem5::guest_abi::Preparer< ABI, Role, Type, decltype((void)&Role< ABI, Type >::prepare)>::prepare
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:100
gem5::guest_abi::ResultStorer
Definition: layout.hh:135
gem5::auxv::Type
Type
Definition: aux_vector.hh:65
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::guest_abi::storeResult
static void storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:163
gem5::guest_abi::initializeState
static ABI::State initializeState(const ThreadContext *tc)
Definition: layout.hh:71
compiler.hh
state
atomic_var_t state
Definition: helpers.cc:188
gem5::guest_abi::prepareForFunction
static void prepareForFunction(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:123
std
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2909
gem5::guest_abi::Preparer::prepare
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:87
gem5::guest_abi::Argument
Definition: definition.hh:98
gem5::guest_abi::Result
Definition: definition.hh:63
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::guest_abi::prepareForResult
static void prepareForResult(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:108
gem5::guest_abi::StateInitializer
Definition: layout.hh:49
gem5::guest_abi::StateInitializer::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:52

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17