tcl/board/arty_s7: Fix proc and chip name
[fw/openocd] / contrib / loaders / erase_check / armv7m_erase_check.s
index 886e3e28004cd66720763713922528316aed56bf..3303c8778ba68d48d554f0eefd7330a7cd739638 100644 (file)
@@ -20,9 +20,8 @@
 
 /*
        parameters:
-       r0 - address in
-       r1 - byte count
-       r2 - mask - result out
+       r0 - pointer to struct { uint32_t size_in_result_out, uint32_t addr }
+       r1 - value to check
 */
 
        .text
 
        .align  2
 
-loop:
-       ldrb    r3, [r0]
-       adds    r0, #1
-       ands    r2, r2, r3
-       subs    r1, r1, #1
-       bne             loop
-end:
+BLOCK_SIZE_RESULT      = 0
+BLOCK_ADDRESS          = 4
+SIZEOF_STRUCT_BLOCK    = 8
+
+start:
+block_loop:
+       ldr     r2, [r0, #BLOCK_SIZE_RESULT]    /* get size */
+       tst     r2, r2
+       beq     done
+
+       ldr     r3, [r0, #BLOCK_ADDRESS]        /* get address */
+
+word_loop:
+       ldr     r4, [r3]        /* read word */
+       adds    r3, #4
+
+       cmp     r4, r1
+       bne     not_erased
+
+       subs    r2, #1
+       bne     word_loop
+
+       movs    r4, #1          /* block is erased */
+save_result:
+       str     r4, [r0, #BLOCK_SIZE_RESULT]
+       adds    r0, #SIZEOF_STRUCT_BLOCK
+       b       block_loop
+
+not_erased:
+       movs    r4, #0
+       b       save_result
+
+/* Avoid padding at .text segment end. Otherwise exit point check fails. */
+        .skip   ( . - start + 2) & 2, 0
+
+done:
        bkpt    #0
 
        .end