gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DataBlock.cc
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 
42 
45 
47 {
48  m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
49  memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes());
50  m_alloc = true;
51 }
52 
53 void
55 {
56  m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
57  m_alloc = true;
58  clear();
59 }
60 
61 void
63 {
65 }
66 
67 bool
68 DataBlock::equal(const DataBlock& obj) const
69 {
70  return !memcmp(m_data, obj.m_data, RubySystem::getBlockSizeBytes());
71 }
72 
73 void
75 {
76  for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
77  if (mask.getMask(i, 1)) {
78  m_data[i] = dblk.m_data[i];
79  }
80  }
81 }
82 
83 void
85 {
86  for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
87  m_data[i] = dblk.m_data[i];
88  }
89  mask.performAtomic(m_data);
90 }
91 
92 void
93 DataBlock::print(std::ostream& out) const
94 {
95  int size = RubySystem::getBlockSizeBytes();
96  out << "[ ";
97  for (int i = 0; i < size; i++) {
98  out << std::setw(2) << std::setfill('0') << std::hex
99  << "0x" << (int)m_data[i] << " " << std::setfill(' ');
100  }
101  out << std::dec << "]" << std::flush;
102 }
103 
104 const uint8_t*
106 {
108  return &m_data[offset];
109 }
110 
111 uint8_t*
113 {
114  return &m_data[offset];
115 }
116 
117 void
118 DataBlock::setData(const uint8_t *data, int offset, int len)
119 {
120  memcpy(&m_data[offset], data, len);
121 }
122 
123 void
125 {
126  int offset = getOffset(pkt->getAddr());
127  assert(offset + pkt->getSize() <= RubySystem::getBlockSizeBytes());
128  pkt->writeData(&m_data[offset]);
129 }
130 
131 DataBlock &
133 {
135  return *this;
136 }
RubySystem::getBlockSizeBytes
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:61
data
const char data[]
Definition: circlebuf.test.cc:47
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
Packet::writeData
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
Definition: packet.hh:1255
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
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
Packet::getSize
unsigned getSize() const
Definition: packet.hh:765
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
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::getData
const uint8_t * getData(int offset, int len) const
Definition: DataBlock.cc:105
DataBlock.hh
WriteMask.hh
RubySystem.hh
DataBlock::alloc
void alloc()
Definition: DataBlock.cc:54
DataBlock::print
void print(std::ostream &out) const
Definition: DataBlock.cc:93
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
getOffset
Addr getOffset(Addr addr)
Definition: Address.cc:48
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
DataBlock::getDataMod
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:112
DataBlock::equal
bool equal(const DataBlock &obj) const
Definition: DataBlock.cc:68
WriteMask
Definition: WriteMask.hh:53
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 Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17