X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=riscv%2Fdebug_module.h;h=eaaf06e9fab79a4f72d5eba2ca4764e9e51053ca;hb=ab8a5631c39300c8ecb24635b16d50d19398dbdd;hp=7a78ad3d278ea3d744864e5c5dd1c3e4b5460cf3;hpb=6ef848928a5e2d72d9b0aed66f669b7b9a80b49a;p=riscv-isa-sim.git diff --git a/riscv/debug_module.h b/riscv/debug_module.h index 7a78ad3..eaaf06e 100644 --- a/riscv/debug_module.h +++ b/riscv/debug_module.h @@ -6,45 +6,103 @@ #include "devices.h" +class sim_t; + +typedef struct { + bool haltreq; + bool resumereq; + enum { + HARTSTATUS_HALTED, + HARTSTATUS_RUNNING, + HARTSTATUS_UNAVAILABLE, + HARTSTATUS_NOTEXIST + } hartstatus; + unsigned hartsel; + bool hartreset; + bool dmactive; + bool reset; + bool authenticated; + bool authbusy; + unsigned version; +} dmcontrol_t; + +typedef struct { + bool autoexec7; + bool autoexec6; + bool autoexec5; + bool autoexec4; + bool autoexec3; + bool autoexec2; + bool autoexec1; + bool autoexec0; + enum { + CMDERR_NONE = 0, + CMDERR_BUSY = 1, + CMDERR_NOTSUP = 2, + CMDERR_EXCEPTION = 3, + CMDERR_HALTRESUME = 4, + CMDERR_OTHER = 7 + } cmderr; + bool busy; + unsigned datacount; +} abstractcs_t; + +class debug_module_data_t : public abstract_device_t +{ + public: + debug_module_data_t(); + + bool load(reg_t addr, size_t len, uint8_t* bytes); + bool store(reg_t addr, size_t len, const uint8_t* bytes); + + uint32_t read32(reg_t addr) const; + void write32(reg_t addr, uint32_t value); + + uint8_t data[DEBUG_EXCHANGE_SIZE]; +}; + class debug_module_t : public abstract_device_t { public: + debug_module_t(sim_t *sim); + + void add_device(bus_t *bus); + bool load(reg_t addr, size_t len, uint8_t* bytes); bool store(reg_t addr, size_t len, const uint8_t* bytes); - void ram_write32(unsigned int index, uint32_t value); - uint32_t ram_read32(unsigned int index); - - void set_interrupt(uint32_t hartid) { - fprintf(stderr, "set debug interrupt 0x%x\n", hartid); - interrupt.insert(hartid); - } - void clear_interrupt(uint32_t hartid) { - fprintf(stderr, "clear debug interrupt 0x%x\n", hartid); - interrupt.erase(hartid); - } - bool get_interrupt(uint32_t hartid) const { - return interrupt.find(hartid) != interrupt.end(); - } - - void set_halt_notification(uint32_t hartid) { - fprintf(stderr, "set debug halt_notification 0x%x\n", hartid); - halt_notification.insert(hartid); - } - void clear_halt_notification(uint32_t hartid) { - fprintf(stderr, "clear debug halt_notification 0x%x\n", hartid); - halt_notification.erase(hartid); - } - bool get_halt_notification(uint32_t hartid) const { - return halt_notification.find(hartid) != halt_notification.end(); - } + // Debug Module Interface that the debugger (in our case through JTAG DTM) + // uses to access the DM. + // Return true for success, false for failure. + bool dmi_read(unsigned address, uint32_t *value); + bool dmi_write(unsigned address, uint32_t value); private: - // Track which interrupts from module to debugger are set. - std::set interrupt; - // Track which halt notifications from debugger to module are set. - std::set halt_notification; - char debug_ram[DEBUG_RAM_SIZE]; + static const unsigned progsize = 8; + + sim_t *sim; + + uint8_t debug_rom_entry[DEBUG_ROM_ENTRY_SIZE]; + uint8_t debug_rom_code[DEBUG_ROM_CODE_SIZE]; + uint8_t debug_rom_exception[DEBUG_ROM_EXCEPTION_SIZE]; + uint8_t program_buffer[progsize * 4]; + bool halted[1024]; + debug_module_data_t dmdata; + // Instruction that will be placed at the current hart's ROM entry address + // after the current action has completed. + uint32_t next_action; + bool action_executed; + + void write32(uint8_t *rom, unsigned int index, uint32_t value); + uint32_t read32(uint8_t *rom, unsigned int index); + + dmcontrol_t dmcontrol; + abstractcs_t abstractcs; + uint32_t command; + + processor_t *current_proc() const; + void reset(); + bool perform_abstract_command(); }; #endif