Deleted Added
sdiff udiff text old ( 10570:dcb908e40547 ) new ( 10723:b1d90d88420e )
full compact
1/*
2 * Copyright (c) 2011-2014 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());
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) {
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 = 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) {
229 val_offset = 0;
230 func_offset = val_start - func_start;
231 overlap_size = size;
232 } else {
233 panic("BUG: Missed a case for a partial functional request");
234 }
235
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.
247
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;
253
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.
275
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));
280
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());
297
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);
302
303 // check if we're done filling the functional access
304 bool done = (bytesValidStart == 0) && (bytesValidEnd == getSize());
305 return done;
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 ---