jlink-nuttx: update regs as nuttx regs save path change

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
This commit is contained in:
zhuyanlin 2022-03-29 17:40:57 +08:00 committed by Abdelatif Guettouche
parent 6a761ff087
commit df6985e2bf

View File

@ -97,7 +97,9 @@ begin_packed_struct struct tcbinfo_s
uint16_t state_off; uint16_t state_off;
uint16_t pri_off; uint16_t pri_off;
uint16_t name_off; uint16_t name_off;
uint16_t reg_num; uint16_t regs_off;
uint16_t basic_num;
uint16_t total_num;
begin_packed_struct begin_packed_struct
union union
{ {
@ -156,6 +158,7 @@ struct plugin_priv_s
{ {
uint32_t *pidhash; uint32_t *pidhash;
uint32_t npidhash; uint32_t npidhash;
uint32_t *regsaddr;
struct tcbinfo_s *tcbinfo; struct tcbinfo_s *tcbinfo;
uint16_t running; uint16_t running;
uint32_t ntcb; uint32_t ntcb;
@ -215,10 +218,9 @@ static int get_pid(struct plugin_priv_s *priv, uint32_t idx,
if (ret != 0) if (ret != 0)
{ {
PERROR("read %d pid error return %d\n", idx, ret); PERROR("read %d pid error return %d\n", idx, ret);
return ret;
} }
return 0; return ret;
} }
static int get_idx_from_pid(struct plugin_priv_s *priv, static int get_idx_from_pid(struct plugin_priv_s *priv,
@ -230,9 +232,10 @@ static int get_idx_from_pid(struct plugin_priv_s *priv,
{ {
uint32_t tmppid; uint32_t tmppid;
if (get_pid(priv, idx, &tmppid)) int ret = get_pid(priv, idx, &tmppid);
if (ret != 0)
{ {
return -1; return ret;
} }
if (tmppid == pid) if (tmppid == pid)
@ -241,16 +244,25 @@ static int get_idx_from_pid(struct plugin_priv_s *priv,
} }
} }
return -1; return -ENOENT;
} }
static int setget_reg(struct plugin_priv_s *priv, uint32_t idx, static int setget_reg(struct plugin_priv_s *priv, uint32_t idx,
uint32_t regidx, uint32_t *regval, bool write) uint32_t regidx, uint32_t *regval, bool write)
{ {
uint32_t regaddr; uint32_t regaddr;
int ret = 0;
regaddr = priv->pidhash[idx] + priv->tcbinfo->reg_offs[regidx]; if (priv->tcbinfo->reg_offs[regidx] == UINT16_MAX)
{
if (write == 0)
{
*regval = 0;
}
return 0;
}
regaddr = priv->regsaddr[idx] + priv->tcbinfo->reg_offs[regidx];
if (write) if (write)
{ {
@ -258,7 +270,7 @@ static int setget_reg(struct plugin_priv_s *priv, uint32_t idx,
} }
else else
{ {
ret = READU32(regaddr, regval); int ret = READU32(regaddr, regval);
if (ret != 0) if (ret != 0)
{ {
PERROR("regread %d regidx %d error %d\n", idx, regidx, ret); PERROR("regread %d regidx %d error %d\n", idx, regidx, ret);
@ -266,35 +278,40 @@ static int setget_reg(struct plugin_priv_s *priv, uint32_t idx,
} }
} }
return ret; return 0;
} }
static int update_tcbinfo(struct plugin_priv_s *priv) static int update_tcbinfo(struct plugin_priv_s *priv)
{ {
if (!priv->tcbinfo) if (!priv->tcbinfo)
{ {
uint16_t reg_num; uint16_t total_num;
int ret;
uint32_t reg_off; uint32_t reg_off;
int ret;
ret = READU16(g_symbols[TCBINFO].address + ret = READU16(g_symbols[TCBINFO].address +
offsetof(struct tcbinfo_s, reg_num), &reg_num); offsetof(struct tcbinfo_s, total_num), &total_num);
if (ret != 0 || !reg_num) if (ret != 0)
{ {
PERROR("error reading regs ret %d\n", ret); PERROR("error reading regs ret %d\n", ret);
return ret; return ret;
} }
if (!total_num)
{
return -EIO;
}
ret = READU32(g_symbols[TCBINFO].address + ret = READU32(g_symbols[TCBINFO].address +
offsetof(struct tcbinfo_s, reg_off), &reg_off); offsetof(struct tcbinfo_s, reg_off), &reg_off);
if (ret != 0 || !reg_off) if (ret != 0)
{ {
PERROR("error in read regoffs address ret %d\n", ret); PERROR("error in read regoffs address ret %d\n", ret);
return ret; return ret;
} }
priv->tcbinfo = ALLOC(sizeof(struct tcbinfo_s) + priv->tcbinfo = ALLOC(sizeof(struct tcbinfo_s) +
reg_num * sizeof(uint16_t)); total_num * sizeof(uint16_t));
if (!priv->tcbinfo) if (!priv->tcbinfo)
{ {
@ -311,14 +328,12 @@ static int update_tcbinfo(struct plugin_priv_s *priv)
} }
ret = READMEM(reg_off, (char *)&priv->tcbinfo->reg_offs[0], ret = READMEM(reg_off, (char *)&priv->tcbinfo->reg_offs[0],
reg_num * sizeof(uint16_t)); total_num * sizeof(uint16_t));
if (ret != reg_num * sizeof(uint16_t)) if (ret != total_num * sizeof(uint16_t))
{ {
PERROR("error in read tcbinfo_s reg_offs ret %d\n", ret); PERROR("error in read tcbinfo_s reg_offs ret %d\n", ret);
return ret; return ret;
} }
PLOG("setup success! regs %d\n", priv->tcbinfo->reg_num);
} }
return 0; return 0;
@ -329,6 +344,7 @@ static int update_pidhash(struct plugin_priv_s *priv)
uint32_t npidhash; uint32_t npidhash;
uint32_t pidhashaddr; uint32_t pidhashaddr;
int ret; int ret;
int i;
ret = READU32(g_symbols[NPIDHASH].address, &npidhash); ret = READU32(g_symbols[NPIDHASH].address, &npidhash);
if (ret != 0 || npidhash == 0) if (ret != 0 || npidhash == 0)
@ -347,6 +363,14 @@ static int update_pidhash(struct plugin_priv_s *priv)
return -ENOMEM; return -ENOMEM;
} }
priv->regsaddr =
REALLOC(priv->regsaddr, npidhash * sizeof(uint32_t *));
if (!priv->regsaddr)
{
PERROR("error in malloc regsaddr\n");
return -ENOMEM;
}
PLOG("npidhash change from %d to %d!\n", priv->npidhash, npidhash); PLOG("npidhash change from %d to %d!\n", priv->npidhash, npidhash);
priv->npidhash = npidhash; priv->npidhash = npidhash;
} }
@ -366,6 +390,20 @@ static int update_pidhash(struct plugin_priv_s *priv)
return ret; return ret;
} }
for (i = 0; i < priv->npidhash; i++)
{
if (priv->pidhash[i])
{
ret = READU32(priv->pidhash[i] + priv->tcbinfo->regs_off,
&priv->regsaddr[i]);
if (ret != 0)
{
PERROR("error in task %d read regs pointer %d\n", i, ret);
return ret;
}
}
}
return 0; return 0;
} }
@ -381,7 +419,9 @@ static int normalize_tcb(struct plugin_priv_s *priv)
{ {
if (priv->pidhash[i]) if (priv->pidhash[i])
{ {
priv->pidhash[priv->ntcb++] = priv->pidhash[i]; priv->pidhash[priv->ntcb] = priv->pidhash[i];
priv->regsaddr[priv->ntcb] = priv->regsaddr[i];
priv->ntcb++;
} }
} }
@ -389,6 +429,7 @@ static int normalize_tcb(struct plugin_priv_s *priv)
if (ret != 0) if (ret != 0)
{ {
PERROR("read readytorun error return %d\n", ret); PERROR("read readytorun error return %d\n", ret);
return ret;
} }
ret = READU16(tcbaddr + priv->tcbinfo->pid_off, &priv->running); ret = READU16(tcbaddr + priv->tcbinfo->pid_off, &priv->running);
@ -491,7 +532,7 @@ int RTOS_GetThreadDisplay(char *display, uint32_t threadid)
if (idx < 0) if (idx < 0)
{ {
PERROR("error in get_idx_from_pid return %d\n", idx); PERROR("error in get_idx_from_pid return %d\n", idx);
return -1; return idx;
} }
len += snprintf(display + len, len += snprintf(display + len,
@ -544,6 +585,7 @@ int RTOS_GetThreadDisplay(char *display, uint32_t threadid)
int RTOS_GetThreadReg(char *hexregval, uint32_t regindex, uint32_t threadid) int RTOS_GetThreadReg(char *hexregval, uint32_t regindex, uint32_t threadid)
{ {
int idx; int idx;
int ret;
uint32_t regval = 0; uint32_t regval = 0;
threadid -= THREADID_BASE; threadid -= THREADID_BASE;
@ -552,30 +594,29 @@ int RTOS_GetThreadReg(char *hexregval, uint32_t regindex, uint32_t threadid)
if (threadid == g_plugin_priv.running) if (threadid == g_plugin_priv.running)
{ {
return -1; return -ENOTSUP;
} }
if (regindex > g_plugin_priv.tcbinfo->reg_num) if (regindex > g_plugin_priv.tcbinfo->total_num)
{ {
return -1; return -EINVAL;
} }
idx = get_idx_from_pid(&g_plugin_priv, threadid); idx = get_idx_from_pid(&g_plugin_priv, threadid);
if (idx < 0) if (idx < 0)
{ {
PERROR("error in get_idx_from_pid return %d\n", idx); PERROR("error in get_idx_from_pid return %d\n", idx);
return -1; return idx;
} }
if (g_plugin_priv.tcbinfo->reg_offs[regindex]) ret = setget_reg(&g_plugin_priv, idx, regindex, &regval, false);
if (ret != 0)
{ {
setget_reg(&g_plugin_priv, idx, regindex, &regval, false); return ret;
encode_hex(hexregval, regval);
return 0;
} }
return -1; encode_hex(hexregval, regval);
return 0;
} }
int RTOS_GetThreadRegList(char *hexreglist, uint32_t threadid) int RTOS_GetThreadRegList(char *hexreglist, uint32_t threadid)
@ -590,23 +631,24 @@ int RTOS_GetThreadRegList(char *hexreglist, uint32_t threadid)
if (threadid == g_plugin_priv.running) if (threadid == g_plugin_priv.running)
{ {
return -1; return -ENOTSUP;
} }
idx = get_idx_from_pid(&g_plugin_priv, threadid); idx = get_idx_from_pid(&g_plugin_priv, threadid);
if (idx < 0) if (idx < 0)
{ {
PERROR("error in get_idx_from_pid return %d\n", idx); PERROR("error in get_idx_from_pid return %d\n", idx);
return -1; return idx;
} }
for (j = 0; j < 17; j++) for (j = 0; j < g_plugin_priv.tcbinfo->basic_num; j++)
{ {
regval = 0; regval = 0;
if (g_plugin_priv.tcbinfo->reg_offs[j]) int ret = setget_reg(&g_plugin_priv, idx, j, &regval, false);
if (ret != 0)
{ {
setget_reg(&g_plugin_priv, idx, j, &regval, false); return ret;
} }
hexreglist += encode_hex(hexreglist, regval); hexreglist += encode_hex(hexreglist, regval);
@ -625,30 +667,24 @@ int RTOS_SetThreadReg(char *hexregval,
if (threadid == g_plugin_priv.running) if (threadid == g_plugin_priv.running)
{ {
return -1; return -ENOTSUP;
} }
if (regindex > g_plugin_priv.tcbinfo->reg_num) if (regindex > g_plugin_priv.tcbinfo->total_num)
{ {
return -1; return -EINVAL;
} }
idx = get_idx_from_pid(&g_plugin_priv, threadid); idx = get_idx_from_pid(&g_plugin_priv, threadid);
if (idx < 0) if (idx < 0)
{ {
PERROR("error in get_idx_from_pid return %d\n", idx); PERROR("error in get_idx_from_pid return %d\n", idx);
return -1; return idx;
} }
if (g_plugin_priv.tcbinfo->reg_offs[regindex]) regval = decode_hex(hexregval);
{
regval = decode_hex(hexregval);
setget_reg(&g_plugin_priv, idx, regindex, &regval, true); return setget_reg(&g_plugin_priv, idx, regindex, &regval, true);
return 0;
}
return -1;
} }
int RTOS_SetThreadRegList(char *hexreglist, uint32_t threadid) int RTOS_SetThreadRegList(char *hexreglist, uint32_t threadid)
@ -661,30 +697,27 @@ int RTOS_SetThreadRegList(char *hexreglist, uint32_t threadid)
if (threadid == g_plugin_priv.running) if (threadid == g_plugin_priv.running)
{ {
return -1; return -ENOTSUP;
} }
idx = get_idx_from_pid(&g_plugin_priv, threadid); idx = get_idx_from_pid(&g_plugin_priv, threadid);
if (idx < 0) if (idx < 0)
{ {
PERROR("error in get_idx_from_pid return %d\n", idx); PERROR("error in get_idx_from_pid return %d\n", idx);
return -1; return idx;
} }
for (j = 0; j < 17; j++) for (j = 0; j < g_plugin_priv.tcbinfo->basic_num; j++)
{ {
if (g_plugin_priv.tcbinfo->reg_offs[j]) regval = decode_hex(hexreglist);
{
regval = decode_hex(hexreglist);
setget_reg(&g_plugin_priv, idx, j, &regval, true); int ret = setget_reg(&g_plugin_priv, idx, j, &regval, true);
if (ret != 0)
hexreglist += 4;
}
else
{ {
return -1; return ret;
} }
hexreglist += 4;
} }
return 0; return 0;