sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin libvex_basictypes.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 10 | Copyright (C) 2004-2017 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 29 | |
| 30 | Neither the names of the U.S. Department of Energy nor the |
| 31 | University of California nor the names of its contributors may be |
| 32 | used to endorse or promote products derived from this software |
| 33 | without prior written permission. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
sewardj | 5287fd7 | 2004-07-05 17:29:08 +0000 | [diff] [blame] | 36 | #ifndef __LIBVEX_BASICTYPES_H |
| 37 | #define __LIBVEX_BASICTYPES_H |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 38 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 39 | /* It is important that the sizes of the following data types (on the |
| 40 | host) are as stated. LibVEX_Init therefore checks these at |
| 41 | startup. */ |
| 42 | |
| 43 | /* Always 8 bits. */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 44 | typedef unsigned char UChar; |
sewardj | 810dcf0 | 2004-11-22 12:55:45 +0000 | [diff] [blame] | 45 | typedef signed char Char; |
| 46 | typedef char HChar; /* signfulness depends on host */ |
| 47 | /* Only to be used for printf etc |
| 48 | format strings */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 49 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 50 | /* Always 16 bits. */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 51 | typedef unsigned short UShort; |
| 52 | typedef signed short Short; |
| 53 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 54 | /* Always 32 bits. */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 55 | typedef unsigned int UInt; |
| 56 | typedef signed int Int; |
| 57 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 58 | /* Always 64 bits. */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 59 | typedef unsigned long long int ULong; |
| 60 | typedef signed long long int Long; |
| 61 | |
florian | c66ba65 | 2014-12-29 19:05:37 +0000 | [diff] [blame] | 62 | /* Equivalent of C's size_t type. The type is unsigned and has this |
| 63 | storage requirement: |
| 64 | 32 bits on a 32-bit architecture |
| 65 | 64 bits on a 64-bit architecture. */ |
| 66 | typedef unsigned long SizeT; |
| 67 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 68 | /* Always 128 bits. */ |
| 69 | typedef UInt U128[4]; |
| 70 | |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 71 | /* Always 256 bits. */ |
| 72 | typedef UInt U256[8]; |
| 73 | |
sewardj | acfbd7d | 2010-08-17 22:52:08 +0000 | [diff] [blame] | 74 | /* A union for doing 128-bit vector primitives conveniently. */ |
| 75 | typedef |
| 76 | union { |
| 77 | UChar w8[16]; |
| 78 | UShort w16[8]; |
| 79 | UInt w32[4]; |
| 80 | ULong w64[2]; |
| 81 | } |
| 82 | V128; |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 83 | |
sewardj | cc3d219 | 2013-03-27 11:37:33 +0000 | [diff] [blame] | 84 | /* A union for doing 256-bit vector primitives conveniently. */ |
| 85 | typedef |
| 86 | union { |
| 87 | UChar w8[32]; |
| 88 | UShort w16[16]; |
| 89 | UInt w32[8]; |
| 90 | ULong w64[4]; |
| 91 | } |
| 92 | V256; |
| 93 | |
sewardj | acfbd7d | 2010-08-17 22:52:08 +0000 | [diff] [blame] | 94 | /* Floating point. */ |
sewardj | a58ea66 | 2004-08-15 03:12:41 +0000 | [diff] [blame] | 95 | typedef float Float; /* IEEE754 single-precision (32-bit) value */ |
| 96 | typedef double Double; /* IEEE754 double-precision (64-bit) value */ |
| 97 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 98 | /* Bool is always 8 bits. */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 99 | typedef unsigned char Bool; |
| 100 | #define True ((Bool)1) |
| 101 | #define False ((Bool)0) |
| 102 | |
sewardj | 7a24055 | 2005-01-28 21:37:12 +0000 | [diff] [blame] | 103 | /* Use this to coerce the result of a C comparison to a Bool. This is |
| 104 | useful when compiling with Intel icc with ultra-paranoid |
| 105 | compilation flags (-Wall). */ |
| 106 | static inline Bool toBool ( Int x ) { |
| 107 | Int r = (x == 0) ? False : True; |
| 108 | return (Bool)r; |
| 109 | } |
sewardj | 9d2e769 | 2005-02-07 01:11:31 +0000 | [diff] [blame] | 110 | static inline UChar toUChar ( Int x ) { |
| 111 | x &= 0xFF; |
| 112 | return (UChar)x; |
| 113 | } |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame] | 114 | static inline HChar toHChar ( Int x ) { |
| 115 | x &= 0xFF; |
| 116 | return (HChar)x; |
| 117 | } |
sewardj | 9d2e769 | 2005-02-07 01:11:31 +0000 | [diff] [blame] | 118 | static inline UShort toUShort ( Int x ) { |
| 119 | x &= 0xFFFF; |
| 120 | return (UShort)x; |
| 121 | } |
sewardj | 40e144d | 2005-03-28 00:46:27 +0000 | [diff] [blame] | 122 | static inline Short toShort ( Int x ) { |
| 123 | x &= 0xFFFF; |
| 124 | return (Short)x; |
| 125 | } |
sewardj | 98e65ba | 2005-02-25 18:36:07 +0000 | [diff] [blame] | 126 | static inline UInt toUInt ( Long x ) { |
| 127 | x &= 0xFFFFFFFFLL; |
| 128 | return (UInt)x; |
| 129 | } |
sewardj | 7a24055 | 2005-01-28 21:37:12 +0000 | [diff] [blame] | 130 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 131 | /* 32/64 bit addresses. */ |
| 132 | typedef UInt Addr32; |
| 133 | typedef ULong Addr64; |
| 134 | |
florian | beac530 | 2014-12-31 12:09:38 +0000 | [diff] [blame] | 135 | /* An address: 32-bit or 64-bit wide depending on host architecture */ |
| 136 | typedef unsigned long Addr; |
| 137 | |
| 138 | |
sewardj | ea602bc | 2004-10-14 21:40:12 +0000 | [diff] [blame] | 139 | /* Something which has the same size as void* on the host. That is, |
| 140 | it is 32 bits on a 32-bit host and 64 bits on a 64-bit host, and so |
| 141 | it can safely be coerced to and from a pointer type on the host |
| 142 | machine. */ |
| 143 | typedef unsigned long HWord; |
| 144 | |
florian | 93a0974 | 2015-01-07 20:14:48 +0000 | [diff] [blame] | 145 | /* Set up VEX_HOST_WORDSIZE and VEX_REGPARM. */ |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 146 | #undef VEX_HOST_WORDSIZE |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 147 | #undef VEX_REGPARM |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 148 | |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 149 | /* The following 4 work OK for Linux. */ |
sewardj | a219a80 | 2005-03-29 21:35:08 +0000 | [diff] [blame] | 150 | #if defined(__x86_64__) |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 151 | # define VEX_HOST_WORDSIZE 8 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 152 | # define VEX_REGPARM(_n) /* */ |
sewardj | 216ac96 | 2011-03-15 12:41:30 +0000 | [diff] [blame] | 153 | |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 154 | #elif defined(__i386__) |
| 155 | # define VEX_HOST_WORDSIZE 4 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 156 | # define VEX_REGPARM(_n) __attribute__((regparm(_n))) |
sewardj | 216ac96 | 2011-03-15 12:41:30 +0000 | [diff] [blame] | 157 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 158 | #elif defined(__powerpc__) && defined(__powerpc64__) |
| 159 | # define VEX_HOST_WORDSIZE 8 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 160 | # define VEX_REGPARM(_n) /* */ |
sewardj | 216ac96 | 2011-03-15 12:41:30 +0000 | [diff] [blame] | 161 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 162 | #elif defined(__powerpc__) && !defined(__powerpc64__) |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 163 | # define VEX_HOST_WORDSIZE 4 |
sewardj | 216ac96 | 2011-03-15 12:41:30 +0000 | [diff] [blame] | 164 | # define VEX_REGPARM(_n) /* */ |
| 165 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 166 | #elif defined(__arm__) && !defined(__aarch64__) |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 167 | # define VEX_HOST_WORDSIZE 4 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 168 | # define VEX_REGPARM(_n) /* */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 169 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 170 | #elif defined(__aarch64__) && !defined(__arm__) |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 171 | # define VEX_HOST_WORDSIZE 8 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 172 | # define VEX_REGPARM(_n) /* */ |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 173 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 174 | #elif defined(__s390x__) |
| 175 | # define VEX_HOST_WORDSIZE 8 |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 176 | # define VEX_REGPARM(_n) /* */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 177 | |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 178 | #elif defined(__mips__) && (__mips == 64) |
petarj | b92a954 | 2013-02-27 22:57:17 +0000 | [diff] [blame] | 179 | # define VEX_HOST_WORDSIZE 8 |
sewardj | bbcf188 | 2014-01-12 12:49:10 +0000 | [diff] [blame] | 180 | # define VEX_REGPARM(_n) /* */ |
| 181 | |
| 182 | #elif defined(__mips__) && (__mips != 64) |
sewardj | d0e5fe7 | 2012-06-07 08:51:02 +0000 | [diff] [blame] | 183 | # define VEX_HOST_WORDSIZE 4 |
| 184 | # define VEX_REGPARM(_n) /* */ |
| 185 | |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 186 | #else |
| 187 | # error "Vex: Fatal: Can't establish the host architecture" |
| 188 | #endif |
| 189 | |
| 190 | |
sewardj | 97e8793 | 2005-02-07 00:00:50 +0000 | [diff] [blame] | 191 | #endif /* ndef __LIBVEX_BASICTYPES_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 192 | |
| 193 | /*---------------------------------------------------------------*/ |
sewardj | 5287fd7 | 2004-07-05 17:29:08 +0000 | [diff] [blame] | 194 | /*--- libvex_basictypes.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 195 | /*---------------------------------------------------------------*/ |
sewardj | 0de8019 | 2015-04-10 12:27:40 +0000 | [diff] [blame] | 196 | |