* configure.in,
[fw/sdcc] / src / mcs51 / main.c
1 /** @file main.c
2     mcs51 specific general functions.
3
4     Note that mlh prepended _mcs51_ on the static functions.  Makes
5     it easier to set a breakpoint using the debugger.
6 */
7 #include "common.h"
8 #include "main.h"
9 #include "ralloc.h"
10 #include "gen.h"
11 #include "dbuf_string.h"
12 #include "../SDCCutil.h"
13
14 static char _defaultRules[] =
15 {
16 #include "peeph.rul"
17 };
18
19 #define OPTION_STACK_SIZE       "--stack-size"
20
21 static OPTION _mcs51_options[] =
22   {
23     { 0, OPTION_STACK_SIZE,  &options.stack_size, "Tells the linker to allocate this space for stack", CLAT_INTEGER },
24     { 0, "--parms-in-bank1", &options.parms_in_bank1, "use Bank1 for parameter passing"},
25     { 0, "--pack-iram",      NULL, "Tells the linker to pack variables in internal ram (default)"},
26     { 0, "--no-pack-iram",   &options.no_pack_iram, "Tells the linker not to pack variables in internal ram"},
27     { 0, NULL }
28   };
29
30 /* list of key words used by msc51 */
31 static char *_mcs51_keywords[] =
32 {
33   "at",
34   "banked",
35   "bit",
36   "code",
37   "critical",
38   "data",
39   "far",
40   "idata",
41   "interrupt",
42   "near",
43   "pdata",
44   "reentrant",
45   "sfr",
46   "sfr16",
47   "sfr32",
48   "sbit",
49   "using",
50   "xdata",
51   "_data",
52   "_code",
53   "_generic",
54   "_near",
55   "_xdata",
56   "_pdata",
57   "_idata",
58   "_naked",
59   "_overlay",
60   NULL
61 };
62
63
64
65 void mcs51_assignRegisters (ebbIndex *);
66
67 static int regParmFlg = 0;      /* determine if we can register a parameter     */
68 static int regBitParmFlg = 0;   /* determine if we can register a bit parameter */
69
70 static void
71 _mcs51_init (void)
72 {
73   asm_addTree (&asm_asxxxx_mapping);
74 }
75
76 static void
77 _mcs51_reset_regparm (void)
78 {
79   regParmFlg = 0;
80   regBitParmFlg = 0;
81 }
82
83 static int
84 _mcs51_regparm (sym_link * l, bool reentrant)
85 {
86     if (IS_SPEC(l) && (SPEC_NOUN(l) == V_BIT)) {
87         /* bit parameters go to b0 thru b7 */
88         if (reentrant && (regBitParmFlg < 8)) {
89             regBitParmFlg++;
90             return 12 + regBitParmFlg;
91         }
92         return 0;
93     }
94     if (options.parms_in_bank1 == 0) {
95         /* simple can pass only the first parameter in a register */
96         if (regParmFlg)
97             return 0;
98
99         regParmFlg = 1;
100         return 1;
101     } else {
102         int size = getSize(l);
103         int remain ;
104
105         /* first one goes the usual way to DPTR */
106         if (regParmFlg == 0) {
107             regParmFlg += 4 ;
108             return 1;
109         }
110         /* second one onwards goes to RB1_0 thru RB1_7 */
111         remain = regParmFlg - 4;
112         if (size > (8 - remain)) {
113             regParmFlg = 12 ;
114             return 0;
115         }
116         regParmFlg += size ;
117         return regParmFlg - size + 1;
118     }
119 }
120
121 static bool
122 _mcs51_parseOptions (int *pargc, char **argv, int *i)
123 {
124   /* TODO: allow port-specific command line options to specify
125    * segment names here.
126    */
127   return FALSE;
128 }
129
130 static void
131 _mcs51_finaliseOptions (void)
132 {
133   if (options.noXinitOpt) {
134     port->genXINIT=0;
135   }
136
137   switch (options.model)
138     {
139     case MODEL_SMALL:
140       port->mem.default_local_map = data;
141       port->mem.default_globl_map = data;
142       port->s.gptr_size = 3;
143       break;
144     case MODEL_MEDIUM:
145       port->mem.default_local_map = pdata;
146       port->mem.default_globl_map = pdata;
147       port->s.gptr_size = 3;
148       break;
149     case MODEL_LARGE:
150       port->mem.default_local_map = xdata;
151       port->mem.default_globl_map = xdata;
152       port->s.gptr_size = 3;
153       break;
154     default:
155       port->mem.default_local_map = data;
156       port->mem.default_globl_map = data;
157       break;
158     }
159
160   if (options.parms_in_bank1) {
161       addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
162   }
163 }
164
165 static void
166 _mcs51_setDefaultOptions (void)
167 {
168 }
169
170 static const char *
171 _mcs51_getRegName (struct regs *reg)
172 {
173   if (reg)
174     return reg->name;
175   return "err";
176 }
177
178 static void
179 _mcs51_genAssemblerPreamble (FILE * of)
180 {
181     if (options.parms_in_bank1) {
182         int i ;
183         for (i=0; i < 8 ; i++ )
184             fprintf (of,"b1_%d = 0x%x \n",i,8+i);
185     }
186 }
187
188 /* Generate interrupt vector table. */
189 static int
190 _mcs51_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
191 {
192   int i;
193
194   dbuf_printf (oBuf, "\tljmp\t__sdcc_gsinit_startup\n");
195
196   /* now for the other interrupts */
197   for (i = 0; i < maxInterrupts; i++)
198     {
199       if (interrupts[i])
200         {
201           dbuf_printf (oBuf, "\tljmp\t%s\n", interrupts[i]->rname);
202           if ( i != maxInterrupts - 1 )
203             dbuf_printf (oBuf, "\t.ds\t5\n");
204         }
205       else
206         {
207           dbuf_printf (oBuf, "\treti\n");
208           if ( i != maxInterrupts - 1 )
209             dbuf_printf (oBuf, "\t.ds\t7\n");
210         }
211     }
212   return TRUE;
213 }
214
215 static void
216 _mcs51_genExtraAreas(FILE *of, bool hasMain)
217 {
218   tfprintf (of, "\t!area\n", HOME_NAME);
219   tfprintf (of, "\t!area\n", "GSINIT0 (CODE)");
220   tfprintf (of, "\t!area\n", "GSINIT1 (CODE)");
221   tfprintf (of, "\t!area\n", "GSINIT2 (CODE)");
222   tfprintf (of, "\t!area\n", "GSINIT3 (CODE)");
223   tfprintf (of, "\t!area\n", "GSINIT4 (CODE)");
224   tfprintf (of, "\t!area\n", "GSINIT5 (CODE)");
225   tfprintf (of, "\t!area\n", STATIC_NAME);
226   tfprintf (of, "\t!area\n", port->mem.post_static_name);
227   tfprintf (of, "\t!area\n", CODE_NAME);
228 }
229
230 static void
231 _mcs51_genInitStartup (FILE *of)
232 {
233   tfprintf (of, "\t!global\n", "__sdcc_gsinit_startup");
234   tfprintf (of, "\t!global\n", "__sdcc_program_startup");
235   tfprintf (of, "\t!global\n", "__start__stack");
236
237   if (options.useXstack)
238     {
239       tfprintf (of, "\t!global\n", "__sdcc_init_xstack");
240       tfprintf (of, "\t!global\n", "__start__xstack");
241     }
242
243   // if the port can copy the XINIT segment to XISEG
244   if (port->genXINIT)
245     {
246       port->genXINIT(of);
247     }
248
249   if (!getenv("SDCC_NOGENRAMCLEAR"))
250     tfprintf (of, "\t!global\n", "__mcs51_genRAMCLEAR");
251 }
252
253
254 /* Generate code to copy XINIT to XISEG */
255 static void _mcs51_genXINIT (FILE * of) {
256   tfprintf (of, "\t!global\n", "__mcs51_genXINIT");
257
258   if (!getenv("SDCC_NOGENRAMCLEAR"))
259     tfprintf (of, "\t!global\n", "__mcs51_genXRAMCLEAR");
260 }
261
262
263 /* Do CSE estimation */
264 static bool cseCostEstimation (iCode *ic, iCode *pdic)
265 {
266     operand *result = IC_RESULT(ic);
267     sym_link *result_type = operandType(result);
268
269     /* if it is a pointer then return ok for now */
270     if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
271
272     /* if bitwise | add & subtract then no since mcs51 is pretty good at it
273        so we will cse only if they are local (i.e. both ic & pdic belong to
274        the same basic block */
275     if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
276         /* then if they are the same Basic block then ok */
277         if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
278         else return 0;
279     }
280
281     /* for others it is cheaper to do the cse */
282     return 1;
283 }
284
285 /* Indicate which extended bit operations this port supports */
286 static bool
287 hasExtBitOp (int op, int size)
288 {
289   if (op == RRC
290       || op == RLC
291       || op == GETHBIT
292       || op == GETABIT
293       || op == GETBYTE
294       || op == GETWORD
295       || (op == SWAP && size <= 2)
296      )
297     return TRUE;
298   else
299     return FALSE;
300 }
301
302 /* Indicate the expense of an access to an output storage class */
303 static int
304 oclsExpense (struct memmap *oclass)
305 {
306   if (IN_FARSPACE(oclass))
307     return 1;
308
309   return 0;
310 }
311
312
313
314 static int
315 instructionSize(char *inst, char *op1, char *op2)
316 {
317   #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0)
318   #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0')
319   #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0')
320   #define IS_Rn(s) (*(s) == 'r' && *(s+1) >= '0' && *(s+1) <= '7')
321   #define IS_atRi(s) (*(s) == '@' && *(s+1) == 'r')
322
323   /* Based on the current (2003-08-22) code generation for the
324      small library, the top instruction probability is:
325
326        57% mov/movx/movc
327         6% push
328         6% pop
329         4% inc
330         4% lcall
331         4% add
332         3% clr
333         2% subb
334   */
335   /* mov, push, & pop are the 69% of the cases. Check them first! */
336   if (ISINST ("mov"))
337     {
338       if (*(inst+3)=='x') return 1; /* movx */
339       if (*(inst+3)=='c') return 1; /* movc */
340       if (IS_C (op1) || IS_C (op2)) return 2;
341       if (IS_A (op1))
342         {
343           if (IS_Rn (op2) || IS_atRi (op2)) return 1;
344           return 2;
345         }
346       if (IS_Rn(op1) || IS_atRi(op1))
347         {
348           if (IS_A(op2)) return 1;
349           return 2;
350         }
351       if (strcmp (op1, "dptr") == 0) return 3;
352       if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2;
353       return 3;
354     }
355
356   if (ISINST ("push")) return 2;
357   if (ISINST ("pop")) return 2;
358
359   if (ISINST ("lcall")) return 3;
360   if (ISINST ("ret")) return 1;
361   if (ISINST ("ljmp")) return 3;
362   if (ISINST ("sjmp")) return 2;
363   if (ISINST ("rlc")) return 1;
364   if (ISINST ("rrc")) return 1;
365   if (ISINST ("rl")) return 1;
366   if (ISINST ("rr")) return 1;
367   if (ISINST ("swap")) return 1;
368   if (ISINST ("jc")) return 2;
369   if (ISINST ("jnc")) return 2;
370   if (ISINST ("jb")) return 3;
371   if (ISINST ("jnb")) return 3;
372   if (ISINST ("jbc")) return 3;
373   if (ISINST ("jmp")) return 1; // always jmp @a+dptr
374   if (ISINST ("jz")) return 2;
375   if (ISINST ("jnz")) return 2;
376   if (ISINST ("cjne")) return 3;
377   if (ISINST ("mul")) return 1;
378   if (ISINST ("div")) return 1;
379   if (ISINST ("da")) return 1;
380   if (ISINST ("xchd")) return 1;
381   if (ISINST ("reti")) return 1;
382   if (ISINST ("nop")) return 1;
383   if (ISINST ("acall")) return 2;
384   if (ISINST ("ajmp")) return 2;
385
386
387   if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch"))
388     {
389       if (IS_Rn(op2) || IS_atRi(op2)) return 1;
390       return 2;
391     }
392   if (ISINST ("inc") || ISINST ("dec"))
393     {
394       if (IS_A(op1) || IS_Rn(op1) || IS_atRi(op1)) return 1;
395       if (strcmp(op1, "dptr") == 0) return 1;
396       return 2;
397     }
398   if (ISINST ("anl") || ISINST ("orl") || ISINST ("xrl"))
399     {
400       if (IS_C(op1)) return 2;
401       if (IS_A(op1))
402         {
403           if (IS_Rn(op2) || IS_atRi(op2)) return 1;
404           return 2;
405         }
406       else
407         {
408           if (IS_A(op2)) return 2;
409           return 3;
410         }
411     }
412   if (ISINST ("clr") || ISINST ("setb") || ISINST ("cpl"))
413     {
414       if (IS_A(op1) || IS_C(op1)) return 1;
415       return 2;
416     }
417   if (ISINST ("djnz"))
418     {
419       if (IS_Rn(op1)) return 2;
420       return 3;
421     }
422
423   /* If the instruction is unrecognized, we shouldn't try to optimize. */
424   /* Return a large value to discourage optimization.                  */
425   return 999;
426 }
427
428 static asmLineNode *
429 newAsmLineNode (void)
430 {
431   asmLineNode *aln;
432
433   aln = Safe_alloc ( sizeof (asmLineNode));
434   aln->size = 0;
435   aln->regsRead = NULL;
436   aln->regsWritten = NULL;
437
438   return aln;
439 }
440
441
442 typedef struct mcs51operanddata
443   {
444     char name[6];
445     int regIdx1;
446     int regIdx2;
447   }
448 mcs51operanddata;
449
450 static mcs51operanddata mcs51operandDataTable[] =
451   {
452     {"a", A_IDX, -1},
453     {"ab", A_IDX, B_IDX},
454     {"ac", CND_IDX, -1},
455     {"acc", A_IDX, -1},
456     {"ar0", R0_IDX, -1},
457     {"ar1", R1_IDX, -1},
458     {"ar2", R2_IDX, -1},
459     {"ar3", R3_IDX, -1},
460     {"ar4", R4_IDX, -1},
461     {"ar5", R5_IDX, -1},
462     {"ar6", R6_IDX, -1},
463     {"ar7", R7_IDX, -1},
464     {"b", B_IDX, -1},
465     {"c", CND_IDX, -1},
466     {"cy", CND_IDX, -1},
467     {"dph", DPH_IDX, -1},
468     {"dpl", DPL_IDX, -1},
469     {"dptr", DPL_IDX, DPH_IDX},
470     {"f0", CND_IDX, -1},
471     {"f1", CND_IDX, -1},
472     {"ov", CND_IDX, -1},
473     {"p", CND_IDX, -1},
474     {"psw", CND_IDX, -1},
475     {"r0", R0_IDX, -1},
476     {"r1", R1_IDX, -1},
477     {"r2", R2_IDX, -1},
478     {"r3", R3_IDX, -1},
479     {"r4", R4_IDX, -1},
480     {"r5", R5_IDX, -1},
481     {"r6", R6_IDX, -1},
482     {"r7", R7_IDX, -1},
483   };
484
485 static int
486 mcs51operandCompare (const void *key, const void *member)
487 {
488   return strcmp((const char *)key, ((mcs51operanddata *)member)->name);
489 }
490
491 static void
492 updateOpRW (asmLineNode *aln, char *op, char *optype)
493 {
494   mcs51operanddata *opdat;
495   char *dot;
496
497   dot = strchr(op, '.');
498   if (dot)
499     *dot = '\0';
500
501   opdat = bsearch (op, mcs51operandDataTable,
502                    sizeof(mcs51operandDataTable)/sizeof(mcs51operanddata),
503                    sizeof(mcs51operanddata), mcs51operandCompare);
504
505   if (opdat && strchr(optype,'r'))
506     {
507       if (opdat->regIdx1 >= 0)
508         aln->regsRead = bitVectSetBit (aln->regsRead, opdat->regIdx1);
509       if (opdat->regIdx2 >= 0)
510         aln->regsRead = bitVectSetBit (aln->regsRead, opdat->regIdx2);
511     }
512   if (opdat && strchr(optype,'w'))
513     {
514       if (opdat->regIdx1 >= 0)
515         aln->regsWritten = bitVectSetBit (aln->regsWritten, opdat->regIdx1);
516       if (opdat->regIdx2 >= 0)
517         aln->regsWritten = bitVectSetBit (aln->regsWritten, opdat->regIdx2);
518     }
519   if (op[0] == '@')
520     {
521       if (!strcmp(op, "@r0"))
522         aln->regsRead = bitVectSetBit (aln->regsRead, R0_IDX);
523       if (!strcmp(op, "@r1"))
524         aln->regsRead = bitVectSetBit (aln->regsRead, R1_IDX);
525       if (strstr(op, "dptr"))
526         {
527           aln->regsRead = bitVectSetBit (aln->regsRead, DPL_IDX);
528           aln->regsRead = bitVectSetBit (aln->regsRead, DPH_IDX);
529         }
530       if (strstr(op, "a+"))
531         aln->regsRead = bitVectSetBit (aln->regsRead, A_IDX);
532     }
533 }
534
535 typedef struct mcs51opcodedata
536   {
537     char name[6];
538     char class[3];
539     char pswtype[3];
540     char op1type[3];
541     char op2type[3];
542   }
543 mcs51opcodedata;
544
545 static mcs51opcodedata mcs51opcodeDataTable[] =
546   {
547     {"acall","j", "",   "",   ""},
548     {"add",  "",  "w",  "rw", "r"},
549     {"addc", "",  "rw", "rw", "r"},
550     {"ajmp", "j", "",   "",   ""},
551     {"anl",  "",  "",   "rw", "r"},
552     {"cjne", "j", "w",  "r",  "r"},
553     {"clr",  "",  "",   "w",  ""},
554     {"cpl",  "",  "",   "rw", ""},
555     {"da",   "",  "rw", "rw", ""},
556     {"dec",  "",  "",   "rw", ""},
557     {"div",  "",  "w",  "rw", ""},
558     {"djnz", "j", "",  "rw",  ""},
559     {"inc",  "",  "",   "rw", ""},
560     {"jb",   "j", "",   "r",  ""},
561     {"jbc",  "j", "",  "rw",  ""},
562     {"jc",   "j", "",   "",   ""},
563     {"jmp",  "j", "",  "",    ""},
564     {"jnb",  "j", "",   "r",  ""},
565     {"jnc",  "j", "",   "",   ""},
566     {"jnz",  "j", "",  "",    ""},
567     {"jz",   "j", "",  "",    ""},
568     {"lcall","j", "",   "",   ""},
569     {"ljmp", "j", "",   "",   ""},
570     {"mov",  "",  "",   "w",  "r"},
571     {"movc", "",  "",   "w",  "r"},
572     {"movx", "",  "",   "w",  "r"},
573     {"mul",  "",  "w",  "rw", ""},
574     {"nop",  "",  "",   "",   ""},
575     {"orl",  "",  "",   "rw", "r"},
576     {"pop",  "",  "",   "w",  ""},
577     {"push", "",  "",   "r",  ""},
578     {"ret",  "j", "",   "",   ""},
579     {"reti", "j", "",   "",   ""},
580     {"rl",   "",  "",   "rw", ""},
581     {"rlc",  "",  "rw", "rw", ""},
582     {"rr",   "",  "",   "rw", ""},
583     {"rrc",  "",  "rw", "rw", ""},
584     {"setb", "",  "",   "w",  ""},
585     {"sjmp", "j", "",   "",   ""},
586     {"subb", "",  "rw", "rw", "r"},
587     {"swap", "",  "",   "rw", ""},
588     {"xch",  "",  "",   "rw", "rw"},
589     {"xchd", "",  "",   "rw", "rw"},
590     {"xrl",  "",  "",   "rw", "r"},
591   };
592
593 static int
594 mcs51opcodeCompare (const void *key, const void *member)
595 {
596   return strcmp((const char *)key, ((mcs51opcodedata *)member)->name);
597 }
598
599 static asmLineNode *
600 asmLineNodeFromLineNode (lineNode *ln)
601 {
602   asmLineNode *aln = newAsmLineNode();
603   char *op, op1[256], op2[256];
604   int opsize;
605   const char *p;
606   char inst[8];
607   mcs51opcodedata *opdat;
608
609   p = ln->line;
610
611   while (*p && isspace(*p)) p++;
612   for (op = inst, opsize=1; *p; p++)
613     {
614       if (isspace(*p) || *p == ';' || *p == ':' || *p == '=')
615         break;
616       else
617         if (opsize < sizeof(inst))
618           *op++ = tolower(*p), opsize++;
619     }
620   *op = '\0';
621
622   if (*p == ';' || *p == ':' || *p == '=')
623     return aln;
624
625   while (*p && isspace(*p)) p++;
626   if (*p == '=')
627     return aln;
628
629   for (op = op1, opsize=1; *p && *p != ','; p++)
630     {
631       if (!isspace(*p) && opsize < sizeof(op1))
632         *op++ = tolower(*p), opsize++;
633     }
634   *op = '\0';
635
636   if (*p == ',') p++;
637   for (op = op2, opsize=1; *p && *p != ','; p++)
638     {
639       if (!isspace(*p) && opsize < sizeof(op2))
640         *op++ = tolower(*p), opsize++;
641     }
642   *op = '\0';
643
644   aln->size = instructionSize(inst, op1, op2);
645
646   aln->regsRead = newBitVect (END_IDX);
647   aln->regsWritten = newBitVect (END_IDX);
648
649   opdat = bsearch (inst, mcs51opcodeDataTable,
650                    sizeof(mcs51opcodeDataTable)/sizeof(mcs51opcodedata),
651                    sizeof(mcs51opcodedata), mcs51opcodeCompare);
652
653   if (opdat)
654     {
655       updateOpRW (aln, op1, opdat->op1type);
656       updateOpRW (aln, op2, opdat->op2type);
657       if (strchr(opdat->pswtype,'r'))
658         aln->regsRead = bitVectSetBit (aln->regsRead, CND_IDX);
659       if (strchr(opdat->pswtype,'w'))
660         aln->regsWritten = bitVectSetBit (aln->regsWritten, CND_IDX);
661     }
662
663   return aln;
664 }
665
666 static int
667 getInstructionSize (lineNode *line)
668 {
669   if (!line->aln)
670     line->aln = asmLineNodeFromLineNode (line);
671
672   return line->aln->size;
673 }
674
675 static bitVect *
676 getRegsRead (lineNode *line)
677 {
678   if (!line->aln)
679     line->aln = asmLineNodeFromLineNode (line);
680
681   return line->aln->regsRead;
682 }
683
684 static bitVect *
685 getRegsWritten (lineNode *line)
686 {
687   if (!line->aln)
688     line->aln = asmLineNodeFromLineNode (line);
689
690   return line->aln->regsWritten;
691 }
692
693
694 /** $1 is always the basename.
695     $2 is always the output file.
696     $3 varies
697     $l is the list of extra options that should be there somewhere...
698     MUST be terminated with a NULL.
699 */
700 static const char *_linkCmd[] =
701 {
702   "aslink", "-nf", "\"$1\"", NULL
703 };
704
705 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
706 static const char *_asmCmd[] =
707 {
708   "asx8051", "$l", "$3", "\"$1.asm\"", NULL
709 };
710
711 /* Globals */
712 PORT mcs51_port =
713 {
714   TARGET_ID_MCS51,
715   "mcs51",
716   "MCU 8051",                   /* Target name */
717   NULL,                         /* Processor name */
718   {
719     glue,
720     TRUE,                       /* Emit glue around main */
721     MODEL_SMALL | MODEL_MEDIUM | MODEL_LARGE,
722     MODEL_SMALL
723   },
724   {
725     _asmCmd,
726     NULL,
727     "-plosgffc",                /* Options with debug */
728     "-plosgff",                 /* Options without debug */
729     0,
730     ".asm",
731     NULL                        /* no do_assemble function */
732   },
733   {
734     _linkCmd,
735     NULL,
736     NULL,
737     ".rel",
738     1
739   },
740   {
741     _defaultRules,
742     getInstructionSize,
743     getRegsRead,
744     getRegsWritten,
745     mcs51DeadMove
746   },
747   {
748     /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
749     1, 2, 2, 4, 1, 2, 3, 1, 4, 4
750   },
751   /* tags for generic pointers */
752   { 0x00, 0x40, 0x60, 0x80 },           /* far, near, xstack, code */
753   {
754     "XSTK    (PAG,XDATA)",      // xstack_name
755     "STACK   (DATA)",           // istack_name
756     "CSEG    (CODE)",           // code_name
757     "DSEG    (DATA)",           // data_name
758     "ISEG    (DATA)",           // idata_name
759     "PSEG    (PAG,XDATA)",      // pdata_name
760     "XSEG    (XDATA)",          // xdata_name
761     "BSEG    (BIT)",            // bit_name
762     "RSEG    (DATA)",           // reg_name
763     "GSINIT  (CODE)",           // static_name
764     "OSEG    (OVR,DATA)",       // overlay_name
765     "GSFINAL (CODE)",           // post_static_name
766     "HOME    (CODE)",           // home_name
767     "XISEG   (XDATA)",          // xidata_name - initialized xdata   initialized xdata
768     "XINIT   (CODE)",           // xinit_name - a code copy of xiseg
769     "CONST   (CODE)",           // const_name - const data (code or not)
770     "CABS    (ABS,CODE)",       // cabs_name - const absolute data (code or not)
771     "XABS    (ABS,XDATA)",      // xabs_name - absolute xdata/pdata
772     "IABS    (ABS,DATA)",       // iabs_name - absolute idata/data
773     NULL,
774     NULL,
775     1
776   },
777   { _mcs51_genExtraAreas, NULL },
778   {
779     +1,         /* direction (+1 = stack grows up) */
780     0,          /* bank_overhead (switch between register banks) */
781     4,          /* isr_overhead */
782     1,          /* call_overhead (2 for return address - 1 for pre-incrementing push */
783     1,          /* reent_overhead */
784     0           /* banked_overhead (switch between code banks) */
785   },
786   {
787     /* mcs51 has an 8 bit mul */
788     1, -1
789   },
790   {
791     mcs51_emitDebuggerSymbol
792   },
793   {
794     256,        /* maxCount */
795     2,          /* sizeofElement */
796     {6,9,15},   /* sizeofMatchJump[] */
797     {9,18,36},  /* sizeofRangeCompare[] */
798     4,          /* sizeofSubtract */
799     6,          /* sizeofDispatch */
800   },
801   "_",
802   _mcs51_init,
803   _mcs51_parseOptions,
804   _mcs51_options,
805   NULL,
806   _mcs51_finaliseOptions,
807   _mcs51_setDefaultOptions,
808   mcs51_assignRegisters,
809   _mcs51_getRegName,
810   _mcs51_keywords,
811   _mcs51_genAssemblerPreamble,
812   NULL,                         /* no genAssemblerEnd */
813   _mcs51_genIVT,
814   _mcs51_genXINIT,
815   _mcs51_genInitStartup,
816   _mcs51_reset_regparm,
817   _mcs51_regparm,
818   NULL,
819   NULL,
820   NULL,
821   hasExtBitOp,                  /* hasExtBitOp */
822   oclsExpense,                  /* oclsExpense */
823   FALSE,
824   TRUE,                         /* little endian */
825   0,                            /* leave lt */
826   0,                            /* leave gt */
827   1,                            /* transform <= to ! > */
828   1,                            /* transform >= to ! < */
829   1,                            /* transform != to !(a == b) */
830   0,                            /* leave == */
831   FALSE,                        /* No array initializer support. */
832   cseCostEstimation,
833   NULL,                         /* no builtin functions */
834   GPOINTER,                     /* treat unqualified pointers as "generic" pointers */
835   1,                            /* reset labelKey to 1 */
836   1,                            /* globals & local static allowed */
837   PORT_MAGIC
838 };