11 #ifndef OPENOCD_HELPER_BINARYBUFFER_H
12 #define OPENOCD_HELPER_BINARYBUFFER_H
31 unsigned first,
unsigned num, uint32_t value)
35 if ((num == 32) && (first == 0)) {
36 buffer[3] = (value >> 24) & 0xff;
37 buffer[2] = (value >> 16) & 0xff;
38 buffer[1] = (value >> 8) & 0xff;
39 buffer[0] = (value >> 0) & 0xff;
41 for (
unsigned i = first; i < first + num; i++) {
42 if (((value >> (i - first)) & 1) == 1)
43 buffer[i / 8] |= 1 << (i % 8);
45 buffer[i / 8] &= ~(1 << (i % 8));
61 unsigned first,
unsigned num, uint64_t value)
65 if ((num == 32) && (first == 0)) {
66 buffer[3] = (value >> 24) & 0xff;
67 buffer[2] = (value >> 16) & 0xff;
68 buffer[1] = (value >> 8) & 0xff;
69 buffer[0] = (value >> 0) & 0xff;
70 }
else if ((num == 64) && (first == 0)) {
71 buffer[7] = (value >> 56) & 0xff;
72 buffer[6] = (value >> 48) & 0xff;
73 buffer[5] = (value >> 40) & 0xff;
74 buffer[4] = (value >> 32) & 0xff;
75 buffer[3] = (value >> 24) & 0xff;
76 buffer[2] = (value >> 16) & 0xff;
77 buffer[1] = (value >> 8) & 0xff;
78 buffer[0] = (value >> 0) & 0xff;
80 for (
unsigned i = first; i < first + num; i++) {
81 if (((value >> (i - first)) & 1) == 1)
82 buffer[i / 8] |= 1 << (i % 8);
84 buffer[i / 8] &= ~(1 << (i % 8));
99 unsigned first,
unsigned num)
101 const uint8_t *
buffer = _buffer;
103 if ((num == 32) && (first == 0)) {
104 return (((uint32_t)
buffer[3]) << 24) |
105 (((uint32_t)
buffer[2]) << 16) |
106 (((uint32_t)
buffer[1]) << 8) |
107 (((uint32_t)
buffer[0]) << 0);
110 for (
unsigned i = first; i < first + num; i++) {
111 if (((
buffer[i / 8] >> (i % 8)) & 1) == 1)
112 result |= 1U << (i - first);
128 unsigned first,
unsigned num)
130 const uint8_t *
buffer = _buffer;
132 if ((num == 32) && (first == 0)) {
133 return 0 + ((((uint32_t)
buffer[3]) << 24) |
134 (((uint32_t)
buffer[2]) << 16) |
135 (((uint32_t)
buffer[1]) << 8) |
136 (((uint32_t)
buffer[0]) << 0));
137 }
else if ((num == 64) && (first == 0)) {
138 return 0 + ((((uint64_t)
buffer[7]) << 56) |
139 (((uint64_t)
buffer[6]) << 48) |
140 (((uint64_t)
buffer[5]) << 40) |
141 (((uint64_t)
buffer[4]) << 32) |
142 (((uint64_t)
buffer[3]) << 24) |
143 (((uint64_t)
buffer[2]) << 16) |
144 (((uint64_t)
buffer[1]) << 8) |
145 (((uint64_t)
buffer[0]) << 0));
148 for (
unsigned i = first; i < first + num; i++) {
149 if (((
buffer[i / 8] >> (i % 8)) & 1) == 1)
150 result = result | ((uint64_t)1 << (uint64_t)(i - first));
167 bool buf_cmp(
const void *buf1,
const void *buf2,
unsigned size);
178 void *
buf_cpy(
const void *from,
void *to,
unsigned size);
188 void *
buf_set_buf(
const void *src,
unsigned src_start,
189 void *dst,
unsigned dst_start,
unsigned len);
192 void *bin_buf,
unsigned buf_size,
unsigned radix);
201 static inline void bit_copy(uint8_t *dst,
unsigned dst_offset,
const uint8_t *src,
202 unsigned src_offset,
unsigned bit_count)
204 buf_set_buf(src, src_offset, dst, dst_offset, bit_count);
222 unsigned src_offset,
unsigned bit_count);
228 size_t unhexify(uint8_t *bin,
const char *hex,
size_t count);
229 size_t hexify(
char *hex,
const uint8_t *bin,
size_t count,
size_t out_maxlen);
uint32_t flip_u32(uint32_t value, unsigned width)
Inverts the ordering of bits inside a 32-bit word (e.g.
void bit_copy_queue_init(struct bit_copy_queue *q)
void * buf_set_ones(void *buf, unsigned size)
Set the contents of buf with count bits, all set to 1.
void bit_copy_discard(struct bit_copy_queue *q)
int bit_copy_queued(struct bit_copy_queue *q, uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
void bit_copy_execute(struct bit_copy_queue *q)
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
bool buf_cmp_mask(const void *buf1, const void *buf2, const void *mask, unsigned size)
bool buf_cmp(const void *buf1, const void *buf2, unsigned size)
static void buf_set_u64(uint8_t *_buffer, unsigned first, unsigned num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
void buffer_shr(void *_buf, unsigned buf_len, unsigned count)
int str_to_buf(const char *str, unsigned len, void *bin_buf, unsigned buf_size, unsigned radix)
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint32_t fast_target_buffer_get_u32(const void *p, bool le)
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
void * buf_set_buf(const void *src, unsigned src_start, void *dst, unsigned dst_start, unsigned len)
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t out_maxlen)
Convert binary data into a string of hexadecimal pairs.
char * buf_to_hex_str(const void *buf, unsigned size)
void * buf_cpy(const void *from, void *to, unsigned size)
Copies size bits out of from and into to.
size_t size
Size of the control block search area.
static uint32_t be_to_h_u32(const uint8_t *buf)
static uint32_t le_to_h_u32(const uint8_t *buf)