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.
12 #include "SDCCmacro.h"
15 #include "dbuf_string.h"
19 #define OPTION_STACK_SIZE "--stack-size"
20 #define OPTION_UDATA_SECTION_NAME "--udata-section-name"
23 static char _defaultRules[] =
28 pic14_options_t pic14_options;
29 extern int debug_verbose; /* from pcode.c */
30 extern char *udata_section_name;
32 static OPTION _pic14_poptions[] =
34 { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
35 { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
36 { 0, OPTION_STACK_SIZE, &options.stack_size, "sets the size if the argument passing stack (default: 16, minimum: 4)", CLAT_INTEGER },
37 { 0, OPTION_UDATA_SECTION_NAME, &udata_section_name, "set udata section name", CLAT_STRING },
38 { 0, NULL, NULL, NULL }
41 /* list of key words used by pic14 */
42 static char *_pic14_keywords[] =
69 void pCodeInitRegisters(void);
71 void pic14_assignRegisters (ebbIndex *);
73 /* Also defined in gen.h, but the #include is commented out */
74 /* for an unknowned reason. - EEP */
75 void pic14_emitDebuggerSymbol (char *);
77 static int regParmFlg = 0; /* determine if we can register a parameter */
82 asm_addTree (&asm_asxxxx_mapping);
83 memset (&pic14_options, 0, sizeof (pic14_options));
87 _pic14_reset_regparm (void)
93 _pic14_regparm (sym_link * l, bool reentrant)
95 /* for this processor it is simple
96 can pass only the first parameter in a register */
105 _pic14_parseOptions (int *pargc, char **argv, int *i)
107 /* TODO: allow port-specific command line options to specify
108 * segment names here.
113 extern set *dataDirsSet;
114 extern set *includeDirsSet;
115 /* pic14 port uses include/pic and lib/pic instead of
116 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
117 * setIncludePaths routine. */
119 _pic14_initPaths (void)
125 if (options.nostdinc)
128 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
129 mergeSets(&includeDirsSet, tempSet);
131 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
133 addSetHead(&includeDirsSet, p);
134 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
138 strcat(p2, DIR_SEPARATOR_STRING);
140 addSetHead(&includeDirsSet, p2);
146 _pic14_finaliseOptions (void)
148 pCodeInitRegisters();
150 port->mem.default_local_map = data;
151 port->mem.default_globl_map = data;
153 /* Hack-o-matic: if we are using the flat24 model,
154 * adjust pointer sizes.
156 if (options.model == MODEL_FLAT24)
159 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
160 "for DS80C390 support. This code generator is "
161 "badly out of date and probably broken.\n");
163 port->s.fptr_size = 3;
164 port->s.gptr_size = 4;
165 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
167 port->stack.call_overhead++; /* This acounts for the extra byte
168 * of return addres on the stack.
169 * but is ugly. There must be a
173 fReturn = fReturn390;
177 if (options.model == MODEL_LARGE)
179 port->mem.default_local_map = xdata;
180 port->mem.default_globl_map = xdata;
184 port->mem.default_local_map = data;
185 port->mem.default_globl_map = data;
188 if (options.stack10bit)
190 if (options.model != MODEL_FLAT24)
193 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
194 fprintf (stderr, "\t10 bit stack mode disabled.\n");
195 options.stack10bit = 0;
199 /* Fixup the memory map for the stack; it is now in
200 * far space and requires a FPOINTER to access it.
203 istack->ptrType = FPOINTER;
210 _pic14_setDefaultOptions (void)
215 _pic14_getRegName (struct regs *reg)
222 extern char *processor_base_name(void);
225 _pic14_genAssemblerPreamble (FILE * of)
227 char * name = processor_base_name();
232 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
235 fprintf (of, "\tlist\tp=%s\n",name);
236 fprintf (of, "\tradix dec\n");
237 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
240 /* Generate interrupt vector table. */
242 _pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
246 if (options.model != MODEL_FLAT24)
248 /* Let the default code handle it. */
252 dbuf_printf (oBuf, "\t;ajmp\t__sdcc_gsinit_startup\n");
254 /* now for the other interrupts */
255 for (i = 0; i < maxInterrupts; i++)
259 dbuf_printf (oBuf, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
263 dbuf_printf (oBuf, "\t;reti\n\t.ds\t7\n");
271 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
274 sym_link *test = NULL;
278 //fprintf(stderr,"checking for native mult\n");
285 /* multiply chars in-place */
286 if (getSize(left) == 1 && getSize(right) == 1)
289 /* use library functions for more complex maths */
293 if ( IS_LITERAL (left))
295 fprintf(stderr,"left is lit\n");
297 val = OP_VALUE (IC_LEFT (ic));
299 else if ( IS_LITERAL (right))
301 fprintf(stderr,"right is lit\n");
303 val = OP_VALUE (IC_RIGHT (ic));
307 fprintf(stderr,"oops, neither is lit so no\n");
311 if ( getSize (test) <= 2)
313 fprintf(stderr,"yep\n");
316 fprintf(stderr,"nope\n");
322 /* Indicate which extended bit operations this port supports */
324 hasExtBitOp (int op, int size)
328 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
335 /* Indicate the expense of an access to an output storage class */
337 oclsExpense (struct memmap *oclass)
339 /* The IN_FARSPACE test is compatible with historical behaviour, */
340 /* but I don't think it is applicable to PIC. If so, please feel */
341 /* free to remove this test -- EEP */
342 if (IN_FARSPACE(oclass))
348 /** $1 is always the basename.
349 $2 is always the output file.
351 $l is the list of extra options that should be there somewhere...
352 MUST be terminated with a NULL.
354 static const char *_linkCmd[] =
356 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
359 static const char *_asmCmd[] =
361 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL
365 extern set *libFilesSet;
366 extern set *libDirsSet;
367 extern set *libPathsSet;
368 extern set *includeDirsSet;
369 extern set *userIncDirsSet;
370 extern set *dataDirsSetSet;
371 extern set *relFilesSet;
372 extern set *linkOptionsSet;
374 static void _pic14_do_link (void)
376 hTab *linkValues=NULL;
385 * link command format:
386 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
390 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
392 shash_add(&linkValues, "linker", "gplink");
394 /* LIBRARY SEARCH DIRS */
395 mergeSets(&tSet, libPathsSet);
396 mergeSets(&tSet, libDirsSet);
397 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
399 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
400 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
401 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
403 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
405 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
407 if(fullSrcFileName) {
408 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
409 shash_add(&linkValues, "user_ofile", temp);
412 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
415 procName = processor_base_name();
420 addSet(&libFilesSet, "libsdcc.lib");
421 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
422 addSet(&libFilesSet, temp);
423 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
425 lcmd = msprintf(linkValues, lfrm);
427 ret = my_system( lcmd );
440 "MCU pic", /* Target name */
444 TRUE, /* Emit glue around main */
445 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
451 "-g", /* options with --debug */
452 NULL, /* options without --debug */
453 //"-plosgffc", /* Options with debug */
454 //"-plosgff", /* Options without debug */
457 NULL /* no do_assemble function */
462 _pic14_do_link, /* own do link function */
470 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
471 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
472 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
473 2 so that we can accomodate the PIC's with 4 register banks (like the
477 /* tags for generic pointers */
478 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
495 "CONST (CODE)", // const_name - const data (code or not)
496 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
497 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
498 "IABS (ABS,DATA)", // iabs_name - absolute data
501 1 // code is read only
507 /* pic14 has an 8 bit mul */
512 pic14_emitDebuggerSymbol
515 255/3, /* maxCount */
516 3, /* sizeofElement */
517 /* The rest of these costs are bogus. They approximate */
518 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
519 {4,4,4}, /* sizeofMatchJump[] */
520 {0,0,0}, /* sizeofRangeCompare[] */
521 0, /* sizeofSubtract */
522 3, /* sizeofDispatch */
529 _pic14_finaliseOptions,
530 _pic14_setDefaultOptions,
531 pic14_assignRegisters,
534 _pic14_genAssemblerPreamble,
535 NULL, /* no genAssemblerEnd */
537 NULL, // _pic14_genXINIT
538 NULL, /* genInitStartup */
539 _pic14_reset_regparm,
541 NULL, /* process a pragma */
544 hasExtBitOp, /* hasExtBitOp */
545 oclsExpense, /* oclsExpense */
547 // TRUE, /* little endian */
548 FALSE, /* little endian - PIC code enumlates big endian */
551 1, /* transform <= to ! > */
552 1, /* transform >= to ! < */
553 1, /* transform != to !(a == b) */
555 FALSE, /* No array initializer support. */
556 0, /* no CSE cost estimation yet */
557 NULL, /* no builtin functions */
558 GPOINTER, /* treat unqualified pointers as "generic" pointers */
559 1, /* reset labelKey to 1 */
560 1, /* globals & local static allowed */