Deleted Added
sdiff udiff text old ( 2680:246e7104f744 ) new ( 5191:bebbfea0baf3 )
full compact
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
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__