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 3714018Sgabeblack@google.com#include "cpu/thread_context.hh" 388706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh" 392SN/A 403535SN/Aclass Arguments 412SN/A{ 422SN/A protected: 432680SN/A ThreadContext *tc; 442SN/A int number; 457707Sgblack@eecs.umich.edu uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false); 462SN/A 472SN/A protected: 4810468Sandreas.hansson@arm.com class Data 492SN/A { 502SN/A public: 512SN/A Data(){} 522SN/A ~Data(); 532SN/A 542SN/A private: 552SN/A std::list<char *> data; 562SN/A 572SN/A public: 582SN/A char *alloc(size_t size); 592SN/A }; 602SN/A 6110468Sandreas.hansson@arm.com std::shared_ptr<Data> data; 622SN/A 632SN/A public: 643535SN/A Arguments(ThreadContext *ctx, int n = 0) 6510468Sandreas.hansson@arm.com : tc(ctx), number(n), data(new Data()) 6610468Sandreas.hansson@arm.com { assert(number >= 0); } 673535SN/A Arguments(const Arguments &args) 682680SN/A : tc(args.tc), number(args.number), data(args.data) {} 693535SN/A ~Arguments() {} 702SN/A 712680SN/A ThreadContext *getThreadContext() const { return tc; } 722SN/A 733535SN/A const Arguments &operator=(const Arguments &args) { 7410468Sandreas.hansson@arm.com if (this != &args) { 7510468Sandreas.hansson@arm.com tc = args.tc; 7610468Sandreas.hansson@arm.com number = args.number; 7710468Sandreas.hansson@arm.com data = args.data; 7810468Sandreas.hansson@arm.com } 792SN/A return *this; 802SN/A } 812SN/A 824826Ssaidi@eecs.umich.edu // for checking if an argument is NULL 834826Ssaidi@eecs.umich.edu bool operator!() { 847707Sgblack@eecs.umich.edu return getArg() == 0; 854826Ssaidi@eecs.umich.edu } 864826Ssaidi@eecs.umich.edu 873535SN/A Arguments &operator++() { 882SN/A ++number; 892SN/A assert(number >= 0); 902SN/A return *this; 912SN/A } 922SN/A 933535SN/A Arguments operator++(int) { 943535SN/A Arguments args = *this; 952SN/A ++number; 962SN/A assert(number >= 0); 972SN/A return args; 982SN/A } 992SN/A 1003535SN/A Arguments &operator--() { 1012SN/A --number; 1022SN/A assert(number >= 0); 1032SN/A return *this; 1042SN/A } 1052SN/A 1063535SN/A Arguments operator--(int) { 1073535SN/A Arguments args = *this; 1082SN/A --number; 1092SN/A assert(number >= 0); 1102SN/A return args; 1112SN/A } 1122SN/A 1133535SN/A const Arguments &operator+=(int index) { 1142SN/A number += index; 1152SN/A assert(number >= 0); 1162SN/A return *this; 1172SN/A } 1182SN/A 1193535SN/A const Arguments &operator-=(int index) { 1202SN/A number -= index; 1212SN/A assert(number >= 0); 1222SN/A return *this; 1232SN/A } 1242SN/A 1253535SN/A Arguments operator[](int index) { 1263535SN/A return Arguments(tc, index); 1272SN/A } 1282SN/A 1292SN/A template <class T> 1302SN/A operator T() { 1312SN/A assert(sizeof(T) <= sizeof(uint64_t)); 1329550Sandreas.hansson@arm.com T d = static_cast<T>(getArg(sizeof(T))); 1339550Sandreas.hansson@arm.com return d; 1342SN/A } 1352SN/A 1362SN/A template <class T> 1372SN/A operator T *() { 1382SN/A T *buf = (T *)data->alloc(sizeof(T)); 13914018Sgabeblack@google.com tc->getVirtProxy().readBlob(getArg(sizeof(T)), buf, sizeof(T)); 1402SN/A return buf; 1412SN/A } 1422SN/A 1432SN/A operator char *() { 1442SN/A char *buf = data->alloc(2048); 14514018Sgabeblack@google.com tc->getVirtProxy().readString(buf, getArg(), 2048); 1462SN/A return buf; 1472SN/A } 1482SN/A}; 1492SN/A 1504826Ssaidi@eecs.umich.edu#endif // __SIM_ARGUMENTS_HH__ 151