@@ -251,9 +251,9 @@ typedef struct {
251
251
/* This target was selected using hasel. */
252
252
bool selected ;
253
253
254
- /* When false, we need to set dcsr.ebreak*, halting the target if that's
255
- * necessary. */
256
- bool dcsr_ebreak_is_set ;
254
+ /* When false, we need to configure certain bits in the dcsr register.
255
+ * To do that, we may momentarily halt the target, if necessary. */
256
+ bool dcsr_register_is_set ;
257
257
258
258
/* This hart was placed into a halt group in examine(). */
259
259
bool haltgroup_supported ;
@@ -1674,9 +1674,9 @@ static int wait_for_authbusy(struct target *target, uint32_t *dmstatus)
1674
1674
return ERROR_OK ;
1675
1675
}
1676
1676
1677
- static int set_dcsr_ebreak (struct target * target , bool step )
1677
+ static int set_dcsr_config (struct target * target , bool step )
1678
1678
{
1679
- LOG_TARGET_DEBUG (target , "Set dcsr.ebreak* " );
1679
+ LOG_TARGET_DEBUG (target , "Set dcsr config " );
1680
1680
1681
1681
if (dm013_select_target (target ) != ERROR_OK )
1682
1682
return ERROR_FAIL ;
@@ -1694,18 +1694,20 @@ static int set_dcsr_ebreak(struct target *target, bool step)
1694
1694
dcsr = set_field (dcsr , CSR_DCSR_EBREAKU , config -> dcsr_ebreak_fields [RISCV_MODE_U ]);
1695
1695
dcsr = set_field (dcsr , CSR_DCSR_EBREAKVS , config -> dcsr_ebreak_fields [RISCV_MODE_VS ]);
1696
1696
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 );
1697
1698
if (dcsr != original_dcsr &&
1698
1699
riscv_reg_set (target , GDB_REGNO_DCSR , dcsr ) != ERROR_OK )
1699
1700
return ERROR_FAIL ;
1700
- info -> dcsr_ebreak_is_set = true;
1701
+ // TODO: Read back the DCSR and check if these WARL bits are set as the user intended.
1702
+ info -> dcsr_register_is_set = true;
1701
1703
return ERROR_OK ;
1702
1704
}
1703
1705
1704
- static int halt_set_dcsr_ebreak (struct target * target )
1706
+ static int halt_set_dcsr_config (struct target * target )
1705
1707
{
1706
1708
RISCV_INFO (r );
1707
1709
RISCV013_INFO (info );
1708
- LOG_TARGET_DEBUG (target , "Halt to set DCSR.ebreak* " );
1710
+ LOG_TARGET_DEBUG (target , "Halt to set dcsr config " );
1709
1711
1710
1712
/* Remove this hart from the halt group. This won't work on all targets
1711
1713
* because the debug spec allows halt groups to be hard-coded, but I
@@ -1743,7 +1745,7 @@ static int halt_set_dcsr_ebreak(struct target *target)
1743
1745
1744
1746
r -> prepped = true;
1745
1747
if (riscv013_halt_go (target ) != ERROR_OK ||
1746
- set_dcsr_ebreak (target , false) != ERROR_OK ||
1748
+ set_dcsr_config (target , false) != ERROR_OK ||
1747
1749
riscv013_step_or_resume_current_hart (target , false) != ERROR_OK ) {
1748
1750
result = ERROR_FAIL ;
1749
1751
} else {
@@ -2132,7 +2134,7 @@ static int examine(struct target *target)
2132
2134
if (result != ERROR_OK )
2133
2135
return result ;
2134
2136
2135
- if (set_dcsr_ebreak (target , false) != ERROR_OK )
2137
+ if (set_dcsr_config (target , false) != ERROR_OK )
2136
2138
return ERROR_FAIL ;
2137
2139
2138
2140
if (state_at_examine_start == RISCV_STATE_RUNNING ) {
@@ -2779,7 +2781,7 @@ static int riscv013_get_hart_state(struct target *target, enum riscv_hart_state
2779
2781
return ERROR_FAIL ;
2780
2782
if (get_field (dmstatus , DM_DMSTATUS_ANYHAVERESET )) {
2781
2783
LOG_TARGET_INFO (target , "Hart unexpectedly reset!" );
2782
- info -> dcsr_ebreak_is_set = false;
2784
+ info -> dcsr_register_is_set = false;
2783
2785
/* TODO: Can we make this more obvious to eg. a gdb user? */
2784
2786
uint32_t dmcontrol = DM_DMCONTROL_DMACTIVE |
2785
2787
DM_DMCONTROL_ACKHAVERESET ;
@@ -2830,17 +2832,17 @@ static int handle_became_unavailable(struct target *target,
2830
2832
2831
2833
riscv_reg_cache_invalidate_all (target );
2832
2834
2833
- info -> dcsr_ebreak_is_set = false;
2835
+ info -> dcsr_register_is_set = false;
2834
2836
return ERROR_OK ;
2835
2837
}
2836
2838
2837
2839
static int tick (struct target * target )
2838
2840
{
2839
2841
RISCV013_INFO (info );
2840
- if (!info -> dcsr_ebreak_is_set &&
2842
+ if (!info -> dcsr_register_is_set &&
2841
2843
target -> state == TARGET_RUNNING &&
2842
2844
target_was_examined (target ))
2843
- return halt_set_dcsr_ebreak (target );
2845
+ return halt_set_dcsr_config (target );
2844
2846
return ERROR_OK ;
2845
2847
}
2846
2848
@@ -2939,13 +2941,13 @@ static int assert_reset(struct target *target)
2939
2941
return riscv013_invalidate_cached_progbuf (target );
2940
2942
}
2941
2943
2942
- static bool dcsr_ebreak_config_equals_reset_value (const struct target * target )
2944
+ static bool dcsr_config_equals_reset_value (const struct target * target )
2943
2945
{
2944
2946
const struct riscv_private_config * const config = riscv_private_config (target );
2945
2947
for (int i = 0 ; i < N_RISCV_MODE ; ++ i )
2946
2948
if (config -> dcsr_ebreak_fields [i ])
2947
2949
return false;
2948
- return true ;
2950
+ return ! config -> dcsr_cetrig ;
2949
2951
}
2950
2952
2951
2953
static int deassert_reset (struct target * target )
@@ -3023,7 +3025,7 @@ static int deassert_reset(struct target *target)
3023
3025
target -> state = TARGET_RUNNING ;
3024
3026
target -> debug_reason = DBG_REASON_NOTHALTED ;
3025
3027
}
3026
- info -> dcsr_ebreak_is_set = dcsr_ebreak_config_equals_reset_value (target );
3028
+ info -> dcsr_register_is_set = dcsr_config_equals_reset_value (target );
3027
3029
return ERROR_OK ;
3028
3030
}
3029
3031
@@ -5367,6 +5369,16 @@ static enum riscv_halt_reason riscv013_halt_reason(struct target *target)
5367
5369
return RISCV_HALT_INTERRUPT ;
5368
5370
case CSR_DCSR_CAUSE_GROUP :
5369
5371
return RISCV_HALT_GROUP ;
5372
+ case CSR_DCSR_CAUSE_OTHER :
5373
+ switch (get_field (dcsr , CSR_DCSR_EXTCAUSE )) {
5374
+ case 0 :
5375
+ LOG_TARGET_WARNING (target , "halted because of hart in a critical error state." );
5376
+ return RISCV_HALT_CRITICAL_ERROR ;
5377
+ default :
5378
+ LOG_TARGET_ERROR (target , "Unknown DCSR extcause field: 0x%"
5379
+ PRIx64 , get_field (dcsr , CSR_DCSR_EXTCAUSE ));
5380
+ return RISCV_HALT_UNKNOWN ;
5381
+ }
5370
5382
}
5371
5383
5372
5384
LOG_TARGET_ERROR (target , "Unknown DCSR cause field: 0x%" PRIx64 , get_field (dcsr , CSR_DCSR_CAUSE ));
@@ -5462,7 +5474,7 @@ static int riscv013_on_step_or_resume(struct target *target, bool step)
5462
5474
if (execute_autofence (target ) != ERROR_OK )
5463
5475
return ERROR_FAIL ;
5464
5476
5465
- if (set_dcsr_ebreak (target , step ) != ERROR_OK )
5477
+ if (set_dcsr_config (target , step ) != ERROR_OK )
5466
5478
return ERROR_FAIL ;
5467
5479
5468
5480
if (riscv_reg_flush_all (target ) != ERROR_OK )
0 commit comments