2004-01-06 Vangelis Rokas <vrokas@otenet.gr>
[fw/sdcc] / src / pic16 / main.c
1 /*-------------------------------------------------------------------------
2
3   main.c - pic16 specific general functions.
4
5    Written by - Scott Dattalo scott@dattalo.com
6    Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com
7     
8    Note that mlh prepended _pic16_ on the static functions.  Makes
9    it easier to set a breakpoint using the debugger.
10
11
12    This program is free software; you can redistribute it and/or modify it
13    under the terms of the GNU General Public License as published by the
14    Free Software Foundation; either version 2, or (at your option) any
15    later version.
16    
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21    
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 -------------------------------------------------------------------------*/
26
27 #include "common.h"
28 #include "main.h"
29 #include "ralloc.h"
30 #include "device.h"
31 #include "SDCCutil.h"
32 #include "glue.h"
33 //#include "gen.h"
34
35
36 static char _defaultRules[] =
37 {
38 #include "peeph.rul"
39 };
40
41 /* list of key words used by pic16 */
42 static char *_pic16_keywords[] =
43 {
44   "at",
45   "bit",
46   "code",
47   "critical",
48   "data",
49   "far",
50   "idata",
51   "interrupt",
52   "near",
53   "pdata",
54   "reentrant",
55   "sfr",
56   "sbit",
57   "using",
58   "xdata",
59   "_data",
60   "_code",
61   "_generic",
62   "_near",
63   "_xdata",
64   "_pdata",
65   "_idata",
66   NULL
67 };
68
69
70 pic16_sectioninfo_t pic16_sectioninfo;
71
72
73 extern char *pic16_processor_base_name(void);
74
75 void  pic16_pCodeInitRegisters(void);
76
77 void pic16_assignRegisters (eBBlock ** ebbs, int count);
78
79 static int regParmFlg = 0;      /* determine if we can register a parameter */
80
81 pic16_options_t pic16_options;
82
83 static void
84 _pic16_init (void)
85 {
86         asm_addTree (&asm_asxxxx_mapping);
87         pic16_pCodeInitRegisters();
88         maxInterrupts = 2;
89         
90
91         /* set pic16 port options to defaults */
92         pic16_options.gen_banksel = 0;
93         pic16_options.opt_banksel = 0;
94         pic16_options.omit_configw = 0;
95         pic16_options.omit_ivt = 0;
96         pic16_options.leave_reset = 0;
97         pic16_options.enable_stack = 0;
98         pic16_options.stack_model = 0;                  /* 0 for 'small', 1 for 'large' */
99 }
100
101 static void
102 _pic16_reset_regparm ()
103 {
104   regParmFlg = 0;
105 }
106
107 static int
108 _pic16_regparm (sym_link * l)
109 {
110   /* for this processor it is simple
111      can pass only the first parameter in a register */
112   //if (regParmFlg)
113   //  return 0;
114
115   regParmFlg++;// = 1;
116   return 1;
117 }
118
119
120 static int
121 _process_pragma(const char *sz)
122 {
123   static const char *WHITE = " \t";
124   char  *ptr = strtok((char *)sz, WHITE);
125
126         if (startsWith (ptr, "maxram")) {
127           char *maxRAM = strtok((char *)NULL, WHITE);
128
129                 if (maxRAM != (char *)NULL) {
130                   int maxRAMaddress;
131                   value *maxRAMVal;
132
133                         maxRAMVal = constVal(maxRAM);
134                         maxRAMaddress = (int)floatFromVal(maxRAMVal);
135                         pic16_setMaxRAM(maxRAMaddress);
136                 }
137         }
138         
139         if(startsWith(ptr, "stack")) {
140           char *stackPosS = strtok((char *)NULL, WHITE);
141           value *stackPosVal;
142
143 //              fprintf(stderr, "Initializing stack pointer to 0x%x\n", (int)floatFromVal(constVal(stackPos)));
144                 stackPosVal = constVal( stackPosS );
145                 stackPos = (unsigned int)floatFromVal( stackPosVal );
146         }
147
148   return 0;
149 }
150
151 #define REP_UDATA       "--preplace-udata-with="
152 #define REP_UDATAACS    "--preplace-udata-acs-with="
153 #define REP_UDATAOVR    "--preplace-udata-ovr-with="
154 #define REP_UDATASHR    "--preplace-udata-sht-with="
155
156 #define NAME_CODE       "--psection-code-name="
157 #define NAME_IDATA      "--psection-idata-name="
158 #define NAME_UDATA      "--psection-udata-name="
159 #define NAME_UDATAACS   "--psection-udata-acs-name="
160 #define NAME_UDATAOVR   "--psection-udata-ovr-name="
161 #define NAME_UDATASHR   "--psection-udata-shr-name="
162
163 #define ADDR_CODE       "--psection-code-addr="
164 #define ADDR_IDATA      "--psection-idata-addr="
165 #define ADDR_UDATA      "--psection-udata-addr="
166 #define ADDR_UDATAACS   "--psection-udata-acs-addr="
167 #define ADDR_UDATAOVR   "--psection-udata-ovr-addr="
168 #define ADDR_UDATASHR   "--psection-udata-shr-addr="
169
170 #define STACK_MODEL     "--pstack-model="
171 #define OPT_BANKSEL     "--obanksel="
172
173
174 extern int pic16_debug_verbose;
175
176 OPTION pic16_optionsTable[]= {
177         { 0,    "--pgen-banksel",       &pic16_options.gen_banksel,     "generate BANKSEL assembler directives"},
178         { 0,    OPT_BANKSEL,            NULL,                           "set banksel optimization level (default=0 no)"},
179         { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
180         { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
181         { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
182         { 0,    "--penable-stack",      &pic16_options.enable_stack,    "enable the use of stack"},
183         { 0,    STACK_MODEL,    NULL,   "use stack model 'small' (default) or 'large'"},
184
185         { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
186         { 0,    REP_UDATA,      NULL,   "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
187
188 #if 0
189         /* these may not be in any use -- VR */
190         { 0,    AT_UDATAACS,    NULL,   "Emit udata_acs variables at another section"},
191         { 0,    AT_UDATAOVR,    NULL,   "Emit udata_ovr variables at another section"},
192         { 0,    AT_UDATASHR,    NULL,   "Emit udata_shr variables at another section"},
193 #endif
194
195 #if 0
196         /* commented out for the time being -- VR */
197         { 0,    NAME_CODE,      NULL,   "Set code section name[,address]"},
198         { 0,    NAME_IDATA,     NULL,   "Set idata section name[,address]"},
199         { 0,    NAME_UDATA,     NULL,   "Set udata section name[,address]"},
200         { 0,    NAME_UDATAACS,  NULL,   "Set udata_acs section name[,address]"},
201         { 0,    NAME_UDATAOVR,  NULL,   "Set udata_ovr section name[,address]"},
202         { 0,    NAME_UDATASHR,  NULL,   "Set udata_shr section name[,address]"},
203         
204         { 0,    ADDR_CODE,      NULL,   "Set code section address"},
205         { 0,    ADDR_IDATA,     NULL,   "Set idata section address"},
206         { 0,    ADDR_UDATA,     NULL,   "Set udata section address"},
207         { 0,    ADDR_UDATAACS,  NULL,   "Set udata_acs section address"},
208         { 0,    ADDR_UDATAOVR,  NULL,   "Set udata_ovr section address"},
209         { 0,    ADDR_UDATASHR,  NULL,   "Set udata_shr section address"},
210 #endif
211
212         { 0,    NULL,           NULL,   NULL}
213         };
214
215
216 #define ISOPT(str)      !strncmp(argv[ *i ], str, strlen(str) )
217
218 extern char *getStringArg(const char *,  char **, int *, int);
219 extern int getIntArg(const char *, char **, int *, int);
220
221 static bool
222 _pic16_parseOptions (int *pargc, char **argv, int *i)
223 {
224   int j=0;
225 //  set *tset;
226
227   /* TODO: allow port-specific command line options to specify
228    * segment names here.
229    */
230         /* check for arguments that have associated an integer variable */
231         while(pic16_optionsTable[j].pparameter) {
232                 if(ISOPT( pic16_optionsTable[j].longOpt )) {
233                         (*pic16_optionsTable[j].pparameter)++;
234                         return TRUE;
235                 }
236                 j++;
237         }
238
239
240         if(ISOPT(STACK_MODEL)) {
241                 switch(*getStringArg(STACK_MODEL, argv, i, *pargc)) {
242                         case 's': pic16_options.stack_model = 0; break;
243                         case 'l': pic16_options.stack_model = 1; break;
244                         
245                         default:
246                                 fprintf(stderr, "Unknown stack model");
247                                 exit(-1);
248                 }
249                 return TRUE;
250         }
251
252         if(ISOPT(OPT_BANKSEL)) {
253                 pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
254                 return TRUE;
255         }
256
257         if(ISOPT(REP_UDATA)) {
258                 pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
259                 return TRUE;
260         }
261         
262 /*
263         if(ISOPT(AT_UDATAACS)) {
264                 pic16_sectioninfo.at_udataacs = Safe_strdup( getStringArg(AT_UDATAACS, argv, i, *pargc));
265                 return TRUE;
266         }
267
268         if(ISOPT(AT_UDATAOVR)) {
269                 pic16_sectioninfo.at_udataovr = Safe_strdup( getStringArg(AT_UDATAOVR, argv, i, *pargc));
270                 return TRUE;
271         }
272         
273         if(ISOPT(AT_UDATASHR)) {
274                 pic16_sectioninfo.at_udatashr = Safe_strdup( getStringArg(AT_UDATASHR, argv, i, *pargc));
275                 return TRUE;
276         }
277 */
278
279 #if 0
280         if(ISOPT(ADDR_CODE)) {
281                 pic16_sectioninfo.addr_code = getIntArg(ADDR_CODE, argv, i, *pargc);
282                 return TRUE;
283         }
284         
285         if(ISOPT(ADDR_IDATA)) {
286                 pic16_sectioninfo.addr_idata = getIntArg(ADDR_IDATA, argv, i, *pargc);
287                 return TRUE;
288         }
289         
290         if(ISOPT(ADDR_UDATA)) {
291                 pic16_sectioninfo.addr_udata = getIntArg(ADDR_UDATA, argv, i, *pargc);
292                 return TRUE;
293         }
294         
295         if(ISOPT(ADDR_UDATAACS)) {
296                 pic16_sectioninfo.addr_udataacs = getIntArg(ADDR_UDATAACS, argv, i, *pargc);
297                 return TRUE;
298         }
299         
300         if(ISOPT(ADDR_UDATAOVR)) {
301                 pic16_sectioninfo.addr_udataovr = getIntArg(ADDR_UDATAOVR, argv, i, *pargc);
302                 return TRUE;
303         }
304         
305         if(ISOPT(ADDR_UDATASHR)) {
306                 pic16_sectioninfo.addr_udatashr = getIntArg(ADDR_UDATASHR, argv, i, *pargc);
307                 return TRUE;
308         }
309
310         tset = newSet();
311         
312         if(ISOPT(NAME_CODE)) {
313                 setParseWithComma(&tset, getStringArg(NAME_CODE, argv, i, *pargc));
314                 if(elementsInSet(tset) > 0)
315                         pic16_sectioninfo.name_code = Safe_strdup( (char *)indexSet(tset, 0));
316                 if(elementsInSet(tset) > 1)
317                         pic16_sectioninfo.addr_code = atoi( (char *)indexSet(tset, 1));
318                 return TRUE;
319         }
320
321         if(ISOPT(NAME_IDATA)) {
322                 setParseWithComma(&tset, getStringArg(NAME_IDATA, argv, i, *pargc));
323                 if(elementsInSet(tset) > 0)
324                         pic16_sectioninfo.name_idata = Safe_strdup( (char *)indexSet(tset, 0));
325                 if(elementsInSet(tset) > 1)
326                         pic16_sectioninfo.addr_idata = atoi( (char *)indexSet(tset, 1));
327                 return TRUE;
328         }
329
330         if(ISOPT(NAME_UDATA)) {
331                 setParseWithComma(&tset, getStringArg(NAME_UDATA, argv, i, *pargc));
332                 if(elementsInSet(tset) > 0)
333                         pic16_sectioninfo.name_udata = Safe_strdup( (char *)indexSet(tset, 0));
334                 if(elementsInSet(tset) > 1)
335                         pic16_sectioninfo.addr_udata = atoi( (char *)indexSet(tset, 1));
336                 return TRUE;
337         }
338
339         if(ISOPT(NAME_UDATAACS)) {
340                 setParseWithComma(&tset, getStringArg(NAME_UDATAACS, argv, i, *pargc));
341                 if(elementsInSet(tset) > 0)
342                         pic16_sectioninfo.name_udataacs = Safe_strdup( (char *)indexSet(tset, 0));
343                 if(elementsInSet(tset) > 1)
344                         pic16_sectioninfo.addr_udataacs = atoi( (char *)indexSet(tset, 1));
345                 return TRUE;
346         }
347
348         if(ISOPT(NAME_UDATAOVR)) {
349                 setParseWithComma(&tset, getStringArg(NAME_UDATAOVR, argv, i, *pargc));
350                 if(elementsInSet(tset) > 0)
351                         pic16_sectioninfo.name_udataovr = Safe_strdup( (char *)indexSet(tset, 0));
352                 if(elementsInSet(tset) > 1)
353                         pic16_sectioninfo.addr_udataovr = atoi( (char *)indexSet(tset, 1));
354                 return TRUE;
355         }
356
357         if(ISOPT(NAME_UDATASHR)) {
358                 setParseWithComma(&tset, getStringArg(NAME_UDATASHR, argv, i, *pargc));
359                 if(elementsInSet(tset) > 0)
360                         pic16_sectioninfo.name_udatashr = Safe_strdup( (char *)indexSet(tset, 0));
361                 if(elementsInSet(tset) > 1)
362                         pic16_sectioninfo.addr_udatashr = atoi( (char *)indexSet(tset, 1));
363                 return TRUE;
364         }
365
366         deleteSet( &tset );
367 #endif
368
369   return FALSE;
370 }
371
372 static void
373 _pic16_finaliseOptions (void)
374 {
375         port->mem.default_local_map = data;
376         port->mem.default_globl_map = data;
377
378         setMainValue("mcu", pic16_processor_base_name() );
379         addSet(&preArgvSet, Safe_strdup("-DMCU={mcu}"));
380 }
381
382
383 /* all the rest is commented ifdef'd out */
384 #if 0
385   /* Hack-o-matic: if we are using the flat24 model,
386    * adjust pointer sizes.
387    */
388   if (options.model == MODEL_FLAT24)
389     {
390
391       fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
392                "for DS80C390 support. This code generator is "
393                "badly out of date and probably broken.\n");
394
395       port->s.fptr_size = 3;
396       port->s.gptr_size = 4;
397       port->stack.isr_overhead++;       /* Will save dpx on ISR entry. */
398 #if 1
399       port->stack.call_overhead++;      /* This acounts for the extra byte 
400                                          * of return addres on the stack.
401                                          * but is ugly. There must be a 
402                                          * better way.
403                                          */
404 #endif
405       fReturn = fReturn390;
406       fReturnSize = 5;
407     }
408
409   if (options.model == MODEL_LARGE)
410     {
411       port->mem.default_local_map = xdata;
412       port->mem.default_globl_map = xdata;
413     }
414   else
415     {
416       port->mem.default_local_map = data;
417       port->mem.default_globl_map = data;
418     }
419
420   if (options.stack10bit)
421     {
422       if (options.model != MODEL_FLAT24)
423         {
424           fprintf (stderr,
425                    "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
426           fprintf (stderr, "\t10 bit stack mode disabled.\n");
427           options.stack10bit = 0;
428         }
429       else
430         {
431           /* Fixup the memory map for the stack; it is now in
432            * far space and requires a FPOINTER to access it.
433            */
434           istack->fmap = 1;
435           istack->ptrType = FPOINTER;
436         }
437     }
438 #endif
439
440
441 static void
442 _pic16_setDefaultOptions (void)
443 {
444         /* initialize to defaults section locations, names and addresses */
445         pic16_sectioninfo.at_udata      = "udata";
446         pic16_sectioninfo.at_udataacs   = "udata_acs";
447         pic16_sectioninfo.at_udataovr   = "udata_ovr";
448         pic16_sectioninfo.at_udatashr   = "udata_shr";
449
450         /* initialize to nothing, so let linker decide about their names */
451         pic16_sectioninfo.name_code     =
452         pic16_sectioninfo.name_idata    =
453         pic16_sectioninfo.name_udata    =
454         pic16_sectioninfo.name_udataacs =
455         pic16_sectioninfo.name_udataovr =
456         pic16_sectioninfo.name_udatashr = "";
457
458         /* initialize to -1, so let linker decide about their address */
459         pic16_sectioninfo.addr_code     =
460         pic16_sectioninfo.addr_idata    =
461         pic16_sectioninfo.addr_udata    =
462         pic16_sectioninfo.addr_udataacs =
463         pic16_sectioninfo.addr_udataovr =
464         pic16_sectioninfo.addr_udatashr = -1;
465 }
466
467 static const char *
468 _pic16_getRegName (struct regs *reg)
469 {
470   if (reg)
471     return reg->name;
472   return "err";
473 }
474
475
476 #if 0
477 static  char *_pic16_mangleFunctionName(char *sz)
478 {
479         fprintf(stderr, "mangled function name: %s\n", sz);
480
481   return sz;
482 }
483 #endif
484
485
486 static void
487 _pic16_genAssemblerPreamble (FILE * of)
488 {
489   char *name = pic16_processor_base_name();
490
491         if(!name) {
492                 name = "p18f452";
493                 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
494         }
495
496         fprintf (of, "\tlist\tp=%s\n",&name[1]);
497
498         if(!pic16_options.omit_configw) {
499                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300001, pic16_getConfigWord(0x300001));
500                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300002, pic16_getConfigWord(0x300002));
501                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300003, pic16_getConfigWord(0x300003));
502                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300005, pic16_getConfigWord(0x300005));
503                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300006, pic16_getConfigWord(0x300006));
504                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300008, pic16_getConfigWord(0x300008));
505                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x300009, pic16_getConfigWord(0x300009));
506                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000a, pic16_getConfigWord(0x30000a));
507                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000b, pic16_getConfigWord(0x30000b));
508                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000c, pic16_getConfigWord(0x30000c));
509                 fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000d, pic16_getConfigWord(0x30000d));
510         }
511         
512   fprintf (of, "\tradix dec\n");
513 }
514
515 /* Generate interrupt vector table. */
516 static int
517 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
518 {
519         /* PIC18F family has only two interrupts, the high and the low
520          * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
521
522         if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
523                 fprintf(of, "; RESET vector\n");
524                 fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
525         }
526         
527         if(!pic16_options.omit_ivt) {
528                 fprintf(of, "\tres 4\n");
529
530
531                 fprintf(of, "; High priority interrupt vector 0x0008\n");
532                 if(interrupts[1]) {
533                         fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
534                         fprintf(of, "\tres\t12\n"); 
535                 } else {
536                         fprintf(of, "\tretfie\n");
537                         fprintf(of, "\tres\t14\n");
538                 }
539
540                 fprintf(of, "; Low priority interrupt vector 0x0018\n");
541                 if(interrupts[2]) {
542                         fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
543                 } else {
544                         fprintf(of, "\tretfie\n");
545                 }
546         }
547
548   return TRUE;
549 }
550
551 static bool
552 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
553 {
554   //  sym_link *test = NULL;
555   //  value *val;
556
557   fprintf(stderr,"checking for native mult\n");
558
559   if ( ic->op != '*')
560     {
561       return FALSE;
562     }
563
564   return TRUE;
565 /*
566   if ( IS_LITERAL (left))
567     {
568       fprintf(stderr,"left is lit\n");
569       test = left;
570       val = OP_VALUE (IC_LEFT (ic));
571     }
572   else if ( IS_LITERAL (right))
573     {
574       fprintf(stderr,"right is lit\n");
575       test = left;
576       val = OP_VALUE (IC_RIGHT (ic));
577     }
578   else
579     {
580       fprintf(stderr,"oops, neither is lit so no\n");
581       return FALSE;
582     }
583
584   if ( getSize (test) <= 2)
585     {
586       fprintf(stderr,"yep\n");
587       return TRUE;
588     }
589   fprintf(stderr,"nope\n");
590
591   return FALSE;
592 */
593 }
594
595 /* Indicate which extended bit operations this port supports */
596 static bool
597 hasExtBitOp (int op, int size)
598 {
599   if (op == RRC
600       || op == RLC
601       /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
602      )
603     return TRUE;
604   else
605     return FALSE;
606 }
607
608 /* Indicate the expense of an access to an output storage class */
609 static int
610 oclsExpense (struct memmap *oclass)
611 {
612   /* The IN_FARSPACE test is compatible with historical behaviour, */
613   /* but I don't think it is applicable to PIC. If so, please feel */
614   /* free to remove this test -- EEP */
615   if (IN_FARSPACE(oclass))
616     return 1;
617     
618   return 0;
619 }
620
621 /** $1 is always the basename.
622     $2 is always the output file.
623     $3 varies
624     $l is the list of extra options that should be there somewhere...
625     MUST be terminated with a NULL.
626 */
627 static const char *_linkCmd[] =
628 {
629   "gplink", "\"$1.o\"", "-o $1", "$l", NULL
630 };
631
632 /* Sigh. This really is not good. For now, I recommend:
633  * sdcc -S -mpic16 file.c
634  * the -S option does not compile or link
635  */
636 static const char *_asmCmd[] =
637 {
638   "gpasm", "-c  -I/usr/local/share/gputils/header", "\"$1.asm\"", NULL
639
640 };
641
642 /* Globals */
643 PORT pic16_port =
644 {
645   TARGET_ID_PIC16,
646   "pic16",
647   "MCU PIC16",                  /* Target name */
648   "p18f452",                    /* Processor */
649   {
650     pic16glue,
651     TRUE,                       /* Emit glue around main */
652     MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
653     MODEL_SMALL
654   },
655   {
656     _asmCmd,                    /* assembler command and arguments */
657     NULL,                       /* alternate macro based form */
658     NULL,                       /* arguments for debug mode */
659     NULL,                       /* arguments for normal mode */
660     0,                          /* print externs as global */
661     ".asm",                     /* assembler file extension */
662     NULL                        /* no do_assemble function */
663   },
664   {
665     _linkCmd,                   /* linker command and arguments */
666     NULL,                       /* alternate macro based form */
667     NULL,                       /* no do_link function */
668     ".rel"                      /* extension for object files */
669   },
670   {
671     _defaultRules
672   },
673   {
674         /* Sizes */
675     1,          /* char */
676     2,          /* short */
677     2,          /* int */
678     4,          /* long */
679     2,          /* ptr */
680     2,          /* fptr, this should be changed to 3 for far pointers (see Microchip) */
681     2,          /* gptr */
682     1,          /* bit */
683     4,          /* float */
684     4           /* max */
685   },
686   {
687     "XSEG    (XDATA)",          // xstack
688     "STACK   (DATA)",           // istack
689     "CSEG    (CODE)",           // code
690     "DSEG    (DATA)",           // data
691     "ISEG    (DATA)",           // idata
692     "XSEG    (XDATA)",          // xdata
693     "BSEG    (BIT)",            // bit
694     "RSEG    (DATA)",           // reg
695     "GSINIT  (CODE)",           // static
696     "OSEG    (OVR,DATA)",       // overlay
697     "GSFINAL (CODE)",           // post static
698     "HOME        (CODE)",       // home
699     NULL,                       // xidata
700     NULL,                       // xinit
701     NULL,                       // default location for auto vars
702     NULL,                       // default location for global vars
703     1                           // code is read only 1=yes
704   },
705   {
706     NULL,               /* genExtraAreaDeclaration */
707     NULL                /* genExatrAreaLinkOptions */
708   },
709   {
710         /* stack related information */
711     -1,                 /* -1 stack grows downwards, +1 upwards */
712     1,                  /* extra overhead when calling between banks */
713     4,                  /* extra overhead when the function is an ISR */
714     1,                  /* extra overhead for a function call */
715     1,                  /* re-entrant space */
716     0                   /* 'banked' call overhead, mild overlap with bank_overhead */
717   },
718     /* pic16 has an 8 bit mul */
719   {
720     1, -1
721   },
722   "_",
723   _pic16_init,
724   _pic16_parseOptions,
725   pic16_optionsTable,
726   _pic16_finaliseOptions,
727   _pic16_setDefaultOptions,
728   pic16_assignRegisters,
729   _pic16_getRegName,
730   _pic16_keywords,
731   _pic16_genAssemblerPreamble,
732   NULL,                         /* no genAssemblerEnd */
733   _pic16_genIVT,
734   NULL, // _pic16_genXINIT
735   _pic16_reset_regparm,
736   _pic16_regparm,
737   _process_pragma,                              /* process a pragma */
738   NULL,                         //_pic16_mangleFunctionName,                            /* mangles function name */
739   _hasNativeMulFor,
740   hasExtBitOp,                  /* hasExtBitOp */
741   oclsExpense,                  /* oclsExpense */
742   FALSE,                        
743   TRUE,                         /* little endian */
744   0,                            /* leave lt */
745   0,                            /* leave gt */
746   1,                            /* transform <= to ! > */
747   1,                            /* transform >= to ! < */
748   1,                            /* transform != to !(a == b) */
749   0,                            /* leave == */
750   FALSE,                        /* No array initializer support. */
751   0,                            /* no CSE cost estimation yet */
752   NULL,                         /* no builtin functions */
753   GPOINTER,                     /* treat unqualified pointers as "generic" pointers */
754   1,                            /* reset labelKey to 1 */
755   1,                            /* globals & local static allowed */
756   PORT_MAGIC
757 };