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[] =
22 /* list of key words used by msc51 */
23 static char *_pic14_keywords[] =
50 void pCodeInitRegisters(void);
52 void pic14_assignRegisters (eBBlock ** ebbs, int count);
54 static int regParmFlg = 0; /* determine if we can register a parameter */
59 asm_addTree (&asm_asxxxx_mapping);
64 _pic14_reset_regparm ()
70 _pic14_regparm (sym_link * l)
72 /* for this processor it is simple
73 can pass only the first parameter in a register */
82 _process_pragma(const char *sz)
84 static const char *WHITE = " \t";
85 char *ptr = strtok((char *)sz, WHITE);
87 if (startsWith (ptr, "memmap"))
94 start = strtok((char *)NULL, WHITE);
95 end = strtok((char *)NULL, WHITE);
96 type = strtok((char *)NULL, WHITE);
97 alias = strtok((char *)NULL, WHITE);
99 if (start != (char *)NULL
100 && end != (char *)NULL
101 && type != (char *)NULL) {
102 value *startVal = constVal(start);
103 value *endVal = constVal(end);
107 if (alias == (char *)NULL) {
108 aliasVal = constVal(0);
110 aliasVal = constVal(alias);
113 r.start_address = (int)floatFromVal(startVal);
114 r.end_address = (int)floatFromVal(endVal);
115 r.alias = (int)floatFromVal(aliasVal);
116 r.bank = (r.start_address >> 7) & 3;
118 if (strcmp(type, "RAM") == 0) {
120 } else if (strcmp(type, "SFR") == 0) {
128 } else if (startsWith (ptr, "maxram")) {
129 char *maxRAM = strtok((char *)NULL, WHITE);
131 if (maxRAM != (char *)NULL) {
135 maxRAMVal = constVal(maxRAM);
136 maxRAMaddress = (int)floatFromVal(maxRAMVal);
137 setMaxRAM(maxRAMaddress);
145 extern char *udata_section_name;
148 _pic14_parseOptions (int *pargc, char **argv, int *i)
152 /* TODO: allow port-specific command line options to specify
153 * segment names here.
156 /* This is a temporary hack, to solve problems with some processors
157 * that do not have udata section. It will be changed when a more
158 * robust solution is figured out -- VR 27-11-2003 FIXME
160 strcpy(buf, "--udata-section-name");
161 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
162 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
163 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
166 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
175 _pic14_finaliseOptions (void)
178 port->mem.default_local_map = data;
179 port->mem.default_globl_map = data;
181 /* Hack-o-matic: if we are using the flat24 model,
182 * adjust pointer sizes.
184 if (options.model == MODEL_FLAT24)
187 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
188 "for DS80C390 support. This code generator is "
189 "badly out of date and probably broken.\n");
191 port->s.fptr_size = 3;
192 port->s.gptr_size = 4;
193 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
195 port->stack.call_overhead++; /* This acounts for the extra byte
196 * of return addres on the stack.
197 * but is ugly. There must be a
201 fReturn = fReturn390;
205 if (options.model == MODEL_LARGE)
207 port->mem.default_local_map = xdata;
208 port->mem.default_globl_map = xdata;
212 port->mem.default_local_map = data;
213 port->mem.default_globl_map = data;
216 if (options.stack10bit)
218 if (options.model != MODEL_FLAT24)
221 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
222 fprintf (stderr, "\t10 bit stack mode disabled.\n");
223 options.stack10bit = 0;
227 /* Fixup the memory map for the stack; it is now in
228 * far space and requires a FPOINTER to access it.
231 istack->ptrType = FPOINTER;
238 _pic14_setDefaultOptions (void)
243 _pic14_getRegName (struct regs *reg)
250 extern char *processor_base_name(void);
253 _pic14_genAssemblerPreamble (FILE * of)
255 char * name = processor_base_name();
260 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
263 fprintf (of, "\tlist\tp=%s\n",&name[1]);
264 fprintf (of, "\tradix dec\n");
265 fprintf (of, "\tinclude \"%s.inc\"\n",name);
268 /* Generate interrupt vector table. */
270 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
274 if (options.model != MODEL_FLAT24)
276 /* Let the default code handle it. */
280 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
282 /* now for the other interrupts */
283 for (i = 0; i < maxInterrupts; i++)
287 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
291 fprintf (of, "\t;reti\n\t.ds\t7\n");
299 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
302 sym_link *test = NULL;
306 fprintf(stderr,"checking for native mult\n");
315 if ( IS_LITERAL (left))
317 fprintf(stderr,"left is lit\n");
319 val = OP_VALUE (IC_LEFT (ic));
321 else if ( IS_LITERAL (right))
323 fprintf(stderr,"right is lit\n");
325 val = OP_VALUE (IC_RIGHT (ic));
329 fprintf(stderr,"oops, neither is lit so no\n");
333 if ( getSize (test) <= 2)
335 fprintf(stderr,"yep\n");
338 fprintf(stderr,"nope\n");
344 /* Indicate which extended bit operations this port supports */
346 hasExtBitOp (int op, int size)
350 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
357 /* Indicate the expense of an access to an output storage class */
359 oclsExpense (struct memmap *oclass)
361 /* The IN_FARSPACE test is compatible with historical behaviour, */
362 /* but I don't think it is applicable to PIC. If so, please feel */
363 /* free to remove this test -- EEP */
364 if (IN_FARSPACE(oclass))
370 /** $1 is always the basename.
371 $2 is always the output file.
373 $l is the list of extra options that should be there somewhere...
374 MUST be terminated with a NULL.
376 static const char *_linkCmd[] =
378 "gplink", "-o $2", "\"$1.o\"", "$l", NULL
381 static const char *_asmCmd[] =
383 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
392 "MCU pic", /* Target name */
396 TRUE, /* Emit glue around main */
397 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
405 //"-plosgffc", /* Options with debug */
406 //"-plosgff", /* Options without debug */
409 NULL /* no do_assemble function */
422 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
423 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
424 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
425 2 so that we can accomodate the PIC's with 4 register banks (like the
446 1 // code is read only
452 /* pic14 has an 8 bit mul */
460 _pic14_finaliseOptions,
461 _pic14_setDefaultOptions,
462 pic14_assignRegisters,
465 _pic14_genAssemblerPreamble,
466 NULL, /* no genAssemblerEnd */
468 NULL, // _pic14_genXINIT
469 NULL, /* genInitStartup */
470 _pic14_reset_regparm,
472 _process_pragma, /* process a pragma */
475 hasExtBitOp, /* hasExtBitOp */
476 oclsExpense, /* oclsExpense */
478 // TRUE, /* little endian */
479 FALSE, /* little endian - PIC code enumlates big endian */
482 1, /* transform <= to ! > */
483 1, /* transform >= to ! < */
484 1, /* transform != to !(a == b) */
486 FALSE, /* No array initializer support. */
487 0, /* no CSE cost estimation yet */
488 NULL, /* no builtin functions */
489 GPOINTER, /* treat unqualified pointers as "generic" pointers */
490 1, /* reset labelKey to 1 */
491 1, /* globals & local static allowed */