* as/asx8051.dsp: added mcs51/strcmpi.h
[fw/sdcc] / src / pic16 / main.c
index a570358a684be58910c1f0cfe1c9ccf10b6ee5c5..c9515fbb23c18e202c063425956da6d63ccb6ccc 100644 (file)
@@ -43,41 +43,50 @@ static char _defaultRules[] =
 static char *_pic16_keywords[] =
 {
   "at",
-//  "bit",
   "code",
   "critical",
   "register",
   "data",
   "far",
-//  "idata",
   "interrupt",
   "near",
   "pdata",
   "reentrant",
   "sfr",
-//  "sbit",
   "using",
-//  "xdata",
   "_data",
   "_code",
   "_generic",
   "_near",
-//  "_xdata",
   "_pdata",
-//  "_idata",
   "_naked",
+  "shadowregs",
+  "wparam",
+  "prodlp",
+  "prodhp",
+  "fsr0lp",
+  "fixed16x16",
+  
+//  "bit",
+//  "idata",
+//  "sbit",
+//  "xdata",
+//  "_xdata",
+//  "_idata",
   NULL
 };
 
 
 pic16_sectioninfo_t pic16_sectioninfo;
 
+int xinst=0;
+
 
 extern char *pic16_processor_base_name(void);
 
 void  pic16_pCodeInitRegisters(void);
 
-void pic16_assignRegisters (eBBlock ** ebbs, int count);
+void pic16_assignRegisters (ebbIndex *);
 
 static int regParmFlg = 0;     /* determine if we can register a parameter */
 
@@ -91,7 +100,6 @@ extern set *libFilesSet;
 /* for an unknowned reason. - EEP */
 void pic16_emitDebuggerSymbol (char *);
  
-extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
 extern void pic16_emitConfigRegs(FILE *of);
 extern void pic16_emitIDRegs(FILE *of);
 
@@ -112,7 +120,7 @@ _pic16_reset_regparm (void)
 }
 
 static int
-_pic16_regparm (sym_link * l)
+_pic16_regparm (sym_link * l, bool reentrant)
 {
   /* force all parameters via SEND/RECEIVE */
   if(0 /*pic16_options.ip_stack*/) {
@@ -137,6 +145,12 @@ set *sectNames=NULL;                       /* list of section listed in pragma directives */
 set *sectSyms=NULL;                    /* list of symbols set in a specific section */
 set *wparamList=NULL;
 
+#if 0
+/* This is an experimental code for #pragma inline
+   and is temporarily disabled for 2.5.0 release */
+set *asmInlineMap=NULL;
+#endif  /* 0 */
+
 struct {
   unsigned ignore: 1;
   unsigned want_libc: 1;
@@ -151,190 +165,252 @@ _process_pragma(const char *sz)
 {
   static const char *WHITE = " \t\n";
   static const char *WHITECOMMA = " \t\n,";
+  char *ptr = strtok((char *)sz, WHITE);
+
+    /* #pragma maxram [maxram] */
+    if (startsWith (ptr, "maxram")) {
+      char *maxRAM = strtok((char *)NULL, WHITE);
+
+        if (maxRAM != (char *)NULL) {
+          int maxRAMaddress;
+          value *maxRAMVal;
+
+            maxRAMVal = constVal(maxRAM);
+            maxRAMaddress = (int)floatFromVal(maxRAMVal);
+            pic16_setMaxRAM(maxRAMaddress);
+        }
+
+        return 0;
+    }
   
-  char *ptr = strtok((char *)sz, WHITE);
+  /* #pragma stack [stack-position] [stack-len] */
+  if(startsWith(ptr, "stack")) {
+    char *stackPosS = strtok((char *)NULL, WHITE);
+    char *stackLenS = strtok((char *)NULL, WHITE);
+    value *stackPosVal;
+    value *stackLenVal;
+    regs *reg;
+    symbol *sym;
+
+      if (!stackPosS) {
+        fprintf (stderr, "%s:%d: #pragma stack [stack-pos] [stack-length] -- stack-position missing\n", filename, lineno-1);
+
+        return 0; /* considered an error */
+      }
 
-       /* #pragma maxram [maxram] */
-       if (startsWith (ptr, "maxram")) {
-         char *maxRAM = strtok((char *)NULL, WHITE);
+      stackPosVal = constVal( stackPosS );
+      stackPos = (unsigned int)floatFromVal( stackPosVal );
 
-               if (maxRAM != (char *)NULL) {
-                 int maxRAMaddress;
-                 value *maxRAMVal;
+      if(stackLenS) {
+        stackLenVal = constVal( stackLenS );
+        stackLen = (unsigned int)floatFromVal( stackLenVal );
+      }
 
-                       maxRAMVal = constVal(maxRAM);
-                       maxRAMaddress = (int)floatFromVal(maxRAMVal);
-                       pic16_setMaxRAM(maxRAMaddress);
-               }
+      if(stackLen < 1) {
+        stackLen = 64;
+        fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
+                filename, lineno-1, stackLen, stackLen);
+      }
 
-          return 0;
-       }
-       
-       /* #pragma stack [stack-position] [stack-len] */
-       if(startsWith(ptr, "stack")) {
-         char *stackPosS = strtok((char *)NULL, WHITE);
-         char *stackLenS = strtok((char *)NULL, WHITE);
-         value *stackPosVal;
-         value *stackLenVal;
-         regs *reg;
-         symbol *sym;
-
-               stackPosVal = constVal( stackPosS );
-               stackPos = (unsigned int)floatFromVal( stackPosVal );
+      /* check sanity of stack */
+      if ((stackPos >> 8) != ((stackPos+stackLen-1) >> 8)) {
+        fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] crosses memory bank boundaries (not fully tested)\n",
+               filename,lineno-1, stackPos, stackPos+stackLen-1);
+      }
 
-               
-               if(stackLenS) {
-                       stackLenVal = constVal( stackLenS );
-                       stackLen = (unsigned int)floatFromVal( stackLenVal );
-               }
+      if (pic16) {
+        if (stackPos < pic16->acsSplitOfs) {
+          fprintf (stderr, "%s:%u: warning: stack [0x%03X, 0x%03X] intersects with the access bank [0x000,0x%03x] -- this is highly discouraged!\n",
+               filename, lineno-1, stackPos, stackPos+stackLen-1, pic16->acsSplitOfs);
+        }
 
-               if(stackLen < 1) {
-                       stackLen = 64;
-                       fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
-                                     filename, lineno-1, stackLen, stackLen);
-                        
-//                     fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
-               }
+        if (stackPos+stackLen > 0xF00 + pic16->acsSplitOfs) {
+          fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] intersects with special function registers [0x%03X,0xFFF]-- this is highly discouraged!\n",
+               filename, lineno-1, stackPos, stackPos+stackLen-1, 0xF00 + pic16->acsSplitOfs);
+        }
 
-//             fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
-                               
-               reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
-               addSet(&pic16_fix_udata, reg);
-               
-               reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
-               addSet(&pic16_fix_udata, reg);
+        if (stackPos+stackLen > pic16->RAMsize) {
+          fprintf (stderr, "%s:%u: error: stack [0x%03X,0x%03X] is placed outside available memory [0x000,0x%03X]!\n",
+               filename, lineno-1, stackPos, stackPos+stackLen-1, pic16->RAMsize-1);
+          exit(-1);
+          return 1;    /* considered an error, but this reports "invalid pragma stack"... */
+        }
+      }
 
-               sym = newSymbol("stack", 0);
-               sprintf(sym->rname, "_%s", sym->name);
-               addSet(&publics, sym);
+      reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
+      addSet(&pic16_fix_udata, reg);
+    
+      reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
+      addSet(&pic16_fix_udata, reg);
+    
+      sym = newSymbol("stack", 0);
+      sprintf(sym->rname, "_%s", sym->name);
+      addSet(&publics, sym);
 
-               sym = newSymbol("stack_end", 0);
-               sprintf(sym->rname, "_%s", sym->name);
-               addSet(&publics, sym);
-               
-               initsfpnt = 1;          // force glue() to initialize stack/frame pointers */
+      sym = newSymbol("stack_end", 0);
+      sprintf(sym->rname, "_%s", sym->name);
+      addSet(&publics, sym);
+    
+      initsfpnt = 1;    // force glue() to initialize stack/frame pointers */
 
-         return 0;
-       }
-       
-       /* #pragma code [symbol] [location] */
-       if(startsWith(ptr, "code")) {
-         char *symname = strtok((char *)NULL, WHITE);
-         char *location = strtok((char *)NULL, WHITE);
-         absSym *absS;
-         value *addr;
-
-               absS = Safe_calloc(1, sizeof(absSym));
-               sprintf(absS->name, "_%s", symname);
-               
-               addr = constVal( location );
-               absS->address = (unsigned int)floatFromVal( addr );
+    return 0;
+  }
+  
+  /* #pragma code [symbol] [location] */
+  if(startsWith(ptr, "code")) {
+    char *symname = strtok((char *)NULL, WHITE);
+    char *location = strtok((char *)NULL, WHITE);
+    absSym *absS;
+    value *addr;
+
+      if (!symname || !location) {
+        fprintf (stderr, "%s:%d: #pragma code [symbol] [location] -- symbol or location missing\n", filename, lineno-1);
+       exit (-1);
+        return 1; /* considered an error, but this reports "invalid pragma code"... */
+      }
+
+      absS = Safe_calloc(1, sizeof(absSym));
+      sprintf(absS->name, "_%s", symname);
+    
+      addr = constVal( location );
+      absS->address = (unsigned int)floatFromVal( addr );
 
-               if((absS->address % 2) != 0) {
-                 absS->address--;
-                 fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
-                                     filename, lineno-1, absS->address);
-                }
+      if((absS->address % 2) != 0) {
+        absS->address--;
+        fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
+                filename, lineno-1, absS->address);
+      }
 
-               addSet(&absSymSet, absS);
-//             fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
-//                     __FILE__, __LINE__, symname, absS->address);
+      addSet(&absSymSet, absS);
+//    fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
+//      __FILE__, __LINE__, symname, absS->address);
 
-         return 0;
-       }
+    return 0;
+  }
+
+  /* #pragma udata [section-name] [symbol] */
+  if(startsWith(ptr, "udata")) {
+    char *sectname = strtok((char *)NULL, WHITE);
+    char *symname = strtok((char *)NULL, WHITE);
+    symbol *nsym;
+    sectSym *ssym;
+    sectName *snam;
+    int found=0;
+    
+      if (!symname || !sectname) {
+        fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno-1);
+       exit (-1);
+        return 1; /* considered an error, but this reports "invalid pragma code"... */
+      }
+    
+      while(symname) {
+        ssym = Safe_calloc(1, sizeof(sectSym));
+        ssym->name = Safe_calloc(1, strlen(symname)+2);
+        sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
+        ssym->reg = NULL;
+
+        addSet(&sectSyms, ssym);
+
+        nsym = newSymbol(symname, 0);
+        strcpy(nsym->rname, ssym->name);
 
-       /* #pragma udata [section-name] [symbol] */
-       if(startsWith(ptr, "udata")) {
-         char *sectname = strtok((char *)NULL, WHITE);
-         char *symname = strtok((char *)NULL, WHITE);
-         symbol *nsym;
-         sectSym *ssym;
-         sectName *snam;
-         int found=0;
-         
-               while(symname) {
-                       ssym = Safe_calloc(1, sizeof(sectSyms));
-                       ssym->name = Safe_calloc(1, strlen(symname)+2);
-                       sprintf(ssym->name, "_%s", symname);
-                       ssym->reg = NULL;
-
-                       addSet(&sectSyms, ssym);
-
-                        nsym = newSymbol(symname, 0);
-                        strcpy(nsym->rname, ssym->name);
 #if 0
-                       checkAddSym(&publics, nsym);
+        checkAddSym(&publics, nsym);
 #endif
 
-                       found = 0;
-                       for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
-                               if(!strcmp(sectname, snam->name)){ found=1; break; }
-                       }
-                       
-                       if(!found) {
-                               snam = Safe_calloc(1, sizeof(sectNames));
-                               snam->name = Safe_strdup( sectname );
-                               snam->regsSet = NULL;
-                               
-                               addSet(&sectNames, snam);
-                       }
-                       
-                       ssym->section = snam;
-                               
+        found = 0;
+        for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
+          if(!strcmp(sectname, snam->name)){ found=1; break; }
+        }
+      
+        if(!found) {
+          snam = Safe_calloc(1, sizeof(sectName));
+          snam->name = Safe_strdup( sectname );
+          snam->regsSet = NULL;
+        
+          addSet(&sectNames, snam);
+        }
+      
+        ssym->section = snam;
+        
 #if 0
-                       fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
-                               ssym->name, snam->name, snam);
+        fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
+           ssym->name, snam->name, snam);
 #endif
 
-                       symname = strtok((char *)NULL, WHITE);
-               }
+        symname = strtok((char *)NULL, WHITE);
+    }
 
-         return 0;
-       }
-       
-       /* #pragma wparam function1[, function2[,...]] */
-       if(startsWith(ptr, "wparam")) {
-         char *fname = strtok((char *)NULL, WHITECOMMA);
-         
-            while(fname) {
-              addSet(&wparamList, Safe_strdup(fname));
+    return 0;
+  }
+  
+  /* #pragma wparam function1[, function2[,...]] */
+  if(startsWith(ptr, "wparam")) {
+    char *fname = strtok((char *)NULL, WHITECOMMA);
+
+      
+      while(fname) {
+        fprintf(stderr, "PIC16 Warning: `%s' wparam pragma is obsolete. use function attribute `wparam' instead.\n", fname);
+        addSet(&wparamList, Safe_strdup(fname));
               
-//              debugf("passing with WREG to %s\n", fname);
-              fname = strtok((char *)NULL, WHITECOMMA);
-            }
+//        debugf("passing with WREG to %s\n", fname);
+        fname = strtok((char *)NULL, WHITECOMMA);
+      }
             
-          return 0;
-        }
+      return 0;
+  }
         
-        /* #pragma library library_module */
-        if(startsWith(ptr, "library")) {
-          char *lmodule = strtok((char *)NULL, WHITE);
+  /* #pragma library library_module */
+  if(startsWith(ptr, "library")) {
+  char *lmodule = strtok((char *)NULL, WHITE);
         
-            if(lmodule) {
-              /* lmodule can be:
-               * c     link the C library
-               * math  link the math library
-               * io    link the IO library
-               * debug link the debug libary
-               * anything else, will link as-is */
-              if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
-              else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
-              else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
-              else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
-              else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
-              else {
-                if(!libflags.ignore) {
-                  fprintf(stderr, "link library %s\n", lmodule);
-                  addSetHead(&libFilesSet, lmodule);
-                }
-              }
-            }
-            
-            return 0;
+    if(lmodule) {
+      /* lmodule can be:
+       * c     link the C library
+       * math  link the math library
+       * io    link the IO library
+       * debug link the debug libary
+       * anything else, will link as-is */
+       
+      if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
+      else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
+      else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
+      else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
+      else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
+      else {
+        if(!libflags.ignore) {
+          fprintf(stderr, "link library %s\n", lmodule);
+          addSetHead(&libFilesSet, lmodule);
         }
-                
-              
-       
+      }
+    }
+    
+    return 0;
+  }
+   
+#if 0
+  /* This is an experimental code for #pragma inline
+     and is temporarily disabled for 2.5.0 release */
+  if(startsWith(ptr, "inline")) {
+    char *tmp = strtok((char *)NULL, WHITECOMMA);
+
+      while(tmp) {
+        addSet(&asmInlineMap, Safe_strdup( tmp ));
+        tmp = strtok((char *)NULL, WHITECOMMA);
+      }
+
+      {
+        char *s;
+          
+          for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
+            debugf("inline asm: `%s'\n", s);
+          }
+      }
+      
+      return 0;
+  }
+#endif  /* 0 */
+
   return 1;
 }
 
@@ -346,7 +422,7 @@ _process_pragma(const char *sz)
 #define ALT_ASM                "--asm="
 #define ALT_LINK       "--link="
 
-#define IVT_LOC                "--ivt-loc"
+#define IVT_LOC                "--ivt-loc="
 #define NO_DEFLIBS     "--nodefaultlibs"
 #define MPLAB_COMPAT   "--mplab-comp"
 
@@ -356,6 +432,8 @@ _process_pragma(const char *sz)
 #define        OFMSG_LRSUPPORT "--flr-support"
 
 #define OPTIMIZE_GOTO   "--optimize-goto"
+#define        OPTIMIZE_CMP    "--optimize-cmp"
+#define        OPTIMIZE_DF     "--optimize-df"
 
 char *alt_asm=NULL;
 char *alt_link=NULL;
@@ -396,8 +474,13 @@ OPTION pic16_optionsTable[]= {
        { 0,    USE_CRT,        NULL,   "use <crt-o> run-time initialization module"},
        { 0,    "--no-crt",     &pic16_options.no_crt,  "do not link any default run-time initialization module"},
        { 0,    "--gstack",     &pic16_options.gstack,  "trace stack pointer push/pop to overflow"},
-//     { 0,    OFMSG_LRSUPPORT,        NULL,           "use support functions for local register store/restore"},
        { 0,    OPTIMIZE_GOTO,  NULL,                   "try to use (conditional) BRA instead of GOTO"},
+       { 0,    OPTIMIZE_CMP,   NULL,                   "try to optimize some compares"},
+       { 0,    OPTIMIZE_DF,    NULL,                   "thoroughly analyze data flow (memory and time intensive!)"},
+       { 0,    "--num-func-alloc-regs", &pic16_options.CATregs, "dump number of temporary registers allocated for each function"},
+#if XINST
+       { 'y',  "--extended",   &xinst, "enable Extended Instruction Set/Literal Offset Addressing mode"},
+#endif
        { 0,    NULL,           NULL,   NULL}
        };
 
@@ -459,6 +542,7 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
 
     if(ISOPT(IVT_LOC)) {
       pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
+      fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc);
       return TRUE;
     }
        
@@ -489,12 +573,21 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
     }
 #endif
 
-#if 1
     if (ISOPT(OPTIMIZE_GOTO)) {
       pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
       return TRUE;
     }
-#endif
+
+    if(ISOPT(OPTIMIZE_CMP)) {
+      pic16_options.opt_flags |= OF_OPTIMIZE_CMP;
+      return TRUE;
+    }
+
+    if (ISOPT(OPTIMIZE_DF)) {
+      pic16_options.opt_flags |= OF_OPTIMIZE_DF;
+      return TRUE;
+    }
+    
 
   return FALSE;
 }
@@ -512,6 +605,9 @@ static void _pic16_initPaths(void)
     setMainValue("mcu", pic16->name[2] );
     addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
 
+    setMainValue("mcu1", pic16->name[1] );
+    addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
+
     sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
     sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
 
@@ -547,13 +643,18 @@ extern set *linkOptionsSet;
 char *msprintf(hTab *pvals, const char *pformat, ...);
 int my_system(const char *cmd);
 
+/* forward declarations */   
+extern const char *pic16_linkCmd[];
+extern const char *pic16_asmCmd[];
+extern set *asmOptionsSet;
+  
 /* custom function to link objects */
 static void _pic16_linkEdit(void)
 {
   hTab *linkValues=NULL;
-  char lfrm[256];
+  char lfrm[1024];
   char *lcmd;
-  char temp[128];
+  char temp[1024];
   set *tSet=NULL;
   int ret;
   
@@ -562,10 +663,9 @@ static void _pic16_linkEdit(void)
         * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
         *
         */
-        
-       sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
-                
-       shash_add(&linkValues, "linker", "gplink");
+       sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {ofiles} {spec_ofiles} {libs}");
+
+       shash_add(&linkValues, "linker", pic16_linkCmd[0]);
 
        mergeSets(&tSet, libDirsSet);
        mergeSets(&tSet, libPathsSet);
@@ -615,11 +715,6 @@ static void _pic16_linkEdit(void)
 }
 
 
-/* forward declarations */
-extern const char *pic16_linkCmd[];
-extern const char *pic16_asmCmd[];
-extern set *asmOptionsSet;
-
 static void
 _pic16_finaliseOptions (void)
 {
@@ -658,6 +753,14 @@ _pic16_finaliseOptions (void)
     if(options.model == MODEL_LARGE)
       addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
     
+    {
+      char buf[128];
+
+        sprintf(buf, "-D%s -D__%s", pic16->name[2], pic16->name[1]);
+        *(strrchr(buf, 'f')) = 'F';
+        addSet(&asmOptionsSet, Safe_strdup( buf ));
+    }
+    
     if(STACK_MODEL_LARGE) {
       addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
       addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
@@ -726,6 +829,7 @@ _pic16_setDefaultOptions (void)
   pic16_options.ip_stack = 1;          /* set to 1 to enable ipop/ipush for stack */
   pic16_options.gstack = 0;
   pic16_options.debgen = 0;
+  pic16_options.CATregs = 0;
 }
 
 static const char *
@@ -815,13 +919,17 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
        /* multiplication is fixed */
        /* support mul for char/int/long */
        if((ic->op == '*')
-         && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
+         && (IS_SYMOP(IC_LEFT(ic)))
+         && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))
+           return TRUE;
 #endif
 
 #if 0
        /* support div for char/int/long */
-       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
-               && (ic->op == '/'))return TRUE;
+       if((ic->op == '/')
+         && (IS_SYMOP(IC_LEFT(ic)))
+         && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0))
+           return TRUE;
 #endif
        
   return FALSE;
@@ -979,6 +1087,7 @@ PORT pic16_port =
     "HOME    (CODE)",  // home
     NULL,                      // xidata
     NULL,                      // xinit
+    "CONST   (CODE)",          // const_name - const data (code or not)
     NULL,                      // default location for auto vars
     NULL,                      // default location for global vars
     1                          // code is read only 1=yes