gem5  v21.1.0.2
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<typename ABI::State, const ThreadContext *>::value>>
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
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<void (*)(ThreadContext *, const Ret &, typename ABI::State &),
148  decltype(&Result<ABI, Ret>::store)>::value>>
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 {
165  ResultStorer<ABI, Ret>::store(tc, ret, state);
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::prepareForArguments
static void prepareForArguments(GEM5_VAR_USED ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:116
gem5::guest_abi::ResultStorer::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:139
gem5::guest_abi::Preparer
Definition: layout.hh:85
gem5::guest_abi::getArgument
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:170
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:101
gem5::guest_abi::ResultStorer
Definition: layout.hh:136
gem5::guest_abi::ResultStorer< ABI, Ret, typename std::enable_if_t< std::is_same< void(*)(ThreadContext *, const Ret &, typename ABI::State &), decltype(&Result< ABI, Ret >::store)>::value > >::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:151
gem5::auxv::Type
Type
Definition: aux_vector.hh:67
gem5::guest_abi::StateInitializer< ABI, typename std::enable_if_t< std::is_constructible< typename ABI::State, const ThreadContext * >::value > >::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:64
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
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:72
compiler.hh
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::guest_abi::prepareForFunction
static void prepareForFunction(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:124
std
Overload hash function for BasicBlockRange type.
Definition: types.hh:111
gem5::guest_abi::Preparer::prepare
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:88
gem5::guest_abi::Argument
Definition: definition.hh:99
gem5::guest_abi::Result
Definition: definition.hh:64
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::guest_abi::prepareForResult
static void prepareForResult(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:109
gem5::guest_abi::StateInitializer
Definition: layout.hh:50
gem5::guest_abi::StateInitializer::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:53

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17