Cleaned up ds390 leftovers in the mcs51 port.
[fw/sdcc] / src / pic / main.c
1 /** @file main.c
2     pic14 specific general functions.
3
4     Note that mlh prepended _pic14_ 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 *_pic14_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   NULL
43 };
44
45
46 void pic14_assignRegisters (eBBlock ** ebbs, int count);
47
48 static int regParmFlg = 0;      /* determine if we can register a parameter */
49
50 static void
51 _pic14_init (void)
52 {
53   asm_addTree (&asm_asxxxx_mapping);
54 }
55
56 static void
57 _pic14_reset_regparm ()
58 {
59   regParmFlg = 0;
60 }
61
62 static int
63 _pic14_regparm (sym_link * l)
64 {
65   /* for this processor it is simple
66      can pass only the first parameter in a register */
67   if (regParmFlg)
68     return 0;
69
70   regParmFlg = 1;
71   return 1;
72 }
73
74 static bool
75 _pic14_parseOptions (int *pargc, char **argv, int *i)
76 {
77   /* TODO: allow port-specific command line options to specify
78    * segment names here.
79    */
80   return FALSE;
81 }
82
83 static void
84 _pic14_finaliseOptions (void)
85 {
86 #if 0
87   /* Hack-o-matic: if we are using the flat24 model,
88    * adjust pointer sizes.
89    */
90   if (options.model == MODEL_FLAT24)
91     {
92
93       fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
94                "for DS80C390 support. This code generator is "
95                "badly out of date and probably broken.\n");
96
97       port->s.fptr_size = 3;
98       port->s.gptr_size = 4;
99       port->stack.isr_overhead++;       /* Will save dpx on ISR entry. */
100 #if 1
101       port->stack.call_overhead++;      /* This acounts for the extra byte 
102                                          * of return addres on the stack.
103                                          * but is ugly. There must be a 
104                                          * better way.
105                                          */
106 #endif
107       fReturn = fReturn390;
108       fReturnSize = 5;
109     }
110
111   if (options.model == MODEL_LARGE)
112     {
113       port->mem.default_local_map = xdata;
114       port->mem.default_globl_map = xdata;
115     }
116   else
117     {
118       port->mem.default_local_map = data;
119       port->mem.default_globl_map = data;
120     }
121
122   if (options.stack10bit)
123     {
124       if (options.model != MODEL_FLAT24)
125         {
126           fprintf (stderr,
127                    "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
128           fprintf (stderr, "\t10 bit stack mode disabled.\n");
129           options.stack10bit = 0;
130         }
131       else
132         {
133           /* Fixup the memory map for the stack; it is now in
134            * far space and requires a FPOINTER to access it.
135            */
136           istack->fmap = 1;
137           istack->ptrType = FPOINTER;
138         }
139     }
140 #endif
141 }
142
143 static void
144 _pic14_setDefaultOptions (void)
145 {
146 }
147
148 static const char *
149 _pic14_getRegName (struct regs *reg)
150 {
151   if (reg)
152     return reg->name;
153   return "err";
154 }
155
156 static void
157 _pic14_genAssemblerPreamble (FILE * of)
158 {
159   fprintf (of, "\tlist\tp=16c84\n");
160   fprintf (of, "\t__config _wdt_off\n");
161   fprintf (of, "\ninclude \"p16c84.inc\"\n");
162 }
163
164 /* Generate interrupt vector table. */
165 static int
166 _pic14_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
167 {
168   int i;
169
170   if (options.model != MODEL_FLAT24)
171     {
172       /* Let the default code handle it. */
173       return FALSE;
174     }
175
176   fprintf (of, "\t;ajmp\t__sdcc_gsinit_startup\n");
177
178   /* now for the other interrupts */
179   for (i = 0; i < maxInterrupts; i++)
180     {
181       if (interrupts[i])
182         {
183           fprintf (of, "\t;ljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname);
184         }
185       else
186         {
187           fprintf (of, "\t;reti\n\t.ds\t7\n");
188         }
189     }
190
191   return TRUE;
192 }
193
194 /** $1 is always the basename.
195     $2 is always the output file.
196     $3 varies
197     $l is the list of extra options that should be there somewhere...
198     MUST be terminated with a NULL.
199 */
200 static const char *_linkCmd[] =
201 {
202   "aslink", "-nf", "$1", NULL
203 };
204
205 static const char *_asmCmd[] =
206 {
207   "gpasm", NULL, NULL, NULL
208
209 };
210
211 /* Globals */
212 PORT pic_port =
213 {
214   TARGET_ID_PIC,
215   "pic14",
216   "MCU pic",                    /* Target name */
217   {
218     TRUE,                       /* Emit glue around main */
219     MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
220     MODEL_SMALL
221   },
222   {
223     _asmCmd,
224     NULL,
225     NULL,
226         //"-plosgffc",          /* Options with debug */
227         //"-plosgff",           /* Options without debug */
228     0
229   },
230   {
231     _linkCmd,
232     NULL,
233     ".rel"
234   },
235   {
236     _defaultRules
237   },
238   {
239         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
240     1, 1, 2, 4, 1, 2, 1, 1, 4, 4
241         /* TSD - I changed the size of gptr from 3 to 1. However, it should be
242            2 so that we can accomodate the PIC's with 4 register banks (like the
243            16f877)
244          */
245   },
246   {
247     "XSEG    (XDATA)",
248     "STACK   (DATA)",
249     "CSEG    (CODE)",
250     "DSEG    (DATA)",
251     "ISEG    (DATA)",
252     "XSEG    (XDATA)",
253     "BSEG    (BIT)",
254     "RSEG    (DATA)",
255     "GSINIT  (CODE)",
256     "OSEG    (OVR,DATA)",
257     "GSFINAL (CODE)",
258     "HOME        (CODE)",
259     NULL,
260     NULL,
261     1
262   },
263   {
264     +1, 1, 4, 1, 1, 0
265   },
266     /* pic14 has an 8 bit mul */
267   {
268     1, 0
269   },
270   "_",
271   _pic14_init,
272   _pic14_parseOptions,
273   _pic14_finaliseOptions,
274   _pic14_setDefaultOptions,
275   pic14_assignRegisters,
276   _pic14_getRegName,
277   _pic14_keywords,
278   _pic14_genAssemblerPreamble,
279   _pic14_genIVT,
280   _pic14_reset_regparm,
281   _pic14_regparm,
282   NULL,
283   FALSE,
284   0,                            /* leave lt */
285   0,                            /* leave gt */
286   1,                            /* transform <= to ! > */
287   1,                            /* transform >= to ! < */
288   1,                            /* transform != to !(a == b) */
289   0,                            /* leave == */
290   PORT_MAGIC
291 };