Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / _gptrput.c
1 /*-------------------------------------------------------------------------
2
3   _gptrput.c :- put value for a generic pointer
4
5              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
6
7    This library is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Library General Public License as published by the
9    Free Software Foundation; either version 2, or (at your option) any
10    later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21    In other words, you are welcome to use, share and improve this program.
22    You are forbidden to forbid anyone else to use, share and improve
23    what you give them.   Help stamp out software-hoarding!
24 -------------------------------------------------------------------------*/
25
26 /* not all devices use P2 to page pdata memory, therefore __XPAGE was
27    introduced. On some targets __XPAGE itself is a paged SFR so it is
28    not safe for all platforms to set this. Furthermore some targets
29    can be configured to behave differently for movx @dptr vs. movx @Ri
30    (don't drive high byte of address bus for movx @Ri only) */
31 #define USE_PDATA_PAGING_REGISTER 0
32
33 __sbit __at (0xF7) B_7;
34 __sbit __at (0xF6) B_6;
35 __sbit __at (0xF5) B_5;
36
37 #if defined DSDCC_MODEL_HUGE
38 void
39 _gptrput (char *gptr, char c) __naked
40 {
41 /* This is the banked version with pointers up to 22 bits.
42    B cannot be trashed */
43
44     gptr; c; /* hush the compiler */
45
46     __asm
47     ;
48     ;   depending on the pointer type according to SDCCsymt.h
49     ;
50         jb      _B_7,codeptr$        ; >0x80 code       ; 3
51         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
52
53         mov     dph,r0 ; save r0 independant of regbank ; 2
54         mov     r0,dpl ; use only low order address     ; 2
55
56         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
57     ;
58     ;   store into near/idata space
59     ;
60         mov     @r0,a                                   ; 1
61  dataptrrestore$:
62         mov     r0,dph ; restore r0                     ; 2
63         mov     dph,#0 ; restore dph                    ; 2
64
65  codeptr$:
66         ret                                             ; 1
67     ;
68     ;   store into external stack/pdata space
69     ;
70  pdataptr$:
71         movx    @r0,a                                   ; 1
72         sjmp    dataptrrestore$                         ; 2
73     ;
74     ;   store into far space
75     ;
76  xdataptr$:
77         mov     _P3,b                                   ; 3
78
79         movx    @dptr,a                                 ; 1
80         ret                                             ; 1
81
82                                                         ;===
83                                                         ;27 bytes
84     __endasm;
85 }
86
87 #elif defined DSDCC_MODEL_MEDIUM
88
89 void
90 _gptrput (char *gptr, char c) __naked
91 {
92 /* This is the non-banked version with pointers up to 14 bits.
93    Assumes B is free to be used */
94
95     gptr; c; /* hush the compiler */
96
97     __asm
98     ;
99     ;   depending on the pointer type according to SDCCsymt.h
100     ;
101         mov     b,dph                                   ; 3
102         jb      _B_7,codeptr$        ; >0x80 code       ; 3
103         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
104
105         mov     b,r0   ; save r0 independant of regbank ; 2
106         mov     r0,dpl ; use only low order address     ; 2
107
108         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
109     ;
110     ;   store into near/idata space
111     ;
112         mov     @r0,a                                   ; 1
113  dataptrrestore$:
114         mov     r0,b   ; restore r0                     ; 2
115
116  codeptr$:
117         ret                                             ; 1
118     ;
119     ;   store into external stack/pdata space
120     ;
121  pdataptr$:
122         movx    @r0,a                                   ; 1
123         sjmp    dataptrrestore$                         ; 2
124     ;
125     ;   store into far space, max 14 bits
126     ;
127  xdataptr$:
128     ; 0 <= dptr <= 0x3FFF
129         movx    @dptr,a                                 ; 1
130         ret                                             ; 1
131                                                         ;===
132                                                         ;25 bytes
133     __endasm;
134 }
135
136 #else
137
138 void
139 _gptrput (char *gptr, char c) __naked
140 {
141 /* This is the new version with pointers up to 16 bits.
142    B cannot be trashed */
143
144     gptr; c; /* hush the compiler */
145
146     __asm
147     ;
148     ;   depending on the pointer type according to SDCCsymt.h
149     ;
150         jb      _B_7,codeptr$        ; >0x80 code       ; 3
151         jnb     _B_6,xdataptr$       ; <0x40 far        ; 3
152
153         mov     dph,r0 ; save r0 independant of regbank ; 2
154         mov     r0,dpl ; use only low order address     ; 2
155
156         jb      _B_5,pdataptr$       ; >0x60 pdata      ; 3
157     ;
158     ;   store into near/idata space
159     ;
160         mov     @r0,a                                   ; 1
161  dataptrrestore$:
162         mov     r0,dph ; restore r0                     ; 2
163         mov     dph,#0 ; restore dph                    ; 2
164
165  codeptr$:
166         ret                                             ; 1
167     ;
168     ;   store into external stack/pdata space
169     ;
170  pdataptr$:
171         movx    @r0,a                                   ; 1
172         sjmp    dataptrrestore$                         ; 2
173     ;
174     ;   store into far space
175     ;
176  xdataptr$:
177         movx    @dptr,a                                 ; 1
178         ret                                             ; 1
179
180                                                         ;===
181                                                         ;24 bytes
182     __endasm;
183 }
184
185 #endif
186
187 #ifdef SDCC_ds390
188
189 void
190 _gptrputWord ()
191 {
192     __asm
193     ;
194     ;   depending on the pointer type acc. to SDCCsymt.h
195     ;
196         jb      _B_7,00013$           ; >0x80 code
197         jnb     _B_6,00012$           ; <0x40 far
198
199         mov     dph,r0 ; save r0 independant of regbank
200         mov     r0,dpl ; use only low order address
201
202         jb      _B_5,00014$           ; >0x60 pdata
203 ;
204 ;       store into near space
205 ;
206         mov     @r0,_ap
207         inc     r0
208         mov     @r0,a
209         sjmp    00015$
210 ;
211 ;       store into far space
212 ;
213  00012$:
214         xch     a,_ap
215         movx    @dptr,a
216         inc     dptr
217         xch     a,_ap
218         movx    @dptr,a
219         sjmp    00016$
220 ;
221 ;       store into code space
222 ;
223  00013$:
224         inc     dptr   ; do nothing
225         sjmp    00016$
226 ;
227 ;       store into xstack space
228 ;
229  00014$:
230         xch     a,_ap
231         movx    @r0,a
232         inc     r0
233         xch     a,_ap
234         movx    @r0, a
235  00015$:
236         mov     dpl,r0
237         mov     r0,dph ; restore r0
238         mov     dph,#0 ; restore dph
239  00016$:
240     __endasm;
241 }
242
243 #endif