_naked allows to use ret instead of sjmp to ret
[fw/sdcc] / device / lib / _gptrput.c
1 /*-------------------------------------------------------------------------
2
3   _gptrput.c :- put 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 void
34 _gptrput (char *gptr, char c) _naked
35 {
36     gptr; c; /* hush the compiler */
37
38     _asm
39         ar0 = 0x00
40         push     acc
41     ;
42     ;   depending on the pointer type acc. to SDCCsymt.h
43     ;
44         mov     a,b
45         jz      00001$  ; 0 near
46         dec     a
47         jz      00002$  ; 1 far
48         dec     a
49         jz      00003$  ; 2 code
50         dec     a
51         jz      00004$  ; 3 pdata
52         dec     a       ; 4 skip generic pointer
53         dec     a
54         jz      00001$  ; 5 idata
55
56  00003$:
57         pop     acc    ; do nothing
58         ret
59 ;
60 ;       store into near space
61 ;
62  00001$:
63         pop     acc
64         push    ar0
65         mov     r0,dpl
66         mov     @r0,a
67         pop     ar0
68         ret
69
70  00002$:
71         pop     acc
72         movx    @dptr,a
73         ret
74
75  00004$:
76 #if USE_PDATA_PAGING_REGISTER
77         pop     acc
78         mov     dph,__XPAGE     ; __XPAGE (usually p2) holds high byte for pdata access
79         movx    @dptr,a
80 #else
81         pop     acc
82         push    ar0
83         mov     r0,dpl
84         movx    @r0,a
85         pop     ar0
86 #endif
87         ret
88 _endasm;
89 }
90
91 #ifdef SDCC_ds390
92 void
93 _gptrputWord ()
94 {
95     _asm
96         push     acc
97     ;
98     ;   depending on the pointer type acc. to SDCCsymt.h
99     ;
100         mov     a,b
101         jz      00011$  ; 0 near
102         dec     a
103         jz      00012$  ; 1 far
104         dec     a
105         jz      00013$  ; 2 code
106         dec     a
107         jz      00014$  ; 3 pdata
108         dec     a       ; 4 skip generic pointer
109         dec     a
110         jz      00011$  ; 5 idata
111         pop     acc
112         sjmp    00016$
113 ;
114 ;       store into near space
115 ;
116  00011$:
117         pop     acc
118         push    ar0
119         mov     r0,dpl
120         mov     @r0,_ap
121         inc     r0
122         mov     @r0,a
123         sjmp    00015$
124
125  00012$:
126         mov     a, _ap
127         movx    @dptr,a
128         inc     dptr
129         pop     acc
130         movx    @dptr,a
131         sjmp    00016$
132
133  00013$:
134         pop     acc    ; do nothing
135         sjmp    00016$
136
137  00014$:
138         pop     acc
139         push    ar0
140         mov     r0,dpl
141         xch     a,_ap
142         movx    @r0,a
143         inc     r0
144         xch     a,_ap
145         movx    @r0, a
146  00015$:
147         inc     dptr
148         pop     ar0
149  00016$:
150     _endasm;
151 }
152
153 #endif