Fix Karl's FarPointer bug
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 14 Sep 2000 23:03:07 +0000 (23:03 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 14 Sep 2000 23:03:07 +0000 (23:03 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@357 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/ds390/gen.c

index 59fb5f7d65a3e6cf5c915646045cb6c816c15208..f24f651f402a77e6d4bccab061b1a4401206db7d 100644 (file)
@@ -6583,13 +6583,32 @@ static void genFarPointerGet (operand *left,
     if (AOP_TYPE(left) != AOP_STR) {
         /* if this is remateriazable */
         if (AOP_TYPE(left) == AOP_IMMD)
+        {
             emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE));
-        else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
-            if (options.model == MODEL_FLAT24)
+        }
+        else 
+        { 
+            /* we need to get it byte by byte */
+           if (AOP_TYPE(left) != AOP_DPTR)
+           {
+               emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE));
+               emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE));
+               if (options.model == MODEL_FLAT24)
+               {
+                           emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
+               }
+            }
+            else
             {
-               emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
+                 /* We need to generate a load to DPTR indirect through DPTR. */
+                 D(emitcode(";", "genFarPointerGet -- indirection special case."););
+                 emitcode("push", "%s", aopGet(AOP(left),0,FALSE,TRUE));
+                 emitcode("push", "%s", aopGet(AOP(left),1,FALSE,TRUE));
+                 emitcode("mov", "dpx,%s",aopGet(AOP(left),2,FALSE,FALSE));
+                 emitcode("pop", "acc");
+                 emitcode("mov", "dph,a");
+                 emitcode("pop", "acc");
+                 emitcode("mov", "dpl,a");
             }
         }
     }
@@ -7156,18 +7175,35 @@ static void genFarPointerSet (operand *right,
         /* if this is remateriazable */
         if (AOP_TYPE(result) == AOP_IMMD)
             emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE));
-        else { /* we need to get it byte by byte */
-            emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
-            emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
-            if (options.model == MODEL_FLAT24)
+        else 
+        {
+            /* we need to get it byte by byte */
+           if (AOP_TYPE(result) != AOP_DPTR)
+           {
+               emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE));
+               emitcode("mov","dph,%s",aopGet(AOP(result),1,FALSE,FALSE));
+               if (options.model == MODEL_FLAT24)
+               {
+                           emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
+               }
+            }
+            else
             {
-               emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
+                 /* We need to generate a load to DPTR indirect through DPTR. */
+                 D(emitcode(";", "genFarPointerSet -- indirection special case."););
+                 emitcode("push", "%s", aopGet(AOP(result),0,FALSE,TRUE));
+                 emitcode("push", "%s", aopGet(AOP(result),1,FALSE,TRUE));
+                 emitcode("mov", "dpx,%s",aopGet(AOP(result),2,FALSE,FALSE));
+                 emitcode("pop", "acc");
+                 emitcode("mov", "dph,a");
+                 emitcode("pop", "acc");
+                 emitcode("mov", "dpl,a");
             }
         }
     }
     /* so dptr know contains the address */
     freeAsmop(result,NULL,ic,TRUE);
-    aopOp(right,ic,FALSE, FALSE);
+    aopOp(right,ic,FALSE, TRUE);
 
     /* if bit then unpack */
     if (IS_BITVAR(retype))