X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Ftypes.h;h=58c9e724579e3082c84d21d132a92e050a2e2e64;hb=f63af76466234cc905df6ea8e0f3fb5284c2058d;hp=210d3c3e92fd3d2f1354e8eb0066a41da9a703cd;hpb=4516eebabac0df24f00f40ff97ff570fdd39b2db;p=openocd.git diff --git a/src/helper/types.h b/src/helper/types.h index 210d3c3e92..58c9e72457 100644 --- a/src/helper/types.h +++ b/src/helper/types.h @@ -16,12 +16,11 @@ * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + * along with this program. If not, see . * ***************************************************************************/ -#ifndef TYPES_H -#define TYPES_H + +#ifndef OPENOCD_HELPER_TYPES_H +#define OPENOCD_HELPER_TYPES_H #include #ifdef HAVE_SYS_TYPES_H @@ -270,6 +269,25 @@ static inline void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len) } } +/** + * Calculate the (even) parity of a 32-bit datum. + * @param x The datum. + * @return 1 if the number of set bits in x is odd, 0 if it is even. + */ +static inline int parity_u32(uint32_t x) +{ +#ifdef __GNUC__ + return __builtin_parityl(x); +#else + x ^= x >> 16; + x ^= x >> 8; + x ^= x >> 4; + x ^= x >> 2; + x ^= x >> 1; + return x & 1; +#endif +} + #if defined(__ECOS) /* eCos plain lacks these definition... A series of upstream patches @@ -278,14 +296,21 @@ static inline void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len) */ #if !defined(_STDINT_H) -#define PRIx32 "x" #define PRId32 "d" -#define SCNx32 "x" #define PRIi32 "i" +#define PRIo32 "o" #define PRIu32 "u" +#define PRIx32 "x" +#define PRIX32 "X" +#define SCNx32 "x" #define PRId8 PRId32 #define SCNx64 "llx" +#define PRId64 "lld" +#define PRIi64 "lli" +#define PRIo64 "llo" +#define PRIu64 "llu" #define PRIx64 "llx" +#define PRIX64 "llX" typedef CYG_ADDRWORD intptr_t; typedef int64_t intmax_t; @@ -319,4 +344,23 @@ typedef uint64_t uintmax_t; #endif -#endif /* TYPES_H */ +#if BUILD_TARGET64 +typedef uint64_t target_addr_t; +#define TARGET_ADDR_MAX UINT64_MAX +#define TARGET_PRIdADDR PRId64 +#define TARGET_PRIuADDR PRIu64 +#define TARGET_PRIoADDR PRIo64 +#define TARGET_PRIxADDR PRIx64 +#define TARGET_PRIXADDR PRIX64 +#else +typedef uint32_t target_addr_t; +#define TARGET_ADDR_MAX UINT32_MAX +#define TARGET_PRIdADDR PRId32 +#define TARGET_PRIuADDR PRIu32 +#define TARGET_PRIoADDR PRIo32 +#define TARGET_PRIxADDR PRIx32 +#define TARGET_PRIXADDR PRIX32 +#endif +#define TARGET_ADDR_FMT "0x%8.8" TARGET_PRIxADDR + +#endif /* OPENOCD_HELPER_TYPES_H */