Introduced device_* helper macros.
This commit is contained in:
parent
9a0173607e
commit
fdaf99a70e
49
devcmd.c
49
devcmd.c
|
@ -38,14 +38,14 @@ int cmd_regs(char **arg)
|
||||||
uint8_t code[16];
|
uint8_t code[16];
|
||||||
int len = sizeof(code);
|
int len = sizeof(code);
|
||||||
|
|
||||||
if (device_default->getregs(device_default, regs) < 0)
|
if (device_getregs(regs) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
show_regs(regs);
|
show_regs(regs);
|
||||||
|
|
||||||
/* Try to disassemble the instruction at PC */
|
/* Try to disassemble the instruction at PC */
|
||||||
if (len > 0x10000 - regs[0])
|
if (len > 0x10000 - regs[0])
|
||||||
len = 0x10000 - regs[0];
|
len = 0x10000 - regs[0];
|
||||||
if (device_default->readmem(device_default, regs[0], code, len) < 0)
|
if (device_readmem(regs[0], code, len) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
disassemble(regs[0], (uint8_t *)code, len);
|
disassemble(regs[0], (uint8_t *)code, len);
|
||||||
|
@ -85,8 +85,7 @@ int cmd_md(char **arg)
|
||||||
uint8_t buf[4096];
|
uint8_t buf[4096];
|
||||||
int blen = length > sizeof(buf) ? sizeof(buf) : length;
|
int blen = length > sizeof(buf) ? sizeof(buf) : length;
|
||||||
|
|
||||||
if (device_default->readmem(device_default,
|
if (device_readmem(offset, buf, blen) < 0)
|
||||||
offset, buf, blen) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
hexdump(offset, buf, blen);
|
hexdump(offset, buf, blen);
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ int cmd_mw(char **arg)
|
||||||
if (!length)
|
if (!length)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (device_default->writemem(device_default, offset, buf, length) < 0)
|
if (device_writemem(offset, buf, length) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -135,7 +134,7 @@ int cmd_mw(char **arg)
|
||||||
|
|
||||||
int cmd_reset(char **arg)
|
int cmd_reset(char **arg)
|
||||||
{
|
{
|
||||||
return device_default->ctl(device_default, DEVICE_CTL_RESET);
|
return device_ctl(DEVICE_CTL_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_erase(char **arg)
|
int cmd_erase(char **arg)
|
||||||
|
@ -167,11 +166,11 @@ int cmd_erase(char **arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_HALT) < 0)
|
if (device_ctl(DEVICE_CTL_HALT) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
printc("Erasing...\n");
|
printc("Erasing...\n");
|
||||||
return device_default->erase(device_default, type, segment);
|
return device_erase(type, segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_step(char **arg)
|
int cmd_step(char **arg)
|
||||||
|
@ -188,7 +187,7 @@ int cmd_step(char **arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_STEP) < 0)
|
if (device_ctl(DEVICE_CTL_STEP) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
reader_set_repeat("step");
|
reader_set_repeat("step");
|
||||||
|
@ -200,7 +199,7 @@ int cmd_run(char **arg)
|
||||||
device_status_t status;
|
device_status_t status;
|
||||||
address_t regs[DEVICE_NUM_REGS];
|
address_t regs[DEVICE_NUM_REGS];
|
||||||
|
|
||||||
if (device_default->getregs(device_default, regs) < 0) {
|
if (device_getregs(regs) < 0) {
|
||||||
printc_err("warning: device: can't fetch registers\n");
|
printc_err("warning: device: can't fetch registers\n");
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
|
@ -217,11 +216,11 @@ int cmd_run(char **arg)
|
||||||
if (i < device_default->max_breakpoints) {
|
if (i < device_default->max_breakpoints) {
|
||||||
printc("Stepping over breakpoint #%d at 0x%04x\n",
|
printc("Stepping over breakpoint #%d at 0x%04x\n",
|
||||||
i, regs[0]);
|
i, regs[0]);
|
||||||
device_default->ctl(device_default, DEVICE_CTL_STEP);
|
device_ctl(DEVICE_CTL_STEP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_RUN) < 0) {
|
if (device_ctl(DEVICE_CTL_RUN) < 0) {
|
||||||
printc_err("run: failed to start CPU\n");
|
printc_err("run: failed to start CPU\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +228,7 @@ int cmd_run(char **arg)
|
||||||
printc("Running. Press Ctrl+C to interrupt...\n");
|
printc("Running. Press Ctrl+C to interrupt...\n");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = device_default->poll(device_default);
|
status = device_poll();
|
||||||
} while (status == DEVICE_STATUS_RUNNING);
|
} while (status == DEVICE_STATUS_RUNNING);
|
||||||
|
|
||||||
if (status == DEVICE_STATUS_INTR)
|
if (status == DEVICE_STATUS_INTR)
|
||||||
|
@ -238,7 +237,7 @@ int cmd_run(char **arg)
|
||||||
if (status == DEVICE_STATUS_ERROR)
|
if (status == DEVICE_STATUS_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_HALT) < 0)
|
if (device_ctl(DEVICE_CTL_HALT) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return cmd_regs(NULL);
|
return cmd_regs(NULL);
|
||||||
|
@ -268,10 +267,10 @@ int cmd_set(char **arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->getregs(device_default, regs) < 0)
|
if (device_getregs(regs) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
regs[reg] = value;
|
regs[reg] = value;
|
||||||
if (device_default->setregs(device_default, regs) < 0)
|
if (device_setregs(regs) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
show_regs(regs);
|
show_regs(regs);
|
||||||
|
@ -312,8 +311,7 @@ int cmd_dis(char **arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->readmem(device_default,
|
if (device_readmem(offset, buf, length) < 0) {
|
||||||
offset, buf, length) < 0) {
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -457,8 +455,7 @@ int cmd_hexout(char **arg)
|
||||||
count = sizeof(buf);
|
count = sizeof(buf);
|
||||||
|
|
||||||
printc("Reading %4d bytes from 0x%04x...\n", count, off);
|
printc("Reading %4d bytes from 0x%04x...\n", count, off);
|
||||||
if (device_default->readmem(device_default,
|
if (device_readmem(off, buf, count) < 0) {
|
||||||
off, buf, count) < 0) {
|
|
||||||
pr_error("hexout: can't read memory");
|
pr_error("hexout: can't read memory");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -505,7 +502,7 @@ static int do_cmd_prog(char **arg, int prog_flags)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_HALT) < 0) {
|
if (device_ctl(DEVICE_CTL_HALT) < 0) {
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -527,7 +524,7 @@ static int do_cmd_prog(char **arg, int prog_flags)
|
||||||
if (prog_flush(&prog) < 0)
|
if (prog_flush(&prog) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_RESET) < 0) {
|
if (device_ctl(DEVICE_CTL_RESET) < 0) {
|
||||||
printc_err("prog: failed to reset after programming\n");
|
printc_err("prog: failed to reset after programming\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -664,7 +661,7 @@ int cmd_locka(char **arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->readmem(device_default, FCTL3, regval, 2) < 0) {
|
if (device_readmem(FCTL3, regval, 2) < 0) {
|
||||||
printc_err("locka: can't read FCTL3 register\n");
|
printc_err("locka: can't read FCTL3 register\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -681,14 +678,12 @@ int cmd_locka(char **arg)
|
||||||
regval[0] |= FCTL3_LOCKA;
|
regval[0] |= FCTL3_LOCKA;
|
||||||
regval[1] = FWKEY;
|
regval[1] = FWKEY;
|
||||||
|
|
||||||
if (device_default->writemem(device_default, FCTL3,
|
if (device_writemem(FCTL3, regval, 2) < 0) {
|
||||||
regval, 2) < 0) {
|
|
||||||
printc_err("locka: can't write FCTL3 register\n");
|
printc_err("locka: can't write FCTL3 register\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->readmem(device_default, FCTL3,
|
if (device_readmem(FCTL3, regval, 2) < 0) {
|
||||||
regval, 2) < 0) {
|
|
||||||
printc_err("locka: can't read FCTL3 register\n");
|
printc_err("locka: can't read FCTL3 register\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
21
device.h
21
device.h
|
@ -25,8 +25,6 @@
|
||||||
struct device;
|
struct device;
|
||||||
typedef struct device *device_t;
|
typedef struct device *device_t;
|
||||||
|
|
||||||
extern device_t device_default;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DEVICE_CTL_RESET,
|
DEVICE_CTL_RESET,
|
||||||
DEVICE_CTL_RUN,
|
DEVICE_CTL_RUN,
|
||||||
|
@ -101,4 +99,23 @@ struct device {
|
||||||
*/
|
*/
|
||||||
int device_setbrk(device_t dev, int which, int enabled, address_t address);
|
int device_setbrk(device_t dev, int which, int enabled, address_t address);
|
||||||
|
|
||||||
|
extern device_t device_default;
|
||||||
|
|
||||||
|
/* Helper macros for operating on the default device */
|
||||||
|
#define device_destroy() device_default->destroy(device_default)
|
||||||
|
#define device_readmem(addr, mem, len) \
|
||||||
|
device_default->readmem(device_default, addr, mem, len)
|
||||||
|
#define device_writemem(addr, mem, len) \
|
||||||
|
device_default->writemem(device_default, addr, mem, len)
|
||||||
|
#define device_erase(type, addr) \
|
||||||
|
device_default->erase(device_default, type, addr)
|
||||||
|
#define device_getregs(regs) \
|
||||||
|
device_default->getregs(device_default, regs)
|
||||||
|
#define device_setregs(regs) \
|
||||||
|
device_default->setregs(device_default, regs)
|
||||||
|
#define device_ctl(op) \
|
||||||
|
device_default->ctl(device_default, op)
|
||||||
|
#define device_poll() \
|
||||||
|
device_default->poll(device_default)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
gdb.c
22
gdb.c
|
@ -209,7 +209,7 @@ static int read_registers(struct gdb_data *data)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printc("Reading registers\n");
|
printc("Reading registers\n");
|
||||||
if (device_default->getregs(device_default, regs) < 0)
|
if (device_getregs(regs) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
gdb_packet_start(data);
|
gdb_packet_start(data);
|
||||||
|
@ -298,7 +298,7 @@ static int write_registers(struct gdb_data *data, char *buf)
|
||||||
buf += 4;
|
buf += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->setregs(device_default, regs) < 0)
|
if (device_setregs(regs) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
return gdb_send(data, "OK");
|
return gdb_send(data, "OK");
|
||||||
|
@ -326,7 +326,7 @@ static int read_memory(struct gdb_data *data, char *text)
|
||||||
|
|
||||||
printc("Reading %4d bytes from 0x%04x\n", length, addr);
|
printc("Reading %4d bytes from 0x%04x\n", length, addr);
|
||||||
|
|
||||||
if (device_default->readmem(device_default, addr, buf, length) < 0)
|
if (device_readmem(addr, buf, length) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
gdb_packet_start(data);
|
gdb_packet_start(data);
|
||||||
|
@ -369,7 +369,7 @@ static int write_memory(struct gdb_data *data, char *text)
|
||||||
|
|
||||||
printc("Writing %4d bytes to 0x%04x\n", length, addr);
|
printc("Writing %4d bytes to 0x%04x\n", length, addr);
|
||||||
|
|
||||||
if (device_default->writemem(device_default, addr, buf, buflen) < 0)
|
if (device_writemem(addr, buf, buflen) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
return gdb_send(data, "OK");
|
return gdb_send(data, "OK");
|
||||||
|
@ -382,11 +382,11 @@ static int run_set_pc(struct gdb_data *data, char *buf)
|
||||||
if (!*buf)
|
if (!*buf)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (device_default->getregs(device_default, regs) < 0)
|
if (device_getregs(regs) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
regs[0] = strtoul(buf, NULL, 16);
|
regs[0] = strtoul(buf, NULL, 16);
|
||||||
return device_default->setregs(device_default, regs);
|
return device_setregs(regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_final_status(struct gdb_data *data)
|
static int run_final_status(struct gdb_data *data)
|
||||||
|
@ -394,7 +394,7 @@ static int run_final_status(struct gdb_data *data)
|
||||||
address_t regs[DEVICE_NUM_REGS];
|
address_t regs[DEVICE_NUM_REGS];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (device_default->getregs(device_default, regs) < 0)
|
if (device_getregs(regs) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
gdb_packet_start(data);
|
gdb_packet_start(data);
|
||||||
|
@ -423,7 +423,7 @@ static int single_step(struct gdb_data *data, char *buf)
|
||||||
printc("Single stepping\n");
|
printc("Single stepping\n");
|
||||||
|
|
||||||
if (run_set_pc(data, buf) < 0 ||
|
if (run_set_pc(data, buf) < 0 ||
|
||||||
device_default->ctl(device_default, DEVICE_CTL_STEP) < 0)
|
device_ctl(DEVICE_CTL_STEP) < 0)
|
||||||
gdb_send(data, "E00");
|
gdb_send(data, "E00");
|
||||||
|
|
||||||
return run_final_status(data);
|
return run_final_status(data);
|
||||||
|
@ -434,11 +434,11 @@ static int run(struct gdb_data *data, char *buf)
|
||||||
printc("Running\n");
|
printc("Running\n");
|
||||||
|
|
||||||
if (run_set_pc(data, buf) < 0 ||
|
if (run_set_pc(data, buf) < 0 ||
|
||||||
device_default->ctl(device_default, DEVICE_CTL_RUN) < 0)
|
device_ctl(DEVICE_CTL_RUN) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
device_status_t status = device_default->poll(device_default);
|
device_status_t status = device_poll();
|
||||||
|
|
||||||
if (status == DEVICE_STATUS_ERROR)
|
if (status == DEVICE_STATUS_ERROR)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
@ -465,7 +465,7 @@ static int run(struct gdb_data *data, char *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (device_default->ctl(device_default, DEVICE_CTL_HALT) < 0)
|
if (device_ctl(DEVICE_CTL_HALT) < 0)
|
||||||
return gdb_send(data, "E00");
|
return gdb_send(data, "E00");
|
||||||
|
|
||||||
return run_final_status(data);
|
return run_final_status(data);
|
||||||
|
|
2
main.c
2
main.c
|
@ -464,7 +464,7 @@ int main(int argc, char **argv)
|
||||||
simio_exit();
|
simio_exit();
|
||||||
|
|
||||||
stab_destroy(stab_default);
|
stab_destroy(stab_default);
|
||||||
device_default->destroy(device_default);
|
device_destroy();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
6
prog.c
6
prog.c
|
@ -34,8 +34,7 @@ int prog_flush(struct prog_data *prog)
|
||||||
|
|
||||||
if (!prog->have_erased && (prog->flags & PROG_WANT_ERASE)) {
|
if (!prog->have_erased && (prog->flags & PROG_WANT_ERASE)) {
|
||||||
printc("Erasing...\n");
|
printc("Erasing...\n");
|
||||||
if (device_default->erase(device_default,
|
if (device_erase(DEVICE_ERASE_MAIN, 0) < 0)
|
||||||
DEVICE_ERASE_MAIN, 0) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
printc("Programming...\n");
|
printc("Programming...\n");
|
||||||
|
@ -43,8 +42,7 @@ int prog_flush(struct prog_data *prog)
|
||||||
}
|
}
|
||||||
|
|
||||||
printc_dbg("Writing %4d bytes to %04x...\n", prog->len, prog->addr);
|
printc_dbg("Writing %4d bytes to %04x...\n", prog->len, prog->addr);
|
||||||
if (device_default->writemem(device_default, prog->addr,
|
if (device_writemem(prog->addr, prog->buf, prog->len) < 0)
|
||||||
prog->buf, prog->len) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
prog->addr += prog->len;
|
prog->addr += prog->len;
|
||||||
|
|
4
rtools.c
4
rtools.c
|
@ -353,7 +353,7 @@ static int do_isearch(address_t addr, address_t len,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->readmem(device_default, addr, mbuf, len) < 0) {
|
if (device_readmem(addr, mbuf, len) < 0) {
|
||||||
printc_err("isearch: couldn't read device memory\n");
|
printc_err("isearch: couldn't read device memory\n");
|
||||||
free(mbuf);
|
free(mbuf);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -940,7 +940,7 @@ int cmd_cgraph(char **arg)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_default->readmem(device_default, offset, memory, len) < 0) {
|
if (device_readmem(offset, memory, len) < 0) {
|
||||||
printc_err("cgraph: couldn't fetch memory\n");
|
printc_err("cgraph: couldn't fetch memory\n");
|
||||||
free(memory);
|
free(memory);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue