* src/SDCCcflow.c (dfNumCompare): committed the wrong version of this
[fw/sdcc] / src / pic16 / device.c
index dab913ad8d2bc9a07bad82aad9d7cad93abaac13..fdf37ec6b1a74c6fdc280fa5c5f8f60874aaf83c 100644 (file)
@@ -35,6 +35,7 @@
 #include "newalloc.h"
 
 
+#include "main.h"
 #include "pcode.h"
 #include "ralloc.h"
 #include "device.h"
@@ -75,6 +76,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -93,6 +98,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -111,6 +120,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -129,6 +142,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -147,6 +164,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -165,6 +186,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -183,6 +208,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -201,6 +230,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -219,6 +252,32 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
+    }
+  },
+  {
+    {"p18f2220", "18f2220", "pic18f2220", "f2220"},
+    0,
+    0x200,     /* 512 */
+    0x80,
+    0,
+    { 0xf80, 0xfff },  /* PIC18F2220 range of SFR's */
+    {
+    /* PIC18F2220 configuration words */
+      0x300001,
+      0x30000d,
+      { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , 
+      { -1, 0, 0xff } /* 4 */  , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
+      { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
+      { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
+      { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -237,6 +296,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -255,6 +318,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -273,6 +340,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -291,6 +362,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -309,6 +384,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -327,6 +406,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -345,6 +428,10 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
   },
   {
@@ -363,17 +450,24 @@ static PIC16_device Pics16[] = {
       { -1, 0, 0xff } /* 7 */  , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
       { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , 
       { 0x40, 0, 0xff } /* d */  }
+    },
+    { 0x200000, 0x200007, 
+      { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
+        { 0, 0 }, { 0, 0 }, { 0, 0 } }
     }
-  },
+  }
 
 };
 
 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;
 unsigned int stackPos = 0;
+unsigned int stackLen = 0;
 
 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
 
@@ -408,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;
@@ -451,8 +564,9 @@ int symCompare(const void *a, const void *b)
 void pic16_dump_usection(FILE *of, set *section, int fix)
 {
   static int abs_usection_no=0;
+  static unsigned int usection_no=0;
   regs *r, *rprev;
-  int init_addr, i;
+  unsigned int init_addr, i;
   regs **rlist;
   regs *r1;
 
@@ -464,7 +578,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
        }
        
        if(!i) {
-               if(rlist)free(rlist);
+               if(rlist)Safe_free(rlist);
          return;
        }
 
@@ -472,12 +586,24 @@ 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, "\nudata_%s_%u\tudata\n", moduleName, usection_no++);
+                       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;
@@ -501,23 +627,45 @@ 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;
                }
        }
-       free(rlist);
+       Safe_free(rlist);
+}
+
+void pic16_dump_gsection(FILE *of, set *sections)
+{
+  regs *r;
+  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)) {
+#if 0
+                       fprintf(stderr, "%s:%d emitting variable %s for section %s (%p)\n", __FILE__, __LINE__,
+                               r->name, sname->name, sname);
+#endif
+                       fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
+               }
+       }
 }
 
 
 /* forward declaration */
 void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
+extern void pic16_pCodeConstString(char *name, char *value);
 
 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 */
@@ -528,7 +676,7 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
        }
        
        if(!i) {
-               if(slist)free(slist);
+               if(slist)Safe_free(slist);
          return;
        }
 
@@ -540,12 +688,25 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
        if(!fix) {
                fprintf(of, "\n\n\tidata\n");
                for(s = setFirstItem(section); s; s = setNextItem(section)) {
-                       fprintf(of, "%s", s->rname);
-                       pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
-                       pic16_flushDB('f', (void *)of);
+
+                       if(s->ival) {
+                               fprintf(of, "%s", s->rname);
+                               pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
+                               pic16_flushDB('f', (void *)of);
+                       } else {
+                               if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
+                                       && SPEC_CVAL (s->etype).v_char) {
+
+//                                     fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
+                                       pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
+                               } else {
+                                       assert(0);
+                               }
+                       }
+                               
                }
        } else {
-         int j=0;
+         unsigned int j=0;
          symbol *s1;
          
                sprev = NULL;
@@ -562,14 +723,26 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
                                fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
                        }
 
-                       fprintf(of, "%s", s->rname);
-                       pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
-                       pic16_flushDB('f', (void *)of);
+                       if(s->ival) {
+                               fprintf(of, "%s", s->rname);
+                               pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
+                               pic16_flushDB('f', (void *)of);
+                       } else {
+                               if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
+                                       && SPEC_CVAL (s->etype).v_char) {
+
+//                                     fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
+                                       pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
+                               } else {
+                                       assert(0);
+                               }
+                       }
+
 
                        sprev = s;
                }
        }
-       free(slist);
+       Safe_free(slist);
 }
 
 
@@ -590,17 +763,19 @@ void pic16_dump_int_registers(FILE *of, set *section)
        qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare);
        
        if(!i) {
-               if(rlist)free(rlist);
+               if(rlist)Safe_free(rlist);
          return;
        }
        
        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);
+       Safe_free(rlist);
 }
 
 
@@ -748,6 +923,8 @@ int checkAddReg(set **set, regs *reg)
 {
   regs *tmp;
 
+
+       if(!reg)return 0;
 #if DEBUG_CHECK
        fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
 #endif
@@ -774,6 +951,7 @@ int checkAddSym(set **set, symbol *sym)
 {
   symbol *tmp;
 
+       if(!sym)return 0;
 #if DEBUG_CHECK
        fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
 #endif
@@ -797,6 +975,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   *
@@ -805,13 +1010,18 @@ int checkAddSym(set **set, symbol *sym)
 void pic16_groupRegistersInSection(set *regset)
 {
   regs *reg;
+  sectSym *ssym;
+  int docontinue=0;
 
        for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
 
-//             fprintf(stderr, "%s:%d group registers in section, reg: %s\n", __FILE__, __LINE__, reg->name);
-
-               if(reg->wasUsed
-                       && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) {
+#if 0
+               fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n",
+                       __FILE__, __LINE__, reg->name, reg->wasUsed, reg);
+#endif
+               if((reg->wasUsed
+                       && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop))))
+                 ) {
                        
                        /* avoid grouping registers that have an initial value,
                         * they will be added later in idataSymSet */
@@ -819,11 +1029,33 @@ void pic16_groupRegistersInSection(set *regset)
                                continue;
 
 #if 0
-                       fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i\n",
+                       fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i code=%i\n",
                                __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed,
                                        (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1),
-                                       (reg->regop?(OP_SYMBOL(reg->regop)->level):-1) );
+                                       (reg->regop?(OP_SYMBOL(reg->regop)->level):-1),
+                                       (reg->regop?(IS_CODE(OP_SYM_ETYPE(reg->regop))):-1) );
 #endif
+                       
+                       docontinue=0;
+                       for(ssym=setFirstItem(sectSyms);ssym;ssym=setNextItem(sectSyms)) {
+                               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);
+                                       if(strcmp(ssym->section->name, "access")) {
+                                               addSet(&ssym->section->regsSet, reg);
+                                               docontinue=1;
+                                               break;
+                                       } else {
+                                               docontinue=0;
+                                               reg->accessBank = 1;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if(docontinue)continue;
+
+//                     fprintf(stderr, "%s:%d reg: %s\n", __FILE__, __LINE__, reg->name);
 
                        if(reg->alias == 0x80) {
                                checkAddReg(&pic16_equ_data, reg);
@@ -834,8 +1066,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);
+                               }
                        }
                }
        }
@@ -853,14 +1090,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;
@@ -868,3 +1117,14 @@ void pic16_assignConfigWordValue(int address, int value)
         }
 }
 
+void pic16_assignIdByteValue(int address, char value)
+{
+  int i;
+
+       for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) {
+               if(address == pic16->idInfo.idAddrStart+i) {
+                       pic16->idInfo.irInfo[i].value = value;
+                       pic16->idInfo.irInfo[i].emit = 1;
+               }
+       }
+}