Skip to content

Commit

Permalink
Fixed register name parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Beer committed May 22, 2010
1 parent 39b71c5 commit ea7be28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
13 changes: 5 additions & 8 deletions devcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,14 @@ static int cmd_set(cproc_t cp, char **arg)
return -1;
}

while (*reg_text && !isdigit(*reg_text))
reg_text++;
reg = atoi(reg_text);

if (expr_eval(stab, val_text, &value) < 0) {
fprintf(stderr, "set: can't parse value: %s\n", val_text);
reg = dis_reg_from_name(reg_text);
if (reg < 0) {
fprintf(stderr, "set: unknown register: %s\n", reg_text);
return -1;
}

if (reg < 0 || reg >= DEVICE_NUM_REGS) {
fprintf(stderr, "set: register out of range: %d\n", reg);
if (expr_eval(stab, val_text, &value) < 0) {
fprintf(stderr, "set: can't parse value: %s\n", val_text);
return -1;
}

Expand Down
29 changes: 15 additions & 14 deletions dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ const char *dis_opcode_name(msp430_op_t op)
return NULL;
}

msp430_op_t dis_opcode_from_name(const char *name)
int dis_opcode_from_name(const char *name)
{
int i;

Expand All @@ -544,19 +544,9 @@ static const char *const msp430_reg_names[] = {
"R12", "R13", "R14", "R15"
};

msp430_reg_t dis_reg_from_name(const char *name)
int dis_reg_from_name(const char *name)
{
const char *num = name;

while (num && isdigit(*num))
num++;

if (*num) {
msp430_reg_t r = atoi(num);

if (r >= 0 && r <= 15)
return r;
}
int i;

if (!strcasecmp(name, "pc"))
return 0;
Expand All @@ -565,7 +555,18 @@ msp430_reg_t dis_reg_from_name(const char *name)
if (!strcasecmp(name, "sr"))
return 2;

return -1;
if (toupper(*name) == 'R')
name++;

for (i = 0; name[i]; i++)
if (!isdigit(name[i]))
return -1;

i = atoi(name);
if (i < 0 || i > 15)
return -1;

return i;
}

const char *dis_reg_name(msp430_reg_t reg)
Expand Down
4 changes: 2 additions & 2 deletions dis.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ int dis_decode(const uint8_t *code,
struct msp430_instruction *insn);

/* Look up names for registers and opcodes */
msp430_op_t dis_opcode_from_name(const char *name);
int dis_opcode_from_name(const char *name);
const char *dis_opcode_name(msp430_op_t op);
msp430_reg_t dis_reg_from_name(const char *name);
int dis_reg_from_name(const char *name);
const char *dis_reg_name(msp430_reg_t reg);

#endif
15 changes: 10 additions & 5 deletions rtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static int isearch_opcode(cproc_t cp, const char *term, char **arg,
struct isearch_query *q)
{
const char *opname = get_arg(arg);
int opc;

if (q->flags & ISEARCH_OPCODE) {
fprintf(stderr, "isearch: opcode already specified\n");
Expand All @@ -65,11 +66,12 @@ static int isearch_opcode(cproc_t cp, const char *term, char **arg,
return -1;
}

q->insn.op = dis_opcode_from_name(opname);
if (q->insn.op < 0) {
opc = dis_opcode_from_name(opname);
if (opc < 0) {
fprintf(stderr, "isearch: unknown opcode: %s\n", opname);
return -1;
}
q->insn.op = opc;

q->flags |= ISEARCH_OPCODE;
return 0;
Expand Down Expand Up @@ -170,9 +172,12 @@ static int isearch_reg(cproc_t cp, const char *term, char **arg,
return -1;
}

while (*reg_text && !isdigit(*reg_text))
reg_text++;
reg = atoi(reg_text);
reg = dis_reg_from_name(reg_text);
if (reg < 0) {
fprintf(stderr, "isearch: unknown register: %s\n",
reg_text);
return -1;
}

q->flags |= which;
if (which == ISEARCH_SRC_REG)
Expand Down

0 comments on commit ea7be28

Please sign in to comment.