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
89 ; pointer to xternal data
92 ; implementation for xram a16-a21 tied to P3
102 #elif defined DSDCC_MODEL_MEDIUM
105 _gptrget (char *gptr) _naked
107 /* This is the non-banked version with pointers up to 15 bits.
108 Assumes B is free to be used */
110 gptr; /* hush the compiler */
114 ; depending on the pointer type acc. to SDCCsymt.h
117 jb _B_7,codeptr$ ; >0x80 code ; 3
118 jnb _B_6,xdataptr$ ; <0x40 far ; 3
120 mov b,r0 ; save r0 independant of regbank ; 2
121 mov r0,dpl ; use only low order address ; 2
123 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
125 ; Pointer to data space
128 mov r0,b ; restore r0 ; 2
131 ; pointer to xternal stack or pdata
135 mov r0,b ; restore r0 ; 2
138 ; pointer to code area, max 15 bits
141 ; 0x8000 <= dptr <= 0xFFFF
142 ; no need to AND dph and restore from B if hardware wraps code memory
149 ; pointer to xternal data, max 14 bits
152 ; 0 <= dptr <= 0x3FFF
163 _gptrget (char *gptr) _naked
165 /* This is the new version with pointers up to 16 bits.
166 B cannot be trashed */
168 gptr; /* hush the compiler */
172 ; depending on the pointer type acc. to SDCCsymt.h
174 jb _B_7,codeptr$ ; >0x80 code ; 3
175 jnb _B_6,xdataptr$ ; <0x40 far ; 3
177 mov dph,r0 ; save r0 independant of regbank ; 2
178 mov r0,dpl ; use only low order address ; 2
180 jb _B_5,pdataptr$ ; >0x60 pdata ; 3
182 ; Pointer to data space
185 mov r0,dph ; restore r0 ; 2
186 mov dph,#0 ; restore dph ; 2
189 ; pointer to xternal stack or pdata
193 mov r0,dph ; restore r0 ; 2
194 mov dph,#0 ; restore dph ; 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