gem5  v20.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 
34 
35 class ThreadContext;
36 
37 namespace GuestABI
38 {
39 
40 /*
41  * State may need to be initialized based on the ThreadContext, for instance
42  * to find out where the stack pointer is initially.
43  */
44 template <typename ABI, typename Enabled=void>
46 {
47  static typename ABI::State
48  init(const ThreadContext *tc)
49  {
50  return typename ABI::State();
51  }
52 };
53 
54 template <typename ABI>
55 struct StateInitializer<ABI, typename std::enable_if<
56  std::is_constructible<typename ABI::State, const ThreadContext *>::value
57  >::type>
58 {
59  static typename ABI::State
60  init(const ThreadContext *tc)
61  {
62  return typename ABI::State(tc);
63  }
64 };
65 
66 template <typename ABI>
67 static typename ABI::State
69 {
70  return StateInitializer<ABI>::init(tc);
71 }
72 
73 /*
74  * This struct template provides a default prepare() method in case the
75  * Result or Argument template doesn't provide one. This is the default in
76  * cases where the return or argument type doesn't affect where things are
77  * stored.
78  */
79 template <typename ABI, template <class ...> class Role,
80  typename Type, typename Enabled=void>
81 struct Preparer
82 {
83  static void
84  prepare(ThreadContext *tc, typename ABI::State &state)
85  {}
86 };
87 
88 /*
89  * If the return or argument type isn't void and does affect where things
90  * are stored, the ABI can implement a prepare() method for the various
91  * argument and/or return types, and this specialization will call into it.
92  */
93 template <typename ABI, template <class ...> class Role, typename Type>
94 struct Preparer<ABI, Role, Type, decltype((void)&Role<ABI, Type>::prepare)>
95 {
96  static void
97  prepare(ThreadContext *tc, typename ABI::State &state)
98  {
99  Role<ABI, Type>::prepare(tc, state);
100  }
101 };
102 
103 template <typename ABI, typename Ret, typename Enabled=void>
104 static void
105 prepareForResult(ThreadContext *tc, typename ABI::State &state)
106 {
108 }
109 
110 template <typename ABI>
111 static void
112 prepareForArguments(ThreadContext *tc, typename ABI::State &state)
113 {
114  return;
115 }
116 
117 template <typename ABI, typename NextArg, typename ...Args>
118 static void
119 prepareForArguments(ThreadContext *tc, typename ABI::State &state)
120 {
122  prepareForArguments<ABI, Args...>(tc, state);
123 }
124 
125 template <typename ABI, typename Ret, typename ...Args>
126 static void
127 prepareForFunction(ThreadContext *tc, typename ABI::State &state)
128 {
129  prepareForResult<ABI, Ret>(tc, state);
130  prepareForArguments<ABI, Args...>(tc, state);
131 }
132 
133 /*
134  * This struct template provides a way to call the Result store method and
135  * optionally pass it the state.
136  */
137 
138 template <typename ABI, typename Ret, typename Enabled=void>
140 {
141  static void
142  store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
143  {
144  Result<ABI, Ret>::store(tc, ret);
145  }
146 };
147 
148 template <typename Ret, typename State>
149 std::true_type foo(void (*)(ThreadContext *, const Ret &ret, State &state));
150 
151 template <typename Ret>
152 std::false_type foo(void (*)(ThreadContext *, const Ret &ret));
153 
154 template <typename ABI, typename Ret>
155 struct ResultStorer<ABI, Ret, typename std::enable_if<
156  std::is_same<void (*)(ThreadContext *, const Ret &, typename ABI::State &),
157  decltype(&Result<ABI, Ret>::store)>::value>::type>
158 {
159  static void
160  store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
161  {
162  Result<ABI, Ret>::store(tc, ret, state);
163  }
164 };
165 
166 /*
167  * Function templates to wrap the Result::store and Argument::get methods.
168  */
169 
170 template <typename ABI, typename Ret>
171 static void
172 storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
173 {
174  ResultStorer<ABI, Ret>::store(tc, ret, state);
175 }
176 
177 template <typename ABI, typename Arg>
178 static Arg
179 getArgument(ThreadContext *tc, typename ABI::State &state)
180 {
181  return Argument<ABI, Arg>::get(tc, state);
182 }
183 
184 } // namespace GuestABI
185 
186 #endif // __SIM_GUEST_ABI_LAYOUT_HH__
GuestABI::StateInitializer
Definition: layout.hh:45
definition.hh
GuestABI::StateInitializer< ABI, typename std::enable_if< std::is_constructible< typename ABI::State, const ThreadContext * >::value >::type >::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:60
type
uint8_t type
Definition: inet.hh:421
GuestABI::getArgument
static Arg getArgument(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:179
GuestABI::prepareForArguments
static void prepareForArguments(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:112
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
GuestABI
Definition: aapcs32.hh:66
GuestABI::prepareForResult
static void prepareForResult(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:105
GuestABI::Argument
Definition: definition.hh:93
GuestABI::Preparer::prepare
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:84
GuestABI::ResultStorer< ABI, Ret, typename std::enable_if< std::is_same< void(*)(ThreadContext *, const Ret &, typename ABI::State &), decltype(&Result< ABI, Ret >::store)>::value >::type >::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:160
GuestABI::initializeState
static ABI::State initializeState(const ThreadContext *tc)
Definition: layout.hh:68
GuestABI::ResultStorer::store
static void store(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:142
GuestABI::Result
Definition: definition.hh:58
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
GuestABI::ResultStorer
Definition: layout.hh:139
GuestABI::storeResult
static void storeResult(ThreadContext *tc, const Ret &ret, typename ABI::State &state)
Definition: layout.hh:172
GuestABI::StateInitializer::init
static ABI::State init(const ThreadContext *tc)
Definition: layout.hh:48
GuestABI::Preparer< ABI, Role, Type, decltype((void)&Role< ABI, Type >::prepare)>::prepare
static void prepare(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:97
GuestABI::prepareForFunction
static void prepareForFunction(ThreadContext *tc, typename ABI::State &state)
Definition: layout.hh:127
GuestABI::foo
std::true_type foo(void(*)(ThreadContext *, const Ret &ret, State &state))
GuestABI::Preparer
Definition: layout.hh:81

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17