summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2008-12-17 23:12:59 -0800
committerKeith Packard <keithp@keithp.com>2008-12-17 23:12:59 -0800
commitfa168f963f8b00144d12aa2770e9c0917cfae123 (patch)
treeb57701ef1b9cc331fc97b977557e8b4029365033
parent5df84df7cd6a31527dcfd11030f00ef9d8abf170 (diff)
Fill out ccdbg-command to support all debug commands.
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--ccdbg-command.c64
-rw-r--r--ccdbg.c24
-rw-r--r--ccdbg.h33
3 files changed, 115 insertions, 6 deletions
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, ...);