+struct cc_break {
+ int enabled;
+ int temporary;
+ uint16_t address;
+};
+
+#define CC_NUM_BREAKPOINTS 4
+
+static struct cc_break breakpoints[CC_NUM_BREAKPOINTS];
+
+enum command_result
+set_breakpoint(FILE *output, uint16_t address, int temporary)
+{
+ int b;
+ uint8_t status;
+ for (b = 0; b < CC_NUM_BREAKPOINTS; b++) {
+ if (breakpoints[b].enabled == 0)
+ break;
+ if (breakpoints[b].address == address)
+ break;
+ }
+ if (b == CC_NUM_BREAKPOINTS) {
+ fprintf(output, "Error: too many breakpoints requested\n");
+ return command_proceed;
+ }
+ if (breakpoints[b].enabled == 0) {
+ breakpoints[b].address = address;
+ status = ccdbg_set_hw_brkpnt(s51_dbg, b, 1, address);
+ fprintf(output, "set_hw_brkpnt status 0x%02x\n", status);
+ }
+ ++breakpoints[b].enabled;
+ fprintf(output, "Breakpoint %d at 0x%04x\n", b, address);
+ breakpoints[b].temporary += temporary;
+ return command_proceed;
+}
+
+enum command_result
+clear_breakpoint(FILE *output, uint16_t address, int temporary)
+{
+ int b;
+ uint8_t status;
+
+ for (b = 0; b < CC_NUM_BREAKPOINTS; b++) {
+ if (breakpoints[b].enabled != 0 &&
+ ((breakpoints[b].temporary != 0) == (temporary != 0)) &&
+ breakpoints[b].address == address)
+ break;
+ }
+ if (b == CC_NUM_BREAKPOINTS) {
+ fprintf(output, "Error: no matching breakpoint found\n");
+ return command_proceed;
+ }
+ --breakpoints[b].enabled;
+ --breakpoints[b].temporary;
+ if (breakpoints[b].enabled == 0) {
+ breakpoints[b].address = -1;
+ ccdbg_set_hw_brkpnt(s51_dbg, b, 0, address);
+ fprintf(output, "set_hw_brkpnt status 0x%02x\n", status);
+ }
+ return command_proceed;
+}
+