Added functions for send data and control packets to windbg. Signed-off-by: Mihail Abakumov <mikhail.abaku...@ispras.ru> Signed-off-by: Pavel Dovgalyuk <dovga...@ispras.ru> Signed-off-by: Dmitriy Koltunov <koltu...@ispras.ru> --- windbgstub.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
diff --git a/windbgstub.c b/windbgstub.c index 7bc3585e53..2ebc161e33 100755 --- a/windbgstub.c +++ b/windbgstub.c @@ -57,6 +57,62 @@ typedef struct WindbgState { static WindbgState *windbg_state; +static uint32_t compute_checksum(uint8_t *data, uint16_t len) +{ + uint32_t checksum = 0; + while (len) { + --len; + checksum += *data++; + } + return checksum; +} + +__attribute__ ((unused)) /* unused yet */ +static void windbg_send_data_packet(uint8_t *data, uint16_t byte_count, + uint16_t type) +{ + uint8_t trailing_byte = PACKET_TRAILING_BYTE; + + KD_PACKET packet = { + .PacketLeader = PACKET_LEADER, + .PacketType = type, + .ByteCount = byte_count, + .PacketId = windbg_state->data_packet_id, + .Checksum = compute_checksum(data, byte_count) + }; + + packet.PacketType = lduw_p(&packet.PacketType); + packet.ByteCount = lduw_p(&packet.ByteCount); + packet.PacketId = ldl_p(&packet.PacketId); + packet.Checksum = ldl_p(&packet.Checksum); + + qemu_chr_fe_write(&windbg_state->chr, PTR(packet), sizeof(packet)); + qemu_chr_fe_write(&windbg_state->chr, data, byte_count); + qemu_chr_fe_write(&windbg_state->chr, &trailing_byte, + sizeof(trailing_byte)); + + windbg_state->data_packet_id ^= 1; +} + +__attribute__ ((unused)) /* unused yet */ +static void windbg_send_control_packet(uint16_t type) +{ + KD_PACKET packet = { + .PacketLeader = CONTROL_PACKET_LEADER, + .PacketType = type, + .ByteCount = 0, + .PacketId = windbg_state->ctrl_packet_id, + .Checksum = 0 + }; + + packet.PacketType = lduw_p(&packet.PacketType); + packet.PacketId = ldl_p(&packet.PacketId); + + qemu_chr_fe_write(&windbg_state->chr, PTR(packet), sizeof(packet)); + + windbg_state->ctrl_packet_id ^= 1; +} + static void windbg_ctx_handler(ParsingContext *ctx) {}