arguments.hh revision 9550
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>
352SN/A
364826Ssaidi@eecs.umich.edu#include "arch/vtophys.hh"
3774SN/A#include "base/refcnt.hh"
386216Snate@binkert.org#include "base/types.hh"
398706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh"
402SN/A
412680SN/Aclass ThreadContext;
422SN/A
433535SN/Aclass Arguments
442SN/A{
452SN/A  protected:
462680SN/A    ThreadContext *tc;
472SN/A    int number;
487707Sgblack@eecs.umich.edu    uint64_t getArg(uint16_t size = (uint16_t)(-1), bool fp = false);
492SN/A
502SN/A  protected:
512SN/A    class Data : public RefCounted
522SN/A    {
532SN/A      public:
542SN/A        Data(){}
552SN/A        ~Data();
562SN/A
572SN/A      private:
582SN/A        std::list<char *> data;
592SN/A
602SN/A      public:
612SN/A        char *alloc(size_t size);
622SN/A    };
632SN/A
642SN/A    RefCountingPtr<Data> data;
652SN/A
662SN/A  public:
673535SN/A    Arguments(ThreadContext *ctx, int n = 0)
682680SN/A        : tc(ctx), number(n), data(NULL)
692SN/A        { assert(number >= 0); data = new Data;}
703535SN/A    Arguments(const Arguments &args)
712680SN/A        : tc(args.tc), number(args.number), data(args.data) {}
723535SN/A    ~Arguments() {}
732SN/A
742680SN/A    ThreadContext *getThreadContext() const { return tc; }
752SN/A
763535SN/A    const Arguments &operator=(const Arguments &args) {
772680SN/A        tc = args.tc;
782SN/A        number = args.number;
792SN/A        data = args.data;
802SN/A        return *this;
812SN/A    }
822SN/A
834826Ssaidi@eecs.umich.edu    // for checking if an argument is NULL
844826Ssaidi@eecs.umich.edu    bool operator!() {
857707Sgblack@eecs.umich.edu        return getArg() == 0;
864826Ssaidi@eecs.umich.edu    }
874826Ssaidi@eecs.umich.edu
883535SN/A    Arguments &operator++() {
892SN/A        ++number;
902SN/A        assert(number >= 0);
912SN/A        return *this;
922SN/A    }
932SN/A
943535SN/A    Arguments operator++(int) {
953535SN/A        Arguments args = *this;
962SN/A        ++number;
972SN/A        assert(number >= 0);
982SN/A        return args;
992SN/A    }
1002SN/A
1013535SN/A    Arguments &operator--() {
1022SN/A        --number;
1032SN/A        assert(number >= 0);
1042SN/A        return *this;
1052SN/A    }
1062SN/A
1073535SN/A    Arguments operator--(int) {
1083535SN/A        Arguments args = *this;
1092SN/A        --number;
1102SN/A        assert(number >= 0);
1112SN/A        return args;
1122SN/A    }
1132SN/A
1143535SN/A    const Arguments &operator+=(int index) {
1152SN/A        number += index;
1162SN/A        assert(number >= 0);
1172SN/A        return *this;
1182SN/A    }
1192SN/A
1203535SN/A    const Arguments &operator-=(int index) {
1212SN/A        number -= index;
1222SN/A        assert(number >= 0);
1232SN/A        return *this;
1242SN/A    }
1252SN/A
1263535SN/A    Arguments operator[](int index) {
1273535SN/A        return Arguments(tc, index);
1282SN/A    }
1292SN/A
1302SN/A    template <class T>
1312SN/A    operator T() {
1322SN/A        assert(sizeof(T) <= sizeof(uint64_t));
1339550Sandreas.hansson@arm.com        T d = static_cast<T>(getArg(sizeof(T)));
1349550Sandreas.hansson@arm.com        return d;
1352SN/A    }
1362SN/A
1372SN/A    template <class T>
1382SN/A    operator T *() {
1392SN/A        T *buf = (T *)data->alloc(sizeof(T));
1409034Sandreas.hansson@arm.com        CopyOut(tc, buf, getArg(sizeof(T)), sizeof(T));
1412SN/A        return buf;
1422SN/A    }
1432SN/A
1442SN/A    operator char *() {
1452SN/A        char *buf = data->alloc(2048);
1467707Sgblack@eecs.umich.edu        CopyStringOut(tc, buf, getArg(), 2048);
1472SN/A        return buf;
1482SN/A    }
1492SN/A};
1502SN/A
1514826Ssaidi@eecs.umich.edu#endif // __SIM_ARGUMENTS_HH__
152