* Added support for doing shifts by helper functions
[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
12 static char _defaultRules[] =
13 {
14 #include "peeph.rul"
15 };
16
17 /* list of key words used by msc51 */
18 static char *_mcs51_keywords[] =
19 {
20   "at",
21   "bit",
22   "code",
23   "critical",
24   "data",
25   "far",
26   "idata",
27   "interrupt",
28   "near",
29   "pdata",
30   "reentrant",
31   "sfr",
32   "sbit",
33   "using",
34   "xdata",
35   "_data",
36   "_code",
37   "_generic",
38   "_near",
39   "_xdata",
40   "_pdata",
41   "_idata",
42   "_naked",
43   NULL
44 };
45
46
47 void mcs51_assignRegisters (eBBlock ** ebbs, int count);
48
49 static int regParmFlg = 0;      /* determine if we can register a parameter */
50
51 static void
52 _mcs51_init (void)
53 {
54   asm_addTree (&asm_asxxxx_mapping);
55 }
56
57 static void
58 _mcs51_reset_regparm ()
59 {
60   regParmFlg = 0;
61 }
62
63 static int
64 _mcs51_regparm (sym_link * l)
65 {
66   /* for this processor it is simple
67      can pass only the first parameter in a register */
68   if (regParmFlg)
69     return 0;
70
71   regParmFlg = 1;
72   return 1;
73 }
74
75 static bool
76 _mcs51_parseOptions (int *pargc, char **argv, int *i)
77 {
78   /* TODO: allow port-specific command line options to specify
79    * segment names here.
80    */
81   return FALSE;
82 }
83
84 static void
85 _mcs51_finaliseOptions (void)
86 {
87   if (options.model == MODEL_LARGE) {
88       port->mem.default_local_map = xdata;
89       port->mem.default_globl_map = xdata;
90     }
91   else
92     {
93       port->mem.default_local_map = data;
94       port->mem.default_globl_map = data;
95     }
96 }
97
98 static void
99 _mcs51_setDefaultOptions (void)
100 {
101 }
102
103 static const char *
104 _mcs51_getRegName (struct regs *reg)
105 {
106   if (reg)
107     return reg->name;
108   return "err";
109 }
110
111 static void
112 _mcs51_genAssemblerPreamble (FILE * of)
113 {
114 }
115
116 /* Generate interrupt vector table. */
117 static int
118 _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
119 {
120   return FALSE;
121 }
122
123 /** $1 is always the basename.
124     $2 is always the output file.
125     $3 varies
126     $l is the list of extra options that should be there somewhere...
127     MUST be terminated with a NULL.
128 */
129 static const char *_linkCmd[] =
130 {
131   "aslink", "-nf", "$1", NULL
132 };
133
134 static const char *_asmCmd[] =
135 {
136   "asx8051", "$l", "-plosgffc", "$1.asm", NULL
137 };
138
139 /* Globals */
140 PORT mcs51_port =
141 {
142   TARGET_ID_MCS51,
143   "mcs51",
144   "MCU 8051",                   /* Target name */
145   {
146     TRUE,                       /* Emit glue around main */
147     MODEL_SMALL | MODEL_LARGE,
148     MODEL_SMALL
149   },
150   {
151     _asmCmd,
152     "-plosgffc",                /* Options with debug */
153     "-plosgff",                 /* Options without debug */
154     0,
155     ".asm"
156   },
157   {
158     _linkCmd,
159     NULL,
160     ".rel"
161   },
162   {
163     _defaultRules
164   },
165   {
166         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
167     1, 2, 2, 4, 1, 2, 3, 1, 4, 4
168   },
169   {
170     "XSEG    (XDATA)",
171     "STACK   (DATA)",
172     "CSEG    (CODE)",
173     "DSEG    (DATA)",
174     "ISEG    (DATA)",
175     "XSEG    (XDATA)",
176     "BSEG    (BIT)",
177     "RSEG    (DATA)",
178     "GSINIT  (CODE)",
179     "OSEG    (OVR,DATA)",
180     "GSFINAL (CODE)",
181     "HOME        (CODE)",
182     NULL,
183     NULL,
184     1
185   },
186   {
187     +1, 1, 4, 1, 1, 0
188   },
189     /* mcs51 has an 8 bit mul */
190   {
191     1, -1
192   },
193   "_",
194   _mcs51_init,
195   _mcs51_parseOptions,
196   _mcs51_finaliseOptions,
197   _mcs51_setDefaultOptions,
198   mcs51_assignRegisters,
199   _mcs51_getRegName,
200   _mcs51_keywords,
201   _mcs51_genAssemblerPreamble,
202   _mcs51_genIVT,
203   _mcs51_reset_regparm,
204   _mcs51_regparm,
205   NULL,
206   NULL,
207   FALSE,
208   0,                            /* leave lt */
209   0,                            /* leave gt */
210   1,                            /* transform <= to ! > */
211   1,                            /* transform >= to ! < */
212   1,                            /* transform != to !(a == b) */
213   0,                            /* leave == */
214   PORT_MAGIC
215 };