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
63 mov r0,dph ; restore r0 ; 2
64 mov dph,#0 ; restore dph ; 2
67 ; pointer to external stack or pdata
71 mov r0,dph ; restore r0 ; 2
72 mov dph,#0 ; restore dph ; 2
75 ; pointer to code area
78 ; implementation for SiLabs C8051F12x
91 ; pointer to xternal data
94 ; implementation for xram a16-a21 tied to P3
104 #elif defined DSDCC_MODEL_MEDIUM
107 _gptrget (char *gptr) _naked
109 /* This is the non-banked version with pointers up to 15 bits.
110 Assumes B is free to be used */
112 gptr; /* hush the compiler */
116 ; depending on the pointer type acc. to SDCCsymt.h
119 jb _B_7,codeptr$ ; >0x80 code ; 3
120 jnb _B_6,xdataptr$ ; <0x40 far ; 3
122 mov b,r0 ; save r0 independant of regbank ; 2
123 mov r0,dpl ; use only low order address ; 2
125 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
127 ; Pointer to data space
130 mov r0,b ; restore r0 ; 2
133 ; pointer to xternal stack or pdata
137 mov r0,b ; restore r0 ; 2
140 ; pointer to code area, max 15 bits
143 ; 0x8000 <= dptr <= 0xFFFF
144 ; no need to AND dph and restore from B if hardware wraps code memory
151 ; pointer to xternal data, max 14 bits
154 ; 0 <= dptr <= 0x3FFF
165 _gptrget (char *gptr) _naked
167 /* This is the new version with pointers up to 16 bits.
168 B cannot be trashed */
170 gptr; /* hush the compiler */
174 ; depending on the pointer type acc. to SDCCsymt.h
176 jb _B_7,codeptr$ ; >0x80 code ; 3
177 jnb _B_6,xdataptr$ ; <0x40 far ; 3
179 mov dph,r0 ; save r0 independant of regbank ; 2
180 mov r0,dpl ; use only low order address ; 2
182 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
184 ; 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 mov r0,dph ; restore r0 ; 2
196 mov dph,#0 ; restore dph ; 2
199 ; pointer to code area, max 16 bits
206 ; pointer to xternal data, max 16 bits
219 _gptrget (char *gptr) _naked
221 /* This is the old version with pointers up to 16 bits. */
223 gptr; /* hush the compiler */
227 ; depending on the pointer type acc. to SDCCsymt.h
230 jz 00001$ ; 0 near ; 2
232 jz 00002$ ; 1 far ; 2
234 jz 00003$ ; 2 code ; 2
236 jz 00004$ ; 3 pdata ; 2
237 dec a ; 4 skip generic pointer ; 1
239 jz 00001$ ; 5 idata ; 2
241 ; any other value for type
246 ; Pointer to data space
251 mov r0,dpl ; use only low order address ; 2
258 ; pointer to xternal data
264 ; pointer to code area
271 ; pointer to xternal stack or pdata
274 #if USE_PDATA_PAGING_REGISTER
275 mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access
291 /* the return value is expected to be in acc/_ap, and not in the standard
292 * location dpl/dph. Therefore we choose return type void here: */
297 _gptrgetWord (unsigned *gptr)
299 /* This is the new version */
300 gptr; /* hush the compiler */
304 ; depending on the pointer type acc. to SDCCsymt.h
306 jb _B_7,00003$ ; >0x80 code
307 jnb _B_6,00002$ ; <0x40 far
309 mov dph,r0 ; save r0 independant of regbank
310 mov r0,dpl ; use only low order address
312 jb _B_5,00004$ ; >0x60 pdata
314 ; Pointer to data space
322 ; pointer to xternal data
331 ; pointer to code area
342 ; pointer to xternal stack
354 mov r0,dph ; restore r0
355 mov dph,#0 ; restore dph
364 _gptrgetWord (unsigned *gptr)
366 gptr; /* hush the compiler */
370 ; depending on the pointer type acc. to SDCCsymt.h
380 dec a ; 4 skip generic pointer
384 ; any other value for type
389 ; Pointer to data space
393 mov r0,dpl ; use only low order address
400 ; pointer to xternal data
409 ; pointer to code area
420 ; pointer to xternal stack