@@ -68,12 +68,8 @@ static int riscv013_access_memory(struct target *target, const riscv_mem_access_
6868static bool riscv013_get_impebreak (const struct target * target );
6969static unsigned int riscv013_get_progbufsize (const struct target * target );
7070
71- typedef enum {
72- HALT_GROUP ,
73- RESUME_GROUP
74- } grouptype_t ;
7571static int set_group (struct target * target , bool * supported , unsigned int group ,
76- grouptype_t grouptype );
72+ enum grouptype grouptype , bool is_trigger , unsigned int trigger_num );
7773
7874/**
7975 * Since almost everything can be accomplish by scanning the dbus register, all
@@ -138,6 +134,8 @@ typedef struct {
138134 * abstractcs.busy may have remained set. In that case we may need to
139135 * re-check the busy state before executing these operations. */
140136 bool abstract_cmd_maybe_busy ;
137+
138+ struct riscv_ext_trigger external_triggers [RISCV_MAX_EXTTRIGGERS ];
141139} dm013_info_t ;
142140
143141typedef struct {
@@ -1732,7 +1730,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
17321730
17331731 if (info -> haltgroup_supported ) {
17341732 bool supported ;
1735- if (set_group (target , & supported , 0 , HALT_GROUP ) != ERROR_OK )
1733+ if (set_group (target , & supported , 0 , HALT_GROUP , false, 0 ) != ERROR_OK )
17361734 return ERROR_FAIL ;
17371735 if (!supported )
17381736 LOG_TARGET_ERROR (target , "Couldn't place hart in halt group 0. "
@@ -1754,7 +1752,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
17541752 /* Add it back to the halt group. */
17551753 if (info -> haltgroup_supported ) {
17561754 bool supported ;
1757- if (set_group (target , & supported , target -> smp , HALT_GROUP ) != ERROR_OK )
1755+ if (set_group (target , & supported , target -> smp , HALT_GROUP , false, 0 ) != ERROR_OK )
17581756 return ERROR_FAIL ;
17591757 if (!supported )
17601758 LOG_TARGET_ERROR (target , "Couldn't place hart back in halt group %d. "
@@ -1785,19 +1783,46 @@ static void deinit_target(struct target *target)
17851783}
17861784
17871785static int set_group (struct target * target , bool * supported , unsigned int group ,
1788- grouptype_t grouptype )
1786+ enum grouptype grouptype , bool is_trigger , unsigned int trigger_num )
17891787{
1790- uint32_t write_val = DM_DMCS2_HGWRITE ;
17911788 assert (group <= 31 );
1789+ assert (trigger_num < 16 );
1790+
1791+ if (!is_trigger && dm013_select_target (target ) != ERROR_OK )
1792+ return ERROR_FAIL ;
1793+
1794+ dm013_info_t * dm = get_dm (target );
1795+ if (!dm )
1796+ return ERROR_FAIL ;
1797+ if (is_trigger && dm -> external_triggers [trigger_num ].haltgroup_was_set &&
1798+ dm -> external_triggers [trigger_num ].haltgroup_num == group ) {
1799+ LOG_TARGET_WARNING (target , "External trigger %d (at address dbgbase=0x%" PRIx32 ") for halt group %d has been set." ,
1800+ trigger_num , dm -> base , group );
1801+ return ERROR_OK ;
1802+ }
1803+
1804+ uint32_t write_val = DM_DMCS2_HGWRITE ;
17921805 write_val = set_field (write_val , DM_DMCS2_GROUP , group );
17931806 write_val = set_field (write_val , DM_DMCS2_GROUPTYPE , (grouptype == HALT_GROUP ) ? 0 : 1 );
1807+ write_val = set_field (write_val , DM_DMCS2_DMEXTTRIGGER , trigger_num );
1808+ write_val = set_field (write_val , DM_DMCS2_HGSELECT ,
1809+ is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS );
17941810 if (dm_write (target , DM_DMCS2 , write_val ) != ERROR_OK )
17951811 return ERROR_FAIL ;
17961812 uint32_t read_val ;
17971813 if (dm_read (target , & read_val , DM_DMCS2 ) != ERROR_OK )
17981814 return ERROR_FAIL ;
17991815 if (supported )
1800- * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group );
1816+ * supported = (get_field (read_val , DM_DMCS2_GROUP ) == group &&
1817+ get_field (read_val , DM_DMCS2_GROUPTYPE ) == ((grouptype == HALT_GROUP ) ? 0 : 1 ) &&
1818+ get_field (read_val , DM_DMCS2_HGSELECT ) ==
1819+ (is_trigger ? DM_DMCS2_HGSELECT_TRIGGERS : DM_DMCS2_HGSELECT_HARTS ) &&
1820+ get_field (read_val , DM_DMCS2_DMEXTTRIGGER ) == trigger_num );
1821+ if (is_trigger && * supported ) {
1822+ dm -> external_triggers [trigger_num ].haltgroup_was_set = true;
1823+ dm -> external_triggers [trigger_num ].haltgroup_num = group ;
1824+ }
1825+
18011826 return ERROR_OK ;
18021827}
18031828
@@ -2145,8 +2170,9 @@ static int examine(struct target *target)
21452170 }
21462171
21472172 if (target -> smp ) {
2148- if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP ) != ERROR_OK )
2173+ if (set_group (target , & info -> haltgroup_supported , target -> smp , HALT_GROUP , false, 0 ) != ERROR_OK )
21492174 return ERROR_FAIL ;
2175+
21502176 if (info -> haltgroup_supported )
21512177 LOG_TARGET_INFO (target , "Core %d made part of halt group %d." , info -> index ,
21522178 target -> smp );
@@ -2881,6 +2907,8 @@ static int init_target(struct command_context *cmd_ctx,
28812907 generic_info -> handle_became_unavailable = & handle_became_unavailable ;
28822908 generic_info -> tick = & tick ;
28832909
2910+ generic_info -> set_group = & set_group ;
2911+
28842912 if (!generic_info -> version_specific ) {
28852913 generic_info -> version_specific = calloc (1 , sizeof (riscv013_info_t ));
28862914 if (!generic_info -> version_specific )
0 commit comments