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.
13 #include "../SDCCutil.h"
14 extern const char *preArgv[128]; /* pre-processor arguments */
15 static char _defaultRules[] =
20 /* list of key words used by msc51 */
21 static char *_ds390_keywords[] =
49 static builtins __ds390_builtins[] = {
50 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
51 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
52 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
53 /* __builtin_inp - used to read from a memory mapped port, increment first pointer */
54 { "__builtin_inp","v",3,{"cx*","cx*","i"}}, /* void __builtin_inp (xdata char *,xdata char *,int) */
55 /* __builtin_inp - used to write to a memory mapped port, increment first pointer */
56 { "__builtin_outp","v",3,{"cx*","cx*","i"}}, /* void __builtin_outp (xdata char *,xdata char *,int) */
57 { "__builtin_swapw","us",1,{"us"}}, /* unsigned short __builtin_swapw (unsigned short) */
58 { "__builtin_memcmp_x2x","c",3,{"cx*","cx*","i"}}, /* void __builtin_memcmp_x2x (xdata char *,xdata char *,int) */
59 { "__builtin_memcmp_c2x","c",3,{"cx*","cp*","i"}}, /* void __builtin_memcmp_c2x (xdata char *,code char *,int) */
60 { NULL , NULL,0, {NULL}} /* mark end of table */
62 void ds390_assignRegisters (eBBlock ** ebbs, int count);
64 static int regParmFlg = 0; /* determine if we can register a parameter */
69 asm_addTree (&asm_asxxxx_mapping);
73 _ds390_reset_regparm ()
79 _ds390_regparm (sym_link * l)
82 if (options.parms_in_bank1 == 0) {
83 /* simple can pass only the first parameter in a register */
90 int size = getSize(l);
93 /* first one goes the usual way to DPTR */
94 if (regParmFlg == 0) {
98 /* second one onwards goes to RB1_0 thru RB1_7 */
99 remain = regParmFlg - 4;
100 if (size > (8 - remain)) {
105 return regParmFlg - size + 1;
110 _ds390_parseOptions (int *pargc, char **argv, int *i)
112 /* TODO: allow port-specific command line options to specify
113 * segment names here.
119 _ds390_finaliseOptions (void)
121 if (options.noXinitOpt) {
125 /* Hack-o-matic: if we are using the flat24 model,
126 * adjust pointer sizes.
128 if (options.model != MODEL_FLAT24) {
130 "*** warning: ds390 port small and large model experimental.\n");
131 if (options.model == MODEL_LARGE)
133 port->mem.default_local_map = xdata;
134 port->mem.default_globl_map = xdata;
138 port->mem.default_local_map = data;
139 port->mem.default_globl_map = data;
143 port->s.fptr_size = 3;
144 port->s.gptr_size = 4;
146 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
148 port->stack.call_overhead += 2; /* This acounts for the extra byte
149 * of return addres on the stack.
150 * but is ugly. There must be a
154 port->mem.default_local_map = xdata;
155 port->mem.default_globl_map = xdata;
157 if (!options.stack10bit)
160 "*** error: ds390 port only supports the 10 bit stack mode.\n");
162 if (!options.stack_loc) options.stack_loc = 0x400008;
165 /* generate native code 16*16 mul/div */
166 if (options.useAccelerator)
167 port->support.muldiv=2;
169 port->support.muldiv=1;
171 /* Fixup the memory map for the stack; it is now in
172 * far space and requires a FPOINTER to access it.
175 istack->ptrType = FPOINTER;
177 if (options.parms_in_bank1) {
178 addToList (preArgv, "-DSDCC_PARMS_IN_BANK1");
184 _ds390_setDefaultOptions (void)
186 options.model=MODEL_FLAT24;
187 options.stack10bit=1;
191 _ds390_getRegName (struct regs *reg)
199 _ds390_genAssemblerPreamble (FILE * of)
201 if (options.model == MODEL_FLAT24)
202 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
204 fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
205 fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of);
206 fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
207 fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
208 fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
209 fputs ("ap = 0x9C\t\t; ap register unknown to assembler\n", of);
210 fputs ("_ap = 0x9C\t\t; _ap register unknown to assembler\n", of);
211 fputs ("mcnt0 = 0xD1\t\t; mcnt0 register unknown to assembler\n", of);
212 fputs ("mcnt1 = 0xD2\t\t; mcnt1 register unknown to assembler\n", of);
213 fputs ("ma = 0xD3\t\t; ma register unknown to assembler\n", of);
214 fputs ("mb = 0xD4\t\t; mb register unknown to assembler\n", of);
215 fputs ("mc = 0xD5\t\t; mc register unknown to assembler\n", of);
216 fputs ("F1 = 0xD1\t\t; F1 user flag unknown to assembler\n", of);
217 fputs ("esp = 0x9B\t\t; ESP user flag unknown to assembler\n", of);
218 if (options.parms_in_bank1) {
220 for (i=0; i < 8 ; i++ )
221 fprintf (of,"b1_%d = 0x%x \n",i,8+i);
225 /* Generate interrupt vector table. */
227 _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
231 if (options.model != MODEL_FLAT24)
233 /* Let the default code handle it. */
237 fprintf (of, "\tajmp\t__reset_vect\n");
239 /* now for the other interrupts */
240 for (i = 0; i < maxInterrupts; i++)
244 fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
248 fprintf (of, "\treti\n\t.ds\t7\n");
252 fprintf (of, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
257 /* Generate code to copy XINIT to XISEG */
258 static void _ds390_genXINIT (FILE * of) {
259 fprintf (of, "; _ds390_genXINIT() start\n");
260 fprintf (of, " mov a,#l_XINIT\n");
261 fprintf (of, " orl a,#l_XINIT>>8\n");
262 fprintf (of, " jz 00003$\n");
263 fprintf (of, " mov a,#s_XINIT\n");
264 fprintf (of, " add a,#l_XINIT\n");
265 fprintf (of, " mov r1,a\n");
266 fprintf (of, " mov a,#s_XINIT>>8\n");
267 fprintf (of, " addc a,#l_XINIT>>8\n");
268 fprintf (of, " mov r2,a\n");
269 fprintf (of, " mov dptr,#s_XINIT\n");
270 fprintf (of, " mov dps,#0x21\n");
271 fprintf (of, " mov dptr,#s_XISEG\n");
272 fprintf (of, "00001$: clr a\n");
273 fprintf (of, " movc a,@a+dptr\n");
274 fprintf (of, " movx @dptr,a\n");
275 fprintf (of, " inc dptr\n");
276 fprintf (of, " inc dptr\n");
277 fprintf (of, "00002$: mov a,dpl\n");
278 fprintf (of, " cjne a,ar1,00001$\n");
279 fprintf (of, " mov a,dph\n");
280 fprintf (of, " cjne a,ar2,00001$\n");
281 fprintf (of, " mov dps,#0\n");
282 fprintf (of, "00003$:\n");
283 fprintf (of, "; _ds390_genXINIT() end\n");
286 /* Do CSE estimation */
287 static bool cseCostEstimation (iCode *ic, iCode *pdic)
289 operand *result = IC_RESULT(ic);
290 //operand *right = IC_RIGHT(ic);
291 //operand *left = IC_LEFT(ic);
292 sym_link *result_type = operandType(result);
293 //sym_link *right_type = (right ? operandType(right) : 0);
294 //sym_link *left_type = (left ? operandType(left) : 0);
296 /* if it is a pointer then return ok for now */
297 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
299 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
300 so we will cse only if they are local (i.e. both ic & pdic belong to
301 the same basic block */
302 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
303 /* then if they are the same Basic block then ok */
304 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
308 /* for others it is cheaper to do the cse */
312 bool _ds390_nativeMulCheck(iCode *ic, sym_link *left, sym_link *right)
314 return FALSE; // #STUB
318 /** $1 is always the basename.
319 $2 is always the output file.
321 $l is the list of extra options that should be there somewhere...
322 MUST be terminated with a NULL.
324 static const char *_linkCmd[] =
326 "aslink", "-nf", "\"$1\"", NULL
329 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ static const char *_asmCmd[] =
331 "asx8051", "$l", "$3", "\"$1.asm\"", NULL
339 "DS80C390", /* Target name */
342 TRUE, /* Emit glue around main */
343 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
349 "-plosgffc", /* Options with debug */
350 "-plosgff", /* Options without debug */
353 NULL /* no do_assemble function */
365 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
366 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
381 "XISEG (XDATA)", // initialized xdata
382 "XINIT (CODE)", // a code copy of xiseg
390 /* ds390 has an 16 bit mul & div */
398 _ds390_finaliseOptions,
399 _ds390_setDefaultOptions,
400 ds390_assignRegisters,
403 _ds390_genAssemblerPreamble,
404 NULL, /* no genAssemblerEnd */
407 _ds390_reset_regparm,
411 _ds390_nativeMulCheck,
415 1, /* transform <= to ! > */
416 1, /* transform >= to ! < */
417 1, /* transform != to !(a == b) */
419 TRUE, /* we support array initializers. */
421 __ds390_builtins, /* table of builtin functions */
422 GPOINTER, /* treat unqualified pointers as "generic" pointers */
423 1, /* reset labelKey to 1 */
424 1, /* globals & local static allowed */
428 /*---------------------------------------------------------------------------------*/
429 /* TININative specific */
430 /*---------------------------------------------------------------------------------*/
432 static void _tininative_init (void)
434 asm_addTree (&asm_a390_mapping);
437 static void _tininative_setDefaultOptions (void)
439 options.model=MODEL_FLAT24;
440 options.stack10bit=1;
441 options.stackAuto = 1;
444 static void _tininative_finaliseOptions (void)
446 /* Hack-o-matic: if we are using the flat24 model,
447 * adjust pointer sizes.
449 if (options.model != MODEL_FLAT24) {
450 options.model = MODEL_FLAT24 ;
451 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
453 port->s.fptr_size = 3;
454 port->s.gptr_size = 4;
456 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
458 port->stack.call_overhead += 2; /* This acounts for the extra byte
459 * of return addres on the stack.
460 * but is ugly. There must be a
464 port->mem.default_local_map = xdata;
465 port->mem.default_globl_map = xdata;
467 if (!options.stack10bit) {
468 options.stack10bit = 1;
469 fprintf(stderr,"TININative supports only stack10bit \n");
472 if (!options.stack_loc) options.stack_loc = 0x400008;
474 /* generate native code 16*16 mul/div */
475 if (options.useAccelerator)
476 port->support.muldiv=2;
478 port->support.muldiv=1;
480 /* Fixup the memory map for the stack; it is now in
481 * far space and requires a FPOINTER to access it.
484 istack->ptrType = FPOINTER;
488 static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
492 static void _tininative_genAssemblerPreamble (FILE * of)
494 fputs("$include(tini.inc)\n", of);
495 fputs("$include(ds80c390.inc)\n", of);
496 fputs("$include(tinimacro.inc)\n", of);
497 fputs("$include(apiequ.inc)\n", of);
498 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
499 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
500 /* Must be first and return 0 */
501 fputs("Lib_Native_Init:\n",of);
502 fputs("\tclr\ta\n",of);
504 fputs("LibraryID:\n",of);
505 fputs("\tdb \"DS\"\n",of);
506 if (options.tini_libid) {
507 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
508 (options.tini_libid>>24 & 0xff),
509 (options.tini_libid>>16 & 0xff),
510 (options.tini_libid>>8 & 0xff),
511 (options.tini_libid & 0xff));
513 fprintf(of,"\tdb 0,0,0,0,0,1\n");
517 static void _tininative_genAssemblerEnd (FILE * of)
521 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
522 static void _tininative_do_assemble (set *asmOptions)
524 static const char *macroCmd[] = {
525 "macro","$1.a51",NULL
527 static const char *a390Cmd[] = {
532 buildCmdLine(buffer,macroCmd,dstFileName,NULL,NULL,NULL);
533 if (my_system(buffer)) {
536 buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions);
537 if (my_system(buffer)) {
542 /* list of key words used by TININative */
543 static char *_tininative_keywords[] =
572 static builtins __tininative_builtins[] = {
573 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
574 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
575 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
577 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
578 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
579 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
580 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
581 /* TINI StateBlock related */
582 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
583 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
584 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
585 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
586 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
587 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
589 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
590 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
591 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
592 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
593 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
594 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
595 /* System functions */
596 { "System_ExecJavaProcess","c",2,{"cx*","i"}}, /* char System_ExecJavaProcess (char *,int) */
597 { "System_GetRTCRegisters","v",1,{"cx*"}}, /* void System_GetRTCRegisters (char *) */
598 { "System_SetRTCRegisters","v",1,{"cx*"}}, /* void System_SetRTCRegisters (char *) */
599 { "System_ThreadSleep","v",2,{"l","c"}}, /* void System_ThreadSleep (long,char) */
600 { "System_ThreadSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ThreadSleep_ExitCriticalSection (long,char) */
601 { "System_ProcessSleep","v",2,{"l","c"}}, /* void System_ProcessSleep (long,char) */
602 { "System_ProcessSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ProcessSleep_ExitCriticalSection (long,char) */
603 { "System_ThreadResume","c",2,{"c","c"}}, /* char System_ThreadResume(char,char) */
604 { "System_SaveJavaThreadState","v",0,{NULL}}, /* void System_SaveJavaThreadState() */
605 { "System_RestoreJavaThreadState","v",0,{NULL}}, /* void System_RestoreJavaThreadState() */
606 { "System_ProcessYield","v",0,{NULL}}, /* void System_ProcessYield() */
607 { "System_ProcessSuspend","v",0,{NULL}}, /* void System_ProcessSuspend() */
608 { "System_ProcessResume","v",1,{"c"}}, /* void System_ProcessResume(char) */
609 { "System_RegisterPoll","c",1,{"vF*"}}, /* char System_RegisterPoll ((void *func pointer)()) */
610 { "System_RemovePoll","c",1,{"vF*"}}, /* char System_RemovePoll ((void *func pointer)()) */
611 { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */
612 { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */
613 { NULL , NULL,0, {NULL}} /* mark end of table */
616 static const char *_a390Cmd[] =
618 "macro", "$l", "$3", "$1.a51", NULL
620 PORT tininative_port =
624 "DS80C390", /* Target name */
625 NULL, /* processor */
627 FALSE, /* Emit glue around main */
634 "-l", /* Options with debug */
635 "-l", /* Options without debug */
638 _tininative_do_assemble
650 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
651 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
675 /* ds390 has an 16 bit mul & div */
683 _tininative_finaliseOptions,
684 _tininative_setDefaultOptions,
685 ds390_assignRegisters,
687 _tininative_keywords,
688 _tininative_genAssemblerPreamble,
689 _tininative_genAssemblerEnd,
692 _ds390_reset_regparm,
700 1, /* transform <= to ! > */
701 1, /* transform >= to ! < */
702 1, /* transform != to !(a == b) */
704 TRUE, /* we support array initializers. */
706 __tininative_builtins, /* table of builtin functions */
707 FPOINTER, /* treat unqualified pointers as far pointers */
708 0, /* DONOT reset labelKey */
709 0, /* globals & local static NOT allowed */
714 _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
716 /* We can't generate a static IVT, since the boot rom creates one
717 * for us in rom_init.
719 * we must patch it as part of the C startup.
721 fprintf (of, ";\tDS80C400 IVT must be generated at runtime.\n");
722 fprintf (of, "\tsjmp\t__sdcc_400boot\n");
723 fprintf (of, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
724 fprintf (of, "\t.db\t0\t; selected bank: zero *should* work...\n");
725 fprintf (of, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
732 _ds400_finaliseOptions (void)
734 if (options.noXinitOpt) {
738 // hackhack: we're a superset of the 390.
739 addToList (preArgv, "-DSDCC_ds390");
740 addToList (preArgv, "-D__ds390");
742 /* Hack-o-matic: if we are using the flat24 model,
743 * adjust pointer sizes.
745 if (options.model != MODEL_FLAT24) {
747 "*** warning: ds400 port small and large model experimental.\n");
748 if (options.model == MODEL_LARGE)
750 port->mem.default_local_map = xdata;
751 port->mem.default_globl_map = xdata;
755 port->mem.default_local_map = data;
756 port->mem.default_globl_map = data;
760 port->s.fptr_size = 3;
761 port->s.gptr_size = 4;
763 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
765 port->stack.call_overhead += 2; /* This acounts for the extra byte
766 * of return addres on the stack.
767 * but is ugly. There must be a
771 port->mem.default_local_map = xdata;
772 port->mem.default_globl_map = xdata;
774 if (!options.stack10bit)
777 "*** error: ds400 port only supports the 10 bit stack mode.\n");
779 if (!options.stack_loc) options.stack_loc = 0xffdc00;
780 // assumes IDM1:0 = 1:0, CMA = 1.
783 /* generate native code 16*16 mul/div */
784 if (options.useAccelerator)
785 port->support.muldiv=2;
787 port->support.muldiv=1;
789 /* Fixup the memory map for the stack; it is now in
790 * far space and requires a FPOINTER to access it.
793 istack->ptrType = FPOINTER;
795 if (options.parms_in_bank1) {
796 addToList (preArgv, "-DSDCC_PARMS_IN_BANK1");
805 "DS80C400", /* Target name */
808 TRUE, /* Emit glue around main */
809 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
815 "-plosgffc", /* Options with debug */
816 "-plosgff", /* Options without debug */
819 NULL /* no do_assemble function */
831 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
832 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
847 "XISEG (XDATA)", // initialized xdata
848 "XINIT (CODE)", // a code copy of xiseg
856 /* ds390 has an 16 bit mul & div */
864 _ds400_finaliseOptions,
865 _ds390_setDefaultOptions,
866 ds390_assignRegisters,
869 _ds390_genAssemblerPreamble,
870 NULL, /* no genAssemblerEnd */
873 _ds390_reset_regparm,
877 _ds390_nativeMulCheck,
881 1, /* transform <= to ! > */
882 1, /* transform >= to ! < */
883 1, /* transform != to !(a == b) */
885 TRUE, /* we support array initializers. */
887 __ds390_builtins, /* table of builtin functions */
888 GPOINTER, /* treat unqualified pointers as "generic" pointers */
889 1, /* reset labelKey to 1 */
890 1, /* globals & local static allowed */