* src/mcs51/ralloc.c (getRegPtr, getRegGpr),
[fw/sdcc] / as / mcs51 / lkmain.c
index 548a44fdf53ba6e222c337bba8c1681192fff450..b51857ceb6290a283f1338010324d57324d1ae47 100644 (file)
@@ -89,13 +89,41 @@ void Areas51 (void)
                "A BSEG_BYTES size 0 flags 0",  /*Size will be obtained from BSEG in lnkarea()*/
                ""
        };
+       
+    char * rel2[]={
+               "XH",
+               "H B areas 0 global symbols",
+               "A _CODE size 0 flags 0",               /*Each .rel has one, so...*/
+               "A REG_BANK_0 size 0 flags 4",  /*Register banks are overlayable*/
+               "A REG_BANK_1 size 0 flags 4",
+               "A REG_BANK_2 size 0 flags 4",
+               "A REG_BANK_3 size 0 flags 4",
+               "A BSEG size 0 flags 80",               /*BSEG must be just before BITS*/
+               "A BSEG_BYTES size 0 flags 0",  /*Size will be obtained from BSEG in lnkarea()*/
+               "A DSEG size 0 flags 0",
+               "A OSEG size 0 flags 4",
+               "A ISEG size 0 flags 0",
+               "A SSEG size 0 flags 4",
+               ""
+       };
        int j;
 
-       for (j=0; rel[j][0]!=0; j++)
-       {
-               ip=rel[j];
-               link_main();
-       }
+    if(packflag_and_stacksize)
+    {
+           for (j=0; rel2[j][0]!=0; j++)
+           {
+                   ip=rel2[j];
+                   link_main();
+           }
+    }
+    else
+    {
+           for (j=0; rel[j][0]!=0; j++)
+           {
+                   ip=rel[j];
+                   link_main();
+           }
+    }
        
        /*Set the start address of the default areas:*/
        for(ap=areap; ap; ap=ap->a_ap)
@@ -105,6 +133,10 @@ void Areas51 (void)
                else if (!strcmp(ap->a_id, "REG_BANK_2")) { ap->a_addr=0x10; ap->a_type=1; }
                else if (!strcmp(ap->a_id, "REG_BANK_3")) { ap->a_addr=0x18; ap->a_type=1; }
                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;
+        }
        }
 }
 
@@ -308,7 +340,10 @@ char *argv[];
                        /*
                         * Link all area addresses.
                         */
-                       lnkarea();
+                       if(!packflag_and_stacksize)
+                lnkarea();
+            else
+                lnkarea2();
                        /*
                         * Process global definitions.
                         */
@@ -335,9 +370,18 @@ char *argv[];
                                map();
 
                        if (sflag) /*JCF: memory usage summary output*/
-                               if(summary(areap))lkexit(1);
+            {
+                if(!packflag_and_stacksize)
+                {
+                                   if(summary(areap)) lkexit(1);
+                }
+                else
+                {
+                                   if(summary2(areap)) lkexit(1);
+                }
+            }
 
-                       if (iram_size)
+                       if ((iram_size) && (!packflag_and_stacksize))
                                iramcheck();
 
                        /*
@@ -776,10 +820,15 @@ parse()
                                        break;
 
                                case 'y': /*JCF: memory usage summary output*/
-                               case 'Y':
                                        ++sflag;
                                        break;
 
+                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;
+                    break;
+
                                case 'j':
                                case 'J':
                                        jflag = 1;
@@ -858,7 +907,7 @@ parse()
                                        return(0);
 
                                case 'z':
-                                case 'Z':
+                case 'Z':
                                        dflag = 1;                                      
                                        return(0);
                                default:
@@ -1310,13 +1359,15 @@ char *usetxt[] = {
        "  -i   Intel Hex as file[IHX]",
        "  -s   Motorola S19 as file[S19]",
        "  -j   Produce NoICE debug as file[NOI]",
-       "  -z   Produce SDCdb debug as file[cdb]",
+       "  -z   Produce SDCdb debug as file[cdb]",
 /*     "List:", */
        "  -u   Update listing file(s) with link data as file(s)[.RST]",
        "Miscellaneous:\n"
        "  -a   [iram-size] Check for internal RAM overflow",
        "  -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",
        "End:",
        "  -e   or null line terminates input",
        0