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.
21 extern set *dataDirsSet;
22 extern set *includeDirsSet;
23 extern set *libDirsSet;
24 extern set *libPathsSet;
25 extern set *linkOptionsSet;
28 pic14_options_t pic14_options;
29 int debug_verbose = 0;
32 #define OPTION_STACK_SIZE "--stack-size"
34 static char _defaultRules[] =
39 static OPTION _pic14_poptions[] =
41 { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
42 { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
43 { 0, OPTION_STACK_SIZE, &options.stack_size, "sets the size if the argument passing stack (default: 16, minimum: 4)", CLAT_INTEGER },
44 { 0, NULL, NULL, NULL }
47 /* list of key words used by pic14 */
48 static char *_pic14_keywords[] =
75 static int regParmFlg = 0; /* determine if we can register a parameter */
78 /** $1 is always the basename.
79 $2 is always the output file.
81 $l is the list of extra options that should be there somewhere...
82 MUST be terminated with a NULL.
84 static const char *_linkCmd[] =
86 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
89 static const char *_asmCmd[] =
91 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL
97 asm_addTree (&asm_asxxxx_mapping);
98 memset (&pic14_options, 0, sizeof (pic14_options));
102 _pic14_reset_regparm (void)
108 _pic14_regparm (sym_link * l, bool reentrant)
110 /* for this processor it is simple
111 can pass only the first parameter in a register */
120 _pic14_parseOptions (int *pargc, char **argv, int *i)
122 /* TODO: allow port-specific command line options to specify
123 * segment names here.
128 /* pic14 port uses include/pic and lib/pic instead of
129 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
130 * setIncludePaths routine. */
132 _pic14_initPaths (void)
138 if (options.nostdinc)
141 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
142 mergeSets(&includeDirsSet, tempSet);
144 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
146 addSetHead(&includeDirsSet, p);
147 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
151 strcat(p2, DIR_SEPARATOR_STRING);
153 addSetHead(&includeDirsSet, p2);
159 _pic14_finaliseOptions (void)
161 pCodeInitRegisters();
163 port->mem.default_local_map = data;
164 port->mem.default_globl_map = data;
168 _pic14_setDefaultOptions (void)
173 _pic14_getRegName (struct regs *reg)
181 _pic14_genAssemblerPreamble (FILE * of)
183 char * name = processor_base_name();
188 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
191 fprintf (of, "\tlist\tp=%s\n",name);
192 fprintf (of, "\tradix dec\n");
193 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
196 /* Generate interrupt vector table. */
198 _pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
200 /* Let the default code handle it. */
205 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
212 /* multiply chars in-place */
213 if (getSize(left) == 1 && getSize(right) == 1)
216 /* use library functions for more complex maths */
220 /* Indicate which extended bit operations this port supports */
222 hasExtBitOp (int op, int size)
226 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
233 /* Indicate the expense of an access to an output storage class */
235 oclsExpense (struct memmap *oclass)
237 /* The IN_FARSPACE test is compatible with historical behaviour, */
238 /* but I don't think it is applicable to PIC. If so, please feel */
239 /* free to remove this test -- EEP */
240 if (IN_FARSPACE(oclass))
246 static void _pic14_do_link (void)
248 hTab *linkValues=NULL;
257 * link command format:
258 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
262 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
264 shash_add(&linkValues, "linker", "gplink");
266 /* LIBRARY SEARCH DIRS */
267 mergeSets(&tSet, libPathsSet);
268 mergeSets(&tSet, libDirsSet);
269 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
271 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
272 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
273 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
275 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
277 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
279 if(fullSrcFileName) {
280 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
281 shash_add(&linkValues, "user_ofile", temp);
284 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
287 procName = processor_base_name();
292 addSet(&libFilesSet, "libsdcc.lib");
293 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
294 addSet(&libFilesSet, temp);
295 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
297 lcmd = msprintf(linkValues, lfrm);
299 ret = my_system( lcmd );
312 "MCU pic", /* Target name */
316 TRUE, /* Emit glue around main */
317 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
323 "-g", /* options with --debug */
324 NULL, /* options without --debug */
325 //"-plosgffc", /* Options with debug */
326 //"-plosgff", /* Options without debug */
329 NULL /* no do_assemble function */
334 _pic14_do_link, /* own do link function */
342 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
343 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
344 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
345 2 so that we can accomodate the PIC's with 4 register banks (like the
349 /* tags for generic pointers */
350 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
367 "CONST (CODE)", // const_name - const data (code or not)
368 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
369 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
370 "IABS (ABS,DATA)", // iabs_name - absolute data
373 1 // code is read only
379 /* pic14 has an 8 bit mul */
384 pic14_emitDebuggerSymbol
387 255/3, /* maxCount */
388 3, /* sizeofElement */
389 /* The rest of these costs are bogus. They approximate */
390 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
391 {4,4,4}, /* sizeofMatchJump[] */
392 {0,0,0}, /* sizeofRangeCompare[] */
393 0, /* sizeofSubtract */
394 3, /* sizeofDispatch */
401 _pic14_finaliseOptions,
402 _pic14_setDefaultOptions,
403 pic14_assignRegisters,
406 _pic14_genAssemblerPreamble,
407 NULL, /* no genAssemblerEnd */
409 NULL, // _pic14_genXINIT
410 NULL, /* genInitStartup */
411 _pic14_reset_regparm,
413 NULL, /* process a pragma */
416 hasExtBitOp, /* hasExtBitOp */
417 oclsExpense, /* oclsExpense */
419 // TRUE, /* little endian */
420 FALSE, /* little endian - PIC code enumlates big endian */
423 1, /* transform <= to ! > */
424 1, /* transform >= to ! < */
425 1, /* transform != to !(a == b) */
427 FALSE, /* No array initializer support. */
428 0, /* no CSE cost estimation yet */
429 NULL, /* no builtin functions */
430 GPOINTER, /* treat unqualified pointers as "generic" pointers */
431 1, /* reset labelKey to 1 */
432 1, /* globals & local static allowed */