make check: Fail if the tests failed
[riscv-isa-sim.git] / debug_rom / debug_rom.S
index c164eeb268d4c753af3605d9f8efb5c23e4f7178..b0be7fc1494db28c151f9c8a45030ce6aa104480 100755 (executable)
@@ -5,18 +5,11 @@
 
 # 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
-
 #define DEBUG_RAM               0x400
 #define DEBUG_RAM_SIZE          64
 
-#define SETHALTNOT              0x100
-#define CLEARDEBINT             0x108
+#define CLEARDEBINT             0x100
+#define SETHALTNOT              0x10c
 
         .global entry
         .global resume
@@ -37,9 +30,6 @@ exception:
 _resume:
         li      s0, 0
 _resume2:
-        # Clear debug interrupt.
-        csrr    s1, CSR_MHARTID
-        sw      s1, CLEARDEBINT(zero)
         fence
 
         # Restore s1.
@@ -47,42 +37,46 @@ _resume2:
         bltz    s1, restore_not_32
 restore_32:
         lw      s1, (DEBUG_RAM + DEBUG_RAM_SIZE - 4)(zero)
-        j       check_halt
+        j       finish_restore
 restore_not_32:
         slli    s1, s1, 1
         bltz    s1, restore_128
 restore_64:
         ld      s1, (DEBUG_RAM + DEBUG_RAM_SIZE - 8)(zero)
-        j       check_halt
+        j       finish_restore
 restore_128:
         nop     #lq      s1, (DEBUG_RAM + DEBUG_RAM_SIZE - 16)(zero)
 
+finish_restore:
         # s0 contains ~0 if we got here through an exception, and 0 otherwise.
         # Store this to the last word in Debug RAM so the debugger can tell if
         # an exception occurred.
         sw      s0, (DEBUG_RAM + DEBUG_RAM_SIZE - 4)(zero)
 
+        # Clear debug interrupt.
+        csrr    s0, CSR_MHARTID
+        sw      s0, CLEARDEBINT(zero)
+
 check_halt:
-        csrr    s0, DCSR
-        andi    s0, s0, (1<<DCSR_HALT_OFFSET)
+        csrr    s0, CSR_DCSR
+        andi    s0, s0, DCSR_HALT
         beqz    s0, exit
         j       wait_for_interrupt
 
 exit:
         # Restore s0.
-        csrr    s0, DSCRATCH
+        csrr    s0, CSR_DSCRATCH
         dret
 
-
 _entry:
         # Save s0 in DSCRATCH
-        csrw    DSCRATCH, s0
+        csrw    CSR_DSCRATCH, s0
 
         # Check why we're here
-        csrr    s0, DCSR
-        # cause is in bits 2:0 of dcsr
-        andi    s0, s0, 7
-        addi    s0, s0, -DCSR_CAUSE_DEBINT
+        csrr    s0, CSR_DCSR
+        # cause is in bits 8:6 of dcsr
+        andi    s0, s0, DCSR_CAUSE
+        addi    s0, s0, -(DCSR_CAUSE_DEBUGINT<<6)
         bnez    s0, spontaneous_halt
 
 jdebugram:
@@ -106,11 +100,11 @@ save_128:
 spontaneous_halt:
         csrr    s0, CSR_MHARTID
         sw      s0, SETHALTNOT(zero)
-        csrsi   DCSR, (1<<DCSR_HALT_OFFSET)
+        csrsi   CSR_DCSR, DCSR_HALT
 
 wait_for_interrupt:
-        csrr    s0, DCSR
-        andi    s0, s0, (1<<DCSR_DEBUGINT_OFFSET)
+        csrr    s0, CSR_DCSR
+        andi    s0, s0, DCSR_DEBUGINT
         beqz    s0, wait_for_interrupt
 
         j       jdebugram