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; --- 19 unchanged lines hidden (view full) --- 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 |
46 protected: |
47 ThreadContext *tc; 48 Addr ptr; |
49 Addr buffer[(sizeof(T)-1)/sizeof(Addr) + 1]; |
50 51 public: |
52 explicit VPtr(ThreadContext *_tc, Addr p = 0) 53 : tc(_tc), ptr(p) 54 { 55 refresh(); 56 } |
57 |
58 template <class U> |
59 VPtr(const VPtr &vp) 60 : tc(vp.tc), ptr(vp.ptr) 61 { 62 refresh(); 63 } |
64 |
65 ~VPtr() 66 {} 67 68 void 69 refresh() |
70 { |
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 |
79 bool 80 operator!() const |
81 { |
82 return ptr == 0; 83 } |
84 |
85 VPtr<T> 86 operator+(int offset) 87 { 88 return VPtr<T>(tc, ptr + offset); |
89 } 90 |
91 const VPtr 92 operator+=(int offset) |
93 { 94 ptr += offset; |
95 refresh(); |
96 97 return *this; 98 } 99 |
100 const VPtr 101 operator=(Addr p) |
102 { |
103 ptr = p; |
104 refresh(); |
105 106 return *this; 107 } 108 109 template <class U> |
110 const VPtr 111 operator=(const VPtr<U> &vp) |
112 { |
113 tc = vp.tc; 114 ptr = vp.ptr; 115 refresh(); |
116 117 return *this; 118 } 119 120 operator T *() 121 { |
122 return (T *)buffer; |
123 } 124 |
125 T * 126 operator->() |
127 { |
128 return (T *)buffer; |
129 } 130 |
131 T & 132 operator*() |
133 { |
134 return *(T *)buffer; |
135 } 136}; 137 138#endif // __ARCH_ALPHA_VPTR_HH__ |