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"
20 static char _defaultRules[] =
26 /* list of key words used by pic14 */
27 static char *_pic14_keywords[] =
54 pic14_options_t pic14_options;
56 #define ARG_STACKLOC "--stack-loc"
57 #define ARG_STACKSIZ "--stack-size"
59 extern int debug_verbose; /* from pcode.c */
60 static OPTION _pic14_poptions[] = {
61 { 0 , "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
62 { 0 , "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
63 { 0 , ARG_STACKLOC, NULL, "sets the lowest address of the argument passing stack" },
64 { 0 , ARG_STACKSIZ, NULL, "sets the size if the argument passing stack (default: 16, minimum: 4)" },
65 { 0 , NULL, NULL, NULL }
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)
110 /* TODO: allow port-specific command line options to specify
111 * segment names here.
114 /* This is a temporary hack, to solve problems with some processors
115 * that do not have udata section. It will be changed when a more
116 * robust solution is figured out -- VR 27-11-2003 FIXME
118 strcpy(buf, "--udata-section-name");
119 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
120 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
121 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
124 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
132 extern set *dataDirsSet;
133 extern set *includeDirsSet;
134 /* pic14 port uses include/pic and lib/pic instead of
135 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
136 * setIncludePaths routine. */
138 _pic14_initPaths (void)
144 if (options.nostdinc)
147 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
148 mergeSets(&includeDirsSet, tempSet);
150 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
152 addSetHead(&includeDirsSet, p);
153 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
157 strcat(p2, DIR_SEPARATOR_STRING);
159 addSetHead(&includeDirsSet, p2);
165 _pic14_finaliseOptions (void)
167 pCodeInitRegisters();
169 port->mem.default_local_map = data;
170 port->mem.default_globl_map = data;
172 /* Hack-o-matic: if we are using the flat24 model,
173 * adjust pointer sizes.
175 if (options.model == MODEL_FLAT24)
178 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
179 "for DS80C390 support. This code generator is "
180 "badly out of date and probably broken.\n");
182 port->s.fptr_size = 3;
183 port->s.gptr_size = 4;
184 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
186 port->stack.call_overhead++; /* This acounts for the extra byte
187 * of return addres on the stack.
188 * but is ugly. There must be a
192 fReturn = fReturn390;
196 if (options.model == MODEL_LARGE)
198 port->mem.default_local_map = xdata;
199 port->mem.default_globl_map = xdata;
203 port->mem.default_local_map = data;
204 port->mem.default_globl_map = data;
207 if (options.stack10bit)
209 if (options.model != MODEL_FLAT24)
212 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
213 fprintf (stderr, "\t10 bit stack mode disabled.\n");
214 options.stack10bit = 0;
218 /* Fixup the memory map for the stack; it is now in
219 * far space and requires a FPOINTER to access it.
222 istack->ptrType = FPOINTER;
229 _pic14_setDefaultOptions (void)
234 _pic14_getRegName (struct regs *reg)
241 extern char *processor_base_name(void);
244 _pic14_genAssemblerPreamble (FILE * of)
246 char * name = processor_base_name();
251 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
254 fprintf (of, "\tlist\tp=%s\n",name);
255 fprintf (of, "\tradix dec\n");
256 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
259 /* Generate interrupt vector table. */
261 _pic14_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
265 if (options.model != MODEL_FLAT24)
267 /* Let the default code handle it. */
271 dbuf_printf (oBuf, "\t;ajmp\t__sdcc_gsinit_startup\n");
273 /* now for the other interrupts */
274 for (i = 0; i < maxInterrupts; i++)
278 dbuf_printf (oBuf, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
282 dbuf_printf (oBuf, "\t;reti\n\t.ds\t7\n");
290 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
293 sym_link *test = NULL;
297 //fprintf(stderr,"checking for native mult\n");
304 /* multiply chars in-place */
305 if (getSize(left) == 1 && getSize(right) == 1)
308 /* use library functions for more complex maths */
312 if ( IS_LITERAL (left))
314 fprintf(stderr,"left is lit\n");
316 val = OP_VALUE (IC_LEFT (ic));
318 else if ( IS_LITERAL (right))
320 fprintf(stderr,"right is lit\n");
322 val = OP_VALUE (IC_RIGHT (ic));
326 fprintf(stderr,"oops, neither is lit so no\n");
330 if ( getSize (test) <= 2)
332 fprintf(stderr,"yep\n");
335 fprintf(stderr,"nope\n");
341 /* Indicate which extended bit operations this port supports */
343 hasExtBitOp (int op, int size)
347 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
354 /* Indicate the expense of an access to an output storage class */
356 oclsExpense (struct memmap *oclass)
358 /* The IN_FARSPACE test is compatible with historical behaviour, */
359 /* but I don't think it is applicable to PIC. If so, please feel */
360 /* free to remove this test -- EEP */
361 if (IN_FARSPACE(oclass))
367 /** $1 is always the basename.
368 $2 is always the output file.
370 $l is the list of extra options that should be there somewhere...
371 MUST be terminated with a NULL.
373 static const char *_linkCmd[] =
375 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
378 static const char *_asmCmd[] =
380 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
384 extern set *libFilesSet;
385 extern set *libDirsSet;
386 extern set *libPathsSet;
387 extern set *includeDirsSet;
388 extern set *userIncDirsSet;
389 extern set *dataDirsSetSet;
390 extern set *relFilesSet;
391 extern set *linkOptionsSet;
393 static void _pic14_do_link (void)
395 hTab *linkValues=NULL;
404 * link command format:
405 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
409 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
411 shash_add(&linkValues, "linker", "gplink");
413 /* LIBRARY SEARCH DIRS */
414 mergeSets(&tSet, libPathsSet);
415 mergeSets(&tSet, libDirsSet);
416 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
418 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
419 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
420 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
422 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
424 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
426 if(fullSrcFileName) {
427 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
428 shash_add(&linkValues, "user_ofile", temp);
431 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
434 procName = processor_base_name();
439 addSet(&libFilesSet, "libsdcc.lib");
440 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
441 addSet(&libFilesSet, temp);
442 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
444 lcmd = msprintf(linkValues, lfrm);
446 ret = my_system( lcmd );
459 "MCU pic", /* Target name */
463 TRUE, /* Emit glue around main */
464 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
472 //"-plosgffc", /* Options with debug */
473 //"-plosgff", /* Options without debug */
476 NULL /* no do_assemble function */
481 _pic14_do_link, /* own do link function */
489 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
490 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
491 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
492 2 so that we can accomodate the PIC's with 4 register banks (like the
496 /* tags for generic pointers */
497 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
514 "CONST (CODE)", // const_name - const data (code or not)
515 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
516 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
517 "IABS (ABS,DATA)", // iabs_name - absolute data
520 1 // code is read only
526 /* pic14 has an 8 bit mul */
531 pic14_emitDebuggerSymbol
534 255/3, /* maxCount */
535 3, /* sizeofElement */
536 /* The rest of these costs are bogus. They approximate */
537 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
538 {4,4,4}, /* sizeofMatchJump[] */
539 {0,0,0}, /* sizeofRangeCompare[] */
540 0, /* sizeofSubtract */
541 3, /* sizeofDispatch */
548 _pic14_finaliseOptions,
549 _pic14_setDefaultOptions,
550 pic14_assignRegisters,
553 _pic14_genAssemblerPreamble,
554 NULL, /* no genAssemblerEnd */
556 NULL, // _pic14_genXINIT
557 NULL, /* genInitStartup */
558 _pic14_reset_regparm,
560 NULL, /* process a pragma */
563 hasExtBitOp, /* hasExtBitOp */
564 oclsExpense, /* oclsExpense */
566 // TRUE, /* little endian */
567 FALSE, /* little endian - PIC code enumlates big endian */
570 1, /* transform <= to ! > */
571 1, /* transform >= to ! < */
572 1, /* transform != to !(a == b) */
574 FALSE, /* No array initializer support. */
575 0, /* no CSE cost estimation yet */
576 NULL, /* no builtin functions */
577 GPOINTER, /* treat unqualified pointers as "generic" pointers */
578 1, /* reset labelKey to 1 */
579 1, /* globals & local static allowed */