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