packet.cc (12652:bae1a1865204) | packet.cc (12821:3663a543ed2a) |
---|---|
1/* 2 * Copyright (c) 2011-2018 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 --- 36 unchanged lines hidden (view full) --- 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 "mem/packet.hh" 52 | 1/* 2 * Copyright (c) 2011-2018 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 --- 36 unchanged lines hidden (view full) --- 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 "mem/packet.hh" 52 |
53#include <algorithm> |
|
53#include <cstring> 54#include <iostream> 55 56#include "base/cprintf.hh" 57#include "base/logging.hh" 58#include "base/trace.hh" 59#include "mem/packet_access.hh" 60 --- 161 unchanged lines hidden (view full) --- 222 { SET2(IsInvalidate, IsResponse), 223 InvalidCmd, "InvalidateResp" } 224}; 225 226bool 227Packet::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size, 228 uint8_t *_data) 229{ | 54#include <cstring> 55#include <iostream> 56 57#include "base/cprintf.hh" 58#include "base/logging.hh" 59#include "base/trace.hh" 60#include "mem/packet_access.hh" 61 --- 161 unchanged lines hidden (view full) --- 223 { SET2(IsInvalidate, IsResponse), 224 InvalidCmd, "InvalidateResp" } 225}; 226 227bool 228Packet::checkFunctional(Printable *obj, Addr addr, bool is_secure, int size, 229 uint8_t *_data) 230{ |
230 Addr func_start = getAddr(); 231 Addr func_end = getAddr() + getSize() - 1; 232 Addr val_start = addr; 233 Addr val_end = val_start + size - 1; | 231 const Addr func_start = getAddr(); 232 const Addr func_end = getAddr() + getSize() - 1; 233 const Addr val_start = addr; 234 const Addr val_end = val_start + size - 1; |
234 235 if (is_secure != _isSecure || func_start > val_end || 236 val_start > func_end) { 237 // no intersection 238 return false; 239 } 240 241 // check print first since it doesn't require data --- 4 unchanged lines hidden (view full) --- 246 } 247 248 // we allow the caller to pass NULL to signify the other packet 249 // has no data 250 if (!_data) { 251 return false; 252 } 253 | 235 236 if (is_secure != _isSecure || func_start > val_end || 237 val_start > func_end) { 238 // no intersection 239 return false; 240 } 241 242 // check print first since it doesn't require data --- 4 unchanged lines hidden (view full) --- 247 } 248 249 // we allow the caller to pass NULL to signify the other packet 250 // has no data 251 if (!_data) { 252 return false; 253 } 254 |
254 // offset of functional request into supplied value (could be 255 // negative if partial overlap) 256 int offset = func_start - val_start; | 255 const Addr val_offset = func_start > val_start ? 256 func_start - val_start : 0; 257 const Addr func_offset = func_start < val_start ? 258 val_start - func_start : 0; 259 const Addr overlap_size = std::min(val_end, func_end)+1 - 260 std::max(val_start, func_start); |
257 258 if (isRead()) { | 261 262 if (isRead()) { |
259 if (func_start >= val_start && func_end <= val_end) { 260 memcpy(getPtr<uint8_t>(), _data + offset, getSize()); 261 if (bytesValid.empty()) 262 bytesValid.resize(getSize(), true); 263 // complete overlap, and as the current packet is a read 264 // we are done 265 return true; 266 } else { 267 // Offsets and sizes to copy in case of partial overlap 268 int func_offset; 269 int val_offset; 270 int overlap_size; | 263 memcpy(getPtr<uint8_t>() + func_offset, 264 _data + val_offset, 265 overlap_size); |
271 | 266 |
272 // calculate offsets and copy sizes for the two byte arrays 273 if (val_start < func_start && val_end <= func_end) { 274 // the one we are checking against starts before and 275 // ends before or the same 276 val_offset = func_start - val_start; 277 func_offset = 0; 278 overlap_size = val_end - func_start; 279 } else if (val_start >= func_start && val_end > func_end) { 280 // the one we are checking against starts after or the 281 // same, and ends after 282 val_offset = 0; 283 func_offset = val_start - func_start; 284 overlap_size = func_end - val_start; 285 } else if (val_start >= func_start && val_end <= func_end) { 286 // the one we are checking against is completely 287 // subsumed in the current packet, possibly starting 288 // and ending at the same address 289 val_offset = 0; 290 func_offset = val_start - func_start; 291 overlap_size = size; 292 } else if (val_start < func_start && val_end > func_end) { 293 // the current packet is completely subsumed in the 294 // one we are checking against 295 val_offset = func_start - val_start; 296 func_offset = 0; 297 overlap_size = func_end - func_start; 298 } else { 299 panic("Missed a case for checkFunctional with " 300 " %s 0x%x size %d, against 0x%x size %d\n", 301 cmdString(), getAddr(), getSize(), addr, size); 302 } | 267 // initialise the tracking of valid bytes if we have not 268 // used it already 269 if (bytesValid.empty()) 270 bytesValid.resize(getSize(), false); |
303 | 271 |
304 // copy partial data into the packet's data array 305 uint8_t *dest = getPtr<uint8_t>() + func_offset; 306 uint8_t *src = _data + val_offset; 307 memcpy(dest, src, overlap_size); | 272 // track if we are done filling the functional access 273 bool all_bytes_valid = true; |
308 | 274 |
309 // initialise the tracking of valid bytes if we have not 310 // used it already 311 if (bytesValid.empty()) 312 bytesValid.resize(getSize(), false); | 275 int i = 0; |
313 | 276 |
314 // track if we are done filling the functional access 315 bool all_bytes_valid = true; | 277 // check up to func_offset 278 for (; all_bytes_valid && i < func_offset; ++i) 279 all_bytes_valid &= bytesValid[i]; |
316 | 280 |
317 int i = 0; | 281 // update the valid bytes 282 for (i = func_offset; i < func_offset + overlap_size; ++i) 283 bytesValid[i] = true; |
318 | 284 |
319 // check up to func_offset 320 for (; all_bytes_valid && i < func_offset; ++i) 321 all_bytes_valid &= bytesValid[i]; | 285 // check the bit after the update we just made 286 for (; all_bytes_valid && i < getSize(); ++i) 287 all_bytes_valid &= bytesValid[i]; |
322 | 288 |
323 // update the valid bytes 324 for (i = func_offset; i < func_offset + overlap_size; ++i) 325 bytesValid[i] = true; 326 327 // check the bit after the update we just made 328 for (; all_bytes_valid && i < getSize(); ++i) 329 all_bytes_valid &= bytesValid[i]; 330 331 return all_bytes_valid; 332 } | 289 return all_bytes_valid; |
333 } else if (isWrite()) { | 290 } else if (isWrite()) { |
334 if (offset >= 0) { 335 memcpy(_data + offset, getConstPtr<uint8_t>(), 336 (min(func_end, val_end) - func_start) + 1); 337 } else { 338 // val_start > func_start 339 memcpy(_data, getConstPtr<uint8_t>() - offset, 340 (min(func_end, val_end) - val_start) + 1); 341 } | 291 memcpy(_data + val_offset, 292 getConstPtr<uint8_t>() + func_offset, 293 overlap_size); |
342 } else { 343 panic("Don't know how to handle command %s\n", cmdString()); 344 } 345 346 // keep going with request by default 347 return false; 348} 349 --- 136 unchanged lines hidden --- | 294 } else { 295 panic("Don't know how to handle command %s\n", cmdString()); 296 } 297 298 // keep going with request by default 299 return false; 300} 301 --- 136 unchanged lines hidden --- |