From: Keith Packard Date: Thu, 18 Dec 2008 07:12:59 +0000 (-0800) Subject: Fill out ccdbg-command to support all debug commands. X-Git-Tag: 0.5~58^2~101 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=fa168f963f8b00144d12aa2770e9c0917cfae123 Fill out ccdbg-command to support all debug commands. Signed-off-by: Keith Packard --- diff --git a/ccdbg-command.c b/ccdbg-command.c index 099afc55..415010f8 100644 --- a/ccdbg-command.c +++ b/ccdbg-command.c @@ -48,9 +48,15 @@ ccdbg_reset(struct ccdbg *dbg) } uint8_t -ccdbg_read_status(struct ccdbg *dbg) +ccdbg_chip_erase(struct ccdbg *dbg) { - return ccdbg_cmd_write_read8(dbg, CC_READ_STATUS, NULL, 0); + return ccdbg_cmd_write_read8(dbg, CC_CHIP_ERASE, NULL, 0); +} + +uint8_t +ccdbg_wr_config(struct ccdbg *dbg, uint8_t config) +{ + return ccdbg_cmd_write_read8(dbg, CC_WR_CONFIG, &config, 1); } uint8_t @@ -59,9 +65,61 @@ ccdbg_rd_config(struct ccdbg *dbg) return ccdbg_cmd_write_read8(dbg, CC_RD_CONFIG, NULL, 0); } +uint8_t +ccdbg_get_pc(struct ccdbg *dbg) +{ + return ccdbg_cmd_write_read16(dbg, CC_GET_PC, NULL, 0); +} + +uint8_t +ccdbg_read_status(struct ccdbg *dbg) +{ + return ccdbg_cmd_write_read8(dbg, CC_READ_STATUS, NULL, 0); +} + +uint8_t +ccdbg_set_hw_brkpnt(struct ccdbg *dbg, uint8_t number, uint8_t enable, uint16_t addr) +{ + uint8_t data[3]; + + data[0] = (number << 3) | (enable << 2); + data[1] = (addr >> 8); + data[2] = addr; + return ccdbg_cmd_write_read8(dbg, CC_SET_HW_BRKPNT, data, 3); +} + +uint8_t +ccdbg_halt(struct ccdbg *dbg) +{ + return ccdbg_cmd_write_read8(dbg, CC_HALT, NULL, 0); +} + +uint8_t +ccdbg_resume(struct ccdbg *dbg) +{ + return ccdbg_cmd_write_read8(dbg, CC_RESUME, NULL, 0); +} + +uint8_t +ccdbg_debug_instr(struct ccdbg *dbg, uint8_t *instr, int nbytes) +{ + return ccdbg_cmd_write_read8(dbg, CC_DEBUG_INSTR(nbytes), instr, nbytes); +} + +uint8_t +ccdbg_step_instr(struct ccdbg *dbg) +{ + return ccdbg_cmd_write_read8(dbg, CC_STEP_INSTR, NULL, 0); +} + +uint8_t +ccdbg_step_replace(struct ccdbg *dbg, uint8_t *instr, int nbytes) +{ + return ccdbg_cmd_write_read8(dbg, CC_STEP_REPLACE(nbytes), instr, nbytes); +} + uint16_t ccdbg_get_chip_id(struct ccdbg *dbg) { return ccdbg_cmd_write_read16(dbg, CC_GET_CHIP_ID, NULL, 0); } - diff --git a/ccdbg.c b/ccdbg.c index 3fcf7053..b682372a 100644 --- a/ccdbg.c +++ b/ccdbg.c @@ -18,6 +18,26 @@ #include "ccdbg.h" +#define MOV 0x75 + +static uint8_t instructions[] = { + 3, MOV, 0xfe, 0x02, + 3, MOV, 0x90, 0xff, + 0 +}; + +static void +ccdbg_instructions(struct ccdbg *dbg, uint8_t *inst) +{ + while(inst[0] != 0) { + uint8_t len = inst[0]; + uint8_t status; + status = ccdbg_debug_instr(dbg, inst+1, len); + printf ("inst status 0x%02x\n", status); + inst += len + 1; + } +} + int main (int argc, char **argv) { @@ -37,7 +57,9 @@ main (int argc, char **argv) printf("Status: 0x%02x\n", status); chip_id = ccdbg_get_chip_id(dbg); printf("Chip id: 0x%04x\n", chip_id); - ccdbg_reset(dbg); + status = ccdbg_halt(dbg); + printf ("halt status: 0x%02x\n", status); + ccdbg_instructions(dbg, instructions); #endif ccdbg_close(dbg); exit (0); diff --git a/ccdbg.h b/ccdbg.h index a0ef1c86..fc0cdd3c 100644 --- a/ccdbg.h +++ b/ccdbg.h @@ -88,7 +88,7 @@ struct ccdbg { #define CC_RESUME 0x4c #define CC_DEBUG_INSTR(n) (0x54|(n)) #define CC_STEP_INSTR 0x5c -#define CC_STEP_REPLACE (0x64|(n)) +#define CC_STEP_REPLACE(n) (0x64|(n)) #define CC_GET_CHIP_ID 0x68 #define CC_DEBUG_BITBANG 0x00000001 @@ -102,14 +102,43 @@ void ccdbg_reset(struct ccdbg *dbg); uint8_t -ccdbg_read_status(struct ccdbg *dbg); +ccdbg_chip_erase(struct ccdbg *dbg); + +uint8_t +ccdbg_wr_config(struct ccdbg *dbg, uint8_t config); uint8_t ccdbg_rd_config(struct ccdbg *dbg); +uint8_t +ccdbg_get_pc(struct ccdbg *dbg); + +uint8_t +ccdbg_read_status(struct ccdbg *dbg); + +uint8_t +ccdbg_set_hw_brkpnt(struct ccdbg *dbg, uint8_t number, uint8_t enable, uint16_t addr); + +uint8_t +ccdbg_halt(struct ccdbg *dbg); + +uint8_t +ccdbg_resume(struct ccdbg *dbg); + +uint8_t +ccdbg_debug_instr(struct ccdbg *dbg, uint8_t *instr, int nbytes); + +uint8_t +ccdbg_step_instr(struct ccdbg *dbg); + +uint8_t +ccdbg_step_replace(struct ccdbg *dbg, uint8_t *instr, int nbytes); + uint16_t ccdbg_get_chip_id(struct ccdbg *dbg); + + /* ccdbg-debug.c */ void ccdbg_debug(int level, char *format, ...);