Minor ds390 performance enhancement on generic pointer reads
[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 unsigned char _gptrget ()
27 {
28     _asm
29     ;   save values passed
30         xch    a,r0
31         push   acc
32     ;
33     ;   depending on the pointer type acc. to SDCCsymt.h
34     ;
35         mov     a,b
36         jz      00001$  ; 0 near
37         dec     a
38         jz      00002$  ; 1 far
39         dec     a
40         jz      00003$  ; 2 code
41         dec     a
42         jz      00004$
43         dec     a       ; 4 skip generic pointer
44         dec     a
45         jz      00001$  ; 5 idata
46     ;
47     ;   any other value for type
48     ;   return xFF
49         mov     a,#0xff
50         sjmp    00005$
51     ;
52     ;   Pointer to data space
53     ;
54  00001$:
55         mov     r0,dpl     ; use only low order address
56         mov     a,@r0
57         sjmp    00005$
58     ;
59     ;   pointer to xternal data
60     ;
61  00002$:
62         movx    a,@dptr
63         sjmp    00005$
64 ;
65 ;   pointer to code area
66 ;
67  00003$:
68         ; clr     a  is already 0
69         movc    a,@a+dptr
70         sjmp    00005$
71 ;
72 ;   pointer to xternal stack
73 ;
74  00004$:
75         mov     r0,dpl
76         movx    a,@r0
77 ;
78 ;   restore and return
79 ;
80  00005$:
81         mov     r0,a
82         pop     acc
83         xch     a,r0
84      _endasm ;
85
86 }
87
88 #ifdef SDCC_ds390
89 unsigned int _gptrgetWord ()
90 {
91     _asm
92     ;
93     ;   depending on the pointer type acc. to SDCCsymt.h
94     ;
95         mov     a,b
96         jz      00001$  ; 0 near
97         dec     a
98         jz      00002$  ; 1 far
99         dec     a
100         jz      00003$  ; 2 code
101         dec     a
102         jz      00004$
103         dec     a       ; 4 skip generic pointer
104         dec     a
105         jz      00001$  ; 5 idata
106     ;
107     ;   any other value for type
108     ;   return xFF
109         mov     a,#0xff
110         sjmp    00006$
111     ;
112     ;   Pointer to data space
113     ;
114  00001$:
115         push    ar0
116         mov     r0,dpl     ; use only low order address
117         mov     _ap,@r0
118         inc     r0
119         mov     a,@r0
120         inc     dpl
121         sjmp    00005$
122     ;
123     ;   pointer to xternal data
124     ;
125  00002$:
126         movx    a,@dptr
127         mov     _ap,a
128         inc     dptr
129         movx    a,@dptr
130         sjmp    00006$
131 ;
132 ;   pointer to code area
133 ;
134  00003$:
135         ; clr     a  is already 0
136         movc    a,@a+dptr
137         mov     _ap,a
138         clr     a
139         inc     dptr
140         movc    a,@a+dptr
141         sjmp    00006$
142 ;
143 ;   pointer to xternal stack
144 ;
145  00004$:
146         push    ar0
147         mov     r0,dpl
148         movx    a,@r0
149         mov     _ap,a
150         inc     r0
151         movx    a,@r0
152         inc     dpl
153 ;
154 ;   restore and return
155 ;
156 00005$:
157     pop ar0
158 00006$: 
159      _endasm ;
160
161 }
162 #endif