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 "dbuf_string.h"
14 #include "../SDCCutil.h"
15 #include "../SDCCglobl.h"
16 static char _defaultRules[] =
21 #define OPTION_STACK_8BIT "--stack-8bit"
22 #define OPTION_FLAT24_MODEL "--model-flat24"
23 #define OPTION_STACK_SIZE "--stack-size"
25 static OPTION _ds390_options[] =
27 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" },
28 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" },
29 { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"},
30 { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"},
31 { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"},
32 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
33 { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds390 arithmetic accelerator"},
34 { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"},
35 { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"},
40 /* list of key words used by msc51 */
41 static char *_ds390_keywords[] =
71 static builtins __ds390_builtins[] = {
72 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
73 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
74 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
75 /* __builtin_inp - used to read from a memory mapped port, increment first pointer */
76 { "__builtin_inp","v",3,{"cx*","cx*","i"}}, /* void __builtin_inp (xdata char *,xdata char *,int) */
77 /* __builtin_inp - used to write to a memory mapped port, increment first pointer */
78 { "__builtin_outp","v",3,{"cx*","cx*","i"}}, /* void __builtin_outp (xdata char *,xdata char *,int) */
79 { "__builtin_swapw","us",1,{"us"}}, /* unsigned short __builtin_swapw (unsigned short) */
80 { "__builtin_memcmp_x2x","c",3,{"cx*","cx*","i"}}, /* void __builtin_memcmp_x2x (xdata char *,xdata char *,int) */
81 { "__builtin_memcmp_c2x","c",3,{"cx*","cp*","i"}}, /* void __builtin_memcmp_c2x (xdata char *,code char *,int) */
82 { NULL , NULL,0, {NULL}} /* mark end of table */
84 void ds390_assignRegisters (ebbIndex * ebbi);
86 static int regParmFlg = 0; /* determine if we can register a parameter */
91 asm_addTree (&asm_asxxxx_mapping);
95 _ds390_reset_regparm (void)
101 _ds390_regparm (sym_link * l, bool reentrant)
103 if (IS_SPEC(l) && (SPEC_NOUN(l) == V_BIT))
105 if (options.parms_in_bank1 == 0) {
106 /* simple can pass only the first parameter in a register */
113 int size = getSize(l);
116 /* first one goes the usual way to DPTR */
117 if (regParmFlg == 0) {
121 /* second one onwards goes to RB1_0 thru RB1_7 */
122 remain = regParmFlg - 4;
123 if (size > (8 - remain)) {
128 return regParmFlg - size + 1;
133 _ds390_parseOptions (int *pargc, char **argv, int *i)
135 /* TODO: allow port-specific command line options to specify
136 * segment names here.
138 if (!strcmp (argv[*i], OPTION_STACK_8BIT))
140 options.stack10bit = 0;
143 else if (!strcmp (argv[*i], OPTION_FLAT24_MODEL))
145 options.model = MODEL_FLAT24;
148 else if (!strcmp (argv[*i], OPTION_STACK_SIZE))
150 options.stack_size = getIntArg (OPTION_STACK_SIZE, argv, i, *pargc);
157 _ds390_finaliseOptions (void)
159 if (options.noXinitOpt) {
163 /* Hack-o-matic: if we are using the flat24 model,
164 * adjust pointer sizes.
166 if (options.model != MODEL_FLAT24) {
168 "*** warning: ds390 port small and large model experimental.\n");
169 if (options.model == MODEL_LARGE)
171 port->mem.default_local_map = xdata;
172 port->mem.default_globl_map = xdata;
176 port->mem.default_local_map = data;
177 port->mem.default_globl_map = data;
181 port->s.fptr_size = 3;
182 port->s.gptr_size = 4;
184 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
186 port->stack.call_overhead += 2; /* This acounts for the extra byte
187 * of return addres on the stack.
188 * but is ugly. There must be a
192 port->mem.default_local_map = xdata;
193 port->mem.default_globl_map = xdata;
195 if (!options.stack10bit)
198 "*** error: ds390 port only supports the 10 bit stack mode.\n");
200 if (!options.stack_loc) options.stack_loc = 0x400008;
203 /* generate native code 16*16 mul/div */
204 if (options.useAccelerator)
205 port->support.muldiv=2;
207 port->support.muldiv=1;
209 /* Fixup the memory map for the stack; it is now in
210 * far space and requires a FPOINTER to access it.
213 istack->ptrType = FPOINTER;
215 if (options.parms_in_bank1) {
216 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
222 _ds390_setDefaultOptions (void)
224 options.model=MODEL_FLAT24;
225 options.stack10bit=1;
229 _ds390_getRegName (struct regs *reg)
236 extern char * iComments2;
239 _ds390_genAssemblerPreamble (FILE * of)
241 fputs (iComments2, of);
242 fputs ("; CPU specific extensions\n",of);
243 fputs (iComments2, of);
245 if (options.model == MODEL_FLAT24)
246 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
248 fputs ("dpl1\t=\t0x84\n", of);
249 fputs ("dph1\t=\t0x85\n", of);
250 fputs ("dps\t=\t0x86\n", of);
251 fputs ("dpx\t=\t0x93\n", of);
252 fputs ("dpx1\t=\t0x95\n", of);
253 fputs ("esp\t=\t0x9B\n", of);
254 fputs ("ap\t=\t0x9C\n", of);
255 fputs ("_ap\t=\t0x9C\n", of);
256 fputs ("mcnt0\t=\t0xD1\n", of);
257 fputs ("mcnt1\t=\t0xD2\n", of);
258 fputs ("ma\t=\t0xD3\n", of);
259 fputs ("mb\t=\t0xD4\n", of);
260 fputs ("mc\t=\t0xD5\n", of);
261 fputs ("F1\t=\t0xD1\t; user flag\n", of);
262 if (options.parms_in_bank1) {
264 for (i=0; i < 8 ; i++ )
265 fprintf (of,"b1_%d\t=\t0x%02X\n",i,8+i);
269 /* Generate interrupt vector table. */
271 _ds390_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
275 if (options.model != MODEL_FLAT24)
277 dbuf_printf (oBuf, "\tljmp\t__sdcc_gsinit_startup\n");
279 /* now for the other interrupts */
280 for (i = 0; i < maxInterrupts; i++)
284 dbuf_printf (oBuf, "\tljmp\t%s\n", interrupts[i]->rname);
285 if ( i != maxInterrupts - 1 )
286 dbuf_printf (oBuf, "\t.ds\t5\n");
290 dbuf_printf (oBuf, "\treti\n");
291 if ( i != maxInterrupts - 1 )
292 dbuf_printf (oBuf, "\t.ds\t7\n");
298 dbuf_printf (oBuf, "\tajmp\t__reset_vect\n");
300 /* now for the other interrupts */
301 for (i = 0; i < maxInterrupts; i++)
305 dbuf_printf (oBuf, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
309 dbuf_printf (oBuf, "\treti\n\t.ds\t7\n");
313 dbuf_printf (oBuf, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
318 /* Generate code to copy XINIT to XISEG */
319 static void _ds390_genXINIT (FILE * of) {
320 fprintf (of, "; _ds390_genXINIT() start\n");
321 fprintf (of, " mov a,#l_XINIT\n");
322 fprintf (of, " orl a,#l_XINIT>>8\n");
323 fprintf (of, " jz 00003$\n");
324 fprintf (of, " mov a,#s_XINIT\n");
325 fprintf (of, " add a,#l_XINIT\n");
326 fprintf (of, " mov r1,a\n");
327 fprintf (of, " mov a,#s_XINIT>>8\n");
328 fprintf (of, " addc a,#l_XINIT>>8\n");
329 fprintf (of, " mov r2,a\n");
330 fprintf (of, " mov dptr,#s_XINIT\n");
331 fprintf (of, " mov dps,#0x21\n");
332 fprintf (of, " mov dptr,#s_XISEG\n");
333 fprintf (of, "00001$: clr a\n");
334 fprintf (of, " movc a,@a+dptr\n");
335 fprintf (of, " movx @dptr,a\n");
336 fprintf (of, " inc dptr\n");
337 fprintf (of, " inc dptr\n");
338 fprintf (of, "00002$: mov a,dpl\n");
339 fprintf (of, " cjne a,ar1,00001$\n");
340 fprintf (of, " mov a,dph\n");
341 fprintf (of, " cjne a,ar2,00001$\n");
342 fprintf (of, " mov dps,#0\n");
343 fprintf (of, "00003$:\n");
344 fprintf (of, "; _ds390_genXINIT() end\n");
347 /* Do CSE estimation */
348 static bool cseCostEstimation (iCode *ic, iCode *pdic)
350 operand *result = IC_RESULT(ic);
351 //operand *right = IC_RIGHT(ic);
352 //operand *left = IC_LEFT(ic);
353 sym_link *result_type = operandType(result);
354 //sym_link *right_type = (right ? operandType(right) : 0);
355 //sym_link *left_type = (left ? operandType(left) : 0);
357 /* if it is a pointer then return ok for now */
358 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
360 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
361 so we will cse only if they are local (i.e. both ic & pdic belong to
362 the same basic block */
363 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
364 /* then if they are the same Basic block then ok */
365 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
369 /* for others it is cheaper to do the cse */
373 bool _ds390_nativeMulCheck(iCode *ic, sym_link *left, sym_link *right)
375 return FALSE; // #STUB
378 /* Indicate which extended bit operations this port supports */
380 hasExtBitOp (int op, int size)
385 || (op == SWAP && size <= 2)
392 /* Indicate the expense of an access to an output storage class */
394 oclsExpense (struct memmap *oclass)
396 if (IN_FARSPACE(oclass))
403 instructionSize(char *inst, char *op1, char *op2)
405 int isflat24 = (options.model == MODEL_FLAT24);
407 #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
408 #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0')
409 #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0')
410 #define IS_Rn(s) (*(s) == 'r' && *(s+1) >= '0' && *(s+1) <= '7')
411 #define IS_atRi(s) (*(s) == '@' && *(s+1) == 'r')
413 /* Based on the current (2003-08-22) code generation for the
414 small library, the top instruction probability is:
425 /* mov, push, & pop are the 69% of the cases. Check them first! */
428 if (*(inst+3)=='x') return 1; /* movx */
429 if (*(inst+3)=='c') return 1; /* movc */
430 if (IS_C (op1) || IS_C (op2)) return 2;
433 if (IS_Rn (op2) || IS_atRi (op2)) return 1;
436 if (IS_Rn(op1) || IS_atRi(op1))
438 if (IS_A(op2)) return 1;
441 if (strcmp (op1, "dptr") == 0) return 3+isflat24;
442 if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2;
446 if (ISINST ("push")) return 2;
447 if (ISINST ("pop")) return 2;
449 if (ISINST ("lcall")) return 3+isflat24;
450 if (ISINST ("ret")) return 1;
451 if (ISINST ("ljmp")) return 3+isflat24;
452 if (ISINST ("sjmp")) return 2;
453 if (ISINST ("rlc")) return 1;
454 if (ISINST ("rrc")) return 1;
455 if (ISINST ("rl")) return 1;
456 if (ISINST ("rr")) return 1;
457 if (ISINST ("swap")) return 1;
458 if (ISINST ("jc")) return 2;
459 if (ISINST ("jnc")) return 2;
460 if (ISINST ("jb")) return 3;
461 if (ISINST ("jnb")) return 3;
462 if (ISINST ("jbc")) return 3;
463 if (ISINST ("jmp")) return 1; // always jmp @a+dptr
464 if (ISINST ("jz")) return 2;
465 if (ISINST ("jnz")) return 2;
466 if (ISINST ("cjne")) return 3;
467 if (ISINST ("mul")) return 1;
468 if (ISINST ("div")) return 1;
469 if (ISINST ("da")) return 1;
470 if (ISINST ("xchd")) return 1;
471 if (ISINST ("reti")) return 1;
472 if (ISINST ("nop")) return 1;
473 if (ISINST ("acall")) return 2+isflat24;
474 if (ISINST ("ajmp")) return 2+isflat24;
477 if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch"))
479 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
482 if (ISINST ("inc") || ISINST ("dec"))
484 if (IS_A(op1) || IS_Rn(op1) || IS_atRi(op1)) return 1;
485 if (strcmp(op1, "dptr") == 0) return 1;
488 if (ISINST ("anl") || ISINST ("orl") || ISINST ("xrl"))
490 if (IS_C(op1)) return 2;
493 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
498 if (IS_A(op2)) return 2;
502 if (ISINST ("clr") || ISINST ("setb") || ISINST ("cpl"))
504 if (IS_A(op1) || IS_C(op1)) return 1;
509 if (IS_Rn(op1)) return 2;
513 /* If the instruction is unrecognized, we shouldn't try to optimize. */
514 /* Return a large value to discourage optimization. */
519 ds390newAsmLineNode (int currentDPS)
523 aln = Safe_alloc ( sizeof (asmLineNode));
525 aln->regsRead = NULL;
526 aln->regsWritten = NULL;
527 aln->initialized = 0;
528 aln->currentDPS = currentDPS;
534 typedef struct ds390operanddata
542 static ds390operanddata ds390operandDataTable[] =
546 {"ab", A_IDX, B_IDX},
561 {"dph", DPH_IDX, -1},
562 {"dph0", DPH_IDX, -1},
563 {"dph1", DPH1_IDX, -1},
564 {"dpl", DPL_IDX, -1},
565 {"dpl0", DPL_IDX, -1},
566 {"dpl1", DPL1_IDX, -1},
567 /* {"dptr", DPL_IDX, DPH_IDX}, */ /* dptr is special, based on currentDPS */
568 {"dps", DPS_IDX, -1},
569 {"dpx", DPX_IDX, -1},
570 {"dpx0", DPX_IDX, -1},
571 {"dpx1", DPX1_IDX, -1},
576 {"psw", CND_IDX, -1},
588 ds390operandCompare (const void *key, const void *member)
590 return strcmp((const char *)key, ((ds390operanddata *)member)->name);
594 updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS)
596 ds390operanddata *opdat;
602 dot = strchr(op, '.');
606 opdat = bsearch (op, ds390operandDataTable,
607 sizeof(ds390operandDataTable)/sizeof(ds390operanddata),
608 sizeof(ds390operanddata), ds390operandCompare);
612 regIdx1 = opdat->regIdx1;
613 regIdx2 = opdat->regIdx2;
615 if (!strcmp(op, "dptr"))
631 if (strchr(optype,'r'))
634 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx1);
636 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx2);
638 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx3);
640 if (strchr(optype,'w'))
643 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx1);
645 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx2);
647 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx3);
651 if (!strcmp(op, "@r0"))
652 aln->regsRead = bitVectSetBit (aln->regsRead, R0_IDX);
653 if (!strcmp(op, "@r1"))
654 aln->regsRead = bitVectSetBit (aln->regsRead, R1_IDX);
655 if (strstr(op, "dptr"))
659 aln->regsRead = bitVectSetBit (aln->regsRead, DPL_IDX);
660 aln->regsRead = bitVectSetBit (aln->regsRead, DPH_IDX);
661 aln->regsRead = bitVectSetBit (aln->regsRead, DPX_IDX);
665 aln->regsRead = bitVectSetBit (aln->regsRead, DPL1_IDX);
666 aln->regsRead = bitVectSetBit (aln->regsRead, DPH1_IDX);
667 aln->regsRead = bitVectSetBit (aln->regsRead, DPX1_IDX);
670 if (strstr(op, "a+"))
671 aln->regsRead = bitVectSetBit (aln->regsRead, A_IDX);
675 typedef struct ds390opcodedata
685 static ds390opcodedata ds390opcodeDataTable[] =
687 {"acall","j", "", "", ""},
688 {"add", "", "w", "rw", "r"},
689 {"addc", "", "rw", "rw", "r"},
690 {"ajmp", "j", "", "", ""},
691 {"anl", "", "", "rw", "r"},
692 {"cjne", "j", "w", "r", "r"},
693 {"clr", "", "", "w", ""},
694 {"cpl", "", "", "rw", ""},
695 {"da", "", "rw", "rw", ""},
696 {"dec", "", "", "rw", ""},
697 {"div", "", "w", "rw", ""},
698 {"djnz", "j", "", "rw", ""},
699 {"inc", "", "", "rw", ""},
700 {"jb", "j", "", "r", ""},
701 {"jbc", "j", "", "rw", ""},
702 {"jc", "j", "", "", ""},
703 {"jmp", "j", "", "", ""},
704 {"jnb", "j", "", "r", ""},
705 {"jnc", "j", "", "", ""},
706 {"jnz", "j", "", "", ""},
707 {"jz", "j", "", "", ""},
708 {"lcall","j", "", "", ""},
709 {"ljmp", "j", "", "", ""},
710 {"mov", "", "", "w", "r"},
711 {"movc", "", "", "w", "r"},
712 {"movx", "", "", "w", "r"},
713 {"mul", "", "w", "rw", ""},
714 {"nop", "", "", "", ""},
715 {"orl", "", "", "rw", "r"},
716 {"pop", "", "", "w", ""},
717 {"push", "", "", "r", ""},
718 {"ret", "j", "", "", ""},
719 {"reti", "j", "", "", ""},
720 {"rl", "", "", "rw", ""},
721 {"rlc", "", "rw", "rw", ""},
722 {"rr", "", "", "rw", ""},
723 {"rrc", "", "rw", "rw", ""},
724 {"setb", "", "", "w", ""},
725 {"sjmp", "j", "", "", ""},
726 {"subb", "", "rw", "rw", "r"},
727 {"swap", "", "", "rw", ""},
728 {"xch", "", "", "rw", "rw"},
729 {"xchd", "", "", "rw", "rw"},
730 {"xrl", "", "", "rw", "r"},
734 ds390opcodeCompare (const void *key, const void *member)
736 return strcmp((const char *)key, ((ds390opcodedata *)member)->name);
740 asmLineNodeFromLineNode (lineNode *ln, int currentDPS)
742 asmLineNode *aln = ds390newAsmLineNode(currentDPS);
743 char *op, op1[256], op2[256];
747 ds390opcodedata *opdat;
749 aln->initialized = 1;
753 while (*p && isspace(*p)) p++;
754 for (op = inst, opsize=1; *p; p++)
756 if (isspace(*p) || *p == ';' || *p == ':' || *p == '=')
759 if (opsize < sizeof(inst))
760 *op++ = tolower(*p), opsize++;
764 if (*p == ';' || *p == ':' || *p == '=')
767 while (*p && isspace(*p)) p++;
771 for (op = op1, opsize=1; *p && *p != ','; p++)
773 if (!isspace(*p) && opsize < sizeof(op1))
774 *op++ = tolower(*p), opsize++;
779 for (op = op2, opsize=1; *p && *p != ','; p++)
781 if (!isspace(*p) && opsize < sizeof(op2))
782 *op++ = tolower(*p), opsize++;
786 aln->size = instructionSize(inst, op1, op2);
788 aln->regsRead = newBitVect (END_IDX);
789 aln->regsWritten = newBitVect (END_IDX);
791 opdat = bsearch (inst, ds390opcodeDataTable,
792 sizeof(ds390opcodeDataTable)/sizeof(ds390opcodedata),
793 sizeof(ds390opcodedata), ds390opcodeCompare);
797 updateOpRW (aln, op1, opdat->op1type, currentDPS);
798 updateOpRW (aln, op2, opdat->op2type, currentDPS);
799 if (strchr(opdat->pswtype,'r'))
800 aln->regsRead = bitVectSetBit (aln->regsRead, CND_IDX);
801 if (strchr(opdat->pswtype,'w'))
802 aln->regsWritten = bitVectSetBit (aln->regsWritten, CND_IDX);
809 initializeAsmLineNode (lineNode *line)
812 line->aln = asmLineNodeFromLineNode (line, 0);
813 else if (line->aln && !line->aln->initialized)
815 int currentDPS = line->aln->currentDPS;
817 line->aln = asmLineNodeFromLineNode (line, currentDPS);
822 getInstructionSize (lineNode *line)
824 initializeAsmLineNode (line);
825 return line->aln->size;
829 getRegsRead (lineNode *line)
831 initializeAsmLineNode (line);
832 return line->aln->regsRead;
836 getRegsWritten (lineNode *line)
838 initializeAsmLineNode (line);
839 return line->aln->regsWritten;
843 /** $1 is always the basename.
844 $2 is always the output file.
846 $l is the list of extra options that should be there somewhere...
847 MUST be terminated with a NULL.
849 static const char *_linkCmd[] =
851 "aslink", "-nf", "\"$1\"", NULL
854 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
855 static const char *_asmCmd[] =
857 "asx8051", "$l", "$3", "\"$1.asm\"", NULL
865 "DS80C390", /* Target name */
869 TRUE, /* Emit glue around main */
870 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
876 "-plosgffc", /* Options with debug */
877 "-plosgff", /* Options without debug */
880 NULL /* no do_assemble function */
896 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
897 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
900 /* tags for generic pointers */
901 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
917 "XISEG (XDATA)", // initialized xdata
918 "XINIT (CODE)", // a code copy of xiseg
919 "CONST (CODE)", // const_name - const data (code or not)
920 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
921 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
922 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
931 /* ds390 has an 16 bit mul & div */
936 ds390_emitDebuggerSymbol
939 255/4, /* maxCount */
940 4, /* sizeofElement */
941 {8,12,20}, /* sizeofMatchJump[] */
942 {10,14,22}, /* sizeofRangeCompare[] */
943 4, /* sizeofSubtract */
944 7, /* sizeofDispatch */
951 _ds390_finaliseOptions,
952 _ds390_setDefaultOptions,
953 ds390_assignRegisters,
956 _ds390_genAssemblerPreamble,
957 NULL, /* no genAssemblerEnd */
960 NULL, /* genInitStartup */
961 _ds390_reset_regparm,
965 _ds390_nativeMulCheck,
966 hasExtBitOp, /* hasExtBitOp */
967 oclsExpense, /* oclsExpense */
969 TRUE, /* little endian */
972 1, /* transform <= to ! > */
973 1, /* transform >= to ! < */
974 1, /* transform != to !(a == b) */
976 FALSE, /* No array initializer support. */
978 __ds390_builtins, /* table of builtin functions */
979 GPOINTER, /* treat unqualified pointers as "generic" pointers */
980 1, /* reset labelKey to 1 */
981 1, /* globals & local static allowed */
985 /*---------------------------------------------------------------------------------*/
986 /* TININative specific */
987 /*---------------------------------------------------------------------------------*/
989 #define OPTION_TINI_LIBID "--tini-libid"
991 static OPTION _tininative_options[] =
993 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" },
994 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" },
995 { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"},
996 { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"},
997 { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"},
998 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
999 { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds390 arithmetic accelerator"},
1000 { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"},
1001 { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"},
1002 { 0, OPTION_TINI_LIBID, NULL, "<nnnn> LibraryID used in -mTININative"},
1007 _tininative_parseOptions (int *pargc, char **argv, int *i)
1009 if (_ds390_parseOptions (pargc, argv, i))
1012 if (!strcmp (argv[*i], OPTION_TINI_LIBID))
1014 options.tini_libid = getIntArg (OPTION_TINI_LIBID, argv, i, *pargc);
1020 static void _tininative_init (void)
1022 asm_addTree (&asm_a390_mapping);
1025 static void _tininative_setDefaultOptions (void)
1027 options.model=MODEL_FLAT24;
1028 options.stack10bit=1;
1029 options.stackAuto = 1;
1032 static void _tininative_finaliseOptions (void)
1034 /* Hack-o-matic: if we are using the flat24 model,
1035 * adjust pointer sizes.
1037 if (options.model != MODEL_FLAT24) {
1038 options.model = MODEL_FLAT24 ;
1039 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
1041 port->s.fptr_size = 3;
1042 port->s.gptr_size = 4;
1044 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1046 port->stack.call_overhead += 2; /* This acounts for the extra byte
1047 * of return addres on the stack.
1048 * but is ugly. There must be a
1052 port->mem.default_local_map = xdata;
1053 port->mem.default_globl_map = xdata;
1055 if (!options.stack10bit) {
1056 options.stack10bit = 1;
1057 fprintf(stderr,"TININative supports only stack10bit \n");
1060 if (!options.stack_loc) options.stack_loc = 0x400008;
1062 /* generate native code 16*16 mul/div */
1063 if (options.useAccelerator)
1064 port->support.muldiv=2;
1066 port->support.muldiv=1;
1068 /* Fixup the memory map for the stack; it is now in
1069 * far space and requires a FPOINTER to access it.
1072 istack->ptrType = FPOINTER;
1076 static int _tininative_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
1081 static void _tininative_genAssemblerPreamble (FILE * of)
1083 fputs("$include(tini.inc)\n", of);
1084 fputs("$include(ds80c390.inc)\n", of);
1085 fputs("$include(tinimacro.inc)\n", of);
1086 fputs("$include(apiequ.inc)\n", of);
1087 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
1088 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
1089 /* Must be first and return 0 */
1090 fputs("Lib_Native_Init:\n",of);
1091 fputs("\tclr\ta\n",of);
1092 fputs("\tret\n",of);
1093 fputs("LibraryID:\n",of);
1094 fputs("\tdb \"DS\"\n",of);
1095 if (options.tini_libid) {
1096 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
1097 (options.tini_libid>>24 & 0xff),
1098 (options.tini_libid>>16 & 0xff),
1099 (options.tini_libid>>8 & 0xff),
1100 (options.tini_libid & 0xff));
1102 fprintf(of,"\tdb 0,0,0,0,0,1\n");
1106 static void _tininative_genAssemblerEnd (FILE * of)
1108 fputs("\tend\n",of);
1110 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
1111 static void _tininative_do_assemble (set *asmOptions)
1113 static const char *macroCmd[] = {
1114 "macro","$1.a51",NULL
1116 static const char *a390Cmd[] = {
1117 "a390","$1.mpp",NULL
1121 buildCmdLine(buffer,macroCmd,dstFileName,NULL,NULL,NULL);
1122 if (my_system(buffer)) {
1125 buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions);
1126 if (my_system(buffer)) {
1131 /* list of key words used by TININative */
1132 static char *_tininative_keywords[] =
1161 static builtins __tininative_builtins[] = {
1162 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
1163 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
1164 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
1166 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
1167 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
1168 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
1169 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
1170 /* TINI StateBlock related */
1171 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
1172 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
1173 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
1174 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
1175 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
1176 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
1177 /* Memory manager */
1178 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
1179 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
1180 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
1181 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
1182 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
1183 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
1184 /* System functions */
1185 { "System_ExecJavaProcess","c",2,{"cx*","i"}}, /* char System_ExecJavaProcess (char *,int) */
1186 { "System_GetRTCRegisters","v",1,{"cx*"}}, /* void System_GetRTCRegisters (char *) */
1187 { "System_SetRTCRegisters","v",1,{"cx*"}}, /* void System_SetRTCRegisters (char *) */
1188 { "System_ThreadSleep","v",2,{"l","c"}}, /* void System_ThreadSleep (long,char) */
1189 { "System_ThreadSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ThreadSleep_ExitCriticalSection (long,char) */
1190 { "System_ProcessSleep","v",2,{"l","c"}}, /* void System_ProcessSleep (long,char) */
1191 { "System_ProcessSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ProcessSleep_ExitCriticalSection (long,char) */
1192 { "System_ThreadResume","c",2,{"c","c"}}, /* char System_ThreadResume(char,char) */
1193 { "System_SaveJavaThreadState","v",0,{NULL}}, /* void System_SaveJavaThreadState() */
1194 { "System_RestoreJavaThreadState","v",0,{NULL}}, /* void System_RestoreJavaThreadState() */
1195 { "System_ProcessYield","v",0,{NULL}}, /* void System_ProcessYield() */
1196 { "System_ProcessSuspend","v",0,{NULL}}, /* void System_ProcessSuspend() */
1197 { "System_ProcessResume","v",1,{"c"}}, /* void System_ProcessResume(char) */
1198 { "System_RegisterPoll","c",1,{"vF*"}}, /* char System_RegisterPoll ((void *func pointer)()) */
1199 { "System_RemovePoll","c",1,{"vF*"}}, /* char System_RemovePoll ((void *func pointer)()) */
1200 { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */
1201 { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */
1202 { NULL , NULL,0, {NULL}} /* mark end of table */
1205 static const char *_a390Cmd[] =
1207 "macro", "$l", "$3", "$1.a51", NULL
1210 PORT tininative_port =
1214 "DS80C390", /* Target name */
1215 NULL, /* processor */
1218 FALSE, /* Emit glue around main */
1225 "-l", /* Options with debug */
1226 "-l", /* Options without debug */
1229 _tininative_do_assemble
1245 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1246 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
1248 /* tags for generic pointers */
1249 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
1267 "CONST (CODE)", // const_name - const data (code or not)
1268 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
1269 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
1270 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
1279 /* ds390 has an 16 bit mul & div */
1284 ds390_emitDebuggerSymbol
1287 255/4, /* maxCount */
1288 4, /* sizeofElement */
1289 {8,12,20}, /* sizeofMatchJump[] */
1290 {10,14,22}, /* sizeofRangeCompare[] */
1291 4, /* sizeofSubtract */
1292 7, /* sizeofDispatch */
1296 _tininative_parseOptions,
1297 _tininative_options,
1299 _tininative_finaliseOptions,
1300 _tininative_setDefaultOptions,
1301 ds390_assignRegisters,
1303 _tininative_keywords,
1304 _tininative_genAssemblerPreamble,
1305 _tininative_genAssemblerEnd,
1308 NULL, /* genInitStartup */
1309 _ds390_reset_regparm,
1314 hasExtBitOp, /* hasExtBitOp */
1315 oclsExpense, /* oclsExpense */
1317 TRUE, /* little endian */
1320 1, /* transform <= to ! > */
1321 1, /* transform >= to ! < */
1322 1, /* transform != to !(a == b) */
1324 FALSE, /* No array initializer support. */
1326 __tininative_builtins, /* table of builtin functions */
1327 FPOINTER, /* treat unqualified pointers as far pointers */
1328 0, /* DONOT reset labelKey */
1329 0, /* globals & local static NOT allowed */
1334 _ds400_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
1336 /* We can't generate a static IVT, since the boot rom creates one
1337 * for us in rom_init.
1339 * we must patch it as part of the C startup.
1341 dbuf_printf (oBuf, ";\tDS80C400 IVT must be generated at runtime.\n");
1342 dbuf_printf (oBuf, "\tsjmp\t__sdcc_400boot\n");
1343 dbuf_printf (oBuf, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
1344 dbuf_printf (oBuf, "\t.db\t0\t; selected bank: zero *should* work...\n");
1345 dbuf_printf (oBuf, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
1351 /*---------------------------------------------------------------------------------*/
1352 /* _ds400 specific */
1353 /*---------------------------------------------------------------------------------*/
1355 static OPTION _ds400_options[] =
1357 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds400 (default)" },
1358 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds400 (not supported yet)" },
1359 { 0, OPTION_STACK_SIZE, NULL, "Tells the linker to allocate this space for stack"},
1360 { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"},
1361 { 0, "--no-pack-iram", &options.no_pack_iram,"Tells the linker not to pack variables in internal ram"},
1362 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds400 (default)" },
1363 { 0, "--use-accelerator", &options.useAccelerator,"generate code for ds400 arithmetic accelerator"},
1364 { 0, "--protect-sp-update", &options.protect_sp_update,"will disable interrupts during ESP:SP updates"},
1365 { 0, "--parms-in-bank1", &options.parms_in_bank1,"use Bank1 for parameter passing"},
1370 _ds400_finaliseOptions (void)
1372 if (options.noXinitOpt) {
1376 // hackhack: we're a superset of the 390.
1377 addSet(&preArgvSet, Safe_strdup("-DSDCC_ds390"));
1378 addSet(&preArgvSet, Safe_strdup("-D__ds390"));
1380 /* Hack-o-matic: if we are using the flat24 model,
1381 * adjust pointer sizes.
1383 if (options.model != MODEL_FLAT24) {
1385 "*** warning: ds400 port small and large model experimental.\n");
1386 if (options.model == MODEL_LARGE)
1388 port->mem.default_local_map = xdata;
1389 port->mem.default_globl_map = xdata;
1393 port->mem.default_local_map = data;
1394 port->mem.default_globl_map = data;
1398 port->s.fptr_size = 3;
1399 port->s.gptr_size = 4;
1401 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1403 port->stack.call_overhead += 2; /* This acounts for the extra byte
1404 * of return addres on the stack.
1405 * but is ugly. There must be a
1409 port->mem.default_local_map = xdata;
1410 port->mem.default_globl_map = xdata;
1412 if (!options.stack10bit)
1415 "*** error: ds400 port only supports the 10 bit stack mode.\n");
1417 if (!options.stack_loc) options.stack_loc = 0xffdc00;
1418 // assumes IDM1:0 = 1:0, CMA = 1.
1421 /* generate native code 16*16 mul/div */
1422 if (options.useAccelerator)
1423 port->support.muldiv=2;
1425 port->support.muldiv=1;
1427 /* Fixup the memory map for the stack; it is now in
1428 * far space and requires a FPOINTER to access it.
1431 istack->ptrType = FPOINTER;
1433 if (options.parms_in_bank1) {
1434 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
1437 // the DS400 rom calling interface uses register bank 3.
1440 } /* MODEL_FLAT24 */
1443 static void _ds400_generateRomDataArea(FILE *fp, bool isMain)
1445 /* Only do this for the file containing main() */
1448 fprintf(fp, "%s", iComments2);
1449 fprintf(fp, "; the direct data area used by the DS80c400 ROM code.\n");
1450 fprintf(fp, "%s", iComments2);
1451 fprintf(fp, ".area ROMSEG (ABS,CON,DATA)\n\n");
1452 fprintf(fp, ".ds 24 ; 24 bytes of directs used starting at 0x68\n\n");
1456 static void _ds400_linkRomDataArea(FILE *fp)
1458 fprintf(fp, "-b ROMSEG = 0x0068\n");
1466 "DS80C400", /* Target name */
1470 TRUE, /* Emit glue around main */
1471 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1477 "-plosgffc", /* Options with debug */
1478 "-plosgff", /* Options without debug */
1481 NULL /* no do_assemble function */
1497 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1498 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
1501 /* tags for generic pointers */
1502 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
1518 "XISEG (XDATA)", // initialized xdata
1519 "XINIT (CODE)", // a code copy of xiseg
1520 "CONST (CODE)", // const_name - const data (code or not)
1521 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
1522 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
1523 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
1528 { _ds400_generateRomDataArea, _ds400_linkRomDataArea },
1532 /* ds390 has an 16 bit mul & div */
1537 ds390_emitDebuggerSymbol
1540 255/4, /* maxCount */
1541 4, /* sizeofElement */
1542 {8,12,20}, /* sizeofMatchJump[] */
1543 {10,14,22}, /* sizeofRangeCompare[] */
1544 4, /* sizeofSubtract */
1545 7, /* sizeofDispatch */
1549 _ds390_parseOptions,
1552 _ds400_finaliseOptions,
1553 _ds390_setDefaultOptions,
1554 ds390_assignRegisters,
1557 _ds390_genAssemblerPreamble,
1558 NULL, /* no genAssemblerEnd */
1561 NULL, /* genInitStartup */
1562 _ds390_reset_regparm,
1566 _ds390_nativeMulCheck,
1567 hasExtBitOp, /* hasExtBitOp */
1568 oclsExpense, /* oclsExpense */
1570 TRUE, /* little endian */
1573 1, /* transform <= to ! > */
1574 1, /* transform >= to ! < */
1575 1, /* transform != to !(a == b) */
1577 FALSE, /* No array initializer support. */
1579 __ds390_builtins, /* table of builtin functions */
1580 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1581 1, /* reset labelKey to 1 */
1582 1, /* globals & local static allowed */