* src/mcs51/ralloc.c (getRegPtr, getRegGpr),
[fw/sdcc] / as / mcs51 / lkmain.c
index 842bcb33f8427e0e7a288c9dd0922cb1800e6e44..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 (iram_size)
+            {
+                if(!packflag_and_stacksize)
+                {
+                                   if(summary(areap)) lkexit(1);
+                }
+                else
+                {
+                                   if(summary2(areap)) lkexit(1);
+                }
+            }
+
+                       if ((iram_size) && (!packflag_and_stacksize))
                                iramcheck();
 
                        /*
@@ -465,6 +509,29 @@ link_main()
        if ((c=endline()) == 0) { return; }
        switch (c) {
 
+    case 'O': /*For some important sdcc options*/
+        if (pass == 0)
+        {
+            if(strlen(sdccopt)==0)
+            {
+                strcpy(sdccopt, &ip[1]);
+                strcpy(sdccopt_module, curr_module);
+            }
+            else
+            {
+                if(strcmp(sdccopt, &ip[1])!=0)
+                {
+                                   fprintf(stderr,
+                                   "?ASlink-Warning-Conflicting sdcc options:\n"
+                    "   \"%s\" in module \"%s\" and\n"
+                    "   \"%s\" in module \"%s\".\n",
+                    sdccopt, sdccopt_module, &ip[1], curr_module);
+                                   lkerr++;
+                }
+            }
+        }
+               break;
+
        case 'X':
                radix = 16;
                break;
@@ -494,7 +561,10 @@ link_main()
 
        case 'M':
                if (pass == 0)
+        {
+            strcpy(curr_module, &ip[1]);
                        module();
+        }
                break;
 
        case 'A':
@@ -750,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;
@@ -832,7 +907,7 @@ parse()
                                        return(0);
 
                                case 'z':
-                                case 'Z':
+                case 'Z':
                                        dflag = 1;                                      
                                        return(0);
                                default:
@@ -1284,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