* src/mcs51/gen.c (pushSide, genSignedRightShift, genDjnz, geniPush):
[fw/sdcc] / device / lib / _gptrget.c
index ca8bc1bdb81758b1ce042c71de8ad56a1e412ed7..f0a4ab89988e2de035140f9cb8930bd3af1cbba3 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
-unsigned char _gptrget ()
+#define P2_PAGES_PDATA 0 /* not all devices use P2 to page pdata memory */
+
+/* the  return value is expected to be in acc, and not in the standard
+ * location dpl. Therefore we choose return type void here: */
+void
+_gptrget (char *gptr)
 {
+    gptr; /* hush the compiler */
+       
     _asm
     ;   save values passed
-       xch    a,r0
-       push   acc
     ;
     ;   depending on the pointer type acc. to SDCCsymt.h
     ;
@@ -39,7 +44,7 @@ unsigned char _gptrget ()
         dec     a
         jz      00003$ ; 2 code
        dec     a
-       jz      00004$
+       jz      00004$  ; 3 pdata
        dec     a       ; 4 skip generic pointer
        dec     a
        jz      00001$  ; 5 idata
@@ -52,8 +57,13 @@ unsigned char _gptrget ()
     ;   Pointer to data space
     ;
  00001$:
+       push    ar0
+        ;
        mov     r0,dpl     ; use only low order address
        mov     a,@r0
+        ;
+        pop     ar0
+        ;
         sjmp    00005$
     ;
     ;   pointer to xternal data
@@ -69,25 +79,34 @@ unsigned char _gptrget ()
         movc    a,@a+dptr
         sjmp    00005$
 ;
-;   pointer to xternal stack
+;   pointer to xternal stack or pdata
 ;
  00004$:
+#if P2_PAGES_PDATA
+        mov     dph,p2          ; p2 holds high byte for pdata access
+        movx    a,@dptr
+#else
+       push    ar0
        mov     r0,dpl
         movx    a,@r0
+       pop     ar0
+#endif 
+       
 ;
-;   restore and return
+;   return
 ;
  00005$:
-        mov     r0,a
-        pop     acc
-       xch     a,r0
      _endasm ;
-
 }
 
 #ifdef SDCC_ds390
-unsigned int _gptrgetWord ()
+/* the  return value is expected to be in acc/_ap, 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
@@ -99,7 +118,7 @@ unsigned int _gptrgetWord ()
         dec     a
         jz      00003$ ; 2 code
        dec     a
-       jz      00004$
+       jz      00004$  ; 3 pdata
        dec     a       ; 4 skip generic pointer
        dec     a
        jz      00001$  ; 5 idata