@@ -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,26 @@ 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 );
17921792 write_val = set_field (write_val , DM_DMCS2_GROUP , group );
17931793 write_val = set_field (write_val , DM_DMCS2_GROUPTYPE , (grouptype == HALT_GROUP ) ? 0 : 1 );
1794+ write_val = set_field (write_val , DM_DMCS2_DMEXTTRIGGER , trigger_num );
1795+ write_val = set_field (write_val , DM_DMCS2_HGSELECT ,
1796+ is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS );
17941797 if (dm_write (target , DM_DMCS2 , write_val ) != ERROR_OK )
17951798 return ERROR_FAIL ;
17961799 uint32_t read_val ;
17971800 if (dm_read (target , & read_val , DM_DMCS2 ) != ERROR_OK )
17981801 return ERROR_FAIL ;
17991802 if (supported )
1800- * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group );
1803+ * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group &&
1804+ get_field (read_val , DM_DMCS2_GROUPTYPE ) == ((grouptype == HALT_GROUP ) ? 0 : 1 ) &&
1805+ get_field (read_val , DM_DMCS2_HGSELECT ) ==
1806+ (is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS ) &&
1807+ get_field (read_val , DM_DMCS2_DMEXTTRIGGER ) == trigger_num );
18011808 return ERROR_OK ;
18021809}
18031810
@@ -2145,14 +2152,33 @@ static int examine(struct target *target)
21452152 }
21462153
21472154 if (target -> smp ) {
2148- if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP ) != ERROR_OK )
2155+ if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP , false, 0 ) != ERROR_OK )
21492156 return ERROR_FAIL ;
21502157 if (info -> haltgroup_supported )
21512158 LOG_TARGET_INFO (target , "Core %d made part of halt group %d." , info -> index ,
21522159 target -> smp );
21532160 else
21542161 LOG_TARGET_INFO (target , "Core %d could not be made part of halt group %d." ,
21552162 info -> index , target -> smp );
2163+
2164+ for (unsigned int i = 0 ; i < RISCV_MAX_EXTTRIGGERS ; i ++ ) {
2165+ if (r -> external_triggers [i ].haltgroup_num != 0 &&
2166+ !r -> external_triggers [i ].haltgroup_was_set &&
2167+ info -> haltgroup_supported ) {
2168+ bool supported ;
2169+ if (set_group (target , & supported , target -> smp , HALT_GROUP , true, i ) != ERROR_OK )
2170+ return ERROR_FAIL ;
2171+ if (supported ) {
2172+ r -> external_triggers [i ].haltgroup_was_set = true;
2173+ LOG_TARGET_INFO (target , "External trigger %d made part of halt group %d." ,
2174+ i , target -> smp );
2175+ } else {
2176+ LOG_TARGET_WARNING (target , "External trigger %d could not be made part of halt group %d." ,
2177+ i , target -> smp );
2178+ }
2179+ }
2180+ }
2181+
21562182 }
21572183
21582184 /* Some regression suites rely on seeing 'Examined RISC-V core' to know
0 commit comments