| 1 |
/* Memory validation functions for AArch64 procedure call standard. |
| 2 |
Copyright (C) 2012 Free Software Foundation, Inc. |
| 3 |
Contributed by ARM Ltd. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it |
| 8 |
under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but |
| 13 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#ifndef VALIDATE_MEMORY_H |
| 22 |
#define VALIDATE_MEMORY_H |
| 23 |
|
| 24 |
enum structure_type |
| 25 |
{ |
| 26 |
flat = 0, |
| 27 |
i32in128, |
| 28 |
f32in64, |
| 29 |
i8in64, |
| 30 |
i16in64, |
| 31 |
i32in64, |
| 32 |
}; |
| 33 |
|
| 34 |
/* Some explicit declarations as I can't include files outside the testsuite. |
| 35 |
*/ |
| 36 |
typedef long unsigned int size_t; |
| 37 |
int memcmp (void *, void *, size_t); |
| 38 |
|
| 39 |
/* These two arrays contain element size and block size data for the enumeration |
| 40 |
above. */ |
| 41 |
const int element_size[] = { 1, 4, 4, 1, 2, 4 }; |
| 42 |
const int block_reverse_size[] = { 1, 16, 8, 8, 8, 8 }; |
| 43 |
|
| 44 |
int |
| 45 |
validate_memory (void *mem1, char *mem2, size_t size, enum structure_type type) |
| 46 |
{ |
| 47 |
/* In big-endian mode, the data in mem2 will have been byte-reversed in |
| 48 |
register sized groups, while the data in mem1 will have been byte-reversed |
| 49 |
according to the true structure of the data. To compare them, we need to |
| 50 |
compare chunks of data in reverse order. |
| 51 |
|
| 52 |
This is only implemented for homogeneous data layouts at the moment. For |
| 53 |
hetrogeneous structures a custom compare case will need to be written. */ |
| 54 |
|
| 55 |
unsigned int i; |
| 56 |
char *cmem1 = (char *) mem1; |
| 57 |
switch (type) |
| 58 |
{ |
| 59 |
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 60 |
case i8in64: |
| 61 |
case i16in64: |
| 62 |
case i32in64: |
| 63 |
for (i = 0; i < size; i += element_size[type]) |
| 64 |
{ |
| 65 |
if (memcmp (cmem1 + i, |
| 66 |
mem2 + block_reverse_size[type] - i - element_size[type], |
| 67 |
element_size[type])) |
| 68 |
return 1; |
| 69 |
} |
| 70 |
return 0; |
| 71 |
break; |
| 72 |
#endif |
| 73 |
case f32in64: |
| 74 |
case i32in128: |
| 75 |
default: |
| 76 |
break; |
| 77 |
} |
| 78 |
return memcmp (mem1, mem2, size); |
| 79 |
} |
| 80 |
|
| 81 |
#endif /* VALIDATE_MEMORY_H. */ |