First pass at 10 bit stack mode for DS80C390
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 8 Mar 2000 23:45:28 +0000 (23:45 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 8 Mar 2000 23:45:28 +0000 (23:45 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@176 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCglobl.h
src/SDCCmain.c
src/mcs51/gen.c
src/mcs51/main.c

index bb71339cda72633df82bd205a4f71bf0fbb9a5de..a66037d35f67e13cb7a07d4ad3830a063ebb7dc6 100644 (file)
@@ -173,6 +173,7 @@ struct options {
     int model  : 3     ; /* see MODEL_* defines above */
     int stackAuto : 3  ; /* Stack Automatic  */
     int useXstack : 3  ; /* use Xternal Stack */
+    int stack10bit : 3;  /* use 10 bit stack (flat24 model only) */
     int genericPtr: 1  ; /* use generic pointers */
     int regExtend : 1  ; /* don't use extended registers */
     int dump_raw  : 1  ; /* dump after intermediate code generation */
index 9ed723065b55bc755dfbab91f2b6a7f4c1192110..b7b6a354031d0281991f5f081c729c7a3e67035e 100644 (file)
@@ -78,6 +78,7 @@ char    *preOutName;
 #define OPTION_SMALL_MODEL "-model-small"
 #define OPTION_FLAT24_MODEL "-model-flat24"
 #define OPTION_STACK_AUTO  "-stack-auto"
+#define OPTION_STACK_10BIT "-stack-10bit"
 #define OPTION_XSTACK      "-xstack"
 #define OPTION_GENERIC     "-generic"
 #define OPTION_NO_GCSE     "-nogcse"
@@ -474,7 +475,12 @@ int   parseCmdLine ( int argc, char **argv )
            if (strcmp(&argv[i][1],OPTION_FLAT24_MODEL) == 0) {
                options.model = MODEL_FLAT24;
                 continue;
-           }       
+           }
+           
+           if (strcmp(&argv[i][1],OPTION_STACK_10BIT) == 0) {
+               options.stack10bit = 1;
+               continue;
+           }
 
            if (strcmp(&argv[i][1],OPTION_STACK_AUTO) == 0) {
                options.stackAuto = 1;
index a182bc99d1116d70c054b039614990ad105c52f8..0eab480bfe51516bf34f10bf5d80f0b6d2449aff 100644 (file)
@@ -273,7 +273,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
     /* assign depending on the storage class */
     /* if it is on the stack or indirectly addressable */
     /* space we need to assign either r0 or r1 to it   */    
-    if (sym->onStack || sym->iaccess) {
+    if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
         sym->aop = aop = newAsmop(0);
         aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
         aop->size = getSize(sym->type);
@@ -283,7 +283,6 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
         if (aop->type != AOP_STK) {
 
             if (sym->onStack) {
-
                     if ( _G.accInUse )
                         emitcode("push","acc");
 
@@ -297,7 +296,6 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
 
                     if ( _G.accInUse )
                         emitcode("pop","acc");
-
             } else
                 emitcode("mov","%s,#%s",
                          aop->aopu.aop_ptr->name,
@@ -307,6 +305,33 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
             aop->aopu.aop_stk = sym->stack;
         return aop;
     }
+    
+    if (sym->onStack && options.stack10bit)
+    {
+        /* It's on the 10 bit stack, which is located in
+         * far data space.
+         */
+        
+        if ( _G.accInUse )
+               emitcode("push","acc");
+
+        emitcode("mov","a,_bp");
+        emitcode("add","a,#0x%02x",
+                 ((sym->stack < 0) ?
+                   ((char)(sym->stack - _G.nRegsSaved )) :
+                   ((char)sym->stack)) & 0xff);
+        
+       emitcode ("mov","dpx,#0x40");
+       emitcode ("mov","dph,#0x00");
+       emitcode ("mov", "dpl, a");
+       
+        if ( _G.accInUse )
+            emitcode("pop","acc");
+            
+       sym->aop = aop = newAsmop(AOP_DPTR);
+       aop->size = getSize(sym->type); 
+       return aop;
+    }
 
     /* if in bit space */
     if (IN_BITSPACE(space)) {
@@ -630,12 +655,23 @@ static void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
             bitVectUnSetBit(ic->rUsed,R1_IDX);          
 
             getFreePtr(ic,&aop,FALSE);
+            
+            if (options.stack10bit)
+            {
+                /* I'm not sure what to do here yet... */
+                /* #STUB */
+               fprintf(stderr, 
+                       "*** Warning: probably generating bad code for "
+                       "10 bit stack mode.\n");
+            }
+            
             if (stk) {
                 emitcode ("mov","a,_bp");
                 emitcode ("add","a,#0x%02x",((char)stk) & 0xff);
                 emitcode ("mov","%s,a",aop->aopu.aop_ptr->name);
-            } else
+            } else {
                 emitcode ("mov","%s,_bp",aop->aopu.aop_ptr->name);
+            }
 
             while (sz--) {
                 emitcode("pop","acc");
@@ -2016,8 +2052,10 @@ static void genFunction (iCode *ic)
            emitcode("inc","%s",spname);
        }
        else
+       {
            /* set up the stack */
            emitcode ("push","_bp");     /* save the callers stack  */
+       }
        emitcode ("mov","_bp,%s",spname);
     }
 
@@ -2057,7 +2095,9 @@ static void genEndFunction (iCode *ic)
     symbol *sym = OP_SYMBOL(IC_LEFT(ic));
 
     if (IS_RENT(sym->etype) || options.stackAuto)
+    {
         emitcode ("mov","%s,_bp",spname);
+    }
 
     /* if use external stack but some variables were
     added to the local stack then decrement the
@@ -2077,7 +2117,9 @@ static void genEndFunction (iCode *ic)
            emitcode("dec","%s",spname);
        }
        else
+       {
            emitcode ("pop","_bp");
+       }
     }
 
     /* restore the register bank  */    
@@ -6842,14 +6884,33 @@ static void genAddrOf (iCode *ic)
             emitcode("mov","a,_bp");
             emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
             aopPut(AOP(IC_RESULT(ic)),"a",0);       
-        } else 
+        } else {
             /* we can just move _bp */
             aopPut(AOP(IC_RESULT(ic)),"_bp",0);
+        }
         /* fill the result with zero */
         size = AOP_SIZE(IC_RESULT(ic)) - 1;
+        
+        
+        if (options.stack10bit && size < (FPTRSIZE - 1))
+        {
+            fprintf(stderr, 
+                   "*** warning: pointer to stack var truncated.\n");
+        }
+        
         offset = 1;
-        while (size--) 
-            aopPut(AOP(IC_RESULT(ic)),zero,offset++);
+        while (size--)
+        {
+            /* Yuck! */
+            if (options.stack10bit && offset == 2)
+            {
+                aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
+            }
+            else
+            {
+               aopPut(AOP(IC_RESULT(ic)),zero,offset++);
+            }
+        }
 
         goto release;
     }
index 04c158b0f495995ac191971b225698ad0321a428..7d0a5a1f05bcbce4426641bc9696793db665d86a 100644 (file)
@@ -80,6 +80,25 @@ static void _mcs51_finaliseOptions(void)
        port->mem.default_local_map = data;
        port->mem.default_globl_map = data;
     }
+    
+    if (options.stack10bit)
+    {
+       if (options.model != MODEL_FLAT24)
+       {
+            fprintf(stderr, 
+                   "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
+            fprintf(stderr, "\t10 bit stack mode disabled.\n");
+            options.stack10bit = 0;
+        }
+        else
+        {
+            /* Fixup the memory map for the stack; it is now in
+             * far space and requires a FPOINTER to access it.
+             */
+            istack->fmap = 1;
+            istack->ptrType = FPOINTER; 
+        }
+    }
 }
 
 static void _mcs51_setDefaultOptions(void)