diff --git a/arch/arm/src/armv7-a/cp15_invalidate_dcache_all.S b/arch/arm/src/armv7-a/cp15_invalidate_dcache_all.S index 281541b664aa1..1cc048ecd2104 100644 --- a/arch/arm/src/armv7-a/cp15_invalidate_dcache_all.S +++ b/arch/arm/src/armv7-a/cp15_invalidate_dcache_all.S @@ -92,9 +92,12 @@ cp15_invalidate_dcache_all: mrc CP15_CCSIDR(r0) /* Read the Cache Size Identification Register */ - ldr r3, =0xffff /* Isolate the NumSets field (bits 13-27) */ + ldr r3, =0x7fff /* Isolate the NumSets field (bits 13-27) */ and r0, r3, r0, lsr #13 /* r0=NumSets (number of sets - 1) */ + ldr r3, =0x3ff /* Isolate the way field (bits 3-12) */ + add r4, r3, r0, lsr #3 /* r4=(number of ways - 1) */ + mov r1, #0 /* r1 = way loop counter */ way_loop: @@ -108,7 +111,7 @@ set_loop: bne set_loop /* Keep looping if not */ add r1, r1, #1 /* Increment the way counter */ - cmp r1, #4 /* Last way? (four ways assumed) */ + cmp r4, r1 /* Last way? */ bne way_loop /* Keep looping if not */ dsb diff --git a/arch/arm/src/armv7-r/cp15_invalidate_dcache_all.S b/arch/arm/src/armv7-r/cp15_invalidate_dcache_all.S index 53e1f745bbe4b..9662957ac836c 100644 --- a/arch/arm/src/armv7-r/cp15_invalidate_dcache_all.S +++ b/arch/arm/src/armv7-r/cp15_invalidate_dcache_all.S @@ -92,9 +92,12 @@ cp15_invalidate_dcache_all: mrc CP15_CCSIDR(r0) /* Read the Cache Size Identification Register */ - ldr r3, =0xffff /* Isolate the NumSets field (bits 13-27) */ + ldr r3, =0x7fff /* Isolate the NumSets field (bits 13-27) */ and r0, r3, r0, lsr #13 /* r0=NumSets (number of sets - 1) */ + ldr r3, =0x3ff /* Isolate the way field (bits 3-12) */ + add r4, r3, r0, lsr #3 /* r4=(number of ways - 1) */ + mov r1, #0 /* r1 = way loop counter */ way_loop: @@ -108,7 +111,7 @@ set_loop: bne set_loop /* Keep looping if not */ add r1, r1, #1 /* Increment the way counter */ - cmp r1, #4 /* Last way? (four ways assumed) */ + cmp r4, r1 /* Last way? (four ways assumed) */ bne way_loop /* Keep looping if not */ dsb