11 #ifndef OPENOCD_HELPER_TYPES_H
12 #define OPENOCD_HELPER_TYPES_H
20 #ifdef HAVE_SYS_TYPES_H
21 #include <sys/types.h>
26 #ifdef HAVE_INTTYPES_H
33 #define __bool_true_false_are_defined 1
46 #define stringify(s) __stringify(s)
47 #define __stringify(s) #s
57 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
68 #define container_of(ptr, type, member) ({ \
69 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
70 (type *)( (void *) ( (char *)__mptr - offsetof(type,member) ) );})
79 #define DIV_ROUND_UP(m, n) (((m) + (n) - 1) / (n))
102 return (uint64_t)((uint64_t)buf[0] |
103 (uint64_t)buf[1] << 8 |
104 (uint64_t)buf[2] << 16 |
105 (uint64_t)buf[3] << 24 |
106 (uint64_t)buf[4] << 32 |
107 (uint64_t)buf[5] << 40 |
108 (uint64_t)buf[6] << 48 |
109 (uint64_t)buf[7] << 56);
114 return (uint32_t)((uint32_t)buf[0] | (uint32_t)buf[1] << 8 | (uint32_t)buf[2] << 16 | (uint32_t)buf[3] << 24);
119 return (uint32_t)((uint32_t)buf[0] | (uint32_t)buf[1] << 8 | (uint32_t)buf[2] << 16);
124 return (uint16_t)((uint16_t)buf[0] | (uint16_t)buf[1] << 8);
129 return (uint64_t)((uint64_t)buf[7] |
130 (uint64_t)buf[6] << 8 |
131 (uint64_t)buf[5] << 16 |
132 (uint64_t)buf[4] << 24 |
133 (uint64_t)buf[3] << 32 |
134 (uint64_t)buf[2] << 40 |
135 (uint64_t)buf[1] << 48 |
136 (uint64_t)buf[0] << 56);
141 return (uint32_t)((uint32_t)buf[3] | (uint32_t)buf[2] << 8 | (uint32_t)buf[1] << 16 | (uint32_t)buf[0] << 24);
146 return (uint32_t)((uint32_t)buf[2] | (uint32_t)buf[1] << 8 | (uint32_t)buf[0] << 16);
151 return (uint16_t)((uint16_t)buf[1] | (uint16_t)buf[0] << 8);
156 buf[7] = (uint8_t) (val >> 56);
157 buf[6] = (uint8_t) (val >> 48);
158 buf[5] = (uint8_t) (val >> 40);
159 buf[4] = (uint8_t) (val >> 32);
160 buf[3] = (uint8_t) (val >> 24);
161 buf[2] = (uint8_t) (val >> 16);
162 buf[1] = (uint8_t) (val >> 8);
163 buf[0] = (uint8_t) (val >> 0);
168 buf[0] = (uint8_t) (val >> 56);
169 buf[1] = (uint8_t) (val >> 48);
170 buf[2] = (uint8_t) (val >> 40);
171 buf[3] = (uint8_t) (val >> 32);
172 buf[4] = (uint8_t) (val >> 24);
173 buf[5] = (uint8_t) (val >> 16);
174 buf[6] = (uint8_t) (val >> 8);
175 buf[7] = (uint8_t) (val >> 0);
180 buf[3] = (uint8_t) (val >> 24);
181 buf[2] = (uint8_t) (val >> 16);
182 buf[1] = (uint8_t) (val >> 8);
183 buf[0] = (uint8_t) (val >> 0);
188 buf[0] = (uint8_t) (val >> 24);
189 buf[1] = (uint8_t) (val >> 16);
190 buf[2] = (uint8_t) (val >> 8);
191 buf[3] = (uint8_t) (val >> 0);
196 buf[2] = (uint8_t) (val >> 16);
197 buf[1] = (uint8_t) (val >> 8);
198 buf[0] = (uint8_t) (val >> 0);
203 buf[0] = (uint8_t) (val >> 16);
204 buf[1] = (uint8_t) (val >> 8);
205 buf[2] = (uint8_t) (val >> 0);
210 buf[1] = (uint8_t) (val >> 8);
211 buf[0] = (uint8_t) (val >> 0);
216 buf[0] = (uint8_t) (val >> 8);
217 buf[1] = (uint8_t) (val >> 0);
229 static inline void buf_bswap16(uint8_t *dst,
const uint8_t *src,
size_t len)
231 assert(len % 2 == 0);
232 assert(dst == src || dst + len <= src || src + len <= dst);
234 for (
size_t n = 0; n < len; n += 2) {
249 static inline void buf_bswap32(uint8_t *dst,
const uint8_t *src,
size_t len)
251 assert(len % 4 == 0);
252 assert(dst == src || dst + len <= src || src + len <= dst);
254 for (
size_t n = 0; n < len; n += 4) {
268 return __builtin_parityl(x);
286 #if !defined(_STDINT_H)
303 typedef CYG_ADDRWORD intptr_t;
304 typedef int64_t intmax_t;
305 typedef uint64_t uintmax_t;
306 #define INT8_MAX 0x7f
307 #define INT8_MIN (-INT8_MAX - 1)
308 # define UINT8_MAX (255)
309 #define INT16_MAX 0x7fff
310 #define INT16_MIN (-INT16_MAX - 1)
311 # define UINT16_MAX (65535)
312 #define INT32_MAX 0x7fffffffL
313 #define INT32_MIN (-INT32_MAX - 1L)
314 # define UINT32_MAX (4294967295U)
315 #define INT64_MAX 0x7fffffffffffffffLL
316 #define INT64_MIN (-INT64_MAX - 1LL)
317 #define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL)
321 #define ULLONG_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
322 #define LLONG_MAX INT64_C(0x7FFFFFFFFFFFFFFF)
323 #define LLONG_MIN ULLONG_MAX
327 #define ULLONG_MAX 18446744073709551615
330 #define isblank(c) ((c) == ' ' || (c) == '\t')
336 #define TARGET_ADDR_MAX UINT64_MAX
337 #define TARGET_PRIdADDR PRId64
338 #define TARGET_PRIuADDR PRIu64
339 #define TARGET_PRIoADDR PRIo64
340 #define TARGET_PRIxADDR PRIx64
341 #define TARGET_PRIXADDR PRIX64
342 #define TARGET_ADDR_FMT "0x%8.8" TARGET_PRIxADDR
static void h_u32_to_be(uint8_t *buf, uint32_t val)
static uint64_t le_to_h_u64(const uint8_t *buf)
static uint32_t be_to_h_u24(const uint8_t *buf)
static void h_u16_to_be(uint8_t *buf, uint16_t val)
static void buf_bswap16(uint8_t *dst, const uint8_t *src, size_t len)
Byte-swap buffer 16-bit.
static uint64_t be_to_h_u64(const uint8_t *buf)
static uint16_t le_to_h_u16(const uint8_t *buf)
static uint32_t le_to_h_u24(const uint8_t *buf)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
static uint32_t be_to_h_u32(const uint8_t *buf)
static void h_u24_to_le(uint8_t *buf, unsigned int val)
static void h_u24_to_be(uint8_t *buf, unsigned int val)
static uint16_t be_to_h_u16(const uint8_t *buf)
static void h_u16_to_le(uint8_t *buf, uint16_t val)
static uint32_t le_to_h_u32(const uint8_t *buf)
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static void h_u64_to_be(uint8_t *buf, uint64_t val)
static void h_u64_to_le(uint8_t *buf, uint64_t val)
static void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len)
Byte-swap buffer 32-bit.