279b17503636f7a3abc3aadc9dfeef1996910d32
[fw/openocd] / contrib / loaders / flash / str9x.s
1 /***************************************************************************
2  *   Copyright (C) 2010 by Spencer Oliver                                  *
3  *   spen@spen-soft.co.uk                                                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
19  ***************************************************************************/
20
21         .text
22         .arm
23         .arch armv5t
24
25         .section .init
26 /*
27         r0 source address (in)
28         r1 target address (in)
29         r2 word count (in)
30         r3 result (out)
31 */
32
33 write:
34         bic             r4, r1, #3                      /* word address */
35         mov             r3, #0x40                       /* write command */
36         strh    r3, [r4, #0]
37         ldrh    r3, [r0], #2            /* read data */
38         strh    r3, [r1], #2            /* write data */
39         mov             r3, #0x70                       /* status command */
40         strh    r3, [r4, #0]
41 busy:
42         ldrb    r3, [r4, #0]            /* status */
43         tst     r3, #0x80
44         beq     busy
45         mov             r5, #0x50                       /* clear status command */
46         strh    r5, [r4, #0]
47         mov             r5, #0xFF                       /* read array */
48         strh    r5, [r4, #0]
49         tst             r3, #0x12
50         bne             exit
51         subs    r2, r2, #1                      /* decrement word count */
52         bne     write
53 exit:
54         bkpt    #0
55
56         .end