contrib: add ram loader src code
[openocd.git] / 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21         .text
22         .arm
23         .section .init
24 /*
25         r0 source address (in)
26         r1 target address (in)
27         r2 word count (in)
28         r3 result (out)
29 */
30
31 write:
32         bic             r4, r1, #3                      /* word address */
33         mov             r3, #0x40                       /* write command */
34         strh    r3, [r4, #0]
35         ldrh    r3, [r0], #2            /* read data */
36         strh    r3, [r1], #2            /* write data */
37         mov             r3, #0x70                       /* status command */
38         strh    r3, [r4, #0]
39 busy:
40         ldrb    r3, [r4, #0]            /* status */
41         tst     r3, #0x80
42         beq     busy
43         mov             r5, #0x50                       /* clear status command */
44         strh    r5, [r4, #0]
45         mov             r5, #0xFF                       /* read array */
46         strh    r5, [r4, #0]
47         tst             r3, #0x12
48         bne             exit
49         subs    r2, r2, #1                      /* decremment word count */
50         bne     write
51 exit:
52         bkpt    #0
53   
54         .end