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)
103 _hc08_finaliseOptions (void)
105 if (options.noXinitOpt) {
109 if (options.model == MODEL_LARGE) {
110 port->mem.default_local_map = xdata;
111 port->mem.default_globl_map = xdata;
115 port->mem.default_local_map = data;
116 port->mem.default_globl_map = data;
122 _hc08_setDefaultOptions (void)
124 options.code_loc = 0x8000;
125 options.data_loc = 0x80;
126 options.xdata_loc = 0x100;
127 options.stack_loc = 0x7fff;
128 options.out_fmt = 1; /* use motorola S19 output */
130 options.ommitFramePtr = 1; /* no frame pointer (we use SP */
131 /* offsets instead) */
136 _hc08_getRegName (struct regs *reg)
144 _hc08_genAssemblerPreamble (FILE * of)
148 symbol *mainExists=newSymbol("main", 0);
151 fprintf (of, "\t.area %s\n",port->mem.code_name);
152 fprintf (of, "\t.area %s\n",port->mem.static_name);
153 fprintf (of, "\t.area %s\n",port->mem.post_static_name);
154 fprintf (of, "\t.area %s\n",port->mem.xinit_name);
155 fprintf (of, "\t.area %s\n",port->mem.data_name);
156 fprintf (of, "\t.area %s\n",port->mem.overlay_name);
157 fprintf (of, "\t.area %s\n",port->mem.bit_name);
158 fprintf (of, "\t.area %s\n",port->mem.xdata_name);
159 fprintf (of, "\t.area %s\n",port->mem.xidata_name);
161 if ((mainExists=findSymWithLevel(SymbolTab, mainExists)))
163 // generate interrupt vector table
164 fprintf (of, "\t.area\tCODEIVT (ABS)\n");
166 for (i=maxInterrupts;i>0;i--)
172 fprintf (of, "\t.org\t0x%04x\n", (0xfffe - (i * 2)));
175 fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
181 fprintf (of, "\t.org\t0xfffe\n");
182 fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n\n");
184 fprintf (of, "\t.area GSINIT\n");
185 fprintf (of, "__sdcc_gs_init_startup:\n");
186 if (options.stack_loc)
188 fprintf (of, "\tldhx\t#0x%04x\n", options.stack_loc+1);
189 fprintf (of, "\ttxs\n");
192 fprintf (of, "\trsp\n");
193 fprintf (of, "\tjsr\t__sdcc_external_startup\n");
194 fprintf (of, "\tbeq\t__sdcc_init_data\n");
195 fprintf (of, "\tjmp\t__sdcc_program_startup\n");
196 fprintf (of, "__sdcc_init_data:\n");
198 fprintf (of, "; _hc08_genXINIT() start\n");
199 fprintf (of, " ldhx #0\n");
200 fprintf (of, "00001$:\n");
201 fprintf (of, " cphx #l_XINIT\n");
202 fprintf (of, " beq 00002$\n");
203 fprintf (of, " lda s_XINIT,x\n");
204 fprintf (of, " sta s_XISEG,x\n");
205 fprintf (of, " aix #1\n");
206 fprintf (of, " bra 00001$\n");
207 fprintf (of, "00002$:\n");
208 fprintf (of, "; _hc08_genXINIT() end\n");
210 fprintf (of, "\t.area GSFINAL\n");
211 fprintf (of, "\tjmp\t__sdcc_program_startup\n\n");
213 fprintf (of, "\t.area CSEG\n");
214 fprintf (of, "__sdcc_program_startup:\n");
215 fprintf (of, "\tjsr\t_main\n");
216 fprintf (of, "\tbra\t.\n");
222 _hc08_genExtraAreas (FILE * asmFile, bool mainExists)
224 fprintf (asmFile, "%s", iComments2);
225 fprintf (asmFile, "; extended address mode data\n");
226 fprintf (asmFile, "%s", iComments2);
227 copyFile (asmFile, xdata->oFile);
231 /* Generate interrupt vector table. */
233 _hc08_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
237 fprintf (of, "\t.area\tCODEIVT (ABS)\n");
238 fprintf (of, "\t.org\t0x%04x\n",
239 (0xfffe - (maxInterrupts * 2)));
241 for (i=maxInterrupts;i>0;i--)
244 fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
246 fprintf (of, "\t.dw\t0xffff\n");
248 fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n");
253 /* Generate code to copy XINIT to XISEG */
254 static void _hc08_genXINIT (FILE * of) {
255 fprintf (of, "; _hc08_genXINIT() start\n");
256 fprintf (of, "; _hc08_genXINIT() end\n");
260 /* Do CSE estimation */
261 static bool cseCostEstimation (iCode *ic, iCode *pdic)
263 operand *result = IC_RESULT(ic);
264 sym_link *result_type = operandType(result);
266 return 0; /* disable CSE */
268 /* if it is a pointer then return ok for now */
269 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
271 if (ic->op == ADDRESS_OF)
274 /* if bitwise | add & subtract then no since hc08 is pretty good at it
275 so we will cse only if they are local (i.e. both ic & pdic belong to
276 the same basic block */
277 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
278 /* then if they are the same Basic block then ok */
279 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
283 /* for others it is cheaper to do the cse */
288 /* Indicate which extended bit operations this port supports */
290 hasExtBitOp (int op, int size)
295 || (op == SWAP && size <= 2)
302 /* Indicate the expense of an access to an output storage class */
304 oclsExpense (struct memmap *oclass)
306 /* The hc08's addressing modes allow access to all storage classes */
307 /* inexpensively (<=0) */
309 if (IN_DIRSPACE (oclass)) /* direct addressing mode is fastest */
311 if (IN_FARSPACE (oclass)) /* extended addressing mode is almost at fast */
313 if (oclass == istack) /* stack is the slowest, but still faster than */
314 return 0; /* trying to copy to a temp location elsewhere */
316 return 0; /* anything we missed */
321 /** $1 is always the basename.
322 $2 is always the output file.
324 $l is the list of extra options that should be there somewhere...
325 MUST be terminated with a NULL.
327 static const char *_linkCmd[] =
329 "link-hc08", "-nf", "\"$1\"", NULL
332 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
333 static const char *_asmCmd[] =
335 "as-hc08", "$l", "$3", "\"$1.asm\"", NULL
343 "HC08", /* Target name */
344 NULL, /* Processor name */
347 FALSE, /* Emit glue around main */
348 MODEL_SMALL | MODEL_LARGE,
354 "-plosgffc", /* Options with debug */
355 "-plosgff", /* Options without debug */
358 NULL /* no do_assemble function */
371 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
372 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
387 "XISEG", // initialized xdata
388 "XINIT", // a code copy of xiseg
393 { _hc08_genExtraAreas,
398 /* hc08 has an 8 bit mul */
406 _hc08_finaliseOptions,
407 _hc08_setDefaultOptions,
408 hc08_assignRegisters,
411 _hc08_genAssemblerPreamble,
412 NULL, /* no genAssemblerEnd */
415 NULL, /* genInitStartup */
418 NULL, /* process_pragma */
419 NULL, /* getMangledFunctionName */
420 NULL, /* hasNativeMulFor */
421 hasExtBitOp, /* hasExtBitOp */
422 oclsExpense, /* oclsExpense */
423 TRUE, /* use_dw_for_init */
424 FALSE, /* little endian */
427 1, /* transform <= to ! > */
428 1, /* transform >= to ! < */
429 1, /* transform != to !(a == b) */
431 FALSE, /* No array initializer support. */
433 NULL, /* no builtin functions */
434 GPOINTER, /* treat unqualified pointers as "generic" pointers */
435 1, /* reset labelKey to 1 */
436 1, /* globals & local static allowed */