summaryrefslogtreecommitdiff
path: root/src/mem/ruby/system/MemoryVector.hh
blob: c5f3cea7f47cc48da1e265bc079857d5b1d4ed02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

#ifndef MEMORYVECTOR_H
#define MEMORYVECTOR_H

#include "mem/ruby/common/Address.hh"

class DirectoryMemory;

/**
 *  MemoryVector holds memory data (DRAM only)
 */
class MemoryVector {
 public:
  MemoryVector();
  MemoryVector(uint32 size);
  ~MemoryVector();
  friend class DirectoryMemory;

  void setSize(uint32 size);  // destructive

  void write(const Address & paddr, uint8* data, int len);
  uint8* read(const Address & paddr, uint8* data, int len);

 private:
  uint8* getBlockPtr(const Address & paddr);

  uint32 m_size;
  uint8* m_vec;
};

inline
MemoryVector::MemoryVector()
{
  m_size = 0;
  m_vec = NULL;
}

inline
MemoryVector::MemoryVector(uint32 size)
{
  m_size = size;
  m_vec = new uint8[size];
}

inline
MemoryVector::~MemoryVector()
{
  delete [] m_vec;
}

inline
void MemoryVector::setSize(uint32 size)
{
  m_size = size;
  if (m_vec != NULL)
    delete [] m_vec;
  m_vec = new uint8[size];
}

inline
void MemoryVector::write(const Address & paddr, uint8* data, int len)
{
  assert(paddr.getAddress() + len <= m_size);
  memcpy(m_vec + paddr.getAddress(), data, len);
}

inline
uint8* MemoryVector::read(const Address & paddr, uint8* data, int len)
{
  assert(paddr.getAddress() + len <= m_size);
  memcpy(data, m_vec + paddr.getAddress(), len);
  return data;
}

inline
uint8* MemoryVector::getBlockPtr(const Address & paddr)
{
  return m_vec + paddr.getAddress();
}

#endif // MEMORYVECTOR_H