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 (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)
81 if (options.parms_in_bank1 == 0) {
82 /* simple can pass only the first parameter in a register */
89 int size = getSize(l);
92 /* first one goes the usual way to DPTR */
93 if (regParmFlg == 0) {
97 /* second one onwards goes to RB1_0 thru RB1_7 */
98 remain = regParmFlg - 4;
99 if (size > (8 - remain)) {
104 return regParmFlg - size + 1;
109 _ds390_parseOptions (int *pargc, char **argv, int *i)
111 /* TODO: allow port-specific command line options to specify
112 * segment names here.
118 _ds390_finaliseOptions (void)
120 if (options.noXinitOpt) {
124 /* Hack-o-matic: if we are using the flat24 model,
125 * adjust pointer sizes.
127 if (options.model != MODEL_FLAT24) {
129 "*** warning: ds390 port small and large model experimental.\n");
130 if (options.model == MODEL_LARGE)
132 port->mem.default_local_map = xdata;
133 port->mem.default_globl_map = xdata;
137 port->mem.default_local_map = data;
138 port->mem.default_globl_map = data;
142 port->s.fptr_size = 3;
143 port->s.gptr_size = 4;
145 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
147 port->stack.call_overhead += 2; /* This acounts for the extra byte
148 * of return addres on the stack.
149 * but is ugly. There must be a
153 port->mem.default_local_map = xdata;
154 port->mem.default_globl_map = xdata;
156 if (!options.stack10bit)
159 "*** error: ds390 port only supports the 10 bit stack mode.\n");
161 if (!options.stack_loc) options.stack_loc = 0x400008;
164 /* generate native code 16*16 mul/div */
165 if (options.useAccelerator)
166 port->support.muldiv=2;
168 port->support.muldiv=1;
170 /* Fixup the memory map for the stack; it is now in
171 * far space and requires a FPOINTER to access it.
174 istack->ptrType = FPOINTER;
176 if (options.parms_in_bank1) {
177 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
183 _ds390_setDefaultOptions (void)
185 options.model=MODEL_FLAT24;
186 options.stack10bit=1;
190 _ds390_getRegName (struct regs *reg)
197 extern char * iComments2;
200 _ds390_genAssemblerPreamble (FILE * of)
202 fputs (iComments2, of);
203 fputs ("; CPU specific extensions\n",of);
204 fputs (iComments2, of);
206 if (options.model == MODEL_FLAT24)
207 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
209 fputs ("dpl1\t=\t0x84\n", of);
210 fputs ("dph1\t=\t0x85\n", of);
211 fputs ("dps\t=\t0x86\n", of);
212 fputs ("dpx\t=\t0x93\n", of);
213 fputs ("dpx1\t=\t0x95\n", of);
214 fputs ("esp\t=\t0x9B\n", of);
215 fputs ("ap\t=\t0x9C\n", of);
216 fputs ("_ap\t=\t0x9C\n", of);
217 fputs ("mcnt0\t=\t0xD1\n", of);
218 fputs ("mcnt1\t=\t0xD2\n", of);
219 fputs ("ma\t=\t0xD3\n", of);
220 fputs ("mb\t=\t0xD4\n", of);
221 fputs ("mc\t=\t0xD5\n", of);
222 fputs ("F1\t=\t0xD1\t; user flag\n", of);
223 if (options.parms_in_bank1) {
225 for (i=0; i < 8 ; i++ )
226 fprintf (of,"b1_%d\t=\t0x%02X\n",i,8+i);
230 /* Generate interrupt vector table. */
232 _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
236 if (options.model != MODEL_FLAT24)
238 /* Let the default code handle it. */
242 fprintf (of, "\tajmp\t__reset_vect\n");
244 /* now for the other interrupts */
245 for (i = 0; i < maxInterrupts; i++)
249 fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
253 fprintf (of, "\treti\n\t.ds\t7\n");
257 fprintf (of, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
262 /* Generate code to copy XINIT to XISEG */
263 static void _ds390_genXINIT (FILE * of) {
264 fprintf (of, "; _ds390_genXINIT() start\n");
265 fprintf (of, " mov a,#l_XINIT\n");
266 fprintf (of, " orl a,#l_XINIT>>8\n");
267 fprintf (of, " jz 00003$\n");
268 fprintf (of, " mov a,#s_XINIT\n");
269 fprintf (of, " add a,#l_XINIT\n");
270 fprintf (of, " mov r1,a\n");
271 fprintf (of, " mov a,#s_XINIT>>8\n");
272 fprintf (of, " addc a,#l_XINIT>>8\n");
273 fprintf (of, " mov r2,a\n");
274 fprintf (of, " mov dptr,#s_XINIT\n");
275 fprintf (of, " mov dps,#0x21\n");
276 fprintf (of, " mov dptr,#s_XISEG\n");
277 fprintf (of, "00001$: clr a\n");
278 fprintf (of, " movc a,@a+dptr\n");
279 fprintf (of, " movx @dptr,a\n");
280 fprintf (of, " inc dptr\n");
281 fprintf (of, " inc dptr\n");
282 fprintf (of, "00002$: mov a,dpl\n");
283 fprintf (of, " cjne a,ar1,00001$\n");
284 fprintf (of, " mov a,dph\n");
285 fprintf (of, " cjne a,ar2,00001$\n");
286 fprintf (of, " mov dps,#0\n");
287 fprintf (of, "00003$:\n");
288 fprintf (of, "; _ds390_genXINIT() end\n");
291 /* Do CSE estimation */
292 static bool cseCostEstimation (iCode *ic, iCode *pdic)
294 operand *result = IC_RESULT(ic);
295 //operand *right = IC_RIGHT(ic);
296 //operand *left = IC_LEFT(ic);
297 sym_link *result_type = operandType(result);
298 //sym_link *right_type = (right ? operandType(right) : 0);
299 //sym_link *left_type = (left ? operandType(left) : 0);
301 /* if it is a pointer then return ok for now */
302 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
304 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
305 so we will cse only if they are local (i.e. both ic & pdic belong to
306 the same basic block */
307 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
308 /* then if they are the same Basic block then ok */
309 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
313 /* for others it is cheaper to do the cse */
317 bool _ds390_nativeMulCheck(iCode *ic, sym_link *left, sym_link *right)
319 return FALSE; // #STUB
322 /* Indicate which extended bit operations this port supports */
324 hasExtBitOp (int op, int size)
329 || (op == SWAP && size <= 2)
336 /* Indicate the expense of an access to an output storage class */
338 oclsExpense (struct memmap *oclass)
340 if (IN_FARSPACE(oclass))
347 instructionSize(char *inst, char *op1, char *op2)
349 int isflat24 = (options.model == MODEL_FLAT24);
351 #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
352 #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0')
353 #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0')
354 #define IS_Rn(s) (*(s) == 'r' && *(s+1) >= '0' && *(s+1) <= '7')
355 #define IS_atRi(s) (*(s) == '@' && *(s+1) == 'r')
357 /* Based on the current (2003-08-22) code generation for the
358 small library, the top instruction probability is:
369 /* mov, push, & pop are the 69% of the cases. Check them first! */
372 if (*(inst+3)=='x') return 1; /* movx */
373 if (*(inst+3)=='c') return 1; /* movc */
374 if (IS_C (op1) || IS_C (op2)) return 2;
377 if (IS_Rn (op2) || IS_atRi (op2)) return 1;
380 if (IS_Rn(op1) || IS_atRi(op1))
382 if (IS_A(op2)) return 1;
385 if (strcmp (op1, "dptr") == 0) return 3+isflat24;
386 if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2;
390 if (ISINST ("push")) return 2;
391 if (ISINST ("pop")) return 2;
393 if (ISINST ("lcall")) return 3+isflat24;
394 if (ISINST ("ret")) return 1;
395 if (ISINST ("ljmp")) return 3+isflat24;
396 if (ISINST ("sjmp")) return 2;
397 if (ISINST ("rlc")) return 1;
398 if (ISINST ("rrc")) return 1;
399 if (ISINST ("rl")) return 1;
400 if (ISINST ("rr")) return 1;
401 if (ISINST ("swap")) return 1;
402 if (ISINST ("jc")) return 2;
403 if (ISINST ("jnc")) return 2;
404 if (ISINST ("jb")) return 3;
405 if (ISINST ("jnb")) return 3;
406 if (ISINST ("jbc")) return 3;
407 if (ISINST ("jmp")) return 1; // always jmp @a+dptr
408 if (ISINST ("jz")) return 2;
409 if (ISINST ("jnz")) return 2;
410 if (ISINST ("cjne")) return 3;
411 if (ISINST ("mul")) return 1;
412 if (ISINST ("div")) return 1;
413 if (ISINST ("da")) return 1;
414 if (ISINST ("xchd")) return 1;
415 if (ISINST ("reti")) return 1;
416 if (ISINST ("nop")) return 1;
417 if (ISINST ("acall")) return 2+isflat24;
418 if (ISINST ("ajmp")) return 2+isflat24;
421 if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch"))
423 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
426 if (ISINST ("inc") || ISINST ("dec"))
428 if (IS_A(op1) || IS_Rn(op1) || IS_atRi(op1)) return 1;
429 if (strcmp(op1, "dptr") == 0) return 1;
432 if (ISINST ("anl") || ISINST ("orl") || ISINST ("xrl"))
434 if (IS_C(op1)) return 2;
437 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
442 if (IS_A(op2)) return 2;
446 if (ISINST ("clr") || ISINST ("setb") || ISINST ("cpl"))
448 if (IS_A(op1) || IS_C(op1)) return 1;
453 if (IS_Rn(op1)) return 2;
457 /* If the instruction is unrecognized, we shouldn't try to optimize. */
458 /* Return a large value to discourage optimization. */
463 ds390newAsmLineNode (int currentDPS)
467 aln = Safe_alloc ( sizeof (asmLineNode));
469 aln->regsRead = NULL;
470 aln->regsWritten = NULL;
471 aln->initialized = 0;
472 aln->currentDPS = currentDPS;
478 typedef struct ds390operanddata
486 static ds390operanddata ds390operandDataTable[] =
490 {"ab", A_IDX, B_IDX},
505 {"dph", DPH_IDX, -1},
506 {"dph0", DPH_IDX, -1},
507 {"dph1", DPH1_IDX, -1},
508 {"dpl", DPL_IDX, -1},
509 {"dpl0", DPL_IDX, -1},
510 {"dpl1", DPL1_IDX, -1},
511 /* {"dptr", DPL_IDX, DPH_IDX}, */ /* dptr is special, based on currentDPS */
512 {"dps", DPS_IDX, -1},
513 {"dpx", DPX_IDX, -1},
514 {"dpx0", DPX_IDX, -1},
515 {"dpx1", DPX1_IDX, -1},
520 {"psw", CND_IDX, -1},
532 ds390operandCompare (const void *key, const void *member)
534 return strcmp((const char *)key, ((ds390operanddata *)member)->name);
538 updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS)
540 ds390operanddata *opdat;
546 dot = strchr(op, '.');
550 opdat = bsearch (op, ds390operandDataTable,
551 sizeof(ds390operandDataTable)/sizeof(ds390operanddata),
552 sizeof(ds390operanddata), ds390operandCompare);
556 regIdx1 = opdat->regIdx1;
557 regIdx2 = opdat->regIdx2;
559 if (!strcmp(op, "dptr"))
575 if (strchr(optype,'r'))
578 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx1);
580 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx2);
582 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx3);
584 if (strchr(optype,'w'))
587 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx1);
589 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx2);
591 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx3);
595 if (!strcmp(op, "@r0"))
596 aln->regsRead = bitVectSetBit (aln->regsRead, R0_IDX);
597 if (!strcmp(op, "@r1"))
598 aln->regsRead = bitVectSetBit (aln->regsRead, R1_IDX);
599 if (strstr(op, "dptr"))
603 aln->regsRead = bitVectSetBit (aln->regsRead, DPL_IDX);
604 aln->regsRead = bitVectSetBit (aln->regsRead, DPH_IDX);
605 aln->regsRead = bitVectSetBit (aln->regsRead, DPX_IDX);
609 aln->regsRead = bitVectSetBit (aln->regsRead, DPL1_IDX);
610 aln->regsRead = bitVectSetBit (aln->regsRead, DPH1_IDX);
611 aln->regsRead = bitVectSetBit (aln->regsRead, DPX1_IDX);
614 if (strstr(op, "a+"))
615 aln->regsRead = bitVectSetBit (aln->regsRead, A_IDX);
619 typedef struct ds390opcodedata
629 static ds390opcodedata ds390opcodeDataTable[] =
631 {"acall","j", "", "", ""},
632 {"add", "", "w", "rw", "r"},
633 {"addc", "", "rw", "rw", "r"},
634 {"ajmp", "j", "", "", ""},
635 {"anl", "", "", "rw", "r"},
636 {"cjne", "j", "w", "r", "r"},
637 {"clr", "", "", "w", ""},
638 {"cpl", "", "", "rw", ""},
639 {"da", "", "rw", "rw", ""},
640 {"dec", "", "", "rw", ""},
641 {"div", "", "w", "rw", ""},
642 {"djnz", "j", "", "rw", ""},
643 {"inc", "", "", "rw", ""},
644 {"jb", "j", "", "r", ""},
645 {"jbc", "j", "", "rw", ""},
646 {"jc", "j", "", "", ""},
647 {"jmp", "j", "", "", ""},
648 {"jnb", "j", "", "r", ""},
649 {"jnc", "j", "", "", ""},
650 {"jnz", "j", "", "", ""},
651 {"jz", "j", "", "", ""},
652 {"lcall","j", "", "", ""},
653 {"ljmp", "j", "", "", ""},
654 {"mov", "", "", "w", "r"},
655 {"movc", "", "", "w", "r"},
656 {"movx", "", "", "w", "r"},
657 {"mul", "", "w", "rw", ""},
658 {"nop", "", "", "", ""},
659 {"orl", "", "", "rw", "r"},
660 {"pop", "", "", "w", ""},
661 {"push", "", "", "r", ""},
662 {"ret", "j", "", "", ""},
663 {"reti", "j", "", "", ""},
664 {"rl", "", "", "rw", ""},
665 {"rlc", "", "rw", "rw", ""},
666 {"rr", "", "", "rw", ""},
667 {"rrc", "", "rw", "rw", ""},
668 {"setb", "", "", "w", ""},
669 {"sjmp", "j", "", "", ""},
670 {"subb", "", "rw", "rw", "r"},
671 {"swap", "", "", "rw", ""},
672 {"xch", "", "", "rw", "rw"},
673 {"xchd", "", "", "rw", "rw"},
674 {"xrl", "", "", "rw", "r"},
678 ds390opcodeCompare (const void *key, const void *member)
680 return strcmp((const char *)key, ((ds390opcodedata *)member)->name);
684 asmLineNodeFromLineNode (lineNode *ln, int currentDPS)
686 asmLineNode *aln = ds390newAsmLineNode(currentDPS);
687 char *op, op1[256], op2[256];
691 ds390opcodedata *opdat;
693 aln->initialized = 1;
697 while (*p && isspace(*p)) p++;
698 for (op = inst, opsize=1; *p; p++)
700 if (isspace(*p) || *p == ';' || *p == ':' || *p == '=')
703 if (opsize < sizeof(inst))
704 *op++ = tolower(*p), opsize++;
708 if (*p == ';' || *p == ':' || *p == '=')
711 while (*p && isspace(*p)) p++;
715 for (op = op1, opsize=1; *p && *p != ','; p++)
717 if (!isspace(*p) && opsize < sizeof(op1))
718 *op++ = tolower(*p), opsize++;
723 for (op = op2, opsize=1; *p && *p != ','; p++)
725 if (!isspace(*p) && opsize < sizeof(op2))
726 *op++ = tolower(*p), opsize++;
730 aln->size = instructionSize(inst, op1, op2);
732 aln->regsRead = newBitVect (END_IDX);
733 aln->regsWritten = newBitVect (END_IDX);
735 opdat = bsearch (inst, ds390opcodeDataTable,
736 sizeof(ds390opcodeDataTable)/sizeof(ds390opcodedata),
737 sizeof(ds390opcodedata), ds390opcodeCompare);
741 updateOpRW (aln, op1, opdat->op1type, currentDPS);
742 updateOpRW (aln, op2, opdat->op2type, currentDPS);
743 if (strchr(opdat->pswtype,'r'))
744 aln->regsRead = bitVectSetBit (aln->regsRead, CND_IDX);
745 if (strchr(opdat->pswtype,'w'))
746 aln->regsWritten = bitVectSetBit (aln->regsWritten, CND_IDX);
753 initializeAsmLineNode (lineNode *line)
756 line->aln = asmLineNodeFromLineNode (line, 0);
757 else if (line->aln && !line->aln->initialized)
759 int currentDPS = line->aln->currentDPS;
761 line->aln = asmLineNodeFromLineNode (line, currentDPS);
766 getInstructionSize (lineNode *line)
768 initializeAsmLineNode (line);
769 return line->aln->size;
773 getRegsRead (lineNode *line)
775 initializeAsmLineNode (line);
776 return line->aln->regsRead;
780 getRegsWritten (lineNode *line)
782 initializeAsmLineNode (line);
783 return line->aln->regsWritten;
787 /** $1 is always the basename.
788 $2 is always the output file.
790 $l is the list of extra options that should be there somewhere...
791 MUST be terminated with a NULL.
793 static const char *_linkCmd[] =
795 "aslink", "-nf", "\"$1\"", NULL
798 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
799 static const char *_asmCmd[] =
801 "asx8051", "$l", "$3", "\"$1.asm\"", NULL
809 "DS80C390", /* Target name */
813 TRUE, /* Emit glue around main */
814 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
820 "-plosgffc", /* Options with debug */
821 "-plosgff", /* Options without debug */
824 NULL /* no do_assemble function */
840 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
841 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
856 "XISEG (XDATA)", // initialized xdata
857 "XINIT (CODE)", // a code copy of xiseg
866 /* ds390 has an 16 bit mul & div */
871 ds390_emitDebuggerSymbol
878 _ds390_finaliseOptions,
879 _ds390_setDefaultOptions,
880 ds390_assignRegisters,
883 _ds390_genAssemblerPreamble,
884 NULL, /* no genAssemblerEnd */
887 NULL, /* genInitStartup */
888 _ds390_reset_regparm,
892 _ds390_nativeMulCheck,
893 hasExtBitOp, /* hasExtBitOp */
894 oclsExpense, /* oclsExpense */
896 TRUE, /* little endian */
899 1, /* transform <= to ! > */
900 1, /* transform >= to ! < */
901 1, /* transform != to !(a == b) */
903 #if 0 // obsolete, and buggy for != xdata
904 TRUE, /* we support array initializers. */
906 FALSE, /* No array initializer support. */
909 __ds390_builtins, /* table of builtin functions */
910 GPOINTER, /* treat unqualified pointers as "generic" pointers */
911 1, /* reset labelKey to 1 */
912 1, /* globals & local static allowed */
916 /*---------------------------------------------------------------------------------*/
917 /* TININative specific */
918 /*---------------------------------------------------------------------------------*/
920 static void _tininative_init (void)
922 asm_addTree (&asm_a390_mapping);
925 static void _tininative_setDefaultOptions (void)
927 options.model=MODEL_FLAT24;
928 options.stack10bit=1;
929 options.stackAuto = 1;
932 static void _tininative_finaliseOptions (void)
934 /* Hack-o-matic: if we are using the flat24 model,
935 * adjust pointer sizes.
937 if (options.model != MODEL_FLAT24) {
938 options.model = MODEL_FLAT24 ;
939 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
941 port->s.fptr_size = 3;
942 port->s.gptr_size = 4;
944 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
946 port->stack.call_overhead += 2; /* This acounts for the extra byte
947 * of return addres on the stack.
948 * but is ugly. There must be a
952 port->mem.default_local_map = xdata;
953 port->mem.default_globl_map = xdata;
955 if (!options.stack10bit) {
956 options.stack10bit = 1;
957 fprintf(stderr,"TININative supports only stack10bit \n");
960 if (!options.stack_loc) options.stack_loc = 0x400008;
962 /* generate native code 16*16 mul/div */
963 if (options.useAccelerator)
964 port->support.muldiv=2;
966 port->support.muldiv=1;
968 /* Fixup the memory map for the stack; it is now in
969 * far space and requires a FPOINTER to access it.
972 istack->ptrType = FPOINTER;
976 static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
980 static void _tininative_genAssemblerPreamble (FILE * of)
982 fputs("$include(tini.inc)\n", of);
983 fputs("$include(ds80c390.inc)\n", of);
984 fputs("$include(tinimacro.inc)\n", of);
985 fputs("$include(apiequ.inc)\n", of);
986 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
987 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
988 /* Must be first and return 0 */
989 fputs("Lib_Native_Init:\n",of);
990 fputs("\tclr\ta\n",of);
992 fputs("LibraryID:\n",of);
993 fputs("\tdb \"DS\"\n",of);
994 if (options.tini_libid) {
995 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
996 (options.tini_libid>>24 & 0xff),
997 (options.tini_libid>>16 & 0xff),
998 (options.tini_libid>>8 & 0xff),
999 (options.tini_libid & 0xff));
1001 fprintf(of,"\tdb 0,0,0,0,0,1\n");
1005 static void _tininative_genAssemblerEnd (FILE * of)
1007 fputs("\tend\n",of);
1009 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
1010 static void _tininative_do_assemble (set *asmOptions)
1012 static const char *macroCmd[] = {
1013 "macro","$1.a51",NULL
1015 static const char *a390Cmd[] = {
1016 "a390","$1.mpp",NULL
1020 buildCmdLine(buffer,macroCmd,dstFileName,NULL,NULL,NULL);
1021 if (my_system(buffer)) {
1024 buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions);
1025 if (my_system(buffer)) {
1030 /* list of key words used by TININative */
1031 static char *_tininative_keywords[] =
1060 static builtins __tininative_builtins[] = {
1061 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
1062 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
1063 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
1065 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
1066 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
1067 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
1068 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
1069 /* TINI StateBlock related */
1070 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
1071 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
1072 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
1073 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
1074 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
1075 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
1076 /* Memory manager */
1077 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
1078 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
1079 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
1080 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
1081 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
1082 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
1083 /* System functions */
1084 { "System_ExecJavaProcess","c",2,{"cx*","i"}}, /* char System_ExecJavaProcess (char *,int) */
1085 { "System_GetRTCRegisters","v",1,{"cx*"}}, /* void System_GetRTCRegisters (char *) */
1086 { "System_SetRTCRegisters","v",1,{"cx*"}}, /* void System_SetRTCRegisters (char *) */
1087 { "System_ThreadSleep","v",2,{"l","c"}}, /* void System_ThreadSleep (long,char) */
1088 { "System_ThreadSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ThreadSleep_ExitCriticalSection (long,char) */
1089 { "System_ProcessSleep","v",2,{"l","c"}}, /* void System_ProcessSleep (long,char) */
1090 { "System_ProcessSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ProcessSleep_ExitCriticalSection (long,char) */
1091 { "System_ThreadResume","c",2,{"c","c"}}, /* char System_ThreadResume(char,char) */
1092 { "System_SaveJavaThreadState","v",0,{NULL}}, /* void System_SaveJavaThreadState() */
1093 { "System_RestoreJavaThreadState","v",0,{NULL}}, /* void System_RestoreJavaThreadState() */
1094 { "System_ProcessYield","v",0,{NULL}}, /* void System_ProcessYield() */
1095 { "System_ProcessSuspend","v",0,{NULL}}, /* void System_ProcessSuspend() */
1096 { "System_ProcessResume","v",1,{"c"}}, /* void System_ProcessResume(char) */
1097 { "System_RegisterPoll","c",1,{"vF*"}}, /* char System_RegisterPoll ((void *func pointer)()) */
1098 { "System_RemovePoll","c",1,{"vF*"}}, /* char System_RemovePoll ((void *func pointer)()) */
1099 { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */
1100 { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */
1101 { NULL , NULL,0, {NULL}} /* mark end of table */
1104 static const char *_a390Cmd[] =
1106 "macro", "$l", "$3", "$1.a51", NULL
1108 PORT tininative_port =
1112 "DS80C390", /* Target name */
1113 NULL, /* processor */
1116 FALSE, /* Emit glue around main */
1123 "-l", /* Options with debug */
1124 "-l", /* Options without debug */
1127 _tininative_do_assemble
1143 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1144 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
1169 /* ds390 has an 16 bit mul & div */
1174 ds390_emitDebuggerSymbol
1178 _ds390_parseOptions,
1181 _tininative_finaliseOptions,
1182 _tininative_setDefaultOptions,
1183 ds390_assignRegisters,
1185 _tininative_keywords,
1186 _tininative_genAssemblerPreamble,
1187 _tininative_genAssemblerEnd,
1190 NULL, /* genInitStartup */
1191 _ds390_reset_regparm,
1196 hasExtBitOp, /* hasExtBitOp */
1197 oclsExpense, /* oclsExpense */
1199 TRUE, /* little endian */
1202 1, /* transform <= to ! > */
1203 1, /* transform >= to ! < */
1204 1, /* transform != to !(a == b) */
1206 TRUE, /* we support array initializers. */
1208 __tininative_builtins, /* table of builtin functions */
1209 FPOINTER, /* treat unqualified pointers as far pointers */
1210 0, /* DONOT reset labelKey */
1211 0, /* globals & local static NOT allowed */
1216 _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
1218 /* We can't generate a static IVT, since the boot rom creates one
1219 * for us in rom_init.
1221 * we must patch it as part of the C startup.
1223 fprintf (of, ";\tDS80C400 IVT must be generated at runtime.\n");
1224 fprintf (of, "\tsjmp\t__sdcc_400boot\n");
1225 fprintf (of, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
1226 fprintf (of, "\t.db\t0\t; selected bank: zero *should* work...\n");
1227 fprintf (of, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
1234 _ds400_finaliseOptions (void)
1236 if (options.noXinitOpt) {
1240 // hackhack: we're a superset of the 390.
1241 addSet(&preArgvSet, Safe_strdup("-DSDCC_ds390"));
1242 addSet(&preArgvSet, Safe_strdup("-D__ds390"));
1244 /* Hack-o-matic: if we are using the flat24 model,
1245 * adjust pointer sizes.
1247 if (options.model != MODEL_FLAT24) {
1249 "*** warning: ds400 port small and large model experimental.\n");
1250 if (options.model == MODEL_LARGE)
1252 port->mem.default_local_map = xdata;
1253 port->mem.default_globl_map = xdata;
1257 port->mem.default_local_map = data;
1258 port->mem.default_globl_map = data;
1262 port->s.fptr_size = 3;
1263 port->s.gptr_size = 4;
1265 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1267 port->stack.call_overhead += 2; /* This acounts for the extra byte
1268 * of return addres on the stack.
1269 * but is ugly. There must be a
1273 port->mem.default_local_map = xdata;
1274 port->mem.default_globl_map = xdata;
1276 if (!options.stack10bit)
1279 "*** error: ds400 port only supports the 10 bit stack mode.\n");
1281 if (!options.stack_loc) options.stack_loc = 0xffdc00;
1282 // assumes IDM1:0 = 1:0, CMA = 1.
1285 /* generate native code 16*16 mul/div */
1286 if (options.useAccelerator)
1287 port->support.muldiv=2;
1289 port->support.muldiv=1;
1291 /* Fixup the memory map for the stack; it is now in
1292 * far space and requires a FPOINTER to access it.
1295 istack->ptrType = FPOINTER;
1297 if (options.parms_in_bank1) {
1298 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
1301 // the DS400 rom calling interface uses register bank 3.
1304 } /* MODEL_FLAT24 */
1307 static void _ds400_generateRomDataArea(FILE *fp, bool isMain)
1309 /* Only do this for the file containing main() */
1312 fprintf(fp, "%s", iComments2);
1313 fprintf(fp, "; the direct data area used by the DS80c400 ROM code.\n");
1314 fprintf(fp, "%s", iComments2);
1315 fprintf(fp, ".area ROMSEG (ABS,CON,DATA)\n\n");
1316 fprintf(fp, ".ds 24 ; 24 bytes of directs used starting at 0x68\n\n");
1320 static void _ds400_linkRomDataArea(FILE *fp)
1322 fprintf(fp, "-b ROMSEG = 0x0068\n");
1330 "DS80C400", /* Target name */
1334 TRUE, /* Emit glue around main */
1335 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1341 "-plosgffc", /* Options with debug */
1342 "-plosgff", /* Options without debug */
1345 NULL /* no do_assemble function */
1361 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1362 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
1377 "XISEG (XDATA)", // initialized xdata
1378 "XINIT (CODE)", // a code copy of xiseg
1383 { _ds400_generateRomDataArea, _ds400_linkRomDataArea },
1387 /* ds390 has an 16 bit mul & div */
1392 ds390_emitDebuggerSymbol
1396 _ds390_parseOptions,
1399 _ds400_finaliseOptions,
1400 _ds390_setDefaultOptions,
1401 ds390_assignRegisters,
1404 _ds390_genAssemblerPreamble,
1405 NULL, /* no genAssemblerEnd */
1408 NULL, /* genInitStartup */
1409 _ds390_reset_regparm,
1413 _ds390_nativeMulCheck,
1414 hasExtBitOp, /* hasExtBitOp */
1415 oclsExpense, /* oclsExpense */
1417 TRUE, /* little endian */
1420 1, /* transform <= to ! > */
1421 1, /* transform >= to ! < */
1422 1, /* transform != to !(a == b) */
1424 TRUE, /* we support array initializers. */
1426 __ds390_builtins, /* table of builtin functions */
1427 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1428 1, /* reset labelKey to 1 */
1429 1, /* globals & local static allowed */