1 #ifndef _RISCV_GDBSERVER_H
2 #define _RISCV_GDBSERVER_H
9 class circular_buffer_t
12 // The buffer can store capacity-1 data elements.
13 circular_buffer_t(unsigned int capacity
) : data(new T
[capacity
]),
14 start(0), end(0), capacity(capacity
) {}
15 circular_buffer_t() : start(0), end(0), capacity(0) {}
16 ~circular_buffer_t() { delete data
; }
19 unsigned int start
; // Data start, inclusive.
20 unsigned int end
; // Data end, exclusive.
21 unsigned int capacity
; // Size of the buffer.
22 unsigned int size() const;
23 bool empty() const { return start
== end
; }
24 bool full() const { return ((end
+1) % capacity
) == start
; }
26 // Return size and address of the block of RAM where more data can be copied
27 // to be added to the buffer.
28 unsigned int contiguous_empty_size() const;
29 T
*contiguous_empty() { return data
+ end
; }
30 void data_added(unsigned int bytes
);
32 unsigned int contiguous_data_size() const;
33 T
*contiguous_data() { return data
+ start
; }
34 // Tell the buffer that some bytes were consumed from the start of the
36 void consume(unsigned int bytes
);
40 T
operator[](unsigned int i
) const { return data
[(start
+ i
) % capacity
]; }
42 void append(const T
*src
, unsigned int count
);
48 // Create a new server, listening for connections from localhost on the given
50 gdbserver_t(uint16_t port
, sim_t
*sim
);
52 // Process all pending messages from a client.
55 void handle_packet(const std::vector
<uint8_t> &packet
);
56 void handle_interrupt();
58 void handle_halt_reason(const std::vector
<uint8_t> &packet
);
59 void handle_read_general_registers(const std::vector
<uint8_t> &packet
);
60 void handle_read_memory(const std::vector
<uint8_t> &packet
);
61 void handle_read_register(const std::vector
<uint8_t> &packet
);
62 void handle_continue(const std::vector
<uint8_t> &packet
);
68 circular_buffer_t
<uint8_t> recv_buf
;
69 circular_buffer_t
<uint8_t> send_buf
;
73 // Read pending data from the client.
76 // Accept a new client if there isn't one already connected.
78 // Process all complete requests in recv_buf.
79 void process_requests();
80 // Add the given message to send_buf.
81 void send(const char* msg
);
82 // Hex-encode a 64-bit value, and send it to gcc in target byte order (little
84 void send(uint64_t value
);
85 // Hex-encode a 32-bit value, and send it to gcc in target byte order (little
87 void send(uint32_t value
);
88 void send_packet(const char* data
);
89 uint8_t running_checksum
;
90 void send_running_checksum();