@@ -121,7 +121,8 @@ typedef enum slot {
121121
122122/*** Info about the core being debugged. ***/
123123
124- #define WALL_CLOCK_TIMEOUT 2
124+ #define WALL_CLOCK_TIMEOUT 2
125+ #define WALL_CLOCK_RESET_TIMEOUT 30
125126
126127struct trigger {
127128 uint64_t address ;
@@ -199,6 +200,14 @@ static void decode_dmi(char *text, unsigned address, unsigned data)
199200 uint64_t mask ;
200201 const char * name ;
201202 } description [] = {
203+ { DMI_DMCONTROL , DMI_DMCONTROL_HALTREQ , "haltreq" },
204+ { DMI_DMCONTROL , DMI_DMCONTROL_RESUMEREQ , "resumereq" },
205+ { DMI_DMCONTROL , DMI_DMCONTROL_HARTRESET , "hartreset" },
206+ { DMI_DMCONTROL , DMI_DMCONTROL_HASEL , "hasel" },
207+ { DMI_DMCONTROL , DMI_DMCONTROL_HARTSEL , "hartsel" },
208+ { DMI_DMCONTROL , DMI_DMCONTROL_NDMRESET , "ndmreset" },
209+ { DMI_DMCONTROL , DMI_DMCONTROL_DMACTIVE , "dmactive" },
210+
202211 { DMI_DMSTATUS , DMI_DMSTATUS_ALLRESUMEACK , "allresumeack" },
203212 { DMI_DMSTATUS , DMI_DMSTATUS_ANYRESUMEACK , "anyresumeack" },
204213 { DMI_DMSTATUS , DMI_DMSTATUS_ALLNONEXISTENT , "allnonexistent" },
@@ -1874,7 +1883,19 @@ void riscv013_reset_current_hart(struct target *target)
18741883 control = set_field (control , DMI_DMCONTROL_NDMRESET , 0 );
18751884 dmi_write (target , DMI_DMCONTROL , control );
18761885
1877- while (get_field (dmi_read (target , DMI_DMSTATUS ), DMI_DMSTATUS_ALLHALTED ) == 0 );
1886+ time_t start = time (NULL );
1887+
1888+ while (1 ) {
1889+ uint32_t dmstatus = dmi_read (target , DMI_DMSTATUS );
1890+ if (get_field (dmstatus , DMI_DMSTATUS_ALLHALTED )) {
1891+ break ;
1892+ }
1893+ if (time (NULL ) - start > WALL_CLOCK_RESET_TIMEOUT ) {
1894+ LOG_ERROR ("Hart didn't halt coming out of reset in %ds; "
1895+ "dmstatus=0x%x" , WALL_CLOCK_RESET_TIMEOUT , dmstatus );
1896+ return ;
1897+ }
1898+ }
18781899
18791900 control = set_field (control , DMI_DMCONTROL_HALTREQ , 0 );
18801901 dmi_write (target , DMI_DMCONTROL , control );
0 commit comments