Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / _gptrgetc.c
1 /*-------------------------------------------------------------------------
2
3   _gptrget.c :- get value for a generic pointer (used with --xram-movc)
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
27 /* the  return value is expected to be in acc, and not in the standard
28  * location dpl. Therefore we choose return type void here: */
29
30 #if 1
31
32 void
33 _gptrgetc (char *gptr) __naked
34 {
35 /* This is the new version with pointers up to 16 bits.
36    B cannot be trashed */
37
38     gptr; /* hush the compiler */
39
40     __asm
41     ;   save values passed
42     ;
43     ;   depending on the pointer type acc. to SDCCsymt.h
44     ;
45         jb              _B_7,codeptr$        ; >0x80 code               ; 3
46         jnb             _B_6,xdataptr$       ; <0x40 far                ; 3
47
48         mov     dph,r0 ; save r0 independant of regbank ; 2
49         mov     r0,dpl ; use only low order address             ; 2
50
51         jb              _B_5,pdataptr$       ; >0x60 pdata              ; 3
52     ;
53     ;   Pointer to data space
54     ;
55         mov     a,@r0                                                                   ; 1
56         mov     r0,dph ; restore r0                                             ; 2
57         mov     dph,#0 ; restore dph                                    ; 2
58         ret                                                                                             ; 1
59     ;
60     ;   pointer to external stack or pdata
61     ;
62  pdataptr$:
63         movx    a,@r0                                                                   ; 1
64         mov     r0,dph ; restore r0                                             ; 2
65         mov     dph,#0 ; restore dph                                    ; 2
66         ret                                                                                             ; 1
67 ;
68 ;   pointer to xternal data
69 ;   pointer to code area
70 ;
71  codeptr$:
72  xdataptr$:
73         clr     a                                                                               ; 1
74         movc    a,@a+dptr                                                               ; 1
75         ret                                                                                             ; 1
76                                                                                                         ;===
77                                                                                                         ;28 bytes
78      __endasm;
79 }
80
81 #else
82
83 void
84 _gptrgetc (char *gptr) __naked
85 {
86     gptr; /* hush the compiler */
87
88     __asm
89     ;   save values passed
90         xch    a,r0
91         push   acc
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      00003$  ; 1 far
99         dec     a
100         jz      00003$  ; 2 code
101         dec     a
102         jz      00004$  ; 3 pdata
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         ret
111     ;
112     ;   Pointer to data space
113     ;
114  00001$:
115         mov     r0,dpl     ; use only low order address
116         mov     a,@r0
117         ret
118 ;
119 ;   pointer to xternal data
120 ;   pointer to code area
121 ;
122  00003$:
123         ; clr     a  is already 0
124         movc    a,@a+dptr
125         ret
126 ;
127 ;   pointer to xternal stack
128 ;
129  00004$:
130         mov     r0,dpl
131         movx    a,@r0
132 ;
133 ;   restore and return
134 ;
135         mov     r0,a
136         pop     acc
137         xch     a,r0
138         ret
139      __endasm;
140
141 }
142 #endif