Skip to content

Commit

Permalink
Merge up to 1173473 from upstream
Browse files Browse the repository at this point in the history
1ae6b07 replaced `buf_cmp()` with
`buf_eq()`, so a96a0a4 needs to be
adjusted.

Change-Id: I97f6a3518db9421dab2ae4dd2312f443e928b114
  • Loading branch information
en-sc committed Oct 3, 2024
2 parents 841b61a + 1173473 commit ec00140
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 158 deletions.
2 changes: 1 addition & 1 deletion doc/openocd.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ the port @var{number} defaults to 6666.
When specified as "disabled", this service is not activated.
@end deffn

@deffn {Config Command} {telnet_port} [number]
@deffn {Config Command} {telnet port} [number]
Specify or query the
port on which to listen for incoming telnet connections.
This port is intended for interaction with one human through TCL commands.
Expand Down
30 changes: 30 additions & 0 deletions src/flash/nor/atsame5.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
#define SAME_SERIES_51 0x01
#define SAME_SERIES_53 0x03
#define SAME_SERIES_54 0x04
#define PIC32CXSG_SERIES_41 0x07
#define PIC32CXSG_SERIES_60 0x00
#define PIC32CXSG_SERIES_61 0x02

/* Device ID macros */
#define SAMD_GET_PROCESSOR(id) (id >> 28)
Expand Down Expand Up @@ -148,6 +151,27 @@ static const struct samd_part same54_parts[] = {
{ 0x03, "SAME54N19A", 512, 192 },
};

/* See PIC32CX SG41/SG60/SG61 Family Silicon Errata and Datasheet Clarifications
* DS80000985G */
/* Known PIC32CX-SG41 parts. */
static const struct samd_part pic32cxsg41_parts[] = {
{ 0x00, "PIC32CX1025SG41128", 1024, 256 },
{ 0x01, "PIC32CX1025SG41100", 1024, 256 },
{ 0x02, "PIC32CX1025SG41064", 1024, 256 },
};

/* Known PIC32CX-SG60 parts. */
static const struct samd_part pic32cxsg60_parts[] = {
{ 0x00, "PIC32CX1025SG60128", 1024, 256 },
{ 0x01, "PIC32CX1025SG60100", 1024, 256 },
};

/* Known PIC32CX-SG61 parts. */
static const struct samd_part pic32cxsg61_parts[] = {
{ 0x00, "PIC32CX1025SG61128", 1024, 256 },
{ 0x01, "PIC32CX1025SG61100", 1024, 256 },
};

/* Each family of parts contains a parts table in the DEVSEL field of DID. The
* processor ID, family ID, and series ID are used to determine which exact
* family this is and then we can use the corresponding table. */
Expand All @@ -169,6 +193,12 @@ static const struct samd_family samd_families[] = {
same53_parts, ARRAY_SIZE(same53_parts) },
{ SAMD_PROCESSOR_M4, SAMD_FAMILY_E, SAME_SERIES_54,
same54_parts, ARRAY_SIZE(same54_parts) },
{ SAMD_PROCESSOR_M4, SAMD_FAMILY_E, PIC32CXSG_SERIES_41,
pic32cxsg41_parts, ARRAY_SIZE(pic32cxsg41_parts) },
{ SAMD_PROCESSOR_M4, SAMD_FAMILY_E, PIC32CXSG_SERIES_60,
pic32cxsg60_parts, ARRAY_SIZE(pic32cxsg60_parts) },
{ SAMD_PROCESSOR_M4, SAMD_FAMILY_E, PIC32CXSG_SERIES_61,
pic32cxsg61_parts, ARRAY_SIZE(pic32cxsg61_parts) },
};

struct samd_info {
Expand Down
30 changes: 15 additions & 15 deletions src/helper/binarybuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,49 @@ void *buf_cpy(const void *from, void *_to, unsigned size)
return _to;
}

static bool buf_cmp_masked(uint8_t a, uint8_t b, uint8_t m)
static bool buf_eq_masked(uint8_t a, uint8_t b, uint8_t m)
{
return (a & m) != (b & m);
return (a & m) == (b & m);
}
static bool buf_cmp_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned trailing)
static bool buf_eq_trailing(uint8_t a, uint8_t b, uint8_t m, unsigned trailing)
{
uint8_t mask = (1 << trailing) - 1;
return buf_cmp_masked(a, b, mask & m);
return buf_eq_masked(a, b, mask & m);
}

bool buf_cmp(const void *_buf1, const void *_buf2, unsigned size)
bool buf_eq(const void *_buf1, const void *_buf2, unsigned size)
{
if (!_buf1 || !_buf2)
return _buf1 != _buf2;
return _buf1 == _buf2;

unsigned last = size / 8;
if (memcmp(_buf1, _buf2, last) != 0)
return true;
return false;

unsigned trailing = size % 8;
if (!trailing)
return false;
return true;

const uint8_t *buf1 = _buf1, *buf2 = _buf2;
return buf_cmp_trailing(buf1[last], buf2[last], 0xff, trailing);
return buf_eq_trailing(buf1[last], buf2[last], 0xff, trailing);
}

bool buf_cmp_mask(const void *_buf1, const void *_buf2,
bool buf_eq_mask(const void *_buf1, const void *_buf2,
const void *_mask, unsigned size)
{
if (!_buf1 || !_buf2)
return _buf1 != _buf2 || _buf1 != _mask;
return _buf1 == _buf2 && _buf1 == _mask;

const uint8_t *buf1 = _buf1, *buf2 = _buf2, *mask = _mask;
unsigned last = size / 8;
for (unsigned i = 0; i < last; i++) {
if (buf_cmp_masked(buf1[i], buf2[i], mask[i]))
return true;
if (!buf_eq_masked(buf1[i], buf2[i], mask[i]))
return false;
}
unsigned trailing = size % 8;
if (!trailing)
return false;
return buf_cmp_trailing(buf1[last], buf2[last], mask[last], trailing);
return true;
return buf_eq_trailing(buf1[last], buf2[last], mask[last], trailing);
}

void *buf_set_ones(void *_buf, unsigned size)
Expand Down
4 changes: 2 additions & 2 deletions src/helper/binarybuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ static inline uint64_t buf_get_u64(const uint8_t *_buffer,
*/
uint32_t flip_u32(uint32_t value, unsigned width);

bool buf_cmp(const void *buf1, const void *buf2, unsigned size);
bool buf_cmp_mask(const void *buf1, const void *buf2,
bool buf_eq(const void *buf1, const void *buf2, unsigned size);
bool buf_eq_mask(const void *buf1, const void *buf2,
const void *mask, unsigned size);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/jtag/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,9 @@ static int jtag_check_value_inner(uint8_t *captured, uint8_t *in_check_value,
int compare_failed;

if (in_check_mask)
compare_failed = buf_cmp_mask(captured, in_check_value, in_check_mask, num_bits);
compare_failed = !buf_eq_mask(captured, in_check_value, in_check_mask, num_bits);
else
compare_failed = buf_cmp(captured, in_check_value, num_bits);
compare_failed = !buf_eq(captured, in_check_value, num_bits);

if (compare_failed) {
char *captured_str, *in_check_value_str;
Expand Down
54 changes: 8 additions & 46 deletions src/rtos/nuttx.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
struct nuttx_params {
const char *target_name;
const struct rtos_register_stacking *stacking;
const struct rtos_register_stacking *(*select_stackinfo)(struct target *target);
};

/*
Expand All @@ -56,19 +55,12 @@ struct symbols {
bool optional;
};

/* Used to index the list of retrieved symbols. See nuttx_symbol_list for the order. */
enum nuttx_symbol_vals {
NX_SYM_READYTORUN = 0,
NX_SYM_PIDHASH,
NX_SYM_NPIDHASH,
NX_SYM_TCB_INFO,
};

static const struct symbols nuttx_symbol_list[] = {
{ "g_readytorun", false },
{ "g_pidhash", false },
{ "g_npidhash", false },
{ "g_tcbinfo", false },
{ "g_reg_offs", false},
{ NULL, false }
};

Expand All @@ -86,18 +78,14 @@ static char *task_state_str[] = {
"STOPPED",
};

static const struct rtos_register_stacking *cortexm_select_stackinfo(struct target *target);

static const struct nuttx_params nuttx_params_list[] = {
{
.target_name = "cortex_m",
.stacking = NULL,
.select_stackinfo = cortexm_select_stackinfo,
.stacking = &nuttx_stacking_cortex_m,
},
{
.target_name = "hla_target",
.stacking = NULL,
.select_stackinfo = cortexm_select_stackinfo,
.stacking = &nuttx_stacking_cortex_m,
},
{
.target_name = "esp32",
Expand All @@ -117,28 +105,6 @@ static const struct nuttx_params nuttx_params_list[] = {
},
};

static bool cortexm_hasfpu(struct target *target)
{
uint32_t cpacr;
struct armv7m_common *armv7m_target = target_to_armv7m(target);

if (!is_armv7m(armv7m_target) || armv7m_target->fp_feature == FP_NONE)
return false;

int retval = target_read_u32(target, FPU_CPACR, &cpacr);
if (retval != ERROR_OK) {
LOG_ERROR("Could not read CPACR register to check FPU state");
return false;
}

return cpacr & 0x00F00000;
}

static const struct rtos_register_stacking *cortexm_select_stackinfo(struct target *target)
{
return cortexm_hasfpu(target) ? &nuttx_stacking_cortex_m_fpu : &nuttx_stacking_cortex_m;
}

static bool nuttx_detect_rtos(struct target *target)
{
if (target->rtos->symbols &&
Expand Down Expand Up @@ -371,29 +337,25 @@ static int nuttx_getreg_current_thread(struct rtos *rtos,
static int nuttx_getregs_fromstack(struct rtos *rtos, int64_t thread_id,
struct rtos_reg **reg_list, int *num_regs)
{
uint16_t xcpreg_off;
uint16_t regs_off;
uint32_t regsaddr;
const struct nuttx_params *priv = rtos->rtos_specific_params;
const struct rtos_register_stacking *stacking = priv->stacking;

if (!stacking) {
if (priv->select_stackinfo) {
stacking = priv->select_stackinfo(rtos->target);
} else {
LOG_ERROR("Can't find a way to get stacking info");
return ERROR_FAIL;
}
LOG_ERROR("Can't find a way to get stacking info");
return ERROR_FAIL;
}

int ret = target_read_u16(rtos->target,
rtos->symbols[NX_SYM_TCB_INFO].address + offsetof(struct tcbinfo, regs_off),
&xcpreg_off);
&regs_off);
if (ret != ERROR_OK) {
LOG_ERROR("Failed to read registers' offset: ret = %d", ret);
return ERROR_FAIL;
}

ret = target_read_u32(rtos->target, thread_id + xcpreg_off, &regsaddr);
ret = target_read_u32(rtos->target, thread_id + regs_off, &regsaddr);
if (ret != ERROR_OK) {
LOG_ERROR("Failed to read registers' address: ret = %d", ret);
return ERROR_FAIL;
Expand Down
Loading

0 comments on commit ec00140

Please sign in to comment.