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.
16 static char _defaultRules[] =
21 /* list of key words used by msc51 */
22 static char *_pic14_keywords[] =
49 void pCodeInitRegisters(void);
51 void pic14_assignRegisters (eBBlock ** ebbs, int count);
53 static int regParmFlg = 0; /* determine if we can register a parameter */
58 asm_addTree (&asm_asxxxx_mapping);
63 _pic14_reset_regparm ()
69 _pic14_regparm (sym_link * l)
71 /* for this processor it is simple
72 can pass only the first parameter in a register */
81 _process_pragma(const char *sz)
83 static const char *WHITE = " \t";
84 char *ptr = strtok((char *)sz, WHITE);
86 if (startsWith (ptr, "memmap"))
93 start = strtok((char *)NULL, WHITE);
94 end = strtok((char *)NULL, WHITE);
95 type = strtok((char *)NULL, WHITE);
96 alias = strtok((char *)NULL, WHITE);
98 if (start != (char *)NULL
99 && end != (char *)NULL
100 && type != (char *)NULL) {
101 value *startVal = constVal(start);
102 value *endVal = constVal(end);
106 if (alias == (char *)NULL) {
107 aliasVal = constVal(0);
109 aliasVal = constVal(alias);
112 r.start_address = (int)floatFromVal(startVal);
113 r.end_address = (int)floatFromVal(endVal);
114 r.alias = (int)floatFromVal(aliasVal);
115 r.bank = (r.start_address >> 7) & 3;
117 if (strcmp(type, "RAM") == 0) {
119 } else if (strcmp(type, "SFR") == 0) {
127 } else if (startsWith (ptr, "maxram")) {
128 char *maxRAM = strtok((char *)NULL, WHITE);
130 if (maxRAM != (char *)NULL) {
134 maxRAMVal = constVal(maxRAM);
135 maxRAMaddress = (int)floatFromVal(maxRAMVal);
136 setMaxRAM(maxRAMaddress);
144 extern char *udata_section_name;
147 _pic14_parseOptions (int *pargc, char **argv, int *i)
151 /* TODO: allow port-specific command line options to specify
152 * segment names here.
155 /* This is a temporary hack, to solve problems with some processors
156 * that do not have udata section. It will be changed when a more
157 * robust solution is figured out -- VR 27-11-2003 FIXME
159 strcpy(buf, "--udata-section-name");
160 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
161 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
162 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
165 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
174 _pic14_finaliseOptions (void)
177 port->mem.default_local_map = data;
178 port->mem.default_globl_map = data;
180 /* Hack-o-matic: if we are using the flat24 model,
181 * adjust pointer sizes.
183 if (options.model == MODEL_FLAT24)
186 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
187 "for DS80C390 support. This code generator is "
188 "badly out of date and probably broken.\n");
190 port->s.fptr_size = 3;
191 port->s.gptr_size = 4;
192 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
194 port->stack.call_overhead++; /* This acounts for the extra byte
195 * of return addres on the stack.
196 * but is ugly. There must be a
200 fReturn = fReturn390;
204 if (options.model == MODEL_LARGE)
206 port->mem.default_local_map = xdata;
207 port->mem.default_globl_map = xdata;
211 port->mem.default_local_map = data;
212 port->mem.default_globl_map = data;
215 if (options.stack10bit)
217 if (options.model != MODEL_FLAT24)
220 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
221 fprintf (stderr, "\t10 bit stack mode disabled.\n");
222 options.stack10bit = 0;
226 /* Fixup the memory map for the stack; it is now in
227 * far space and requires a FPOINTER to access it.
230 istack->ptrType = FPOINTER;
237 _pic14_setDefaultOptions (void)
242 _pic14_getRegName (struct regs *reg)
249 extern char *processor_base_name(void);
252 _pic14_genAssemblerPreamble (FILE * of)
254 char * name = processor_base_name();
259 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
262 fprintf (of, "\tlist\tp=%s\n",&name[1]);
263 fprintf (of, "\tradix dec");
264 fprintf (of, "\ninclude \"%s.inc\"\n",name);
267 /* Generate interrupt vector table. */
269 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
273 if (options.model != MODEL_FLAT24)
275 /* Let the default code handle it. */
279 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
281 /* now for the other interrupts */
282 for (i = 0; i < maxInterrupts; i++)
286 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
290 fprintf (of, "\t;reti\n\t.ds\t7\n");
298 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
301 sym_link *test = NULL;
305 fprintf(stderr,"checking for native mult\n");
314 if ( IS_LITERAL (left))
316 fprintf(stderr,"left is lit\n");
318 val = OP_VALUE (IC_LEFT (ic));
320 else if ( IS_LITERAL (right))
322 fprintf(stderr,"right is lit\n");
324 val = OP_VALUE (IC_RIGHT (ic));
328 fprintf(stderr,"oops, neither is lit so no\n");
332 if ( getSize (test) <= 2)
334 fprintf(stderr,"yep\n");
337 fprintf(stderr,"nope\n");
343 /* Indicate which extended bit operations this port supports */
345 hasExtBitOp (int op, int size)
349 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
356 /* Indicate the expense of an access to an output storage class */
358 oclsExpense (struct memmap *oclass)
360 /* The IN_FARSPACE test is compatible with historical behaviour, */
361 /* but I don't think it is applicable to PIC. If so, please feel */
362 /* free to remove this test -- EEP */
363 if (IN_FARSPACE(oclass))
369 /** $1 is always the basename.
370 $2 is always the output file.
372 $l is the list of extra options that should be there somewhere...
373 MUST be terminated with a NULL.
375 static const char *_linkCmd[] =
377 "gplink", "-o $2", "\"$1.o\"", "$l", NULL
380 static const char *_asmCmd[] =
382 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
391 "MCU pic", /* Target name */
395 TRUE, /* Emit glue around main */
396 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
404 //"-plosgffc", /* Options with debug */
405 //"-plosgff", /* Options without debug */
408 NULL /* no do_assemble function */
421 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
422 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
423 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
424 2 so that we can accomodate the PIC's with 4 register banks (like the
445 1 // code is read only
451 /* pic14 has an 8 bit mul */
459 _pic14_finaliseOptions,
460 _pic14_setDefaultOptions,
461 pic14_assignRegisters,
464 _pic14_genAssemblerPreamble,
465 NULL, /* no genAssemblerEnd */
467 NULL, // _pic14_genXINIT
468 _pic14_reset_regparm,
470 _process_pragma, /* process a pragma */
473 hasExtBitOp, /* hasExtBitOp */
474 oclsExpense, /* oclsExpense */
476 TRUE, /* little endian */
479 1, /* transform <= to ! > */
480 1, /* transform >= to ! < */
481 1, /* transform != to !(a == b) */
483 FALSE, /* No array initializer support. */
484 0, /* no CSE cost estimation yet */
485 NULL, /* no builtin functions */
486 GPOINTER, /* treat unqualified pointers as "generic" pointers */
487 1, /* reset labelKey to 1 */
488 1, /* globals & local static allowed */