2 ds390 specific general functions.
4 Note that mlh prepended _ds390_ on the static functions. Makes
5 it easier to set a breakpoint using the debugger.
14 static char _defaultRules[] =
19 /* list of key words used by msc51 */
20 static char *_ds390_keywords[] =
48 static builtins __ds390_builtins[] = {
49 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
50 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
51 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
52 { NULL , NULL,0, {NULL}} /* mark end of table */
54 void ds390_assignRegisters (eBBlock ** ebbs, int count);
56 static int regParmFlg = 0; /* determine if we can register a parameter */
61 asm_addTree (&asm_asxxxx_mapping);
65 _ds390_reset_regparm ()
71 _ds390_regparm (sym_link * l)
73 /* for this processor it is simple
74 can pass only the first parameter in a register */
83 _ds390_parseOptions (int *pargc, char **argv, int *i)
85 /* TODO: allow port-specific command line options to specify
92 _ds390_finaliseOptions (void)
94 /* Hack-o-matic: if we are using the flat24 model,
95 * adjust pointer sizes.
97 if (options.model != MODEL_FLAT24) {
99 "*** warning: ds390 port small and large model experimental.\n");
100 if (options.model == MODEL_LARGE)
102 port->mem.default_local_map = xdata;
103 port->mem.default_globl_map = xdata;
107 port->mem.default_local_map = data;
108 port->mem.default_globl_map = data;
112 port->s.fptr_size = 3;
113 port->s.gptr_size = 4;
115 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
117 port->stack.call_overhead += 2; /* This acounts for the extra byte
118 * of return addres on the stack.
119 * but is ugly. There must be a
123 port->mem.default_local_map = xdata;
124 port->mem.default_globl_map = xdata;
126 if (!options.stack10bit)
129 "*** error: ds390 port only supports the 10 bit stack mode.\n");
131 if (!options.stack_loc) options.stack_loc = 0x400007;
134 /* generate native code 16*16 mul/div */
135 if (options.useAccelerator)
136 port->support.muldiv=2;
138 port->support.muldiv=1;
140 /* Fixup the memory map for the stack; it is now in
141 * far space and requires a FPOINTER to access it.
144 istack->ptrType = FPOINTER;
149 _ds390_setDefaultOptions (void)
151 options.model=MODEL_FLAT24;
152 options.stack10bit=1;
156 _ds390_getRegName (struct regs *reg)
164 _ds390_genAssemblerPreamble (FILE * of)
166 if (options.model == MODEL_FLAT24)
167 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
169 fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
170 fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of);
171 fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
172 fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
173 fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
174 fputs ("ap = 0x9C\t\t; ap register unknown to assembler\n", of);
175 fputs ("_ap = 0x9C\t\t; _ap register unknown to assembler\n", of);
176 fputs ("mcnt0 = 0xD1\t\t; mcnt0 register unknown to assembler\n", of);
177 fputs ("mcnt1 = 0xD2\t\t; mcnt1 register unknown to assembler\n", of);
178 fputs ("ma = 0xD3\t\t; ma register unknown to assembler\n", of);
179 fputs ("mb = 0xD4\t\t; mb register unknown to assembler\n", of);
180 fputs ("mc = 0xD5\t\t; mc register unknown to assembler\n", of);
181 fputs ("F1 = 0xD1\t\t; F1 user flag unknown to assembler\n", of);
182 fputs ("esp = 0x9B\t\t; ESP user flag unknown to assembler\n", of);
185 /* Generate interrupt vector table. */
187 _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
191 if (options.model != MODEL_FLAT24)
193 /* Let the default code handle it. */
197 fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
199 /* now for the other interrupts */
200 for (i = 0; i < maxInterrupts; i++)
204 fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
208 fprintf (of, "\treti\n\t.ds\t7\n");
215 /* Generate code to copy XINIT to XISEG */
216 static void _ds390_genXINIT (FILE * of) {
217 fprintf (of, "; _ds390_genXINIT() start\n");
218 fprintf (of, " mov a,#l_XINIT\n");
219 fprintf (of, " orl a,#l_XINIT>>8\n");
220 fprintf (of, " jz 00003$\n");
221 fprintf (of, " mov a,#s_XINIT\n");
222 fprintf (of, " add a,#l_XINIT\n");
223 fprintf (of, " mov r1,a\n");
224 fprintf (of, " mov a,#s_XINIT>>8\n");
225 fprintf (of, " addc a,#l_XINIT>>8\n");
226 fprintf (of, " mov r2,a\n");
227 fprintf (of, " mov dptr,#s_XINIT\n");
228 fprintf (of, " mov dps,#0x21\n");
229 fprintf (of, " mov dptr,#s_XISEG\n");
230 fprintf (of, "00001$: clr a\n");
231 fprintf (of, " movc a,@a+dptr\n");
232 fprintf (of, " movx @dptr,a\n");
233 fprintf (of, " inc dptr\n");
234 fprintf (of, " inc dptr\n");
235 fprintf (of, "00002$: mov a,dpl\n");
236 fprintf (of, " cjne a,ar1,00001$\n");
237 fprintf (of, " mov a,dph\n");
238 fprintf (of, " cjne a,ar2,00001$\n");
239 fprintf (of, " mov dps,#0\n");
240 fprintf (of, "00003$:\n");
241 fprintf (of, "; _ds390_genXINIT() end\n");
244 /* Do CSE estimation */
245 static bool cseCostEstimation (iCode *ic, iCode *pdic)
247 operand *result = IC_RESULT(ic);
248 //operand *right = IC_RIGHT(ic);
249 //operand *left = IC_LEFT(ic);
250 sym_link *result_type = operandType(result);
251 //sym_link *right_type = (right ? operandType(right) : 0);
252 //sym_link *left_type = (left ? operandType(left) : 0);
254 /* if it is a pointer then return ok for now */
255 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
257 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
258 so we will cse only if they are local (i.e. both ic & pdic belong to
259 the same basic block */
260 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
261 /* then if they are the same Basic block then ok */
262 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
266 /* for others it is cheaper to do the cse */
269 /** $1 is always the basename.
270 $2 is always the output file.
272 $l is the list of extra options that should be there somewhere...
273 MUST be terminated with a NULL.
275 static const char *_linkCmd[] =
277 "aslink", "-nf", "$1", NULL
280 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ static const char *_asmCmd[] =
282 "asx8051", "$l", "$3", "$1.asm", NULL
290 "DS80C390", /* Target name */
292 TRUE, /* Emit glue around main */
293 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
299 "-plosgffc", /* Options with debug */
300 "-plosgff", /* Options without debug */
303 NULL /* no do_assemble function */
315 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
316 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
331 "XISEG (XDATA)", // initialized xdata
332 "XINIT (CODE)", // a code copy of xiseg
340 /* ds390 has an 16 bit mul & div */
347 _ds390_finaliseOptions,
348 _ds390_setDefaultOptions,
349 ds390_assignRegisters,
352 _ds390_genAssemblerPreamble,
353 NULL, /* no genAssemblerEnd */
356 _ds390_reset_regparm,
364 1, /* transform <= to ! > */
365 1, /* transform >= to ! < */
366 1, /* transform != to !(a == b) */
368 TRUE, /* we support array initializers. */
370 __ds390_builtins, /* table of builtin functions */
371 GPOINTER, /* treat unqualified pointers as "generic" pointers */
372 1, /* reset labelKey to 1 */
373 1, /* globals & local static allowed */
377 /*---------------------------------------------------------------------------------*/
378 /* TININative specific */
379 /*---------------------------------------------------------------------------------*/
381 static void _tininative_init (void)
383 asm_addTree (&asm_a390_mapping);
386 static void _tininative_setDefaultOptions (void)
388 options.model=MODEL_FLAT24;
389 options.stack10bit=1;
390 options.stackAuto = 1;
393 static void _tininative_finaliseOptions (void)
395 /* Hack-o-matic: if we are using the flat24 model,
396 * adjust pointer sizes.
398 if (options.model != MODEL_FLAT24) {
399 options.model = MODEL_FLAT24 ;
400 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
402 port->s.fptr_size = 3;
403 port->s.gptr_size = 4;
405 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
407 port->stack.call_overhead += 2; /* This acounts for the extra byte
408 * of return addres on the stack.
409 * but is ugly. There must be a
413 port->mem.default_local_map = xdata;
414 port->mem.default_globl_map = xdata;
416 if (!options.stack10bit) {
417 options.stack10bit = 1;
418 fprintf(stderr,"TININative supports only stack10bit \n");
421 if (!options.stack_loc) options.stack_loc = 0x400007;
423 /* generate native code 16*16 mul/div */
424 if (options.useAccelerator)
425 port->support.muldiv=2;
427 port->support.muldiv=1;
429 /* Fixup the memory map for the stack; it is now in
430 * far space and requires a FPOINTER to access it.
433 istack->ptrType = FPOINTER;
437 static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
441 static void _tininative_genAssemblerPreamble (FILE * of)
443 fputs("$include(tini.inc)\n", of);
444 fputs("$include(ds80c390.inc)\n", of);
445 fputs("$include(tinimacro.inc)\n", of);
446 fputs("$include(apiequ.inc)\n", of);
447 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
448 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
449 /* Must be first and return 0 */
450 fputs("Lib_Native_Init:\n",of);
451 fputs("\tclr\ta\n",of);
453 fputs("LibraryID:\n",of);
454 fputs("\tdb \"DS\"\n",of);
455 if (options.tini_libid) {
456 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
457 (options.tini_libid>>24 & 0xff),
458 (options.tini_libid>>16 & 0xff),
459 (options.tini_libid>>8 & 0xff),
460 (options.tini_libid & 0xff));
462 fprintf(of,"\tdb 0,0,0,0,0,1\n");
466 static void _tininative_genAssemblerEnd (FILE * of)
470 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
471 static void _tininative_do_assemble (const char * const *asmOptions)
473 static const char *macroCmd[] = {
474 "macro","$1.a51",NULL
476 static const char *a390Cmd[] = {
481 buildCmdLine(buffer,macroCmd,srcFileName,NULL,NULL,NULL);
482 if (my_system(buffer)) {
485 buildCmdLine(buffer,a390Cmd,srcFileName,NULL,NULL,asmOptions);
486 if (my_system(buffer)) {
491 /* list of key words used by TININative */
492 static char *_tininative_keywords[] =
521 static builtins __tininative_builtins[] = {
522 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
523 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
524 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
526 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
527 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
528 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
529 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
530 /* TINI StateBlock related */
531 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
532 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
533 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
534 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
535 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
536 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
538 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
539 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
540 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
541 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
542 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
543 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
544 { "MM_AppTag","c",2,{"i","c"}}, /* char *MM_AppTag (int,char) */
545 { NULL , NULL,0, {NULL}} /* mark end of table */
548 static const char *_a390Cmd[] =
550 "macro", "$l", "$3", "$1.a51", NULL
552 PORT tininative_port =
556 "DS80C390", /* Target name */
558 FALSE, /* Emit glue around main */
565 "-l", /* Options with debug */
566 "-l", /* Options without debug */
569 _tininative_do_assemble
581 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
582 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
606 /* ds390 has an 16 bit mul & div */
613 _tininative_finaliseOptions,
614 _tininative_setDefaultOptions,
615 ds390_assignRegisters,
617 _tininative_keywords,
618 _tininative_genAssemblerPreamble,
619 _tininative_genAssemblerEnd,
622 _ds390_reset_regparm,
630 1, /* transform <= to ! > */
631 1, /* transform >= to ! < */
632 1, /* transform != to !(a == b) */
634 TRUE, /* we support array initializers. */
636 __tininative_builtins, /* table of builtin functions */
637 FPOINTER, /* treat unqualified pointers as far pointers */
638 0, /* DONOT reset labelKey */
639 0, /* globals & local static NOT allowed */