* Added support for the gb.
[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
11 static char _defaultRules[] =
12 {
13 #include "peeph.rul"
14 };
15
16 /* list of key words used by msc51 */
17 static char *_mcs51_keywords[] =     {
18     "at",
19     "bit",
20     "code",
21     "critical",
22     "data",
23     "far",
24     "idata",
25     "interrupt",
26     "near",
27     "pdata",
28     "reentrant",
29     "sfr",
30     "sbit",
31     "using",
32     "xdata",
33     "_data",
34     "_code",
35     "_generic",
36     "_near",
37     "_xdata",
38     "_pdata",
39     "_idata",
40     NULL
41 };
42
43
44 void mcs51_assignRegisters (eBBlock **ebbs, int count);
45
46 static bool _mcs51_parseOptions(int *pargc, char **argv, int *i)
47 {
48     /* TODO: allow port-specific command line options to specify
49      * segment names here.
50      */
51     return FALSE;
52 }
53
54 static void _mcs51_finaliseOptions(void)
55 {
56     /* Hack-o-matic: if we are using the flat24 model,
57      * adjust pointer sizes.
58      */
59     if (options.model == MODEL_FLAT24)
60     {
61         port->s.fptr_size = 3;
62         port->s.gptr_size = 4;
63         port->stack.isr_overhead++;   /* Will save dpx on ISR entry. */
64         #if 1
65         port->stack.call_overhead++;       /* This acounts for the extra byte 
66                                             * of return addres on the stack.
67                                             * but is ugly. There must be a 
68                                             * better way.
69                                             */
70         #endif                                      
71         
72     } 
73 }
74
75 static void _mcs51_setDefaultOptions(void)
76 {
77 }
78
79 static const char *_mcs51_getRegName(struct regs *reg)
80 {
81     if (reg)
82         return reg->name;
83     return "err";
84 }
85
86 static void _mcs51_genAssemblerPreamble(FILE *of)
87 {
88    if (options.model == MODEL_FLAT24)
89    {
90        fputs(".flat24 on\t\t; 24 bit flat addressing\n", of);
91        fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
92
93    }
94 }
95
96 /* Generate interrupt vector table. */
97 static int _mcs51_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
98 {
99     int i;
100     
101     if (options.model != MODEL_FLAT24)
102     {
103         /* Let the default code handle it. */
104         return FALSE;
105     }
106     
107     fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
108     
109     /* now for the other interrupts */
110     for (i = 0; i < maxInterrupts; i++) 
111     {
112         if (interrupts[i])
113         {
114             fprintf(of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
115         }
116         else
117         {
118             fprintf(of, "\treti\n\t.ds\t7\n");
119         }
120     }
121     
122     return TRUE;
123 }
124
125 /** $1 is always the basename.
126     $2 is always the output file.
127     $3 varies
128     $l is the list of extra options that should be there somewhere...
129     MUST be terminated with a NULL.
130 */
131 static const char *_linkCmd[] = {
132     "aslink", "-nf", "$1", NULL
133 };
134
135 static const char *_asmCmd[] = {
136     "asx8051", "-plosgffc", "$1.asm", NULL
137 };
138
139 /* Globals */
140 PORT mcs51_port = {
141     "mcs51",
142     "MCU 8051",                 /* Target name */
143     {   
144         _asmCmd,
145         "-plosgffc",            /* Options with debug */
146         "-plosgff",             /* Options without debug */
147     },
148     {
149         _linkCmd
150     },
151     {
152         _defaultRules
153     },
154     {
155         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
156         1, 1, 2, 4, 1, 2, 3, 1, 4, 4
157     },
158     {
159         "XSEG    (XDATA)",
160         "STACK   (DATA)",
161         "CSEG    (CODE)",
162         "DSEG    (DATA)",
163         "ISEG    (DATA)",
164         "XSEG    (XDATA)",
165         "BSEG    (BIT)",
166         "RSEG    (DATA)",
167         "GSINIT  (CODE)",
168         "OSEG    (OVR,DATA)"
169     },
170     { 
171         +1, 1, 4, 1, 1
172     },
173     /* mcs51 has an 8 bit mul */
174     {
175         1
176     },
177     NULL,
178     _mcs51_parseOptions,
179     _mcs51_finaliseOptions,
180     _mcs51_setDefaultOptions,
181     mcs51_assignRegisters,
182     _mcs51_getRegName ,
183     _mcs51_keywords,
184     _mcs51_genAssemblerPreamble,
185     _mcs51_genIVT
186 };
187