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