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 |
45using namespace std; 46 |
47// The one downside to bitsets is that static initializers can get ugly. 48#define SET1(a1) (1 << (a1)) 49#define SET2(a1, a2) (SET1(a1) | SET1(a2)) 50#define SET3(a1, a2, a3) (SET2(a1, a2) | SET1(a3)) 51#define SET4(a1, a2, a3, a4) (SET3(a1, a2, a3) | SET1(a4)) 52#define SET5(a1, a2, a3, a4, a5) (SET4(a1, a2, a3, a4) | SET1(a5)) 53#define SET6(a1, a2, a3, a4, a5, a6) (SET5(a1, a2, a3, a4, a5) | SET1(a6)) 54 --- 75 unchanged lines hidden (view full) --- 130 /* InvalidDestError -- packet dest field invalid */ 131 { SET2(IsResponse, IsError), InvalidCmd, "InvalidDestError" }, 132 /* BadAddressError -- memory address invalid */ 133 { SET2(IsResponse, IsError), InvalidCmd, "BadAddressError" }, 134 /* PrintReq */ 135 { SET2(IsRequest, IsPrint), InvalidCmd, "PrintReq" } 136}; 137 |
138bool 139Packet::checkFunctional(Printable *obj, Addr addr, int size, uint8_t *data) 140{ 141 Addr func_start = getAddr(); 142 Addr func_end = getAddr() + getSize() - 1; 143 Addr val_start = addr; 144 Addr val_end = val_start + size - 1; 145 --- 15 unchanged lines hidden (view full) --- 161 162 // offset of functional request into supplied value (could be 163 // negative if partial overlap) 164 int offset = func_start - val_start; 165 166 if (isRead()) { 167 if (func_start >= val_start && func_end <= val_end) { 168 allocate(); |
169 memcpy(getPtr |
170 makeResponse(); 171 return true; 172 } else { 173 // In this case the timing packet only partially satisfies 174 // the request, so we would need more information to make 175 // this work. Like bytes valid in the packet or 176 // something, so the request could continue and get this 177 // bit of possibly newer data along with the older data 178 // not written to yet. 179 panic("Memory value only partially satisfies the functional " 180 "request. Now what?"); 181 } 182 } else if (isWrite()) { 183 if (offset >= 0) { |
184 memcpy(data + offset, getPtr 185 (min(func_end, val_end) - func_start) + 1); 186 } else { 187 // val_start > func_start 188 memcpy(data, getPtr<uint8_t>() - offset, 189 (min(func_end, val_end) - val_start) + 1); |
190 } 191 } else { 192 panic("Don't know how to handle command %s\n", cmdString()); 193 } 194 195 // keep going with request by default 196 return false; 197} 198 |
199void |
200Packet::print(ostream &o, const int verbosity, const string &prefix) const |
201{ 202 ccprintf(o, "%s[%x:%x] %s\n", prefix, 203 getAddr(), getAddr() + getSize() - 1, cmdString()); 204} 205 |
206Packet::PrintReqState::PrintReqState(ostream &_os, int _verbosity) 207 : curPrefixPtr(new string("")), os(_os), verbosity(_verbosity) |
208{ 209 labelStack.push_back(LabelStackEntry("", curPrefixPtr)); 210} 211 |
212Packet::PrintReqState::~PrintReqState() 213{ 214 labelStack.pop_back(); 215 assert(labelStack.empty()); 216 delete curPrefixPtr; 217} 218 |
219Packet::PrintReqState:: |
220LabelStackEntry::LabelStackEntry(const string &_label, string *_prefix) |
221 : label(_label), prefix(_prefix), labelPrinted(false) 222{ 223} 224 |
225void |
226Packet::PrintReqState::pushLabel(const string &lbl, const string &prefix) |
227{ 228 labelStack.push_back(LabelStackEntry(lbl, curPrefixPtr)); |
229 curPrefixPtr = new string(*curPrefixPtr); |
230 *curPrefixPtr += prefix; 231} 232 233void 234Packet::PrintReqState::popLabel() 235{ 236 delete curPrefixPtr; 237 curPrefixPtr = labelStack.back().prefix; --- 27 unchanged lines hidden --- |