contrib: replace the GPLv2-or-later license tag
[fw/openocd] / contrib / loaders / flash / nrf5 / nrf5.S
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4  *   Copyright (C) 2014 Angus Gratton                                      *
5  *   gus@projectgus.com                                                    *
6  ***************************************************************************/
7
8         .text
9         .syntax unified
10         .cpu cortex-m0
11         .thumb
12
13 /*
14  * Params :
15  * r0 = byte count
16  * r1 = buffer start
17  * r2 = buffer end
18  * r3 = target address
19  * r6 = watchdog refresh value
20  * r7 = watchdog refresh register address
21  */
22
23         .thumb_func
24         .global _start
25 _start:
26 wait_fifo:
27         // Kick the watchdog
28         str     r6, [r7, #0]
29         // Load write pointer
30         ldr     r5, [r1, #0]
31         // Abort if it is NULL
32         cmp     r5, #0
33         beq.n   exit
34         // Load read pointer
35         ldr     r4, [r1, #4]
36         // Continue waiting if it equals the write pointer
37         cmp     r4, r5
38         beq.n   wait_fifo
39         // Copy one word from buffer to target, and increment pointers
40         ldmia   r4!, {r5}
41         stmia   r3!, {r5}
42         // If at end of buffer, wrap back to buffer start
43         cmp     r4, r2
44         bcc.n   no_wrap
45         mov     r4, r1
46         adds    r4, #8
47 no_wrap:
48         // Update read pointer inside the buffer
49         str     r4, [r1, #4]
50         // Deduce the word transferred from the byte count
51         subs    r0, #4
52         // Start again
53         bne.n   wait_fifo
54 exit:
55         // Wait for OpenOCD
56         bkpt    #0x00
57
58         .pool