* device/lib/_gptrget.c,
[fw/sdcc] / device / lib / _gptrget.c
index 25a421254558fb0a684733434e39aede44ee381a..30f982976095aed6cfc07e5f95d8fb36dddf36fa 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
-/* 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 save for all platforms to set this */
+/* 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
 
 /* the  return value is expected to be in acc, and not in the standard
@@ -34,36 +36,36 @@ void
 _gptrget (char *gptr)
 {
     gptr; /* hush the compiler */
-       
+
     _asm
     ;   save values passed
     ;
     ;   depending on the pointer type acc. to SDCCsymt.h
     ;
         mov     a,b
-        jz      00001$ ; 0 near
-       dec     a
-       jz      00002$  ; 1 far
+        jz      00001$  ; 0 near
+        dec     a
+        jz      00002$  ; 1 far
+        dec     a
+        jz      00003$  ; 2 code
+        dec     a
+        jz      00004$  ; 3 pdata
+        dec     a       ; 4 skip generic pointer
         dec     a
-        jz      00003$ ; 2 code
-       dec     a
-       jz      00004$  ; 3 pdata
-       dec     a       ; 4 skip generic pointer
-       dec     a
-       jz      00001$  ; 5 idata
+        jz      00001$  ; 5 idata
     ;
     ;   any other value for type
     ;   return xFF
-       mov     a,#0xff
-       sjmp    00005$
+        mov     a,#0xff
+        sjmp    00005$
     ;
     ;   Pointer to data space
     ;
  00001$:
-       push    ar0
+        push    ar0
         ;
-       mov     r0,dpl     ; use only low order address
-       mov     a,@r0
+        mov     r0,dpl     ; use only low order address
+        mov     a,@r0
         ;
         pop     ar0
         ;
@@ -78,7 +80,7 @@ _gptrget (char *gptr)
 ;   pointer to code area
 ;
  00003$:
-       ; clr     a  is already 0
+        ; clr     a  is already 0
         movc    a,@a+dptr
         sjmp    00005$
 ;
@@ -89,12 +91,12 @@ _gptrget (char *gptr)
         mov     dph,__XPAGE     ; __XPAGE (usually p2) holds high byte for pdata access
         movx    a,@dptr
 #else
-       push    ar0
-       mov     r0,dpl
+        push    ar0
+        mov     r0,dpl
         movx    a,@r0
-       pop     ar0
-#endif 
-       
+        pop     ar0
+#endif
+
 ;
 ;   return
 ;
@@ -115,69 +117,69 @@ _gptrgetWord (unsigned *gptr)
     ;   depending on the pointer type acc. to SDCCsymt.h
     ;
         mov     a,b
-        jz      00001$ ; 0 near
-       dec     a
-       jz      00002$  ; 1 far
+        jz      00001$  ; 0 near
         dec     a
-        jz      00003$ ; 2 code
-       dec     a
-       jz      00004$  ; 3 pdata
-       dec     a       ; 4 skip generic pointer
-       dec     a
-       jz      00001$  ; 5 idata
+        jz      00002$  ; 1 far
+        dec     a
+        jz      00003$  ; 2 code
+        dec     a
+        jz      00004$  ; 3 pdata
+        dec     a       ; 4 skip generic pointer
+        dec     a
+        jz      00001$  ; 5 idata
     ;
     ;   any other value for type
     ;   return xFF
-       mov     a,#0xff
-       sjmp    00006$
+        mov     a,#0xff
+        sjmp    00006$
     ;
     ;   Pointer to data space
     ;
  00001$:
-        push   ar0
-       mov     r0,dpl     ; use only low order address
-       mov     _ap,@r0
-       inc     r0
-       mov     a,@r0
-       inc     dpl
+        push    ar0
+        mov     r0,dpl     ; use only low order address
+        mov     _ap,@r0
+        inc     r0
+        mov     a,@r0
+        inc     dpl
         sjmp    00005$
     ;
     ;   pointer to xternal data
     ;
  00002$:
         movx    a,@dptr
-       mov     _ap,a
-       inc     dptr
-       movx    a,@dptr
+        mov     _ap,a
+        inc     dptr
+        movx    a,@dptr
         sjmp    00006$
 ;
 ;   pointer to code area
 ;
  00003$:
-       ; clr     a  is already 0
+        ; clr     a  is already 0
+        movc    a,@a+dptr
+        mov     _ap,a
+        clr     a
+        inc     dptr
         movc    a,@a+dptr
-       mov     _ap,a
-       clr     a
-       inc     dptr
-       movc    a,@a+dptr
         sjmp    00006$
 ;
 ;   pointer to xternal stack
 ;
  00004$:
-       push    ar0
-       mov     r0,dpl
+        push    ar0
+        mov     r0,dpl
+        movx    a,@r0
+        mov     _ap,a
+        inc     r0
         movx    a,@r0
-       mov     _ap,a
-       inc     r0
-       movx    a,@r0
-       inc     dpl
+        inc     dpl
 ;
 ;   restore and return
 ;
 00005$:
     pop ar0
-00006$:        
+00006$:
      _endasm ;
 
 }