* src/z80/gen.c (setupPair): Added 'extended stack' support for the z80. Can now...
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Oct 2001 18:28:35 +0000 (18:28 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 7 Oct 2001 18:28:35 +0000 (18:28 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1373 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/z80/gen.c
src/z80/gen.h
support/regression/tests/bp.c

index 204e19bdb78b4e200e450c867a2a19ad85f0cda8..203d72e586b108d422b7846c18c431314eac731d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2001-10-07  Michael Hope  <michaelh@juju.net.nz>
 
+       * src/z80/gen.c (setupPair): Added 'extended stack' support for the z80.  Can now have local variables or parameters of more than 127 bytes in size.  Increadibly slow, but it will work.  Currently anything involving the carry flag.
+
        * support/Util/NewAlloc.c (freeTrace): Changed free for the gc case to not free at all.  Fixes runtime segfault.
 
        * support/regression/tests/scott-compare3.c (c_abcd): Fixed up casts.
index 91528e38e39a69db50886042ac72642d3f33a6be..7421f80070cf69ed65f888c99414c391aeecdd60 100644 (file)
@@ -167,10 +167,6 @@ static struct
 // PENDING
 #define ACC_NAME       _pairs[PAIR_AF].h
 
-#define RESULTONSTACK(x) \
-                         (IC_RESULT(x) && IC_RESULT(x)->aop && \
-                         IC_RESULT(x)->aop->type == AOP_STK )
-
 enum 
   {
     LSB,
@@ -539,8 +535,21 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool requires_a)
   /* Assign depending on the storage class */
   if (sym->onStack || sym->iaccess)
     {
-      emitDebug ("; AOP_STK for %s", sym->rname);
-      sym->aop = aop = newAsmop (AOP_STK);
+      /* The pointer that is used depends on how big the offset is.
+         Normally everything is AOP_STK, but for offsets of < -127 or
+         > 128 on the Z80 an extended stack pointer is used.
+      */
+      if (IS_Z80 && (sym->stack < -127 || sym->stack > (int)(128-getSize (sym->type))))
+        {
+          emitDebug ("; AOP_EXSTK for %s", sym->rname);
+          sym->aop = aop = newAsmop (AOP_EXSTK);
+        }
+      else
+        {
+          emitDebug ("; AOP_STK for %s", sym->rname);
+          sym->aop = aop = newAsmop (AOP_STK);
+        }
+
       aop->size = getSize (sym->type);
       aop->aopu.aop_stk = sym->stack;
       return aop;
@@ -1038,6 +1047,7 @@ requiresHL (asmop * aop)
     case AOP_IY:
     case AOP_HL:
     case AOP_STK:
+    case AOP_EXSTK:
       return TRUE;
     default:
       return FALSE;
@@ -1150,12 +1160,39 @@ setupPair (PAIR_ID pairId, asmop * aop, int offset)
   switch (aop->type)
     {
     case AOP_IY:
+      wassertl (pairId == PAIR_IY, "AOP_IY must be in IY");
       fetchLitPair (pairId, aop, 0);
       break;
+
     case AOP_HL:
       fetchLitPair (pairId, aop, offset);
       _G.pairs[pairId].offset = offset;
       break;
+
+    case AOP_EXSTK:
+      wassertl (IS_Z80, "Only the Z80 has an extended stack");
+      wassertl (pairId == PAIR_IY, "The Z80 extended stack must be in IY");
+
+      {
+       int offset = aop->aopu.aop_stk + _G.stack.offset;
+
+        if (_G.pairs[pairId].last_type == aop->type &&
+            _G.pairs[pairId].offset == offset)
+          {
+            /* Already setup */
+          }
+        else
+          {
+            /* PENDING: Do this better. */
+            sprintf (buffer, "%d", offset + _G.stack.pushed);
+            emit2 ("ld iy,!hashedstr", buffer);
+            emit2 ("add iy,sp");
+            _G.pairs[pairId].last_type = aop->type;
+            _G.pairs[pairId].offset = offset;
+          }
+      }
+      break;
+
     case AOP_STK:
       {
        /* Doesnt include _G.stack.pushed */
@@ -1263,6 +1300,13 @@ aopGet (asmop * aop, int offset, bool bit16)
 
       return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
+    case AOP_EXSTK:
+      wassert (IS_Z80);
+      setupPair (PAIR_IY, aop, offset);
+      tsprintf (s, "!*iyx", offset, offset);
+
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
+
     case AOP_STK:
       if (IS_GB)
        {
@@ -1398,14 +1442,17 @@ aopPut (asmop * aop, const char *s, int offset)
 
     case AOP_IY:
       wassert (!IS_GB);
-      setupPair (PAIR_IY, aop, offset);
       if (!canAssignToPtr (s))
        {
          emit2 ("ld a,%s", s);
+          setupPair (PAIR_IY, aop, offset);
          emit2 ("ld !*iyx,a", offset);
        }
       else
-       emit2 ("ld !*iyx,%s", offset, s);
+        {
+          setupPair (PAIR_IY, aop, offset);
+          emit2 ("ld !*iyx,%s", offset, s);
+        }
       break;
 
     case AOP_HL:
@@ -1421,6 +1468,21 @@ aopPut (asmop * aop, const char *s, int offset)
       emit2 ("ld !*hl,%s", s);
       break;
 
+    case AOP_EXSTK:
+      wassert (!IS_GB);
+      if (!canAssignToPtr (s))
+       {
+         emit2 ("ld a,%s", s);
+          setupPair (PAIR_IY, aop, offset);
+         emit2 ("ld !*iyx,a", offset);
+       }
+      else
+        {
+          setupPair (PAIR_IY, aop, offset);
+          emit2 ("ld !*iyx,%s", offset, s);
+        }
+      break;
+
     case AOP_STK:
       if (IS_GB)
        {
index 57277a34f4a19fdab3c1fa2fcec2b7d018ef73df..8751531ce8aa89299d916eae04de8a0891bcc9c6 100644 (file)
@@ -53,7 +53,9 @@ typedef enum
     /* Is in H and L */
     AOP_HLREG,
     /* Simple literal. */
-    AOP_SIMPLELIT
+    AOP_SIMPLELIT,
+    /* Is in the extended stack pointer (IY on the Z80) */
+    AOP_EXSTK
   }
 AOP_TYPE;
 
index f534c98e4dd1c011ef14ea5d9bb0d151330282ed..41cd4c774cbf432ff1f5bc98da864a9f36acbd3f 100644 (file)
@@ -15,8 +15,8 @@ verifyBlock(char *p, char val, int len)
   return 1;
 }
 
-char
-spoil(char a)
+int
+spoil(int a)
 {
   return a;
 }
@@ -42,7 +42,7 @@ void
 testBP(void)
 {
   char above[ABOVE_MEM_SIZE];
-  char f;
+  int f;
   char below[BELOW_MEM_SIZE];
 
   memset(above, ABOVE_MEM_TEST_SIZE, sizeof(above));
@@ -56,4 +56,5 @@ testBP(void)
 
   ASSERT(verifyBlock(above, ABOVE_MEM_TEST_SIZE, sizeof(above)));
   ASSERT(verifyBlock(below, BELOW_MEM_TEST_SIZE, sizeof(below)));
+
 }