New directory structure:
[gem5.git] / src / arch / alpha / arguments.hh
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __ARCH_ALPHA_ARGUMENTS_HH__
30 #define __ARCH_ALPHA_ARGUMENTS_HH__
31
32 #include <assert.h>
33
34 #include "arch/alpha/vtophys.hh"
35 #include "base/refcnt.hh"
36 #include "sim/host.hh"
37
38 class ExecContext;
39
40 namespace AlphaISA {
41
42 class AlphaArguments
43 {
44 protected:
45 ExecContext *xc;
46 int number;
47 uint64_t getArg(bool fp = false);
48
49 protected:
50 class Data : public RefCounted
51 {
52 public:
53 Data(){}
54 ~Data();
55
56 private:
57 std::list<char *> data;
58
59 public:
60 char *alloc(size_t size);
61 };
62
63 RefCountingPtr<Data> data;
64
65 public:
66 AlphaArguments(ExecContext *ctx, int n = 0)
67 : xc(ctx), number(n), data(NULL)
68 { assert(number >= 0); data = new Data;}
69 AlphaArguments(const AlphaArguments &args)
70 : xc(args.xc), number(args.number), data(args.data) {}
71 ~AlphaArguments() {}
72
73 ExecContext *getExecContext() const { return xc; }
74
75 const AlphaArguments &operator=(const AlphaArguments &args) {
76 xc = args.xc;
77 number = args.number;
78 data = args.data;
79 return *this;
80 }
81
82 AlphaArguments &operator++() {
83 ++number;
84 assert(number >= 0);
85 return *this;
86 }
87
88 AlphaArguments operator++(int) {
89 AlphaArguments args = *this;
90 ++number;
91 assert(number >= 0);
92 return args;
93 }
94
95 AlphaArguments &operator--() {
96 --number;
97 assert(number >= 0);
98 return *this;
99 }
100
101 AlphaArguments operator--(int) {
102 AlphaArguments args = *this;
103 --number;
104 assert(number >= 0);
105 return args;
106 }
107
108 const AlphaArguments &operator+=(int index) {
109 number += index;
110 assert(number >= 0);
111 return *this;
112 }
113
114 const AlphaArguments &operator-=(int index) {
115 number -= index;
116 assert(number >= 0);
117 return *this;
118 }
119
120 AlphaArguments operator[](int index) {
121 return AlphaArguments(xc, index);
122 }
123
124 template <class T>
125 operator T() {
126 assert(sizeof(T) <= sizeof(uint64_t));
127 T data = static_cast<T>(getArg());
128 return data;
129 }
130
131 template <class T>
132 operator T *() {
133 T *buf = (T *)data->alloc(sizeof(T));
134 CopyData(xc, buf, getArg(), sizeof(T));
135 return buf;
136 }
137
138 operator char *() {
139 char *buf = data->alloc(2048);
140 CopyStringOut(xc, buf, getArg(), 2048);
141 return buf;
142 }
143 };
144
145 }; // namespace AlphaISA
146
147 #endif // __ARCH_ALPHA_ARGUMENTS_HH__