2017-03-28 05:51:54 +02:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
|
|
|
#include "spike/encoding.h"
|
|
|
|
|
|
|
|
// These are implementation-specific addresses in the Debug Module
|
|
|
|
#define HALTED 0x100
|
|
|
|
#define GOING 0x104
|
|
|
|
#define RESUMING 0x108
|
|
|
|
#define EXCEPTION 0x10C
|
|
|
|
|
|
|
|
// Region of memory where each hart has 1
|
|
|
|
// byte to read.
|
2017-04-07 18:54:51 +02:00
|
|
|
#define FLAGS 0x400
|
|
|
|
#define FLAG_GO 0
|
|
|
|
#define FLAG_RESUME 1
|
2017-03-28 05:51:54 +02:00
|
|
|
|
|
|
|
.option norvc
|
|
|
|
.global entry
|
|
|
|
.global exception
|
|
|
|
|
|
|
|
// Entry location on ebreak, Halt, or Breakpoint
|
|
|
|
// It is the same for all harts. They branch when
|
2017-04-07 18:54:51 +02:00
|
|
|
// their GO or RESUME bit is set.
|
2017-03-28 05:51:54 +02:00
|
|
|
|
|
|
|
entry:
|
|
|
|
jal zero, _entry
|
|
|
|
resume:
|
|
|
|
jal zero, _resume
|
|
|
|
exception:
|
|
|
|
jal zero, _exception
|
|
|
|
|
|
|
|
_entry:
|
|
|
|
// This fence is required because the execution may have written something
|
|
|
|
// into the Abstract Data or Program Buffer registers.
|
|
|
|
fence
|
|
|
|
csrw CSR_DSCRATCH, s0 // Save s0 to allow signaling MHARTID
|
|
|
|
|
|
|
|
// We continue to let the hart know that we are halted in order that
|
|
|
|
// a DM which was reset is still made aware that a hart is halted.
|
|
|
|
// We keep checking both whether there is something the debugger wants
|
2017-04-07 18:54:51 +02:00
|
|
|
// us to do, or whether we should resume.
|
2017-03-28 05:51:54 +02:00
|
|
|
entry_loop:
|
|
|
|
csrr s0, CSR_MHARTID
|
|
|
|
sw s0, HALTED(zero)
|
2017-04-07 18:54:51 +02:00
|
|
|
lbu s0, FLAGS(s0) // 1 byte flag per hart. Only one hart advances here.
|
|
|
|
andi s0, s0, (1 << FLAG_GO)
|
|
|
|
bnez s0, going
|
|
|
|
csrr s0, CSR_MHARTID
|
|
|
|
lbu s0, FLAGS(s0) // multiple harts can resume here
|
|
|
|
andi s0, s0, (1 << FLAG_RESUME)
|
|
|
|
bnez s0, resume
|
2017-03-28 05:51:54 +02:00
|
|
|
jal zero, entry_loop
|
|
|
|
|
|
|
|
_exception:
|
|
|
|
sw zero, EXCEPTION(zero) // Let debug module know you got an exception.
|
|
|
|
ebreak
|
|
|
|
|
|
|
|
going:
|
|
|
|
csrr s0, CSR_DSCRATCH // Restore s0 here
|
2017-04-07 18:54:51 +02:00
|
|
|
sw zero, GOING(zero) // When debug module sees this write, the GO flag is reset.
|
2017-03-28 05:51:54 +02:00
|
|
|
jalr zero, zero, %lo(whereto) // Rocket-Chip has a specific hack which is that jalr in
|
|
|
|
// Debug Mode will flush the I-Cache. We need that so that the
|
|
|
|
// remainder of the variable instructions will be what Debug Module
|
|
|
|
// intends.
|
|
|
|
_resume:
|
|
|
|
csrr s0, CSR_MHARTID
|
2017-04-07 18:54:51 +02:00
|
|
|
sw s0, RESUMING(zero) // When Debug Module sees this write, the RESUME flag is reset.
|
2017-03-28 05:51:54 +02:00
|
|
|
csrr s0, CSR_DSCRATCH // Restore s0
|
|
|
|
dret
|
|
|
|
|
|
|
|
// END OF ACTUAL "ROM" CONTENTS. BELOW IS JUST FOR LINKER SCRIPT.
|
|
|
|
|
|
|
|
.section .whereto
|
|
|
|
whereto:
|
|
|
|
nop
|
|
|
|
// Variable "ROM" This is : jal x0 abstract, jal x0 program_buffer,
|
|
|
|
// or jal x0 resume, as desired.
|
|
|
|
// Debug Module state machine tracks what is 'desired'.
|
|
|
|
// We don't need/want to use jalr here because all of the
|
|
|
|
// Variable ROM contents are set by
|
|
|
|
// Debug Module before setting the OK_GO byte.
|