Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / mcs51 / crtxinit.asm
1 ; /*-------------------------------------------------------------------------
2 ;
3 ;   crtxinit.asm :- C run-time: copy XINIT to XISEG
4 ;
5 ;    This library is free software; you can redistribute it and/or modify it
6 ;    under the terms of the GNU Library General Public License as published by the
7 ;    Free Software Foundation; either version 2, or (at your option) any
8 ;    later version.
9 ;
10 ;    This library 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 Library General Public License for more details.
14 ;
15 ;    You should have received a copy of the GNU Library General Public License
16 ;    along with this program; if not, write to the Free Software
17 ;    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 ;
19 ;    In other words, you are welcome to use, share and improve this program.
20 ;    You are forbidden to forbid anyone else to use, share and improve
21 ;    what you give them.   Help stamp out software-hoarding!
22 ; -------------------------------------------------------------------------*/
23
24 ; Set DUAL_DPTR to 1 and reassemble if your derivative has dual data pointers
25 ; Especially useful if movx @Ri cannot go beyond the first 256 bytes of xdata
26 ; due to lack of P2 or _XPAGE
27 ; If the derivative has auto-toggle or auto-increment it can be further optimized
28         DUAL_DPTR = 0
29
30         .area CSEG    (CODE)
31         .area GSINIT0 (CODE)
32         .area GSINIT1 (CODE)
33         .area GSINIT2 (CODE)
34         .area GSINIT3 (CODE)
35         .area GSINIT4 (CODE)
36         .area GSINIT5 (CODE)
37         .area GSINIT  (CODE)
38         .area GSFINAL (CODE)
39
40         .area GSINIT3 (CODE)
41
42         .if DUAL_DPTR
43
44         .globl _DPS                     ; assume DPSEL is in DPS bit0
45
46 __mcs51_genXINIT::
47         mov     r1,#l_XINIT
48         mov     a,r1
49         orl     a,#(l_XINIT >> 8)
50         jz      00003$
51         mov     r2,#((l_XINIT+255) >> 8)
52         orl     _DPS,#0x01              ; set DPSEL, select DPTR1
53         mov     dptr,#s_XINIT           ; DPTR1 for code
54         dec     _DPS                    ; clear DPSEL, select DPTR0
55         mov     dptr,#s_XISEG           ; DPTR0 for xdata
56 00001$: clr     a
57         inc     _DPS                    ; set DPSEL, select DPTR1
58         movc    a,@a+dptr
59         inc     dptr
60         dec     _DPS                    ; clear DPSEL, select DPTR0
61         movx    @dptr,a
62         inc     dptr
63         djnz    r1,00001$
64         djnz    r2,00001$
65 00003$:
66
67         .else
68
69         .globl __XPAGE
70
71 __mcs51_genXINIT::
72         mov     r1,#l_XINIT
73         mov     a,r1
74         orl     a,#(l_XINIT >> 8)
75         jz      00003$
76         mov     r2,#((l_XINIT+255) >> 8)
77         mov     dptr,#s_XINIT
78         mov     r0,#s_XISEG
79         mov     __XPAGE,#(s_XISEG >> 8)
80 00001$: clr     a
81         movc    a,@a+dptr
82         movx    @r0,a
83         inc     dptr
84         inc     r0
85         cjne    r0,#0,00002$
86         inc     __XPAGE
87 00002$: djnz    r1,00001$
88         djnz    r2,00001$
89         mov     __XPAGE,#0xFF
90 00003$:
91
92         .endif