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.
12 static char _defaultRules[] =
17 /* list of key words used by msc51 */
18 static char *_ds390_keywords[] =
46 static builtins __ds390_builtins[] = {
47 { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
48 { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code char *,int) */
49 { "__builtin_memset_x","v",3,{"cx*","c","i"}}, /* void __builtin_memset (xdata char *,char,int) */
50 { NULL , NULL,0, {NULL}} /* mark end of table */
52 void ds390_assignRegisters (eBBlock ** ebbs, int count);
54 static int regParmFlg = 0; /* determine if we can register a parameter */
59 asm_addTree (&asm_asxxxx_mapping);
63 _ds390_reset_regparm ()
69 _ds390_regparm (sym_link * l)
71 /* for this processor it is simple
72 can pass only the first parameter in a register */
81 _ds390_parseOptions (int *pargc, char **argv, int *i)
83 /* TODO: allow port-specific command line options to specify
90 _ds390_finaliseOptions (void)
92 /* Hack-o-matic: if we are using the flat24 model,
93 * adjust pointer sizes.
95 if (options.model != MODEL_FLAT24) {
97 "*** warning: ds390 port small and large model experimental.\n");
98 if (options.model == MODEL_LARGE)
100 port->mem.default_local_map = xdata;
101 port->mem.default_globl_map = xdata;
105 port->mem.default_local_map = data;
106 port->mem.default_globl_map = data;
110 port->s.fptr_size = 3;
111 port->s.gptr_size = 4;
113 port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */
115 port->stack.call_overhead += 2; /* This acounts for the extra byte
116 * of return addres on the stack.
117 * but is ugly. There must be a
121 port->mem.default_local_map = xdata;
122 port->mem.default_globl_map = xdata;
124 if (!options.stack10bit)
127 "*** error: ds390 port only supports the 10 bit stack mode.\n");
129 if (!options.stack_loc) options.stack_loc = 0x400007;
132 /* generate native code 16*16 mul/div */
133 if (options.useAccelerator)
134 port->support.muldiv=2;
136 port->support.muldiv=1;
138 /* Fixup the memory map for the stack; it is now in
139 * far space and requires a FPOINTER to access it.
142 istack->ptrType = FPOINTER;
147 _ds390_setDefaultOptions (void)
149 options.model=MODEL_FLAT24;
150 options.stack10bit=1;
154 _ds390_getRegName (struct regs *reg)
162 _ds390_genAssemblerPreamble (FILE * of)
164 if (options.model == MODEL_FLAT24)
165 fputs (".flat24 on\t\t; 24 bit flat addressing\n", of);
167 fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
168 fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of);
169 fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of);
170 fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of);
171 fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of);
172 fputs ("ap = 0x9C\t\t; ap register unknown to assembler\n", of);
173 fputs ("mcnt0 = 0xD1\t\t; mcnt0 register unknown to assembler\n", of);
174 fputs ("mcnt1 = 0xD2\t\t; mcnt1 register unknown to assembler\n", of);
175 fputs ("ma = 0xD3\t\t; ma register unknown to assembler\n", of);
176 fputs ("mb = 0xD4\t\t; mb register unknown to assembler\n", of);
177 fputs ("mc = 0xD5\t\t; mc register unknown to assembler\n", of);
178 fputs ("F1 = 0xD1\t\t; F1 user flag unknown to assembler\n", of);
179 fputs ("esp = 0x9B\t\t; ESP user flag unknown to assembler\n", of);
182 /* Generate interrupt vector table. */
184 _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
188 if (options.model != MODEL_FLAT24)
190 /* Let the default code handle it. */
194 fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
196 /* now for the other interrupts */
197 for (i = 0; i < maxInterrupts; i++)
201 fprintf (of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
205 fprintf (of, "\treti\n\t.ds\t7\n");
212 /* Generate code to copy XINIT to XISEG */
213 static void _ds390_genXINIT (FILE * of) {
214 fprintf (of, "; _ds390_genXINIT() start\n");
215 fprintf (of, " mov a,#s_XINIT\n");
216 fprintf (of, " add a,#l_XINIT\n");
217 fprintf (of, " mov r1,a\n");
218 fprintf (of, " mov a,#s_XINIT>>8\n");
219 fprintf (of, " addc a,#l_XINIT>>8\n");
220 fprintf (of, " mov r2,a\n");
221 fprintf (of, " mov dptr,#s_XINIT\n");
222 fprintf (of, " mov dps,#0x21\n");
223 fprintf (of, " mov dptr,#s_XISEG\n");
224 fprintf (of, "00001$: clr a\n");
225 fprintf (of, " movc a,@a+dptr\n");
226 fprintf (of, " movx @dptr,a\n");
227 fprintf (of, " inc dptr\n");
228 fprintf (of, " inc dptr\n");
229 fprintf (of, "00002$: mov a,dpl\n");
230 fprintf (of, " cjne a,ar1,00001$\n");
231 fprintf (of, " mov a,dph\n");
232 fprintf (of, " cjne a,ar2,00001$\n");
233 fprintf (of, " mov dps,#0\n");
234 fprintf (of, "; _ds390_genXINIT() end\n");
237 /* Do CSE estimation */
238 static bool cseCostEstimation (iCode *ic, iCode *pdic)
240 operand *result = IC_RESULT(ic);
241 //operand *right = IC_RIGHT(ic);
242 //operand *left = IC_LEFT(ic);
243 sym_link *result_type = operandType(result);
244 //sym_link *right_type = (right ? operandType(right) : 0);
245 //sym_link *left_type = (left ? operandType(left) : 0);
247 /* if it is a pointer then return ok for now */
248 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
250 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
251 so we will cse only if they are local (i.e. both ic & pdic belong to
252 the same basic block */
253 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
254 /* then if they are the same Basic block then ok */
255 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
259 /* for others it is cheaper to do the cse */
262 /** $1 is always the basename.
263 $2 is always the output file.
265 $l is the list of extra options that should be there somewhere...
266 MUST be terminated with a NULL.
268 static const char *_linkCmd[] =
270 "aslink", "-nf", "$1", NULL
273 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ static const char *_asmCmd[] =
275 "asx8051", "$l", "$3", "$1.asm", NULL
283 "DS80C390", /* Target name */
285 TRUE, /* Emit glue around main */
286 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
292 "-plosgffc", /* Options with debug */
293 "-plosgff", /* Options without debug */
307 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
308 1, 2, 2, 4, 1, 2, 3, 1, 4, 4
323 "XISEG (XDATA)", // initialized xdata
324 "XINIT (CODE)", // a code copy of xiseg
332 /* ds390 has an 16 bit mul & div */
339 _ds390_finaliseOptions,
340 _ds390_setDefaultOptions,
341 ds390_assignRegisters,
344 _ds390_genAssemblerPreamble,
347 _ds390_reset_regparm,
355 1, /* transform <= to ! > */
356 1, /* transform >= to ! < */
357 1, /* transform != to !(a == b) */
359 TRUE, /* we support array initializers. */
361 __ds390_builtins, /* table of builtin functions */