packet.cc (8436:5648986156db) packet.cc (8668:be72c2a127b2)
1/*
1/*
2 * Copyright (c) 2011 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 *
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * Copyright (c) 2010 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Ali Saidi
30 * Steve Reinhardt
31 */
32
33/**
34 * @file
35 * Definition of the Packet Class, a packet is a transaction occuring
36 * between a single level of the memory heirarchy (ie L1->L2).
37 */
38
39#include <cstring>
40#include <iostream>
41
42#include "base/cprintf.hh"
43#include "base/misc.hh"
44#include "base/trace.hh"
45#include "mem/packet.hh"
46
47using namespace std;
48
49// The one downside to bitsets is that static initializers can get ugly.
50#define SET1(a1) (1 << (a1))
51#define SET2(a1, a2) (SET1(a1) | SET1(a2))
52#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
53#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
54#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
55#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
56
57const MemCmd::CommandInfo
58MemCmd::commandInfo[] =
59{
60 /* InvalidCmd */
61 { 0, InvalidCmd, "InvalidCmd" },
62 /* ReadReq */
63 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
64 /* ReadResp */
65 { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
66 /* ReadRespWithInvalidate */
67 { SET4(IsRead, IsResponse, HasData, IsInvalidate),
68 InvalidCmd, "ReadRespWithInvalidate" },
69 /* WriteReq */
70 { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
71 WriteResp, "WriteReq" },
72 /* WriteResp */
73 { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
74 /* Writeback */
75 { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
76 InvalidCmd, "Writeback" },
77 /* SoftPFReq */
78 { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
79 SoftPFResp, "SoftPFReq" },
80 /* HardPFReq */
81 { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
82 HardPFResp, "HardPFReq" },
83 /* SoftPFResp */
84 { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
85 InvalidCmd, "SoftPFResp" },
86 /* HardPFResp */
87 { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
88 InvalidCmd, "HardPFResp" },
89 /* WriteInvalidateReq */
90 { SET6(IsWrite, NeedsExclusive, IsInvalidate,
91 IsRequest, HasData, NeedsResponse),
92 WriteInvalidateResp, "WriteInvalidateReq" },
93 /* WriteInvalidateResp */
94 { SET3(IsWrite, NeedsExclusive, IsResponse),
95 InvalidCmd, "WriteInvalidateResp" },
96 /* UpgradeReq */
97 { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
98 UpgradeResp, "UpgradeReq" },
99 /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
100 { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
101 IsRequest, NeedsResponse),
102 UpgradeResp, "SCUpgradeReq" },
103 /* UpgradeResp */
104 { SET3(NeedsExclusive, IsUpgrade, IsResponse),
105 InvalidCmd, "UpgradeResp" },
106 /* SCUpgradeFailReq: generates UpgradeFailResp ASAP */
107 { SET5(IsInvalidate, NeedsExclusive, IsLlsc,
108 IsRequest, NeedsResponse),
109 UpgradeFailResp, "SCUpgradeFailReq" },
110 /* UpgradeFailResp */
111 { SET2(NeedsExclusive, IsResponse),
112 InvalidCmd, "UpgradeFailResp" },
113 /* ReadExReq */
114 { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
115 ReadExResp, "ReadExReq" },
116 /* ReadExResp */
117 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
118 InvalidCmd, "ReadExResp" },
119 /* LoadLockedReq: note that we use plain ReadResp as response, so that
120 * we can also use ReadRespWithInvalidate when needed */
121 { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
122 ReadResp, "LoadLockedReq" },
123 /* StoreCondReq */
124 { SET6(IsWrite, NeedsExclusive, IsLlsc,
125 IsRequest, NeedsResponse, HasData),
126 StoreCondResp, "StoreCondReq" },
127 /* StoreCondFailReq: generates failing StoreCondResp ASAP */
128 { SET6(IsWrite, NeedsExclusive, IsLlsc,
129 IsRequest, NeedsResponse, HasData),
130 StoreCondResp, "StoreCondFailReq" },
131 /* StoreCondResp */
132 { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
133 InvalidCmd, "StoreCondResp" },
134 /* SwapReq -- for Swap ldstub type operations */
135 { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
136 SwapResp, "SwapReq" },
137 /* SwapResp -- for Swap ldstub type operations */
138 { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
139 InvalidCmd, "SwapResp" },
140 /* IntReq -- for interrupts */
141 { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
142 MessageResp, "MessageReq" },
143 /* IntResp -- for interrupts */
144 { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
145 /* NetworkNackError -- nacked at network layer (not by protocol) */
146 { SET2(IsResponse, IsError), InvalidCmd, "NetworkNackError" },
147 /* InvalidDestError -- packet dest field invalid */
148 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
149 /* BadAddressError -- memory address invalid */
150 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
151 /* FunctionalReadError */
152 { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
153 /* FunctionalWriteError */
154 { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
155 /* PrintReq */
156 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
157 /* Flush Request */
158 { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
159};
160
161bool
162Packet::checkFunctional(Printable *obj, Addr addr, int size, uint8_t *data)
163{
164 Addr func_start = getAddr();
165 Addr func_end = getAddr() + getSize() - 1;
166 Addr val_start = addr;
167 Addr val_end = val_start + size - 1;
168
169 if (func_start > val_end || val_start > func_end) {
170 // no intersection
171 return false;
172 }
173
174 // check print first since it doesn't require data
175 if (isPrint()) {
176 dynamic_cast<PrintReqState*>(senderState)->printObj(obj);
177 return false;
178 }
179
180 // if there's no data, there's no need to look further
181 if (!data) {
182 return false;
183 }
184
185 // offset of functional request into supplied value (could be
186 // negative if partial overlap)
187 int offset = func_start - val_start;
188
189 if (isRead()) {
190 if (func_start >= val_start && func_end <= val_end) {
191 allocate();
192 memcpy(getPtr<uint8_t>(), data + offset, getSize());
193 return true;
194 } else {
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2010 Advanced Micro Devices, Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Ali Saidi
42 * Steve Reinhardt
43 */
44
45/**
46 * @file
47 * Definition of the Packet Class, a packet is a transaction occuring
48 * between a single level of the memory heirarchy (ie L1->L2).
49 */
50
51#include <cstring>
52#include <iostream>
53
54#include "base/cprintf.hh"
55#include "base/misc.hh"
56#include "base/trace.hh"
57#include "mem/packet.hh"
58
59using namespace std;
60
61// The one downside to bitsets is that static initializers can get ugly.
62#define SET1(a1) (1 << (a1))
63#define SET2(a1, a2) (SET1(a1) | SET1(a2))
64#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
65#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
66#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
67#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
68
69const MemCmd::CommandInfo
70MemCmd::commandInfo[] =
71{
72 /* InvalidCmd */
73 { 0, InvalidCmd, "InvalidCmd" },
74 /* ReadReq */
75 { SET3(IsRead, IsRequest, NeedsResponse), ReadResp, "ReadReq" },
76 /* ReadResp */
77 { SET3(IsRead, IsResponse, HasData), InvalidCmd, "ReadResp" },
78 /* ReadRespWithInvalidate */
79 { SET4(IsRead, IsResponse, HasData, IsInvalidate),
80 InvalidCmd, "ReadRespWithInvalidate" },
81 /* WriteReq */
82 { SET5(IsWrite, NeedsExclusive, IsRequest, NeedsResponse, HasData),
83 WriteResp, "WriteReq" },
84 /* WriteResp */
85 { SET3(IsWrite, NeedsExclusive, IsResponse), InvalidCmd, "WriteResp" },
86 /* Writeback */
87 { SET4(IsWrite, NeedsExclusive, IsRequest, HasData),
88 InvalidCmd, "Writeback" },
89 /* SoftPFReq */
90 { SET4(IsRead, IsRequest, IsSWPrefetch, NeedsResponse),
91 SoftPFResp, "SoftPFReq" },
92 /* HardPFReq */
93 { SET4(IsRead, IsRequest, IsHWPrefetch, NeedsResponse),
94 HardPFResp, "HardPFReq" },
95 /* SoftPFResp */
96 { SET4(IsRead, IsResponse, IsSWPrefetch, HasData),
97 InvalidCmd, "SoftPFResp" },
98 /* HardPFResp */
99 { SET4(IsRead, IsResponse, IsHWPrefetch, HasData),
100 InvalidCmd, "HardPFResp" },
101 /* WriteInvalidateReq */
102 { SET6(IsWrite, NeedsExclusive, IsInvalidate,
103 IsRequest, HasData, NeedsResponse),
104 WriteInvalidateResp, "WriteInvalidateReq" },
105 /* WriteInvalidateResp */
106 { SET3(IsWrite, NeedsExclusive, IsResponse),
107 InvalidCmd, "WriteInvalidateResp" },
108 /* UpgradeReq */
109 { SET5(IsInvalidate, NeedsExclusive, IsUpgrade, IsRequest, NeedsResponse),
110 UpgradeResp, "UpgradeReq" },
111 /* SCUpgradeReq: response could be UpgradeResp or UpgradeFailResp */
112 { SET6(IsInvalidate, NeedsExclusive, IsUpgrade, IsLlsc,
113 IsRequest, NeedsResponse),
114 UpgradeResp, "SCUpgradeReq" },
115 /* UpgradeResp */
116 { SET3(NeedsExclusive, IsUpgrade, IsResponse),
117 InvalidCmd, "UpgradeResp" },
118 /* SCUpgradeFailReq: generates UpgradeFailResp ASAP */
119 { SET5(IsInvalidate, NeedsExclusive, IsLlsc,
120 IsRequest, NeedsResponse),
121 UpgradeFailResp, "SCUpgradeFailReq" },
122 /* UpgradeFailResp */
123 { SET2(NeedsExclusive, IsResponse),
124 InvalidCmd, "UpgradeFailResp" },
125 /* ReadExReq */
126 { SET5(IsRead, NeedsExclusive, IsInvalidate, IsRequest, NeedsResponse),
127 ReadExResp, "ReadExReq" },
128 /* ReadExResp */
129 { SET4(IsRead, NeedsExclusive, IsResponse, HasData),
130 InvalidCmd, "ReadExResp" },
131 /* LoadLockedReq: note that we use plain ReadResp as response, so that
132 * we can also use ReadRespWithInvalidate when needed */
133 { SET4(IsRead, IsLlsc, IsRequest, NeedsResponse),
134 ReadResp, "LoadLockedReq" },
135 /* StoreCondReq */
136 { SET6(IsWrite, NeedsExclusive, IsLlsc,
137 IsRequest, NeedsResponse, HasData),
138 StoreCondResp, "StoreCondReq" },
139 /* StoreCondFailReq: generates failing StoreCondResp ASAP */
140 { SET6(IsWrite, NeedsExclusive, IsLlsc,
141 IsRequest, NeedsResponse, HasData),
142 StoreCondResp, "StoreCondFailReq" },
143 /* StoreCondResp */
144 { SET4(IsWrite, NeedsExclusive, IsLlsc, IsResponse),
145 InvalidCmd, "StoreCondResp" },
146 /* SwapReq -- for Swap ldstub type operations */
147 { SET6(IsRead, IsWrite, NeedsExclusive, IsRequest, HasData, NeedsResponse),
148 SwapResp, "SwapReq" },
149 /* SwapResp -- for Swap ldstub type operations */
150 { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData),
151 InvalidCmd, "SwapResp" },
152 /* IntReq -- for interrupts */
153 { SET4(IsWrite, IsRequest, NeedsResponse, HasData),
154 MessageResp, "MessageReq" },
155 /* IntResp -- for interrupts */
156 { SET2(IsWrite, IsResponse), InvalidCmd, "MessageResp" },
157 /* NetworkNackError -- nacked at network layer (not by protocol) */
158 { SET2(IsResponse, IsError), InvalidCmd, "NetworkNackError" },
159 /* InvalidDestError -- packet dest field invalid */
160 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
161 /* BadAddressError -- memory address invalid */
162 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
163 /* FunctionalReadError */
164 { SET3(IsRead, IsResponse, IsError), InvalidCmd, "FunctionalReadError" },
165 /* FunctionalWriteError */
166 { SET3(IsWrite, IsResponse, IsError), InvalidCmd, "FunctionalWriteError" },
167 /* PrintReq */
168 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" },
169 /* Flush Request */
170 { SET3(IsRequest, IsFlush, NeedsExclusive), InvalidCmd, "FlushReq" },
171};
172
173bool
174Packet::checkFunctional(Printable *obj, Addr addr, int size, uint8_t *data)
175{
176 Addr func_start = getAddr();
177 Addr func_end = getAddr() + getSize() - 1;
178 Addr val_start = addr;
179 Addr val_end = val_start + size - 1;
180
181 if (func_start > val_end || val_start > func_end) {
182 // no intersection
183 return false;
184 }
185
186 // check print first since it doesn't require data
187 if (isPrint()) {
188 dynamic_cast<PrintReqState*>(senderState)->printObj(obj);
189 return false;
190 }
191
192 // if there's no data, there's no need to look further
193 if (!data) {
194 return false;
195 }
196
197 // offset of functional request into supplied value (could be
198 // negative if partial overlap)
199 int offset = func_start - val_start;
200
201 if (isRead()) {
202 if (func_start >= val_start && func_end <= val_end) {
203 allocate();
204 memcpy(getPtr<uint8_t>(), data + offset, getSize());
205 return true;
206 } else {
195 // In this case the timing packet only partially satisfies
196 // the request, so we would need more information to make
197 // this work. Like bytes valid in the packet or
198 // something, so the request could continue and get this
199 // bit of possibly newer data along with the older data
200 // not written to yet.
201 panic("Memory value only partially satisfies the functional "
202 "request. Now what?");
207 // Offsets and sizes to copy in case of partial overlap
208 int func_offset;
209 int val_offset;
210 int overlap_size;
211
212 // calculate offsets and copy sizes for the two byte arrays
213 if (val_start < func_start && val_end <= func_end) {
214 val_offset = func_start - val_start;
215 func_offset = 0;
216 overlap_size = val_end - func_start;
217 } else if (val_start >= func_start && val_end > func_end) {
218 val_offset = 0;
219 func_offset = val_start - func_start;
220 overlap_size = func_end - val_start;
221 } else if (val_start >= func_start && val_end <= func_end) {
222 val_offset = 0;
223 func_offset = val_start - func_start;
224 overlap_size = size;
225 } else {
226 panic("BUG: Missed a case for a partial functional request");
227 }
228
229 // Figure out how much of the partial overlap should be copied
230 // into the packet and not overwrite previously found bytes.
231 if (bytesValidStart == 0 && bytesValidEnd == 0) {
232 // No bytes have been copied yet, just set indices
233 // to found range
234 bytesValidStart = func_offset;
235 bytesValidEnd = func_offset + overlap_size;
236 } else {
237 // Some bytes have already been copied. Use bytesValid
238 // indices and offset values to figure out how much data
239 // to copy and where to copy it to.
240
241 // Indice overlap conditions to check
242 int a = func_offset - bytesValidStart;
243 int b = (func_offset + overlap_size) - bytesValidEnd;
244 int c = func_offset - bytesValidEnd;
245 int d = (func_offset + overlap_size) - bytesValidStart;
246
247 if (a >= 0 && b <= 0) {
248 // bytes already in pkt data array are superset of
249 // found bytes, will not copy any bytes
250 overlap_size = 0;
251 } else if (a < 0 && d >= 0 && b <= 0) {
252 // found bytes will move bytesValidStart towards 0
253 overlap_size = bytesValidStart - func_offset;
254 bytesValidStart = func_offset;
255 } else if (b > 0 && c <= 0 && a >= 0) {
256 // found bytes will move bytesValidEnd
257 // towards end of pkt data array
258 overlap_size =
259 (func_offset + overlap_size) - bytesValidEnd;
260 val_offset += bytesValidEnd - func_offset;
261 func_offset = bytesValidEnd;
262 bytesValidEnd += overlap_size;
263 } else if (a < 0 && b > 0) {
264 // Found bytes are superset of copied range. Will move
265 // bytesValidStart towards 0 and bytesValidEnd towards
266 // end of pkt data array. Need to break copy into two
267 // pieces so as to not overwrite previously found data.
268
269 // copy the first half
270 uint8_t *dest = getPtr<uint8_t>() + func_offset;
271 uint8_t *src = data + val_offset;
272 memcpy(dest, src, (bytesValidStart - func_offset));
273
274 // re-calc the offsets and indices to do the copy
275 // required for the second half
276 val_offset += (bytesValidEnd - func_offset);
277 bytesValidStart = func_offset;
278 overlap_size =
279 (func_offset + overlap_size) - bytesValidEnd;
280 func_offset = bytesValidEnd;
281 bytesValidEnd += overlap_size;
282 } else if ((c > 0 && b > 0)
283 || (a < 0 && d < 0)) {
284 // region to be copied is discontiguous! Not supported.
285 panic("BUG: Discontiguous bytes found"
286 "for functional copying!");
287 }
288 }
289
290 assert((bytesValidStart >= 0) && (bytesValidEnd <= getSize()));
291
292 // copy partial data into the packet's data array
293 uint8_t *dest = getPtr<uint8_t>() + func_offset;
294 uint8_t *src = data + val_offset;
295 memcpy(dest, src, overlap_size);
296
297 // check if we're done filling the functional access
298 bool done = (bytesValidStart == 0) && (bytesValidEnd == getSize());
299 return done;
203 }
204 } else if (isWrite()) {
205 if (offset >= 0) {
206 memcpy(data + offset, getPtr<uint8_t>(),
207 (min(func_end, val_end) - func_start) + 1);
208 } else {
209 // val_start > func_start
210 memcpy(data, getPtr<uint8_t>() - offset,
211 (min(func_end, val_end) - val_start) + 1);
212 }
213 } else {
214 panic("Don't know how to handle command %s\n", cmdString());
215 }
216
217 // keep going with request by default
218 return false;
219}
220
221void
222Packet::print(ostream &o, const int verbosity, const string &prefix) const
223{
224 ccprintf(o, "%s[%x:%x] %s\n", prefix,
225 getAddr(), getAddr() + getSize() - 1, cmdString());
226}
227
228Packet::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
229 : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
230{
231 labelStack.push_back(LabelStackEntry("", curPrefixPtr));
232}
233
234Packet::PrintReqState::~PrintReqState()
235{
236 labelStack.pop_back();
237 assert(labelStack.empty());
238 delete curPrefixPtr;
239}
240
241Packet::PrintReqState::
242LabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
243 : label(_label), prefix(_prefix), labelPrinted(false)
244{
245}
246
247void
248Packet::PrintReqState::pushLabel(const string &lbl, const string &prefix)
249{
250 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
251 curPrefixPtr = new string(*curPrefixPtr);
252 *curPrefixPtr += prefix;
253}
254
255void
256Packet::PrintReqState::popLabel()
257{
258 delete curPrefixPtr;
259 curPrefixPtr = labelStack.back().prefix;
260 labelStack.pop_back();
261 assert(!labelStack.empty());
262}
263
264void
265Packet::PrintReqState::printLabels()
266{
267 if (!labelStack.back().labelPrinted) {
268 LabelStack::iterator i = labelStack.begin();
269 LabelStack::iterator end = labelStack.end();
270 while (i != end) {
271 if (!i->labelPrinted) {
272 ccprintf(os, "%s%s\n", *(i->prefix), i->label);
273 i->labelPrinted = true;
274 }
275 i++;
276 }
277 }
278}
279
280
281void
282Packet::PrintReqState::printObj(Printable *obj)
283{
284 printLabels();
285 obj->print(os, verbosity, curPrefix());
286}
300 }
301 } else if (isWrite()) {
302 if (offset >= 0) {
303 memcpy(data + offset, getPtr<uint8_t>(),
304 (min(func_end, val_end) - func_start) + 1);
305 } else {
306 // val_start > func_start
307 memcpy(data, getPtr<uint8_t>() - offset,
308 (min(func_end, val_end) - val_start) + 1);
309 }
310 } else {
311 panic("Don't know how to handle command %s\n", cmdString());
312 }
313
314 // keep going with request by default
315 return false;
316}
317
318void
319Packet::print(ostream &o, const int verbosity, const string &prefix) const
320{
321 ccprintf(o, "%s[%x:%x] %s\n", prefix,
322 getAddr(), getAddr() + getSize() - 1, cmdString());
323}
324
325Packet::PrintReqState::PrintReqState(ostream &_os, int _verbosity)
326 : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity)
327{
328 labelStack.push_back(LabelStackEntry("", curPrefixPtr));
329}
330
331Packet::PrintReqState::~PrintReqState()
332{
333 labelStack.pop_back();
334 assert(labelStack.empty());
335 delete curPrefixPtr;
336}
337
338Packet::PrintReqState::
339LabelStackEntry::LabelStackEntry(const string &_label, string *_prefix)
340 : label(_label), prefix(_prefix), labelPrinted(false)
341{
342}
343
344void
345Packet::PrintReqState::pushLabel(const string &lbl, const string &prefix)
346{
347 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
348 curPrefixPtr = new string(*curPrefixPtr);
349 *curPrefixPtr += prefix;
350}
351
352void
353Packet::PrintReqState::popLabel()
354{
355 delete curPrefixPtr;
356 curPrefixPtr = labelStack.back().prefix;
357 labelStack.pop_back();
358 assert(!labelStack.empty());
359}
360
361void
362Packet::PrintReqState::printLabels()
363{
364 if (!labelStack.back().labelPrinted) {
365 LabelStack::iterator i = labelStack.begin();
366 LabelStack::iterator end = labelStack.end();
367 while (i != end) {
368 if (!i->labelPrinted) {
369 ccprintf(os, "%s%s\n", *(i->prefix), i->label);
370 i->labelPrinted = true;
371 }
372 i++;
373 }
374 }
375}
376
377
378void
379Packet::PrintReqState::printObj(Printable *obj)
380{
381 printLabels();
382 obj->print(os, verbosity, curPrefix());
383}