Added options --stack-size and --pack-iram
authorjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 18 Feb 2004 17:57:54 +0000 (17:57 +0000)
committerjesusc <jesusc@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 18 Feb 2004 17:57:54 +0000 (17:57 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3206 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
as/mcs51/aslink.h
as/mcs51/lkarea.c
as/mcs51/lkdata.c
as/mcs51/lkmain.c
as/mcs51/lkmem.c
doc/sdccman.lyx
src/SDCCglobl.h
src/SDCCmain.c

index 9566a913c45f87dce7edf231b9d4a0ce8d862a7e..1640d9d873dcab8735842ac23c7f4d923f941cd1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-02-18  Jesus Calvino-Fraga <jesusc AT ece.ubc.ca>
+
+       * as/mcs51/aslink.h, as/mcs51/lkarea.c, as/mcs51/lkdata.c, as/mcs51/lkmain.c,
+       as/mcs51/lkmem.c, src/SDCCglob.h, src/SDCCmain.c: added options --stack-size and
+       --pack-iram.
+       * doc/sdccman.lyx: described options --stack-size and --pack-iram.
+
 2004-02-17 Bernhard Held <bernhard AT bernhardheld.de>
 
        * device/include/c8051f320.h: added. Contributed by Maarten Brock.
index ff4cb8da9842a1970e15641694372821910d9b79..ace467effb2f572fca31eff6420d1445d6feeb14 100644 (file)
@@ -578,7 +578,9 @@ extern      int     mflag;          /*      Map output flag
                                 */
 extern int     sflag;          /*      JCF: Memory usage output flag
                                 */
-extern int     packflag_and_stacksize; /*      Pack data memory flag
+extern int     packflag;       /*      Pack data memory flag
+                                */
+extern int     stacksize;      /*      Pack data memory flag
                                 */
 extern int     jflag;          /*      NoICE output flag
                                 */
index 9646d30f5560df8ecd33e1364ed9ed5730632881..693b5d493bdb9a14178ed30a6567cde6faf1ba56 100644 (file)
@@ -658,6 +658,23 @@ void lnksect2 (struct area *tap, int rloc)
                 for(j=0, size=0; j<ramlimit; j++)
                     if(idatamap[j]==fchar) size++;
 
+                if( (fchar=='S') && (stacksize==0) )
+                {
+                   /*Search for the largest space available and use it for stack*/
+                    for(j=0, k=0, taxp->a_size=0; j<ramlimit; j++)
+                    {
+                        if(idatamap[j]==' ')
+                        {
+                            if((++k)>(int)taxp->a_size) taxp->a_size=k;
+                        }
+                        else
+                        {
+                            k=0;
+                        }
+                    }
+                    stacksize=taxp->a_size;
+                }
+
                 /*If more space required, release the previously allocated areax in 
                 internal RAM and search for a bigger one*/
                 if((int)taxp->a_size>size)
index 1840ee794f617f346f777c331855369736e08497..660c22af26a284cdd322057504dfa1f612aee010 100644 (file)
@@ -55,7 +55,9 @@ int   mflag;          /*      Map output flag
                         */
 int    sflag;          /*      JCF: Memory usage output flag
                         */
-int    packflag_and_stacksize=0;       /*      JCF: Pack internal memory flag
+int    packflag=0;     /*      JCF: Pack internal memory flag
+                        */
+int    stacksize=0;    /*      JCF: Stack size
                         */
 int    aflag;          /*      Overlapping area warning flag
                         */
index b51857ceb6290a283f1338010324d57324d1ae47..fd11cf39458126d69138259fdfa24751dfd407be 100644 (file)
@@ -108,7 +108,7 @@ void Areas51 (void)
        };
        int j;
 
-    if(packflag_and_stacksize)
+    if(packflag)
     {
            for (j=0; rel2[j][0]!=0; j++)
            {
@@ -135,7 +135,7 @@ void Areas51 (void)
                else if (!strcmp(ap->a_id, "BSEG_BYTES")) { ap->a_addr=0x20; ap->a_type=1; }
                else if (!strcmp(ap->a_id, "SSEG"))
         {
-            if(packflag_and_stacksize>1) ap->a_axp->a_size=packflag_and_stacksize;
+            if(stacksize) ap->a_axp->a_size=stacksize;
         }
        }
 }
@@ -340,7 +340,7 @@ char *argv[];
                        /*
                         * Link all area addresses.
                         */
-                       if(!packflag_and_stacksize)
+                       if(!packflag)
                 lnkarea();
             else
                 lnkarea2();
@@ -371,7 +371,7 @@ char *argv[];
 
                        if (sflag) /*JCF: memory usage summary output*/
             {
-                if(!packflag_and_stacksize)
+                if(!packflag)
                 {
                                    if(summary(areap)) lkexit(1);
                 }
@@ -381,7 +381,7 @@ char *argv[];
                 }
             }
 
-                       if ((iram_size) && (!packflag_and_stacksize))
+                       if ((iram_size) && (!packflag))
                                iramcheck();
 
                        /*
@@ -825,10 +825,19 @@ parse()
 
                 case 'Y':
                     unget(getnb());
-                    /*The stack segment default size is 16 bytes.  Use -Yxx for xx bytes*/
-                    packflag_and_stacksize=(ip && *ip)?expr(0):16;
+                    packflag=1;
                     break;
 
+                case 'A':
+                    unget(getnb());
+                    if (ip && *ip)
+                    {
+                        stacksize=expr(0);
+                        if(stacksize>256) stacksize=256;
+                        else if(stacksize<0) stacksize=0;
+                    }
+                                       return(0);
+
                                case 'j':
                                case 'J':
                                        jflag = 1;
@@ -892,7 +901,6 @@ parse()
                                        return(0);
 
                                case 'a':
-                               case 'A':
                                        iramsav();
                                        return(0);
 
@@ -1367,7 +1375,8 @@ char *usetxt[] = {
        "  -v   [xram-size] Check for external RAM overflow",
        "  -w   [code-size] Check for code overflow",
        "  -y   Generate memory usage summary file[mem]",
-       "  -Y   [stack-size] Pack internal ram and allocate space for stack",
+       "  -Y   Pack internal ram",
+       "  -A   [stack-size] Allocate space for stack",
        "End:",
        "  -e   or null line terminates input",
        0
index 9e63c868be56238c386cb1e893d8ac13cacf8740..bf4c4ef854c563669beb2170a2ef31bff39d84ea 100644 (file)
@@ -73,12 +73,14 @@ int summary(struct area * areap)
                {0x7f,  0,      128, "DATA",       0x0020},
                {0,             0,      128, "TOTAL:",     0x0000}
        };
-       
+
        _Mem IRam= {0xff,   0,   128, "INDIRECT RAM",           0x0080};
        _Mem Stack={0xff,   0,     1, "STACK",                          0x0000};
        _Mem XRam= {0xffff, 0, 65536, "EXTERNAL RAM",           0x0100};
        _Mem Rom=  {0xffff, 0, 65536, "ROM/EPROM/FLASH",        0x0200};
-       
+
+       if(stacksize==0) stacksize=MIN_STACK;
+
        if(rflag) /*For the DS390*/
        {
                XRam.Max=0x1000000; /*24 bits*/
@@ -285,7 +287,7 @@ int summary(struct area * areap)
        {
                for(j=Stack.Start, k=0; (j<(int)iram_size)&&(dram[j]==0); j++, k++);
                fprintf(of, " with %d bytes available\n", k);
-               if (k<MIN_STACK)
+               if ((int)k<stacksize)
                {
                        sprintf(buff, "Only %d byte%s available for stack.\n",
                                k, (k==1)?"":"s");
@@ -356,7 +358,6 @@ extern char idatamap[]; //0:not used, 1:used
 int summary2(struct area * areap) 
 {
        #define EQ(A,B) !as_strcmpi((A),(B))
-       #define MIN_STACK 16
 
        char buff[128];
        int j, toreturn=0;
index d5b5d0ebca68e454db8c949a519ba6c79f19286a..b6bfc0289cd839e5adc96a29c4cd701a7343efa2 100644 (file)
@@ -1718,10 +1718,10 @@ Install paths
 \begin_inset  Tabular
 <lyxtabular version="3" rows="5" columns="4">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -5888,6 +5888,54 @@ status Collapsed
 
  Causes the linker to check if the code memory usage is within limits of
  the given value.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-stack-size
+\series default 
+\SpecialChar ~
+<Value>
+\begin_inset LatexCommand \index{-\/-stack-size <Value>}
+
+\end_inset 
+
+ Causes the linker to check if there is at minimum <Value> bytes for stack.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-pack-iram
+\series default 
+\SpecialChar ~
+
+\begin_inset LatexCommand \index{-\/-pack-iram}
+
+\end_inset 
+
+ Causes the linker use unused register banks for data variables or stack.
 \layout Subsection
 
 DS390 / DS400 Options
@@ -12253,8 +12301,8 @@ For signed & unsigned int (16 bit) and long (32 bit) variables, division,
 \begin_inset  Tabular
 <lyxtabular version="3" rows="11" columns="2">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -12547,8 +12595,8 @@ SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
 \begin_inset  Tabular
 <lyxtabular version="3" rows="17" columns="2">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -13870,8 +13918,8 @@ The compiler creates the following #defines
 \begin_inset  Tabular
 <lyxtabular version="3" rows="10" columns="2">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -14875,8 +14923,8 @@ PIC16 port defines the following preprocessor macros while translating a
 \begin_inset  Tabular
 <lyxtabular version="3" rows="2" columns="2">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -14937,10 +14985,10 @@ PIC16 port uses the following directories for searching header files and
 \begin_inset  Tabular
 <lyxtabular version="3" rows="3" columns="4">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -15159,9 +15207,9 @@ Memory model affects the default size of pointers within the source.
 \begin_inset  Tabular
 <lyxtabular version="3" rows="3" columns="3">
 <features>
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -15311,9 +15359,9 @@ large
 \begin_inset  Tabular
 <lyxtabular version="3" rows="3" columns="3">
 <features>
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -15411,8 +15459,8 @@ Return values from functions are placed to the appropriate registers following
 \begin_inset  Tabular
 <lyxtabular version="3" rows="6" columns="2">
 <features>
-<column alignment="center" valignment="top" leftline="true" width="0">
-<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0(null)">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
@@ -17323,7 +17371,7 @@ Documentation
 \begin_inset  Tabular
 <lyxtabular version="3" rows="10" columns="2">
 <features>
-<column alignment="left" valignment="top" leftline="true" width="0">
+<column alignment="left" valignment="top" leftline="true" width="0(null)">
 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
 <row topline="true" bottomline="true">
 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
index 5ef744e0e711d34a311abd2ed8b7fb45a5f7a297..687d9075c624e46723ab77f4f8eb72f389364b0c 100644 (file)
@@ -226,6 +226,8 @@ struct options
     int tini_libid;            /* library ID for TINI */
     int protect_sp_update;     /* DS390 - will disable interrupts during ESP:SP updates */
     int parms_in_bank1;        /* DS390 - use reg bank1 to pass parameters */
+    int stack_size;            /* MCS51/DS390 - Tells the linker to allocate this space for stack */
+    int pack_iram;             /* MCS51/DS390 - Tells the linker to pack variables in internal ram */
     /* starting address of the segments */
     int xstack_loc;            /* initial location of external stack */
     int stack_loc;             /* initial value of internal stack pointer */
index 59f2763287bb8bbf8e5a5e669407d8d992dd003e..5c6bddaf72f9a6d895edd85ae069b1b434c2eef9 100644 (file)
@@ -124,6 +124,8 @@ char buffer[PATH_MAX * 2];
 #define OPTION_PRINT_SEARCH_DIRS "--print-search-dirs"
 #define OPTION_MSVC_ERROR_STYLE "--vc"
 #define OPTION_USE_STDOUT       "--use-stdout"
+#define OPTION_STACK_SIZE      "--stack-size"
+#define OPTION_PACK_IRAM       "--pack-iram"
 
 static const OPTION
 optionsTable[] = {
@@ -218,6 +220,8 @@ optionsTable[] = {
 #endif
 #if !OPT_DISABLE_DS390 || !OPT_DISABLE_MCS51
     { 0,    "--parms-in-bank1",            &options.parms_in_bank1,"MCS51/DS390 - use Bank1 for parameter passing"},
+    { 0,    OPTION_STACK_SIZE,     NULL,"MCS51/DS390 - Tells the linker to allocate this space for stack"},
+    { 0,    OPTION_PACK_IRAM,      &options.pack_iram,"MCS51/DS390 - Tells the linker to pack variables in internal ram"},
 #endif
     { 0,    OPTION_NO_XINIT_OPT,    &options.noXinitOpt, "don't memcpy initialized xram from code"},
     { 0,    OPTION_NO_CCODE_IN_ASM, &options.noCcodeInAsm, "don't include c-code as comments in the asm file"},
@@ -908,6 +912,12 @@ parseCmdLine (int argc, char **argv)
                 options.stack_loc = getIntArg(OPTION_STACK_LOC, argv, &i, argc);
                 continue;
            }
+         
+      if (strcmp (argv[i], OPTION_STACK_SIZE) == 0)
+           {
+                options.stack_size = getIntArg(OPTION_STACK_SIZE, argv, &i, argc);
+                continue;
+           }
 
          if (strcmp (argv[i], OPTION_XRAM_LOC) == 0)
            {
@@ -1307,6 +1317,8 @@ linkEdit (char **envp)
       else /*For all the other ports.  Including pics???*/
         {
           fprintf (lnkfile, "-myux%c\n", (options.out_fmt ? 's' : 'i'));
+          if(options.pack_iram)
+              fprintf (lnkfile, "-Y\n");
         }
 
       if (!(TARGET_IS_Z80 || TARGET_IS_GBZ80)) /*Not for the z80, gbz80*/
@@ -1315,6 +1327,10 @@ linkEdit (char **envp)
           if (options.iram_size)
             fprintf (lnkfile, "-a 0x%04x\n", options.iram_size);
 
+          /* if stack size specified*/
+          if(options.stack_size)
+              fprintf (lnkfile, "-A 0x%02x\n", options.stack_size);
+
           /* if xram size specified */
           if (options.xram_size_set)
             fprintf (lnkfile, "-v 0x%04x\n", options.xram_size);