gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DataBlock.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __MEM_RUBY_COMMON_DATABLOCK_HH__
42 #define __MEM_RUBY_COMMON_DATABLOCK_HH__
43 
44 #include <inttypes.h>
45 
46 #include <cassert>
47 #include <iomanip>
48 #include <iostream>
49 
50 #include "mem/packet.hh"
51 
52 class WriteMask;
53 
54 class DataBlock
55 {
56  public:
58  {
59  alloc();
60  }
61 
62  DataBlock(const DataBlock &cp);
63 
65  {
66  if (m_alloc)
67  delete [] m_data;
68  }
69 
70  DataBlock& operator=(const DataBlock& obj);
71 
72  void assign(uint8_t *data);
73 
74  void clear();
75  uint8_t getByte(int whichByte) const;
76  const uint8_t *getData(int offset, int len) const;
77  uint8_t *getDataMod(int offset);
78  void setByte(int whichByte, uint8_t data);
79  void setData(const uint8_t *data, int offset, int len);
80  void setData(PacketPtr pkt);
81  void copyPartial(const DataBlock &dblk, int offset, int len);
82  void copyPartial(const DataBlock &dblk, const WriteMask &mask);
83  void atomicPartial(const DataBlock & dblk, const WriteMask & mask);
84  bool equal(const DataBlock& obj) const;
85  void print(std::ostream& out) const;
86 
87  private:
88  void alloc();
89  uint8_t *m_data;
90  bool m_alloc;
91 };
92 
93 inline void
95 {
96  assert(data != NULL);
97  if (m_alloc) {
98  delete [] m_data;
99  }
100  m_data = data;
101  m_alloc = false;
102 }
103 
104 inline uint8_t
105 DataBlock::getByte(int whichByte) const
106 {
107  return m_data[whichByte];
108 }
109 
110 inline void
111 DataBlock::setByte(int whichByte, uint8_t data)
112 {
113  m_data[whichByte] = data;
114 }
115 
116 inline void
118 {
119  setData(&dblk.m_data[offset], offset, len);
120 }
121 
122 inline std::ostream&
123 operator<<(std::ostream& out, const DataBlock& obj)
124 {
125  obj.print(out);
126  out << std::flush;
127  return out;
128 }
129 
130 inline bool
131 operator==(const DataBlock& obj1,const DataBlock& obj2)
132 {
133  return obj1.equal(obj2);
134 }
135 
136 #endif // __MEM_RUBY_COMMON_DATABLOCK_HH__
data
const char data[]
Definition: circlebuf.test.cc:47
DataBlock::m_data
uint8_t * m_data
Definition: DataBlock.hh:89
DataBlock::setData
void setData(const uint8_t *data, int offset, int len)
Definition: DataBlock.cc:118
DataBlock::clear
void clear()
Definition: DataBlock.cc:62
DataBlock::m_alloc
bool m_alloc
Definition: DataBlock.hh:90
DataBlock::DataBlock
DataBlock()
Definition: DataBlock.hh:57
DataBlock
Definition: DataBlock.hh:54
packet.hh
DataBlock::operator=
DataBlock & operator=(const DataBlock &obj)
Definition: DataBlock.cc:132
cp
Definition: cprintf.cc:37
DataBlock::copyPartial
void copyPartial(const DataBlock &dblk, int offset, int len)
Definition: DataBlock.hh:117
DataBlock::setByte
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:111
DataBlock::getData
const uint8_t * getData(int offset, int len) const
Definition: DataBlock.cc:105
DataBlock::assign
void assign(uint8_t *data)
Definition: DataBlock.hh:94
DataBlock::alloc
void alloc()
Definition: DataBlock.cc:54
DataBlock::getByte
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:105
DataBlock::print
void print(std::ostream &out) const
Definition: DataBlock.cc:93
operator<<
std::ostream & operator<<(std::ostream &out, const DataBlock &obj)
Definition: DataBlock.hh:123
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
DataBlock::getDataMod
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:112
DataBlock::~DataBlock
~DataBlock()
Definition: DataBlock.hh:64
DataBlock::equal
bool equal(const DataBlock &obj) const
Definition: DataBlock.cc:68
WriteMask
Definition: WriteMask.hh:53
operator==
bool operator==(const DataBlock &obj1, const DataBlock &obj2)
Definition: DataBlock.hh:131
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
DataBlock::atomicPartial
void atomicPartial(const DataBlock &dblk, const WriteMask &mask)
Definition: DataBlock.cc:84
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17