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 _gptrget (char *gptr) _naked
219 /* This is the old version with pointers up to 16 bits. */
221 gptr; /* hush the compiler */
225 ; depending on the pointer type acc. to SDCCsymt.h
228 jz 00001$ ; 0 near ; 2
230 jz 00002$ ; 1 far ; 2
232 jz 00003$ ; 2 code ; 2
234 jz 00004$ ; 3 pdata ; 2
235 dec a ; 4 skip generic pointer ; 1
237 jz 00001$ ; 5 idata ; 2
239 ; any other value for type
244 ; Pointer to data space
249 mov r0,dpl ; use only low order address ; 2
256 ; pointer to xternal data
262 ; pointer to code area
269 ; pointer to xternal stack or pdata
272 #if USE_PDATA_PAGING_REGISTER
273 mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access
289 /* the return value is expected to be in acc/_ap, and not in the standard
290 * location dpl/dph. Therefore we choose return type void here: */
295 _gptrgetWord (unsigned *gptr)
297 /* This is the new version */
298 gptr; /* hush the compiler */
302 ; depending on the pointer type acc. to SDCCsymt.h
304 jb _B_7,00003$ ; >0x80 code
305 jnb _B_6,00002$ ; <0x40 far
307 mov dph,r0 ; save r0 independant of regbank
308 mov r0,dpl ; use only low order address
310 jb _B_5,00004$ ; >0x60 pdata
312 ; Pointer to data space
320 ; pointer to xternal data
329 ; pointer to code area
340 ; pointer to xternal stack
352 mov r0,dph ; restore r0
353 mov dph,#0 ; restore dph
362 _gptrgetWord (unsigned *gptr)
364 gptr; /* hush the compiler */
368 ; depending on the pointer type acc. to SDCCsymt.h
378 dec a ; 4 skip generic pointer
382 ; any other value for type
387 ; Pointer to data space
391 mov r0,dpl ; use only low order address
398 ; pointer to xternal data
407 ; pointer to code area
418 ; pointer to xternal stack