summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/vptr.hh86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/sim/vptr.hh b/src/sim/vptr.hh
index bcc22f0ca..383f65351 100644
--- a/src/sim/vptr.hh
+++ b/src/sim/vptr.hh
@@ -33,6 +33,7 @@
#include "arch/vtophys.hh"
#include "arch/isa_traits.hh"
+#include "mem/vport.hh"
class ThreadContext;
@@ -42,82 +43,95 @@ class VPtr
public:
typedef T Type;
- private:
+ protected:
ThreadContext *tc;
Addr ptr;
+ Addr buffer[(sizeof(T)-1)/sizeof(Addr) + 1];
public:
- ThreadContext *GetTC() const { return tc; }
- Addr GetPointer() const { return ptr; }
+ explicit VPtr(ThreadContext *_tc, Addr p = 0)
+ : tc(_tc), ptr(p)
+ {
+ refresh();
+ }
- public:
- explicit VPtr(ThreadContext *_tc, Addr p = 0) : tc(_tc), ptr(p) { }
template <class U>
- VPtr(const VPtr<U> &vp) : tc(vp.GetTC()), ptr(vp.GetPointer()) {}
- ~VPtr() {}
+ VPtr(const VPtr<U> &vp)
+ : tc(vp.tc), ptr(vp.ptr)
+ {
+ refresh();
+ }
+
+ ~VPtr()
+ {}
- bool operator!() const
+ void
+ refresh()
{
- return ptr == 0;
+ if (!ptr)
+ return;
+
+ VirtualPort *port = tc->getVirtPort(tc);
+ port->readBlob(ptr, buffer, sizeof(T));
+ tc->delVirtPort(port);
}
- VPtr<T> operator+(int offset)
+ bool
+ operator!() const
{
- VPtr<T> ptr(*this);
- ptr += offset;
+ return ptr == 0;
+ }
- return ptr;
+ VPtr<T>
+ operator+(int offset)
+ {
+ return VPtr<T>(tc, ptr + offset);
}
- const VPtr<T> &operator+=(int offset)
+ const VPtr<T> &
+ operator+=(int offset)
{
ptr += offset;
- assert((ptr & (TheISA::PageBytes - 1)) + sizeof(T)
- < TheISA::PageBytes);
+ refresh();
return *this;
}
- const VPtr<T> &operator=(Addr p)
+ const VPtr<T> &
+ operator=(Addr p)
{
- assert((p & (TheISA::PageBytes - 1)) + sizeof(T)
- < TheISA::PageBytes);
ptr = p;
+ refresh();
return *this;
}
template <class U>
- const VPtr<T> &operator=(const VPtr<U> &vp)
+ const VPtr<T> &
+ operator=(const VPtr<U> &vp)
{
- tc = vp.GetTC();
- ptr = vp.GetPointer();
+ tc = vp.tc;
+ ptr = vp.ptr;
+ refresh();
return *this;
}
operator T *()
{
- panic("Needs to be rewritten\n");
-/* void *addr = vtomem(tc, ptr, sizeof(T));
- return (T *)addr;
- */
+ return (T *)buffer;
}
- T *operator->()
+ T *
+ operator->()
{
- panic("Needs to be rewritten\n");
-/* void *addr = vtomem(tc, ptr, sizeof(T));
- return (T *)addr;
- */
+ return (T *)buffer;
}
- T &operator*()
+ T &
+ operator*()
{
- panic("Needs to be rewritten\n");
-/* void *addr = vtomem(tc, ptr, sizeof(T));
- return *(T *)addr;
- */
+ return *(T *)buffer;
}
};