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