vptr.hh revision 1354
11689SN/A/* 22316SN/A * Copyright (c) 2004 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A */ 282665SN/A 291689SN/A#ifndef __ARCH_ALPHA_VPTR_HH__ 301061SN/A#define __ARCH_ALPHA_VPTR_HH__ 315596Sgblack@eecs.umich.edu 321061SN/A#include "arch/alpha/vtophys.hh" 331061SN/A 345596Sgblack@eecs.umich.educlass ExecContext; 355596Sgblack@eecs.umich.edu 365596Sgblack@eecs.umich.edutemplate <class T> 375596Sgblack@eecs.umich.educlass VPtr 385596Sgblack@eecs.umich.edu{ 394637SN/A public: 405596Sgblack@eecs.umich.edu typedef T Type; 414637SN/A 424637SN/A private: 434637SN/A ExecContext *xc; 444637SN/A Addr ptr; 454637SN/A 465596Sgblack@eecs.umich.edu public: 475596Sgblack@eecs.umich.edu ExecContext *GetXC() const { return xc; } 485596Sgblack@eecs.umich.edu Addr GetPointer() const { return ptr; } 495596Sgblack@eecs.umich.edu 505596Sgblack@eecs.umich.edu public: 514637SN/A explicit VPtr(ExecContext *_xc, Addr p = 0) : xc(_xc), ptr(p) { } 525596Sgblack@eecs.umich.edu template <class U> 531061SN/A VPtr(const VPtr<U> &vp) : xc(vp.GetXC()), ptr(vp.GetPointer()) {} 542292SN/A ~VPtr() {} 551061SN/A 561061SN/A bool operator!() const 571061SN/A { 585596Sgblack@eecs.umich.edu return ptr == 0; 591464SN/A } 601061SN/A 612292SN/A VPtr<T> operator+(int offset) 622292SN/A { 632292SN/A VPtr<T> ptr(*this); 642292SN/A ptr += offset; 652292SN/A 665596Sgblack@eecs.umich.edu return ptr; 672292SN/A } 681464SN/A 691464SN/A const VPtr<T> &operator+=(int offset) 701464SN/A { 712292SN/A ptr += offset; 723782SN/A assert((ptr & (AlphaISA::PageBytes - 1)) + sizeof(T) 731464SN/A < AlphaISA::PageBytes); 741464SN/A 752292SN/A return *this; 763782SN/A } 772292SN/A 781464SN/A const VPtr<T> &operator=(Addr p) 791061SN/A { 801061SN/A assert((p & (AlphaISA::PageBytes)) + sizeof(T) < AlphaISA::PageBytes); 812292SN/A ptr = p; 822292SN/A 835596Sgblack@eecs.umich.edu return *this; 842292SN/A } 852348SN/A 862680SN/A template <class U> 872348SN/A const VPtr<T> &operator=(const VPtr<U> &vp) 882680SN/A { 892292SN/A xc = vp.GetXC(); 902292SN/A ptr = vp.GetPointer(); 912292SN/A 922292SN/A return *this; 932292SN/A } 942292SN/A 952292SN/A operator T *() 962292SN/A { 972292SN/A void *addr = vtomem(xc, ptr, sizeof(T)); 982292SN/A return (T *)addr; 992292SN/A } 1002292SN/A 1015596Sgblack@eecs.umich.edu T *operator->() 1022292SN/A { 1032348SN/A void *addr = vtomem(xc, ptr, sizeof(T)); 1042680SN/A return (T *)addr; 1052348SN/A } 1062680SN/A 1072292SN/A T &operator*() 1082292SN/A { 1092292SN/A void *addr = vtomem(xc, ptr, sizeof(T)); 1102292SN/A return *(T *)addr; 1112292SN/A } 1122292SN/A}; 1132292SN/A 1142292SN/A#endif // __ARCH_ALPHA_VPTR_HH__ 1152292SN/A