1 /*-------------------------------------------------------------------------
3 _gptrget.c :- get 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 /* the return value is expected to be in acc, and not in the standard
38 * location dpl. Therefore we choose return type void here: */
39 #if defined DSDCC_MODEL_HUGE
41 _gptrget (char *gptr) __naked
43 /* This is the banked version with pointers up to 23 bits.
44 B cannot be trashed */
46 gptr; /* hush the compiler */
50 ; depending on the pointer type acc. to SDCCsymt.h
52 jb _B_7,codeptr$ ; >0x80 code ; 3
53 jnb _B_6,xdataptr$ ; <0x40 far ; 3
55 mov dph,r0 ; save r0 independant of regbank ; 2
56 mov r0,dpl ; use only low order address ; 2
58 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
60 ; Pointer to data space
64 mov r0,dph ; restore r0 ; 2
65 mov dph,#0 ; restore dph ; 2
68 ; pointer to external stack or pdata
72 sjmp dataptrrestore$ ; 2
74 ; pointer to code area
77 ; implementation for SiLabs C8051F12x
90 ; pointer to xternal data
93 ; implementation for xram a16-a21 tied to P3
103 #elif defined DSDCC_MODEL_MEDIUM
106 _gptrget (char *gptr) __naked
108 /* This is the non-banked version with pointers up to 15 bits.
109 Assumes B is free to be used */
111 gptr; /* hush the compiler */
115 ; depending on the pointer type acc. to SDCCsymt.h
118 jb _B_7,codeptr$ ; >0x80 code ; 3
119 jnb _B_6,xdataptr$ ; <0x40 far ; 3
121 mov b,r0 ; save r0 independant of regbank ; 2
122 mov r0,dpl ; use only low order address ; 2
124 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
126 ; Pointer to data space
129 mov r0,b ; restore r0 ; 2
132 ; pointer to xternal stack or pdata
136 mov r0,b ; restore r0 ; 2
139 ; pointer to code area, max 15 bits
142 ; 0x8000 <= dptr <= 0xFFFF
143 ; no need to AND dph and restore from B if hardware wraps code memory
150 ; pointer to xternal data, max 14 bits
153 ; 0 <= dptr <= 0x3FFF
164 _gptrget (char *gptr) __naked
166 /* This is the new version with pointers up to 16 bits.
167 B cannot be trashed */
169 gptr; /* hush the compiler */
173 ; depending on the pointer type acc. to SDCCsymt.h
175 jb _B_7,codeptr$ ; >0x80 code ; 3
176 jnb _B_6,xdataptr$ ; <0x40 far ; 3
178 mov dph,r0 ; save r0 independant of regbank ; 2
179 mov r0,dpl ; use only low order address ; 2
181 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
183 ; Pointer to data space
187 mov r0,dph ; restore r0 ; 2
188 mov dph,#0 ; restore dph ; 2
191 ; pointer to xternal stack or pdata
195 sjmp dataptrrestore$ ; 2
197 ; pointer to code area, max 16 bits
204 ; pointer to xternal data, max 16 bits
217 /* the return value is expected to be in acc/_ap, and not in the standard
218 * location dpl/dph. Therefore we choose return type void here: */
221 _gptrgetWord (unsigned *gptr)
223 gptr; /* hush the compiler */
227 ; depending on the pointer type acc. to SDCCsymt.h
229 jb _B_7,00003$ ; >0x80 code
230 jnb _B_6,00002$ ; <0x40 far
232 mov dph,r0 ; save r0 independant of regbank
233 mov r0,dpl ; use only low order address
235 jb _B_5,00004$ ; >0x60 pdata
237 ; Pointer to data space
245 ; pointer to xternal data
254 ; pointer to code area
265 ; pointer to xternal stack
277 mov r0,dph ; restore r0
278 mov dph,#0 ; restore dph