gem5  v20.1.0.0
definition.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_DEFINITION_HH__
29 #define __SIM_GUEST_ABI_DEFINITION_HH__
30 
31 class ThreadContext;
32 
33 namespace GuestABI
34 {
35 
36 /*
37  * To implement an ABI, a subclass needs to implement a system of
38  * specializations of these two templates Result and Argument, and define a
39  * "State" type.
40  *
41  * The State type carries information about, for instance, how many
42  * integer registers have been consumed gathering earlier arguments. It
43  * may contain multiple elements if there are multiple dimensions to track,
44  * for instance the number of integer and floating point registers used so far.
45  *
46  * Result and Argument are class templates instead of function templates so
47  * that they can be partially specialized if necessary. C++ doesn't let you
48  * partially specialize function templates because that conflicts with
49  * template resolution using the function's arguments. Since we already know
50  * what type we want and we don't need argument based resolution, we can just
51  * wrap the desired functionality in classes and sidestep the problem.
52  *
53  * Also note that these templates have an "Enabled" parameter to support
54  * std::enable_if style conditional specializations.
55  */
56 
57 template <typename ABI, typename Ret, typename Enabled=void>
58 struct Result
59 {
60  /*
61  * Store result "ret" into the state accessible through tc. Optionally
62  * accept "state" in case it holds some signature wide information.
63  *
64  * Note that the declaration below is only to document the expected
65  * signature and is commented out so it won't be used by accident.
66  * Specializations of this Result class should define their own version
67  * of this method which actually does something.
68  *
69  * static void store(ThreadContext *tc, const Ret &ret);
70  * static void store(ThreadContext *tc, const Ret &ret,
71  * typename ABI::State &state);
72  */
73 
74  /*
75  * Prepare for a result of type Ret. This might mean, for instance,
76  * allocating an argument register for a result pointer.
77  *
78  * This method can be excluded if no preparation is necessary.
79  *
80  * static void prepare(ThreadContext *tc, typename ABI::State &state);
81  */
82 };
83 
84 /*
85  * This partial specialization prevents having to special case 'void' when
86  * working with return types.
87  */
88 template <typename ABI>
89 struct Result<ABI, void>
90 {};
91 
92 template <typename ABI, typename Arg, typename Enabled=void>
93 struct Argument
94 {
95  /*
96  * Retrieve an argument of type Arg from the state accessible through tc,
97  * assuming the state represented by "state" has already been used.
98  * Also update state to account for this argument as well.
99  *
100  * Like Result::store above, the declaration below is only to document
101  * the expected method signature.
102  *
103  * static Arg get(ThreadContext *tc, typename ABI::State &state);
104  */
105 
106  /*
107  * Prepare for an argument of type Arg. This might mean, for instance,
108  * allocating an argument register for a result pointer.
109  *
110  * This method can be excluded if no preparation is necessary.
111  *
112  * static void allocate(ThreadContext *tc, typename ABI::State &state);
113  */
114 };
115 
116 } // namespace GuestABI
117 
118 #endif // __SIM_GUEST_ABI_DEFINITION_HH__
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::Argument
Definition: definition.hh:93
GuestABI::Result
Definition: definition.hh:58

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