Right.
[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     } 
64 }
65
66 static void _mcs51_setDefaultOptions(void)
67 {
68 }
69
70 static const char *_mcs51_getRegName(struct regs *reg)
71 {
72     if (reg)
73         return reg->name;
74     return "err";
75 }
76
77 static void _mcs51_genAssemblerPreamble(FILE *of)
78 {
79    if (options.model == MODEL_FLAT24)
80    {
81        fputs(".flat24 on\t\t; 24 bit flat addressing\n", of);
82        fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of);
83
84    }
85 }
86
87 /* Generate interrupt vector table. */
88 static int _mcs51_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
89 {
90     int i;
91     
92     if (options.model != MODEL_FLAT24)
93     {
94         /* Let the default code handle it. */
95         return FALSE;
96     }
97     
98     fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n");
99     
100     /* now for the other interrupts */
101     for (i = 0; i < maxInterrupts; i++) 
102     {
103         if (interrupts[i])
104         {
105             fprintf(of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
106         }
107         else
108         {
109             fprintf(of, "\treti\n\t.ds\t7\n");
110         }
111     }
112     
113     return TRUE;
114 }
115
116 /** $1 is always the basename.
117     $2 is always the output file.
118     $3 varies
119     $l is the list of extra options that should be there somewhere...
120     MUST be terminated with a NULL.
121 */
122 static const char *_linkCmd[] = {
123     "aslink", "-nf", "$1", NULL
124 };
125
126 static const char *_asmCmd[] = {
127     "asx8051", "-plosgffc", "$1.asm", NULL
128 };
129
130 /* Globals */
131 PORT mcs51_port = {
132     "mcs51",
133     "MCU 8051",                 /* Target name */
134     {   
135         _asmCmd,
136         "-plosgffc",            /* Options with debug */
137         "-plosgff",             /* Options without debug */
138     },
139     {
140         _linkCmd
141     },
142     {
143         _defaultRules
144     },
145     {
146         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
147         1, 1, 2, 4, 1, 2, 3, 1, 4, 4
148     },
149     {
150         "XSEG    (XDATA)",
151         "STACK   (DATA)",
152         "CSEG    (CODE)",
153         "DSEG    (DATA)",
154         "ISEG    (DATA)",
155         "XSEG    (XDATA)",
156         "BSEG    (BIT)",
157         "RSEG    (DATA)",
158         "GSINIT  (CODE)",
159         "OSEG    (OVR,DATA)"
160     },
161     { 
162         +1, 1, 4, 1, 1
163     },
164     /* mcs51 has an 8 bit mul */
165     {
166         1
167     },
168     _mcs51_parseOptions,
169     _mcs51_finaliseOptions,
170     _mcs51_setDefaultOptions,
171     mcs51_assignRegisters,
172     _mcs51_getRegName ,
173     _mcs51_keywords,
174     _mcs51_genAssemblerPreamble,
175     _mcs51_genIVT
176 };
177