1 // See LICENSE for license details.
2 #ifndef _RISCV_DEBUG_MODULE_H
3 #define _RISCV_DEBUG_MODULE_H
18 HARTSTATUS_UNAVAILABLE
,
46 CMDERR_HALTRESUME
= 4,
53 class debug_module_data_t
: public abstract_device_t
56 debug_module_data_t();
58 bool load(reg_t addr
, size_t len
, uint8_t* bytes
);
59 bool store(reg_t addr
, size_t len
, const uint8_t* bytes
);
61 uint32_t read32(reg_t addr
) const;
62 void write32(reg_t addr
, uint32_t value
);
64 uint8_t data
[DEBUG_EXCHANGE_SIZE
];
67 class debug_module_t
: public abstract_device_t
70 debug_module_t(sim_t
*sim
);
72 void add_device(bus_t
*bus
);
74 bool load(reg_t addr
, size_t len
, uint8_t* bytes
);
75 bool store(reg_t addr
, size_t len
, const uint8_t* bytes
);
77 void set_interrupt(uint32_t hartid
) {
78 interrupt
.insert(hartid
);
80 void clear_interrupt(uint32_t hartid
) {
81 interrupt
.erase(hartid
);
83 bool get_interrupt(uint32_t hartid
) const {
84 return interrupt
.find(hartid
) != interrupt
.end();
87 void set_halt_notification(uint32_t hartid
) {
88 halt_notification
.insert(hartid
);
90 void clear_halt_notification(uint32_t hartid
) {
91 halt_notification
.erase(hartid
);
93 bool get_halt_notification(uint32_t hartid
) const {
94 return halt_notification
.find(hartid
) != halt_notification
.end();
97 // Debug Module Interface that the debugger (in our case through JTAG DTM)
98 // uses to access the DM.
99 // Return true for success, false for failure.
100 bool dmi_read(unsigned address
, uint32_t *value
);
101 bool dmi_write(unsigned address
, uint32_t value
);
105 // Track which interrupts from module to debugger are set.
106 std::set
<uint32_t> interrupt
;
107 // Track which halt notifications from debugger to module are set.
108 std::set
<uint32_t> halt_notification
;
109 uint8_t debug_rom_entry
[DEBUG_ROM_ENTRY_SIZE
];
110 uint8_t debug_rom_code
[DEBUG_ROM_CODE_SIZE
];
111 uint8_t debug_rom_exception
[DEBUG_ROM_EXCEPTION_SIZE
];
113 debug_module_data_t dmdata
;
115 void write32(uint8_t *rom
, unsigned int index
, uint32_t value
);
116 uint32_t read32(uint8_t *rom
, unsigned int index
);
118 static const unsigned progsize
= 8;
120 dmcontrol_t dmcontrol
;
121 abstractcs_t abstractcs
;
122 uint32_t ibuf
[progsize
];
124 processor_t
*current_proc() const;
126 bool perform_abstract_command(uint32_t command
);