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