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);
145 _pic14_parseOptions (int *pargc, char **argv, int *i)
147 /* TODO: allow port-specific command line options to specify
148 * segment names here.
154 _pic14_finaliseOptions (void)
157 port->mem.default_local_map = data;
158 port->mem.default_globl_map = data;
160 /* Hack-o-matic: if we are using the flat24 model,
161 * adjust pointer sizes.
163 if (options.model == MODEL_FLAT24)
166 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
167 "for DS80C390 support. This code generator is "
168 "badly out of date and probably broken.\n");
170 port->s.fptr_size = 3;
171 port->s.gptr_size = 4;
172 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
174 port->stack.call_overhead++; /* This acounts for the extra byte
175 * of return addres on the stack.
176 * but is ugly. There must be a
180 fReturn = fReturn390;
184 if (options.model == MODEL_LARGE)
186 port->mem.default_local_map = xdata;
187 port->mem.default_globl_map = xdata;
191 port->mem.default_local_map = data;
192 port->mem.default_globl_map = data;
195 if (options.stack10bit)
197 if (options.model != MODEL_FLAT24)
200 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
201 fprintf (stderr, "\t10 bit stack mode disabled.\n");
202 options.stack10bit = 0;
206 /* Fixup the memory map for the stack; it is now in
207 * far space and requires a FPOINTER to access it.
210 istack->ptrType = FPOINTER;
217 _pic14_setDefaultOptions (void)
222 _pic14_getRegName (struct regs *reg)
229 extern char *processor_base_name(void);
232 _pic14_genAssemblerPreamble (FILE * of)
234 char * name = processor_base_name();
239 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
242 fprintf (of, "\tlist\tp=%s\n",&name[1]);
243 fprintf (of, "\tradix dec");
244 fprintf (of, "\ninclude \"%s.inc\"\n",name);
247 /* Generate interrupt vector table. */
249 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
253 if (options.model != MODEL_FLAT24)
255 /* Let the default code handle it. */
259 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
261 /* now for the other interrupts */
262 for (i = 0; i < maxInterrupts; i++)
266 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
270 fprintf (of, "\t;reti\n\t.ds\t7\n");
278 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
281 sym_link *test = NULL;
285 fprintf(stderr,"checking for native mult\n");
294 if ( IS_LITERAL (left))
296 fprintf(stderr,"left is lit\n");
298 val = OP_VALUE (IC_LEFT (ic));
300 else if ( IS_LITERAL (right))
302 fprintf(stderr,"right is lit\n");
304 val = OP_VALUE (IC_RIGHT (ic));
308 fprintf(stderr,"oops, neither is lit so no\n");
312 if ( getSize (test) <= 2)
314 fprintf(stderr,"yep\n");
317 fprintf(stderr,"nope\n");
323 /** $1 is always the basename.
324 $2 is always the output file.
326 $l is the list of extra options that should be there somewhere...
327 MUST be terminated with a NULL.
329 static const char *_linkCmd[] =
331 "gplink", "", "\"$1.o\"", NULL
334 static const char *_asmCmd[] =
336 "gpasm", "-c", "\"$1.asm\"", NULL
345 "MCU pic", /* Target name */
349 TRUE, /* Emit glue around main */
350 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
358 //"-plosgffc", /* Options with debug */
359 //"-plosgff", /* Options without debug */
362 NULL /* no do_assemble function */
374 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
375 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
376 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
377 2 so that we can accomodate the PIC's with 4 register banks (like the
398 1 // code is read only
404 /* pic14 has an 8 bit mul */
412 _pic14_finaliseOptions,
413 _pic14_setDefaultOptions,
414 pic14_assignRegisters,
417 _pic14_genAssemblerPreamble,
418 NULL, /* no genAssemblerEnd */
420 NULL, // _pic14_genXINIT
421 _pic14_reset_regparm,
423 _process_pragma, /* process a pragma */
429 1, /* transform <= to ! > */
430 1, /* transform >= to ! < */
431 1, /* transform != to !(a == b) */
433 FALSE, /* No array initializer support. */
434 0, /* no CSE cost estimation yet */
435 NULL, /* no builtin functions */
436 GPOINTER, /* treat unqualified pointers as "generic" pointers */
437 1, /* reset labelKey to 1 */
438 1, /* globals & local static allowed */