From ffe4998fe57c5e58e591fc75e62e092e8e20d668 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Tue, 26 Apr 2016 12:12:57 -0700 Subject: [PATCH] processor_t unfriends gdbserver_t. --- debug_rom/debug_rom.S | 2 +- debug_rom/debug_rom.h | 2 +- riscv/execute.cc | 4 ++-- riscv/gdbserver.cc | 31 +++++++++++++++++++++++++------ riscv/processor.cc | 4 ++-- riscv/processor.h | 6 +++--- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/debug_rom/debug_rom.S b/debug_rom/debug_rom.S index 7130364..ca58ee4 100755 --- a/debug_rom/debug_rom.S +++ b/debug_rom/debug_rom.S @@ -95,7 +95,7 @@ save_128: spontaneous_halt: csrr s0, CSR_MHARTID sw s0, SETHALTNOT(zero) - csrsi DCSR, DCSR_HALT_OFFSET + csrsi DCSR, (1< 0) { diff --git a/riscv/gdbserver.cc b/riscv/gdbserver.cc index a460b67..0487939 100644 --- a/riscv/gdbserver.cc +++ b/riscv/gdbserver.cc @@ -178,13 +178,13 @@ uint32_t gdbserver_t::read_debug_ram(unsigned int index) void gdbserver_t::halt() { processor_t *p = sim->get_core(0); - write_debug_ram(0, csrsi(DCSR_ADDRESS, DCSR_HALT_OFFSET)); + write_debug_ram(0, csrsi(DCSR_ADDRESS, DCSR_HALT_MASK)); write_debug_ram(1, csrr(S0, DPC_ADDRESS)); write_debug_ram(2, sw(S0, 0, (uint16_t) DEBUG_RAM_START)); write_debug_ram(3, csrr(S0, DCSR_ADDRESS)); write_debug_ram(4, sw(S0, 0, (uint16_t) DEBUG_RAM_START + 8)); write_debug_ram(5, jal(0, (uint32_t) (DEBUG_ROM_RESUME - (DEBUG_RAM_START + 4*5)))); - sim->debug_module.set_interrupt(p->id); + sim->debug_module.set_interrupt(0); state = STATE_HALTING; } @@ -356,6 +356,12 @@ void gdbserver_t::handle_halt_reason(const std::vector &packet) send_packet("S00"); } +void die(const char* msg) +{ + fprintf(stderr, "%s\n", msg); + abort(); +} + void gdbserver_t::handle_general_registers_read(const std::vector &packet) { // Register order that gdb expects is: @@ -374,7 +380,8 @@ void gdbserver_t::handle_general_registers_read(const std::vector &pack running_checksum = 0; processor_t *p = sim->get_core(0); for (int r = 0; r < 32; r++) { - send(p->state.XPR[r]); + die("handle_general_registers_read"); + // send(p->state.XPR[r]); } send_running_checksum(); expect_ack = true; @@ -457,6 +464,8 @@ void gdbserver_t::handle_register_read(const std::vector &packet) send("$"); running_checksum = 0; + die("handle_register_read"); + /* if (n >= REG_XPR0 && n <= REG_XPR31) { send(p->state.XPR[n - REG_XPR0]); } else if (n == REG_PC) { @@ -475,6 +484,7 @@ void gdbserver_t::handle_register_read(const std::vector &packet) } else { return send_packet("E02"); } + */ send_running_checksum(); expect_ack = true; @@ -496,6 +506,8 @@ void gdbserver_t::handle_register_write(const std::vector &packet) processor_t *p = sim->get_core(0); + die("handle_register_write"); + /* if (n >= REG_XPR0 && n <= REG_XPR31) { p->state.XPR.write(n - REG_XPR0, value); } else if (n == REG_PC) { @@ -511,6 +523,7 @@ void gdbserver_t::handle_register_write(const std::vector &packet) } else { return send_packet("E07"); } + */ return send_packet("OK"); } @@ -574,7 +587,8 @@ void gdbserver_t::handle_continue(const std::vector &packet) processor_t *p = sim->get_core(0); if (packet[2] != '#') { std::vector::const_iterator iter = packet.begin() + 2; - p->state.pc = consume_hex_number(iter, packet.end()); + die("handle_continue"); + // p->state.pc = consume_hex_number(iter, packet.end()); if (*iter != '#') return send_packet("E30"); } @@ -589,7 +603,8 @@ void gdbserver_t::handle_step(const std::vector &packet) processor_t *p = sim->get_core(0); if (packet[2] != '#') { std::vector::const_iterator iter = packet.begin() + 2; - p->state.pc = consume_hex_number(iter, packet.end()); + die("handle_step"); + //p->state.pc = consume_hex_number(iter, packet.end()); if (*iter != '#') return send_packet("E40"); } @@ -662,6 +677,8 @@ void gdbserver_t::handle_breakpoint(const std::vector &packet) } processor_t *p = sim->get_core(0); + die("handle_breakpoint"); + /* mmu_t* mmu = p->mmu; if (insert) { bp.insert(mmu); @@ -674,6 +691,7 @@ void gdbserver_t::handle_breakpoint(const std::vector &packet) } mmu->flush_icache(); sim->debug_mmu->flush_icache(); + */ return send_packet("OK"); } @@ -768,12 +786,13 @@ void gdbserver_t::handle() if (client_fd > 0) { processor_t *p = sim->get_core(0); - if (state == STATE_HALTING && sim->debug_module.get_interrupt(p->id) == 0) { + if (state == STATE_HALTING && sim->debug_module.get_interrupt(0) == 0) { // gdb requested a halt and now it's done. send_packet("T05"); fprintf(stderr, "DPC: 0x%x\n", read_debug_ram(0)); fprintf(stderr, "DCSR: 0x%x\n", read_debug_ram(2)); state = STATE_HALTED; + p->debug = false; } /* TODO diff --git a/riscv/processor.cc b/riscv/processor.cc index 3cb2f5a..9b97120 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -22,8 +22,8 @@ #define STATE state processor_t::processor_t(const char* isa, sim_t* sim, uint32_t id) - : sim(sim), ext(NULL), disassembler(new disassembler_t), - id(id), run(false), debug(false) + : debug(false), sim(sim), ext(NULL), disassembler(new disassembler_t), + id(id), run(false) { parse_isa_string(isa); diff --git a/riscv/processor.h b/riscv/processor.h index 3511d30..9c2f7a6 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -122,6 +122,9 @@ public: bool load(reg_t addr, size_t len, uint8_t* bytes); bool store(reg_t addr, size_t len, const uint8_t* bytes); + // When true, display disassembly of each instruction that's executed. + bool debug; + private: sim_t* sim; mmu_t* mmu; // main memory is always accessed via the mmu @@ -134,8 +137,6 @@ private: reg_t isa; std::string isa_string; bool run; // !reset - // When true, display disassembly of each instruction that's executed. - bool debug; bool histogram_enabled; std::vector instructions; @@ -155,7 +156,6 @@ private: friend class mmu_t; friend class rtc_t; friend class extension_t; - friend class gdbserver_t; void parse_isa_string(const char* isa); void build_opcode_map(); -- 2.30.2