gdb can now read spike memory.
[riscv-isa-sim.git] / riscv / gdbserver.h
index c9479361de45c544eb238e20ad8d949df56c9783..d81790d4aebb6c4e5601fb9a680e20ea05d54ca0 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdint.h>
 
+class sim_t;
+
 template <typename T>
 class circular_buffer_t
 {
@@ -19,21 +21,25 @@ public:
   unsigned int capacity;    // Size of the buffer.
   unsigned int size() const;
   bool empty() const { return start == end; }
-  // Tell the buffer that some bytes were consumed from the start of the
-  // buffer.
-  void consume(unsigned int bytes);
+  bool full() const { return ((end+1) % capacity) == start; }
 
   // Return size and address of the block of RAM where more data can be copied
   // to be added to the buffer.
-  unsigned int contiguous_space() const;
-  T *contiguous_data() { return data + end; }
+  unsigned int contiguous_empty_size() const;
+  T *contiguous_empty() { return data + end; }
   void data_added(unsigned int bytes);
 
+  unsigned int contiguous_data_size() const;
+  T *contiguous_data() { return data + start; }
+  // Tell the buffer that some bytes were consumed from the start of the
+  // buffer.
+  void consume(unsigned int bytes);
+
   void reset();
 
-  T operator[](unsigned int i) {
-    return data[(start + i) % capacity];
-  }
+  T operator[](unsigned int i) const { return data[(start + i) % capacity]; }
+
+  void append(const T *src, unsigned int count);
 };
 
 class gdbserver_t
@@ -41,30 +47,37 @@ class gdbserver_t
 public:
   // Create a new server, listening for connections from localhost on the given
   // port.
-  gdbserver_t(uint16_t port);
+  gdbserver_t(uint16_t port, sim_t *sim);
 
   // Process all pending messages from a client.
   void handle();
 
   void handle_packet(const std::vector<uint8_t> &packet);
+  void handle_halt_reason(const std::vector<uint8_t> &packet);
+  void handle_read_general_registers(const std::vector<uint8_t> &packet);
+  void handle_read_memory(const std::vector<uint8_t> &packet);
 
 private:
+  sim_t *sim;
   int socket_fd;
   int client_fd;
   circular_buffer_t<uint8_t> recv_buf;
-  uint8_t send_buf[64 * 1024];          // Circular buffer.
-  unsigned int send_start, send_end;    // Data start (inclusive)/end (exclusive)pointers.
+  circular_buffer_t<uint8_t> send_buf;
 
-  bool ack_mode;
+  bool expect_ack;
 
   // Read pending data from the client.
   void read();
+  void write();
   // Accept a new client if there isn't one already connected.
   void accept();
   // Process all complete requests in recv_buf.
   void process_requests();
   // Add the given message to send_buf.
   void send(const char* msg);
+  void send_packet(const char* data);
+  uint8_t running_checksum;
+  void send_running_checksum();
 };
 
 #endif