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 #include "../SDCCglobl.h"
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 (ebbIndex * ebbi);
64 static int regParmFlg = 0; /* determine if we can register a parameter */
69 asm_addTree (&asm_asxxxx_mapping);
73 _ds390_reset_regparm (void)
79 _ds390_regparm (sym_link * l, bool reentrant)
81 if (IS_SPEC(l) && (SPEC_NOUN(l) == V_BIT))
83 if (options.parms_in_bank1 == 0) {
84 /* simple can pass only the first parameter in a register */
91 int size = getSize(l);
94 /* first one goes the usual way to DPTR */
95 if (regParmFlg == 0) {
99 /* second one onwards goes to RB1_0 thru RB1_7 */
100 remain = regParmFlg - 4;
101 if (size > (8 - remain)) {
106 return regParmFlg - size + 1;
111 _ds390_parseOptions (int *pargc, char **argv, int *i)
113 /* TODO: allow port-specific command line options to specify
114 * segment names here.
120 _ds390_finaliseOptions (void)
122 if (options.noXinitOpt) {
126 /* Hack-o-matic: if we are using the flat24 model,
127 * adjust pointer sizes.
129 if (options.model != MODEL_FLAT24) {
131 "*** warning: ds390 port small and large model experimental.\n");
132 if (options.model == MODEL_LARGE)
134 port->mem.default_local_map = xdata;
135 port->mem.default_globl_map = xdata;
139 port->mem.default_local_map = data;
140 port->mem.default_globl_map = data;
144 port->s.fptr_size = 3;
145 port->s.gptr_size = 4;
147 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
149 port->stack.call_overhead += 2; /* This acounts for the extra byte
150 * of return addres on the stack.
151 * but is ugly. There must be a
155 port->mem.default_local_map = xdata;
156 port->mem.default_globl_map = xdata;
158 if (!options.stack10bit)
161 "*** error: ds390 port only supports the 10 bit stack mode.\n");
163 if (!options.stack_loc) options.stack_loc = 0x400008;
166 /* generate native code 16*16 mul/div */
167 if (options.useAccelerator)
168 port->support.muldiv=2;
170 port->support.muldiv=1;
172 /* Fixup the memory map for the stack; it is now in
173 * far space and requires a FPOINTER to access it.
176 istack->ptrType = FPOINTER;
178 if (options.parms_in_bank1) {
179 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
185 _ds390_setDefaultOptions (void)
187 options.model=MODEL_FLAT24;
188 options.stack10bit=1;
192 _ds390_getRegName (struct regs *reg)
199 extern char * iComments2;
202 _ds390_genAssemblerPreamble (FILE * of)
204 fputs (iComments2, of);
205 fputs ("; CPU specific extensions\n",of);
206 fputs (iComments2, of);
208 if (options.model == MODEL_FLAT24)
209 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
211 fputs ("dpl1\t=\t0x84\n", of);
212 fputs ("dph1\t=\t0x85\n", of);
213 fputs ("dps\t=\t0x86\n", of);
214 fputs ("dpx\t=\t0x93\n", of);
215 fputs ("dpx1\t=\t0x95\n", of);
216 fputs ("esp\t=\t0x9B\n", of);
217 fputs ("ap\t=\t0x9C\n", of);
218 fputs ("_ap\t=\t0x9C\n", of);
219 fputs ("mcnt0\t=\t0xD1\n", of);
220 fputs ("mcnt1\t=\t0xD2\n", of);
221 fputs ("ma\t=\t0xD3\n", of);
222 fputs ("mb\t=\t0xD4\n", of);
223 fputs ("mc\t=\t0xD5\n", of);
224 fputs ("F1\t=\t0xD1\t; user flag\n", of);
225 if (options.parms_in_bank1) {
227 for (i=0; i < 8 ; i++ )
228 fprintf (of,"b1_%d\t=\t0x%02X\n",i,8+i);
232 /* Generate interrupt vector table. */
234 _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
238 if (options.model != MODEL_FLAT24)
240 fprintf (of, "\tljmp\t__sdcc_gsinit_startup\n");
242 /* now for the other interrupts */
243 for (i = 0; i < maxInterrupts; i++)
247 fprintf (of, "\tljmp\t%s\n", interrupts[i]->rname);
248 if ( i != maxInterrupts - 1 )
249 fprintf (of, "\t.ds\t5\n");
253 fprintf (of, "\treti\n");
254 if ( i != maxInterrupts - 1 )
255 fprintf (of, "\t.ds\t7\n");
261 fprintf (of, "\tajmp\t__reset_vect\n");
263 /* now for the other interrupts */
264 for (i = 0; i < maxInterrupts; i++)
268 fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
272 fprintf (of, "\treti\n\t.ds\t7\n");
276 fprintf (of, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
281 /* Generate code to copy XINIT to XISEG */
282 static void _ds390_genXINIT (FILE * of) {
283 fprintf (of, "; _ds390_genXINIT() start\n");
284 fprintf (of, " mov a,#l_XINIT\n");
285 fprintf (of, " orl a,#l_XINIT>>8\n");
286 fprintf (of, " jz 00003$\n");
287 fprintf (of, " mov a,#s_XINIT\n");
288 fprintf (of, " add a,#l_XINIT\n");
289 fprintf (of, " mov r1,a\n");
290 fprintf (of, " mov a,#s_XINIT>>8\n");
291 fprintf (of, " addc a,#l_XINIT>>8\n");
292 fprintf (of, " mov r2,a\n");
293 fprintf (of, " mov dptr,#s_XINIT\n");
294 fprintf (of, " mov dps,#0x21\n");
295 fprintf (of, " mov dptr,#s_XISEG\n");
296 fprintf (of, "00001$: clr a\n");
297 fprintf (of, " movc a,@a+dptr\n");
298 fprintf (of, " movx @dptr,a\n");
299 fprintf (of, " inc dptr\n");
300 fprintf (of, " inc dptr\n");
301 fprintf (of, "00002$: mov a,dpl\n");
302 fprintf (of, " cjne a,ar1,00001$\n");
303 fprintf (of, " mov a,dph\n");
304 fprintf (of, " cjne a,ar2,00001$\n");
305 fprintf (of, " mov dps,#0\n");
306 fprintf (of, "00003$:\n");
307 fprintf (of, "; _ds390_genXINIT() end\n");
310 /* Do CSE estimation */
311 static bool cseCostEstimation (iCode *ic, iCode *pdic)
313 operand *result = IC_RESULT(ic);
314 //operand *right = IC_RIGHT(ic);
315 //operand *left = IC_LEFT(ic);
316 sym_link *result_type = operandType(result);
317 //sym_link *right_type = (right ? operandType(right) : 0);
318 //sym_link *left_type = (left ? operandType(left) : 0);
320 /* if it is a pointer then return ok for now */
321 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
323 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
324 so we will cse only if they are local (i.e. both ic & pdic belong to
325 the same basic block */
326 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
327 /* then if they are the same Basic block then ok */
328 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
332 /* for others it is cheaper to do the cse */
336 bool _ds390_nativeMulCheck(iCode *ic, sym_link *left, sym_link *right)
338 return FALSE; // #STUB
341 /* Indicate which extended bit operations this port supports */
343 hasExtBitOp (int op, int size)
348 || (op == SWAP && size <= 2)
355 /* Indicate the expense of an access to an output storage class */
357 oclsExpense (struct memmap *oclass)
359 if (IN_FARSPACE(oclass))
366 instructionSize(char *inst, char *op1, char *op2)
368 int isflat24 = (options.model == MODEL_FLAT24);
370 #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
371 #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0')
372 #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0')
373 #define IS_Rn(s) (*(s) == 'r' && *(s+1) >= '0' && *(s+1) <= '7')
374 #define IS_atRi(s) (*(s) == '@' && *(s+1) == 'r')
376 /* Based on the current (2003-08-22) code generation for the
377 small library, the top instruction probability is:
388 /* mov, push, & pop are the 69% of the cases. Check them first! */
391 if (*(inst+3)=='x') return 1; /* movx */
392 if (*(inst+3)=='c') return 1; /* movc */
393 if (IS_C (op1) || IS_C (op2)) return 2;
396 if (IS_Rn (op2) || IS_atRi (op2)) return 1;
399 if (IS_Rn(op1) || IS_atRi(op1))
401 if (IS_A(op2)) return 1;
404 if (strcmp (op1, "dptr") == 0) return 3+isflat24;
405 if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2;
409 if (ISINST ("push")) return 2;
410 if (ISINST ("pop")) return 2;
412 if (ISINST ("lcall")) return 3+isflat24;
413 if (ISINST ("ret")) return 1;
414 if (ISINST ("ljmp")) return 3+isflat24;
415 if (ISINST ("sjmp")) return 2;
416 if (ISINST ("rlc")) return 1;
417 if (ISINST ("rrc")) return 1;
418 if (ISINST ("rl")) return 1;
419 if (ISINST ("rr")) return 1;
420 if (ISINST ("swap")) return 1;
421 if (ISINST ("jc")) return 2;
422 if (ISINST ("jnc")) return 2;
423 if (ISINST ("jb")) return 3;
424 if (ISINST ("jnb")) return 3;
425 if (ISINST ("jbc")) return 3;
426 if (ISINST ("jmp")) return 1; // always jmp @a+dptr
427 if (ISINST ("jz")) return 2;
428 if (ISINST ("jnz")) return 2;
429 if (ISINST ("cjne")) return 3;
430 if (ISINST ("mul")) return 1;
431 if (ISINST ("div")) return 1;
432 if (ISINST ("da")) return 1;
433 if (ISINST ("xchd")) return 1;
434 if (ISINST ("reti")) return 1;
435 if (ISINST ("nop")) return 1;
436 if (ISINST ("acall")) return 2+isflat24;
437 if (ISINST ("ajmp")) return 2+isflat24;
440 if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch"))
442 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
445 if (ISINST ("inc") || ISINST ("dec"))
447 if (IS_A(op1) || IS_Rn(op1) || IS_atRi(op1)) return 1;
448 if (strcmp(op1, "dptr") == 0) return 1;
451 if (ISINST ("anl") || ISINST ("orl") || ISINST ("xrl"))
453 if (IS_C(op1)) return 2;
456 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
461 if (IS_A(op2)) return 2;
465 if (ISINST ("clr") || ISINST ("setb") || ISINST ("cpl"))
467 if (IS_A(op1) || IS_C(op1)) return 1;
472 if (IS_Rn(op1)) return 2;
476 /* If the instruction is unrecognized, we shouldn't try to optimize. */
477 /* Return a large value to discourage optimization. */
482 ds390newAsmLineNode (int currentDPS)
486 aln = Safe_alloc ( sizeof (asmLineNode));
488 aln->regsRead = NULL;
489 aln->regsWritten = NULL;
490 aln->initialized = 0;
491 aln->currentDPS = currentDPS;
497 typedef struct ds390operanddata
505 static ds390operanddata ds390operandDataTable[] =
509 {"ab", A_IDX, B_IDX},
524 {"dph", DPH_IDX, -1},
525 {"dph0", DPH_IDX, -1},
526 {"dph1", DPH1_IDX, -1},
527 {"dpl", DPL_IDX, -1},
528 {"dpl0", DPL_IDX, -1},
529 {"dpl1", DPL1_IDX, -1},
530 /* {"dptr", DPL_IDX, DPH_IDX}, */ /* dptr is special, based on currentDPS */
531 {"dps", DPS_IDX, -1},
532 {"dpx", DPX_IDX, -1},
533 {"dpx0", DPX_IDX, -1},
534 {"dpx1", DPX1_IDX, -1},
539 {"psw", CND_IDX, -1},
551 ds390operandCompare (const void *key, const void *member)
553 return strcmp((const char *)key, ((ds390operanddata *)member)->name);
557 updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS)
559 ds390operanddata *opdat;
565 dot = strchr(op, '.');
569 opdat = bsearch (op, ds390operandDataTable,
570 sizeof(ds390operandDataTable)/sizeof(ds390operanddata),
571 sizeof(ds390operanddata), ds390operandCompare);
575 regIdx1 = opdat->regIdx1;
576 regIdx2 = opdat->regIdx2;
578 if (!strcmp(op, "dptr"))
594 if (strchr(optype,'r'))
597 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx1);
599 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx2);
601 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx3);
603 if (strchr(optype,'w'))
606 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx1);
608 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx2);
610 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx3);
614 if (!strcmp(op, "@r0"))
615 aln->regsRead = bitVectSetBit (aln->regsRead, R0_IDX);
616 if (!strcmp(op, "@r1"))
617 aln->regsRead = bitVectSetBit (aln->regsRead, R1_IDX);
618 if (strstr(op, "dptr"))
622 aln->regsRead = bitVectSetBit (aln->regsRead, DPL_IDX);
623 aln->regsRead = bitVectSetBit (aln->regsRead, DPH_IDX);
624 aln->regsRead = bitVectSetBit (aln->regsRead, DPX_IDX);
628 aln->regsRead = bitVectSetBit (aln->regsRead, DPL1_IDX);
629 aln->regsRead = bitVectSetBit (aln->regsRead, DPH1_IDX);
630 aln->regsRead = bitVectSetBit (aln->regsRead, DPX1_IDX);
633 if (strstr(op, "a+"))
634 aln->regsRead = bitVectSetBit (aln->regsRead, A_IDX);
638 typedef struct ds390opcodedata
648 static ds390opcodedata ds390opcodeDataTable[] =
650 {"acall","j", "", "", ""},
651 {"add", "", "w", "rw", "r"},
652 {"addc", "", "rw", "rw", "r"},
653 {"ajmp", "j", "", "", ""},
654 {"anl", "", "", "rw", "r"},
655 {"cjne", "j", "w", "r", "r"},
656 {"clr", "", "", "w", ""},
657 {"cpl", "", "", "rw", ""},
658 {"da", "", "rw", "rw", ""},
659 {"dec", "", "", "rw", ""},
660 {"div", "", "w", "rw", ""},
661 {"djnz", "j", "", "rw", ""},
662 {"inc", "", "", "rw", ""},
663 {"jb", "j", "", "r", ""},
664 {"jbc", "j", "", "rw", ""},
665 {"jc", "j", "", "", ""},
666 {"jmp", "j", "", "", ""},
667 {"jnb", "j", "", "r", ""},
668 {"jnc", "j", "", "", ""},
669 {"jnz", "j", "", "", ""},
670 {"jz", "j", "", "", ""},
671 {"lcall","j", "", "", ""},
672 {"ljmp", "j", "", "", ""},
673 {"mov", "", "", "w", "r"},
674 {"movc", "", "", "w", "r"},
675 {"movx", "", "", "w", "r"},
676 {"mul", "", "w", "rw", ""},
677 {"nop", "", "", "", ""},
678 {"orl", "", "", "rw", "r"},
679 {"pop", "", "", "w", ""},
680 {"push", "", "", "r", ""},
681 {"ret", "j", "", "", ""},
682 {"reti", "j", "", "", ""},
683 {"rl", "", "", "rw", ""},
684 {"rlc", "", "rw", "rw", ""},
685 {"rr", "", "", "rw", ""},
686 {"rrc", "", "rw", "rw", ""},
687 {"setb", "", "", "w", ""},
688 {"sjmp", "j", "", "", ""},
689 {"subb", "", "rw", "rw", "r"},
690 {"swap", "", "", "rw", ""},
691 {"xch", "", "", "rw", "rw"},
692 {"xchd", "", "", "rw", "rw"},
693 {"xrl", "", "", "rw", "r"},
697 ds390opcodeCompare (const void *key, const void *member)
699 return strcmp((const char *)key, ((ds390opcodedata *)member)->name);
703 asmLineNodeFromLineNode (lineNode *ln, int currentDPS)
705 asmLineNode *aln = ds390newAsmLineNode(currentDPS);
706 char *op, op1[256], op2[256];
708 const unsigned char *p;
710 ds390opcodedata *opdat;
712 aln->initialized = 1;
716 while (*p && isspace(*p)) p++;
717 for (op = inst, opsize=1; *p; p++)
719 if (isspace(*p) || *p == ';' || *p == ':' || *p == '=')
722 if (opsize < sizeof(inst))
723 *op++ = tolower(*p), opsize++;
727 if (*p == ';' || *p == ':' || *p == '=')
730 while (*p && isspace(*p)) p++;
734 for (op = op1, opsize=1; *p && *p != ','; p++)
736 if (!isspace(*p) && opsize < sizeof(op1))
737 *op++ = tolower(*p), opsize++;
742 for (op = op2, opsize=1; *p && *p != ','; p++)
744 if (!isspace(*p) && opsize < sizeof(op2))
745 *op++ = tolower(*p), opsize++;
749 aln->size = instructionSize(inst, op1, op2);
751 aln->regsRead = newBitVect (END_IDX);
752 aln->regsWritten = newBitVect (END_IDX);
754 opdat = bsearch (inst, ds390opcodeDataTable,
755 sizeof(ds390opcodeDataTable)/sizeof(ds390opcodedata),
756 sizeof(ds390opcodedata), ds390opcodeCompare);
760 updateOpRW (aln, op1, opdat->op1type, currentDPS);
761 updateOpRW (aln, op2, opdat->op2type, currentDPS);
762 if (strchr(opdat->pswtype,'r'))
763 aln->regsRead = bitVectSetBit (aln->regsRead, CND_IDX);
764 if (strchr(opdat->pswtype,'w'))
765 aln->regsWritten = bitVectSetBit (aln->regsWritten, CND_IDX);
772 initializeAsmLineNode (lineNode *line)
775 line->aln = asmLineNodeFromLineNode (line, 0);
776 else if (line->aln && !line->aln->initialized)
778 int currentDPS = line->aln->currentDPS;
780 line->aln = asmLineNodeFromLineNode (line, currentDPS);
785 getInstructionSize (lineNode *line)
787 initializeAsmLineNode (line);
788 return line->aln->size;
792 getRegsRead (lineNode *line)
794 initializeAsmLineNode (line);
795 return line->aln->regsRead;
799 getRegsWritten (lineNode *line)
801 initializeAsmLineNode (line);
802 return line->aln->regsWritten;
806 /** $1 is always the basename.
807 $2 is always the output file.
809 $l is the list of extra options that should be there somewhere...
810 MUST be terminated with a NULL.
812 static const char *_linkCmd[] =
814 "aslink", "-nf", "\"$1\"", NULL
817 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
818 static const char *_asmCmd[] =
820 "asx8051", "$l", "$3", "\"$1.asm\"", NULL
828 "DS80C390", /* Target name */
832 TRUE, /* Emit glue around main */
833 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
839 "-plosgffc", /* Options with debug */
840 "-plosgff", /* Options without debug */
843 NULL /* no do_assemble function */
859 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
860 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
876 "XISEG (XDATA)", // initialized xdata
877 "XINIT (CODE)", // a code copy of xiseg
878 "CONST (CODE)", // const_name - const data (code or not)
887 /* ds390 has an 16 bit mul & div */
892 ds390_emitDebuggerSymbol
895 255/4, /* maxCount */
896 4, /* sizeofElement */
897 {8,12,20}, /* sizeofMatchJump[] */
898 {10,14,22}, /* sizeofRangeCompare[] */
899 4, /* sizeofSubtract */
900 7, /* sizeofDispatch */
907 _ds390_finaliseOptions,
908 _ds390_setDefaultOptions,
909 ds390_assignRegisters,
912 _ds390_genAssemblerPreamble,
913 NULL, /* no genAssemblerEnd */
916 NULL, /* genInitStartup */
917 _ds390_reset_regparm,
921 _ds390_nativeMulCheck,
922 hasExtBitOp, /* hasExtBitOp */
923 oclsExpense, /* oclsExpense */
925 TRUE, /* little endian */
928 1, /* transform <= to ! > */
929 1, /* transform >= to ! < */
930 1, /* transform != to !(a == b) */
932 #if 0 // obsolete, and buggy for != xdata
933 TRUE, /* we support array initializers. */
935 FALSE, /* No array initializer support. */
938 __ds390_builtins, /* table of builtin functions */
939 GPOINTER, /* treat unqualified pointers as "generic" pointers */
940 1, /* reset labelKey to 1 */
941 1, /* globals & local static allowed */
945 /*---------------------------------------------------------------------------------*/
946 /* TININative specific */
947 /*---------------------------------------------------------------------------------*/
949 static void _tininative_init (void)
951 asm_addTree (&asm_a390_mapping);
954 static void _tininative_setDefaultOptions (void)
956 options.model=MODEL_FLAT24;
957 options.stack10bit=1;
958 options.stackAuto = 1;
961 static void _tininative_finaliseOptions (void)
963 /* Hack-o-matic: if we are using the flat24 model,
964 * adjust pointer sizes.
966 if (options.model != MODEL_FLAT24) {
967 options.model = MODEL_FLAT24 ;
968 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
970 port->s.fptr_size = 3;
971 port->s.gptr_size = 4;
973 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
975 port->stack.call_overhead += 2; /* This acounts for the extra byte
976 * of return addres on the stack.
977 * but is ugly. There must be a
981 port->mem.default_local_map = xdata;
982 port->mem.default_globl_map = xdata;
984 if (!options.stack10bit) {
985 options.stack10bit = 1;
986 fprintf(stderr,"TININative supports only stack10bit \n");
989 if (!options.stack_loc) options.stack_loc = 0x400008;
991 /* generate native code 16*16 mul/div */
992 if (options.useAccelerator)
993 port->support.muldiv=2;
995 port->support.muldiv=1;
997 /* Fixup the memory map for the stack; it is now in
998 * far space and requires a FPOINTER to access it.
1001 istack->ptrType = FPOINTER;
1005 static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
1009 static void _tininative_genAssemblerPreamble (FILE * of)
1011 fputs("$include(tini.inc)\n", of);
1012 fputs("$include(ds80c390.inc)\n", of);
1013 fputs("$include(tinimacro.inc)\n", of);
1014 fputs("$include(apiequ.inc)\n", of);
1015 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
1016 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
1017 /* Must be first and return 0 */
1018 fputs("Lib_Native_Init:\n",of);
1019 fputs("\tclr\ta\n",of);
1020 fputs("\tret\n",of);
1021 fputs("LibraryID:\n",of);
1022 fputs("\tdb \"DS\"\n",of);
1023 if (options.tini_libid) {
1024 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
1025 (options.tini_libid>>24 & 0xff),
1026 (options.tini_libid>>16 & 0xff),
1027 (options.tini_libid>>8 & 0xff),
1028 (options.tini_libid & 0xff));
1030 fprintf(of,"\tdb 0,0,0,0,0,1\n");
1034 static void _tininative_genAssemblerEnd (FILE * of)
1036 fputs("\tend\n",of);
1038 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
1039 static void _tininative_do_assemble (set *asmOptions)
1041 static const char *macroCmd[] = {
1042 "macro","$1.a51",NULL
1044 static const char *a390Cmd[] = {
1045 "a390","$1.mpp",NULL
1049 buildCmdLine(buffer,macroCmd,dstFileName,NULL,NULL,NULL);
1050 if (my_system(buffer)) {
1053 buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions);
1054 if (my_system(buffer)) {
1059 /* list of key words used by TININative */
1060 static char *_tininative_keywords[] =
1089 static builtins __tininative_builtins[] = {
1090 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
1091 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
1092 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
1094 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
1095 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
1096 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
1097 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
1098 /* TINI StateBlock related */
1099 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
1100 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
1101 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
1102 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
1103 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
1104 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
1105 /* Memory manager */
1106 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
1107 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
1108 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
1109 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
1110 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
1111 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
1112 /* System functions */
1113 { "System_ExecJavaProcess","c",2,{"cx*","i"}}, /* char System_ExecJavaProcess (char *,int) */
1114 { "System_GetRTCRegisters","v",1,{"cx*"}}, /* void System_GetRTCRegisters (char *) */
1115 { "System_SetRTCRegisters","v",1,{"cx*"}}, /* void System_SetRTCRegisters (char *) */
1116 { "System_ThreadSleep","v",2,{"l","c"}}, /* void System_ThreadSleep (long,char) */
1117 { "System_ThreadSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ThreadSleep_ExitCriticalSection (long,char) */
1118 { "System_ProcessSleep","v",2,{"l","c"}}, /* void System_ProcessSleep (long,char) */
1119 { "System_ProcessSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ProcessSleep_ExitCriticalSection (long,char) */
1120 { "System_ThreadResume","c",2,{"c","c"}}, /* char System_ThreadResume(char,char) */
1121 { "System_SaveJavaThreadState","v",0,{NULL}}, /* void System_SaveJavaThreadState() */
1122 { "System_RestoreJavaThreadState","v",0,{NULL}}, /* void System_RestoreJavaThreadState() */
1123 { "System_ProcessYield","v",0,{NULL}}, /* void System_ProcessYield() */
1124 { "System_ProcessSuspend","v",0,{NULL}}, /* void System_ProcessSuspend() */
1125 { "System_ProcessResume","v",1,{"c"}}, /* void System_ProcessResume(char) */
1126 { "System_RegisterPoll","c",1,{"vF*"}}, /* char System_RegisterPoll ((void *func pointer)()) */
1127 { "System_RemovePoll","c",1,{"vF*"}}, /* char System_RemovePoll ((void *func pointer)()) */
1128 { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */
1129 { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */
1130 { NULL , NULL,0, {NULL}} /* mark end of table */
1133 static const char *_a390Cmd[] =
1135 "macro", "$l", "$3", "$1.a51", NULL
1137 PORT tininative_port =
1141 "DS80C390", /* Target name */
1142 NULL, /* processor */
1145 FALSE, /* Emit glue around main */
1152 "-l", /* Options with debug */
1153 "-l", /* Options without debug */
1156 _tininative_do_assemble
1172 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1173 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
1191 "CONST (CODE)", // const_name - const data (code or not)
1200 /* ds390 has an 16 bit mul & div */
1205 ds390_emitDebuggerSymbol
1208 255/4, /* maxCount */
1209 4, /* sizeofElement */
1210 {8,12,20}, /* sizeofMatchJump[] */
1211 {10,14,22}, /* sizeofRangeCompare[] */
1212 4, /* sizeofSubtract */
1213 7, /* sizeofDispatch */
1217 _ds390_parseOptions,
1220 _tininative_finaliseOptions,
1221 _tininative_setDefaultOptions,
1222 ds390_assignRegisters,
1224 _tininative_keywords,
1225 _tininative_genAssemblerPreamble,
1226 _tininative_genAssemblerEnd,
1229 NULL, /* genInitStartup */
1230 _ds390_reset_regparm,
1235 hasExtBitOp, /* hasExtBitOp */
1236 oclsExpense, /* oclsExpense */
1238 TRUE, /* little endian */
1241 1, /* transform <= to ! > */
1242 1, /* transform >= to ! < */
1243 1, /* transform != to !(a == b) */
1245 TRUE, /* we support array initializers. */
1247 __tininative_builtins, /* table of builtin functions */
1248 FPOINTER, /* treat unqualified pointers as far pointers */
1249 0, /* DONOT reset labelKey */
1250 0, /* globals & local static NOT allowed */
1255 _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
1257 /* We can't generate a static IVT, since the boot rom creates one
1258 * for us in rom_init.
1260 * we must patch it as part of the C startup.
1262 fprintf (of, ";\tDS80C400 IVT must be generated at runtime.\n");
1263 fprintf (of, "\tsjmp\t__sdcc_400boot\n");
1264 fprintf (of, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
1265 fprintf (of, "\t.db\t0\t; selected bank: zero *should* work...\n");
1266 fprintf (of, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
1273 _ds400_finaliseOptions (void)
1275 if (options.noXinitOpt) {
1279 // hackhack: we're a superset of the 390.
1280 addSet(&preArgvSet, Safe_strdup("-DSDCC_ds390"));
1281 addSet(&preArgvSet, Safe_strdup("-D__ds390"));
1283 /* Hack-o-matic: if we are using the flat24 model,
1284 * adjust pointer sizes.
1286 if (options.model != MODEL_FLAT24) {
1288 "*** warning: ds400 port small and large model experimental.\n");
1289 if (options.model == MODEL_LARGE)
1291 port->mem.default_local_map = xdata;
1292 port->mem.default_globl_map = xdata;
1296 port->mem.default_local_map = data;
1297 port->mem.default_globl_map = data;
1301 port->s.fptr_size = 3;
1302 port->s.gptr_size = 4;
1304 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1306 port->stack.call_overhead += 2; /* This acounts for the extra byte
1307 * of return addres on the stack.
1308 * but is ugly. There must be a
1312 port->mem.default_local_map = xdata;
1313 port->mem.default_globl_map = xdata;
1315 if (!options.stack10bit)
1318 "*** error: ds400 port only supports the 10 bit stack mode.\n");
1320 if (!options.stack_loc) options.stack_loc = 0xffdc00;
1321 // assumes IDM1:0 = 1:0, CMA = 1.
1324 /* generate native code 16*16 mul/div */
1325 if (options.useAccelerator)
1326 port->support.muldiv=2;
1328 port->support.muldiv=1;
1330 /* Fixup the memory map for the stack; it is now in
1331 * far space and requires a FPOINTER to access it.
1334 istack->ptrType = FPOINTER;
1336 if (options.parms_in_bank1) {
1337 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
1340 // the DS400 rom calling interface uses register bank 3.
1343 } /* MODEL_FLAT24 */
1346 static void _ds400_generateRomDataArea(FILE *fp, bool isMain)
1348 /* Only do this for the file containing main() */
1351 fprintf(fp, "%s", iComments2);
1352 fprintf(fp, "; the direct data area used by the DS80c400 ROM code.\n");
1353 fprintf(fp, "%s", iComments2);
1354 fprintf(fp, ".area ROMSEG (ABS,CON,DATA)\n\n");
1355 fprintf(fp, ".ds 24 ; 24 bytes of directs used starting at 0x68\n\n");
1359 static void _ds400_linkRomDataArea(FILE *fp)
1361 fprintf(fp, "-b ROMSEG = 0x0068\n");
1369 "DS80C400", /* Target name */
1373 TRUE, /* Emit glue around main */
1374 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1380 "-plosgffc", /* Options with debug */
1381 "-plosgff", /* Options without debug */
1384 NULL /* no do_assemble function */
1400 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1401 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
1417 "XISEG (XDATA)", // initialized xdata
1418 "XINIT (CODE)", // a code copy of xiseg
1419 "CONST (CODE)", // const_name - const data (code or not)
1424 { _ds400_generateRomDataArea, _ds400_linkRomDataArea },
1428 /* ds390 has an 16 bit mul & div */
1433 ds390_emitDebuggerSymbol
1436 255/4, /* maxCount */
1437 4, /* sizeofElement */
1438 {8,12,20}, /* sizeofMatchJump[] */
1439 {10,14,22}, /* sizeofRangeCompare[] */
1440 4, /* sizeofSubtract */
1441 7, /* sizeofDispatch */
1445 _ds390_parseOptions,
1448 _ds400_finaliseOptions,
1449 _ds390_setDefaultOptions,
1450 ds390_assignRegisters,
1453 _ds390_genAssemblerPreamble,
1454 NULL, /* no genAssemblerEnd */
1457 NULL, /* genInitStartup */
1458 _ds390_reset_regparm,
1462 _ds390_nativeMulCheck,
1463 hasExtBitOp, /* hasExtBitOp */
1464 oclsExpense, /* oclsExpense */
1466 TRUE, /* little endian */
1469 1, /* transform <= to ! > */
1470 1, /* transform >= to ! < */
1471 1, /* transform != to !(a == b) */
1473 TRUE, /* we support array initializers. */
1475 __ds390_builtins, /* table of builtin functions */
1476 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1477 1, /* reset labelKey to 1 */
1478 1, /* globals & local static allowed */