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
74 ; store into far space
87 #elif defined DSDCC_MODEL_MEDIUM
90 _gptrput (char *gptr, char c) __naked
92 /* This is the non-banked version with pointers up to 14 bits.
93 Assumes B is free to be used */
95 gptr; c; /* hush the compiler */
99 ; depending on the pointer type according to SDCCsymt.h
102 jb _B_7,codeptr$ ; >0x80 code ; 3
103 jnb _B_6,xdataptr$ ; <0x40 far ; 3
105 mov b,r0 ; save r0 independant of regbank ; 2
106 mov r0,dpl ; use only low order address ; 2
108 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
110 ; store into near/idata space
114 mov r0,b ; restore r0 ; 2
119 ; store into external stack/pdata space
123 sjmp dataptrrestore$ ; 2
125 ; store into far space, max 14 bits
128 ; 0 <= dptr <= 0x3FFF
139 _gptrput (char *gptr, char c) __naked
141 /* This is the new version with pointers up to 16 bits.
142 B cannot be trashed */
144 gptr; c; /* hush the compiler */
148 ; depending on the pointer type according to SDCCsymt.h
150 jb _B_7,codeptr$ ; >0x80 code ; 3
151 jnb _B_6,xdataptr$ ; <0x40 far ; 3
153 mov dph,r0 ; save r0 independant of regbank ; 2
154 mov r0,dpl ; use only low order address ; 2
156 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
158 ; 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 sjmp dataptrrestore$ ; 2
174 ; store into far space
194 ; depending on the pointer type acc. to SDCCsymt.h
196 jb _B_7,00013$ ; >0x80 code
197 jnb _B_6,00012$ ; <0x40 far
199 mov dph,r0 ; save r0 independant of regbank
200 mov r0,dpl ; use only low order address
202 jb _B_5,00014$ ; >0x60 pdata
204 ; store into near space
211 ; store into far space
221 ; store into code space
224 inc dptr ; do nothing
227 ; store into xstack space
237 mov r0,dph ; restore r0
238 mov dph,#0 ; restore dph