@@ -251,9 +251,9 @@ typedef struct {
251251 /* This target was selected using hasel. */
252252 bool selected ;
253253
254- /* When false, we need to set dcsr.ebreak* , halting the target if that's
254+ /* When false, we need to set dcsr config , halting the target if that's
255255 * necessary. */
256- bool dcsr_ebreak_is_set ;
256+ bool dcsr_config_is_set ;
257257
258258 /* This hart was placed into a halt group in examine(). */
259259 bool haltgroup_supported ;
@@ -1674,7 +1674,7 @@ static int wait_for_authbusy(struct target *target, uint32_t *dmstatus)
16741674 return ERROR_OK ;
16751675}
16761676
1677- static int set_dcsr_ebreak (struct target * target , bool step )
1677+ static int set_dcsr_config (struct target * target , bool step )
16781678{
16791679 LOG_TARGET_DEBUG (target , "Set dcsr.ebreak*" );
16801680
@@ -1694,14 +1694,15 @@ static int set_dcsr_ebreak(struct target *target, bool step)
16941694 dcsr = set_field (dcsr , CSR_DCSR_EBREAKU , config -> dcsr_ebreak_fields [RISCV_MODE_U ]);
16951695 dcsr = set_field (dcsr , CSR_DCSR_EBREAKVS , config -> dcsr_ebreak_fields [RISCV_MODE_VS ]);
16961696 dcsr = set_field (dcsr , CSR_DCSR_EBREAKVU , config -> dcsr_ebreak_fields [RISCV_MODE_VU ]);
1697+ dcsr = set_field (dcsr , CSR_DCSR_CETRIG , config -> dcsr_cetrig );
16971698 if (dcsr != original_dcsr &&
16981699 riscv_reg_set (target , GDB_REGNO_DCSR , dcsr ) != ERROR_OK )
16991700 return ERROR_FAIL ;
1700- info -> dcsr_ebreak_is_set = true;
1701+ info -> dcsr_config_is_set = true;
17011702 return ERROR_OK ;
17021703}
17031704
1704- static int halt_set_dcsr_ebreak (struct target * target )
1705+ static int halt_set_dcsr_config (struct target * target )
17051706{
17061707 RISCV_INFO (r );
17071708 RISCV013_INFO (info );
@@ -1743,7 +1744,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
17431744
17441745 r -> prepped = true;
17451746 if (riscv013_halt_go (target ) != ERROR_OK ||
1746- set_dcsr_ebreak (target , false) != ERROR_OK ||
1747+ set_dcsr_config (target , false) != ERROR_OK ||
17471748 riscv013_step_or_resume_current_hart (target , false) != ERROR_OK ) {
17481749 result = ERROR_FAIL ;
17491750 } else {
@@ -2132,7 +2133,7 @@ static int examine(struct target *target)
21322133 if (result != ERROR_OK )
21332134 return result ;
21342135
2135- if (set_dcsr_ebreak (target , false) != ERROR_OK )
2136+ if (set_dcsr_config (target , false) != ERROR_OK )
21362137 return ERROR_FAIL ;
21372138
21382139 if (state_at_examine_start == RISCV_STATE_RUNNING ) {
@@ -2779,7 +2780,7 @@ static int riscv013_get_hart_state(struct target *target, enum riscv_hart_state
27792780 return ERROR_FAIL ;
27802781 if (get_field (dmstatus , DM_DMSTATUS_ANYHAVERESET )) {
27812782 LOG_TARGET_INFO (target , "Hart unexpectedly reset!" );
2782- info -> dcsr_ebreak_is_set = false;
2783+ info -> dcsr_config_is_set = false;
27832784 /* TODO: Can we make this more obvious to eg. a gdb user? */
27842785 uint32_t dmcontrol = DM_DMCONTROL_DMACTIVE |
27852786 DM_DMCONTROL_ACKHAVERESET ;
@@ -2830,17 +2831,17 @@ static int handle_became_unavailable(struct target *target,
28302831
28312832 riscv_reg_cache_invalidate_all (target );
28322833
2833- info -> dcsr_ebreak_is_set = false;
2834+ info -> dcsr_config_is_set = false;
28342835 return ERROR_OK ;
28352836}
28362837
28372838static int tick (struct target * target )
28382839{
28392840 RISCV013_INFO (info );
2840- if (!info -> dcsr_ebreak_is_set &&
2841+ if (!info -> dcsr_config_is_set &&
28412842 target -> state == TARGET_RUNNING &&
28422843 target_was_examined (target ))
2843- return halt_set_dcsr_ebreak (target );
2844+ return halt_set_dcsr_config (target );
28442845 return ERROR_OK ;
28452846}
28462847
@@ -2939,13 +2940,13 @@ static int assert_reset(struct target *target)
29392940 return riscv013_invalidate_cached_progbuf (target );
29402941}
29412942
2942- static bool dcsr_ebreak_config_equals_reset_value (const struct target * target )
2943+ static bool dcsr_config_equals_reset_value (const struct target * target )
29432944{
29442945 const struct riscv_private_config * const config = riscv_private_config (target );
29452946 for (int i = 0 ; i < N_RISCV_MODE ; ++ i )
29462947 if (config -> dcsr_ebreak_fields [i ])
29472948 return false;
2948- return true ;
2949+ return ! config -> dcsr_cetrig ;
29492950}
29502951
29512952static int deassert_reset (struct target * target )
@@ -3023,7 +3024,7 @@ static int deassert_reset(struct target *target)
30233024 target -> state = TARGET_RUNNING ;
30243025 target -> debug_reason = DBG_REASON_NOTHALTED ;
30253026 }
3026- info -> dcsr_ebreak_is_set = dcsr_ebreak_config_equals_reset_value (target );
3027+ info -> dcsr_config_is_set = dcsr_config_equals_reset_value (target );
30273028 return ERROR_OK ;
30283029}
30293030
@@ -5367,6 +5368,14 @@ static enum riscv_halt_reason riscv013_halt_reason(struct target *target)
53675368 return RISCV_HALT_INTERRUPT ;
53685369 case CSR_DCSR_CAUSE_GROUP :
53695370 return RISCV_HALT_GROUP ;
5371+ case CSR_DCSR_CAUSE_OTHER :
5372+ if (get_field (dcsr , CSR_DCSR_EXTCAUSE ) == 0 ) {
5373+ LOG_TARGET_INFO (target , "halted because of hart in a critical error state." );
5374+ return RISCV_HALT_CRITERR ;
5375+ }
5376+ LOG_TARGET_ERROR (target , "Unknown DCSR extcause field: 0x%"
5377+ PRIx64 , get_field (dcsr , CSR_DCSR_EXTCAUSE ));
5378+ return RISCV_HALT_UNKNOWN ;
53705379 }
53715380
53725381 LOG_TARGET_ERROR (target , "Unknown DCSR cause field: 0x%" PRIx64 , get_field (dcsr , CSR_DCSR_CAUSE ));
@@ -5462,7 +5471,7 @@ static int riscv013_on_step_or_resume(struct target *target, bool step)
54625471 if (execute_autofence (target ) != ERROR_OK )
54635472 return ERROR_FAIL ;
54645473
5465- if (set_dcsr_ebreak (target , step ) != ERROR_OK )
5474+ if (set_dcsr_config (target , step ) != ERROR_OK )
54665475 return ERROR_FAIL ;
54675476
54685477 if (riscv_reg_flush_all (target ) != ERROR_OK )
0 commit comments