1 /*-------------------------------------------------------------------------
3 _gptrput.c :- put value for a generic pointer
5 Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
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
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.
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.
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 -------------------------------------------------------------------------*/
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
33 __sbit __at (0xF7) B_7;
34 __sbit __at (0xF6) B_6;
35 __sbit __at (0xF5) B_5;
37 #if defined DSDCC_MODEL_HUGE
39 _gptrput (char *gptr, char c) _naked
41 /* This is the banked version with pointers up to 22 bits.
42 B cannot be trashed */
44 gptr; c; /* hush the compiler */
48 ; depending on the pointer type according to SDCCsymt.h
50 jb _B_7,codeptr$ ; >0x80 code ; 3
51 jnb _B_6,xdataptr$ ; <0x40 far ; 3
53 mov dph,r0 ; save r0 independant of regbank ; 2
54 mov r0,dpl ; use only low order address ; 2
56 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
58 ; store into near/idata space
61 mov r0,dph ; restore r0 ; 2
62 mov dph,#0 ; restore dph ; 2
67 ; store into external stack/pdata space
71 mov r0,dph ; restore r0 ; 2
72 mov dph,#0 ; restore dph ; 2
75 ; store into far space
88 #elif defined DSDCC_MODEL_MEDIUM
91 _gptrput (char *gptr, char c) _naked
93 /* This is the non-banked version with pointers up to 14 bits.
94 Assumes B is free to be used */
96 gptr; c; /* hush the compiler */
100 ; depending on the pointer type according to SDCCsymt.h
103 jb _B_7,codeptr$ ; >0x80 code ; 3
104 jnb _B_6,xdataptr$ ; <0x40 far ; 3
106 mov b,r0 ; save r0 independant of regbank ; 2
107 mov r0,dpl ; use only low order address ; 2
109 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
111 ; store into near/idata space
114 mov r0,b ; restore r0 ; 2
119 ; store into external stack/pdata space
123 mov r0,b ; restore r0 ; 2
126 ; store into far space, max 14 bits
129 ; 0 <= dptr <= 0x3FFF
140 _gptrput (char *gptr, char c) _naked
142 /* This is the new version with pointers up to 16 bits.
143 B cannot be trashed */
145 gptr; c; /* hush the compiler */
149 ; depending on the pointer type according to SDCCsymt.h
151 jb _B_7,codeptr$ ; >0x80 code ; 3
152 jnb _B_6,xdataptr$ ; <0x40 far ; 3
154 mov dph,r0 ; save r0 independant of regbank ; 2
155 mov r0,dpl ; use only low order address ; 2
157 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
159 ; store into near/idata space
162 mov r0,dph ; restore r0 ; 2
163 mov dph,#0 ; restore dph ; 2
168 ; store into external stack/pdata space
172 mov r0,dph ; restore r0 ; 2
173 mov dph,#0 ; restore dph ; 2
176 ; store into far space
190 _gptrput (char *gptr, char c) _naked
192 /* This is the old version with pointers up to 16 bits. */
194 gptr; c; /* hush the compiler */
200 ; depending on the pointer type acc. to SDCCsymt.h
203 jz 00001$ ; 0 near ; 2
205 jz 00002$ ; 1 far ; 2
207 jz 00003$ ; 2 code ; 2
209 jz 00004$ ; 3 pdata ; 2
210 dec a ; 4 skip generic pointer ; 1
212 jz 00001$ ; 5 idata ; 2
215 pop acc ; do nothing ; 2
218 ; store into near space
234 #if USE_PDATA_PAGING_REGISTER
236 mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access
261 ; depending on the pointer type acc. to SDCCsymt.h
263 jb _B_7,00013$ ; >0x80 code
264 jnb _B_6,00012$ ; <0x40 far
266 mov dph,r0 ; save r0 independant of regbank
267 mov r0,dpl ; use only low order address
269 jb _B_5,00014$ ; >0x60 pdata
271 ; store into near space
278 ; store into far space
288 ; store into code space
291 inc dptr ; do nothing
294 ; store into xstack space
304 mov r0,dph ; restore r0
305 mov dph,#0 ; restore dph
318 ; depending on the pointer type acc. to SDCCsymt.h
328 dec a ; 4 skip generic pointer
334 ; store into near space