2 hc08 specific general functions.
4 Note that mlh prepended _hc08_ on the static functions. Makes
5 it easier to set a breakpoint using the debugger.
11 #include "../SDCCutil.h"
13 void copyFile(FILE *dest, FILE *src);
14 extern char * iComments2;
16 static char _defaultRules[] =
21 /* list of key words used by msc51 */
22 static char *_hc08_keywords[] =
52 void hc08_assignRegisters (eBBlock ** ebbs, int count);
54 static int regParmFlg = 0; /* determine if we can register a parameter */
59 asm_addTree (&asm_asxxxx_mapping);
63 _hc08_reset_regparm ()
69 _hc08_regparm (sym_link * l)
71 int size = getSize(l);
73 /* If they fit completely, the first two bytes of parameters can go */
74 /* into A and X, otherwise, they go on the stack. Examples: */
75 /* foo(char p1) A <- p1 */
76 /* foo(char p1, char p2) A <- p1, X <- p2 */
77 /* foo(char p1, char p2, char p3) A <- p1, X <- p2, stack <- p3 */
78 /* foo(int p1) XA <- p1 */
79 /* foo(long p1) stack <- p1 */
80 /* foo(char p1, int p2) A <- p1, stack <- p2 */
81 /* foo(int p1, char p2) XA <- p1, stack <- p2 */
86 if ((regParmFlg+size)>2)
93 return 1+regParmFlg-size;
97 _hc08_parseOptions (int *pargc, char **argv, int *i)
99 if (!strcmp (argv[*i], "--out-fmt-elf"))
108 static OPTION _hc08_options[] =
110 { 0, "--out-fmt-elf", NULL, "Output executable in ELF format" },
115 _hc08_finaliseOptions (void)
117 if (options.noXinitOpt) {
121 if (options.model == MODEL_LARGE) {
122 port->mem.default_local_map = xdata;
123 port->mem.default_globl_map = xdata;
127 port->mem.default_local_map = data;
128 port->mem.default_globl_map = data;
131 istack->ptrType = FPOINTER;
135 _hc08_setDefaultOptions (void)
137 options.code_loc = 0x8000;
138 options.data_loc = 0x80;
139 options.xdata_loc = 0x100;
140 options.stack_loc = 0x7fff;
141 options.out_fmt = 1; /* use motorola S19 output */
143 options.ommitFramePtr = 1; /* no frame pointer (we use SP */
144 /* offsets instead) */
149 _hc08_getRegName (struct regs *reg)
157 _hc08_genAssemblerPreamble (FILE * of)
161 symbol *mainExists=newSymbol("main", 0);
164 fprintf (of, "\t.area %s\n",port->mem.code_name);
165 fprintf (of, "\t.area %s\n",port->mem.static_name);
166 fprintf (of, "\t.area %s\n",port->mem.post_static_name);
167 fprintf (of, "\t.area %s\n",port->mem.xinit_name);
168 fprintf (of, "\t.area %s\n",port->mem.data_name);
169 fprintf (of, "\t.area %s\n",port->mem.overlay_name);
170 fprintf (of, "\t.area %s\n",port->mem.bit_name);
171 fprintf (of, "\t.area %s\n",port->mem.xdata_name);
172 fprintf (of, "\t.area %s\n",port->mem.xidata_name);
174 if ((mainExists=findSymWithLevel(SymbolTab, mainExists)))
176 // generate interrupt vector table
177 fprintf (of, "\t.area\tCODEIVT (ABS)\n");
179 for (i=maxInterrupts;i>0;i--)
185 fprintf (of, "\t.org\t0x%04x\n", (0xfffe - (i * 2)));
188 fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
194 fprintf (of, "\t.org\t0xfffe\n");
195 fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n\n");
197 fprintf (of, "\t.area GSINIT\n");
198 fprintf (of, "__sdcc_gs_init_startup:\n");
199 if (options.stack_loc)
201 fprintf (of, "\tldhx\t#0x%04x\n", options.stack_loc+1);
202 fprintf (of, "\ttxs\n");
205 fprintf (of, "\trsp\n");
206 fprintf (of, "\tjsr\t__sdcc_external_startup\n");
207 fprintf (of, "\tbeq\t__sdcc_init_data\n");
208 fprintf (of, "\tjmp\t__sdcc_program_startup\n");
209 fprintf (of, "__sdcc_init_data:\n");
211 fprintf (of, "; _hc08_genXINIT() start\n");
212 fprintf (of, " ldhx #0\n");
213 fprintf (of, "00001$:\n");
214 fprintf (of, " cphx #l_XINIT\n");
215 fprintf (of, " beq 00002$\n");
216 fprintf (of, " lda s_XINIT,x\n");
217 fprintf (of, " sta s_XISEG,x\n");
218 fprintf (of, " aix #1\n");
219 fprintf (of, " bra 00001$\n");
220 fprintf (of, "00002$:\n");
221 fprintf (of, "; _hc08_genXINIT() end\n");
223 fprintf (of, "\t.area GSFINAL\n");
224 fprintf (of, "\tjmp\t__sdcc_program_startup\n\n");
226 fprintf (of, "\t.area CSEG\n");
227 fprintf (of, "__sdcc_program_startup:\n");
228 fprintf (of, "\tjsr\t_main\n");
229 fprintf (of, "\tbra\t.\n");
235 _hc08_genExtraAreas (FILE * asmFile, bool mainExists)
237 fprintf (asmFile, "%s", iComments2);
238 fprintf (asmFile, "; extended address mode data\n");
239 fprintf (asmFile, "%s", iComments2);
240 copyFile (asmFile, xdata->oFile);
244 /* Generate interrupt vector table. */
246 _hc08_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
250 fprintf (of, "\t.area\tCODEIVT (ABS)\n");
251 fprintf (of, "\t.org\t0x%04x\n",
252 (0xfffe - (maxInterrupts * 2)));
254 for (i=maxInterrupts;i>0;i--)
257 fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
259 fprintf (of, "\t.dw\t0xffff\n");
261 fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n");
266 /* Generate code to copy XINIT to XISEG */
267 static void _hc08_genXINIT (FILE * of) {
268 fprintf (of, "; _hc08_genXINIT() start\n");
269 fprintf (of, "; _hc08_genXINIT() end\n");
273 /* Do CSE estimation */
274 static bool cseCostEstimation (iCode *ic, iCode *pdic)
276 operand *result = IC_RESULT(ic);
277 sym_link *result_type = operandType(result);
279 return 0; /* disable CSE */
281 /* if it is a pointer then return ok for now */
282 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
284 if (ic->op == ADDRESS_OF)
287 /* if bitwise | add & subtract then no since hc08 is pretty good at it
288 so we will cse only if they are local (i.e. both ic & pdic belong to
289 the same basic block */
290 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
291 /* then if they are the same Basic block then ok */
292 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
296 /* for others it is cheaper to do the cse */
301 /* Indicate which extended bit operations this port supports */
303 hasExtBitOp (int op, int size)
308 || (op == SWAP && size <= 2)
315 /* Indicate the expense of an access to an output storage class */
317 oclsExpense (struct memmap *oclass)
319 /* The hc08's addressing modes allow access to all storage classes */
320 /* inexpensively (<=0) */
322 if (IN_DIRSPACE (oclass)) /* direct addressing mode is fastest */
324 if (IN_FARSPACE (oclass)) /* extended addressing mode is almost at fast */
326 if (oclass == istack) /* stack is the slowest, but still faster than */
327 return 0; /* trying to copy to a temp location elsewhere */
329 return 0; /* anything we missed */
334 /** $1 is always the basename.
335 $2 is always the output file.
337 $l is the list of extra options that should be there somewhere...
338 MUST be terminated with a NULL.
340 static const char *_linkCmd[] =
342 "link-hc08", "-nf", "\"$1\"", NULL
345 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
346 static const char *_asmCmd[] =
348 "as-hc08", "$l", "$3", "\"$1.asm\"", NULL
356 "HC08", /* Target name */
357 NULL, /* Processor name */
360 FALSE, /* Emit glue around main */
361 MODEL_SMALL | MODEL_LARGE,
367 "-plosgffc", /* Options with debug */
368 "-plosgff", /* Options without debug */
371 NULL /* no do_assemble function */
384 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
385 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
400 "XISEG", // initialized xdata
401 "XINIT", // a code copy of xiseg
406 { _hc08_genExtraAreas,
411 /* hc08 has an 8 bit mul */
419 _hc08_finaliseOptions,
420 _hc08_setDefaultOptions,
421 hc08_assignRegisters,
424 _hc08_genAssemblerPreamble,
425 NULL, /* no genAssemblerEnd */
428 NULL, /* genInitStartup */
431 NULL, /* process_pragma */
432 NULL, /* getMangledFunctionName */
433 NULL, /* hasNativeMulFor */
434 hasExtBitOp, /* hasExtBitOp */
435 oclsExpense, /* oclsExpense */
436 TRUE, /* use_dw_for_init */
437 FALSE, /* little endian */
440 1, /* transform <= to ! > */
441 1, /* transform >= to ! < */
442 1, /* transform != to !(a == b) */
444 FALSE, /* No array initializer support. */
446 NULL, /* no builtin functions */
447 GPOINTER, /* treat unqualified pointers as "generic" pointers */
448 1, /* reset labelKey to 1 */
449 1, /* globals & local static allowed */