Fixed register name parsing.

This commit is contained in:
Daniel Beer 2010-05-22 16:17:06 +12:00
parent 39b71c5292
commit ea7be28f18
4 changed files with 32 additions and 29 deletions

View File

@ -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;
}

29
dis.c
View File

@ -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;
@ -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;
@ -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)

4
dis.h
View File

@ -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

View File

@ -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");
@ -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;
@ -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)