* .version: bumped version to 2.4.7
[fw/sdcc] / device / lib / _gptrget.c
1 /*-------------------------------------------------------------------------
2
3   _gptrget.c :- get value for a generic pointer
4
5              Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)
6
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
10    later version.
11
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.
16
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.
20
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 -------------------------------------------------------------------------*/
25
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
32
33 /* the  return value is expected to be in acc, and not in the standard
34  * location dpl. Therefore we choose return type void here: */
35 void
36 _gptrget (char *gptr) _naked
37 {
38     gptr; /* hush the compiler */
39
40     _asm
41         ar0 = 0x00
42     ;   save values passed
43     ;
44     ;   depending on the pointer type acc. to SDCCsymt.h
45     ;
46         mov     a,b
47         jz      00001$  ; 0 near
48         dec     a
49         jz      00002$  ; 1 far
50         dec     a
51         jz      00003$  ; 2 code
52         dec     a
53         jz      00004$  ; 3 pdata
54         dec     a       ; 4 skip generic pointer
55         dec     a
56         jz      00001$  ; 5 idata
57     ;
58     ;   any other value for type
59     ;   return xFF
60         mov     a,#0xff
61         sjmp    00005$
62     ;
63     ;   Pointer to data space
64     ;
65  00001$:
66         push    ar0
67         ;
68         mov     r0,dpl     ; use only low order address
69         mov     a,@r0
70         ;
71         pop     ar0
72         ;
73         sjmp    00005$
74     ;
75     ;   pointer to xternal data
76     ;
77  00002$:
78         movx    a,@dptr
79         sjmp    00005$
80 ;
81 ;   pointer to code area
82 ;
83  00003$:
84         ; clr     a  is already 0
85         movc    a,@a+dptr
86         sjmp    00005$
87 ;
88 ;   pointer to xternal stack or pdata
89 ;
90  00004$:
91 #if USE_PDATA_PAGING_REGISTER
92         mov     dph,__XPAGE     ; __XPAGE (usually p2) holds high byte for pdata access
93         movx    a,@dptr
94 #else
95         push    ar0
96         mov     r0,dpl
97         movx    a,@r0
98         pop     ar0
99 #endif
100
101 ;
102 ;   return
103 ;
104  00005$:
105         ret
106      _endasm ;
107 }
108
109 #ifdef SDCC_ds390
110 /* the  return value is expected to be in acc/_ap, and not in the standard
111  * location dpl/dph. Therefore we choose return type void here: */
112 void
113 _gptrgetWord (unsigned *gptr)
114 {
115     gptr; /* hush the compiler */
116
117     _asm
118     ;
119     ;   depending on the pointer type acc. to SDCCsymt.h
120     ;
121         mov     a,b
122         jz      00001$  ; 0 near
123         dec     a
124         jz      00002$  ; 1 far
125         dec     a
126         jz      00003$  ; 2 code
127         dec     a
128         jz      00004$  ; 3 pdata
129         dec     a       ; 4 skip generic pointer
130         dec     a
131         jz      00001$  ; 5 idata
132     ;
133     ;   any other value for type
134     ;   return xFF
135         mov     a,#0xff
136         sjmp    00006$
137     ;
138     ;   Pointer to data space
139     ;
140  00001$:
141         push    ar0
142         mov     r0,dpl     ; use only low order address
143         mov     _ap,@r0
144         inc     r0
145         mov     a,@r0
146         inc     dpl
147         sjmp    00005$
148     ;
149     ;   pointer to xternal data
150     ;
151  00002$:
152         movx    a,@dptr
153         mov     _ap,a
154         inc     dptr
155         movx    a,@dptr
156         sjmp    00006$
157 ;
158 ;   pointer to code area
159 ;
160  00003$:
161         ; clr     a  is already 0
162         movc    a,@a+dptr
163         mov     _ap,a
164         clr     a
165         inc     dptr
166         movc    a,@a+dptr
167         sjmp    00006$
168 ;
169 ;   pointer to xternal stack
170 ;
171  00004$:
172         push    ar0
173         mov     r0,dpl
174         movx    a,@r0
175         mov     _ap,a
176         inc     r0
177         movx    a,@r0
178         inc     dpl
179 ;
180 ;   restore and return
181 ;
182 00005$:
183     pop ar0
184 00006$:
185      _endasm ;
186
187 }
188 #endif