gem5  v22.1.0.0
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 
46 namespace gem5
47 {
48 
49 namespace ruby
50 {
51 
53 {
54  m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
56  m_alloc = true;
57 }
58 
59 void
61 {
62  m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
63  m_alloc = true;
64  clear();
65 }
66 
67 void
69 {
71 }
72 
73 bool
74 DataBlock::equal(const DataBlock& obj) const
75 {
76  return !memcmp(m_data, obj.m_data, RubySystem::getBlockSizeBytes());
77 }
78 
79 void
81 {
82  for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
83  if (mask.getMask(i, 1)) {
84  m_data[i] = dblk.m_data[i];
85  }
86  }
87 }
88 
89 void
91 {
92  for (int i = 0; i < RubySystem::getBlockSizeBytes(); i++) {
93  m_data[i] = dblk.m_data[i];
94  }
95  mask.performAtomic(m_data);
96 }
97 
98 void
99 DataBlock::print(std::ostream& out) const
100 {
101  int size = RubySystem::getBlockSizeBytes();
102  out << "[ ";
103  for (int i = 0; i < size; i++) {
104  out << std::setw(2) << std::setfill('0') << std::hex
105  << "0x" << (int)m_data[i] << " " << std::setfill(' ');
106  }
107  out << std::dec << "]" << std::flush;
108 }
109 
110 const uint8_t*
112 {
114  return &m_data[offset];
115 }
116 
117 uint8_t*
119 {
120  return &m_data[offset];
121 }
122 
123 void
124 DataBlock::setData(const uint8_t *data, int offset, int len)
125 {
126  memcpy(&m_data[offset], data, len);
127 }
128 
129 void
131 {
132  int offset = getOffset(pkt->getAddr());
133  assert(offset + pkt->getSize() <= RubySystem::getBlockSizeBytes());
134  pkt->writeData(&m_data[offset]);
135 }
136 
137 DataBlock &
139 {
141  return *this;
142 }
143 
144 } // namespace ruby
145 } // namespace gem5
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Addr getAddr() const
Definition: packet.hh:805
unsigned getSize() const
Definition: packet.hh:815
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
Definition: packet.hh:1309
const uint8_t * getData(int offset, int len) const
Definition: DataBlock.cc:111
void copyPartial(const DataBlock &dblk, int offset, int len)
Definition: DataBlock.hh:123
uint8_t * getDataMod(int offset)
Definition: DataBlock.cc:118
DataBlock & operator=(const DataBlock &obj)
Definition: DataBlock.cc:138
bool equal(const DataBlock &obj) const
Definition: DataBlock.cc:74
void print(std::ostream &out) const
Definition: DataBlock.cc:99
void atomicPartial(const DataBlock &dblk, const WriteMask &mask)
Definition: DataBlock.cc:90
void setData(const uint8_t *data, int offset, int len)
Definition: DataBlock.cc:124
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:72
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
uint16_t len
Definition: helpers.cc:62
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Addr getOffset(Addr addr)
Definition: Address.cc:54
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1