Symbol table and address expressions are now 32-bit clean.

This commit is contained in:
Daniel Beer 2010-08-05 13:59:33 +12:00
parent 622396a1c1
commit 137329cc13
11 changed files with 68 additions and 64 deletions

View File

@ -66,7 +66,7 @@ struct cproc_option {
union {
char text[128];
int numeric;
address_t numeric;
} data;
};

View File

@ -28,7 +28,7 @@ static int format_addr(stab_t stab, char *buf, int max_len,
msp430_amode_t amode, uint16_t addr)
{
char name[64];
uint16_t offset;
address_t offset;
int numeric = 0;
const char *prefix = "";
@ -193,7 +193,7 @@ void cproc_disassemble(cproc_t cp,
int retval;
int count;
int i;
uint16_t oboff;
address_t oboff;
char obname[64];
char buf[256];
int len = 0;

View File

@ -58,8 +58,8 @@ static int cmd_md(cproc_t cp, char **arg)
device_t dev = cproc_device(cp);
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
int offset = 0;
int length = 0x40;
address_t offset = 0;
address_t length = 0x40;
if (!off_text) {
fprintf(stderr, "md: offset must be specified\n");
@ -107,8 +107,8 @@ static int cmd_mw(cproc_t cp, char **arg)
stab_t stab = cproc_stab(cp);
char *off_text = get_arg(arg);
char *byte_text;
int offset = 0;
int length = 0;
address_t offset = 0;
address_t length = 0;
uint8_t buf[1024];
if (!off_text) {
@ -236,7 +236,7 @@ static int cmd_set(cproc_t cp, char **arg)
char *reg_text = get_arg(arg);
char *val_text = get_arg(arg);
int reg;
int value = 0;
address_t value = 0;
uint16_t regs[DEVICE_NUM_REGS];
if (!(reg_text && val_text)) {
@ -271,8 +271,8 @@ static int cmd_dis(cproc_t cp, char **arg)
stab_t stab = cproc_stab(cp);
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
int offset = 0;
int length = 0x40;
address_t offset = 0;
address_t length = 0x40;
uint8_t buf[4096];
if (!off_text) {
@ -397,8 +397,8 @@ static int cmd_hexout(cproc_t cp, char **arg)
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
char *filename = *arg;
int off;
int length;
address_t off;
address_t length;
struct hexout_data hexout;
if (!(off_text && len_text && *filename)) {
@ -583,7 +583,7 @@ static int cmd_setbreak(cproc_t cp, char **arg)
char *addr_text = get_arg(arg);
char *index_text = get_arg(arg);
int index = -1;
int addr;
address_t addr;
if (!addr_text) {
fprintf(stderr, "setbreak: address required\n");
@ -656,7 +656,7 @@ static int cmd_break(cproc_t cp, char **arg)
if (bp->flags & DEVICE_BP_ENABLED) {
char name[128];
uint16_t offset;
address_t offset;
printf(" %d. 0x%04x", i, bp->addr);
if (!stab_nearest(stab, bp->addr, name,

23
expr.c
View File

@ -33,17 +33,17 @@
*/
struct addr_exp_state {
int last_operator;
int data_stack[32];
int data_stack_size;
int op_stack[32];
int op_stack_size;
int last_operator;
address_t data_stack[32];
int data_stack_size;
int op_stack[32];
int op_stack_size;
};
static int addr_exp_data(stab_t stab,
struct addr_exp_state *s, const char *text)
{
int value;
address_t value;
if (!s->last_operator || s->last_operator == ')') {
fprintf(stderr, "syntax error at token %s\n", text);
@ -73,10 +73,9 @@ static int addr_exp_data(stab_t stab,
static int addr_exp_pop(struct addr_exp_state *s)
{
char op = s->op_stack[--s->op_stack_size];
int data1 = s->data_stack[--s->data_stack_size];
int data2 = 0;
int result = 0;
address_t data1 = s->data_stack[--s->data_stack_size];
address_t data2 = 0;
address_t result = 0;
if (op != 'N')
data2 = s->data_stack[--s->data_stack_size];
@ -197,7 +196,7 @@ static int addr_exp_op(struct addr_exp_state *s, char op)
return -1;
}
static int addr_exp_finish(struct addr_exp_state *s, int *ret)
static int addr_exp_finish(struct addr_exp_state *s, address_t *ret)
{
if (s->last_operator && s->last_operator != ')') {
fprintf(stderr, "syntax error at end of expression\n");
@ -226,7 +225,7 @@ static int addr_exp_finish(struct addr_exp_state *s, int *ret)
return 0;
}
int expr_eval(stab_t stab, const char *text, int *addr)
int expr_eval(stab_t stab, const char *text, address_t *addr)
{
const char *text_save = text;
int last_cc = 1;

2
expr.h
View File

@ -25,6 +25,6 @@
/* Parse an address expression, storing the result in the integer
* pointed to. Returns 0 if parsed successfully, -1 if not.
*/
int expr_eval(stab_t stab, const char *text, int *value);
int expr_eval(stab_t stab, const char *text, address_t *value);
#endif

15
main.c
View File

@ -51,20 +51,21 @@ static void io_prefix(stab_t stab,
uint16_t addr, int is_byte)
{
char name[64];
address_t offset;
if (!stab_nearest(stab, pc, name, sizeof(name), &pc)) {
if (!stab_nearest(stab, pc, name, sizeof(name), &offset)) {
printf("%s", name);
if (pc)
printf("+0x%x", pc);
if (offset)
printf("+0x%x", offset);
} else {
printf("0x%04x", pc);
}
printf(": IO %s.%c: 0x%04x", prefix, is_byte ? 'B' : 'W', addr);
if (!stab_nearest(stab, addr, name, sizeof(name), &addr)) {
if (!stab_nearest(stab, addr, name, sizeof(name), &offset)) {
printf(" (%s", name);
if (addr)
printf("+0x%x", addr);
if (offset)
printf("+0x%x", offset);
printf(")");
}
}
@ -79,7 +80,7 @@ static int fetch_io(void *user_data, uint16_t pc,
for (;;) {
char text[128];
int len;
int data;
address_t data;
printf("? ");
fflush(stdout);

View File

@ -128,7 +128,7 @@ static int isearch_addr(cproc_t cp, const char *term, char **arg,
int which = toupper(*term) == 'S' ?
ISEARCH_SRC_ADDR : ISEARCH_DST_ADDR;
const char *addr_text;
int addr;
address_t addr;
if (q->flags & which) {
fprintf(stderr, "isearch: address already specified\n");
@ -392,8 +392,8 @@ static int cmd_isearch(cproc_t cp, char **arg)
struct isearch_query q;
const char *addr_text;
const char *len_text;
int addr;
int len;
address_t addr;
address_t len;
addr_text = get_arg(arg);
len_text = get_arg(arg);
@ -711,7 +711,7 @@ static int add_irq_edges(int offset, int len, uint8_t *memory,
}
static int add_symbol_nodes(void *user_data, const char *name,
uint16_t offset)
address_t offset)
{
struct call_graph *graph = (struct call_graph *)user_data;
@ -778,7 +778,7 @@ static void cgraph_summary(struct call_graph *graph, cproc_t cp)
int from_count = 0;
int to_count = 0;
char name[64];
uint16_t o;
address_t o;
while (j < graph->edge_from.size &&
CG_EDGE_FROM(graph, j)->src < n->offset)
@ -817,7 +817,7 @@ static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
int j = 0;
int k = 0;
char name[64];
u_int16_t offset;
address_t offset;
struct cg_node *n;
while (i + 1 < graph->node_list.size &&
@ -893,7 +893,7 @@ static int cmd_cgraph(cproc_t cp, char **arg)
stab_t stab = cproc_stab(cp);
device_t dev = cproc_device(cp);
char *offset_text, *len_text, *addr_text;;
int offset, len, addr;
address_t offset, len, addr;
uint8_t *memory;
struct call_graph graph;

22
stab.c
View File

@ -58,8 +58,8 @@ static void sym_key_init(struct sym_key *key, const char *text)
}
struct addr_key {
uint16_t addr;
char name[64];
address_t addr;
char name[64];
};
static const struct addr_key addr_key_zero = {
@ -80,7 +80,7 @@ static int addr_key_compare(const void *left, const void *right)
return strcmp(kl->name, kr->name);
}
static void addr_key_init(struct addr_key *key, uint16_t addr,
static void addr_key_init(struct addr_key *key, address_t addr,
const char *text)
{
int len = strlen(text);
@ -98,7 +98,7 @@ static const struct btree_def sym_table_def = {
.zero = &sym_key_zero,
.branches = 32,
.key_size = sizeof(struct sym_key),
.data_size = sizeof(uint16_t)
.data_size = sizeof(address_t)
};
static const struct btree_def addr_table_def = {
@ -128,8 +128,8 @@ int stab_set(stab_t st, const char *name, int value)
{
struct sym_key skey;
struct addr_key akey;
uint16_t addr = value;
uint16_t old_addr;
address_t addr = value;
address_t old_addr;
sym_key_init(&skey, name);
@ -152,8 +152,8 @@ int stab_set(stab_t st, const char *name, int value)
return 0;
}
int stab_nearest(stab_t st, uint16_t addr, char *ret_name, int max_len,
uint16_t *ret_offset)
int stab_nearest(stab_t st, address_t addr, char *ret_name, int max_len,
address_t *ret_offset)
{
struct addr_key akey;
int i;
@ -173,10 +173,10 @@ int stab_nearest(stab_t st, uint16_t addr, char *ret_name, int max_len,
return -1;
}
int stab_get(stab_t st, const char *name, int *value)
int stab_get(stab_t st, const char *name, address_t *value)
{
struct sym_key skey;
uint16_t addr;
address_t addr;
sym_key_init(&skey, name);
if (btree_get(st->sym, &skey, &addr))
@ -189,7 +189,7 @@ int stab_get(stab_t st, const char *name, int *value)
int stab_del(stab_t st, const char *name)
{
struct sym_key skey;
uint16_t value;
address_t value;
struct addr_key akey;
sym_key_init(&skey, name);

9
stab.h
View File

@ -20,6 +20,7 @@
#define STAB_H_
#include <stdint.h>
#include "util.h"
struct stab;
typedef struct stab *stab_t;
@ -41,13 +42,13 @@ int stab_set(stab_t st, const char *name, int value);
*
* Returns 0 if found, 1 otherwise.
*/
int stab_nearest(stab_t st, uint16_t addr, char *ret_name, int max_len,
uint16_t *ret_offset);
int stab_nearest(stab_t st, address_t addr, char *ret_name, int max_len,
address_t *ret_offset);
/* Retrieve the value of a symbol. Returns 0 on success or -1 if the symbol
* doesn't exist.
*/
int stab_get(stab_t st, const char *name, int *value);
int stab_get(stab_t st, const char *name, address_t *value);
/* Delete a symbol table entry. Returns 0 on success or -1 if the symbol
* doesn't exist.
@ -56,7 +57,7 @@ int stab_del(stab_t st, const char *name);
/* Enumerate all symbols in the table */
typedef int (*stab_callback_t)(void *user_data,
const char *name, uint16_t value);
const char *name, address_t value);
int stab_enum(stab_t st, stab_callback_t cb, void *user_data);

16
sym.c
View File

@ -33,8 +33,8 @@
static int cmd_eval(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
int addr;
uint16_t offset;
address_t addr;
address_t offset;
char name[64];
if (expr_eval(stab, *arg, &addr) < 0) {
@ -83,7 +83,7 @@ static int cmd_sym_load_add(cproc_t cp, int clear, char **arg)
return 0;
}
static int savemap_cb(void *user_data, const char *name, uint16_t value)
static int savemap_cb(void *user_data, const char *name, address_t value)
{
FILE *savemap_out = (FILE *)user_data;
@ -127,13 +127,13 @@ static int cmd_sym_savemap(cproc_t cp, char **arg)
return 0;
}
static int print_sym(void *user_data, const char *name, uint16_t value)
static int print_sym(void *user_data, const char *name, address_t value)
{
printf("0x%04x: %s\n", value, name);
return 0;
}
static int find_sym(void *user_data, const char *name, uint16_t value)
static int find_sym(void *user_data, const char *name, address_t value)
{
regex_t *find_preg = (regex_t *)user_data;
@ -185,7 +185,7 @@ static int renames_do(stab_t stab,
VECTOR_PTR(rename->list, i, struct rename_record);
char new_name[128];
int len = r->start;
int value;
address_t value;
if (len + 1 > sizeof(new_name))
len = sizeof(new_name) - 1;
@ -217,7 +217,7 @@ static int renames_do(stab_t stab,
return 0;
}
static int find_renames(void *user_data, const char *name, uint16_t value)
static int find_renames(void *user_data, const char *name, address_t value)
{
struct rename_data *rename = (struct rename_data *)user_data;
regmatch_t pmatch;
@ -317,7 +317,7 @@ static int cmd_sym(cproc_t cp, char **arg)
if (!strcasecmp(subcmd, "set")) {
char *name = get_arg(arg);
char *val_text = get_arg(arg);
int value;
address_t value;
if (!(name && val_text)) {
fprintf(stderr, "sym: need a name and value to set "

3
util.h
View File

@ -28,6 +28,9 @@
#define LE_WORD(b, x) ((LE_BYTE(b, x + 1) << 8) | LE_BYTE(b, x))
#define LE_LONG(b, x) ((LE_WORD(b, x + 2) << 16) | LE_WORD(b, x))
/* This type fits an MSP430X register value */
typedef uint32_t address_t;
/* Various utility functions for IO */
int open_serial(const char *device, int rate);
int read_with_timeout(int fd, uint8_t *data, int len);