EXEEXT introduces to solve Cygwin problems
[fw/sdcc] / as / mcs51 / lkarea.c
index cdc3c071f43079a3787e48dcba8335ab66aa1c2f..1d979b4fc25e3ac9e5e881fe16661b74055ff39b 100644 (file)
@@ -320,6 +320,9 @@ lnkarea()
        int  locIndex;
        char temp[NCPS];
        struct sym *sp;
+       /*JCF: used to save the REG_BANK_[0-3] and SBIT_BYTES area pointers*/
+       struct area *ta[5];
+       int j;
 
        rloc[0] = rloc[1] = rloc[2] = rloc[3] = 0;
        ap = areap;
@@ -375,6 +378,29 @@ lnkarea()
                        sp->s_type |= S_DEF;
 
                }
+               
+               /*JCF: Since area BSEG is defined just before BSEG_BYTES, use the bit size of BSEG
+               to compute the byte size of BSEG_BYTES: */
+               if (!strcmp(ap->a_id, "BSEG")) {
+                       ap->a_ap->a_axp->a_size=(ap->a_size+7)/8; /*Bits to bytes*/
+               }
+               else if (!strcmp(ap->a_id, "REG_BANK_0")) ta[0]=ap;
+               else if (!strcmp(ap->a_id, "REG_BANK_1")) ta[1]=ap;
+               else if (!strcmp(ap->a_id, "REG_BANK_2")) ta[2]=ap;
+               else if (!strcmp(ap->a_id, "REG_BANK_3")) ta[3]=ap;
+               else if (!strcmp(ap->a_id, "BSEG_BYTES"))
+               {
+                       ta[4]=ap;
+                       for(j=4; j>1; j--)
+                       {
+                               /*If upper register banks are not used roll back the rellocation counter*/
+                               if ( (ta[j]->a_size==0) && (ta[j-1]->a_size==0) )
+                               {
+                                       rloc[0]-=8;
+                               }
+                               else break;
+                       }
+               }
                ap = ap->a_ap;
        }
 }