@@ -346,6 +346,26 @@ int esp_riscv_semihosting(struct target *target)
346346 struct esp_riscv_common * esp_riscv = target_to_esp_riscv (target );
347347 struct semihosting * semihosting = target -> semihosting ;
348348
349+ /*
350+ If a bp/wp set request comes from Core1, the other cores may continue running.
351+ We need to ensure that all harts are in a halted state.
352+ */
353+ if (target -> smp && (semihosting -> op == ESP_SEMIHOSTING_SYS_BREAKPOINT_SET ||
354+ semihosting -> op == ESP_SEMIHOSTING_SYS_WATCHPOINT_SET )) {
355+ struct target_list * head ;
356+ foreach_smp_target (head , target -> smp_targets ) {
357+ struct target * curr = head -> target ;
358+ if (curr -> state != TARGET_HALTED ) {
359+ LOG_TARGET_DEBUG (curr , "Target must be in halted state. Try to halt it" );
360+ res = riscv_halt (curr );
361+ if (res != ERROR_OK )
362+ return res ;
363+ /* Here all halts are in the halted state. Resume-all will be handled in riscv_semihosting() return */
364+ break ;
365+ }
366+ }
367+ }
368+
349369 switch (semihosting -> op ) {
350370 case ESP_SEMIHOSTING_SYS_APPTRACE_INIT :
351371 res = esp_riscv_apptrace_info_init (target , semihosting -> param , NULL );
@@ -374,7 +394,7 @@ int esp_riscv_semihosting(struct target *target)
374394 return ERROR_FAIL ;
375395 }
376396 int set = semihosting_get_field (target ,
377- ESP_RISCV_SET_WATCHPOINT_ARG_SET ,
397+ ESP_RISCV_SET_BREAKPOINT_ARG_SET ,
378398 fields );
379399 if (set ) {
380400 if (esp_riscv -> target_bp_addr [id ]) {
0 commit comments