1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
/*-------------------------------------------------------------------------
_gptrget.c - get value for a generic pointer
Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
As a special exception, if you link this library with other files,
some of which are compiled with SDCC, to produce an executable,
this library does not by itself cause the resulting executable to
be covered by the GNU General Public License. This exception does
not however invalidate any other reasons why the executable file
might be covered by the GNU General Public License.
-------------------------------------------------------------------------*/
/* not all devices use P2 to page pdata memory, therefore __XPAGE was
introduced. On some targets __XPAGE itself is a paged SFR so it is
not safe for all platforms to set this. Furthermore some targets
can be configured to behave differently for movx @dptr vs. movx @Ri
(don't drive high byte of address bus for movx @Ri only) */
#define USE_PDATA_PAGING_REGISTER 0
__sbit __at (0xF7) B_7;
__sbit __at (0xF6) B_6;
__sbit __at (0xF5) B_5;
/* the return value is expected to be in acc, and not in the standard
* location dpl. Therefore we choose return type void here: */
#if defined DSDCC_MODEL_HUGE
void
_gptrget (char *gptr) __naked
{
/* This is the banked version with pointers up to 23 bits.
B cannot be trashed */
gptr; /* hush the compiler */
__asm
;
; depending on the pointer type acc. to SDCCsymt.h
;
jb _B_7,codeptr$ ; >0x80 code ; 3
jnb _B_6,xdataptr$ ; <0x40 far ; 3
mov dph,r0 ; save r0 independant of regbank ; 2
mov r0,dpl ; use only low order address ; 2
jb _B_5,pdataptr$ ; >0x60 pdata ; 3
;
; Pointer to data space
;
mov a,@r0 ; 1
dataptrrestore$:
mov r0,dph ; restore r0 ; 2
mov dph,#0 ; restore dph ; 2
ret ; 1
;
; pointer to external stack or pdata
;
pdataptr$:
movx a,@r0 ; 1
sjmp dataptrrestore$ ; 2
;
; pointer to code area
;
codeptr$:
; implementation for SiLabs C8051F12x
mov a,b ; 2
anl a,#0x03 ; 2
swap a ; 1
push _PSBANK ; 2
anl _PSBANK,#0x0F ; 3
orl _PSBANK,a ; 2
clr a ; 1
movc a,@a+dptr ; 1
pop _PSBANK ; 2
ret ; 1
;
; pointer to xternal data
;
xdataptr$:
; implementation for xram a16-a21 tied to P3
mov _P3,b ; 3
movx a,@dptr ; 1
ret ; 1
;===
;44 bytes
__endasm;
}
#elif defined DSDCC_MODEL_MEDIUM
void
_gptrget (char *gptr) __naked
{
/* This is the non-banked version with pointers up to 15 bits.
Assumes B is free to be used */
gptr; /* hush the compiler */
__asm
;
; depending on the pointer type acc. to SDCCsymt.h
;
mov b,dph ; 3
jb _B_7,codeptr$ ; >0x80 code ; 3
jnb _B_6,xdataptr$ ; <0x40 far ; 3
mov b,r0 ; save r0 independant of regbank ; 2
mov r0,dpl ; use only low order address ; 2
jb _B_5,pdataptr$ ; >0x60 pdata ; 3
;
; Pointer to data space
;
mov a,@r0 ; 1
mov r0,b ; restore r0 ; 2
ret ; 1
;
; pointer to xternal stack or pdata
;
pdataptr$:
movx a,@r0 ; 1
mov r0,b ; restore r0 ; 2
ret ; 1
;
; pointer to code area, max 15 bits
;
codeptr$:
; 0x8000 <= dptr <= 0xFFFF
; no need to AND dph and restore from B if hardware wraps code memory
anl dph,#0x7F ; 3
clr a ; 1
movc a,@a+dptr ; 1
mov dph,b ; 3
ret ; 1
;
; pointer to xternal data, max 14 bits
;
xdataptr$:
; 0 <= dptr <= 0x3FFF
movx a,@dptr ; 1
ret ; 1
;===
;35 bytes
__endasm;
}
#else
void
_gptrget (char *gptr) __naked
{
/* This is the new version with pointers up to 16 bits.
B cannot be trashed */
gptr; /* hush the compiler */
__asm
;
; depending on the pointer type acc. to SDCCsymt.h
;
jb _B_7,codeptr$ ; >0x80 code ; 3
jnb _B_6,xdataptr$ ; <0x40 far ; 3
mov dph,r0 ; save r0 independant of regbank ; 2
mov r0,dpl ; use only low order address ; 2
jb _B_5,pdataptr$ ; >0x60 pdata ; 3
;
; Pointer to data space
;
mov a,@r0 ; 1
dataptrrestore$:
mov r0,dph ; restore r0 ; 2
mov dph,#0 ; restore dph ; 2
ret ; 1
;
; pointer to xternal stack or pdata
;
pdataptr$:
movx a,@r0 ; 1
sjmp dataptrrestore$ ; 2
;
; pointer to code area, max 16 bits
;
codeptr$:
clr a ; 1
movc a,@a+dptr ; 1
ret ; 1
;
; pointer to xternal data, max 16 bits
;
xdataptr$:
movx a,@dptr ; 1
ret ; 1
;===
;27 bytes
__endasm;
}
#endif
#ifdef __SDCC_ds390
/* the return value is expected to be in acc/acc1, and not in the standard
* location dpl/dph. Therefore we choose return type void here: */
void
_gptrgetWord (unsigned *gptr)
{
gptr; /* hush the compiler */
__asm
;
; depending on the pointer type acc. to SDCCsymt.h
;
jb _B_7,00003$ ; >0x80 code
jnb _B_6,00002$ ; <0x40 far
mov dph,r0 ; save r0 independant of regbank
mov r0,dpl ; use only low order address
jb _B_5,00004$ ; >0x60 pdata
;
; Pointer to data space
;
mov acc1,@r0
inc r0
mov a,@r0
inc dpl
sjmp 00005$
;
; pointer to xternal data
;
00002$:
movx a,@dptr
mov acc1,a
inc dptr
movx a,@dptr
sjmp 00006$
;
; pointer to code area
;
00003$:
clr a
movc a,@a+dptr
mov acc1,a
clr a
inc dptr
movc a,@a+dptr
sjmp 00006$
;
; pointer to xternal stack
;
00004$:
movx a,@r0
mov acc1,a
inc r0
movx a,@r0
inc dpl
;
; restore and return
;
00005$:
mov r0,dph ; restore r0
mov dph,#0 ; restore dph
00006$:
xch a,acc1
__endasm;
}
#endif
|