Allow register names in address expressions.

This commit is contained in:
Ingo van Lil 2016-01-21 18:35:52 +01:00
parent a643a2e833
commit e4644f70aa
2 changed files with 30 additions and 5 deletions

View File

@ -732,10 +732,19 @@ Any command which accepts a memory address, length or register value
as an argument may be given an address expression. An address as an argument may be given an address expression. An address
expression consists of an algebraic combination of values. expression consists of an algebraic combination of values.
An address value may be either a symbol name, a hex value preceded An address value can be one of the following:
with the specifier "0x", a decimal value preceded with the specifier .RS
"0d", or a number in the default input radix (without a specifier). See A symbol name
the option \fBiradix\fR for more information. .br
A CPU register name preceded with "@"
.br
A hex value preceded with the specifier "0x"
.br
A decimal value preceded with the specifier "0d"
.br
A number in the default input radix (without a specifier). See the option
\fBiradix\fR for more information.
.RE
The operators recognised are the usual algebraic operators: \fB+\fR, \fB-\fR, The operators recognised are the usual algebraic operators: \fB+\fR, \fB-\fR,
\fB*\fR, \fB/\fR, \fB%\fR, \fB(\fR and \fB)\fR. Operator precedence is the \fB*\fR, \fB/\fR, \fB%\fR, \fB(\fR and \fB)\fR. Operator precedence is the
@ -751,6 +760,8 @@ The following are all valid examples of address expressions:
.B main+0x3f .B main+0x3f
.br .br
.B __bss_end-__bss_start .B __bss_end-__bss_start
.br
.B @sp
.SH OPTIONS .SH OPTIONS
MSPDebug's behaviour can be configured via the following variables: MSPDebug's behaviour can be configured via the following variables:
.IP "\fBcolor\fR (boolean)" .IP "\fBcolor\fR (boolean)"

View File

@ -29,6 +29,8 @@
#include "output.h" #include "output.h"
#include "opdb.h" #include "opdb.h"
#include "demangle.h" #include "demangle.h"
#include "device.h"
#include "dis.h"
/************************************************************************ /************************************************************************
* Address expression parsing. * Address expression parsing.
@ -56,6 +58,18 @@ static int addr_exp_data(struct addr_exp_state *s, const char *text)
value = strtoul(text + 2, NULL, 16); value = strtoul(text + 2, NULL, 16);
} else if (*text == '0' && text[1] == 'd') { } else if (*text == '0' && text[1] == 'd') {
value = atoi(text + 2); value = atoi(text + 2);
} else if (*text == '@') {
int reg = dis_reg_from_name(text + 1);
if (reg < 0) {
printc_err("invalid register: %s\n", text);
return -1;
}
address_t regs[DEVICE_NUM_REGS];
if (device_getregs(regs) < 0)
return -1;
value = regs[reg];
} else if (stab_get(text, &value) < 0) { } else if (stab_get(text, &value) < 0) {
char *end; char *end;
@ -252,7 +266,7 @@ int expr_eval(const char *text, address_t *addr)
else if (!*text || isspace(*text)) else if (!*text || isspace(*text))
cc = 2; cc = 2;
else if (isalnum(*text) || *text == '.' || *text == '_' || else if (isalnum(*text) || *text == '.' || *text == '_' ||
*text == '$' || *text == ':') *text == '$' || *text == ':' || *text == '@')
cc = 3; cc = 3;
else { else {
printc_err("illegal character in expression: %c\n", printc_err("illegal character in expression: %c\n",