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