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 */
31 static OPTION _pic14_poptions[] =
33 { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
34 { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
35 { 0, OPTION_STACK_SIZE, NULL, "sets the size if the argument passing stack (default: 16, minimum: 4)" },
36 { 0, OPTION_UDATA_SECTION_NAME, NULL, "set udata section name" },
37 { 0, NULL, NULL, NULL }
40 /* list of key words used by pic14 */
41 static char *_pic14_keywords[] =
68 void pCodeInitRegisters(void);
70 void pic14_assignRegisters (ebbIndex *);
72 /* Also defined in gen.h, but the #include is commented out */
73 /* for an unknowned reason. - EEP */
74 void pic14_emitDebuggerSymbol (char *);
76 static int regParmFlg = 0; /* determine if we can register a parameter */
81 asm_addTree (&asm_asxxxx_mapping);
82 memset (&pic14_options, 0, sizeof (pic14_options));
86 _pic14_reset_regparm (void)
92 _pic14_regparm (sym_link * l, bool reentrant)
94 /* for this processor it is simple
95 can pass only the first parameter in a register */
103 extern char *udata_section_name;
106 _pic14_parseOptions (int *pargc, char **argv, int *i)
108 /* TODO: allow port-specific command line options to specify
109 * segment names here.
112 /* This is a temporary hack, to solve problems with some processors
113 * that do not have udata section. It will be changed when a more
114 * robust solution is figured out -- VR 27-11-2003 FIXME
116 if (!strcmp (argv[*i], OPTION_UDATA_SECTION_NAME))
118 if (udata_section_name) Safe_free(udata_section_name);
119 udata_section_name = Safe_strdup(getStringArg (OPTION_UDATA_SECTION_NAME, argv, i, *pargc));
122 else if (!strcmp (argv[*i], OPTION_STACK_SIZE))
124 options.stack_size = getIntArg (OPTION_STACK_SIZE, argv, i, *pargc);
130 extern set *dataDirsSet;
131 extern set *includeDirsSet;
132 /* pic14 port uses include/pic and lib/pic instead of
133 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
134 * setIncludePaths routine. */
136 _pic14_initPaths (void)
142 if (options.nostdinc)
145 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
146 mergeSets(&includeDirsSet, tempSet);
148 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
150 addSetHead(&includeDirsSet, p);
151 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
155 strcat(p2, DIR_SEPARATOR_STRING);
157 addSetHead(&includeDirsSet, p2);
163 _pic14_finaliseOptions (void)
165 pCodeInitRegisters();
167 port->mem.default_local_map = data;
168 port->mem.default_globl_map = data;
170 /* Hack-o-matic: if we are using the flat24 model,
171 * adjust pointer sizes.
173 if (options.model == MODEL_FLAT24)
176 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
177 "for DS80C390 support. This code generator is "
178 "badly out of date and probably broken.\n");
180 port->s.fptr_size = 3;
181 port->s.gptr_size = 4;
182 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
184 port->stack.call_overhead++; /* This acounts for the extra byte
185 * of return addres on the stack.
186 * but is ugly. There must be a
190 fReturn = fReturn390;
194 if (options.model == MODEL_LARGE)
196 port->mem.default_local_map = xdata;
197 port->mem.default_globl_map = xdata;
201 port->mem.default_local_map = data;
202 port->mem.default_globl_map = data;
205 if (options.stack10bit)
207 if (options.model != MODEL_FLAT24)
210 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
211 fprintf (stderr, "\t10 bit stack mode disabled.\n");
212 options.stack10bit = 0;
216 /* Fixup the memory map for the stack; it is now in
217 * far space and requires a FPOINTER to access it.
220 istack->ptrType = FPOINTER;
227 _pic14_setDefaultOptions (void)
232 _pic14_getRegName (struct regs *reg)
239 extern char *processor_base_name(void);
242 _pic14_genAssemblerPreamble (FILE * of)
244 char * name = processor_base_name();
249 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
252 fprintf (of, "\tlist\tp=%s\n",name);
253 fprintf (of, "\tradix dec\n");
254 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
257 /* Generate interrupt vector table. */
259 _pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
263 if (options.model != MODEL_FLAT24)
265 /* Let the default code handle it. */
269 dbuf_printf (oBuf, "\t;ajmp\t__sdcc_gsinit_startup\n");
271 /* now for the other interrupts */
272 for (i = 0; i < maxInterrupts; i++)
276 dbuf_printf (oBuf, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
280 dbuf_printf (oBuf, "\t;reti\n\t.ds\t7\n");
288 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
291 sym_link *test = NULL;
295 //fprintf(stderr,"checking for native mult\n");
302 /* multiply chars in-place */
303 if (getSize(left) == 1 && getSize(right) == 1)
306 /* use library functions for more complex maths */
310 if ( IS_LITERAL (left))
312 fprintf(stderr,"left is lit\n");
314 val = OP_VALUE (IC_LEFT (ic));
316 else if ( IS_LITERAL (right))
318 fprintf(stderr,"right is lit\n");
320 val = OP_VALUE (IC_RIGHT (ic));
324 fprintf(stderr,"oops, neither is lit so no\n");
328 if ( getSize (test) <= 2)
330 fprintf(stderr,"yep\n");
333 fprintf(stderr,"nope\n");
339 /* Indicate which extended bit operations this port supports */
341 hasExtBitOp (int op, int size)
345 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
352 /* Indicate the expense of an access to an output storage class */
354 oclsExpense (struct memmap *oclass)
356 /* The IN_FARSPACE test is compatible with historical behaviour, */
357 /* but I don't think it is applicable to PIC. If so, please feel */
358 /* free to remove this test -- EEP */
359 if (IN_FARSPACE(oclass))
365 /** $1 is always the basename.
366 $2 is always the output file.
368 $l is the list of extra options that should be there somewhere...
369 MUST be terminated with a NULL.
371 static const char *_linkCmd[] =
373 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
376 static const char *_asmCmd[] =
378 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
382 extern set *libFilesSet;
383 extern set *libDirsSet;
384 extern set *libPathsSet;
385 extern set *includeDirsSet;
386 extern set *userIncDirsSet;
387 extern set *dataDirsSetSet;
388 extern set *relFilesSet;
389 extern set *linkOptionsSet;
391 static void _pic14_do_link (void)
393 hTab *linkValues=NULL;
402 * link command format:
403 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
407 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
409 shash_add(&linkValues, "linker", "gplink");
411 /* LIBRARY SEARCH DIRS */
412 mergeSets(&tSet, libPathsSet);
413 mergeSets(&tSet, libDirsSet);
414 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
416 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
417 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
418 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
420 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
422 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
424 if(fullSrcFileName) {
425 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
426 shash_add(&linkValues, "user_ofile", temp);
429 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
432 procName = processor_base_name();
437 addSet(&libFilesSet, "libsdcc.lib");
438 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
439 addSet(&libFilesSet, temp);
440 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
442 lcmd = msprintf(linkValues, lfrm);
444 ret = my_system( lcmd );
457 "MCU pic", /* Target name */
461 TRUE, /* Emit glue around main */
462 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
470 //"-plosgffc", /* Options with debug */
471 //"-plosgff", /* Options without debug */
474 NULL /* no do_assemble function */
479 _pic14_do_link, /* own do link function */
487 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
488 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
489 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
490 2 so that we can accomodate the PIC's with 4 register banks (like the
494 /* tags for generic pointers */
495 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
512 "CONST (CODE)", // const_name - const data (code or not)
513 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
514 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
515 "IABS (ABS,DATA)", // iabs_name - absolute data
518 1 // code is read only
524 /* pic14 has an 8 bit mul */
529 pic14_emitDebuggerSymbol
532 255/3, /* maxCount */
533 3, /* sizeofElement */
534 /* The rest of these costs are bogus. They approximate */
535 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
536 {4,4,4}, /* sizeofMatchJump[] */
537 {0,0,0}, /* sizeofRangeCompare[] */
538 0, /* sizeofSubtract */
539 3, /* sizeofDispatch */
546 _pic14_finaliseOptions,
547 _pic14_setDefaultOptions,
548 pic14_assignRegisters,
551 _pic14_genAssemblerPreamble,
552 NULL, /* no genAssemblerEnd */
554 NULL, // _pic14_genXINIT
555 NULL, /* genInitStartup */
556 _pic14_reset_regparm,
558 NULL, /* process a pragma */
561 hasExtBitOp, /* hasExtBitOp */
562 oclsExpense, /* oclsExpense */
564 // TRUE, /* little endian */
565 FALSE, /* little endian - PIC code enumlates big endian */
568 1, /* transform <= to ! > */
569 1, /* transform >= to ! < */
570 1, /* transform != to !(a == b) */
572 FALSE, /* No array initializer support. */
573 0, /* no CSE cost estimation yet */
574 NULL, /* no builtin functions */
575 GPOINTER, /* treat unqualified pointers as "generic" pointers */
576 1, /* reset labelKey to 1 */
577 1, /* globals & local static allowed */