Added ASlink-Warning to messages
[fw/sdcc] / as / mcs51 / lkmain.c
index 66464a45b2c880f69cfaf1129bb5f24099732293..86e3357d81febf15eeb3f73192488ed3905eb974 100644 (file)
@@ -51,6 +51,40 @@ extern int unlink(const char *);
  *
  */
 
+/*JCF:         Creates some of the default areas so they are allocated in the right order.*/
+void Areas51 (void)
+{
+       char * rel[]={
+               "XH",
+               "H 7 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()*/
+               ""
+       };
+       int j;
+
+       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)
+       {
+               /**/ if (!strcmp(ap->a_id, "REG_BANK_0")) { ap->a_addr=0x00; ap->a_type=1; }
+               else if (!strcmp(ap->a_id, "REG_BANK_1")) { ap->a_addr=0x08; ap->a_type=1; }
+               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; }
+       }
+}
+
 /*)Function    VOID    main(argc,argv)
  *
  *             int     argc            number of command line arguments + 1
@@ -142,8 +176,6 @@ char *argv[];
        register char *p;
        register int c, i;
 
-       fprintf(stdout, "\n");
-
        startp = (struct lfile *) new (sizeof (struct lfile));
 
        pflag = 1;
@@ -212,7 +244,9 @@ char *argv[];
        syminit();
        
        if (dflag){
-           dfp = afile("temp", "cdb", 1);
+           //dfp = afile("temp", "cdb", 1);
+               SaveLinkedFilePath(linkp->f_idp); //Must be the first one... 
+               dfp = afile(linkp->f_idp,"cdb",1); //JCF: Nov 30, 2002
            if (dfp == NULL) 
                lkexit(1);
        }
@@ -223,6 +257,8 @@ char *argv[];
                filep = linkp;
                hp = NULL;
                radix = 10;
+               
+               Areas51(); /*JCF: Create the default 8051 areas in the right order*/
 
                while (getline()) {
                        ip = ib;
@@ -271,6 +307,9 @@ char *argv[];
                        if (mflag || jflag)
                                map();
 
+                       if (sflag) /*JCF: memory usage summary output*/
+                               if(summary(areap))lkexit(1);
+
                        if (iram_size)
                                iramcheck();
 
@@ -302,6 +341,9 @@ char *argv[];
                        reloc('E');
                }
        }
+       //JCF:
+       CreateAOMF51();
+
        lkexit(lkerr);
        return 0;
 }
@@ -341,14 +383,15 @@ int i;
        if (rfp != NULL) fclose(rfp);
        if (sfp != NULL) fclose(sfp);
        if (tfp != NULL) fclose(tfp);
-       if (dfp != NULL) {
+       if (dfp != NULL) fclose(dfp);
+       /*if (dfp != NULL)
            FILE *xfp = afile(linkp->f_idp,"cdb",1);
            dfp = freopen("temp.cdb","r",dfp);
            copyfile(xfp,dfp);
            fclose(xfp);
            fclose(dfp);
            unlink("temp.cdb");
-       }
+       }*/
        exit(i);
 }
 
@@ -676,6 +719,11 @@ parse()
                                        ++mflag;
                                        break;
 
+                               case 'y': /*JCF: memory usage summary output*/
+                               case 'Y':
+                                       ++sflag;
+                                       break;
+
                                case 'j':
                                case 'J':
                                        jflag = 1;
@@ -743,6 +791,16 @@ parse()
                                        iramsav();
                                        return(0);
 
+                               case 'v':
+                               case 'V':
+                                       xramsav();
+                                       return(0);
+
+                               case 'w':
+                               case 'W':
+                                       codesav();
+                                       return(0);
+
                                case 'z':
                                 case 'Z':
                                        dflag = 1;                                      
@@ -871,14 +929,14 @@ setbas()
                        }
                        if (ap == NULL) {
                                fprintf(stderr,
-                               "No definition of area %s\n", id);
+                               "ASlink-Warning-No definition of area %s\n", id);
                                lkerr++;
                        } else {
                                ap->a_addr = v;
                                 ap->a_type = 1;        /* JLH: value set */
                        }
                } else {
-                       fprintf(stderr, "No '=' in base expression");
+                       fprintf(stderr, "ASlink-Warning-No '=' in base expression");
                        lkerr++;
                }
                bsp = bsp->b_base;
@@ -1045,14 +1103,14 @@ char *ft;
        register char *p1, *p2, *p3;
        register int c;
        FILE *fp;
-       char fb[FILSPC];
+       char fb[PATH_MAX];
        char *omode = (wf ? (wf == 2 ? "a" : "w") : "r");
 
        p1 = fn;
        p2 = fb;
        p3 = ft;
        while ((c = *p1++) != 0 && c != FSEPX) {
-               if (p2 < &fb[FILSPC-4])
+               if (p2 < &fb[PATH_MAX-4])
                        *p2++ = c;
        }
        *p2++ = FSEPX;
@@ -1064,12 +1122,12 @@ char *ft;
                }
        }
        while ((c = *p3++) != 0) {
-               if (p2 < &fb[FILSPC-1])
+               if (p2 < &fb[PATH_MAX-1])
                        *p2++ = c;
        }
        *p2++ = 0;      
        if ((fp = fopen(fb, omode)) == NULL) {
-           if (strcmp(ft,"cdb")) {
+           if (strcmp(ft,"adb")) {
                fprintf(stderr, "%s: cannot %s.\n", fb, wf?"create":"open");
                lkerr++;
            }
@@ -1113,6 +1171,29 @@ iramsav()
     iram_size = 128;           /* Default is 128 (0x80) bytes */
 }
 
+/*Similar to iramsav but for xram memory*/
+VOID
+xramsav()
+{
+  unget(getnb());
+  if (ip && *ip)
+    xram_size = expr(0);       /* evaluate size expression */
+  else
+       xram_size = rflag?0x1000000:0x10000;
+}
+
+/*Similar to iramsav but for code memory*/
+VOID
+codesav()
+{
+  unget(getnb());
+  if (ip && *ip)
+    code_size = expr(0);       /* evaluate size expression */
+  else
+       code_size = rflag?0x1000000:0x10000;
+}
+
+
 /*)Function    VOID    iramcheck()
  *
  *     The function iramcheck() is used at the end of linking to check that
@@ -1183,6 +1264,8 @@ char *usetxt[] = {
        "  -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",
        "End:",
        "  -e   or null line terminates input",
        0