gem5  v22.1.0.0
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 namespace gem5
53 {
54 
55 namespace ruby
56 {
57 
58 class WriteMask;
59 
60 class DataBlock
61 {
62  public:
64  {
65  alloc();
66  }
67 
68  DataBlock(const DataBlock &cp);
69 
71  {
72  if (m_alloc)
73  delete [] m_data;
74  }
75 
76  DataBlock& operator=(const DataBlock& obj);
77 
78  void assign(uint8_t *data);
79 
80  void clear();
81  uint8_t getByte(int whichByte) const;
82  const uint8_t *getData(int offset, int len) const;
83  uint8_t *getDataMod(int offset);
84  void setByte(int whichByte, uint8_t data);
85  void setData(const uint8_t *data, int offset, int len);
86  void setData(PacketPtr pkt);
87  void copyPartial(const DataBlock &dblk, int offset, int len);
88  void copyPartial(const DataBlock &dblk, const WriteMask &mask);
89  void atomicPartial(const DataBlock & dblk, const WriteMask & mask);
90  bool equal(const DataBlock& obj) const;
91  void print(std::ostream& out) const;
92 
93  private:
94  void alloc();
95  uint8_t *m_data;
96  bool m_alloc;
97 };
98 
99 inline void
101 {
102  assert(data != NULL);
103  if (m_alloc) {
104  delete [] m_data;
105  }
106  m_data = data;
107  m_alloc = false;
108 }
109 
110 inline uint8_t
111 DataBlock::getByte(int whichByte) const
112 {
113  return m_data[whichByte];
114 }
115 
116 inline void
117 DataBlock::setByte(int whichByte, uint8_t data)
118 {
119  m_data[whichByte] = data;
120 }
121 
122 inline void
124 {
125  setData(&dblk.m_data[offset], offset, len);
126 }
127 
128 inline std::ostream&
129 operator<<(std::ostream& out, const DataBlock& obj)
130 {
131  obj.print(out);
132  out << std::flush;
133  return out;
134 }
135 
136 inline bool
137 operator==(const DataBlock& obj1,const DataBlock& obj2)
138 {
139  return obj1.equal(obj2);
140 }
141 
142 } // namespace ruby
143 } // namespace gem5
144 
145 #endif // __MEM_RUBY_COMMON_DATABLOCK_HH__
const char data[]
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:111
void assign(uint8_t *data)
Definition: DataBlock.hh:100
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 setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:117
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
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< 23, 0 > offset
Definition: types.hh:144
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
bool operator==(const DataBlock &obj1, const DataBlock &obj2)
Definition: DataBlock.hh:137
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Declaration of the Packet class.

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