@@ -2913,11 +2913,15 @@ static int deassert_reset(struct target *target)
29132913 return dm_write (target , DM_DMCONTROL , control );
29142914}
29152915
2916- static int execute_fence (struct target * target )
2916+ static int execute_autofence (struct target * target )
29172917{
29182918 if (dm013_select_target (target ) != ERROR_OK )
29192919 return ERROR_FAIL ;
29202920
2921+ RISCV_INFO (r );
2922+ if (!r -> autofence )
2923+ return ERROR_OK ;
2924+
29212925 /* FIXME: For non-coherent systems we need to flush the caches right
29222926 * here, but there's no ISA-defined way of doing that. */
29232927 struct riscv_program program ;
@@ -2939,8 +2943,9 @@ static int execute_fence(struct target *target)
29392943 LOG_TARGET_ERROR (target , "Unexpected error during fence execution" );
29402944 return ERROR_FAIL ;
29412945 }
2942- LOG_TARGET_DEBUG (target , "Unable to execute fence" );
2946+ LOG_TARGET_DEBUG (target , "Unable to execute fence.i and fence rw, rw " );
29432947 }
2948+ LOG_TARGET_DEBUG (target , "Successfully executed fence.i and fence rw, rw" );
29442949 return ERROR_OK ;
29452950 }
29462951
@@ -2954,6 +2959,7 @@ static int execute_fence(struct target *target)
29542959 }
29552960 LOG_TARGET_DEBUG (target , "Unable to execute fence.i" );
29562961 }
2962+ LOG_TARGET_DEBUG (target , "Successfully executed fence.i" );
29572963
29582964 riscv_program_init (& program , target );
29592965 riscv_program_fence_rw_rw (& program );
@@ -2964,6 +2970,7 @@ static int execute_fence(struct target *target)
29642970 }
29652971 LOG_TARGET_DEBUG (target , "Unable to execute fence rw, rw" );
29662972 }
2973+ LOG_TARGET_DEBUG (target , "Successfully executed fence rw, rw" );
29672974 return ERROR_OK ;
29682975 }
29692976
@@ -4273,7 +4280,7 @@ read_memory_progbuf(struct target *target, target_addr_t address,
42734280
42744281 memset (buffer , 0 , count * size );
42754282
4276- if (execute_fence (target ) != ERROR_OK )
4283+ if (execute_autofence (target ) != ERROR_OK )
42774284 return MEM_ACCESS_SKIPPED_FENCE_EXEC_FAILED ;
42784285
42794286 uint64_t mstatus = 0 ;
@@ -4864,7 +4871,7 @@ write_memory_progbuf(struct target *target, target_addr_t address,
48644871 if (register_write_direct (target , GDB_REGNO_MSTATUS , mstatus_old ))
48654872 return MEM_ACCESS_FAILED ;
48664873
4867- if (execute_fence (target ) != ERROR_OK )
4874+ if (execute_autofence (target ) != ERROR_OK )
48684875 return MEM_ACCESS_SKIPPED_FENCE_EXEC_FAILED ;
48694876
48704877 return result == ERROR_OK ? MEM_ACCESS_OK : MEM_ACCESS_FAILED ;
@@ -5351,18 +5358,12 @@ static int riscv013_get_dmi_scan_length(struct target *target)
53515358 return info -> abits + DTM_DMI_DATA_LENGTH + DTM_DMI_OP_LENGTH ;
53525359}
53535360
5354- static int maybe_execute_fence_i (struct target * target )
5355- {
5356- if (has_sufficient_progbuf (target , 2 ))
5357- return execute_fence (target );
5358- return ERROR_OK ;
5359- }
5360-
53615361/* Helper Functions. */
53625362static int riscv013_on_step_or_resume (struct target * target , bool step )
53635363{
5364- if (maybe_execute_fence_i (target ) != ERROR_OK )
5365- return ERROR_FAIL ;
5364+ if (has_sufficient_progbuf (target , 2 ))
5365+ if (execute_autofence (target ) != ERROR_OK )
5366+ return ERROR_FAIL ;
53665367
53675368 if (set_dcsr_ebreak (target , step ) != ERROR_OK )
53685369 return ERROR_FAIL ;
0 commit comments