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; --- 23 unchanged lines hidden (view full) --- 32/** 33 * @file 34 * Definition of the Packet Class, a packet is a transaction occuring 35 * between a single level of the memory heirarchy (ie L1->L2). 36 */ 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)) --- 68 unchanged lines hidden (view full) --- 117 /* SwapResp -- for Swap ldstub type operations */ 118 { SET5(IsRead, IsWrite, NeedsExclusive, IsResponse, HasData), 119 InvalidCmd, "SwapResp" }, 120 /* NetworkNackError -- nacked at network layer (not by protocol) */ 121 { SET2(IsResponse, IsError), InvalidCmd, "NetworkNackError" }, 122 /* InvalidDestError -- packet dest field invalid */ 123 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" }, 124 /* BadAddressError -- memory address invalid */ |
125 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" }, 126 /* PrintReq */ 127 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" } |
128}; 129 130 131/** delete the data pointed to in the data pointer. Ok to call to matter how 132 * data was allocted. */ 133void 134Packet::deleteData() 135{ --- 16 unchanged lines hidden (view full) --- 152 assert(!staticData); 153 dynamicData = true; 154 arrayData = true; 155 data = new uint8_t[getSize()]; 156} 157 158 159bool |
160Packet::checkFunctional(Printable *obj, Addr addr, int size, uint8_t *data) |
161{ 162 Addr func_start = getAddr(); 163 Addr func_end = getAddr() + getSize() - 1; 164 Addr val_start = addr; 165 Addr val_end = val_start + size - 1; 166 167 if (func_start > val_end || val_start > func_end) { 168 // no intersection 169 return false; 170 } 171 |
172 // check print first since it doesn't require data 173 if (isPrint()) { 174 dynamic_cast<PrintReqState*>(senderState)->printObj(obj); 175 return false; 176 } 177 178 // if there's no data, there's no need to look further 179 if (!data) { 180 return false; 181 } 182 |
183 // offset of functional request into supplied value (could be 184 // negative if partial overlap) 185 int offset = func_start - val_start; 186 187 if (isRead()) { 188 if (func_start >= val_start && func_end <= val_end) { 189 allocate(); 190 std::memcpy(getPtr<uint8_t>(), data + offset, getSize()); --- 12 unchanged lines hidden (view full) --- 203 } else if (isWrite()) { 204 if (offset >= 0) { 205 std::memcpy(data + offset, getPtr<uint8_t>(), 206 (std::min(func_end, val_end) - func_start) + 1); 207 } else { // val_start > func_start 208 std::memcpy(data, getPtr<uint8_t>() - offset, 209 (std::min(func_end, val_end) - val_start) + 1); 210 } |
211 } else { |
212 panic("Don't know how to handle command %s\n", cmdString()); |
213 } 214 215 // keep going with request by default 216 return false; |
217} 218 219 |
220void 221Packet::print(std::ostream &o, const int verbosity, 222 const std::string &prefix) const |
223{ |
224 ccprintf(o, "%s[%x:%x] %s\n", prefix, 225 getAddr(), getAddr() + getSize() - 1, cmdString()); 226} |
227 |
228 |
229Packet::PrintReqState::PrintReqState(std::ostream &_os, int _verbosity) 230 : curPrefixPtr(new std::string("")), os(_os), verbosity(_verbosity) 231{ 232 labelStack.push_back(LabelStackEntry("", curPrefixPtr)); 233} |
234 |
235 236Packet::PrintReqState::~PrintReqState() 237{ 238 labelStack.pop_back(); 239 assert(labelStack.empty()); 240 delete curPrefixPtr; |
241} 242 |
243 244Packet::PrintReqState:: 245LabelStackEntry::LabelStackEntry(const std::string &_label, 246 std::string *_prefix) 247 : label(_label), prefix(_prefix), labelPrinted(false) 248{ 249} 250 251 252void 253Packet::PrintReqState::pushLabel(const std::string &lbl, 254 const std::string &prefix) 255{ 256 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr)); 257 curPrefixPtr = new std::string(*curPrefixPtr); 258 *curPrefixPtr += prefix; 259} 260 261void 262Packet::PrintReqState::popLabel() 263{ 264 delete curPrefixPtr; 265 curPrefixPtr = labelStack.back().prefix; 266 labelStack.pop_back(); 267 assert(!labelStack.empty()); 268} 269 270void 271Packet::PrintReqState::printLabels() 272{ 273 if (!labelStack.back().labelPrinted) { 274 LabelStack::iterator i = labelStack.begin(); 275 LabelStack::iterator end = labelStack.end(); 276 while (i != end) { 277 if (!i->labelPrinted) { 278 ccprintf(os, "%s%s\n", *(i->prefix), i->label); 279 i->labelPrinted = true; 280 } 281 i++; 282 } 283 } 284} 285 286 287void 288Packet::PrintReqState::printObj(Printable *obj) 289{ 290 printLabels(); 291 obj->print(os, verbosity, curPrefix()); 292} |