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