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"
18 static char _defaultRules[] =
24 /* list of key words used by pic14 */
25 static char *_pic14_keywords[] =
52 pic14_options_t pic14_options;
54 extern int debug_verbose; /* from pcode.c */
55 static OPTION _pic14_poptions[] = {
56 { 0 , "--debug-xtra", &debug_verbose, "show more debug info in assembly output" },
57 { 0 , "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" },
58 { 0 , NULL, NULL, NULL }
61 void pCodeInitRegisters(void);
63 void pic14_assignRegisters (ebbIndex *);
65 /* Also defined in gen.h, but the #include is commented out */
66 /* for an unknowned reason. - EEP */
67 void pic14_emitDebuggerSymbol (char *);
69 static int regParmFlg = 0; /* determine if we can register a parameter */
74 asm_addTree (&asm_asxxxx_mapping);
75 memset (&pic14_options, 0, sizeof (pic14_options));
79 _pic14_reset_regparm (void)
85 _pic14_regparm (sym_link * l, bool reentrant)
87 /* for this processor it is simple
88 can pass only the first parameter in a register */
97 _process_pragma(const char *sz)
99 static const char *WHITE = " \t";
100 char *ptr = strtok((char *)sz, WHITE);
102 if (startsWith (ptr, "memmap"))
109 start = strtok((char *)NULL, WHITE);
110 end = strtok((char *)NULL, WHITE);
111 type = strtok((char *)NULL, WHITE);
112 alias = strtok((char *)NULL, WHITE);
114 if (start != (char *)NULL
115 && end != (char *)NULL
116 && type != (char *)NULL) {
117 value *startVal = constVal(start);
118 value *endVal = constVal(end);
122 if (alias == (char *)NULL) {
123 aliasVal = constVal(0);
125 aliasVal = constVal(alias);
128 r.start_address = (int)floatFromVal(startVal);
129 r.end_address = (int)floatFromVal(endVal);
130 r.alias = (int)floatFromVal(aliasVal);
131 r.bank = (r.start_address >> 7) & 3;
133 if (strcmp(type, "RAM") == 0) {
135 } else if (strcmp(type, "SFR") == 0) {
143 } else if (startsWith (ptr, "maxram")) {
144 // not used any more - comes from device config file pic14devices.txt instead
150 extern char *udata_section_name;
153 _pic14_parseOptions (int *pargc, char **argv, int *i)
157 /* TODO: allow port-specific command line options to specify
158 * segment names here.
161 /* This is a temporary hack, to solve problems with some processors
162 * that do not have udata section. It will be changed when a more
163 * robust solution is figured out -- VR 27-11-2003 FIXME
165 strcpy(buf, "--udata-section-name");
166 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
167 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
168 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
171 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
179 extern set *dataDirsSet;
180 extern set *includeDirsSet;
181 /* pic14 port uses include/pic and lib/pic instead of
182 * include/pic14 and lib/pic14 as indicated by SDCCmain.c's
183 * setIncludePaths routine. */
185 _pic14_initPaths (void)
191 if (options.nostdinc)
194 tempSet = appendStrSet(dataDirsSet, NULL, INCLUDE_DIR_SUFFIX DIR_SEPARATOR_STRING "pic");
195 mergeSets(&includeDirsSet, tempSet);
197 if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
199 addSetHead(&includeDirsSet, p);
200 p2=Safe_alloc(strlen(p)+strlen(DIR_SEPARATOR_STRING)+strlen("pic")+1);
204 strcat(p2, DIR_SEPARATOR_STRING);
206 addSetHead(&includeDirsSet, p2);
212 _pic14_finaliseOptions (void)
214 pCodeInitRegisters();
216 port->mem.default_local_map = data;
217 port->mem.default_globl_map = data;
219 /* Hack-o-matic: if we are using the flat24 model,
220 * adjust pointer sizes.
222 if (options.model == MODEL_FLAT24)
225 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
226 "for DS80C390 support. This code generator is "
227 "badly out of date and probably broken.\n");
229 port->s.fptr_size = 3;
230 port->s.gptr_size = 4;
231 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
233 port->stack.call_overhead++; /* This acounts for the extra byte
234 * of return addres on the stack.
235 * but is ugly. There must be a
239 fReturn = fReturn390;
243 if (options.model == MODEL_LARGE)
245 port->mem.default_local_map = xdata;
246 port->mem.default_globl_map = xdata;
250 port->mem.default_local_map = data;
251 port->mem.default_globl_map = data;
254 if (options.stack10bit)
256 if (options.model != MODEL_FLAT24)
259 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
260 fprintf (stderr, "\t10 bit stack mode disabled.\n");
261 options.stack10bit = 0;
265 /* Fixup the memory map for the stack; it is now in
266 * far space and requires a FPOINTER to access it.
269 istack->ptrType = FPOINTER;
276 _pic14_setDefaultOptions (void)
281 _pic14_getRegName (struct regs *reg)
288 extern char *processor_base_name(void);
291 _pic14_genAssemblerPreamble (FILE * of)
293 char * name = processor_base_name();
298 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
301 fprintf (of, "\tlist\tp=%s\n",name);
302 fprintf (of, "\tradix dec\n");
303 fprintf (of, "\tinclude \"p%s.inc\"\n",name);
306 /* Generate interrupt vector table. */
308 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
312 if (options.model != MODEL_FLAT24)
314 /* Let the default code handle it. */
318 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
320 /* now for the other interrupts */
321 for (i = 0; i < maxInterrupts; i++)
325 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
329 fprintf (of, "\t;reti\n\t.ds\t7\n");
337 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
340 sym_link *test = NULL;
344 //fprintf(stderr,"checking for native mult\n");
351 /* multiply chars in-place */
352 if (getSize(left) == 1 && getSize(right) == 1)
355 /* use library functions for more complex maths */
359 if ( IS_LITERAL (left))
361 fprintf(stderr,"left is lit\n");
363 val = OP_VALUE (IC_LEFT (ic));
365 else if ( IS_LITERAL (right))
367 fprintf(stderr,"right is lit\n");
369 val = OP_VALUE (IC_RIGHT (ic));
373 fprintf(stderr,"oops, neither is lit so no\n");
377 if ( getSize (test) <= 2)
379 fprintf(stderr,"yep\n");
382 fprintf(stderr,"nope\n");
388 /* Indicate which extended bit operations this port supports */
390 hasExtBitOp (int op, int size)
394 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
401 /* Indicate the expense of an access to an output storage class */
403 oclsExpense (struct memmap *oclass)
405 /* The IN_FARSPACE test is compatible with historical behaviour, */
406 /* but I don't think it is applicable to PIC. If so, please feel */
407 /* free to remove this test -- EEP */
408 if (IN_FARSPACE(oclass))
414 /** $1 is always the basename.
415 $2 is always the output file.
417 $l is the list of extra options that should be there somewhere...
418 MUST be terminated with a NULL.
420 static const char *_linkCmd[] =
422 "gplink", "$l", "-o \"$2\"", "\"$1\"", "$3", NULL
425 static const char *_asmCmd[] =
427 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
431 extern set *libFilesSet;
432 extern set *libDirsSet;
433 extern set *libPathsSet;
434 extern set *includeDirsSet;
435 extern set *userIncDirsSet;
436 extern set *dataDirsSetSet;
437 extern set *relFilesSet;
438 extern set *linkOptionsSet;
440 static void _pic14_do_link (void)
442 hTab *linkValues=NULL;
451 * link command format:
452 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
456 sprintf(lfrm, "{linker} {incdirs} {sysincdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
458 shash_add(&linkValues, "linker", "gplink");
460 /* LIBRARY SEARCH DIRS */
461 mergeSets(&tSet, libPathsSet);
462 mergeSets(&tSet, libDirsSet);
463 shash_add(&linkValues, "incdirs", joinStrSet(appendStrSet(tSet, "-I\"", "\"")));
465 SNPRINTF (&temp[0], 128, "%cpic\"", DIR_SEPARATOR_CHAR);
466 joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0]));
467 shash_add(&linkValues, "sysincdirs", joinStrSet(appendStrSet(libDirsSet, "-I\"", &temp[0])));
469 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
471 shash_add(&linkValues, "outfile", dstFileName);
473 if(fullSrcFileName) {
474 sprintf(temp, "%s.o", dstFileName);
475 shash_add(&linkValues, "user_ofile", temp);
478 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
481 procName = processor_base_name();
486 addSet(&libFilesSet, "libsdcc.lib");
487 SNPRINTF(&temp[0], 128, "pic%s.lib", procName);
488 addSet(&libFilesSet, temp);
489 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
491 lcmd = msprintf(linkValues, lfrm);
493 ret = my_system( lcmd );
506 "MCU pic", /* Target name */
510 TRUE, /* Emit glue around main */
511 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
519 //"-plosgffc", /* Options with debug */
520 //"-plosgff", /* Options without debug */
523 NULL /* no do_assemble function */
528 _pic14_do_link, /* own do link function */
536 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
537 1, 2, 2, 4, 2, 2, 3, 1, 4, 4
538 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
539 2 so that we can accomodate the PIC's with 4 register banks (like the
559 "CONST (CODE)", // const_name - const data (code or not)
562 1 // code is read only
568 /* pic14 has an 8 bit mul */
573 pic14_emitDebuggerSymbol
576 255/3, /* maxCount */
577 3, /* sizeofElement */
578 /* The rest of these costs are bogus. They approximate */
579 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
580 {4,4,4}, /* sizeofMatchJump[] */
581 {0,0,0}, /* sizeofRangeCompare[] */
582 0, /* sizeofSubtract */
583 3, /* sizeofDispatch */
590 _pic14_finaliseOptions,
591 _pic14_setDefaultOptions,
592 pic14_assignRegisters,
595 _pic14_genAssemblerPreamble,
596 NULL, /* no genAssemblerEnd */
598 NULL, // _pic14_genXINIT
599 NULL, /* genInitStartup */
600 _pic14_reset_regparm,
602 _process_pragma, /* process a pragma */
605 hasExtBitOp, /* hasExtBitOp */
606 oclsExpense, /* oclsExpense */
608 // TRUE, /* little endian */
609 FALSE, /* little endian - PIC code enumlates big endian */
612 1, /* transform <= to ! > */
613 1, /* transform >= to ! < */
614 1, /* transform != to !(a == b) */
616 FALSE, /* No array initializer support. */
617 0, /* no CSE cost estimation yet */
618 NULL, /* no builtin functions */
619 GPOINTER, /* treat unqualified pointers as "generic" pointers */
620 1, /* reset labelKey to 1 */
621 1, /* globals & local static allowed */