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