2004-01-13 Vangelis Rokas <vrokas@otenet.gr>
[fw/sdcc] / src / pic16 / main.c
index abd6c3a5d4aa120afa4f24161be6786827adeb15..44f4c13dcb0aa0e00a9a2ae0c4cbbab40152635f 100644 (file)
@@ -1,9 +1,29 @@
-/** @file main.c
-    pic16 specific general functions.
+/*-------------------------------------------------------------------------
+
+  main.c - pic16 specific general functions.
+
+   Written by - Scott Dattalo scott@dattalo.com
+   Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com
+    
+   Note that mlh prepended _pic16_ on the static functions.  Makes
+   it easier to set a breakpoint using the debugger.
+
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-------------------------------------------------------------------------*/
 
-    Note that mlh prepended _pic16_ on the static functions.  Makes
-    it easier to set a breakpoint using the debugger.
-*/
 #include "common.h"
 #include "main.h"
 #include "ralloc.h"
@@ -43,20 +63,40 @@ static char *_pic16_keywords[] =
   "_xdata",
   "_pdata",
   "_idata",
+  "_naked",
   NULL
 };
 
+
+pic16_sectioninfo_t pic16_sectioninfo;
+
+
+extern char *pic16_processor_base_name(void);
+
 void  pic16_pCodeInitRegisters(void);
 
 void pic16_assignRegisters (eBBlock ** ebbs, int count);
 
 static int regParmFlg = 0;     /* determine if we can register a parameter */
 
+pic16_options_t pic16_options;
+
 static void
 _pic16_init (void)
 {
-  asm_addTree (&asm_asxxxx_mapping);
-  pic16_pCodeInitRegisters();
+       asm_addTree (&asm_asxxxx_mapping);
+       pic16_pCodeInitRegisters();
+       maxInterrupts = 2;
+       
+
+       /* set pic16 port options to defaults */
+       pic16_options.gen_banksel = 0;
+       pic16_options.opt_banksel = 0;
+       pic16_options.omit_configw = 0;
+       pic16_options.omit_ivt = 0;
+       pic16_options.leave_reset = 0;
+       pic16_options.enable_stack = 0;
+       pic16_options.stack_model = 0;                  /* 0 for 'small', 1 for 'large' */
 }
 
 static void
@@ -77,85 +117,301 @@ _pic16_regparm (sym_link * l)
   return 1;
 }
 
+
+set *absSymSet;
+
 static int
 _process_pragma(const char *sz)
 {
   static const char *WHITE = " \t";
+  
   char *ptr = strtok((char *)sz, WHITE);
 
-  if (startsWith (ptr, "memmap"))
-    {
-      char     *start;
-      char     *end;
-      char     *type;
-      char     *alias;
-
-      start = strtok((char *)NULL, WHITE);
-      end = strtok((char *)NULL, WHITE);
-      type = strtok((char *)NULL, WHITE);
-      alias = strtok((char *)NULL, WHITE);
-
-      if (start != (char *)NULL
-         && end != (char *)NULL
-         && type != (char *)NULL) {
-       value           *startVal = constVal(start);
-       value           *endVal = constVal(end);
-       value           *aliasVal;
-       memRange        r;
-
-       if (alias == (char *)NULL) {
-         aliasVal = constVal(0);
-       } else {
-         aliasVal = constVal(alias);
+       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);
+               }
        }
+       
+       if(startsWith(ptr, "stack")) {
+         char *stackPosS = strtok((char *)NULL, WHITE);
+         value *stackPosVal;
+
+//             fprintf(stderr, "Initializing stack pointer to 0x%x\n", (int)floatFromVal(constVal(stackPos)));
+               stackPosVal = constVal( stackPosS );
+               stackPos = (unsigned int)floatFromVal( stackPosVal );
 
-       r.start_address = (int)floatFromVal(startVal);
-       r.end_address = (int)floatFromVal(endVal);
-       r.alias = (int)floatFromVal(aliasVal);
-       r.bank = (r.start_address >> 7) & 0xf;
-
-       if (strcmp(type, "RAM") == 0) {
-         pic16_addMemRange(&r, 0);
-       } else if (strcmp(type, "SFR") == 0) {
-         pic16_addMemRange(&r, 1);
-       } else {
-         return 1;
+         return 0;
        }
-      }
+       
+       if(startsWith(ptr, "code")) {
+         char *symname = strtok((char *)NULL, WHITE);
+         char *location = strtok((char *)NULL, WHITE);
+         absSym *absS;
+         value *addr;
 
-      return 0;
-    } else if (startsWith (ptr, "maxram")) {
-      char *maxRAM = strtok((char *)NULL, WHITE);
+               absS = Safe_calloc(1, sizeof(absSym));
+               absS->name = Safe_strdup( symname );
+               addr = constVal( location );
+               absS->address = (unsigned int)floatFromVal( addr );
 
-      if (maxRAM != (char *)NULL) {
-       int     maxRAMaddress;
-       value   *maxRAMVal;
+               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;
+       }         
 
-       maxRAMVal = constVal(maxRAM);
-       maxRAMaddress = (int)floatFromVal(maxRAMVal);
-       pic16_setMaxRAM(maxRAMaddress);
-      }
-       
-      return 0;
-    }
   return 1;
 }
 
+#define REP_UDATA      "--preplace-udata-with="
+#define REP_UDATAACS   "--preplace-udata-acs-with="
+#define REP_UDATAOVR   "--preplace-udata-ovr-with="
+#define REP_UDATASHR   "--preplace-udata-sht-with="
+
+#define NAME_CODE      "--psection-code-name="
+#define NAME_IDATA     "--psection-idata-name="
+#define NAME_UDATA     "--psection-udata-name="
+#define NAME_UDATAACS  "--psection-udata-acs-name="
+#define NAME_UDATAOVR  "--psection-udata-ovr-name="
+#define NAME_UDATASHR  "--psection-udata-shr-name="
+
+#define ADDR_CODE      "--psection-code-addr="
+#define ADDR_IDATA     "--psection-idata-addr="
+#define ADDR_UDATA     "--psection-udata-addr="
+#define ADDR_UDATAACS  "--psection-udata-acs-addr="
+#define ADDR_UDATAOVR  "--psection-udata-ovr-addr="
+#define ADDR_UDATASHR  "--psection-udata-shr-addr="
+
+#define STACK_MODEL    "--pstack-model="
+#define OPT_BANKSEL    "--obanksel="
+
+
+extern int pic16_debug_verbose;
+extern int pic16_ralloc_debug;
+extern int pic16_pcode_verbose;
+
+OPTION pic16_optionsTable[]= {
+       { 0,    "--pgen-banksel",       &pic16_options.gen_banksel,     "generate BANKSEL assembler directives"},
+       { 0,    OPT_BANKSEL,            NULL,                           "set banksel optimization level (default=0 no)"},
+       { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
+       { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
+       { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
+       { 0,    "--penable-stack",      &pic16_options.enable_stack,    "enable the use of stack"},
+       { 0,    STACK_MODEL,    NULL,   "use stack model 'small' (default) or 'large'"},
+
+       { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
+       { 0,    "--debug-ralloc",       &pic16_ralloc_debug,    "dump register allocator debug file *.d"},
+       { 0,    "--pcode-verbose",      &pic16_pcode_verbose,   "dump pcode related info"},
+               
+       { 0,    REP_UDATA,      NULL,   "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
+
+#if 0
+       /* these may not be in any use -- VR */
+       { 0,    AT_UDATAACS,    NULL,   "Emit udata_acs variables at another section"},
+       { 0,    AT_UDATAOVR,    NULL,   "Emit udata_ovr variables at another section"},
+       { 0,    AT_UDATASHR,    NULL,   "Emit udata_shr variables at another section"},
+#endif
+
+#if 0
+       /* commented out for the time being -- VR */
+       { 0,    NAME_CODE,      NULL,   "Set code section name[,address]"},
+       { 0,    NAME_IDATA,     NULL,   "Set idata section name[,address]"},
+       { 0,    NAME_UDATA,     NULL,   "Set udata section name[,address]"},
+       { 0,    NAME_UDATAACS,  NULL,   "Set udata_acs section name[,address]"},
+       { 0,    NAME_UDATAOVR,  NULL,   "Set udata_ovr section name[,address]"},
+       { 0,    NAME_UDATASHR,  NULL,   "Set udata_shr section name[,address]"},
+       
+       { 0,    ADDR_CODE,      NULL,   "Set code section address"},
+       { 0,    ADDR_IDATA,     NULL,   "Set idata section address"},
+       { 0,    ADDR_UDATA,     NULL,   "Set udata section address"},
+       { 0,    ADDR_UDATAACS,  NULL,   "Set udata_acs section address"},
+       { 0,    ADDR_UDATAOVR,  NULL,   "Set udata_ovr section address"},
+       { 0,    ADDR_UDATASHR,  NULL,   "Set udata_shr section address"},
+#endif
+
+       { 0,    NULL,           NULL,   NULL}
+       };
+
+
+#define ISOPT(str)     !strncmp(argv[ *i ], str, strlen(str) )
+
+extern char *getStringArg(const char *,  char **, int *, int);
+extern int getIntArg(const char *, char **, int *, int);
+
 static bool
 _pic16_parseOptions (int *pargc, char **argv, int *i)
 {
+  int j=0;
+//  set *tset;
+
   /* TODO: allow port-specific command line options to specify
    * segment names here.
    */
+       /* check for arguments that have associated an integer variable */
+       while(pic16_optionsTable[j].pparameter) {
+               if(ISOPT( pic16_optionsTable[j].longOpt )) {
+                       (*pic16_optionsTable[j].pparameter)++;
+                       return TRUE;
+               }
+               j++;
+       }
+
+
+       if(ISOPT(STACK_MODEL)) {
+               switch(*getStringArg(STACK_MODEL, argv, i, *pargc)) {
+                       case 's': pic16_options.stack_model = 0; break;
+                       case 'l': pic16_options.stack_model = 1; break;
+                       
+                       default:
+                               fprintf(stderr, "Unknown stack model");
+                               exit(-1);
+               }
+               return TRUE;
+       }
+
+       if(ISOPT(OPT_BANKSEL)) {
+               pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
+               return TRUE;
+       }
+
+       if(ISOPT(REP_UDATA)) {
+               pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
+               return TRUE;
+       }
+       
+/*
+       if(ISOPT(AT_UDATAACS)) {
+               pic16_sectioninfo.at_udataacs = Safe_strdup( getStringArg(AT_UDATAACS, argv, i, *pargc));
+               return TRUE;
+       }
+
+       if(ISOPT(AT_UDATAOVR)) {
+               pic16_sectioninfo.at_udataovr = Safe_strdup( getStringArg(AT_UDATAOVR, argv, i, *pargc));
+               return TRUE;
+       }
+       
+       if(ISOPT(AT_UDATASHR)) {
+               pic16_sectioninfo.at_udatashr = Safe_strdup( getStringArg(AT_UDATASHR, argv, i, *pargc));
+               return TRUE;
+       }
+*/
+
+#if 0
+       if(ISOPT(ADDR_CODE)) {
+               pic16_sectioninfo.addr_code = getIntArg(ADDR_CODE, argv, i, *pargc);
+               return TRUE;
+       }
+       
+       if(ISOPT(ADDR_IDATA)) {
+               pic16_sectioninfo.addr_idata = getIntArg(ADDR_IDATA, argv, i, *pargc);
+               return TRUE;
+       }
+       
+       if(ISOPT(ADDR_UDATA)) {
+               pic16_sectioninfo.addr_udata = getIntArg(ADDR_UDATA, argv, i, *pargc);
+               return TRUE;
+       }
+       
+       if(ISOPT(ADDR_UDATAACS)) {
+               pic16_sectioninfo.addr_udataacs = getIntArg(ADDR_UDATAACS, argv, i, *pargc);
+               return TRUE;
+       }
+       
+       if(ISOPT(ADDR_UDATAOVR)) {
+               pic16_sectioninfo.addr_udataovr = getIntArg(ADDR_UDATAOVR, argv, i, *pargc);
+               return TRUE;
+       }
+       
+       if(ISOPT(ADDR_UDATASHR)) {
+               pic16_sectioninfo.addr_udatashr = getIntArg(ADDR_UDATASHR, argv, i, *pargc);
+               return TRUE;
+       }
+
+       tset = newSet();
+       
+       if(ISOPT(NAME_CODE)) {
+               setParseWithComma(&tset, getStringArg(NAME_CODE, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_code = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_code = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       if(ISOPT(NAME_IDATA)) {
+               setParseWithComma(&tset, getStringArg(NAME_IDATA, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_idata = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_idata = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       if(ISOPT(NAME_UDATA)) {
+               setParseWithComma(&tset, getStringArg(NAME_UDATA, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_udata = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_udata = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       if(ISOPT(NAME_UDATAACS)) {
+               setParseWithComma(&tset, getStringArg(NAME_UDATAACS, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_udataacs = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_udataacs = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       if(ISOPT(NAME_UDATAOVR)) {
+               setParseWithComma(&tset, getStringArg(NAME_UDATAOVR, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_udataovr = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_udataovr = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       if(ISOPT(NAME_UDATASHR)) {
+               setParseWithComma(&tset, getStringArg(NAME_UDATASHR, argv, i, *pargc));
+               if(elementsInSet(tset) > 0)
+                       pic16_sectioninfo.name_udatashr = Safe_strdup( (char *)indexSet(tset, 0));
+               if(elementsInSet(tset) > 1)
+                       pic16_sectioninfo.addr_udatashr = atoi( (char *)indexSet(tset, 1));
+               return TRUE;
+       }
+
+       deleteSet( &tset );
+#endif
+
   return FALSE;
 }
 
 static void
 _pic16_finaliseOptions (void)
 {
+       port->mem.default_local_map = data;
+       port->mem.default_globl_map = data;
 
-      port->mem.default_local_map = data;
-      port->mem.default_globl_map = data;
+       options.all_callee_saves = 1;           // always callee saves
+
+       setMainValue("mcu", pic16_processor_base_name() );
+       addSet(&preArgvSet, Safe_strdup("-DMCU={mcu}"));
+}
+
+
+/* all the rest is commented ifdef'd out */
 #if 0
   /* Hack-o-matic: if we are using the flat24 model,
    * adjust pointer sizes.
@@ -211,11 +467,32 @@ _pic16_finaliseOptions (void)
        }
     }
 #endif
-}
+
 
 static void
 _pic16_setDefaultOptions (void)
 {
+       /* initialize to defaults section locations, names and addresses */
+       pic16_sectioninfo.at_udata      = "udata";
+       pic16_sectioninfo.at_udataacs   = "udata_acs";
+       pic16_sectioninfo.at_udataovr   = "udata_ovr";
+       pic16_sectioninfo.at_udatashr   = "udata_shr";
+
+       /* initialize to nothing, so let linker decide about their names */
+       pic16_sectioninfo.name_code     =
+       pic16_sectioninfo.name_idata    =
+       pic16_sectioninfo.name_udata    =
+       pic16_sectioninfo.name_udataacs =
+       pic16_sectioninfo.name_udataovr =
+       pic16_sectioninfo.name_udatashr = "";
+
+       /* initialize to -1, so let linker decide about their address */
+       pic16_sectioninfo.addr_code     =
+       pic16_sectioninfo.addr_idata    =
+       pic16_sectioninfo.addr_udata    =
+       pic16_sectioninfo.addr_udataacs =
+       pic16_sectioninfo.addr_udataovr =
+       pic16_sectioninfo.addr_udatashr = -1;
 }
 
 static const char *
@@ -226,36 +503,43 @@ _pic16_getRegName (struct regs *reg)
   return "err";
 }
 
-extern char *pic16_processor_base_name(void);
 
-static void
-_pic16_genAssemblerPreamble (FILE * of)
+#if 1
+static  char *_pic16_mangleFunctionName(char *sz)
 {
-  char * name = pic16_processor_base_name();
+//     fprintf(stderr, "mangled function name: %s\n", sz);
 
-  if(!name) {
+  return sz;
+}
+#endif
 
-    name = "p18f452";
-    fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
-  }
 
-  fprintf (of, "\tlist\tp=%s\n",&name[1]);
-  fprintf (of, "\tinclude \"%s.inc\"\n",name);
+static void
+_pic16_genAssemblerPreamble (FILE * of)
+{
+  char *name = pic16_processor_base_name();
 
-#if 0
-  fprintf (of, "\t__config _CONFIG1H,0x%x\n",pic16_getConfigWord(0x300001));
-  fprintf (of, "\t__config _CONFIG2L,0x%x\n",pic16_getConfigWord(0x300002));
-  fprintf (of, "\t__config _CONFIG2H,0x%x\n",pic16_getConfigWord(0x300003));
-  fprintf (of, "\t__config _CONFIG3H,0x%x\n",pic16_getConfigWord(0x300005));
-  fprintf (of, "\t__config _CONFIG4L,0x%x\n",pic16_getConfigWord(0x300006));
-  fprintf (of, "\t__config _CONFIG5L,0x%x\n",pic16_getConfigWord(0x300008));
-  fprintf (of, "\t__config _CONFIG5H,0x%x\n",pic16_getConfigWord(0x300009));
-  fprintf (of, "\t__config _CONFIG6L,0x%x\n",pic16_getConfigWord(0x30000a));
-  fprintf (of, "\t__config _CONFIG6H,0x%x\n",pic16_getConfigWord(0x30000b));
-  fprintf (of, "\t__config _CONFIG7L,0x%x\n",pic16_getConfigWord(0x30000c));
-  fprintf (of, "\t__config _CONFIG7H,0x%x\n",pic16_getConfigWord(0x30000d));
-#endif
+       if(!name) {
+               name = "p18f452";
+               fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
+       }
 
+       fprintf (of, "\tlist\tp=%s\n",&name[1]);
+
+       if(!pic16_options.omit_configw) {
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300001, pic16_getConfigWord(0x300001));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300002, pic16_getConfigWord(0x300002));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300003, pic16_getConfigWord(0x300003));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300005, pic16_getConfigWord(0x300005));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300006, pic16_getConfigWord(0x300006));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300008, pic16_getConfigWord(0x300008));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300009, pic16_getConfigWord(0x300009));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000a, pic16_getConfigWord(0x30000a));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000b, pic16_getConfigWord(0x30000b));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000c, pic16_getConfigWord(0x30000c));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000d, pic16_getConfigWord(0x30000d));
+       }
+       
   fprintf (of, "\tradix dec\n");
 }
 
@@ -263,28 +547,34 @@ _pic16_genAssemblerPreamble (FILE * of)
 static int
 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
 {
-  int i;
+       /* PIC18F family has only two interrupts, the high and the low
+        * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
 
-  if (options.model != MODEL_FLAT24)
-    {
-      /* Let the default code handle it. */
-      return FALSE;
-    }
-
-  fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
-
-  /* now for the other interrupts */
-  for (i = 0; i < maxInterrupts; i++)
-    {
-      if (interrupts[i])
-       {
-         fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+       if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
+               fprintf(of, "; RESET vector\n");
+               fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
        }
-      else
-       {
-         fprintf (of, "\t;reti\n\t.ds\t7\n");
+       
+       if(!pic16_options.omit_ivt) {
+               fprintf(of, "\tres 4\n");
+
+
+               fprintf(of, "; High priority interrupt vector 0x0008\n");
+               if(interrupts[1]) {
+                       fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
+                       fprintf(of, "\tres\t12\n"); 
+               } else {
+                       fprintf(of, "\tretfie\n");
+                       fprintf(of, "\tres\t14\n");
+               }
+
+               fprintf(of, "; Low priority interrupt vector 0x0018\n");
+               if(interrupts[2]) {
+                       fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
+               } else {
+                       fprintf(of, "\tretfie\n");
+               }
        }
-    }
 
   return TRUE;
 }
@@ -333,6 +623,32 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
 */
 }
 
+/* Indicate which extended bit operations this port supports */
+static bool
+hasExtBitOp (int op, int size)
+{
+  if (op == RRC
+      || op == RLC
+      /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
+     )
+    return TRUE;
+  else
+    return FALSE;
+}
+
+/* Indicate the expense of an access to an output storage class */
+static int
+oclsExpense (struct memmap *oclass)
+{
+  /* The IN_FARSPACE test is compatible with historical behaviour, */
+  /* but I don't think it is applicable to PIC. If so, please feel */
+  /* free to remove this test -- EEP */
+  if (IN_FARSPACE(oclass))
+    return 1;
+    
+  return 0;
+}
+
 /** $1 is always the basename.
     $2 is always the output file.
     $3 varies
@@ -350,7 +666,7 @@ static const char *_linkCmd[] =
  */
 static const char *_asmCmd[] =
 {
-  "gpasm", "-c  -I/usr/local/share/gputils/header", "\"$1.asm\"", NULL
+  "gpasm", "$l", "-c", "\"$1.asm\"", NULL
 
 };
 
@@ -368,55 +684,68 @@ PORT pic16_port =
     MODEL_SMALL
   },
   {
-    _asmCmd,
-    NULL,
-    NULL,
-    NULL,
-       //"-plosgffc",          /* Options with debug */
-       //"-plosgff",           /* Options without debug */
-    0,
-    ".asm",
+    _asmCmd,                   /* assembler command and arguments */
+    NULL,                      /* alternate macro based form */
+    NULL,                      /* arguments for debug mode */
+    NULL,                      /* arguments for normal mode */
+    0,                         /* print externs as global */
+    ".asm",                    /* assembler file extension */
     NULL                       /* no do_assemble function */
   },
   {
-    _linkCmd,
-    NULL,
-    NULL,
-    ".rel"
+    _linkCmd,                  /* linker command and arguments */
+    NULL,                      /* alternate macro based form */
+    NULL,                      /* no do_link function */
+    ".o",                      /* extension for object files */
+    0                          /* no need for linker file */
   },
   {
     _defaultRules
   },
   {
-       /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
-    1, 2, 2, 4, 2, 2, 2, 1, 4, 4
-       /* TSD - I changed the size of gptr from 3 to 1. However, it should be
-          2 so that we can accomodate the PIC's with 4 register banks (like the
-          16f877)
-        */
+       /* Sizes */
+    1,         /* char */
+    2,         /* short */
+    2,         /* int */
+    4,         /* long */
+    2,         /* ptr */
+    3,         /* fptr, far pointers (see Microchip) */
+    2,         /* gptr */
+    1,         /* bit */
+    4,         /* float */
+    4          /* max */
+  },
+  {
+    "XSEG    (XDATA)",         // xstack
+    "STACK   (DATA)",          // istack
+    "CSEG    (CODE)",          // code
+    "DSEG    (DATA)",          // data
+    "ISEG    (DATA)",          // idata
+    "XSEG    (XDATA)",         // xdata
+    "BSEG    (BIT)",           // bit
+    "RSEG    (DATA)",          // reg
+    "GSINIT  (CODE)",          // static
+    "OSEG    (OVR,DATA)",      // overlay
+    "GSFINAL (CODE)",          // post static
+    "HOME       (CODE)",       // home
+    NULL,                      // xidata
+    NULL,                      // xinit
+    NULL,                      // default location for auto vars
+    NULL,                      // default location for global vars
+    1                          // code is read only 1=yes
   },
   {
-    "XSEG    (XDATA)",
-    "STACK   (DATA)",
-    "CSEG    (CODE)",
-    "DSEG    (DATA)",
-    "ISEG    (DATA)",
-    "XSEG    (XDATA)",
-    "BSEG    (BIT)",
-    "RSEG    (DATA)",
-    "GSINIT  (CODE)",
-    "OSEG    (OVR,DATA)",
-    "GSFINAL (CODE)",
-    "HOME       (CODE)",
-    NULL, // xidata
-    NULL, // xinit
-    NULL,
-    NULL,
-    1        // code is read only
+    NULL,              /* genExtraAreaDeclaration */
+    NULL               /* genExatrAreaLinkOptions */
   },
-  { NULL, NULL },
   {
-    +1, 1, 4, 1, 1, 0
+       /* stack related information */
+    -1,                        /* -1 stack grows downwards, +1 upwards */
+    1,                 /* extra overhead when calling between banks */
+    4,                 /* extra overhead when the function is an ISR */
+    1,                 /* extra overhead for a function call */
+    1,                 /* re-entrant space */
+    0                  /* 'banked' call overhead, mild overlap with bank_overhead */
   },
     /* pic16 has an 8 bit mul */
   {
@@ -425,7 +754,7 @@ PORT pic16_port =
   "_",
   _pic16_init,
   _pic16_parseOptions,
-  NULL,
+  pic16_optionsTable,
   _pic16_finaliseOptions,
   _pic16_setDefaultOptions,
   pic16_assignRegisters,
@@ -438,9 +767,12 @@ PORT pic16_port =
   _pic16_reset_regparm,
   _pic16_regparm,
   _process_pragma,                             /* process a pragma */
-  NULL,
+  _pic16_mangleFunctionName,                           /* mangles function name */
   _hasNativeMulFor,
-  FALSE,
+  hasExtBitOp,                 /* hasExtBitOp */
+  oclsExpense,                 /* oclsExpense */
+  FALSE,                       
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */