* src/port.h,
[fw/sdcc] / src / pic16 / main.c
index 4d2fb48f10ea46d05c934c277b65fe0e91e4f49c..e1c6f24c16c78ad56277e5d32b48255f366e3578 100644 (file)
@@ -1,14 +1,35 @@
-/** @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"
 #include "device.h"
 #include "SDCCutil.h"
+#include "glue.h"
 //#include "gen.h"
 
 
@@ -56,6 +77,7 @@ _pic16_init (void)
 {
   asm_addTree (&asm_asxxxx_mapping);
   pic16_pCodeInitRegisters();
+  maxInterrupts = 2;
 }
 
 static void
@@ -262,28 +284,55 @@ _pic16_genAssemblerPreamble (FILE * of)
 static int
 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
 {
+#if 0
   int i;
+#endif
 
-  if (options.model != MODEL_FLAT24)
-    {
-      /* Let the default code handle it. */
-      return FALSE;
-    }
+#if 0
+       if (options.model != MODEL_FLAT24) {
+       /* Let the default code handle it. */
+         return FALSE;
+       }
+#endif
+
+       /* PIC18F family has only two interrupts, the high and the low
+        * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
 
-  fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
+       fprintf(of, "; RESET vector\n");
+       fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
+       fprintf(of, "\tres 6\n");
 
+
+       fprintf(of, "; High priority interrupt vector 0x0008\n");
+       if(interrupts[1]) {
+               fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
+               fprintf(of, "\tres\t8\n");
+       } else {
+               fprintf(of, "\tretfie\n");
+               fprintf(of, "\tres\t8\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");
+       }
+#if 0
   /* now for the other interrupts */
   for (i = 0; i < maxInterrupts; i++)
     {
+       fprintf(of, "; %s priority interrupt vector 0x%s\n", (i==0)?"high":"low", (i==0)?"0008":"0018");
       if (interrupts[i])
        {
-         fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
+         fprintf (of, "\tgoto\t%s\n\tres\t4\n", interrupts[i]->rname);
        }
       else
        {
-         fprintf (of, "\t;reti\n\t.ds\t7\n");
+         fprintf (of, "\tretfie\n\tres\t7\n");
        }
     }
+#endif
 
   return TRUE;
 }
@@ -332,6 +381,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
@@ -359,8 +434,9 @@ PORT pic16_port =
   TARGET_ID_PIC16,
   "pic16",
   "MCU PIC16",                 /* Target name */
-  "p18f452",                    /* Processor */
+  "p18f442",                    /* Processor */
   {
+    pic16glue,
     TRUE,                      /* Emit glue around main */
     MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
     MODEL_SMALL
@@ -394,24 +470,25 @@ PORT pic16_port =
         */
   },
   {
-    "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
+    "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
   },
+  { NULL, NULL },
   {
     +1, 1, 4, 1, 1, 0
   },
@@ -437,7 +514,10 @@ PORT pic16_port =
   _process_pragma,                             /* process a pragma */
   NULL,
   _hasNativeMulFor,
+  hasExtBitOp,                 /* hasExtBitOp */
+  oclsExpense,                 /* oclsExpense */
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */