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"
19 static char _defaultRules[] =
25 /* list of key words used by pic14 */
26 static char *_pic14_keywords[] =
53 pic14_options_t pic14_options;
55 #define ARG_STACKLOC "--stack-loc"
56 #define ARG_STACKSIZ "--stack-size"
58 extern int debug_verbose; /* from pcode.c */
59 static OPTION _pic14_poptions[] = {
60 { 0 , "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
61 { 0 , "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
62 { 0 , ARG_STACKLOC, NULL, "sets the lowest address of the argument passing stack" },
63 { 0 , ARG_STACKSIZ, NULL, "sets the size if the argument passing stack (default: 16, minimum: 4)" },
64 { 0 , NULL, NULL, NULL }
67 void pCodeInitRegisters(void);
69 void pic14_assignRegisters (ebbIndex *);
71 /* Also defined in gen.h, but the #include is commented out */
72 /* for an unknowned reason. - EEP */
73 void pic14_emitDebuggerSymbol (char *);
75 static int regParmFlg = 0; /* determine if we can register a parameter */
80 asm_addTree (&asm_asxxxx_mapping);
81 memset (&pic14_options, 0, sizeof (pic14_options));
85 _pic14_reset_regparm (void)
91 _pic14_regparm (sym_link * l, bool reentrant)
93 /* for this processor it is simple
94 can pass only the first parameter in a register */
102 extern char *udata_section_name;
105 _pic14_parseOptions (int *pargc, char **argv, int *i)
109 /* TODO: allow port-specific command line options to specify
110 * segment names here.
113 /* This is a temporary hack, to solve problems with some processors
114 * that do not have udata section. It will be changed when a more
115 * robust solution is figured out -- VR 27-11-2003 FIXME
117 strcpy(buf, "--udata-section-name");
118 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
119 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
120 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
123 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
131 extern set *dataDirsSet;
132 extern set *includeDirsSet;
133 /* pic14 port uses include/pic and lib/pic instead of
134 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
135 * setIncludePaths routine. */
137 _pic14_initPaths (void)
143 if (options.nostdinc)
146 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
147 mergeSets(&includeDirsSet, tempSet);
149 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
151 addSetHead(&includeDirsSet, p);
152 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
156 strcat(p2, DIR_SEPARATOR_STRING);
158 addSetHead(&includeDirsSet, p2);
164 _pic14_finaliseOptions (void)
166 pCodeInitRegisters();
168 port->mem.default_local_map = data;
169 port->mem.default_globl_map = data;
171 /* Hack-o-matic: if we are using the flat24 model,
172 * adjust pointer sizes.
174 if (options.model == MODEL_FLAT24)
177 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
178 "for DS80C390 support. This code generator is "
179 "badly out of date and probably broken.\n");
181 port->s.fptr_size = 3;
182 port->s.gptr_size = 4;
183 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
185 port->stack.call_overhead++; /* This acounts for the extra byte
186 * of return addres on the stack.
187 * but is ugly. There must be a
191 fReturn = fReturn390;
195 if (options.model == MODEL_LARGE)
197 port->mem.default_local_map = xdata;
198 port->mem.default_globl_map = xdata;
202 port->mem.default_local_map = data;
203 port->mem.default_globl_map = data;
206 if (options.stack10bit)
208 if (options.model != MODEL_FLAT24)
211 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
212 fprintf (stderr, "\t10 bit stack mode disabled.\n");
213 options.stack10bit = 0;
217 /* Fixup the memory map for the stack; it is now in
218 * far space and requires a FPOINTER to access it.
221 istack->ptrType = FPOINTER;
228 _pic14_setDefaultOptions (void)
233 _pic14_getRegName (struct regs *reg)
240 extern char *processor_base_name(void);
243 _pic14_genAssemblerPreamble (FILE * of)
245 char * name = processor_base_name();
250 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
253 fprintf (of, "\tlist\tp=%s\n",name);
254 fprintf (of, "\tradix dec\n");
255 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
258 /* Generate interrupt vector table. */
260 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
264 if (options.model != MODEL_FLAT24)
266 /* Let the default code handle it. */
270 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
272 /* now for the other interrupts */
273 for (i = 0; i < maxInterrupts; i++)
277 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
281 fprintf (of, "\t;reti\n\t.ds\t7\n");
289 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
292 sym_link *test = NULL;
296 //fprintf(stderr,"checking for native mult\n");
303 /* multiply chars in-place */
304 if (getSize(left) == 1 && getSize(right) == 1)
307 /* use library functions for more complex maths */
311 if ( IS_LITERAL (left))
313 fprintf(stderr,"left is lit\n");
315 val = OP_VALUE (IC_LEFT (ic));
317 else if ( IS_LITERAL (right))
319 fprintf(stderr,"right is lit\n");
321 val = OP_VALUE (IC_RIGHT (ic));
325 fprintf(stderr,"oops, neither is lit so no\n");
329 if ( getSize (test) <= 2)
331 fprintf(stderr,"yep\n");
334 fprintf(stderr,"nope\n");
340 /* Indicate which extended bit operations this port supports */
342 hasExtBitOp (int op, int size)
346 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
353 /* Indicate the expense of an access to an output storage class */
355 oclsExpense (struct memmap *oclass)
357 /* The IN_FARSPACE test is compatible with historical behaviour, */
358 /* but I don't think it is applicable to PIC. If so, please feel */
359 /* free to remove this test -- EEP */
360 if (IN_FARSPACE(oclass))
366 /** $1 is always the basename.
367 $2 is always the output file.
369 $l is the list of extra options that should be there somewhere...
370 MUST be terminated with a NULL.
372 static const char *_linkCmd[] =
374 "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL
377 static const char *_asmCmd[] =
379 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
383 extern set *libFilesSet;
384 extern set *libDirsSet;
385 extern set *libPathsSet;
386 extern set *includeDirsSet;
387 extern set *userIncDirsSet;
388 extern set *dataDirsSetSet;
389 extern set *relFilesSet;
390 extern set *linkOptionsSet;
392 static void _pic14_do_link (void)
394 hTab *linkValues=NULL;
403 * link command format:
404 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
408 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
410 shash_add(&linkValues, "linker", "gplink");
412 /* LIBRARY SEARCH DIRS */
413 mergeSets(&tSet, libPathsSet);
414 mergeSets(&tSet, libDirsSet);
415 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
417 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
418 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
419 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
421 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
423 shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
425 if(fullSrcFileName) {
426 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName );
427 shash_add(&linkValues, "user_ofile", temp);
430 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
433 procName = processor_base_name();
438 addSet(&libFilesSet, "libsdcc.lib");
439 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
440 addSet(&libFilesSet, temp);
441 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
443 lcmd = msprintf(linkValues, lfrm);
445 ret = my_system( lcmd );
458 "MCU pic", /* Target name */
462 TRUE, /* Emit glue around main */
463 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
471 //"-plosgffc", /* Options with debug */
472 //"-plosgff", /* Options without debug */
475 NULL /* no do_assemble function */
480 _pic14_do_link, /* own do link function */
488 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
489 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
490 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
491 2 so that we can accomodate the PIC's with 4 register banks (like the
495 /* tags for generic pointers */
496 { 0x00, 0x00, 0x00, 0x80 }, /* far, near, xstack, code */
513 "CONST (CODE)", // const_name - const data (code or not)
514 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
515 "XABS (ABS,XDATA)", // xabs_name - absolute xdata
516 "IABS (ABS,DATA)", // iabs_name - absolute data
519 1 // code is read only
525 /* pic14 has an 8 bit mul */
530 pic14_emitDebuggerSymbol
533 255/3, /* maxCount */
534 3, /* sizeofElement */
535 /* The rest of these costs are bogus. They approximate */
536 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
537 {4,4,4}, /* sizeofMatchJump[] */
538 {0,0,0}, /* sizeofRangeCompare[] */
539 0, /* sizeofSubtract */
540 3, /* sizeofDispatch */
547 _pic14_finaliseOptions,
548 _pic14_setDefaultOptions,
549 pic14_assignRegisters,
552 _pic14_genAssemblerPreamble,
553 NULL, /* no genAssemblerEnd */
555 NULL, // _pic14_genXINIT
556 NULL, /* genInitStartup */
557 _pic14_reset_regparm,
559 NULL, /* process a pragma */
562 hasExtBitOp, /* hasExtBitOp */
563 oclsExpense, /* oclsExpense */
565 // TRUE, /* little endian */
566 FALSE, /* little endian - PIC code enumlates big endian */
569 1, /* transform <= to ! > */
570 1, /* transform >= to ! < */
571 1, /* transform != to !(a == b) */
573 FALSE, /* No array initializer support. */
574 0, /* no CSE cost estimation yet */
575 NULL, /* no builtin functions */
576 GPOINTER, /* treat unqualified pointers as "generic" pointers */
577 1, /* reset labelKey to 1 */
578 1, /* globals & local static allowed */