arguments.hh revision 3535
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 * Authors: Nathan Binkert
29 */
30
31#ifndef __ARCH_ALPHA_ARGUMENTS_HH__
32#define __ARCH_ALPHA_ARGUMENTS_HH__
33
34#include <assert.h>
35
36#include "arch/alpha/vtophys.hh"
37#include "base/refcnt.hh"
38#include "sim/host.hh"
39
40class ThreadContext;
41
42namespace AlphaISA {
43
44class Arguments
45{
46  protected:
47    ThreadContext *tc;
48    int number;
49    uint64_t getArg(bool fp = false);
50
51  protected:
52    class Data : public RefCounted
53    {
54      public:
55        Data(){}
56        ~Data();
57
58      private:
59        std::list<char *> data;
60
61      public:
62        char *alloc(size_t size);
63    };
64
65    RefCountingPtr<Data> data;
66
67  public:
68    Arguments(ThreadContext *ctx, int n = 0)
69        : tc(ctx), number(n), data(NULL)
70        { assert(number >= 0); data = new Data;}
71    Arguments(const Arguments &args)
72        : tc(args.tc), number(args.number), data(args.data) {}
73    ~Arguments() {}
74
75    ThreadContext *getThreadContext() const { return tc; }
76
77    const Arguments &operator=(const Arguments &args) {
78        tc = args.tc;
79        number = args.number;
80        data = args.data;
81        return *this;
82    }
83
84    Arguments &operator++() {
85        ++number;
86        assert(number >= 0);
87        return *this;
88    }
89
90    Arguments operator++(int) {
91        Arguments args = *this;
92        ++number;
93        assert(number >= 0);
94        return args;
95    }
96
97    Arguments &operator--() {
98        --number;
99        assert(number >= 0);
100        return *this;
101    }
102
103    Arguments operator--(int) {
104        Arguments args = *this;
105        --number;
106        assert(number >= 0);
107        return args;
108    }
109
110    const Arguments &operator+=(int index) {
111        number += index;
112        assert(number >= 0);
113        return *this;
114    }
115
116    const Arguments &operator-=(int index) {
117        number -= index;
118        assert(number >= 0);
119        return *this;
120    }
121
122    Arguments operator[](int index) {
123        return Arguments(tc, index);
124    }
125
126    template <class T>
127    operator T() {
128        assert(sizeof(T) <= sizeof(uint64_t));
129        T data = static_cast<T>(getArg());
130        return data;
131    }
132
133    template <class T>
134    operator T *() {
135        T *buf = (T *)data->alloc(sizeof(T));
136        CopyData(tc, buf, getArg(), sizeof(T));
137        return buf;
138    }
139
140    operator char *() {
141        char *buf = data->alloc(2048);
142        CopyStringOut(tc, buf, getArg(), 2048);
143        return buf;
144    }
145};
146
147}; // namespace AlphaISA
148
149#endif // __ARCH_ALPHA_ARGUMENTS_HH__
150