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