@@ -73,7 +73,7 @@ typedef enum {
7373 RESUME_GROUP
7474} grouptype_t ;
7575static int set_group (struct target * target , bool * supported , unsigned int group ,
76- grouptype_t grouptype );
76+ grouptype_t grouptype , bool is_trigger , unsigned int trigger_num );
7777
7878/**
7979 * Since almost everything can be accomplish by scanning the dbus register, all
@@ -1732,7 +1732,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
17321732
17331733 if (info -> haltgroup_supported ) {
17341734 bool supported ;
1735- if (set_group (target , & supported , 0 , HALT_GROUP ) != ERROR_OK )
1735+ if (set_group (target , & supported , 0 , HALT_GROUP , false, 0 ) != ERROR_OK )
17361736 return ERROR_FAIL ;
17371737 if (!supported )
17381738 LOG_TARGET_ERROR (target , "Couldn't place hart in halt group 0. "
@@ -1754,7 +1754,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
17541754 /* Add it back to the halt group. */
17551755 if (info -> haltgroup_supported ) {
17561756 bool supported ;
1757- if (set_group (target , & supported , target -> smp , HALT_GROUP ) != ERROR_OK )
1757+ if (set_group (target , & supported , target -> smp , HALT_GROUP , false, 0 ) != ERROR_OK )
17581758 return ERROR_FAIL ;
17591759 if (!supported )
17601760 LOG_TARGET_ERROR (target , "Couldn't place hart back in halt group %d. "
@@ -1785,19 +1785,27 @@ static void deinit_target(struct target *target)
17851785}
17861786
17871787static int set_group (struct target * target , bool * supported , unsigned int group ,
1788- grouptype_t grouptype )
1788+ grouptype_t grouptype , bool is_trigger , unsigned int trigger_num )
17891789{
17901790 uint32_t write_val = DM_DMCS2_HGWRITE ;
17911791 assert (group <= 31 );
1792+ assert (trigger_num < 16 );
17921793 write_val = set_field (write_val , DM_DMCS2_GROUP , group );
17931794 write_val = set_field (write_val , DM_DMCS2_GROUPTYPE , (grouptype == HALT_GROUP ) ? 0 : 1 );
1795+ write_val = set_field (write_val , DM_DMCS2_DMEXTTRIGGER , trigger_num );
1796+ write_val = set_field (write_val , DM_DMCS2_HGSELECT ,
1797+ is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS );
17941798 if (dm_write (target , DM_DMCS2 , write_val ) != ERROR_OK )
17951799 return ERROR_FAIL ;
17961800 uint32_t read_val ;
17971801 if (dm_read (target , & read_val , DM_DMCS2 ) != ERROR_OK )
17981802 return ERROR_FAIL ;
17991803 if (supported )
1800- * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group );
1804+ * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group &&
1805+ get_field (read_val , DM_DMCS2_GROUPTYPE ) == ((grouptype == HALT_GROUP ) ? 0 : 1 ) &&
1806+ get_field (read_val , DM_DMCS2_HGSELECT ) ==
1807+ (is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS ) &&
1808+ get_field (read_val , DM_DMCS2_DMEXTTRIGGER ) == trigger_num );
18011809 return ERROR_OK ;
18021810}
18031811
@@ -2145,14 +2153,33 @@ static int examine(struct target *target)
21452153 }
21462154
21472155 if (target -> smp ) {
2148- if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP ) != ERROR_OK )
2156+ if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP , false, 0 ) != ERROR_OK )
21492157 return ERROR_FAIL ;
21502158 if (info -> haltgroup_supported )
21512159 LOG_TARGET_INFO (target , "Core %d made part of halt group %d." , info -> index ,
21522160 target -> smp );
21532161 else
21542162 LOG_TARGET_INFO (target , "Core %d could not be made part of halt group %d." ,
21552163 info -> index , target -> smp );
2164+
2165+ for (unsigned int i = 0 ; i < RISCV_MAX_EXTTRIGGERS ; i ++ ) {
2166+ if (r -> external_triggers [i ].haltgroup_num != 0 &&
2167+ !r -> external_triggers [i ].haltgroup_was_set &&
2168+ info -> haltgroup_supported ) {
2169+ bool supported ;
2170+ if (set_group (target , & supported , target -> smp , HALT_GROUP , true, i ) != ERROR_OK )
2171+ return ERROR_FAIL ;
2172+ if (supported ) {
2173+ r -> external_triggers [i ].haltgroup_was_set = true;
2174+ LOG_TARGET_INFO (target , "External trigger %d made part of halt group %d." ,
2175+ i , target -> smp );
2176+ } else {
2177+ LOG_TARGET_WARNING (target , "External trigger %d could not be made part of halt group %d." ,
2178+ i , target -> smp );
2179+ }
2180+ }
2181+ }
2182+
21562183 }
21572184
21582185 /* Some regression suites rely on seeing 'Examined RISC-V core' to know
0 commit comments