packet.cc (10570:dcb908e40547) | packet.cc (10723:b1d90d88420e) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2011-2014 ARM Limited | 2 * Copyright (c) 2011-2015 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 --- 191 unchanged lines hidden (view full) --- 202 203 // offset of functional request into supplied value (could be 204 // negative if partial overlap) 205 int offset = func_start - val_start; 206 207 if (isRead()) { 208 if (func_start >= val_start && func_end <= val_end) { 209 memcpy(getPtr<uint8_t>(), _data + offset, getSize()); | 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 --- 191 unchanged lines hidden (view full) --- 202 203 // offset of functional request into supplied value (could be 204 // negative if partial overlap) 205 int offset = func_start - val_start; 206 207 if (isRead()) { 208 if (func_start >= val_start && func_end <= val_end) { 209 memcpy(getPtr<uint8_t>(), _data + offset, getSize()); |
210 if (bytesValid.empty()) 211 bytesValid.resize(getSize(), true); |
|
210 // complete overlap, and as the current packet is a read 211 // we are done 212 return true; 213 } else { 214 // Offsets and sizes to copy in case of partial overlap 215 int func_offset; 216 int val_offset; 217 int overlap_size; 218 219 // calculate offsets and copy sizes for the two byte arrays 220 if (val_start < func_start && val_end <= func_end) { | 212 // complete overlap, and as the current packet is a read 213 // we are done 214 return true; 215 } else { 216 // Offsets and sizes to copy in case of partial overlap 217 int func_offset; 218 int val_offset; 219 int overlap_size; 220 221 // calculate offsets and copy sizes for the two byte arrays 222 if (val_start < func_start && val_end <= func_end) { |
223 // the one we are checking against starts before and 224 // ends before or the same |
|
221 val_offset = func_start - val_start; 222 func_offset = 0; 223 overlap_size = val_end - func_start; 224 } else if (val_start >= func_start && val_end > func_end) { | 225 val_offset = func_start - val_start; 226 func_offset = 0; 227 overlap_size = val_end - func_start; 228 } else if (val_start >= func_start && val_end > func_end) { |
229 // the one we are checking against starts after or the 230 // same, and ends after |
|
225 val_offset = 0; 226 func_offset = val_start - func_start; 227 overlap_size = func_end - val_start; 228 } else if (val_start >= func_start && val_end <= func_end) { | 231 val_offset = 0; 232 func_offset = val_start - func_start; 233 overlap_size = func_end - val_start; 234 } else if (val_start >= func_start && val_end <= func_end) { |
235 // the one we are checking against is completely 236 // subsumed in the current packet, possibly starting 237 // and ending at the same address |
|
229 val_offset = 0; 230 func_offset = val_start - func_start; 231 overlap_size = size; | 238 val_offset = 0; 239 func_offset = val_start - func_start; 240 overlap_size = size; |
241 } else if (val_start < func_start && val_end > func_end) { 242 // the current packet is completely subsumed in the 243 // one we are checking against 244 val_offset = func_start - val_start; 245 func_offset = 0; 246 overlap_size = func_end - func_start; |
|
232 } else { | 247 } else { |
233 panic("BUG: Missed a case for a partial functional request"); | 248 panic("Missed a case for checkFunctional with " 249 " %s 0x%x size %d, against 0x%x size %d\n", 250 cmdString(), getAddr(), getSize(), addr, size); |
234 } 235 | 251 } 252 |
236 // Figure out how much of the partial overlap should be copied 237 // into the packet and not overwrite previously found bytes. 238 if (bytesValidStart == 0 && bytesValidEnd == 0) { 239 // No bytes have been copied yet, just set indices 240 // to found range 241 bytesValidStart = func_offset; 242 bytesValidEnd = func_offset + overlap_size; 243 } else { 244 // Some bytes have already been copied. Use bytesValid 245 // indices and offset values to figure out how much data 246 // to copy and where to copy it to. | 253 // copy partial data into the packet's data array 254 uint8_t *dest = getPtr<uint8_t>() + func_offset; 255 uint8_t *src = _data + val_offset; 256 memcpy(dest, src, overlap_size); |
247 | 257 |
248 // Indice overlap conditions to check 249 int a = func_offset - bytesValidStart; 250 int b = (func_offset + overlap_size) - bytesValidEnd; 251 int c = func_offset - bytesValidEnd; 252 int d = (func_offset + overlap_size) - bytesValidStart; | 258 // initialise the tracking of valid bytes if we have not 259 // used it already 260 if (bytesValid.empty()) 261 bytesValid.resize(getSize(), false); |
253 | 262 |
254 if (a >= 0 && b <= 0) { 255 // bytes already in pkt data array are superset of 256 // found bytes, will not copy any bytes 257 overlap_size = 0; 258 } else if (a < 0 && d >= 0 && b <= 0) { 259 // found bytes will move bytesValidStart towards 0 260 overlap_size = bytesValidStart - func_offset; 261 bytesValidStart = func_offset; 262 } else if (b > 0 && c <= 0 && a >= 0) { 263 // found bytes will move bytesValidEnd 264 // towards end of pkt data array 265 overlap_size = 266 (func_offset + overlap_size) - bytesValidEnd; 267 val_offset += bytesValidEnd - func_offset; 268 func_offset = bytesValidEnd; 269 bytesValidEnd += overlap_size; 270 } else if (a < 0 && b > 0) { 271 // Found bytes are superset of copied range. Will move 272 // bytesValidStart towards 0 and bytesValidEnd towards 273 // end of pkt data array. Need to break copy into two 274 // pieces so as to not overwrite previously found data. | 263 // track if we are done filling the functional access 264 bool all_bytes_valid = true; |
275 | 265 |
276 // copy the first half 277 uint8_t *dest = getPtr<uint8_t>() + func_offset; 278 uint8_t *src = _data + val_offset; 279 memcpy(dest, src, (bytesValidStart - func_offset)); | 266 int i = 0; |
280 | 267 |
281 // re-calc the offsets and indices to do the copy 282 // required for the second half 283 val_offset += (bytesValidEnd - func_offset); 284 bytesValidStart = func_offset; 285 overlap_size = 286 (func_offset + overlap_size) - bytesValidEnd; 287 func_offset = bytesValidEnd; 288 bytesValidEnd += overlap_size; 289 } else if ((c > 0 && b > 0) 290 || (a < 0 && d < 0)) { 291 // region to be copied is discontiguous! Not supported. 292 panic("BUG: Discontiguous bytes found" 293 "for functional copying!"); 294 } 295 } 296 assert(bytesValidEnd <= getSize()); | 268 // check up to func_offset 269 for (; all_bytes_valid && i < func_offset; ++i) 270 all_bytes_valid &= bytesValid[i]; |
297 | 271 |
298 // copy partial data into the packet's data array 299 uint8_t *dest = getPtr<uint8_t>() + func_offset; 300 uint8_t *src = _data + val_offset; 301 memcpy(dest, src, overlap_size); | 272 // update the valid bytes 273 for (i = func_offset; i < func_offset + overlap_size; ++i) 274 bytesValid[i] = true; |
302 | 275 |
303 // check if we're done filling the functional access 304 bool done = (bytesValidStart == 0) && (bytesValidEnd == getSize()); 305 return done; | 276 // check the bit after the update we just made 277 for (; all_bytes_valid && i < getSize(); ++i) 278 all_bytes_valid &= bytesValid[i]; 279 280 return all_bytes_valid; |
306 } 307 } else if (isWrite()) { 308 if (offset >= 0) { 309 memcpy(_data + offset, getConstPtr<uint8_t>(), 310 (min(func_end, val_end) - func_start) + 1); 311 } else { 312 // val_start > func_start 313 memcpy(_data, getConstPtr<uint8_t>() - offset, --- 101 unchanged lines hidden --- | 281 } 282 } else if (isWrite()) { 283 if (offset >= 0) { 284 memcpy(_data + offset, getConstPtr<uint8_t>(), 285 (min(func_end, val_end) - func_start) + 1); 286 } else { 287 // val_start > func_start 288 memcpy(_data, getConstPtr<uint8_t>() - offset, --- 101 unchanged lines hidden --- |