Deleted Added
sdiff udiff text old ( 5650:d2782c951841 ) new ( 5735:a88e8e7dec75 )
full compact
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 28 unchanged lines hidden (view full) ---

37
38#include <iostream>
39#include <cstring>
40#include "base/cprintf.hh"
41#include "base/misc.hh"
42#include "base/trace.hh"
43#include "mem/packet.hh"
44
45// The one downside to bitsets is that static initializers can get ugly.
46#define SET1(a1) (1 << (a1))
47#define SET2(a1, a2) (SET1(a1) | SET1(a2))
48#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3))
49#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4))
50#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5))
51#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6))
52

--- 75 unchanged lines hidden (view full) ---

128 /* InvalidDestError -- packet dest field invalid */
129 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" },
130 /* BadAddressError -- memory address invalid */
131 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" },
132 /* PrintReq */
133 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" }
134};
135
136
137/** delete the data pointed to in the data pointer. Ok to call to matter how
138 * data was allocted. */
139void
140Packet::deleteData()
141{
142 assert(staticData || dynamicData);
143 if (staticData)
144 return;
145
146 if (arrayData)
147 delete [] data;
148 else
149 delete data;
150}
151
152/** If there isn't data in the packet, allocate some. */
153void
154Packet::allocate()
155{
156 if (data)
157 return;
158 assert(!staticData);
159 dynamicData = true;
160 arrayData = true;
161 data = new uint8_t[getSize()];
162}
163
164
165bool
166Packet::checkFunctional(Printable *obj, Addr addr, int size, uint8_t *data)
167{
168 Addr func_start = getAddr();
169 Addr func_end = getAddr() + getSize() - 1;
170 Addr val_start = addr;
171 Addr val_end = val_start + size - 1;
172

--- 15 unchanged lines hidden (view full) ---

188
189 // offset of functional request into supplied value (could be
190 // negative if partial overlap)
191 int offset = func_start - val_start;
192
193 if (isRead()) {
194 if (func_start >= val_start && func_end <= val_end) {
195 allocate();
196 std::memcpy(getPtr<uint8_t>(), data + offset, getSize());
197 makeResponse();
198 return true;
199 } else {
200 // In this case the timing packet only partially satisfies
201 // the request, so we would need more information to make
202 // this work. Like bytes valid in the packet or
203 // something, so the request could continue and get this
204 // bit of possibly newer data along with the older data
205 // not written to yet.
206 panic("Memory value only partially satisfies the functional "
207 "request. Now what?");
208 }
209 } else if (isWrite()) {
210 if (offset >= 0) {
211 std::memcpy(data + offset, getPtr<uint8_t>(),
212 (std::min(func_end, val_end) - func_start) + 1);
213 } else { // val_start > func_start
214 std::memcpy(data, getPtr<uint8_t>() - offset,
215 (std::min(func_end, val_end) - val_start) + 1);
216 }
217 } else {
218 panic("Don't know how to handle command %s\n", cmdString());
219 }
220
221 // keep going with request by default
222 return false;
223}
224
225
226void
227Packet::print(std::ostream &o, const int verbosity,
228 const std::string &prefix) const
229{
230 ccprintf(o, "%s[%x:%x] %s\n", prefix,
231 getAddr(), getAddr() + getSize() - 1, cmdString());
232}
233
234
235Packet::PrintReqState::PrintReqState(std::ostream &_os, int _verbosity)
236 : curPrefixPtr(new std::string("")), os(_os), verbosity(_verbosity)
237{
238 labelStack.push_back(LabelStackEntry("", curPrefixPtr));
239}
240
241
242Packet::PrintReqState::~PrintReqState()
243{
244 labelStack.pop_back();
245 assert(labelStack.empty());
246 delete curPrefixPtr;
247}
248
249
250Packet::PrintReqState::
251LabelStackEntry::LabelStackEntry(const std::string &_label,
252 std::string *_prefix)
253 : label(_label), prefix(_prefix), labelPrinted(false)
254{
255}
256
257
258void
259Packet::PrintReqState::pushLabel(const std::string &lbl,
260 const std::string &prefix)
261{
262 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr));
263 curPrefixPtr = new std::string(*curPrefixPtr);
264 *curPrefixPtr += prefix;
265}
266
267void
268Packet::PrintReqState::popLabel()
269{
270 delete curPrefixPtr;
271 curPrefixPtr = labelStack.back().prefix;

--- 27 unchanged lines hidden ---