X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=riscv%2Fdebug_module.cc;h=5275a5f7a4002366535e6f06361695e611c7fcd7;hb=d6fcfdebf6a893bf37670fd67203d18653df4a0e;hp=de54a8377256346b8223c5a5fe6b4025b8400bfc;hpb=58aa702359ec56f0b26a3f10a2617a58c9818451;p=riscv-isa-sim.git diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index de54a83..5275a5f 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -4,6 +4,7 @@ #include "debug_defines.h" #include "opcodes.h" #include "mmu.h" +#include "sim.h" #include "debug_rom/debug_rom.h" #include "debug_rom_defines.h" @@ -16,10 +17,12 @@ ///////////////////////// debug_module_t -debug_module_t::debug_module_t(sim_t *sim, unsigned progbufsize, unsigned max_bus_master_bits) : +debug_module_t::debug_module_t(sim_t *sim, unsigned progbufsize, unsigned max_bus_master_bits, + bool require_authentication) : progbufsize(progbufsize), program_buffer_bytes(4 + 4*progbufsize), max_bus_master_bits(max_bus_master_bits), + require_authentication(require_authentication), debug_progbuf_start(debug_data_start - program_buffer_bytes), debug_abstract_start(debug_progbuf_start - debug_abstract_size*4), sim(sim) @@ -33,6 +36,7 @@ debug_module_t::debug_module_t(sim_t *sim, unsigned progbufsize, unsigned max_bu memset(halted, 0, sizeof(halted)); memset(debug_rom_flags, 0, sizeof(debug_rom_flags)); memset(resumeack, 0, sizeof(resumeack)); + memset(havereset, 0, sizeof(havereset)); memset(program_buffer, 0, program_buffer_bytes); program_buffer[4*progbufsize] = ebreak(); program_buffer[4*progbufsize+1] = ebreak() >> 8; @@ -65,7 +69,7 @@ void debug_module_t::reset() dmstatus = {0}; dmstatus.impebreak = true; - dmstatus.authenticated = 1; + dmstatus.authenticated = !require_authentication; dmstatus.version = 2; abstractcs = {0}; @@ -87,6 +91,8 @@ void debug_module_t::reset() sbcs.access16 = true; if (max_bus_master_bits >= 8) sbcs.access8 = true; + + challenge = random(); } void debug_module_t::add_device(bus_t *bus) { @@ -383,6 +389,10 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) result = set_field(result, DMI_DMSTATUS_IMPEBREAK, dmstatus.impebreak); + result = set_field(result, DMI_DMSTATUS_ALLHAVERESET, + havereset[dmcontrol.hartsel]); + result = set_field(result, DMI_DMSTATUS_ANYHAVERESET, + havereset[dmcontrol.hartsel]); result = set_field(result, DMI_DMSTATUS_ALLNONEXISTENT, dmstatus.allnonexistant); result = set_field(result, DMI_DMSTATUS_ALLUNAVAIL, dmstatus.allunavail); result = set_field(result, DMI_DMSTATUS_ALLRUNNING, dmstatus.allrunning); @@ -462,6 +472,9 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) case DMI_SBDATA3: result = sbdata[3]; break; + case DMI_AUTHDATA: + result = challenge; + break; default: result = 0; D(fprintf(stderr, "Unexpected. Returning Error.")); @@ -611,6 +624,11 @@ bool debug_module_t::perform_abstract_command() bool debug_module_t::dmi_write(unsigned address, uint32_t value) { D(fprintf(stderr, "dmi_write(0x%x, 0x%x)\n", address, value)); + + if (!dmstatus.authenticated && address != DMI_AUTHDATA && + address != DMI_DMCONTROL) + return false; + if (address >= DMI_DATA0 && address < DMI_DATA0 + abstractcs.datacount) { unsigned i = address - DMI_DATA0; if (!abstractcs.busy) @@ -643,6 +661,8 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) if (!dmcontrol.dmactive && get_field(value, DMI_DMCONTROL_DMACTIVE)) reset(); dmcontrol.dmactive = get_field(value, DMI_DMCONTROL_DMACTIVE); + if (!dmstatus.authenticated) + return true; if (dmcontrol.dmactive) { dmcontrol.haltreq = get_field(value, DMI_DMCONTROL_HALTREQ); dmcontrol.resumereq = get_field(value, DMI_DMCONTROL_RESUMEREQ); @@ -650,6 +670,9 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) dmcontrol.ndmreset = get_field(value, DMI_DMCONTROL_NDMRESET); dmcontrol.hartsel = get_field(value, ((1L<