2 pic16 specific general functions.
4 Note that mlh prepended _pic16_ on the static functions. Makes
5 it easier to set a breakpoint using the debugger.
15 static char _defaultRules[] =
20 /* list of key words used by pic16 */
21 static char *_pic16_keywords[] =
48 void pic16_pCodeInitRegisters(void);
50 void pic16_assignRegisters (eBBlock ** ebbs, int count);
52 static int regParmFlg = 0; /* determine if we can register a parameter */
57 asm_addTree (&asm_asxxxx_mapping);
58 pic16_pCodeInitRegisters();
62 _pic16_reset_regparm ()
68 _pic16_regparm (sym_link * l)
70 /* for this processor it is simple
71 can pass only the first parameter in a register */
80 _process_pragma(const char *sz)
82 static const char *WHITE = " \t";
83 char *ptr = strtok((char *)sz, WHITE);
85 if (startsWith (ptr, "memmap"))
92 start = strtok((char *)NULL, WHITE);
93 end = strtok((char *)NULL, WHITE);
94 type = strtok((char *)NULL, WHITE);
95 alias = strtok((char *)NULL, WHITE);
97 if (start != (char *)NULL
98 && end != (char *)NULL
99 && type != (char *)NULL) {
100 value *startVal = constVal(start);
101 value *endVal = constVal(end);
105 if (alias == (char *)NULL) {
106 aliasVal = constVal(0);
108 aliasVal = constVal(alias);
111 r.start_address = (int)floatFromVal(startVal);
112 r.end_address = (int)floatFromVal(endVal);
113 r.alias = (int)floatFromVal(aliasVal);
114 r.bank = (r.start_address >> 7) & 0xf;
116 if (strcmp(type, "RAM") == 0) {
117 pic16_addMemRange(&r, 0);
118 } else if (strcmp(type, "SFR") == 0) {
119 pic16_addMemRange(&r, 1);
126 } else if (startsWith (ptr, "maxram")) {
127 char *maxRAM = strtok((char *)NULL, WHITE);
129 if (maxRAM != (char *)NULL) {
133 maxRAMVal = constVal(maxRAM);
134 maxRAMaddress = (int)floatFromVal(maxRAMVal);
135 pic16_setMaxRAM(maxRAMaddress);
144 _pic16_parseOptions (int *pargc, char **argv, int *i)
146 /* TODO: allow port-specific command line options to specify
147 * segment names here.
153 _pic16_finaliseOptions (void)
156 port->mem.default_local_map = data;
157 port->mem.default_globl_map = data;
159 /* Hack-o-matic: if we are using the flat24 model,
160 * adjust pointer sizes.
162 if (options.model == MODEL_FLAT24)
165 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
166 "for DS80C390 support. This code generator is "
167 "badly out of date and probably broken.\n");
169 port->s.fptr_size = 3;
170 port->s.gptr_size = 4;
171 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
173 port->stack.call_overhead++; /* This acounts for the extra byte
174 * of return addres on the stack.
175 * but is ugly. There must be a
179 fReturn = fReturn390;
183 if (options.model == MODEL_LARGE)
185 port->mem.default_local_map = xdata;
186 port->mem.default_globl_map = xdata;
190 port->mem.default_local_map = data;
191 port->mem.default_globl_map = data;
194 if (options.stack10bit)
196 if (options.model != MODEL_FLAT24)
199 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
200 fprintf (stderr, "\t10 bit stack mode disabled.\n");
201 options.stack10bit = 0;
205 /* Fixup the memory map for the stack; it is now in
206 * far space and requires a FPOINTER to access it.
209 istack->ptrType = FPOINTER;
216 _pic16_setDefaultOptions (void)
221 _pic16_getRegName (struct regs *reg)
228 extern char *pic16_processor_base_name(void);
231 _pic16_genAssemblerPreamble (FILE * of)
233 char * name = pic16_processor_base_name();
238 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
241 fprintf (of, "\tlist\tp=%s\n",&name[1]);
242 fprintf (of, "\tinclude \"%s.inc\"\n",name);
245 fprintf (of, "\t__config _CONFIG1H,0x%x\n",pic16_getConfigWord(0x300001));
246 fprintf (of, "\t__config _CONFIG2L,0x%x\n",pic16_getConfigWord(0x300002));
247 fprintf (of, "\t__config _CONFIG2H,0x%x\n",pic16_getConfigWord(0x300003));
248 fprintf (of, "\t__config _CONFIG3H,0x%x\n",pic16_getConfigWord(0x300005));
249 fprintf (of, "\t__config _CONFIG4L,0x%x\n",pic16_getConfigWord(0x300006));
250 fprintf (of, "\t__config _CONFIG5L,0x%x\n",pic16_getConfigWord(0x300008));
251 fprintf (of, "\t__config _CONFIG5H,0x%x\n",pic16_getConfigWord(0x300009));
252 fprintf (of, "\t__config _CONFIG6L,0x%x\n",pic16_getConfigWord(0x30000a));
253 fprintf (of, "\t__config _CONFIG6H,0x%x\n",pic16_getConfigWord(0x30000b));
254 fprintf (of, "\t__config _CONFIG7L,0x%x\n",pic16_getConfigWord(0x30000c));
255 fprintf (of, "\t__config _CONFIG7H,0x%x\n",pic16_getConfigWord(0x30000d));
258 fprintf (of, "\tradix dec\n");
261 /* Generate interrupt vector table. */
263 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
267 if (options.model != MODEL_FLAT24)
269 /* Let the default code handle it. */
273 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
275 /* now for the other interrupts */
276 for (i = 0; i < maxInterrupts; i++)
280 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
284 fprintf (of, "\t;reti\n\t.ds\t7\n");
292 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
294 // sym_link *test = NULL;
297 fprintf(stderr,"checking for native mult\n");
306 if ( IS_LITERAL (left))
308 fprintf(stderr,"left is lit\n");
310 val = OP_VALUE (IC_LEFT (ic));
312 else if ( IS_LITERAL (right))
314 fprintf(stderr,"right is lit\n");
316 val = OP_VALUE (IC_RIGHT (ic));
320 fprintf(stderr,"oops, neither is lit so no\n");
324 if ( getSize (test) <= 2)
326 fprintf(stderr,"yep\n");
329 fprintf(stderr,"nope\n");
335 /** $1 is always the basename.
336 $2 is always the output file.
338 $l is the list of extra options that should be there somewhere...
339 MUST be terminated with a NULL.
341 static const char *_linkCmd[] =
343 "gplink", "\"$1.o\"", "-o $1", "$l", NULL
346 /* Sigh. This really is not good. For now, I recommend:
347 * sdcc -S -mpic16 file.c
348 * the -S option does not compile or link
350 static const char *_asmCmd[] =
352 "gpasm", "-c -I/usr/local/share/gputils/header", "\"$1.asm\"", NULL
361 "MCU PIC16", /* Target name */
362 "p18f452", /* Processor */
364 TRUE, /* Emit glue around main */
365 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
373 //"-plosgffc", /* Options with debug */
374 //"-plosgff", /* Options without debug */
377 NULL /* no do_assemble function */
389 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
390 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
391 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
392 2 so that we can accomodate the PIC's with 4 register banks (like the
413 1 // code is read only
418 /* pic16 has an 8 bit mul */
426 _pic16_finaliseOptions,
427 _pic16_setDefaultOptions,
428 pic16_assignRegisters,
431 _pic16_genAssemblerPreamble,
432 NULL, /* no genAssemblerEnd */
434 NULL, // _pic16_genXINIT
435 _pic16_reset_regparm,
437 _process_pragma, /* process a pragma */
443 1, /* transform <= to ! > */
444 1, /* transform >= to ! < */
445 1, /* transform != to !(a == b) */
447 FALSE, /* No array initializer support. */
448 0, /* no CSE cost estimation yet */
449 NULL, /* no builtin functions */
450 GPOINTER, /* treat unqualified pointers as "generic" pointers */
451 1, /* reset labelKey to 1 */
452 1, /* globals & local static allowed */