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
62 mov r0,dph ; restore r0 ; 2
63 mov dph,#0 ; restore dph ; 2
68 ; store into external stack/pdata space
72 sjmp dataptrrestore$ ; 2
73 mov r0,dph ; restore r0 ; 2
74 mov dph,#0 ; restore dph ; 2
77 ; store into far space
90 #elif defined DSDCC_MODEL_MEDIUM
93 _gptrput (char *gptr, char c) _naked
95 /* This is the non-banked version with pointers up to 14 bits.
96 Assumes B is free to be used */
98 gptr; c; /* hush the compiler */
102 ; depending on the pointer type according to SDCCsymt.h
105 jb _B_7,codeptr$ ; >0x80 code ; 3
106 jnb _B_6,xdataptr$ ; <0x40 far ; 3
108 mov b,r0 ; save r0 independant of regbank ; 2
109 mov r0,dpl ; use only low order address ; 2
111 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
113 ; store into near/idata space
117 mov r0,b ; restore r0 ; 2
122 ; store into external stack/pdata space
126 sjmp dataptrrestore$ ; 2
128 ; store into far space, max 14 bits
131 ; 0 <= dptr <= 0x3FFF
142 _gptrput (char *gptr, char c) _naked
144 /* This is the new version with pointers up to 16 bits.
145 B cannot be trashed */
147 gptr; c; /* hush the compiler */
151 ; depending on the pointer type according to SDCCsymt.h
153 jb _B_7,codeptr$ ; >0x80 code ; 3
154 jnb _B_6,xdataptr$ ; <0x40 far ; 3
156 mov dph,r0 ; save r0 independant of regbank ; 2
157 mov r0,dpl ; use only low order address ; 2
159 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
161 ; store into near/idata space
165 mov r0,dph ; restore r0 ; 2
166 mov dph,#0 ; restore dph ; 2
171 ; store into external stack/pdata space
175 sjmp dataptrrestore$ ; 2
177 ; store into far space
191 _gptrput (char *gptr, char c) _naked
193 /* This is the old version with pointers up to 16 bits. */
195 gptr; c; /* hush the compiler */
201 ; depending on the pointer type acc. to SDCCsymt.h
204 jz 00001$ ; 0 near ; 2
206 jz 00002$ ; 1 far ; 2
208 jz 00003$ ; 2 code ; 2
210 jz 00004$ ; 3 pdata ; 2
211 dec a ; 4 skip generic pointer ; 1
213 jz 00001$ ; 5 idata ; 2
216 pop acc ; do nothing ; 2
219 ; store into near space
235 #if USE_PDATA_PAGING_REGISTER
237 mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access
262 ; depending on the pointer type acc. to SDCCsymt.h
264 jb _B_7,00013$ ; >0x80 code
265 jnb _B_6,00012$ ; <0x40 far
267 mov dph,r0 ; save r0 independant of regbank
268 mov r0,dpl ; use only low order address
270 jb _B_5,00014$ ; >0x60 pdata
272 ; store into near space
279 ; store into far space
289 ; store into code space
292 inc dptr ; do nothing
295 ; store into xstack space
305 mov r0,dph ; restore r0
306 mov dph,#0 ; restore dph
319 ; depending on the pointer type acc. to SDCCsymt.h
329 dec a ; 4 skip generic pointer
335 ; store into near space