1/* 2 * Copyright (c) 2004-2005 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 * Authors: Nathan Binkert 29 */ 30 31#ifndef __ARCH_ALPHA_VPTR_HH__ 32#define __ARCH_ALPHA_VPTR_HH__ 33 34#include "arch/vtophys.hh" 35#include "arch/isa_traits.hh"
|
36#include "mem/vport.hh" |
37 38class ThreadContext; 39 40template <class T> 41class VPtr 42{ 43 public: 44 typedef T Type; 45
|
45 private:
|
46 protected: |
47 ThreadContext *tc; 48 Addr ptr;
|
49 Addr buffer[(sizeof(T)-1)/sizeof(Addr) + 1]; |
50 51 public:
|
50 ThreadContext *GetTC() const { return tc; }
51 Addr GetPointer() const { return ptr; }
|
52 explicit VPtr(ThreadContext *_tc, Addr p = 0) 53 : tc(_tc), ptr(p) 54 { 55 refresh(); 56 } |
57
|
53 public:
54 explicit VPtr(ThreadContext *_tc, Addr p = 0) : tc(_tc), ptr(p) { }
|
58 template <class U>
|
56 VPtr(const VPtr<U> &vp) : tc(vp.GetTC()), ptr(vp.GetPointer()) {}
57 ~VPtr() {}
|
59 VPtr(const VPtr &vp) 60 : tc(vp.tc), ptr(vp.ptr) 61 { 62 refresh(); 63 } |
64
|
59 bool operator!() const
|
65 ~VPtr() 66 {} 67 68 void 69 refresh() |
70 {
|
61 return ptr == 0;
|
71 if (!ptr) 72 return; 73 74 VirtualPort *port = tc->getVirtPort(tc); 75 port->readBlob(ptr, buffer, sizeof(T)); 76 tc->delVirtPort(port); |
77 } 78
|
64 VPtr<T> operator+(int offset)
|
79 bool 80 operator!() const |
81 {
|
66 VPtr<T> ptr(*this);
67 ptr += offset;
|
82 return ptr == 0; 83 } |
84
|
69 return ptr;
|
85 VPtr<T> 86 operator+(int offset) 87 { 88 return VPtr<T>(tc, ptr + offset); |
89 } 90
|
72 const VPtr<T> &operator+=(int offset)
|
91 const VPtr & 92 operator+=(int offset) |
93 { 94 ptr += offset;
|
75 assert((ptr & (TheISA::PageBytes - 1)) + sizeof(T)
76 < TheISA::PageBytes);
|
95 refresh(); |
96 97 return *this; 98 } 99
|
81 const VPtr<T> &operator=(Addr p)
|
100 const VPtr & 101 operator=(Addr p) |
102 {
|
83 assert((p & (TheISA::PageBytes - 1)) + sizeof(T)
84 < TheISA::PageBytes);
|
103 ptr = p;
|
104 refresh(); |
105 106 return *this; 107 } 108 109 template <class U>
|
91 const VPtr<T> &operator=(const VPtr<U> &vp)
|
110 const VPtr & 111 operator=(const VPtr<U> &vp) |
112 {
|
93 tc = vp.GetTC();
94 ptr = vp.GetPointer();
|
113 tc = vp.tc; 114 ptr = vp.ptr; 115 refresh(); |
116 117 return *this; 118 } 119 120 operator T *() 121 {
|
101 panic("Needs to be rewritten\n");
102/* void *addr = vtomem(tc, ptr, sizeof(T));
103 return (T *)addr;
104 */
|
122 return (T *)buffer; |
123 } 124
|
107 T *operator->()
|
125 T * 126 operator->() |
127 {
|
109 panic("Needs to be rewritten\n");
110/* void *addr = vtomem(tc, ptr, sizeof(T));
111 return (T *)addr;
112 */
|
128 return (T *)buffer; |
129 } 130
|
115 T &operator*()
|
131 T & 132 operator*() |
133 {
|
117 panic("Needs to be rewritten\n");
118/* void *addr = vtomem(tc, ptr, sizeof(T));
119 return *(T *)addr;
120 */
|
134 return *(T *)buffer; |
135 } 136}; 137 138#endif // __ARCH_ALPHA_VPTR_HH__
|