vptr.hh (2680:246e7104f744) vptr.hh (5191:bebbfea0baf3)
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"
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"
36
37class ThreadContext;
38
39template <class T>
40class VPtr
41{
42 public:
43 typedef T Type;
44
37
38class ThreadContext;
39
40template <class T>
41class VPtr
42{
43 public:
44 typedef T Type;
45
45 private:
46 protected:
46 ThreadContext *tc;
47 Addr ptr;
47 ThreadContext *tc;
48 Addr ptr;
49 Addr buffer[(sizeof(T)-1)/sizeof(Addr) + 1];
48
49 public:
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 }
52
57
53 public:
54 explicit VPtr(ThreadContext *_tc, Addr p = 0) : tc(_tc), ptr(p) { }
55 template <class U>
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 }
58
64
59 bool operator!() const
65 ~VPtr()
66 {}
67
68 void
69 refresh()
60 {
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);
62 }
63
77 }
78
64 VPtr<T> operator+(int offset)
79 bool
80 operator!() const
65 {
81 {
66 VPtr<T> ptr(*this);
67 ptr += offset;
82 return ptr == 0;
83 }
68
84
69 return ptr;
85 VPtr<T>
86 operator+(int offset)
87 {
88 return VPtr<T>(tc, ptr + offset);
70 }
71
89 }
90
72 const VPtr<T> &operator+=(int offset)
91 const VPtr &
92 operator+=(int offset)
73 {
74 ptr += offset;
93 {
94 ptr += offset;
75 assert((ptr & (TheISA::PageBytes - 1)) + sizeof(T)
76 < TheISA::PageBytes);
95 refresh();
77
78 return *this;
79 }
80
96
97 return *this;
98 }
99
81 const VPtr<T> &operator=(Addr p)
100 const VPtr &
101 operator=(Addr p)
82 {
102 {
83 assert((p & (TheISA::PageBytes - 1)) + sizeof(T)
84 < TheISA::PageBytes);
85 ptr = p;
103 ptr = p;
104 refresh();
86
87 return *this;
88 }
89
90 template <class U>
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)
92 {
112 {
93 tc = vp.GetTC();
94 ptr = vp.GetPointer();
113 tc = vp.tc;
114 ptr = vp.ptr;
115 refresh();
95
96 return *this;
97 }
98
99 operator T *()
100 {
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;
105 }
106
123 }
124
107 T *operator->()
125 T *
126 operator->()
108 {
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;
113 }
114
129 }
130
115 T &operator*()
131 T &
132 operator*()
116 {
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;
121 }
122};
123
124#endif // __ARCH_ALPHA_VPTR_HH__
135 }
136};
137
138#endif // __ARCH_ALPHA_VPTR_HH__