* src/SDCCmain.c (linkEdit): modifications only for pic16 port,
[fw/sdcc] / src / pic16 / glue.c
index 2cc5b0dcaa6ebccd15a261be5522cf712747bc45..d92db723a0c14a7db1372b63935921910e61b88a 100644 (file)
@@ -132,17 +132,14 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
        for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) {
 
 #if 0
-               fprintf(stderr, "\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\taggregate: %d\n",
+               fprintf(stderr, "%s\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\taggregate: %d\n",
+                       __FUNCTION__,
                        map->sname, sym->name, sym->used, IS_EXTERN(sym->etype), IS_STATIC(sym->etype),
                        IS_AGGREGATE(sym->type));
                printTypeChain( sym->type, stderr );
                fprintf(stderr, "\n");
 #endif
 
-//             if(PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))
-//                     continue;
-
-
                /* if extern then add to externs */
                if (IS_EXTERN (sym->etype)) {
                        checkAddSym(&externs, sym);
@@ -188,7 +185,19 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 #endif
 
                                reg = pic16_allocDirReg( operandFromSymbol( sym ));
-                               checkAddReg(&pic16_rel_udata, reg);
+                               
+                               {
+                                 sectSym *ssym;
+                                 int found=0;
+                                 
+#if 1
+                                       for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
+                                               if(!strcmp(ssym->name, reg->name))found=1;
+                                       }
+#endif
+
+                                       if(!found)checkAddReg(&pic16_rel_udata, reg);
+                               }
                        }
 
                /* if extern then do nothing or is a function
@@ -277,10 +286,28 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                                        } else {
                                                reg = pic16_allocDirReg( operandFromSymbol( sym ) );
                                        }
-                                       if(checkAddReg(&pic16_rel_udata, reg)) {
-                                               addSetHead(&publics, sym);
+
+                                       {
+                                         sectSym *ssym;
+                                         int found=0;
+                                 
+#if 1
+                                               for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
+                                                       if(!strcmp(ssym->name, reg->name))found=1;
+                                               }
+#endif
+
+                                               if(!found)
+                                                       if(checkAddReg(&pic16_rel_udata, reg)) {
+                                                               addSetHead(&publics, sym);
+                                                       }
+
                                        }
+
+
+               
                                } else
+
                                        addSetHead(&publics, sym);
                        }
 
@@ -366,7 +393,8 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
       return valCastLiteral(toType, 0.0);
   }
 
-  expr = list2expr (ilist);
+  expr = decorateType(resolveSymbols( list2expr (ilist) ), FALSE);
+//  expr = list2expr( ilist );
   
   if (!expr)
     goto wrong;
@@ -406,7 +434,7 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
     if (IS_AST_SYM_VALUE (expr->left)) {
       val = copyValue (AST_VALUE (expr->left));
       val->type = newLink (DECLARATOR);
-      if (SPEC_SCLS (expr->left->etype) == S_CODE) {
+      if(SPEC_SCLS (expr->left->etype) == S_CODE) {
         DCL_TYPE (val->type) = CPOINTER;
         DCL_PTR_CONST (val->type) = port->mem.code_ro;
       }
@@ -420,6 +448,7 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
         DCL_TYPE (val->type) = EEPPOINTER;
       else
         DCL_TYPE (val->type) = POINTER;
+
       val->type->next = expr->left->ftype;
       val->etype = getSpec (val->type);
       return val;
@@ -483,6 +512,7 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
     val->etype = getSpec (val->type);
     return val;
   }
+
  wrong:
   if (expr)
     werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
@@ -493,41 +523,6 @@ value *pic16_initPointer (initList * ilist, sym_link *toType)
 }
 
 
-/*-----------------------------------------------------------------*/
-/* return the generic pointer high byte for a given pointer type.  */
-/*-----------------------------------------------------------------*/
-int pic16_pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
-{
-  switch (p_type)
-    {
-    case IPOINTER:
-    case POINTER:
-       fprintf(stderr, "%s:%d pointer is IPOINTER/POINTER\n", __FILE__, __LINE__);
-      return GPTYPE_NEAR;
-    case GPOINTER:
-       fprintf(stderr, "%s:%d pointer is GPOINTER\n", __FILE__, __LINE__);
-      werror (E_CANNOT_USE_GENERIC_POINTER, 
-              iname ? iname : "<null>", 
-              oname ? oname : "<null>");
-      exit (1);
-    case FPOINTER:
-       fprintf(stderr, "%s:%d pointer is FPOINTER\n", __FILE__, __LINE__);
-      return GPTYPE_FAR;
-    case CPOINTER:
-       fprintf(stderr, "%s:%d pointer is CPOINTER\n", __FILE__, __LINE__);
-      return GPTYPE_CODE;
-    case PPOINTER:
-       fprintf(stderr, "%s:%d pointer is PPOINTER\n", __FILE__, __LINE__);
-      return GPTYPE_XSTACK;
-    default:
-      fprintf (stderr, "*** internal error: unknown pointer type %d in GPByte.\n",
-               p_type);
-      break;
-    }
-  return -1;
-}
-
-
 /*-----------------------------------------------------------------*/
 /* printPointerType - generates ival for pointer type              */
 /*-----------------------------------------------------------------*/
@@ -553,11 +548,18 @@ void pic16_printPointerType (const char *name, char ptype, void *p)
 /*-----------------------------------------------------------------*/
 /* printGPointerType - generates ival for generic pointer type     */
 /*-----------------------------------------------------------------*/
-void pic16_printGPointerType (const char *iname, const char *oname,
+void pic16_printGPointerType (const char *iname, const char *oname, const unsigned int itype,
                    const unsigned int type, char ptype, void *p)
 {
   _pic16_printPointerType (iname, ptype, p);
-  pic16_emitDB(pic16_pointerTypeToGPByte(type, iname, oname), ptype, p);
+
+  if(itype == FPOINTER || itype == CPOINTER) { // || itype == GPOINTER) {
+    char buf[256];
+
+       sprintf(buf, "UPPER(%s)", iname);
+       pic16_emitDS(buf, ptype, p);
+  }
+
   pic16_flushDB(ptype, p);
 }
 
@@ -572,7 +574,7 @@ pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype,
   value *val;
   unsigned long ulval;
 
-  //fprintf(stderr, "%s\n",__FUNCTION__);
+//  fprintf(stderr, "%s for symbol %s\n",__FUNCTION__, sym->rname);
 
   /* if initList is deep */
   if (ilist && ilist->type == INIT_DEEP)
@@ -780,6 +782,7 @@ void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *
   default:
        /* VR - only 1,2,4 size long can be handled???? Why? */
        fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
+       assert(0);
   }
   *sym = lsym;
   *ilist = lilist;
@@ -834,7 +837,7 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
      VR - Attempting to port this function to pic16 port - 8-Jun-2004
    */
 
-       fprintf(stderr, "%s\n",__FUNCTION__);
+//     fprintf(stderr, "%s\n",__FUNCTION__);
 
   size = getSize (type);
 
@@ -844,11 +847,11 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
         {
          pic16_emitDS(val->name, ptype, p);
         }
-      else if (size == FPTRSIZE)
+      else if (size == 2)
         {
           pic16_printPointerType (val->name, ptype, p);
         }
-      else if (size == GPTRSIZE)
+      else if (size == 3)
         {
           int type;
           if (IS_PTR (val->type)) {
@@ -860,12 +863,13 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
             // this is a literal string
             type=CPOINTER;
           }
-          pic16_printGPointerType(val->name, sym->name, type, ptype, p);
+          pic16_printGPointerType(val->name, sym->name, type, type, ptype, p);
         }
       else
         {
           fprintf (stderr, "*** internal error: unknown size in "
                    "printIvalCharPtr.\n");
+         assert(0);
         }
     }
   else
@@ -874,52 +878,26 @@ int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char pty
       switch (size)
         {
         case 1:
-         pic16_emitDS(aopLiteral(val, 0), ptype, p);
-//          tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
+         pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
           break;
         case 2:
-         pic16_emitDS(aopLiteral(val, 0), ptype, p);
-         pic16_emitDS(aopLiteral(val, 1), ptype, p);
-//            tfprintf (oFile, "\t.byte %s,%s\n",
-//                      aopLiteral (val, 0), aopLiteral (val, 1));
+         pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+         pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
           break;
         case 3:
-          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
-            // non-zero mcs51 generic pointer
-            werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
-          }
-
-         pic16_emitDS(aopLiteral(val, 0), ptype, p);
-         pic16_emitDS(aopLiteral(val, 1), ptype, p);
-         pic16_emitDS(aopLiteral(val, 2), ptype, p);
-         
-//          fprintf (oFile, "\t.byte %s,%s,%s\n",
-//                     aopLiteral (val, 0), 
-//                     aopLiteral (val, 1),
-//                    aopLiteral (val, 2));
+         pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+         pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
+         pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
           break;
 
-
-/* no 4 bytes size long for pic16 port */
-        case 4:
-          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
-            // non-zero ds390 generic pointer
-            werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
-          }
-
-//          fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
-//                     aopLiteral (val, 0), 
-//                     aopLiteral (val, 1), 
-//                     aopLiteral (val, 2),
-//                     aopLiteral (val, 3));
-          break;
         default:
           assert (0);
         }
     }
 
-  if (val->sym && val->sym->isstrlit && !isinSet(statsg->syms, val->sym)) {
-    addSet (&statsg->syms, val->sym);
+  if (val->sym && val->sym->isstrlit) {        // && !isinSet(statsg->syms, val->sym)) {
+       if(ptype == 'p' && !isinSet(statsg->syms, val->sym))addSet (&statsg->syms, val->sym);
+       else if(ptype == 'f' /*&& !isinSet(rel_idataSymSet, val->sym)*/)addSet(&rel_idataSymSet, val->sym);
   }
 
   return 1;
@@ -960,14 +938,11 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
     }
 
   /* now generate the name */
-  if (!val->sym)
-    {
+  if (!val->sym) {
       pic16_printPointerType (val->name, ptype, p);
-    }
-  else
-    {
+  } else {
       pic16_printPointerType (val->sym->rname, ptype, p);
-    }
+  }
 
   return;
 }
@@ -981,6 +956,11 @@ void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char p
   value *val;
   int size;
 
+#if 0
+       fprintf(stderr, "%s:%d initialising pointer: %s size: %d\n", __FILE__, __LINE__,
+               sym->rname, getSize(sym->type));
+#endif
+
   /* if deep then   */
   if (ilist && (ilist->type == INIT_DEEP))
     ilist = ilist->init.deep;
@@ -1013,23 +993,17 @@ void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char p
         {
         case 1:
             pic16_emitDB((unsigned int)floatFromVal(val) & 0xff, ptype, p);
-//            tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
             break;
         case 2:
             pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
             pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-//            tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
             break;
         case 3:
             pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
             pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-
-          if (IS_GENPTR (val->type))
-            pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
-          else if (IS_PTR (val->type))
-            pic16_emitDB(pic16_pointerTypeToGPByte(DCL_TYPE(val->type), NULL, NULL), ptype, p);
-          else
             pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
+        default:
+               assert(0);
         }
       return;
     }
@@ -1041,16 +1015,17 @@ void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char p
     {
       pic16_emitDS(val->name, ptype, p);
     }
-  else if (size == FPTRSIZE)
+  else if (size == 2)
     {
         pic16_printPointerType (val->name, ptype, p);
     }
-  else if (size == GPTRSIZE)
+  else if (size == 3)
     {
-      pic16_printGPointerType (val->name, sym->name,
+      pic16_printGPointerType (val->name, sym->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
                          (IS_PTR (val->type) ? DCL_TYPE (val->type) :
                           PTR_TYPE (SPEC_OCLS (val->etype))), ptype, p);
-    }
+    } else
+       assert(0);
   return;
 }
 
@@ -1066,17 +1041,21 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
   if (!p)
     return;
 
-//     fprintf(stderr, "%s:%d generating init for %s\n", __FILE__, __LINE__, sym->name);
-
-  /* if structure then    */
+#if 0
+       fprintf(stderr, "%s:%d generating init for %s\n", __FILE__, __LINE__, sym->name);
+       fprintf(stderr, "%s: IS_STRUCT: %d  IS_ARRAY: %d  IS_PTR: %d  IS_SPEC: %d\n", sym->name,
+               IS_STRUCT(type), IS_ARRAY(type), IS_PTR(type), IS_SPEC(type));
+#endif
+       
+  /* if structure then */
   if (IS_STRUCT (type))
     {
-      fprintf(stderr,"%s struct\n",__FUNCTION__);
+//      fprintf(stderr,"%s struct\n",__FUNCTION__);
       pic16_printIvalStruct (sym, type, ilist, ptype, p);
       return;
     }
 
-  /* if this is an array   */
+  /* if this is an array */
   if (IS_ARRAY (type))
     {
 //     fprintf(stderr,"%s array\n",__FUNCTION__);
@@ -1098,7 +1077,7 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
         }
       }
 
-#if 1
+#if 0
       // and the type must match
       itype=ilist->init.node->ftype;
 
@@ -1120,7 +1099,7 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
   /* if this is a pointer */
   if (IS_PTR (type))
     {
-      fprintf(stderr,"%s pointer\n",__FUNCTION__);
+//      fprintf(stderr,"%s pointer\n",__FUNCTION__);
       pic16_printIvalPtr (sym, type, ilist, ptype, p);
       return;
     }
@@ -1137,10 +1116,21 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
 
 int PIC16_IS_CONFIG_ADDRESS(int address)
 {
+  return ((address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd));
+}
 
-  return (address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd);
+int PIC16_IS_IDLOC_ADDRESS(int address)
+{
+   return ((address >= pic16->idInfo.idAddrStart && address <= pic16->idInfo.idAddrEnd));
 }
 
+/* wrapper function for the above */
+int PIC16_IS_HWREG_ADDRESS(int address)
+{
+  return (PIC16_IS_CONFIG_ADDRESS(address) || PIC16_IS_IDLOC_ADDRESS(address));
+}
+
+
 /*-----------------------------------------------------------------*/
 /* emitStaticSeg - emitcode for the static segment                 */
 /*-----------------------------------------------------------------*/
@@ -1149,8 +1139,6 @@ pic16emitStaticSeg (memmap * map)
 {
   symbol *sym;
 
-  fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
-
   //fprintf(stderr, "%s\n",__FUNCTION__);
 
   pic16_initDB();
@@ -1161,8 +1149,8 @@ pic16emitStaticSeg (memmap * map)
     {
 
 #if 0
-       fprintf(stderr, "\t%s: sym: %s\tused: %d\tSPEC_ABSA: %d\tSPEC_AGGREGATE: %d\tCODE: %d\n\
-CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
+       fprintf(stderr, "%s\t%s: sym: %s\tused: %d\tSPEC_ABSA: %d\tSPEC_AGGREGATE: %d\tCODE: %d\n\
+CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n", __FUNCTION__,
                map->sname, sym->name, sym->used, SPEC_ABSA(sym->etype), IS_AGGREGATE(sym->type),
                IS_CODE(sym->etype), IN_CODESPACE( SPEC_OCLS(sym->etype)), IS_CONSTANT(sym->etype),
                IS_PTR_CONST(sym->etype), SPEC_CONST(sym->etype));
@@ -1171,20 +1159,22 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
 #endif
 
         if(SPEC_ABSA(sym->etype) && PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype))) {
-             
                pic16_assignConfigWordValue(SPEC_ADDR(sym->etype),
                        (int) floatFromVal(list2val(sym->ival)));
 
                continue;
         }
 
-       /* if it is "extern" then do nothing */
-       if (IS_EXTERN (sym->etype)) {
+        if(SPEC_ABSA(sym->etype) && PIC16_IS_IDLOC_ADDRESS(SPEC_ADDR(sym->etype))) {
+               pic16_assignIdByteValue(SPEC_ADDR(sym->etype),
+                       (char) floatFromVal(list2val(sym->ival)));
 
-               /* do not emit if it is a config word declaration */
-               if(!SPEC_ABSA(sym->etype)
-                       || (SPEC_ABSA(sym->etype) && !PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype))))
-                       checkAddSym(&externs, sym);
+               continue;
+        }
+
+       /* if it is "extern" then do nothing */
+       if (IS_EXTERN (sym->etype) && !SPEC_ABSA(sym->etype)) {
+               checkAddSym(&externs, sym);
          continue;
        }
 
@@ -1195,44 +1185,18 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
                checkAddSym(&publics, sym);
        }
 
-#if 0
       /* print extra debug info if required */
-      if (options.debug || sym->level == 0)
-       {
+      if (options.debug || sym->level == 0) {
          /* NOTE to me - cdbFile may be null in which case,
           * the sym name will be printed to stdout. oh well */
-         if(cdbFile)
-           cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
-         if (!sym->level)
-           {                   /* global */
-             if (IS_STATIC (sym->etype))
-               fprintf (code->oFile, "F%s_", moduleName);      /* scope is file */
-             else
-               fprintf (code->oFile, "G_");    /* scope is global */
-           }
-         else
-           /* symbol is local */
-           fprintf (code->oFile, "L%s_",
-                    (sym->localof ? sym->localof->name : "-null-"));
-         fprintf (code->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
-
-       }
-#endif
-
+          debugFile->writeSymbol(sym);
+      }
+        
       /* if it has an absolute address */
-      if (SPEC_ABSA (sym->etype))
-       {
-               fprintf(stderr, "%s:%d spec_absa is true for symbol: %s\n",
-                       __FILE__, __LINE__, sym->name);
+      if (SPEC_ABSA (sym->etype)) {
+//             fprintf(stderr, "%s:%d spec_absa is true for symbol: %s\n",
+//                     __FILE__, __LINE__, sym->name);
                        
-         if (options.debug || sym->level == 0)
-           fprintf (code->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
-
-         fprintf (code->oFile, "%s\t=\t0x%04x\n",
-                  sym->rname,
-                  SPEC_ADDR (sym->etype));
-
          /* if it has an initial value */
          if (sym->ival)
            {
@@ -1241,6 +1205,7 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
               absSym *abSym;
               pCode *pcf;
               
+              /* symbol has absolute address and initial value */
              noAlloc++;
              resolveIvalSym (sym->ival, sym->type);
              asym = newSymbol(sym->rname, 0);
@@ -1257,6 +1222,7 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
              
              pic16_addpCode2pBlock(pb,pcf);
              pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
+//           fprintf(stderr, "%s:%d [1] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
              pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
               pic16_flushDB('p', (void *)pb);
 
@@ -1266,57 +1232,61 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n",
          else
            {
 
+             /* symbol has absolute address but no initial value */
+             
              /* allocate space */
              fprintf (code->oFile, "%s:\n", sym->rname);
+
              /* special case for character strings */
              if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
-                 SPEC_CVAL (sym->etype).v_char)
+                 SPEC_CVAL (sym->etype).v_char) {
+
+//             fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, sym->rname);
+
                pic16_pCodeConstString(sym->rname , SPEC_CVAL (sym->etype).v_char);
-               /*printChar (code->oFile,
-                          SPEC_CVAL (sym->etype).v_char,
-                          strlen (SPEC_CVAL (sym->etype).v_char) + 1);*/
-             else
-               fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+             } else {
+               assert(0);
+             }
            }
   
        } else {
 //             fprintf(stderr, "%s:%d spec_absa is false for symbol: %s\n",
 //                     __FILE__, __LINE__, sym->name);
 
-         if (options.debug || sym->level == 0)
-           fprintf (code->oFile, " == .\n");
-
          /* if it has an initial value */
-         if (sym->ival)
-           {
+         if (sym->ival) {
              pBlock *pb;
 
+             /* symbol doesn't have absolute address but has initial value */
              fprintf (code->oFile, "%s:\n", sym->rname);
              noAlloc++;
              resolveIvalSym (sym->ival, sym->type);
 
              pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
              pic16_addpBlock(pb);
-             pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
 
+//           fprintf(stderr, "%s:%d [2] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
+
+             pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
              pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
               pic16_flushDB('p', (void *)pb);
              noAlloc--;
-           }
-         else
-           {
+           } else {
 
+             /* symbol doesn't have absolute address and no initial value */
              /* allocate space */
+//           fprintf(stderr, "%s:%d [3] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
              fprintf (code->oFile, "%s:\n", sym->rname);
              /* special case for character strings */
              if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
-                 SPEC_CVAL (sym->etype).v_char)
+                 SPEC_CVAL (sym->etype).v_char) {
+               
+//             fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, sym->rname);
+
                pic16_pCodeConstString(sym->rname , SPEC_CVAL (sym->etype).v_char);
-               /*printChar (code->oFile,
-                          SPEC_CVAL (sym->etype).v_char,
-                          strlen (SPEC_CVAL (sym->etype).v_char) + 1);*/
-             else
-               fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+             } else {
+               assert(0);
+             }
            }
        }
     }
@@ -1338,6 +1308,17 @@ void pic16_emitConfigRegs(FILE *of)
                                pic16->cwInfo.crInfo[i].value);
 }
 
+void pic16_emitIDRegs(FILE *of)
+{
+  int i;
+
+       for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart;i++)
+               if(pic16->idInfo.irInfo[i].emit)
+                       fprintf (of, "\t__idlocs 0x%06x, 0x%hhx\n",
+                               pic16->idInfo.idAddrStart+i,
+                               pic16->idInfo.irInfo[i].value);
+}
+
 
 static void
 pic16emitMaps ()
@@ -1372,8 +1353,7 @@ pic16createInterruptVect (FILE * vFile)
 
        if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
                fprintf (vFile, ";\t.area\t%s\n", CODE_NAME);
-               fprintf(vFile, ".intvecs\tcode\t0x0000\n");
-               fprintf (vFile, "__interrupt_vect:\n");
+               fprintf(vFile, ".intvecs\tcode\t0x%06x\n", pic16_options.ivt_loc);
 
                /* this is an overkill since WE are the port,
                 * and we know if we have a genIVT function! */
@@ -1481,6 +1461,7 @@ pic16emitOverlay (FILE * afile)
             and addPublics allowed then add it to the public set */
          if ((sym->_isparm && !IS_REGPARM (sym->etype))
              && !IS_STATIC (sym->etype)) {
+//           fprintf(stderr, "%s:%d %s accessed\n", __FILE__, __LINE__, __FUNCTION__);
              checkAddSym(&publics, sym);
 //         addSetHead (&publics, sym);
          }
@@ -1579,9 +1560,9 @@ pic16glue ()
 
                if(initsfpnt) {
                        pic16_addpCode2pBlock(pb, pic16_newpCode(POC_LFSR,
-                               pic16_popGetLit2(1, pic16_newpCodeOpRegFromStr("stack"))));
+                               pic16_popGetLit2(1, pic16_newpCodeOpRegFromStr("_stack"))));
                        pic16_addpCode2pBlock(pb, pic16_newpCode(POC_LFSR,
-                               pic16_popGetLit2(2, pic16_newpCodeOpRegFromStr("stack"))));
+                               pic16_popGetLit2(2, pic16_newpCodeOpRegFromStr("_stack"))));
                }
 
                /* put in the call to main */
@@ -1624,8 +1605,8 @@ pic16glue ()
        pic16emitOverlay(ovrFile);
        pic16_AnalyzepCode('*');
 
-#if 0
-       {
+#if 1
+       if(pic16_options.dumpcalltree) {
          FILE *cFile;
                sprintf(buffer, dstFileName);
                strcat(buffer, ".calltree");
@@ -1657,18 +1638,18 @@ pic16glue ()
     
        /* initial comments */
        pic16initialComments (asmFile);
-    
+
        /* print module name */
        fprintf(asmFile, "#FILE\t\"%s\"\n", fullSrcFileName);
-    
+
        /* Let the port generate any global directives, etc. */
        if (port->genAssemblerPreamble) {
                port->genAssemblerPreamble(asmFile);
        }
-    
+       
        /* print the extern variables to this module */
        pic16_printExterns(asmFile);
-  
+       
        /* print the global variables in this module */
        pic16printPublics (asmFile);
 
@@ -1679,42 +1660,11 @@ pic16glue ()
        fprintf (asmFile, "%s", iComments2);
        copyFile (asmFile, sfr->oFile);
 #endif
-    
 
        /* Put all variables into a cblock */
        pic16_AnalyzeBanking();
        pic16_writeUsedRegs(asmFile);
 
-#if 0
-       /* create the overlay segments */
-       fprintf (asmFile, "%s", iComments2);
-       fprintf (asmFile, "; overlayable items in internal ram \n");
-       fprintf (asmFile, "%s", iComments2);    
-       copyFile (asmFile, ovrFile);
-#endif
-
-#if 0
-
-       /* create the stack segment MOF */
-       if (mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf (asmFile, "%s", iComments2);
-               fprintf (asmFile, "; Stack segment in internal ram \n");
-               fprintf (asmFile, "%s", iComments2);    
-               fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
-                       ";__start__stack:\n;\t.ds\t1\n\n");
-       }
-#endif
-
-#if 0
-       /* no indirect data in pic */
-       /* create the idata segment */
-       fprintf (asmFile, "%s", iComments2);
-       fprintf (asmFile, "; indirectly addressable internal ram data\n");
-       fprintf (asmFile, "%s", iComments2);
-       copyFile (asmFile, idata->oFile);
-#endif
-
-
 #if 0
        /* no xdata in pic */
        /* if external stack then reserve space of it */