arguments.hh revision 10468
12SN/A/* 21762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Nathan Binkert 292SN/A */ 302SN/A 314826Ssaidi@eecs.umich.edu#ifndef __SIM_ARGUMENTS_HH__ 324826Ssaidi@eecs.umich.edu#define __SIM_ARGUMENTS_HH__ 332SN/A 346216Snate@binkert.org#include <cassert> 3510468Sandreas.hansson@arm.com#include <memory> 362SN/A 376216Snate@binkert.org#include "base/types.hh" 388706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 392SN/A 402680SN/Aclass ThreadContext; 412SN/A 423535SN/Aclass Arguments 432SN/A{ 442SN/A protected: 452680SN/A ThreadContext *tc; 462SN/A int number; 477707Sgblack@eecs.umich.edu uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false); 482SN/A 492SN/A protected: 5010468Sandreas.hansson@arm.com class Data 512SN/A { 522SN/A public: 532SN/A Data(){} 542SN/A ~Data(); 552SN/A 562SN/A private: 572SN/A std::list<char *> data; 582SN/A 592SN/A public: 602SN/A char *alloc(size_t size); 612SN/A }; 622SN/A 6310468Sandreas.hansson@arm.com std::shared_ptr<Data> data; 642SN/A 652SN/A public: 663535SN/A Arguments(ThreadContext *ctx, int n = 0) 6710468Sandreas.hansson@arm.com : tc(ctx), number(n), data(new Data()) 6810468Sandreas.hansson@arm.com { assert(number >= 0); } 693535SN/A Arguments(const Arguments &args) 702680SN/A : tc(args.tc), number(args.number), data(args.data) {} 713535SN/A ~Arguments() {} 722SN/A 732680SN/A ThreadContext *getThreadContext() const { return tc; } 742SN/A 753535SN/A const Arguments &operator=(const Arguments &args) { 7610468Sandreas.hansson@arm.com if (this != &args) { 7710468Sandreas.hansson@arm.com tc = args.tc; 7810468Sandreas.hansson@arm.com number = args.number; 7910468Sandreas.hansson@arm.com data = args.data; 8010468Sandreas.hansson@arm.com } 812SN/A return *this; 822SN/A } 832SN/A 844826Ssaidi@eecs.umich.edu // for checking if an argument is NULL 854826Ssaidi@eecs.umich.edu bool operator!() { 867707Sgblack@eecs.umich.edu return getArg() == 0; 874826Ssaidi@eecs.umich.edu } 884826Ssaidi@eecs.umich.edu 893535SN/A Arguments &operator++() { 902SN/A ++number; 912SN/A assert(number >= 0); 922SN/A return *this; 932SN/A } 942SN/A 953535SN/A Arguments operator++(int) { 963535SN/A Arguments args = *this; 972SN/A ++number; 982SN/A assert(number >= 0); 992SN/A return args; 1002SN/A } 1012SN/A 1023535SN/A Arguments &operator--() { 1032SN/A --number; 1042SN/A assert(number >= 0); 1052SN/A return *this; 1062SN/A } 1072SN/A 1083535SN/A Arguments operator--(int) { 1093535SN/A Arguments args = *this; 1102SN/A --number; 1112SN/A assert(number >= 0); 1122SN/A return args; 1132SN/A } 1142SN/A 1153535SN/A const Arguments &operator+=(int index) { 1162SN/A number += index; 1172SN/A assert(number >= 0); 1182SN/A return *this; 1192SN/A } 1202SN/A 1213535SN/A const Arguments &operator-=(int index) { 1222SN/A number -= index; 1232SN/A assert(number >= 0); 1242SN/A return *this; 1252SN/A } 1262SN/A 1273535SN/A Arguments operator[](int index) { 1283535SN/A return Arguments(tc, index); 1292SN/A } 1302SN/A 1312SN/A template <class T> 1322SN/A operator T() { 1332SN/A assert(sizeof(T) <= sizeof(uint64_t)); 1349550Sandreas.hansson@arm.com T d = static_cast<T>(getArg(sizeof(T))); 1359550Sandreas.hansson@arm.com return d; 1362SN/A } 1372SN/A 1382SN/A template <class T> 1392SN/A operator T *() { 1402SN/A T *buf = (T *)data->alloc(sizeof(T)); 1419034Sandreas.hansson@arm.com CopyOut(tc, buf, getArg(sizeof(T)), sizeof(T)); 1422SN/A return buf; 1432SN/A } 1442SN/A 1452SN/A operator char *() { 1462SN/A char *buf = data->alloc(2048); 1477707Sgblack@eecs.umich.edu CopyStringOut(tc, buf, getArg(), 2048); 1482SN/A return buf; 1492SN/A } 1502SN/A}; 1512SN/A 1524826Ssaidi@eecs.umich.edu#endif // __SIM_ARGUMENTS_HH__ 153