2 pic14 specific general functions.
4 Note that mlh prepended _pic14_ on the static functions. Makes
5 it easier to set a breakpoint using the debugger.
8 #include "dbuf_string.h"
10 #include "SDCCmacro.h"
22 extern set *dataDirsSet;
23 extern set *includeDirsSet;
24 extern set *libDirsSet;
25 extern set *libPathsSet;
26 extern set *linkOptionsSet;
29 pic14_options_t pic14_options;
30 int debug_verbose = 0;
33 #define OPTION_STACK_SIZE "--stack-size"
35 static char _defaultRules[] =
40 static OPTION _pic14_poptions[] =
42 { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
43 { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
44 { 0, OPTION_STACK_SIZE, &options.stack_size, "sets the size if the argument passing stack (default: 16, minimum: 4)", CLAT_INTEGER },
45 { 0, NULL, NULL, NULL }
48 /* list of key words used by pic14 */
49 static char *_pic14_keywords[] =
76 static int regParmFlg = 0; /* determine if we can register a parameter */
79 /** $1 is always the basename.
80 $2 is always the output file.
82 $l is the list of extra options that should be there somewhere...
83 MUST be terminated with a NULL.
85 static const char *_linkCmd[] =
87 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
90 static const char *_asmCmd[] =
92 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL
98 asm_addTree (&asm_asxxxx_mapping);
99 memset (&pic14_options, 0, sizeof (pic14_options));
103 _pic14_reset_regparm (void)
109 _pic14_regparm (sym_link * l, bool reentrant)
111 /* for this processor it is simple
112 can pass only the first parameter in a register */
121 _pic14_parseOptions (int *pargc, char **argv, int *i)
123 /* TODO: allow port-specific command line options to specify
124 * segment names here.
129 /* pic14 port uses include/pic and lib/pic instead of
130 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
131 * setIncludePaths routine. */
133 _pic14_initPaths (void)
139 if (options.nostdinc)
142 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
143 mergeSets(&includeDirsSet, tempSet);
145 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
147 addSetHead(&includeDirsSet, p);
148 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
152 strcat(p2, DIR_SEPARATOR_STRING);
154 addSetHead(&includeDirsSet, p2);
160 _pic14_finaliseOptions (void)
162 pCodeInitRegisters();
164 port->mem.default_local_map = data;
165 port->mem.default_globl_map = data;
167 /* Hack-o-matic: if we are using the flat24 model,
168 * adjust pointer sizes.
170 if (options.model == MODEL_FLAT24)
173 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
174 "for DS80C390 support. This code generator is "
175 "badly out of date and probably broken.\n");
177 port->s.fptr_size = 3;
178 port->s.gptr_size = 4;
179 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
181 port->stack.call_overhead++; /* This acounts for the extra byte
182 * of return addres on the stack.
183 * but is ugly. There must be a
187 fReturn = fReturn390;
191 if (options.model == MODEL_LARGE)
193 port->mem.default_local_map = xdata;
194 port->mem.default_globl_map = xdata;
198 port->mem.default_local_map = data;
199 port->mem.default_globl_map = data;
202 if (options.stack10bit)
204 if (options.model != MODEL_FLAT24)
207 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
208 fprintf (stderr, "\t10 bit stack mode disabled.\n");
209 options.stack10bit = 0;
213 /* Fixup the memory map for the stack; it is now in
214 * far space and requires a FPOINTER to access it.
217 istack->ptrType = FPOINTER;
224 _pic14_setDefaultOptions (void)
229 _pic14_getRegName (struct regs *reg)
237 _pic14_genAssemblerPreamble (FILE * of)
239 char * name = processor_base_name();
244 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
247 fprintf (of, "\tlist\tp=%s\n",name);
248 fprintf (of, "\tradix dec\n");
249 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
252 /* Generate interrupt vector table. */
254 _pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
258 if (options.model != MODEL_FLAT24)
260 /* Let the default code handle it. */
264 dbuf_printf (oBuf, "\t;ajmp\t__sdcc_gsinit_startup\n");
266 /* now for the other interrupts */
267 for (i = 0; i < maxInterrupts; i++)
271 dbuf_printf (oBuf, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
275 dbuf_printf (oBuf, "\t;reti\n\t.ds\t7\n");
283 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
286 sym_link *test = NULL;
290 //fprintf(stderr,"checking for native mult\n");
297 /* multiply chars in-place */
298 if (getSize(left) == 1 && getSize(right) == 1)
301 /* use library functions for more complex maths */
305 if ( IS_LITERAL (left))
307 fprintf(stderr,"left is lit\n");
309 val = OP_VALUE (IC_LEFT (ic));
311 else if ( IS_LITERAL (right))
313 fprintf(stderr,"right is lit\n");
315 val = OP_VALUE (IC_RIGHT (ic));
319 fprintf(stderr,"oops, neither is lit so no\n");
323 if ( getSize (test) <= 2)
325 fprintf(stderr,"yep\n");
328 fprintf(stderr,"nope\n");
334 /* Indicate which extended bit operations this port supports */
336 hasExtBitOp (int op, int size)
340 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
347 /* Indicate the expense of an access to an output storage class */
349 oclsExpense (struct memmap *oclass)
351 /* The IN_FARSPACE test is compatible with historical behaviour, */
352 /* but I don't think it is applicable to PIC. If so, please feel */
353 /* free to remove this test -- EEP */
354 if (IN_FARSPACE(oclass))
360 static void _pic14_do_link (void)
362 hTab *linkValues=NULL;
371 * link command format:
372 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
376 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
378 shash_add(&linkValues, "linker", "gplink");
380 /* LIBRARY SEARCH DIRS */
381 mergeSets(&tSet, libPathsSet);
382 mergeSets(&tSet, libDirsSet);
383 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
385 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
386 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
387 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
389 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
391 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
393 if(fullSrcFileName) {
394 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
395 shash_add(&linkValues, "user_ofile", temp);
398 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
401 procName = processor_base_name();
406 addSet(&libFilesSet, "libsdcc.lib");
407 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
408 addSet(&libFilesSet, temp);
409 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
411 lcmd = msprintf(linkValues, lfrm);
413 ret = my_system( lcmd );
426 "MCU pic", /* Target name */
430 TRUE, /* Emit glue around main */
431 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
437 "-g", /* options with --debug */
438 NULL, /* options without --debug */
439 //"-plosgffc", /* Options with debug */
440 //"-plosgff", /* Options without debug */
443 NULL /* no do_assemble function */
448 _pic14_do_link, /* own do link function */
456 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
457 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
458 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
459 2 so that we can accomodate the PIC's with 4 register banks (like the
463 /* tags for generic pointers */
464 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
481 "CONST (CODE)", // const_name - const data (code or not)
482 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
483 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
484 "IABS (ABS,DATA)", // iabs_name - absolute data
487 1 // code is read only
493 /* pic14 has an 8 bit mul */
498 pic14_emitDebuggerSymbol
501 255/3, /* maxCount */
502 3, /* sizeofElement */
503 /* The rest of these costs are bogus. They approximate */
504 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
505 {4,4,4}, /* sizeofMatchJump[] */
506 {0,0,0}, /* sizeofRangeCompare[] */
507 0, /* sizeofSubtract */
508 3, /* sizeofDispatch */
515 _pic14_finaliseOptions,
516 _pic14_setDefaultOptions,
517 pic14_assignRegisters,
520 _pic14_genAssemblerPreamble,
521 NULL, /* no genAssemblerEnd */
523 NULL, // _pic14_genXINIT
524 NULL, /* genInitStartup */
525 _pic14_reset_regparm,
527 NULL, /* process a pragma */
530 hasExtBitOp, /* hasExtBitOp */
531 oclsExpense, /* oclsExpense */
533 // TRUE, /* little endian */
534 FALSE, /* little endian - PIC code enumlates big endian */
537 1, /* transform <= to ! > */
538 1, /* transform >= to ! < */
539 1, /* transform != to !(a == b) */
541 FALSE, /* No array initializer support. */
542 0, /* no CSE cost estimation yet */
543 NULL, /* no builtin functions */
544 GPOINTER, /* treat unqualified pointers as "generic" pointers */
545 1, /* reset labelKey to 1 */
546 1, /* globals & local static allowed */