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

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0