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, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER },
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;
152 _ds390_finaliseOptions (void)
154 if (options.noXinitOpt) {
158 /* Hack-o-matic: if we are using the flat24 model,
159 * adjust pointer sizes.
161 if (options.model != MODEL_FLAT24) {
163 "*** warning: ds390 port small and large model experimental.\n");
164 if (options.model == MODEL_LARGE)
166 port->mem.default_local_map = xdata;
167 port->mem.default_globl_map = xdata;
171 port->mem.default_local_map = data;
172 port->mem.default_globl_map = data;
176 port->s.fptr_size = 3;
177 port->s.gptr_size = 4;
179 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
181 port->stack.call_overhead += 2; /* This acounts for the extra byte
182 * of return addres on the stack.
183 * but is ugly. There must be a
187 port->mem.default_local_map = xdata;
188 port->mem.default_globl_map = xdata;
190 if (!options.stack10bit)
193 "*** error: ds390 port only supports the 10 bit stack mode.\n");
195 if (!options.stack_loc) options.stack_loc = 0x400008;
198 /* generate native code 16*16 mul/div */
199 if (options.useAccelerator)
200 port->support.muldiv=2;
202 port->support.muldiv=1;
204 /* Fixup the memory map for the stack; it is now in
205 * far space and requires a FPOINTER to access it.
208 istack->ptrType = FPOINTER;
210 if (options.parms_in_bank1) {
211 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
217 _ds390_setDefaultOptions (void)
219 options.model=MODEL_FLAT24;
220 options.stack10bit=1;
224 _ds390_getRegName (struct regs *reg)
231 extern char * iComments2;
234 _ds390_genAssemblerPreamble (FILE * of)
236 fputs (iComments2, of);
237 fputs ("; CPU specific extensions\n",of);
238 fputs (iComments2, of);
240 if (options.model == MODEL_FLAT24)
241 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
243 fputs ("dpl1\t=\t0x84\n", of);
244 fputs ("dph1\t=\t0x85\n", of);
245 fputs ("dps\t=\t0x86\n", of);
246 fputs ("dpx\t=\t0x93\n", of);
247 fputs ("dpx1\t=\t0x95\n", of);
248 fputs ("esp\t=\t0x9B\n", of);
249 fputs ("ap\t=\t0x9C\n", of);
250 fputs ("_ap\t=\t0x9C\n", of);
251 fputs ("mcnt0\t=\t0xD1\n", of);
252 fputs ("mcnt1\t=\t0xD2\n", of);
253 fputs ("ma\t=\t0xD3\n", of);
254 fputs ("mb\t=\t0xD4\n", of);
255 fputs ("mc\t=\t0xD5\n", of);
256 fputs ("F1\t=\t0xD1\t; user flag\n", of);
257 if (options.parms_in_bank1) {
259 for (i=0; i < 8 ; i++ )
260 fprintf (of,"b1_%d\t=\t0x%02X\n",i,8+i);
264 /* Generate interrupt vector table. */
266 _ds390_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
270 if (options.model != MODEL_FLAT24)
272 dbuf_printf (oBuf, "\tljmp\t__sdcc_gsinit_startup\n");
274 /* now for the other interrupts */
275 for (i = 0; i < maxInterrupts; i++)
279 dbuf_printf (oBuf, "\tljmp\t%s\n", interrupts[i]->rname);
280 if ( i != maxInterrupts - 1 )
281 dbuf_printf (oBuf, "\t.ds\t5\n");
285 dbuf_printf (oBuf, "\treti\n");
286 if ( i != maxInterrupts - 1 )
287 dbuf_printf (oBuf, "\t.ds\t7\n");
293 dbuf_printf (oBuf, "\tajmp\t__reset_vect\n");
295 /* now for the other interrupts */
296 for (i = 0; i < maxInterrupts; i++)
300 dbuf_printf (oBuf, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
304 dbuf_printf (oBuf, "\treti\n\t.ds\t7\n");
308 dbuf_printf (oBuf, "__reset_vect:\n\tljmp\t__sdcc_gsinit_startup\n");
313 /* Generate code to copy XINIT to XISEG */
314 static void _ds390_genXINIT (FILE * of) {
315 fprintf (of, "; _ds390_genXINIT() start\n");
316 fprintf (of, " mov a,#l_XINIT\n");
317 fprintf (of, " orl a,#l_XINIT>>8\n");
318 fprintf (of, " jz 00003$\n");
319 fprintf (of, " mov a,#s_XINIT\n");
320 fprintf (of, " add a,#l_XINIT\n");
321 fprintf (of, " mov r1,a\n");
322 fprintf (of, " mov a,#s_XINIT>>8\n");
323 fprintf (of, " addc a,#l_XINIT>>8\n");
324 fprintf (of, " mov r2,a\n");
325 fprintf (of, " mov dptr,#s_XINIT\n");
326 fprintf (of, " mov dps,#0x21\n");
327 fprintf (of, " mov dptr,#s_XISEG\n");
328 fprintf (of, "00001$: clr a\n");
329 fprintf (of, " movc a,@a+dptr\n");
330 fprintf (of, " movx @dptr,a\n");
331 fprintf (of, " inc dptr\n");
332 fprintf (of, " inc dptr\n");
333 fprintf (of, "00002$: mov a,dpl\n");
334 fprintf (of, " cjne a,ar1,00001$\n");
335 fprintf (of, " mov a,dph\n");
336 fprintf (of, " cjne a,ar2,00001$\n");
337 fprintf (of, " mov dps,#0\n");
338 fprintf (of, "00003$:\n");
339 fprintf (of, "; _ds390_genXINIT() end\n");
342 /* Do CSE estimation */
343 static bool cseCostEstimation (iCode *ic, iCode *pdic)
345 operand *result = IC_RESULT(ic);
346 //operand *right = IC_RIGHT(ic);
347 //operand *left = IC_LEFT(ic);
348 sym_link *result_type = operandType(result);
349 //sym_link *right_type = (right ? operandType(right) : 0);
350 //sym_link *left_type = (left ? operandType(left) : 0);
352 /* if it is a pointer then return ok for now */
353 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
355 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
356 so we will cse only if they are local (i.e. both ic & pdic belong to
357 the same basic block */
358 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
359 /* then if they are the same Basic block then ok */
360 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
364 /* for others it is cheaper to do the cse */
368 bool _ds390_nativeMulCheck(iCode *ic, sym_link *left, sym_link *right)
370 return FALSE; // #STUB
373 /* Indicate which extended bit operations this port supports */
375 hasExtBitOp (int op, int size)
380 || (op == SWAP && size <= 2)
387 /* Indicate the expense of an access to an output storage class */
389 oclsExpense (struct memmap *oclass)
391 if (IN_FARSPACE(oclass))
398 instructionSize(char *inst, char *op1, char *op2)
400 int isflat24 = (options.model == MODEL_FLAT24);
402 #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
403 #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0')
404 #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0')
405 #define IS_Rn(s) (*(s) == 'r' && *(s+1) >= '0' && *(s+1) <= '7')
406 #define IS_atRi(s) (*(s) == '@' && *(s+1) == 'r')
408 /* Based on the current (2003-08-22) code generation for the
409 small library, the top instruction probability is:
420 /* mov, push, & pop are the 69% of the cases. Check them first! */
423 if (*(inst+3)=='x') return 1; /* movx */
424 if (*(inst+3)=='c') return 1; /* movc */
425 if (IS_C (op1) || IS_C (op2)) return 2;
428 if (IS_Rn (op2) || IS_atRi (op2)) return 1;
431 if (IS_Rn(op1) || IS_atRi(op1))
433 if (IS_A(op2)) return 1;
436 if (strcmp (op1, "dptr") == 0) return 3+isflat24;
437 if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2;
441 if (ISINST ("push")) return 2;
442 if (ISINST ("pop")) return 2;
444 if (ISINST ("lcall")) return 3+isflat24;
445 if (ISINST ("ret")) return 1;
446 if (ISINST ("ljmp")) return 3+isflat24;
447 if (ISINST ("sjmp")) return 2;
448 if (ISINST ("rlc")) return 1;
449 if (ISINST ("rrc")) return 1;
450 if (ISINST ("rl")) return 1;
451 if (ISINST ("rr")) return 1;
452 if (ISINST ("swap")) return 1;
453 if (ISINST ("jc")) return 2;
454 if (ISINST ("jnc")) return 2;
455 if (ISINST ("jb")) return 3;
456 if (ISINST ("jnb")) return 3;
457 if (ISINST ("jbc")) return 3;
458 if (ISINST ("jmp")) return 1; // always jmp @a+dptr
459 if (ISINST ("jz")) return 2;
460 if (ISINST ("jnz")) return 2;
461 if (ISINST ("cjne")) return 3;
462 if (ISINST ("mul")) return 1;
463 if (ISINST ("div")) return 1;
464 if (ISINST ("da")) return 1;
465 if (ISINST ("xchd")) return 1;
466 if (ISINST ("reti")) return 1;
467 if (ISINST ("nop")) return 1;
468 if (ISINST ("acall")) return 2+isflat24;
469 if (ISINST ("ajmp")) return 2+isflat24;
472 if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch"))
474 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
477 if (ISINST ("inc") || ISINST ("dec"))
479 if (IS_A(op1) || IS_Rn(op1) || IS_atRi(op1)) return 1;
480 if (strcmp(op1, "dptr") == 0) return 1;
483 if (ISINST ("anl") || ISINST ("orl") || ISINST ("xrl"))
485 if (IS_C(op1)) return 2;
488 if (IS_Rn(op2) || IS_atRi(op2)) return 1;
493 if (IS_A(op2)) return 2;
497 if (ISINST ("clr") || ISINST ("setb") || ISINST ("cpl"))
499 if (IS_A(op1) || IS_C(op1)) return 1;
504 if (IS_Rn(op1)) return 2;
508 /* If the instruction is unrecognized, we shouldn't try to optimize. */
509 /* Return a large value to discourage optimization. */
514 ds390newAsmLineNode (int currentDPS)
518 aln = Safe_alloc ( sizeof (asmLineNode));
520 aln->regsRead = NULL;
521 aln->regsWritten = NULL;
522 aln->initialized = 0;
523 aln->currentDPS = currentDPS;
529 typedef struct ds390operanddata
537 static ds390operanddata ds390operandDataTable[] =
541 {"ab", A_IDX, B_IDX},
556 {"dph", DPH_IDX, -1},
557 {"dph0", DPH_IDX, -1},
558 {"dph1", DPH1_IDX, -1},
559 {"dpl", DPL_IDX, -1},
560 {"dpl0", DPL_IDX, -1},
561 {"dpl1", DPL1_IDX, -1},
562 /* {"dptr", DPL_IDX, DPH_IDX}, */ /* dptr is special, based on currentDPS */
563 {"dps", DPS_IDX, -1},
564 {"dpx", DPX_IDX, -1},
565 {"dpx0", DPX_IDX, -1},
566 {"dpx1", DPX1_IDX, -1},
571 {"psw", CND_IDX, -1},
583 ds390operandCompare (const void *key, const void *member)
585 return strcmp((const char *)key, ((ds390operanddata *)member)->name);
589 updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS)
591 ds390operanddata *opdat;
597 dot = strchr(op, '.');
601 opdat = bsearch (op, ds390operandDataTable,
602 sizeof(ds390operandDataTable)/sizeof(ds390operanddata),
603 sizeof(ds390operanddata), ds390operandCompare);
607 regIdx1 = opdat->regIdx1;
608 regIdx2 = opdat->regIdx2;
610 if (!strcmp(op, "dptr"))
626 if (strchr(optype,'r'))
629 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx1);
631 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx2);
633 aln->regsRead = bitVectSetBit (aln->regsRead, regIdx3);
635 if (strchr(optype,'w'))
638 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx1);
640 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx2);
642 aln->regsWritten = bitVectSetBit (aln->regsWritten, regIdx3);
646 if (!strcmp(op, "@r0"))
647 aln->regsRead = bitVectSetBit (aln->regsRead, R0_IDX);
648 if (!strcmp(op, "@r1"))
649 aln->regsRead = bitVectSetBit (aln->regsRead, R1_IDX);
650 if (strstr(op, "dptr"))
654 aln->regsRead = bitVectSetBit (aln->regsRead, DPL_IDX);
655 aln->regsRead = bitVectSetBit (aln->regsRead, DPH_IDX);
656 aln->regsRead = bitVectSetBit (aln->regsRead, DPX_IDX);
660 aln->regsRead = bitVectSetBit (aln->regsRead, DPL1_IDX);
661 aln->regsRead = bitVectSetBit (aln->regsRead, DPH1_IDX);
662 aln->regsRead = bitVectSetBit (aln->regsRead, DPX1_IDX);
665 if (strstr(op, "a+"))
666 aln->regsRead = bitVectSetBit (aln->regsRead, A_IDX);
670 typedef struct ds390opcodedata
680 static ds390opcodedata ds390opcodeDataTable[] =
682 {"acall","j", "", "", ""},
683 {"add", "", "w", "rw", "r"},
684 {"addc", "", "rw", "rw", "r"},
685 {"ajmp", "j", "", "", ""},
686 {"anl", "", "", "rw", "r"},
687 {"cjne", "j", "w", "r", "r"},
688 {"clr", "", "", "w", ""},
689 {"cpl", "", "", "rw", ""},
690 {"da", "", "rw", "rw", ""},
691 {"dec", "", "", "rw", ""},
692 {"div", "", "w", "rw", ""},
693 {"djnz", "j", "", "rw", ""},
694 {"inc", "", "", "rw", ""},
695 {"jb", "j", "", "r", ""},
696 {"jbc", "j", "", "rw", ""},
697 {"jc", "j", "", "", ""},
698 {"jmp", "j", "", "", ""},
699 {"jnb", "j", "", "r", ""},
700 {"jnc", "j", "", "", ""},
701 {"jnz", "j", "", "", ""},
702 {"jz", "j", "", "", ""},
703 {"lcall","j", "", "", ""},
704 {"ljmp", "j", "", "", ""},
705 {"mov", "", "", "w", "r"},
706 {"movc", "", "", "w", "r"},
707 {"movx", "", "", "w", "r"},
708 {"mul", "", "w", "rw", ""},
709 {"nop", "", "", "", ""},
710 {"orl", "", "", "rw", "r"},
711 {"pop", "", "", "w", ""},
712 {"push", "", "", "r", ""},
713 {"ret", "j", "", "", ""},
714 {"reti", "j", "", "", ""},
715 {"rl", "", "", "rw", ""},
716 {"rlc", "", "rw", "rw", ""},
717 {"rr", "", "", "rw", ""},
718 {"rrc", "", "rw", "rw", ""},
719 {"setb", "", "", "w", ""},
720 {"sjmp", "j", "", "", ""},
721 {"subb", "", "rw", "rw", "r"},
722 {"swap", "", "", "rw", ""},
723 {"xch", "", "", "rw", "rw"},
724 {"xchd", "", "", "rw", "rw"},
725 {"xrl", "", "", "rw", "r"},
729 ds390opcodeCompare (const void *key, const void *member)
731 return strcmp((const char *)key, ((ds390opcodedata *)member)->name);
735 asmLineNodeFromLineNode (lineNode *ln, int currentDPS)
737 asmLineNode *aln = ds390newAsmLineNode(currentDPS);
738 char *op, op1[256], op2[256];
742 ds390opcodedata *opdat;
744 aln->initialized = 1;
748 while (*p && isspace(*p)) p++;
749 for (op = inst, opsize=1; *p; p++)
751 if (isspace(*p) || *p == ';' || *p == ':' || *p == '=')
754 if (opsize < sizeof(inst))
755 *op++ = tolower(*p), opsize++;
759 if (*p == ';' || *p == ':' || *p == '=')
762 while (*p && isspace(*p)) p++;
766 for (op = op1, opsize=1; *p && *p != ','; p++)
768 if (!isspace(*p) && opsize < sizeof(op1))
769 *op++ = tolower(*p), opsize++;
774 for (op = op2, opsize=1; *p && *p != ','; p++)
776 if (!isspace(*p) && opsize < sizeof(op2))
777 *op++ = tolower(*p), opsize++;
781 aln->size = instructionSize(inst, op1, op2);
783 aln->regsRead = newBitVect (END_IDX);
784 aln->regsWritten = newBitVect (END_IDX);
786 opdat = bsearch (inst, ds390opcodeDataTable,
787 sizeof(ds390opcodeDataTable)/sizeof(ds390opcodedata),
788 sizeof(ds390opcodedata), ds390opcodeCompare);
792 updateOpRW (aln, op1, opdat->op1type, currentDPS);
793 updateOpRW (aln, op2, opdat->op2type, currentDPS);
794 if (strchr(opdat->pswtype,'r'))
795 aln->regsRead = bitVectSetBit (aln->regsRead, CND_IDX);
796 if (strchr(opdat->pswtype,'w'))
797 aln->regsWritten = bitVectSetBit (aln->regsWritten, CND_IDX);
804 initializeAsmLineNode (lineNode *line)
807 line->aln = asmLineNodeFromLineNode (line, 0);
808 else if (line->aln && !line->aln->initialized)
810 int currentDPS = line->aln->currentDPS;
812 line->aln = asmLineNodeFromLineNode (line, currentDPS);
817 getInstructionSize (lineNode *line)
819 initializeAsmLineNode (line);
820 return line->aln->size;
824 getRegsRead (lineNode *line)
826 initializeAsmLineNode (line);
827 return line->aln->regsRead;
831 getRegsWritten (lineNode *line)
833 initializeAsmLineNode (line);
834 return line->aln->regsWritten;
838 /** $1 is always the basename.
839 $2 is always the output file.
841 $l is the list of extra options that should be there somewhere...
842 MUST be terminated with a NULL.
844 static const char *_linkCmd[] =
846 "aslink", "-nf", "\"$1\"", NULL
849 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
850 static const char *_asmCmd[] =
852 "asx8051", "$l", "$3", "\"$1.asm\"", NULL
860 "DS80C390", /* Target name */
864 TRUE, /* Emit glue around main */
865 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
871 "-plosgffc", /* Options with debug */
872 "-plosgff", /* Options without debug */
875 NULL /* no do_assemble function */
891 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
892 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
895 /* tags for generic pointers */
896 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
912 "XISEG (XDATA)", // initialized xdata
913 "XINIT (CODE)", // a code copy of xiseg
914 "CONST (CODE)", // const_name - const data (code or not)
915 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
916 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
917 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
926 /* ds390 has an 16 bit mul & div */
931 ds390_emitDebuggerSymbol
934 255/4, /* maxCount */
935 4, /* sizeofElement */
936 {8,12,20}, /* sizeofMatchJump[] */
937 {10,14,22}, /* sizeofRangeCompare[] */
938 4, /* sizeofSubtract */
939 7, /* sizeofDispatch */
946 _ds390_finaliseOptions,
947 _ds390_setDefaultOptions,
948 ds390_assignRegisters,
951 _ds390_genAssemblerPreamble,
952 NULL, /* no genAssemblerEnd */
955 NULL, /* genInitStartup */
956 _ds390_reset_regparm,
960 _ds390_nativeMulCheck,
961 hasExtBitOp, /* hasExtBitOp */
962 oclsExpense, /* oclsExpense */
964 TRUE, /* little endian */
967 1, /* transform <= to ! > */
968 1, /* transform >= to ! < */
969 1, /* transform != to !(a == b) */
971 FALSE, /* No array initializer support. */
973 __ds390_builtins, /* table of builtin functions */
974 GPOINTER, /* treat unqualified pointers as "generic" pointers */
975 1, /* reset labelKey to 1 */
976 1, /* globals & local static allowed */
980 /*---------------------------------------------------------------------------------*/
981 /* TININative specific */
982 /*---------------------------------------------------------------------------------*/
984 #define OPTION_TINI_LIBID "--tini-libid"
986 static OPTION _tininative_options[] =
988 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds390 (default)" },
989 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds390 (not supported yet)" },
990 { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER },
991 { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"},
992 { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"},
993 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
994 { 0, "--use-accelerator", &options.useAccelerator, "generate code for ds390 arithmetic accelerator"},
995 { 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"},
996 { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"},
997 { 0, OPTION_TINI_LIBID, &options.tini_libid, "<nnnn> LibraryID used in -mTININative", CLAT_INTEGER },
1001 static void _tininative_init (void)
1003 asm_addTree (&asm_a390_mapping);
1006 static void _tininative_setDefaultOptions (void)
1008 options.model=MODEL_FLAT24;
1009 options.stack10bit=1;
1010 options.stackAuto = 1;
1013 static void _tininative_finaliseOptions (void)
1015 /* Hack-o-matic: if we are using the flat24 model,
1016 * adjust pointer sizes.
1018 if (options.model != MODEL_FLAT24) {
1019 options.model = MODEL_FLAT24 ;
1020 fprintf(stderr,"TININative supports only MODEL FLAT24\n");
1022 port->s.fptr_size = 3;
1023 port->s.gptr_size = 4;
1025 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1027 port->stack.call_overhead += 2; /* This acounts for the extra byte
1028 * of return addres on the stack.
1029 * but is ugly. There must be a
1033 port->mem.default_local_map = xdata;
1034 port->mem.default_globl_map = xdata;
1036 if (!options.stack10bit) {
1037 options.stack10bit = 1;
1038 fprintf(stderr,"TININative supports only stack10bit \n");
1041 if (!options.stack_loc) options.stack_loc = 0x400008;
1043 /* generate native code 16*16 mul/div */
1044 if (options.useAccelerator)
1045 port->support.muldiv=2;
1047 port->support.muldiv=1;
1049 /* Fixup the memory map for the stack; it is now in
1050 * far space and requires a FPOINTER to access it.
1053 istack->ptrType = FPOINTER;
1057 static int _tininative_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
1062 static void _tininative_genAssemblerPreamble (FILE * of)
1064 fputs("$include(tini.inc)\n", of);
1065 fputs("$include(ds80c390.inc)\n", of);
1066 fputs("$include(tinimacro.inc)\n", of);
1067 fputs("$include(apiequ.inc)\n", of);
1068 fputs("_bpx EQU 01Eh \t\t; _bpx (frame pointer) mapped to R8_B3:R7_B3\n", of);
1069 fputs("_ap EQU 01Dh \t\t; _ap mapped to R6_B3\n", of);
1070 /* Must be first and return 0 */
1071 fputs("Lib_Native_Init:\n",of);
1072 fputs("\tclr\ta\n",of);
1073 fputs("\tret\n",of);
1074 fputs("LibraryID:\n",of);
1075 fputs("\tdb \"DS\"\n",of);
1076 if (options.tini_libid) {
1077 fprintf(of,"\tdb 0,0,0%02xh,0%02xh,0%02xh,0%02xh\n",
1078 (options.tini_libid>>24 & 0xff),
1079 (options.tini_libid>>16 & 0xff),
1080 (options.tini_libid>>8 & 0xff),
1081 (options.tini_libid & 0xff));
1083 fprintf(of,"\tdb 0,0,0,0,0,1\n");
1087 static void _tininative_genAssemblerEnd (FILE * of)
1089 fputs("\tend\n",of);
1091 /* tininative assembler , calls "macro", if it succeeds calls "a390" */
1092 static void _tininative_do_assemble (set *asmOptions)
1094 static const char *macroCmd[] = {
1095 "macro","$1.a51",NULL
1097 static const char *a390Cmd[] = {
1098 "a390","$1.mpp",NULL
1102 buildCmdLine(buffer,macroCmd,dstFileName,NULL,NULL,NULL);
1103 if (my_system(buffer)) {
1106 buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions);
1107 if (my_system(buffer)) {
1112 /* list of key words used by TININative */
1113 static char *_tininative_keywords[] =
1142 static builtins __tininative_builtins[] = {
1143 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
1144 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
1145 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
1147 { "NatLib_LoadByte","c",1,{"c"}}, /* char Natlib_LoadByte (0 based parameter number) */
1148 { "NatLib_LoadShort","s",1,{"c"}}, /* short Natlib_LoadShort (0 based parameter number) */
1149 { "NatLib_LoadInt","l",1,{"c"}}, /* long Natlib_LoadLong (0 based parameter number) */
1150 { "NatLib_LoadPointer","cx*",1,{"c"}}, /* long Natlib_LoadPointer (0 based parameter number) */
1151 /* TINI StateBlock related */
1152 { "NatLib_InstallImmutableStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallImmutableStateBlock(state block *,int handle) */
1153 { "NatLib_InstallEphemeralStateBlock","c",2,{"vx*","us"}},/* char NatLib_InstallEphemeralStateBlock(state block *,int handle) */
1154 { "NatLib_RemoveImmutableStateBlock","v",0,{NULL}},/* void NatLib_RemoveImmutableStateBlock() */
1155 { "NatLib_RemoveEphemeralStateBlock","v",0,{NULL}},/* void NatLib_RemoveEphemeralStateBlock() */
1156 { "NatLib_GetImmutableStateBlock","i",0,{NULL}}, /* int NatLib_GetImmutableStateBlock () */
1157 { "NatLib_GetEphemeralStateBlock","i",0,{NULL}}, /* int NatLib_GetEphemeralStateBlock () */
1158 /* Memory manager */
1159 { "MM_XMalloc","i",1,{"l"}}, /* int MM_XMalloc (long) */
1160 { "MM_Malloc","i",1,{"i"}}, /* int MM_Malloc (int) */
1161 { "MM_ApplicationMalloc","i",1,{"i"}}, /* int MM_ApplicationMalloc (int) */
1162 { "MM_Free","i",1,{"i"}}, /* int MM_Free (int) */
1163 { "MM_Deref","cx*",1,{"i"}}, /* char *MM_Free (int) */
1164 { "MM_UnrestrictedPersist","c",1,{"i"}}, /* char MM_UnrestrictedPersist (int) */
1165 /* System functions */
1166 { "System_ExecJavaProcess","c",2,{"cx*","i"}}, /* char System_ExecJavaProcess (char *,int) */
1167 { "System_GetRTCRegisters","v",1,{"cx*"}}, /* void System_GetRTCRegisters (char *) */
1168 { "System_SetRTCRegisters","v",1,{"cx*"}}, /* void System_SetRTCRegisters (char *) */
1169 { "System_ThreadSleep","v",2,{"l","c"}}, /* void System_ThreadSleep (long,char) */
1170 { "System_ThreadSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ThreadSleep_ExitCriticalSection (long,char) */
1171 { "System_ProcessSleep","v",2,{"l","c"}}, /* void System_ProcessSleep (long,char) */
1172 { "System_ProcessSleep_ExitCriticalSection","v",2,{"l","c"}},/* void System_ProcessSleep_ExitCriticalSection (long,char) */
1173 { "System_ThreadResume","c",2,{"c","c"}}, /* char System_ThreadResume(char,char) */
1174 { "System_SaveJavaThreadState","v",0,{NULL}}, /* void System_SaveJavaThreadState() */
1175 { "System_RestoreJavaThreadState","v",0,{NULL}}, /* void System_RestoreJavaThreadState() */
1176 { "System_ProcessYield","v",0,{NULL}}, /* void System_ProcessYield() */
1177 { "System_ProcessSuspend","v",0,{NULL}}, /* void System_ProcessSuspend() */
1178 { "System_ProcessResume","v",1,{"c"}}, /* void System_ProcessResume(char) */
1179 { "System_RegisterPoll","c",1,{"vF*"}}, /* char System_RegisterPoll ((void *func pointer)()) */
1180 { "System_RemovePoll","c",1,{"vF*"}}, /* char System_RemovePoll ((void *func pointer)()) */
1181 { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */
1182 { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */
1183 { NULL , NULL,0, {NULL}} /* mark end of table */
1186 static const char *_a390Cmd[] =
1188 "macro", "$l", "$3", "$1.a51", NULL
1191 PORT tininative_port =
1195 "DS80C390", /* Target name */
1196 NULL, /* processor */
1199 FALSE, /* Emit glue around main */
1206 "-l", /* Options with debug */
1207 "-l", /* Options without debug */
1210 _tininative_do_assemble
1226 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1227 1, 2, 2, 4, 1, 3, 3, 1, 4, 4
1229 /* tags for generic pointers */
1230 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
1248 "CONST (CODE)", // const_name - const data (code or not)
1249 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
1250 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
1251 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
1260 /* ds390 has an 16 bit mul & div */
1265 ds390_emitDebuggerSymbol
1268 255/4, /* maxCount */
1269 4, /* sizeofElement */
1270 {8,12,20}, /* sizeofMatchJump[] */
1271 {10,14,22}, /* sizeofRangeCompare[] */
1272 4, /* sizeofSubtract */
1273 7, /* sizeofDispatch */
1277 _ds390_parseOptions,
1278 _tininative_options,
1280 _tininative_finaliseOptions,
1281 _tininative_setDefaultOptions,
1282 ds390_assignRegisters,
1284 _tininative_keywords,
1285 _tininative_genAssemblerPreamble,
1286 _tininative_genAssemblerEnd,
1289 NULL, /* genInitStartup */
1290 _ds390_reset_regparm,
1295 hasExtBitOp, /* hasExtBitOp */
1296 oclsExpense, /* oclsExpense */
1298 TRUE, /* little endian */
1301 1, /* transform <= to ! > */
1302 1, /* transform >= to ! < */
1303 1, /* transform != to !(a == b) */
1305 FALSE, /* No array initializer support. */
1307 __tininative_builtins, /* table of builtin functions */
1308 FPOINTER, /* treat unqualified pointers as far pointers */
1309 0, /* DONOT reset labelKey */
1310 0, /* globals & local static NOT allowed */
1315 _ds400_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
1317 /* We can't generate a static IVT, since the boot rom creates one
1318 * for us in rom_init.
1320 * we must patch it as part of the C startup.
1322 dbuf_printf (oBuf, ";\tDS80C400 IVT must be generated at runtime.\n");
1323 dbuf_printf (oBuf, "\tsjmp\t__sdcc_400boot\n");
1324 dbuf_printf (oBuf, "\t.ascii\t'TINI'\t; required signature for 400 boot loader.\n");
1325 dbuf_printf (oBuf, "\t.db\t0\t; selected bank: zero *should* work...\n");
1326 dbuf_printf (oBuf, "\t__sdcc_400boot:\tljmp\t__sdcc_gsinit_startup\n");
1332 /*---------------------------------------------------------------------------------*/
1333 /* _ds400 specific */
1334 /*---------------------------------------------------------------------------------*/
1336 static OPTION _ds400_options[] =
1338 { 0, OPTION_FLAT24_MODEL, NULL, "use the flat24 model for the ds400 (default)" },
1339 { 0, OPTION_STACK_8BIT, NULL, "use the 8bit stack for the ds400 (not supported yet)" },
1340 { 0, OPTION_STACK_SIZE, &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER },
1341 { 0, "--pack-iram", NULL, "Tells the linker to pack variables in internal ram (default)"},
1342 { 0, "--no-pack-iram", &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"},
1343 { 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds400 (default)" },
1344 { 0, "--use-accelerator", &options.useAccelerator, "generate code for ds400 arithmetic accelerator"},
1345 { 0, "--protect-sp-update", &options.protect_sp_update, "will disable interrupts during ESP:SP updates"},
1346 { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"},
1351 _ds400_finaliseOptions (void)
1353 if (options.noXinitOpt) {
1357 // hackhack: we're a superset of the 390.
1358 addSet(&preArgvSet, Safe_strdup("-DSDCC_ds390"));
1359 addSet(&preArgvSet, Safe_strdup("-D__ds390"));
1361 /* Hack-o-matic: if we are using the flat24 model,
1362 * adjust pointer sizes.
1364 if (options.model != MODEL_FLAT24) {
1366 "*** warning: ds400 port small and large model experimental.\n");
1367 if (options.model == MODEL_LARGE)
1369 port->mem.default_local_map = xdata;
1370 port->mem.default_globl_map = xdata;
1374 port->mem.default_local_map = data;
1375 port->mem.default_globl_map = data;
1379 port->s.fptr_size = 3;
1380 port->s.gptr_size = 4;
1382 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
1384 port->stack.call_overhead += 2; /* This acounts for the extra byte
1385 * of return addres on the stack.
1386 * but is ugly. There must be a
1390 port->mem.default_local_map = xdata;
1391 port->mem.default_globl_map = xdata;
1393 if (!options.stack10bit)
1396 "*** error: ds400 port only supports the 10 bit stack mode.\n");
1398 if (!options.stack_loc) options.stack_loc = 0xffdc00;
1399 // assumes IDM1:0 = 1:0, CMA = 1.
1402 /* generate native code 16*16 mul/div */
1403 if (options.useAccelerator)
1404 port->support.muldiv=2;
1406 port->support.muldiv=1;
1408 /* Fixup the memory map for the stack; it is now in
1409 * far space and requires a FPOINTER to access it.
1412 istack->ptrType = FPOINTER;
1414 if (options.parms_in_bank1) {
1415 addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
1418 // the DS400 rom calling interface uses register bank 3.
1421 } /* MODEL_FLAT24 */
1424 static void _ds400_generateRomDataArea(FILE *fp, bool isMain)
1426 /* Only do this for the file containing main() */
1429 fprintf(fp, "%s", iComments2);
1430 fprintf(fp, "; the direct data area used by the DS80c400 ROM code.\n");
1431 fprintf(fp, "%s", iComments2);
1432 fprintf(fp, ".area ROMSEG (ABS,CON,DATA)\n\n");
1433 fprintf(fp, ".ds 24 ; 24 bytes of directs used starting at 0x68\n\n");
1437 static void _ds400_linkRomDataArea(FILE *fp)
1439 fprintf(fp, "-b ROMSEG = 0x0068\n");
1447 "DS80C400", /* Target name */
1451 TRUE, /* Emit glue around main */
1452 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1458 "-plosgffc", /* Options with debug */
1459 "-plosgff", /* Options without debug */
1462 NULL /* no do_assemble function */
1478 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
1479 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
1482 /* tags for generic pointers */
1483 { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */
1499 "XISEG (XDATA)", // initialized xdata
1500 "XINIT (CODE)", // a code copy of xiseg
1501 "CONST (CODE)", // const_name - const data (code or not)
1502 "CABS (ABS,CODE)", // cabs_name - const absolute data (code or not)
1503 "XABS (ABS,XDATA)", // xabs_name - absolute xdata/pdata
1504 "IABS (ABS,DATA)", // iabs_name - absolute idata/data
1509 { _ds400_generateRomDataArea, _ds400_linkRomDataArea },
1513 /* ds390 has an 16 bit mul & div */
1518 ds390_emitDebuggerSymbol
1521 255/4, /* maxCount */
1522 4, /* sizeofElement */
1523 {8,12,20}, /* sizeofMatchJump[] */
1524 {10,14,22}, /* sizeofRangeCompare[] */
1525 4, /* sizeofSubtract */
1526 7, /* sizeofDispatch */
1530 _ds390_parseOptions,
1533 _ds400_finaliseOptions,
1534 _ds390_setDefaultOptions,
1535 ds390_assignRegisters,
1538 _ds390_genAssemblerPreamble,
1539 NULL, /* no genAssemblerEnd */
1542 NULL, /* genInitStartup */
1543 _ds390_reset_regparm,
1547 _ds390_nativeMulCheck,
1548 hasExtBitOp, /* hasExtBitOp */
1549 oclsExpense, /* oclsExpense */
1551 TRUE, /* little endian */
1554 1, /* transform <= to ! > */
1555 1, /* transform >= to ! < */
1556 1, /* transform != to !(a == b) */
1558 FALSE, /* No array initializer support. */
1560 __ds390_builtins, /* table of builtin functions */
1561 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1562 1, /* reset labelKey to 1 */
1563 1, /* globals & local static allowed */