contrib: replace the GPLv2-or-later license tag
[openocd.git] / contrib / loaders / erase_check / stm8_erase_check.s
blob116ac59f1094baaa5818d3dfddd64539a4026256
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * Copyright (C) 2017 Ake Rehnman
5 * ake.rehnman(at)gmail.com
6 */
7 ;;
8 ;; erase check memory code
9 ;;
10 .org 0x0
11 ;; start address
12 start_addr: .byte 0x00
13 .word 0x8000
14 ;; byte count
15 byte_cnt: .byte 0x00
16 .word 0x8000
18 ; SP must point to start_addr on entry
19 ; first relocate start_addr to the location
20 ; we are running at
21 start:
22 ldw X,SP
23 ldw .cont+2,X
24 ldw X,(start_addr+1,SP) ;start addr
25 ldw Y,(byte_cnt+1,SP) ;count
26 ld A,#0xff
28 ; if count == 0 return
29 .L1:
30 tnzw Y
31 jrne .decrcnt ;continue if low word != 0
32 tnz (byte_cnt,SP) ;high byte
33 jreq .exit ;goto exit
35 ; decrement count (byte_cnt)
36 .decrcnt:
37 tnzw Y ;low word count
38 jrne .decr1
39 dec (byte_cnt,SP) ;high byte
40 .decr1:
41 decw Y; decr low word
43 ; first check if [start_addr] is 0xff
44 .cont:
45 ldf A, [start_addr.e]
46 cp A,#0xff
47 jrne .exit ;exit if not 0xff
49 ; increment start_addr (addr)
50 incw X
51 jrne .L1
52 inc (start_addr,SP) ;increment high byte
53 jra .L1
55 .exit:
56 ldw (start_addr+1,SP),X ;start addr
57 ldw (byte_cnt+1,SP),Y ;count
58 break