@@ -890,11 +890,11 @@ void riscv_info_init(struct target *target, riscv_info_t *r)
890890
891891int riscv_halt_all_harts (struct target * target )
892892{
893- if ( riscv_rtos_enabled (target )) {
894- for ( int i = 0 ; i < riscv_count_harts (target ); ++ i )
895- riscv_halt_one_hart ( target , i ) ;
896- } else {
897- riscv_halt_one_hart (target , riscv_current_hartid ( target ) );
893+ for ( int i = 0 ; i < riscv_count_harts (target ); ++ i ) {
894+ if (! riscv_hart_enabled (target , i ) )
895+ continue ;
896+
897+ riscv_halt_one_hart (target , i );
898898 }
899899
900900 return ERROR_OK ;
@@ -916,11 +916,11 @@ int riscv_halt_one_hart(struct target *target, int hartid)
916916
917917int riscv_resume_all_harts (struct target * target )
918918{
919- if ( riscv_rtos_enabled (target )) {
920- for ( int i = 0 ; i < riscv_count_harts (target ); ++ i )
921- riscv_resume_one_hart ( target , i ) ;
922- } else {
923- riscv_resume_one_hart (target , riscv_current_hartid ( target ) );
919+ for ( int i = 0 ; i < riscv_count_harts (target ); ++ i ) {
920+ if (! riscv_hart_enabled (target , i ) )
921+ continue ;
922+
923+ riscv_resume_one_hart (target , i );
924924 }
925925
926926 riscv_invalidate_register_cache (target );
@@ -944,11 +944,11 @@ int riscv_resume_one_hart(struct target *target, int hartid)
944944
945945int riscv_reset_all_harts (struct target * target )
946946{
947- if ( riscv_rtos_enabled (target )) {
948- for ( int i = 0 ; i < riscv_count_harts (target ); ++ i )
949- riscv_reset_one_hart ( target , i ) ;
950- } else {
951- riscv_reset_one_hart (target , riscv_current_hartid ( target ) );
947+ for ( int i = 0 ; i < riscv_count_harts (target ); ++ i ) {
948+ if (! riscv_hart_enabled (target , i ) )
949+ continue ;
950+
951+ riscv_reset_one_hart (target , i );
952952 }
953953
954954 riscv_invalidate_register_cache (target );
@@ -1018,10 +1018,9 @@ void riscv_set_current_hartid(struct target *target, int hartid)
10181018
10191019 int previous_hartid = riscv_current_hartid (target );
10201020 r -> current_hartid = hartid ;
1021- assert (riscv_rtos_enabled (target ) || target -> coreid == hartid );
1021+ assert (riscv_hart_enabled (target , hartid ) );
10221022 LOG_DEBUG ("setting hartid to %d, was %d" , hartid , previous_hartid );
1023- if (riscv_rtos_enabled (target ))
1024- r -> select_current_hart (target );
1023+ r -> select_current_hart (target );
10251024
10261025 /* This might get called during init, in which case we shouldn't be
10271026 * setting up the register cache. */
@@ -1234,3 +1233,12 @@ int riscv_dmi_write_u64_bits(struct target *target)
12341233 RISCV_INFO (r );
12351234 return r -> dmi_write_u64_bits (target );
12361235}
1236+
1237+ bool riscv_hart_enabled (struct target * target , int hartid )
1238+ {
1239+ /* FIXME: Add a hart mask to the RTOS. */
1240+ if (riscv_rtos_enabled (target ))
1241+ return hartid < riscv_count_harts (target );
1242+
1243+ return hartid == target -> coreid ;
1244+ }
0 commit comments