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