TSD PIC port
[fw/sdcc] / src / SDCCmem.c
index e19ed96f11695b5a4a6276aa6c09b5280fcdc833..3b47782fff85f20232733bf07ed3f3411ed53138 100644 (file)
@@ -6,10 +6,10 @@
 
 /* memory segments */
 memmap  *xstack= NULL ;         /* xternal stack data         */
-memmap  *istack= NULL;  /* internal stack                 */
-memmap  *code  = NULL;  /* code segment                   */
+memmap  *istack= NULL;  /* internal stack             */
+memmap  *code  = NULL;  /* code segment               */
 memmap  *data  = NULL;  /* internal data upto 128     */
-memmap  *xdata = NULL;  /* external data                          */
+memmap  *xdata = NULL;  /* external data              */
 memmap  *idata = NULL;  /* internal data upto 256     */
 memmap  *bit   = NULL;  /* bit addressable space      */
 memmap  *statsg= NULL;  /* the constant data segment  */
@@ -19,14 +19,12 @@ memmap  *sfrbit= NULL;   /* sfr bit space               */
 memmap  *generic=NULL;   /* is a generic pointer        */
 memmap  *overlay=NULL;   /* overlay segment             */
 memmap  *eeprom =NULL;   /* eeprom location             */
+memmap *home   =NULL;   /* Unswitchable code bank      */
 
 /* this is a set of sets each set containing
    symbols in a single overlay */
 set *ovrSetSets = NULL;    
 
-extern set *operKeyReset ;
-extern set *tmpfileSet ;
-extern symbol *interrupts[];
 int maxRegBank = 0;
 int fatalError = 0                      ;/* fatal error flag                   */
 
@@ -114,6 +112,18 @@ void initMem ()
        */
        code      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C',CPOINTER);
 
+       /* home  segment ;   
+                  SFRSPACE       -   NO
+                  FAR-SPACE      -   YES
+                  PAGED          -   NO
+                  DIRECT-ACCESS  -   NO
+                  BIT-ACCESS     -   NO
+                  CODE-ACESS     -   YES 
+                  DEBUG-NAME     -   'C'
+                  POINTER-TYPE   -   CPOINTER
+       */
+       home      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C',CPOINTER);
+
        /* Static segment (code for variables );
                   SFRSPACE       -   NO
                   FAR-SPACE      -   YES
@@ -253,8 +263,10 @@ void allocIntoSeg (symbol *sym)
 /*-----------------------------------------------------------------*/
 void allocGlobal ( symbol *sym )
 {
+       
     /* symbol name is internal name  */
-    sprintf (sym->rname,"%s%s", port->fun_prefix, sym->name);
+    if (!sym->level) /* local statics can come here */
+           sprintf (sym->rname,"%s%s", port->fun_prefix, sym->name);
     
     /* add it to the operandKey reset */
     addSet(&operKeyReset,sym);
@@ -431,7 +443,7 @@ void allocParms ( value  *val )
                    /* PENDING: isr, bank overhead, ... */
                    SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = 
                        stackPtr +
-                       (IS_BANKED(currFunc->etype) ? port->stack.banked_overhead : 0) +
+                       (IS_BANKEDCALL(currFunc->etype) ? port->stack.banked_overhead : 0) +
                        (IS_ISR(currFunc->etype) ? port->stack.isr_overhead : 0) +
                        0;
                    stackPtr += getSize (lval->type);
@@ -452,11 +464,15 @@ void allocParms ( value  *val )
                   note here that we put it into the overlay segment
                   first, we will remove it from the overlay segment
                   after the overlay determination has been done */
-               SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = 
-                   ( options.model  ? port->mem.default_local_map : 
-                     (options.noOverlay ? port->mem.default_local_map
-                      :overlay ));
-           
+               if (options.model == MODEL_SMALL) {
+                   SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = 
+                       ( options.model == MODEL_SMALL ? port->mem.default_local_map : 
+                         (options.noOverlay ? port->mem.default_local_map
+                          :overlay ));
+               } else {
+                   SPEC_SCLS(lval->etype) = S_XDATA;
+                   SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = xdata;
+               }
            allocIntoSeg(lval->sym);
        }
     }
@@ -521,9 +537,7 @@ void allocLocal ( symbol *sym  )
 
     /* if this is a static variable */
     if ( IS_STATIC (sym->etype)) {
-/*     SPEC_OCLS(sym->etype) = (options.model ? xdata : data ); */
-       SPEC_OCLS(sym->etype) = port->mem.default_local_map;
-       allocIntoSeg (sym);
+       allocGlobal(sym);
         sym->allocreq = 1;
        return   ;
     }
@@ -628,7 +642,7 @@ void allocLocal ( symbol *sym  )
     /* again note that we have put it into the overlay segment
        will remove and put into the 'data' segment if required after 
        overlay  analysis has been done */   
-    SPEC_OCLS(sym->etype) = ( options.model  ? port->mem.default_local_map : 
+    SPEC_OCLS(sym->etype) = ( options.model == MODEL_SMALL ? port->mem.default_local_map : 
                              (options.noOverlay ? port->mem.default_local_map
                               : overlay )) ;
     allocIntoSeg (sym); 
@@ -852,7 +866,7 @@ void redoStackOffsets ()
 
     /* if the debug option is set then output the
        symbols to the map file */
-    if (options.debug) {
+    if (options.debug && !options.nodebug) {
        for (sym = setFirstItem(istack->syms); sym;
             sym = setNextItem(istack->syms))
            cdbSymbol(sym,cdbFile,FALSE,FALSE);
@@ -902,6 +916,58 @@ static void printAllocInfoSeg ( memmap *map, symbol *func, FILE *of)
     }
 }
 
+/*-----------------------------------------------------------------*/
+/* canOverlayLocals - returns true if the local variables can overlayed */
+/*-----------------------------------------------------------------*/
+static bool canOverlayLocals (eBBlock **ebbs, int count)
+{
+    int i;
+    /* if staticAuto is in effect or the current function
+       being compiled is reentrant or the overlay segment
+       is empty or no overlay option is in effect then */
+    if (options.noOverlay ||
+       options.stackAuto ||
+       (currFunc &&
+        (IS_RENT(currFunc->etype) ||
+         IS_ISR(currFunc->etype))) ||
+       elementsInSet(overlay->syms) == 0)
+       
+       return FALSE;
+
+    /* otherwise do thru the blocks and see if there
+       any function calls if found then return false */
+    for (i = 0; i < count ; i++ ) {
+       iCode *ic;
+
+       for (ic = ebbs[i]->sch; ic ; ic = ic->next)
+           if (ic && ( ic->op == CALL || ic->op == PCALL))
+               return FALSE;
+    }
+
+    /* no function calls found return TRUE */
+    return TRUE;
+}
+
+/*-----------------------------------------------------------------*/
+/* doOverlays - move the overlay segment to appropriate location   */
+/*-----------------------------------------------------------------*/
+void doOverlays( eBBlock **ebbs, int count)
+{
+    /* check if the parameters and local variables
+       of this function can be put in the overlay segment
+       This check is essentially to see if the function
+       calls any other functions if yes then we cannot
+       overlay */
+    if (canOverlayLocals(ebbs,count))
+       /* if we can then put the parameters &
+          local variables in the overlay set */
+       overlay2Set();       
+    else
+       /* otherwise put them into data where
+          they belong */
+       overlay2data();
+}
+
 /*-----------------------------------------------------------------*/
 /* printAllocInfo - prints allocation information for a function   */
 /*-----------------------------------------------------------------*/