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