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 /* Also defined in gen.h, but the #include is commented out */
55 /* for an unknowned reason. - EEP */
56 void pic14_emitDebuggerSymbol (char *);
58 static int regParmFlg = 0; /* determine if we can register a parameter */
63 asm_addTree (&asm_asxxxx_mapping);
68 _pic14_reset_regparm (void)
74 _pic14_regparm (sym_link * l)
76 /* for this processor it is simple
77 can pass only the first parameter in a register */
86 _process_pragma(const char *sz)
88 static const char *WHITE = " \t";
89 char *ptr = strtok((char *)sz, WHITE);
91 if (startsWith (ptr, "memmap"))
98 start = strtok((char *)NULL, WHITE);
99 end = strtok((char *)NULL, WHITE);
100 type = strtok((char *)NULL, WHITE);
101 alias = strtok((char *)NULL, WHITE);
103 if (start != (char *)NULL
104 && end != (char *)NULL
105 && type != (char *)NULL) {
106 value *startVal = constVal(start);
107 value *endVal = constVal(end);
111 if (alias == (char *)NULL) {
112 aliasVal = constVal(0);
114 aliasVal = constVal(alias);
117 r.start_address = (int)floatFromVal(startVal);
118 r.end_address = (int)floatFromVal(endVal);
119 r.alias = (int)floatFromVal(aliasVal);
120 r.bank = (r.start_address >> 7) & 3;
122 if (strcmp(type, "RAM") == 0) {
124 } else if (strcmp(type, "SFR") == 0) {
132 } else if (startsWith (ptr, "maxram")) {
133 char *maxRAM = strtok((char *)NULL, WHITE);
135 if (maxRAM != (char *)NULL) {
139 maxRAMVal = constVal(maxRAM);
140 maxRAMaddress = (int)floatFromVal(maxRAMVal);
141 setMaxRAM(maxRAMaddress);
149 extern char *udata_section_name;
152 _pic14_parseOptions (int *pargc, char **argv, int *i)
156 /* TODO: allow port-specific command line options to specify
157 * segment names here.
160 /* This is a temporary hack, to solve problems with some processors
161 * that do not have udata section. It will be changed when a more
162 * robust solution is figured out -- VR 27-11-2003 FIXME
164 strcpy(buf, "--udata-section-name");
165 if(!strncmp(buf, argv[ *i ], strlen(buf))) {
166 if(strlen(argv[ *i ]) <= strlen(buf)+1) {
167 fprintf(stderr, "WARNING: no `%s' entered\n", buf+2);
170 udata_section_name = strdup( strchr(argv[*i], '=') + 1 );
179 _pic14_finaliseOptions (void)
182 port->mem.default_local_map = data;
183 port->mem.default_globl_map = data;
185 /* Hack-o-matic: if we are using the flat24 model,
186 * adjust pointer sizes.
188 if (options.model == MODEL_FLAT24)
191 fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
192 "for DS80C390 support. This code generator is "
193 "badly out of date and probably broken.\n");
195 port->s.fptr_size = 3;
196 port->s.gptr_size = 4;
197 port->stack.isr_overhead++; /* Will save dpx on ISR entry. */
199 port->stack.call_overhead++; /* This acounts for the extra byte
200 * of return addres on the stack.
201 * but is ugly. There must be a
205 fReturn = fReturn390;
209 if (options.model == MODEL_LARGE)
211 port->mem.default_local_map = xdata;
212 port->mem.default_globl_map = xdata;
216 port->mem.default_local_map = data;
217 port->mem.default_globl_map = data;
220 if (options.stack10bit)
222 if (options.model != MODEL_FLAT24)
225 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
226 fprintf (stderr, "\t10 bit stack mode disabled.\n");
227 options.stack10bit = 0;
231 /* Fixup the memory map for the stack; it is now in
232 * far space and requires a FPOINTER to access it.
235 istack->ptrType = FPOINTER;
242 _pic14_setDefaultOptions (void)
247 _pic14_getRegName (struct regs *reg)
254 extern char *processor_base_name(void);
257 _pic14_genAssemblerPreamble (FILE * of)
259 char * name = processor_base_name();
264 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
267 fprintf (of, "\tlist\tp=%s\n",&name[1]);
268 fprintf (of, "\tradix dec\n");
269 fprintf (of, "\tinclude \"%s.inc\"\n",name);
272 /* Generate interrupt vector table. */
274 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
278 if (options.model != MODEL_FLAT24)
280 /* Let the default code handle it. */
284 fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
286 /* now for the other interrupts */
287 for (i = 0; i < maxInterrupts; i++)
291 fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
295 fprintf (of, "\t;reti\n\t.ds\t7\n");
303 _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
306 sym_link *test = NULL;
310 fprintf(stderr,"checking for native mult\n");
319 if ( IS_LITERAL (left))
321 fprintf(stderr,"left is lit\n");
323 val = OP_VALUE (IC_LEFT (ic));
325 else if ( IS_LITERAL (right))
327 fprintf(stderr,"right is lit\n");
329 val = OP_VALUE (IC_RIGHT (ic));
333 fprintf(stderr,"oops, neither is lit so no\n");
337 if ( getSize (test) <= 2)
339 fprintf(stderr,"yep\n");
342 fprintf(stderr,"nope\n");
348 /* Indicate which extended bit operations this port supports */
350 hasExtBitOp (int op, int size)
354 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
361 /* Indicate the expense of an access to an output storage class */
363 oclsExpense (struct memmap *oclass)
365 /* The IN_FARSPACE test is compatible with historical behaviour, */
366 /* but I don't think it is applicable to PIC. If so, please feel */
367 /* free to remove this test -- EEP */
368 if (IN_FARSPACE(oclass))
374 /** $1 is always the basename.
375 $2 is always the output file.
377 $l is the list of extra options that should be there somewhere...
378 MUST be terminated with a NULL.
380 static const char *_linkCmd[] =
382 "gplink", "-o $2", "\"$1.o\"", "$l", NULL
385 static const char *_asmCmd[] =
387 "gpasm", "$l", "-c", "\"$1.asm\"", NULL
396 "MCU pic", /* Target name */
400 TRUE, /* Emit glue around main */
401 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
409 //"-plosgffc", /* Options with debug */
410 //"-plosgff", /* Options without debug */
413 NULL /* no do_assemble function */
426 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
427 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
428 /* TSD - I changed the size of gptr from 3 to 1. However, it should be
429 2 so that we can accomodate the PIC's with 4 register banks (like the
450 1 // code is read only
456 /* pic14 has an 8 bit mul */
461 pic14_emitDebuggerSymbol
464 255/3, /* maxCount */
465 3, /* sizeofElement */
466 /* The rest of these costs are bogus. They approximate */
467 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
468 {4,4,4}, /* sizeofMatchJump[] */
469 {0,0,0}, /* sizeofRangeCompare[] */
470 0, /* sizeofSubtract */
471 3, /* sizeofDispatch */
478 _pic14_finaliseOptions,
479 _pic14_setDefaultOptions,
480 pic14_assignRegisters,
483 _pic14_genAssemblerPreamble,
484 NULL, /* no genAssemblerEnd */
486 NULL, // _pic14_genXINIT
487 NULL, /* genInitStartup */
488 _pic14_reset_regparm,
490 _process_pragma, /* process a pragma */
493 hasExtBitOp, /* hasExtBitOp */
494 oclsExpense, /* oclsExpense */
496 // TRUE, /* little endian */
497 FALSE, /* little endian - PIC code enumlates big endian */
500 1, /* transform <= to ! > */
501 1, /* transform >= to ! < */
502 1, /* transform != to !(a == b) */
504 FALSE, /* No array initializer support. */
505 0, /* no CSE cost estimation yet */
506 NULL, /* no builtin functions */
507 GPOINTER, /* treat unqualified pointers as "generic" pointers */
508 1, /* reset labelKey to 1 */
509 1, /* globals & local static allowed */