packet.cc (8436:5648986156db) | packet.cc (8668:be72c2a127b2) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2011 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 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
|
2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * Copyright (c) 2010 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; --- 177 unchanged lines hidden (view full) --- 187 int offset = func_start - val_start; 188 189 if (isRead()) { 190 if (func_start >= val_start && func_end <= val_end) { 191 allocate(); 192 memcpy(getPtr<uint8_t>(), data + offset, getSize()); 193 return true; 194 } else { | 14 * Copyright (c) 2006 The Regents of The University of Michigan 15 * Copyright (c) 2010 Advanced Micro Devices, Inc. 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; --- 177 unchanged lines hidden (view full) --- 199 int offset = func_start - val_start; 200 201 if (isRead()) { 202 if (func_start >= val_start && func_end <= val_end) { 203 allocate(); 204 memcpy(getPtr<uint8_t>(), data + offset, getSize()); 205 return true; 206 } else { |
195 // In this case the timing packet only partially satisfies 196 // the request, so we would need more information to make 197 // this work. Like bytes valid in the packet or 198 // something, so the request could continue and get this 199 // bit of possibly newer data along with the older data 200 // not written to yet. 201 panic("Memory value only partially satisfies the functional " 202 "request. Now what?"); | 207 // Offsets and sizes to copy in case of partial overlap 208 int func_offset; 209 int val_offset; 210 int overlap_size; 211 212 // calculate offsets and copy sizes for the two byte arrays 213 if (val_start < func_start && val_end <= func_end) { 214 val_offset = func_start - val_start; 215 func_offset = 0; 216 overlap_size = val_end - func_start; 217 } else if (val_start >= func_start && val_end > func_end) { 218 val_offset = 0; 219 func_offset = val_start - func_start; 220 overlap_size = func_end - val_start; 221 } else if (val_start >= func_start && val_end <= func_end) { 222 val_offset = 0; 223 func_offset = val_start - func_start; 224 overlap_size = size; 225 } else { 226 panic("BUG: Missed a case for a partial functional request"); 227 } 228 229 // Figure out how much of the partial overlap should be copied 230 // into the packet and not overwrite previously found bytes. 231 if (bytesValidStart == 0 && bytesValidEnd == 0) { 232 // No bytes have been copied yet, just set indices 233 // to found range 234 bytesValidStart = func_offset; 235 bytesValidEnd = func_offset + overlap_size; 236 } else { 237 // Some bytes have already been copied. Use bytesValid 238 // indices and offset values to figure out how much data 239 // to copy and where to copy it to. 240 241 // Indice overlap conditions to check 242 int a = func_offset - bytesValidStart; 243 int b = (func_offset + overlap_size) - bytesValidEnd; 244 int c = func_offset - bytesValidEnd; 245 int d = (func_offset + overlap_size) - bytesValidStart; 246 247 if (a >= 0 && b <= 0) { 248 // bytes already in pkt data array are superset of 249 // found bytes, will not copy any bytes 250 overlap_size = 0; 251 } else if (a < 0 && d >= 0 && b <= 0) { 252 // found bytes will move bytesValidStart towards 0 253 overlap_size = bytesValidStart - func_offset; 254 bytesValidStart = func_offset; 255 } else if (b > 0 && c <= 0 && a >= 0) { 256 // found bytes will move bytesValidEnd 257 // towards end of pkt data array 258 overlap_size = 259 (func_offset + overlap_size) - bytesValidEnd; 260 val_offset += bytesValidEnd - func_offset; 261 func_offset = bytesValidEnd; 262 bytesValidEnd += overlap_size; 263 } else if (a < 0 && b > 0) { 264 // Found bytes are superset of copied range. Will move 265 // bytesValidStart towards 0 and bytesValidEnd towards 266 // end of pkt data array. Need to break copy into two 267 // pieces so as to not overwrite previously found data. 268 269 // copy the first half 270 uint8_t *dest = getPtr<uint8_t>() + func_offset; 271 uint8_t *src = data + val_offset; 272 memcpy(dest, src, (bytesValidStart - func_offset)); 273 274 // re-calc the offsets and indices to do the copy 275 // required for the second half 276 val_offset += (bytesValidEnd - func_offset); 277 bytesValidStart = func_offset; 278 overlap_size = 279 (func_offset + overlap_size) - bytesValidEnd; 280 func_offset = bytesValidEnd; 281 bytesValidEnd += overlap_size; 282 } else if ((c > 0 && b > 0) 283 || (a < 0 && d < 0)) { 284 // region to be copied is discontiguous! Not supported. 285 panic("BUG: Discontiguous bytes found" 286 "for functional copying!"); 287 } 288 } 289 290 assert((bytesValidStart >= 0) && (bytesValidEnd <= getSize())); 291 292 // copy partial data into the packet's data array 293 uint8_t *dest = getPtr<uint8_t>() + func_offset; 294 uint8_t *src = data + val_offset; 295 memcpy(dest, src, overlap_size); 296 297 // check if we're done filling the functional access 298 bool done = (bytesValidStart == 0) && (bytesValidEnd == getSize()); 299 return done; |
203 } 204 } else if (isWrite()) { 205 if (offset >= 0) { 206 memcpy(data + offset, getPtr<uint8_t>(), 207 (min(func_end, val_end) - func_start) + 1); 208 } else { 209 // val_start > func_start 210 memcpy(data, getPtr<uint8_t>() - offset, --- 76 unchanged lines hidden --- | 300 } 301 } else if (isWrite()) { 302 if (offset >= 0) { 303 memcpy(data + offset, getPtr<uint8_t>(), 304 (min(func_end, val_end) - func_start) + 1); 305 } else { 306 // val_start > func_start 307 memcpy(data, getPtr<uint8_t>() - offset, --- 76 unchanged lines hidden --- |