/* Does not acknowledge. */ static int attempt_receive_packet(struct gdb_context *ctx) { u8 csum; u8 received_csum; u8 ch; /* Skip over everything up to the first '$' */ while ( (ch = gdb_io_read(ctx)) != '$' ) continue; csum = 0; for ( ctx->in_bytes = 0; ctx->in_bytes < sizeof(ctx->in_buf); ctx->in_bytes++ ) { ch = gdb_io_read(ctx); if ( ch == '#' ) break; ctx->in_buf[ctx->in_bytes] = ch; csum += ch; } if ( ctx->in_bytes == sizeof(ctx->in_buf) ) { dbg_printk("WARNING: GDB sent a stupidly big packet.\n"); return -1; } ctx->in_buf[ctx->in_bytes] = '\0'; received_csum = char2hex(gdb_io_read(ctx)) * 16 + char2hex(gdb_io_read(ctx)); return (received_csum == csum) ? 0 : -1; }
void gdb_recv_packet() { uint8_t *ptr; size_t len, remain = 0; do { do { len = remain; remain = 0; ptr = &gdb_input[len]; len += gdb_io_read(ptr, sizeof(gdb_input) - len); if(len) { remain = gdb_consume_packet(gdb_input, len); debug(GDBSTUB_PKT, "remain (%D)\n", remain); if(remain && remain != len) { ptr = gdb_input + (len - remain); memcpy(gdb_input, ptr, remain); } } } while(remain); } while(gdb_locked()); }
static int gdb_check_ack(struct gdb_context *ctx) { u8 c = gdb_io_read(ctx); switch ( c ) { case '+': return 1; case '-': return 0; default: printk("Bad ack: %c\n", c); return 0; } }
void gdb_wait_ack() { uint8_t x; while(gdb_io_read(&x, 1) != 1 && x != GDB_ACK_BYTE); }