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