doc/sdccman.lyx: minor changes, mentioned beta vendor support for ds80c400
[fw/sdcc] / src / pic16 / glue.c
index f9728d6ce163bbaaa0d329330db92da4f343d09e..211c3822e5bcead403ced7bc2da7a84427ca9485 100644 (file)
@@ -1,6 +1,6 @@
 /*-------------------------------------------------------------------------
 
-  SDCCglue.c - glues everything we have done together into one file.
+  glue.c - glues everything we have done together into one file.
                 Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1998)
 
    This program is free software; you can redistribute it and/or modify it
 #include "ralloc.h"
 #include "pcode.h"
 #include "newalloc.h"
+#include "gen.h"
+#include "device.h"
+#include "main.h"
+#include <string.h>
+
+#include <string.h>
 
 
 #ifdef WORDS_BIGENDIAN
@@ -41,6 +47,7 @@ extern symbol *interrupts[256];
 static void printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb);
 extern int noAlloc;
 extern set *publics;
+extern set *externs;
 extern unsigned maxInterrupts;
 extern int maxRegBank;
 extern symbol *mainf;
@@ -52,6 +59,11 @@ extern char *iComments1;
 extern char *iComments2;
 //extern void emitStaticSeg (memmap * map);
 
+extern int initsfpnt;
+
+set *rel_idataSymSet=NULL;
+set *fix_idataSymSet=NULL;
+
 extern DEFSETFUNC (closeTmpFiles);
 extern DEFSETFUNC (rmTmpFiles);
 
@@ -63,8 +75,11 @@ extern void pic16_writeUsedRegs(FILE *);
 extern void initialComments (FILE * afile);
 extern void printPublics (FILE * afile);
 
-extern void printChar (FILE * ofile, char *s, int plen);
 void  pic16_pCodeInitRegisters(void);
+pCodeOp *pic16_popGetLit(unsigned int lit);
+pCodeOp *pic16_popGetLit2(unsigned int lit, pCodeOp *arg2);
+pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
+extern void pic16_pCodeConstString(char *name, char *value);
 
 /*-----------------------------------------------------------------*/
 /* aopLiteral - string from a literal value                        */
@@ -94,6 +109,10 @@ int pic16aopLiteral (value *val, int offset)
 
 }
 
+iCode *tic;
+symbol *nsym;
+char tbuffer[512], *tbuf=tbuffer;;
+
 
 /*-----------------------------------------------------------------*/
 /* emitRegularMap - emit code for maps with no special cases       */
@@ -102,109 +121,229 @@ static void
 pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 {
   symbol *sym;
-  int i, size, bitvars = 0;;
+//  int i, size, bitvars = 0;;
 
-  if (addPublics)
-    fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+//     fprintf(stderr, "%s:%d map name= %s\n", __FUNCTION__, __LINE__, map->sname);
+       
+       if(addPublics)
+               fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+               /* print the area name */
 
-  /* print the area name */
-  for (sym = setFirstItem (map->syms); sym;
-       sym = setNextItem (map->syms))
-    {
+       for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) {
 
-      /* if extern then do nothing */
-      if (IS_EXTERN (sym->etype))
-       continue;
-
-      /* if allocation required check is needed
-         then check if the symbol really requires
-         allocation only for local variables */
-      if (arFlag && !IS_AGGREGATE (sym->type) &&
-         !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
-         !sym->allocreq && sym->level)
-       continue;
-
-      /* if global variable & not static or extern
-         and addPublics allowed then add it to the public set */
-      if ((sym->level == 0 ||
-          (sym->_isparm && !IS_REGPARM (sym->etype))) &&
-         addPublics &&
-         !IS_STATIC (sym->etype))
-       addSetHead (&publics, sym);
-
-      /* if extern then do nothing or is a function
-         then do nothing */
-      if (IS_FUNC (sym->type))
-       continue;
 #if 0
-      /* print extra debug info if required */
-      if (options.debug || sym->level == 0)
-       {
+               fprintf(stderr, "\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\n",
+                       map->sname, sym->name, sym->used, IS_EXTERN(sym->etype), IS_STATIC(sym->etype));
+               printTypeChain( sym->type, stderr );
+               fprintf(stderr, "\n");
+#endif
 
-         cdbSymbol (sym, cdbFile, FALSE, FALSE);
+//             if(PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))
+//                     continue;
 
-         if (!sym->level)      /* global */
-           if (IS_STATIC (sym->etype))
-             fprintf (map->oFile, "F%s_", moduleName);         /* scope is file */
-           else
-             fprintf (map->oFile, "G_");       /* scope is global */
-         else
-           /* symbol is local */
-           fprintf (map->oFile, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
-         fprintf (map->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
-       }
+
+               /* if extern then add to externs */
+               if (IS_EXTERN (sym->etype)) {
+                       checkAddSym(&externs, sym);
+                       continue;
+               }
+               
+               /* if allocation required check is needed
+                *  then check if the symbol really requires
+                * allocation only for local variables */
+                if (arFlag && !IS_AGGREGATE (sym->type) &&
+                       !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
+                       !sym->allocreq && sym->level) {
+
+//                     fprintf(stderr, "%s:%d special case, continuing...\n", __FILE__, __LINE__);
+
+                       continue;
+               }
+
+               /* if global variable & not static or extern
+                * and addPublics allowed then add it to the public set */
+               if ((sym->used) && (sym->level == 0 ||
+                       (sym->_isparm && !IS_REGPARM (sym->etype))) &&
+                       addPublics &&
+                       !IS_STATIC (sym->etype) && !IS_FUNC(sym->type)) {
+                 
+                       checkAddSym(&publics, sym);
+//                     addSetHead(&publics, sym);
+               } else
+                       if(IS_STATIC(sym->etype)
+                               && !(sym->ival && !sym->level)
+                       ) {
+                         regs *reg;
+                               /* add it to udata list */
+
+//                             fprintf(stderr, "%s:%d adding %s (%s) remat=%d\n", __FILE__, __LINE__,
+//                                     sym->name, sym->rname, sym->remat);
+                                       
+                                               //, OP_SYMBOL(operandFromSymbol(sym))->name);
+#define SET_IMPLICIT   1
+
+#if SET_IMPLICIT
+                               if(IS_STRUCT(sym->type))
+                                       sym->implicit = 1;
 #endif
 
-      /* if is has an absolute address then generate
-         an equate for this no need to allocate space */
-      if (SPEC_ABSA (sym->etype))
-       {
-         //if (options.debug || sym->level == 0)
-         //fprintf (map->oFile,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
+                               reg = pic16_allocDirReg( operandFromSymbol( sym ));
+                               checkAddReg(&pic16_rel_udata, reg);
+                       }
+
+               /* if extern then do nothing or is a function
+                * then do nothing */
+               if (IS_FUNC (sym->type) && !IS_STATIC(sym->etype)) {
+                       if(SPEC_OCLS(sym->etype) == code) {
+//                             fprintf(stderr, "%s:%d: symbol added: %s\n", __FILE__, __LINE__, sym->rname);
+                               checkAddSym(&publics, sym);
+                       }
+                       continue;
+               }
 
-         fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
-                  sym->rname,
-                  SPEC_ADDR (sym->etype));
-       }
-      else
-       {
-         /* allocate space */
+#if 0
+               /* print extra debug info if required */
+               if (options.debug || sym->level == 0) {
+                       cdbWriteSymbol (sym);   //, cdbFile, FALSE, FALSE);
+
+                       if (!sym->level)        /* global */
+                               if (IS_STATIC (sym->etype))
+                                       fprintf (map->oFile, "F%s_", moduleName);               /* scope is file */
+                               else
+                                       fprintf (map->oFile, "G_");     /* scope is global */
+                       else
+                               /* symbol is local */
+                               fprintf (map->oFile, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
+                       fprintf (map->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
+               }
+#endif
 
-         /* If this is a bit variable, then allocate storage after 8 bits have been declared */
-         /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
-         /* by grouping the bits together into groups of 8 and storing them in the normal ram. */
-         if (IS_BITVAR (sym->etype))
-           {
-             bitvars++;
-           }
-         else
-           {
-             fprintf (map->oFile, "\t%s\n", sym->rname);
-             if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1)
-               {
-                 for (i = 1; i < size; i++)
-                   fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+
+               /* if is has an absolute address then generate
+               an equate for this no need to allocate space */
+               if (SPEC_ABSA (sym->etype)) {
+//                     if (options.debug || sym->level == 0)
+//                             fprintf (stderr,"; %s == 0x%04x\t\treqv= %p nRegs= %d\n",
+//                                     sym->name, SPEC_ADDR (sym->etype), sym->reqv, sym->regType);
+
+                       fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
+                               sym->rname,
+                               SPEC_ADDR (sym->etype));
+
+                       /* emit only if it is global */
+                       if(sym->level == 0) {
+                         regs *reg;
+
+                               reg = pic16_dirregWithName( sym->name );
+                               if(!reg) {
+                                       /* here */
+//                                     fprintf(stderr, "%s:%d: implicit add of symbol = %s\n",
+//                                                     __FUNCTION__, __LINE__, sym->name);
+
+                                       /* if IS_STRUCT is omitted the following
+                                        * fixes structures but break char/int etc */
+#if SET_IMPLICIT
+                                       if(IS_STRUCT(sym->type))
+                                               sym->implicit = 1;              // mark as implicit
+#endif
+                                       if(!sym->ival) {
+                                               reg = pic16_allocDirReg( operandFromSymbol(sym) );
+                                               if(reg) {
+                                                       if(checkAddReg(&pic16_fix_udata, reg)) {
+                                                               /* and add to globals list if not exist */
+                                                               addSet(&publics, sym);
+                                                       }
+                                               }
+                                       } else
+                                               addSet(&publics, sym);
+                               }
+                       }
+               } else {
+                       if(!sym->used && (sym->level == 0)) {
+                         regs *reg;
+
+                               /* symbol not used, just declared probably, but its in
+                                * level 0, so we must declare it fine as global */
+                               
+//                             fprintf(stderr, "EXTRA symbol declaration sym= %s\n", sym->name);
+
+#if SET_IMPLICIT
+                               if(IS_STRUCT(sym->type))
+                                       sym->implicit = 1;              // mark as implicit
+#endif
+                               if(!sym->ival) {
+                                       reg = pic16_allocDirReg( operandFromSymbol( sym ) );
+                                       if(checkAddReg(&pic16_rel_udata, reg)) {
+                                               addSetHead(&publics, sym);
+                                       }
+                               } else
+                                       addSetHead(&publics, sym);
+                       }
+
+#if 0
+                       /* allocate space */
+                       /* If this is a bit variable, then allocate storage after 8 bits have been declared */
+                       /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
+                       /* by grouping the bits together into groups of 8 and storing them in the normal ram. */
+                       if (IS_BITVAR (sym->etype)) {
+                               bitvars++;
+                       } else {
+                               fprintf (map->oFile, "\t%s\n", sym->rname);
+                               if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1) {
+                                       for (i = 1; i < size; i++)
+                                               fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+                               }
+                       }
+                       fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
+#endif
                }
-           }
-         //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
-       }
        
-       /* if it has a initial value then do it only if
-          it is a global variable */
-       if (sym->ival && sym->level == 0) {
-           ast *ival = NULL;
-           
-           if (IS_AGGREGATE (sym->type))
-               ival = initAggregates (sym, sym->ival, NULL);
-           else
-               ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
-                               decorateType (resolveSymbols (list2expr (sym->ival))));
-           codeOutFile = statsg->oFile;
-           GcurMemmap = statsg;
-           eBBlockFromiCode (iCodeFromAst (ival));
-           sym->ival = NULL;
+               /* FIXME -- VR Fix the following, so that syms to be placed
+                * in the idata section and let linker decide about their fate */
+
+               /* if it has an initial value then do it only if
+                       it is a global variable */
+
+               if (sym->ival && sym->level == 0) {
+                 ast *ival = NULL;
+
+#if 0
+                       if(SPEC_OCLS(sym->etype)==data) {
+                               fprintf(stderr, "%s: sym %s placed in data segment\n", map->sname, sym->name);
+                       }
+
+                       if(SPEC_OCLS(sym->etype)==code) {
+                               fprintf(stderr, "%s: sym %s placed in code segment\n", map->sname, sym->name);
+                       }
+#endif
+
+//                     fprintf(stderr, "'%s': sym '%s' has initial value\n", map->sname, sym->name);
+
+                       if (IS_AGGREGATE (sym->type)) {
+                               if(SPEC_ABSA(sym->etype))
+                                       addSet(&fix_idataSymSet, copySymbol(sym));
+                               else
+                                       addSet(&rel_idataSymSet, copySymbol(sym));
+//                             ival = initAggregates (sym, sym->ival, NULL);
+                       } else {
+                               if(SPEC_ABSA(sym->etype))
+                                       addSet(&fix_idataSymSet, copySymbol(sym));
+                               else
+                                       addSet(&rel_idataSymSet, copySymbol(sym));
+
+//                                     ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
+//                                             decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+                       }
+
+                       if(ival) {
+                               setAstLineno(ival, sym->lineDef);
+                               codeOutFile = statsg->oFile;
+                               GcurMemmap = statsg;
+                               eBBlockFromiCode (iCodeFromAst (ival));
+                               sym->ival = NULL;
+                       }
+               }
        }
-    }
 }
 
 
@@ -243,19 +382,26 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb)
 
   switch (getSize (type)) {
   case 1:
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
     break;
 
   case 2:
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); 
     break;
 
   case 4:
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2))));
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2))));
+    // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3))));
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); 
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); 
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,2)); 
+    pic16_emitDB(pb, BYTE_IN_LONG(ulval,3)); 
     break;
   }
 }
@@ -272,7 +418,7 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
   if(!pb)
     return 0;
 
-  fprintf(stderr, "%s\n",__FUNCTION__);
+  // fprintf(stderr, "%s\n",__FUNCTION__);
   if (!s)
     {
 
@@ -283,14 +429,20 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
          if (!DCL_ELEM (type))
            DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
 
-         //printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
-         //fprintf(stderr, "%s omitting call to printChar\n",__FUNCTION__);
-         pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";omitting call to printChar"));
+               for(remain=0; remain<DCL_ELEM(type); remain++)
+                       pic16_emitDB(pb, SPEC_CVAL(val->etype).v_char[ remain ]);
+                       
+//       pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";omitting call to printChar"));
 
          if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0)
-           while (remain--)
-             //tfprintf (oFile, "\t!db !constbyte\n", 0);
-             pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(0)));
+            {
+             while (remain--)
+                {
+                 //tfprintf (oFile, "\t!db !constbyte\n", 0);
+                 // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(0)));
+                  pic16_emitDB(pb,0);
+                }
+            }
          return 1;
        }
       else
@@ -299,10 +451,12 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
   else {
     //printChar (oFile, s, strlen (s) + 1);
 
-    for(remain=0; remain<strlen(s); remain++) {
-      pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(s[remain])));
-      //fprintf(stderr,"0x%02x ",s[remain]);
-    }
+    for(remain=0; remain<strlen(s); remain++) 
+      {
+        // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(s[remain])));
+        //fprintf(stderr,"0x%02x ",s[remain]);
+        pic16_emitDB(pb, s[remain]);
+      }
     //fprintf(stderr,"\n");
   }
   return 1;
@@ -321,15 +475,23 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
   if(!pb)
     return;
 
+
   /* take care of the special   case  */
   /* array of characters can be init  */
   /* by a string                      */
   if (IS_CHAR (type->next)) {
-    //fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
+    fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__);
     if (!IS_LITERAL(list2val(ilist)->etype)) {
       werror (W_INIT_WRONG);
       return;
     }
+
+       fprintf(stderr, "%s:%d adding %s to idata\n", __FILE__, __LINE__, sym->name);
+       if(SPEC_ABSA(sym->etype))
+               addSet(&fix_idataSymSet, copySymbol(sym));
+       else
+               addSet(&rel_idataSymSet, copySymbol(sym));
+
     if (printIvalChar (type,
                       (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
                       pb, SPEC_CVAL (sym->etype).v_char))
@@ -376,6 +538,8 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
   return;
 }
 
+
+
 /*-----------------------------------------------------------------*/
 /* printIval - generates code for initial value                    */
 /*-----------------------------------------------------------------*/
@@ -385,11 +549,16 @@ printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb)
   if (!ilist || !pb)
     return;
 
+//     fprintf(stderr, "%s:%d generating init for %s\n", __FILE__, __LINE__, sym->name);
+
   /* if structure then    */
   if (IS_STRUCT (type))
     {
       //fprintf(stderr,"%s struct\n",__FUNCTION__);
       //printIvalStruct (sym, type, ilist, oFile);
+       fprintf(stderr, "%s:%d: PIC16 port error: structure initialisation is not implemented yet.\n",
+               __FILE__, __LINE__);
+       abort();
       return;
     }
 
@@ -398,6 +567,9 @@ printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb)
     {
       //fprintf(stderr,"%s pointer\n",__FUNCTION__);
       //printIvalPtr (sym, type, ilist, oFile);
+       fprintf(stderr, "%s:%d: PIC16 port error: pointer initialisation is not implemented yet.\n",
+               __FILE__, __LINE__);
+       abort();
       return;
     }
 
@@ -418,7 +590,12 @@ printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb)
     }
 }
 
-extern void pic16_pCodeConstString(char *name, char *value);
+int PIC16_IS_CONFIG_ADDRESS(int address)
+{
+
+  return (address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd);
+}
+
 /*-----------------------------------------------------------------*/
 /* emitStaticSeg - emitcode for the static segment                 */
 /*-----------------------------------------------------------------*/
@@ -435,14 +612,38 @@ pic16emitStaticSeg (memmap * map)
   for (sym = setFirstItem (map->syms); sym;
        sym = setNextItem (map->syms))
     {
-      /* if it is "extern" then do nothing */
-      if (IS_EXTERN (sym->etype))
-       continue;
 
-      /* if it is not static add it to the public
-         table */
-      if (!IS_STATIC (sym->etype))
-       addSetHead (&publics, sym);
+#if 0
+       fprintf(stderr, "\t%s: sym: %s\tused: %d\n", map->sname, sym->name, sym->used);
+       printTypeChain( sym->type, stderr );
+       fprintf(stderr, "\n");
+#endif
+
+        if(SPEC_ABSA(sym->etype)
+             && (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)) {
+
+               /* 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 not static add it to the public
+          table */
+       if (!IS_STATIC (sym->etype)) {
+               /* do not emit if it is a config word declaration */
+               checkAddSym(&publics, sym);
+       }
 
 #if 0
       /* print extra debug info if required */
@@ -472,15 +673,66 @@ pic16emitStaticSeg (memmap * map)
       /* 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 (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));
-       }
-      else
-       {
+
+         /* if it has an initial value */
+         if (sym->ival)
+           {
+             pBlock *pb;
+              symbol *asym;
+              absSym *abSym;
+              pCode *pcf;
+              
+             noAlloc++;
+             resolveIvalSym (sym->ival, sym->type);
+             asym = newSymbol(sym->rname, 0);
+             abSym = Safe_calloc(1, sizeof(absSym));
+             abSym->name = Safe_strdup( sym->rname );
+             abSym->address = SPEC_ADDR( sym->etype );
+             addSet(&absSymSet, abSym);
+             
+             pb = pic16_newpCodeChain(NULL, 'A',pic16_newpCodeCharP("; Starting pCode block for absolute Ival"));
+             pic16_addpBlock(pb);
+
+             pcf = pic16_newpCodeFunction(moduleName, asym->name);
+             PCF(pcf)->absblock = 1;
+             
+             pic16_addpCode2pBlock(pb,pcf);
+             pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
+             printIval (sym, sym->type, sym->ival, pb);
+              pic16_flushDB(pb);
+
+             pic16_addpCode2pBlock(pb, pic16_newpCodeFunction(NULL, NULL));
+             noAlloc--;
+           }
+         else
+           {
+
+             /* 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)
+               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 {
+//             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");
 
@@ -491,13 +743,14 @@ pic16emitStaticSeg (memmap * map)
 
              fprintf (code->oFile, "%s:\n", sym->rname);
              noAlloc++;
-             resolveIvalSym (sym->ival);
+             resolveIvalSym (sym->ival, sym->type);
              //printIval (sym, sym->type, sym->ival, code->oFile);
              pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
              pic16_addpBlock(pb);
              pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
 
              printIval (sym, sym->type, sym->ival, pb);
+              pic16_flushDB(pb);
              noAlloc--;
            }
          else
@@ -522,8 +775,20 @@ pic16emitStaticSeg (memmap * map)
 
 
 /*-----------------------------------------------------------------*/
-/* emitMaps - emits the code for the data portion the code         */
+/* pic16_emitConfigRegs - emits the configuration registers              */
 /*-----------------------------------------------------------------*/
+void pic16_emitConfigRegs(FILE *of)
+{
+  int i;
+
+       for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart;i++)
+               if(pic16->cwInfo.crInfo[i].emit)        //mask != -1)
+                       fprintf (of, "\t__config 0x%x, 0x%hhx\n",
+                               pic16->cwInfo.confAddrStart+i,
+                               pic16->cwInfo.crInfo[i].value);
+}
+
+
 static void
 pic16emitMaps ()
 {
@@ -545,83 +810,77 @@ pic16emitMaps ()
 static void
 pic16createInterruptVect (FILE * vFile)
 {
-  unsigned i = 0;
-  mainf = newSymbol ("main", 0);
-  mainf->block = 0;
-
-  /* only if the main function exists */
-  if (!(mainf = findSymWithLevel (SymbolTab, mainf)))
-    {
-      if (!options.cc_only)
-       werror (E_NO_MAIN);
-      return;
-    }
-
-  /* if the main is only a prototype ie. no body then do nothing */
-  if (!IFFUNC_HASBODY(mainf->type))
-    {
-      /* if ! compile only then main function should be present */
-      if (!options.cc_only)
-       werror (E_NO_MAIN);
-      return;
-    }
-
-  fprintf (vFile, ";\t.area\t%s\n", CODE_NAME);
-  fprintf (vFile, ";__interrupt_vect:\n");
-
-
-  if (!port->genIVT || !(port->genIVT (vFile, interrupts, maxInterrupts)))
-    {
-      /* "generic" interrupt table header (if port doesn't specify one).
-
-       * Look suspiciously like 8051 code to me...
-       */
-
-      fprintf (vFile, ";\tljmp\t__sdcc_gsinit_startup\n");
+       /* if the main is only a prototype ie. no body then do nothing */
+#if 0
+       if (!IFFUNC_HASBODY(mainf->type)) {
+               /* if ! compile only then main function should be present */
+               if (!options.cc_only)
+                       werror (E_NO_MAIN);
+               return;
+       }
+#endif
 
+       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");
 
-      /* now for the other interrupts */
-      for (; i < maxInterrupts; i++)
-       {
-         if (interrupts[i])
-           fprintf (vFile, ";\tljmp\t%s\n;\t.ds\t5\n", interrupts[i]->rname);
-         else
-           fprintf (vFile, ";\treti\n;\t.ds\t7\n");
+               /* this is an overkill since WE are the port,
+                * and we know if we have a genIVT function! */
+               if(port->genIVT) {
+                       port->genIVT(vFile, interrupts, maxInterrupts);
+               }
        }
-    }
+       
 }
 
 
 /*-----------------------------------------------------------------*/
-/* initialComments - puts in some initial comments                 */
+/* pic16initialComments - puts in some initial comments            */
 /*-----------------------------------------------------------------*/
 static void
 pic16initialComments (FILE * afile)
 {
   initialComments (afile);
-  fprintf (afile, "; PIC port for the 16-bit core\n");
+  fprintf (afile, "; PIC16 port for the Microchip 16-bit core micros\n");
   fprintf (afile, iComments2);
 
 }
 
 /*-----------------------------------------------------------------*/
-/* printPublics - generates .global for publics                    */
+/* printPublics - generates global declarations for publics        */
 /*-----------------------------------------------------------------*/
 static void
-pic16printPublics (FILE * afile)
+pic16printPublics (FILE *afile)
 {
   symbol *sym;
 
-  fprintf (afile, "%s", iComments2);
-  fprintf (afile, "; publics variables in this module\n");
-  fprintf (afile, "%s", iComments2);
+       fprintf (afile, "%s", iComments2);
+       fprintf (afile, "; public variables in this module\n");
+       fprintf (afile, "%s", iComments2);
 
-  for (sym = setFirstItem (publics); sym;
-       sym = setNextItem (publics))
-    fprintf (afile, ";\t.globl %s\n", sym->rname);
+       for(sym = setFirstItem (publics); sym; sym = setNextItem (publics))
+               fprintf(afile, "\tglobal %s\n", sym->rname);
 }
 
+/*-----------------------------------------------------------------*/
+/* printExterns - generates extern declarations for externs        */
+/*-----------------------------------------------------------------*/
+static void
+pic16_printExterns(FILE *afile)
+{
+  symbol *sym;
+
+       fprintf(afile, "%s", iComments2);
+       fprintf(afile, "; extern variables in this module\n");
+       fprintf(afile, "%s", iComments2);
+       
+       for(sym = setFirstItem(externs); sym; sym = setNextItem(externs))
+               fprintf(afile, "\textern %s\n", sym->rname);
 
+       for(sym = setFirstItem(pic16_builtin_functions); sym; sym = setNextItem(pic16_builtin_functions))
+               fprintf(afile, "\textern _%s\n", sym->name);
+}
 
 /*-----------------------------------------------------------------*/
 /* emitOverlay - will emit code for the overlay stuff              */
@@ -671,8 +930,10 @@ pic16emitOverlay (FILE * afile)
          /* if global variable & not static or extern
             and addPublics allowed then add it to the public set */
          if ((sym->_isparm && !IS_REGPARM (sym->etype))
-             && !IS_STATIC (sym->etype))
-           addSetHead (&publics, sym);
+             && !IS_STATIC (sym->etype)) {
+             checkAddSym(&publics, sym);
+//         addSetHead (&publics, sym);
+         }
 
          /* if extern then do nothing or is a function
             then do nothing */
@@ -739,234 +1000,274 @@ pic16glue ()
   FILE *asmFile;
   FILE *ovrFile = tempfile();
 
-  addSetHead(&tmpfileSet,ovrFile);
-  pic16_pCodeInitRegisters();
 
-  if (mainf && IFFUNC_HASBODY(mainf->type)) {
+       mainf = newSymbol ("main", 0);
+       mainf->block = 0;
 
-    pBlock *pb = pic16_newpCodeChain(NULL,'X',pic16_newpCodeCharP("; Starting pCode block"));
-    pic16_addpBlock(pb);
+       mainf = findSymWithLevel(SymbolTab, mainf);
+#if 0
+       /* only if the main function exists */
+       if (!(mainf = findSymWithLevel (SymbolTab, mainf))) {
+               if (!options.cc_only)
+                       werror (E_NO_MAIN);
+               return;
+       }
+#endif
 
-    /* entry point @ start of CSEG */
-    pic16_addpCode2pBlock(pb,pic16_newpCodeLabel("__sdcc_program_startup",-1));
-    /* put in the call to main */
-    pic16_addpCode2pBlock(pb,pic16_newpCode(POC_CALL,pic16_newpCodeOp("_main",PO_STR)));
+//     fprintf(stderr, "main function= %p (%s)\thas body= %d\n", mainf, (mainf?mainf->name:NULL), mainf?IFFUNC_HASBODY(mainf->type):-1);
 
-    if (options.mainreturn) {
+       addSetHead(&tmpfileSet,ovrFile);
+       pic16_pCodeInitRegisters();
 
-      pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";\treturn from main will return to caller\n"));
-      pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETURN,NULL));
+       if (mainf && IFFUNC_HASBODY(mainf->type)) {
+         pBlock *pb = pic16_newpCodeChain(NULL,'X',pic16_newpCodeCharP("; Starting pCode block"));
 
-    } else {
+               pic16_addpBlock(pb);
 
-      pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";\treturn from main will lock up\n"));
-      pic16_addpCode2pBlock(pb,pic16_newpCode(POC_GOTO,pic16_newpCodeOp("$",PO_STR)));
+               /* entry point @ start of CSEG */
+               pic16_addpCode2pBlock(pb,pic16_newpCodeLabel("__sdcc_program_startup",-1));
 
-    }
-  }
+               if(initsfpnt) {
+                       pic16_addpCode2pBlock(pb, pic16_newpCode(POC_LFSR,
+                               pic16_popGetLit2(1, pic16_newpCodeOpRegFromStr("stack"))));
+                       pic16_addpCode2pBlock(pb, pic16_newpCode(POC_LFSR,
+                               pic16_popGetLit2(2, pic16_newpCodeOpRegFromStr("stack"))));
+               }
 
+               /* put in the call to main */
+               pic16_addpCode2pBlock(pb,pic16_newpCode(POC_CALL,pic16_newpCodeOp("_main",PO_STR)));
 
-  /* At this point we've got all the code in the form of pCode structures */
-  /* Now it needs to be rearranged into the order it should be placed in the */
-  /* code space */
+               if (options.mainreturn) {
+                       pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";\treturn from main will return to caller\n"));
+                       pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETURN,NULL));
+               } else {
+                       pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";\treturn from main will lock up\n"));
+                       pic16_addpCode2pBlock(pb,pic16_newpCode(POC_GOTO,pic16_newpCodeOp("$",PO_STR)));
+               }
+       }
 
-  pic16_movepBlock2Head('P');              // Last
-  pic16_movepBlock2Head(code->dbName);
-  pic16_movepBlock2Head('X');
-  pic16_movepBlock2Head(statsg->dbName);   // First
+       /* At this point we've got all the code in the form of pCode structures */
+       /* Now it needs to be rearranged into the order it should be placed in the */
+       /* code space */
 
+       pic16_movepBlock2Head('P');              // Last
+       pic16_movepBlock2Head(code->dbName);
+       pic16_movepBlock2Head('X');
+       pic16_movepBlock2Head(statsg->dbName);   // First
 
-  /* print the global struct definitions */
-  if (options.debug)
-    cdbStructBlock (0);        //,cdbFile);
+       /* print the global struct definitions */
+//     if (options.debug)
+//             cdbStructBlock (0);     //,cdbFile);
 
-  vFile = tempfile();
-  /* PENDING: this isnt the best place but it will do */
-  if (port->general.glue_up_main) {
-    /* create the interrupt vector table */
-    pic16createInterruptVect (vFile);
-  }
+       vFile = tempfile();
+       /* PENDING: this isnt the best place but it will do */
+       if (port->general.glue_up_main) {
+               /* create the interrupt vector table */
+               pic16createInterruptVect (vFile);
+       }
 
-  addSetHead(&tmpfileSet,vFile);
+       addSetHead(&tmpfileSet,vFile);
     
-  /* emit code for the all the variables declared */
-  pic16emitMaps ();
-  /* do the overlay segments */
-  pic16emitOverlay(ovrFile);
+       /* emit code for the all the variables declared */
+       pic16emitMaps ();
+       /* do the overlay segments */
+       pic16emitOverlay(ovrFile);
+       pic16_AnalyzepCode('*');
 
+#if 0
+       {
+         FILE *cFile;
+               sprintf(buffer, dstFileName);
+               strcat(buffer, ".calltree");
+               cFile = fopen(buffer, "w");
+               pic16_printCallTree( cFile );
+               fclose(cFile);
+       }
+#endif
 
-  pic16_AnalyzepCode('*');
-
-  //#ifdef PCODE_DEBUG
-  //pic16_printCallTree(stderr);
-  //#endif
-
-  pic16_InlinepCode();
-
-  pic16_AnalyzepCode('*');
-
-  pic16_pcode_test();
+       pic16_InlinepCode();
+       pic16_AnalyzepCode('*');
 
+       if(pic16_debug_verbose)
+               pic16_pcode_test();
 
-  /* now put it all together into the assembler file */
-  /* create the assembler file name */
-    
-  if ((noAssemble || options.c1mode)  && fullDstFileName)
-    {
-      sprintf (buffer, fullDstFileName);
-    }
-  else
-    {
-      sprintf (buffer, dstFileName);
-      strcat (buffer, ".asm");
-    }
+       /* now put it all together into the assembler file */
+       /* create the assembler file name */
+       if ((noAssemble || options.c1mode)  && fullDstFileName) {
+               sprintf (buffer, fullDstFileName);
+       } else {
+               sprintf (buffer, dstFileName);
+               strcat (buffer, ".asm");
+       }
 
-  if (!(asmFile = fopen (buffer, "w"))) {
-    werror (E_FILE_OPEN_ERR, buffer);
-    exit (1);
-  }
+       if (!(asmFile = fopen (buffer, "w"))) {
+               werror (E_FILE_OPEN_ERR, buffer);
+               exit (1);
+       }
     
-  /* initial comments */
-  pic16initialComments (asmFile);
+       /* initial comments */
+       pic16initialComments (asmFile);
     
-  /* print module name */
-  fprintf (asmFile, ";\t.module %s\n", moduleName);
+       /* 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 global variables in this module */
-  pic16printPublics (asmFile);
+       /* 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);
 
-  /* copy the sfr segment */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; special function registers\n");
-  fprintf (asmFile, "%s", iComments2);
-  copyFile (asmFile, sfr->oFile);
+#if 0
+       /* copy the sfr segment */
+       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "; special function registers\n");
+       fprintf (asmFile, "%s", iComments2);
+       copyFile (asmFile, sfr->oFile);
+#endif
     
 
-  /* Put all variables into a cblock */
-  pic16_AnalyzeBanking();
-  pic16_writeUsedRegs(asmFile);
-
-  /* create the overlay segments */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; overlayable items in internal ram \n");
-  fprintf (asmFile, "%s", iComments2);    
-  copyFile (asmFile, ovrFile);
-
-  /* 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");
-  }
+       /* Put all variables into a cblock */
+       pic16_AnalyzeBanking();
+       pic16_writeUsedRegs(asmFile);
 
-  /* create the idata segment */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; indirectly addressable internal ram data\n");
-  fprintf (asmFile, "%s", iComments2);
-  copyFile (asmFile, idata->oFile);
-    
-  /* if external stack then reserve space of it */
-  if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
-    fprintf (asmFile, "%s", iComments2);
-    fprintf (asmFile, "; external stack \n");
-    fprintf (asmFile, "%s", iComments2);
-    fprintf (asmFile,";\t.area XSEG (XDATA)\n"); /* MOF */
-    fprintf (asmFile,";\t.ds 256\n");
-  }
-       
-       
-  /* copy xtern ram data */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; external ram data\n");
-  fprintf (asmFile, "%s", iComments2);
-  copyFile (asmFile, xdata->oFile);
-    
+#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
 
-  /* copy the bit segment */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; bit data\n");
-  fprintf (asmFile, "%s", iComments2);
-  copyFile (asmFile, bit->oFile);
+#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
 
-  fprintf (asmFile, "\tORG 0\n");
 
-  /* copy the interrupt vector table */
-  if (mainf && IFFUNC_HASBODY(mainf->type)) {
-    fprintf (asmFile, "%s", iComments2);
-    fprintf (asmFile, "; interrupt vector \n");
-    fprintf (asmFile, "%s", iComments2);
-    copyFile (asmFile, vFile);
-  }
-    
-  /* copy global & static initialisations */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; global & static initialisations\n");
-  fprintf (asmFile, "%s", iComments2);
+#if 0
+       /* no xdata in pic */
+       /* if external stack then reserve space of it */
+       if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
+               fprintf (asmFile, "%s", iComments2);
+               fprintf (asmFile, "; external stack \n");
+               fprintf (asmFile, "%s", iComments2);
+               fprintf (asmFile,";\t.area XSEG (XDATA)\n"); /* MOF */
+               fprintf (asmFile,";\t.ds 256\n");
+       }
+#endif
+
+#if 0  
+       /* no xdata in pic */
+       /* copy xtern ram data */
+       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "; external ram data\n");
+       fprintf (asmFile, "%s", iComments2);
+       copyFile (asmFile, xdata->oFile);
+#endif
+
+#if 0
+       /* copy the bit segment */
+       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "; bit data\n");
+       fprintf (asmFile, "%s", iComments2);
+       copyFile (asmFile, bit->oFile);
+#endif
+
+       /* copy the interrupt vector table */
+       if(mainf && IFFUNC_HASBODY(mainf->type)) {
+               fprintf (asmFile, "%s", iComments2);
+               fprintf (asmFile, "; interrupt vector \n");
+               fprintf (asmFile, "%s", iComments2);
+               copyFile (asmFile, vFile);
+       }
     
-  /* Everywhere we generate a reference to the static_name area, 
-   * (which is currently only here), we immediately follow it with a 
-   * definition of the post_static_name area. This guarantees that
-   * the post_static_name area will immediately follow the static_name
-   * area.
-   */
-  fprintf (asmFile, ";\t.area %s\n", port->mem.static_name); /* MOF */
-  fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
-  fprintf (asmFile, ";\t.area %s\n", port->mem.static_name);
+       /* copy global & static initialisations */
+       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "; global & static initialisations\n");
+       fprintf (asmFile, "%s", iComments2);
     
-  if (mainf && IFFUNC_HASBODY(mainf->type)) {
-    fprintf (asmFile,"__sdcc_gsinit_startup:\n");
-    /* if external stack is specified then the
-       higher order byte of the xdatalocation is
-       going into P2 and the lower order going into
-       spx */
-    if (options.useXstack) {
-      fprintf(asmFile,";\tmov\tP2,#0x%02x\n",
-             (((unsigned int)options.xdata_loc) >> 8) & 0xff);
-      fprintf(asmFile,";\tmov\t_spx,#0x%02x\n",
-             (unsigned int)options.xdata_loc & 0xff);
-    }
+#if 0
+       /* copy over code */
+       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "\tcode\n");
+       fprintf (asmFile, "%s", iComments2);
+#endif
 
-  }
+       if(pic16_debug_verbose)
+               fprintf(asmFile, "; A code from now on!\n");
+       pic16_copypCode(asmFile, 'A');
 
-  if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type))
-    {
-      /* This code is generated in the post-static area.
-       * This area is guaranteed to follow the static area
-       * by the ugly shucking and jiving about 20 lines ago.
-       */
-      fprintf(asmFile, ";\t.area %s\n", port->mem.post_static_name);
-      fprintf (asmFile,";\tljmp\t__sdcc_program_startup\n");
-    }
+
+       if(mainf && IFFUNC_HASBODY(mainf->type)) {
+               fprintf(asmFile, "\tcode\n");
+               fprintf(asmFile,"__sdcc_gsinit_startup:\n");
+
+#if 0
+               /* FIXME 8051 legacy (?!) - VR 20-Jun-2003 */
+               /* if external stack is specified then the
+                * higher order byte of the xdatalocation is
+                * going into P2 and the lower order going into */
        
-  /* copy over code */
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; code\n");
-  fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, ";\t.area %s\n", port->mem.code_name);
+               if (options.useXstack) {
+                       fprintf(asmFile,";\tmov\tP2,#0x%02x\n",
+                                       (((unsigned int)options.xdata_loc) >> 8) & 0xff);
+                       fprintf(asmFile,";\tmov\t_spx,#0x%02x\n",
+                                       (unsigned int)options.xdata_loc & 0xff);
+               }
+#endif
+       }
+
+//     copyFile (stderr, code->oFile);
+
+       fprintf(asmFile, "; I code from now on!\n");
+       pic16_copypCode(asmFile, 'I');
+
+       if(pic16_debug_verbose)
+               fprintf(asmFile, "; dbName from now on!\n");
+       pic16_copypCode(asmFile, statsg->dbName);
+
+
+       if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) {
+               fprintf (asmFile,"\tgoto\t__sdcc_program_startup\n");
+       }
+       
+
+       if(pic16_debug_verbose)
+               fprintf(asmFile, "; X code from now on!\n");
+       pic16_copypCode(asmFile, 'X');
 
-  //copyFile (stderr, code->oFile);
+       if(pic16_debug_verbose)
+               fprintf(asmFile, "; M code from now on!\n");
+       pic16_copypCode(asmFile, 'M');
 
-  pic16_copypCode(asmFile, 'I');
-  pic16_copypCode(asmFile, statsg->dbName);
-  pic16_copypCode(asmFile, 'X');
-  pic16_copypCode(asmFile, 'M');
-  pic16_copypCode(asmFile, code->dbName);
-  pic16_copypCode(asmFile, 'P');
 
+       pic16_copypCode(asmFile, code->dbName);
 
-  fprintf (asmFile,"\tend\n");
+       pic16_copypCode(asmFile, 'P');
 
-  fclose (asmFile);
+       fprintf (asmFile,"\tend\n");
+       fclose (asmFile);
 
-  rm_tmpfiles();
+       rm_tmpfiles();
 }