2004-11-04 Vangelis Rokas <vrokas AT otenet.gr>
[fw/sdcc] / src / pic16 / device.c
index bbc2302323b41f4630ed7d6542044a83aa00c827..9420f969fc3feb439416df66f214cc1062c7e57e 100644 (file)
@@ -461,6 +461,8 @@ static PIC16_device Pics16[] = {
 
 static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
 
+stats_t statistics = { 0, 0, 0, 0 };
+
 #define DEFAULT_PIC "452"
 
 PIC16_device *pic16=NULL;
@@ -500,6 +502,25 @@ void pic16_dump_equates(FILE *of, set *equs)
 }
 
 
+void pic16_dump_access(FILE *of, set *section)
+{
+  regs *r;
+
+       r = setFirstItem(section);
+       if(!r)return;
+       
+       fprintf(of, "%s", iComments2);
+       fprintf(of, ";\tAccess bank symbols\n");
+       fprintf(of, "%s", iComments2);
+       
+       fprintf(of, "\tudata_acs\n");
+       for(; r; r = setNextItem(section)) {
+               fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+               statistics.adsize += r->size;
+       }
+}
+
+
 int regCompare(const void *a, const void *b)
 {
   const regs *const *i = a;
@@ -544,7 +565,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
 {
   static int abs_usection_no=0;
   regs *r, *rprev;
-  int init_addr, i;
+  unsigned int init_addr, i;
   regs **rlist;
   regs *r1;
 
@@ -564,12 +585,23 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
        qsort(rlist, i  /*elementsInSet(section)*/, sizeof(regs *), regCompare);
        
        if(!fix) {
+
+#define EMIT_SINGLE_UDATA_SECTION      0
+#if EMIT_SINGLE_UDATA_SECTION
                fprintf(of, "\n\n\tudata\n");
                for(r = setFirstItem(section); r; r = setNextItem(section)) {
                        fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
                }
+#else
+               for(r = setFirstItem(section); r; r = setNextItem(section)) {
+                       fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name);
+                       fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
+               }
+#endif
        } else {
-         int j=0;
+         unsigned int j=0;
          int deb_addr=0;
 
                rprev = NULL;
@@ -593,6 +625,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
                        } else {
                                fprintf(of, "%s\tres\t%d\n", r->name, r->size);
                                deb_addr += r->size;
+                               statistics.udsize += r->size;
                        }
                        
                        rprev = r;
@@ -607,6 +640,7 @@ void pic16_dump_gsection(FILE *of, set *sections)
   sectName *sname;
 
        for(sname = setFirstItem(sections); sname; sname = setNextItem(sections)) {
+               if(!strcmp(sname->name, "access"))continue;
                fprintf(of, "\n\n%s\tudata\n", sname->name);
 
                for(r=setFirstItem(sname->regsSet); r; r=setNextItem(sname->regsSet)) {
@@ -615,6 +649,7 @@ void pic16_dump_gsection(FILE *of, set *sections)
                                r->name, sname->name, sname);
 #endif
                        fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
                }
        }
 }
@@ -628,7 +663,7 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
 {
   static int abs_isection_no=0;
   symbol *s, *sprev;
-  int init_addr, i;
+  unsigned int init_addr, i;
   symbol **slist;
 
        /* put all symbols in an array */
@@ -669,7 +704,7 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
                                
                }
        } else {
-         int j=0;
+         unsigned int j=0;
          symbol *s1;
          
                sprev = NULL;
@@ -733,8 +768,10 @@ void pic16_dump_int_registers(FILE *of, set *section)
        fprintf(of, "\n\n; Internal registers\n");
        
        fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers");
-       for(r = setFirstItem(section); r; r = setNextItem(section))
+       for(r = setFirstItem(section); r; r = setNextItem(section)) {
                fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+               statistics.intsize += r->size;
+       }
 
        free(rlist);
 }
@@ -936,6 +973,33 @@ int checkAddSym(set **set, symbol *sym)
   return 0;
 }
 
+int checkSym(set *set, symbol *sym)
+{
+  symbol *tmp;
+
+       if(!sym)return 0;
+       
+#if DEUG_CHECK
+       fprintf(stderr, "%s: about to search for SYMbol: %s ... ", __FUNCTION__, sym->name);
+#endif
+
+       for(tmp = setFirstItem( set ); tmp; tmp = setNextItem( set )) {
+               if(!strcmp(tmp->name, sym->name))break;
+       }
+       
+       if(!tmp) {
+#if DEBUG_CHECK
+               fprintf(stderr, "not found\n");
+#endif
+               return 0;
+       }
+
+#if DEBUG_CHECK
+       fprintf(stderr, "found\n");
+#endif
+
+  return 1;
+}
 
 /*-----------------------------------------------------------------*
  * void pic16_groupRegistersInSection - add each register to its   *
@@ -975,8 +1039,15 @@ void pic16_groupRegistersInSection(set *regset)
                                if(!strcmp(ssym->name, reg->name)) {
 //                                     fprintf(stderr, "%s:%d section found %s (%p) with var %s\n",
 //                                                     __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name);
-                                       addSet(&ssym->section->regsSet, reg);
-                                       docontinue=1;
+                                       if(strcmp(ssym->section->name, "access")) {
+                                               addSet(&ssym->section->regsSet, reg);
+                                               docontinue=1;
+                                               break;
+                                       } else {
+                                               docontinue=0;
+                                               reg->accessBank = 1;
+                                               break;
+                                       }
                                }
                        }
 
@@ -993,8 +1064,13 @@ void pic16_groupRegistersInSection(set *regset)
                        if(!reg->isFixed) {
                                if(reg->pc_type == PO_GPR_TEMP)
                                        checkAddReg(&pic16_int_regs, reg);
-                               else
-                                       checkAddReg(&pic16_rel_udata, reg);
+                               else {
+                                       if(reg->accessBank) {
+                                               if(reg->alias != 0x40)
+                                                       checkAddReg(&pic16_acs_udata, reg);
+                                       } else
+                                               checkAddReg(&pic16_rel_udata, reg);
+                               }
                        }
                }
        }
@@ -1012,14 +1088,26 @@ void pic16_groupRegistersInSection(set *regset)
  * This routine will assign a value to that address.
  *
  *-----------------------------------------------------------------*/
-void pic16_assignConfigWordValue(int address, int value)
+void pic16_assignConfigWordValue(int address, unsigned int value)
 {
   int i;
 
         for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) {
                 if((address == pic16->cwInfo.confAddrStart+i)
                   && (pic16->cwInfo.crInfo[i].mask != -1)) {
-//                        fprintf(stderr, "setting location 0x%X to value 0x%x\n", /*address*/ pic16->cwInfo.confAddrStart+i, val
+
+#if 0
+                        fprintf(stderr, "setting location 0x%X to value 0x%x\tmask: 0x%x\ttest: 0x%x\n",
+                               /*address*/ pic16->cwInfo.confAddrStart+i, (~value)&0xff,
+                                       pic16->cwInfo.crInfo[i].mask,
+                                       (pic16->cwInfo.crInfo[i].mask) & (~value));
+#endif
+
+                       if((((pic16->cwInfo.crInfo[i].mask) & (~value))&0xff) != ((~value)&0xff)) {
+                               fprintf(stderr, "%s:%d a wrong value has been given for configuration register 0x%x\n",
+                                       __FILE__, __LINE__, address);
+                                       return;
+                       }
                         pic16->cwInfo.crInfo[i].value = value;
                         pic16->cwInfo.crInfo[i].emit = 1;
                         return;