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