It implements gdb remote protocol to talk with a host gdb during the
debug session. The implementation is divided in three layers:
1 - The top layer that is responsible for the gdb remote protocol.
2 - An architecture specific layer responsible to write/read registers,
set breakpoints, handle exceptions, ...
3 - A transport layer to be used to communicate with the host
The communication with GDB in the host is synchronous and the systems
stops execution waiting for instructions and return its execution after
a "continue" or "step" command. The protocol has an exception that is
when the host sends a packet to cause an interruption, usually triggered
by a Ctrl-C. This implementation ignores this instruction though.
This initial work supports only X86 using uart as backend.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
51 lines
938 B
C
51 lines
938 B
C
/*
|
|
* Copyright (c) 2020 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <kernel.h>
|
|
#include <drivers/uart.h>
|
|
#include <sys/__assert.h>
|
|
|
|
static const struct device *uart_dev;
|
|
|
|
int z_gdb_backend_init(void)
|
|
{
|
|
int ret = 0;
|
|
static const struct uart_config uart_cfg = {
|
|
.baudrate = 115200,
|
|
.parity = UART_CFG_PARITY_NONE,
|
|
.stop_bits = UART_CFG_STOP_BITS_1,
|
|
.data_bits = UART_CFG_DATA_BITS_8,
|
|
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE
|
|
};
|
|
|
|
if (uart_dev == NULL) {
|
|
uart_dev = device_get_binding(
|
|
CONFIG_GDBSTUB_SERIAL_BACKEND_NAME);
|
|
|
|
__ASSERT(uart_dev != NULL, "Could not get uart device");
|
|
|
|
ret = uart_configure(uart_dev, &uart_cfg);
|
|
__ASSERT(ret == 0, "Could not configure uart device");
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void z_gdb_putchar(unsigned char ch)
|
|
{
|
|
uart_poll_out(uart_dev, ch);
|
|
}
|
|
|
|
unsigned char z_gdb_getchar(void)
|
|
{
|
|
unsigned char ch;
|
|
|
|
while (uart_poll_in(uart_dev, &ch) < 0) {
|
|
}
|
|
|
|
return ch;
|
|
}
|