# This code should be functional. Doesn't have to be optimal. # I'm writing it to prove that it can be done. #include "riscv/encoding.h" # TODO: Update these constants once they're finalized in the doc. #define DCSR 0x790 #define DCSR_CAUSE_DEBINT 3 #define DCSR_HALT_OFFSET 3 #define DCSR_DEBUGINT_OFFSET 10 #define DSCRATCH 0x792 # TODO: Should be 0x400 #define DEBUG_RAM (-0x400) #define DEBUG_RAM_SIZE 64 # TODO: Should be 0x100, 0x108 #define SETHALTNOT (-0x100) #define CLEARDEBINT (-0x108) .global entry .global resume # Automatically called when Debug Mode is first entered. entry: j _entry # Should be called by Debug RAM code that has finished execution and # wants to return to Debug Mode. resume: # Clear debug interrupt. clear_debint: csrr s1, CSR_MHARTID sw s1, CLEARDEBINT(zero) # TODO: race: what if the debugger sets debug int at this point? clear_debint_loop: csrr s1, DCSR andi s1, s1, (1<