e07d7a95ee00eda51d910c82275240e18723fc39
[fw/sdcc] / src / port.h
1 /** @file port.h
2     Definitions for what a port must provide.
3     All ports are referenced in SDCCmain.c.
4 */
5 #ifndef PORT_INCLUDE
6 #define PORT_INCLUDE
7
8 #include "SDCCicode.h"
9 #include "SDCCargs.h"
10 #include "SDCCpeeph.h"
11
12 #define TARGET_ID_MCS51    1
13 #define TARGET_ID_GBZ80    2
14 #define TARGET_ID_Z80      3
15 #define TARGET_ID_AVR      4
16 #define TARGET_ID_DS390    5
17 #define TARGET_ID_PIC      6
18 #define TARGET_ID_PIC16    7
19 #define TARGET_ID_XA51     9
20 #define TARGET_ID_DS400    10
21 #define TARGET_ID_HC08     11
22
23 /* Macro to test the target we are compiling for.
24    Can only be used after SDCCmain has defined the port
25 */
26 #define TARGET_IS_MCS51 (port->id==TARGET_ID_MCS51)
27 #define TARGET_IS_GBZ80 (port->id==TARGET_ID_GBZ80)
28 #define TARGET_IS_Z80 (port->id==TARGET_ID_Z80)
29 #define TARGET_IS_AVR (port->id==TARGET_ID_AVR)
30 #define TARGET_IS_DS390 (port->id==TARGET_ID_DS390)
31 #define TARGET_IS_DS400 (port->id==TARGET_ID_DS400)
32 #define TARGET_IS_PIC   (port->id==TARGET_ID_PIC)
33 #define TARGET_IS_PIC16 (port->id==TARGET_ID_PIC16)
34 #define TARGET_IS_XA51 (port->id==TARGET_ID_XA51)
35 #define TARGET_IS_HC08 (port->id==TARGET_ID_HC08)
36
37 #define MAX_BUILTIN_ARGS        16
38 /* definition of builtin functions */
39 typedef struct builtins
40   {
41     char *name;                         /* name of builtin function */
42     char *rtype;                        /* return type as string : see typefromStr */
43     int  nParms;                        /* number of parms : max 8 */
44     char *parm_types[MAX_BUILTIN_ARGS]; /* each parm type as string : see typeFromStr */
45   } builtins;
46
47 struct ebbIndex;
48
49 /* pragma structure */
50 struct pragma_s
51   {
52     const char *name;
53     int id;
54     char deprecated;
55     int (*func)(int id, const char *name, const char *cp);
56   };
57
58 /* defined in SDCClex.lex */
59 int process_pragma_tbl(const struct pragma_s *pragma_tbl, const char *s);
60
61 /* Processor specific names */
62 typedef struct
63   {
64 /** Unique id for this target */
65     const int id;
66 /** Target name used for -m */
67     const char *target;
68
69 /** Target name string, used for --help */
70     const char *target_name;
71
72 /** Specific processor for the given target family. specified by -p */
73     char *processor;
74
75     struct
76       {
77         /** Pointer to glue function */
78         void (*do_glue)(void);
79         /** TRUE if all types of glue functions should be inserted into
80             the file that also defines main.
81             We dont want this in cases like the z80 where the startup
82             code is provided by a seperate module.
83         */
84         bool glue_up_main;
85         /* OR of MODEL_* */
86         int supported_models;
87         int default_model;
88       }
89     general;
90
91     /* assembler related information */
92     struct
93       {
94         /** Command to run and arguments (eg as-z80) */
95         const char **cmd;
96         /** Alternate macro based form. */
97         const char *mcmd;
98         /** Arguments for debug mode. */
99         const char *debug_opts;
100         /** Arguments for normal assembly mode. */
101         const char *plain_opts;
102         /* print externs as global */
103         int externGlobal;
104         /* assembler file extension */
105         const char *file_ext;
106         /** If non-null will be used to execute the assembler. */
107         void (*do_assemble) (set *);
108       }
109     assembler;
110
111     /* linker related info */
112     struct
113       {
114         /** Command to run (eg link-z80) */
115         const char **cmd;
116         /** Alternate macro based form. */
117         const char *mcmd;
118         /** If non-null will be used to execute the link. */
119         void (*do_link) (void);
120         /** Extension for object files (.rel, .obj, ...) */
121         const char *rel_ext;
122         /** 1 if port needs the .lnk file, 0 otherwise */
123         const int needLinkerScript;
124       }
125     linker;
126
127     struct
128       {
129 /** Default peephole rules */
130         char *default_rules;
131         int (*getSize)(lineNode *line);
132         bitVect * (*getRegsRead)(lineNode *line);
133         bitVect * (*getRegsWritten)(lineNode *line);
134       }
135     peep;
136
137 /** Basic type sizes */
138     struct
139       {
140         int char_size;
141         int short_size;
142         unsigned int int_size;
143         int long_size;
144         int ptr_size;       //near
145         int fptr_size;      //far
146         int gptr_size;      //generic
147         int bit_size;
148         int float_size;
149         int max_base_size;
150       }
151     s;
152
153 /** tags for far, near, xstack, code generic pointers */
154     struct
155       {
156         int tag_far;
157         int tag_near;
158         int tag_xstack;
159         int tag_code;
160       }
161     gp_tags;
162
163 /** memory regions related stuff */
164     struct
165       {
166         const char *xstack_name;
167         const char *istack_name;
168         const char *code_name;
169         const char *data_name;
170         const char *idata_name;
171         const char *pdata_name;
172         const char *xdata_name;
173         const char *bit_name;
174         const char *reg_name;
175         const char *static_name;
176         const char *overlay_name;
177         const char *post_static_name;
178         const char *home_name;
179         const char *xidata_name; // initialized xdata
180         const char *xinit_name; // a code copy of xidata
181         const char *const_name; // const data (code or not)
182         const char *cabs_name; // const absolute data (code or not)
183         const char *xabs_name; // absolute xdata/pdata
184         const char *iabs_name; // absolute idata/data
185         struct memmap *default_local_map; // default location for auto vars
186         struct memmap *default_globl_map; // default location for globl vars
187         int code_ro;            /* code space read-only 1=yes */
188       }
189     mem;
190
191     struct
192       {
193           void (*genExtraAreaDeclaration)(FILE *, bool);
194           void (*genExtraAreaLinkOptions)(FILE *);
195       }
196     extraAreas;
197
198     /* stack related information */
199     struct
200       {
201 /** -1 for grows down (z80), +1 for grows up (mcs51) */
202         int direction;
203 /** Extra overhead when calling between banks */
204         int bank_overhead;
205 /** Extra overhead when the function is an ISR */
206         int isr_overhead;
207 /** Standard overhead for a function call */
208         int call_overhead;
209 /** Re-enterant space */
210         int reent_overhead;
211         /** 'banked' call overhead.
212             Mild overlap with bank_overhead */
213         int banked_overhead;
214       }
215     stack;
216
217     struct
218       {
219         /** One more than the smallest
220             mul/div operation the processor can do natively
221             Eg if the processor has an 8 bit mul, native below is 2 */
222         unsigned muldiv;
223         unsigned shift;
224       }
225     support;
226
227     struct
228       {
229         void (*emitDebuggerSymbol) (char *);
230         struct
231           {
232             int (*regNum) (struct regs *);
233             bitVect * cfiSame;
234             bitVect * cfiUndef;
235             int addressSize;
236             int regNumRet;
237             int regNumSP;
238             int regNumBP;
239             int offsetSP;
240           }
241         dwarf;
242       }
243     debugger;
244
245     struct
246       {
247         int maxCount;
248         int sizeofElement;
249         int sizeofMatchJump[3];
250         int sizeofRangeCompare[3];
251         int sizeofSubtract;
252         int sizeofDispatch;
253       }
254     jumptableCost;
255
256 /** Prefix to add to a C function (eg "_") */
257     const char *fun_prefix;
258
259     /** Called once the processor target has been selected.
260         First chance to initalise and set any port specific variables.
261         'port' is set before calling this.  May be NULL.
262     */
263     void (*init) (void);
264 /** Parses one option + its arguments */
265       bool (*parseOption) (int *pargc, char **argv, int *i);
266 /** Optional list of automatically parsed options.  Should be
267     implemented to at least show the help text correctly. */
268     OPTION *poptions;
269 /** Initialise port spectific paths */
270     void (*initPaths)(void);
271 /** Called after all the options have been parsed. */
272     void (*finaliseOptions) (void);
273     /** Called after the port has been selected but before any
274         options are parsed. */
275     void (*setDefaultOptions) (void);
276 /** Does the dirty work. */
277     void (*assignRegisters) (struct ebbIndex *);
278
279     /** Returns the register name of a symbol.
280         Used so that 'regs' can be an incomplete type. */
281     const char *(*getRegName) (struct regs * reg);
282
283     /* list of keywords that are used by this
284        target (used by lexer) */
285     char **keywords;
286
287     /* Write any port specific assembler output. */
288     void (*genAssemblerPreamble) (FILE * of);
289       /* invoked at end assembler file */
290     void (*genAssemblerEnd) (FILE * of);
291
292     /* Write the port specific IVT. If genIVT is NULL or if
293      * it returns zero, default (8051) IVT generation code
294      * will be used.
295      */
296     int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
297
298     void (*genXINIT) (FILE * of);
299
300     /* Write port specific startup code */
301     void (*genInitStartup) (FILE * of);
302
303     /* parameter passing in register related functions */
304     void (*reset_regparms) (void);      /* reset the register count */
305     int (*reg_parm) (struct sym_link *, bool reentrant);        /* will return 1 if can be passed in register */
306
307     /** Process the pragma string 'sz'.  Returns 0 if recognised and
308         processed, 1 otherwise.  May be NULL.
309     */
310     int (*process_pragma) (const char *sz);
311
312     /** Mangles a support function name to reflect the calling model.
313      */
314     char *(*getMangledFunctionName) (char *szOrginial);
315
316     /** Returns true if the port can multiply the two types nativly
317         without using support functions.
318     */
319     bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right);
320
321     /** Returns true if the port has implemented certain bit
322         manipulation iCodes (RRC, RLC, SWAP, GETHBIT, GETABIT, GETBYTE, GETWORD)
323     */
324     bool (*hasExtBitOp) (int op, int size);
325
326     /** Returns the relative expense of accessing a particular output
327         storage class. Larger values indicate higher expense.
328     */
329     int (*oclsExpense) (struct memmap *oclass);
330
331     /** If TRUE, then tprintf and !dw will be used for some initalisers
332      */
333     bool use_dw_for_init;
334
335     /** TRUE for targets with little endian byte ordering, FALSE for
336         targets with big endian byte ordering.
337      */
338     bool little_endian;
339
340     /* condition transformations */
341     bool lt_nge;                /* transform (a < b)  to !(a >= b)  */
342     bool gt_nle;                /* transform (a > b)  to !(a <= b)  */
343     bool le_ngt;                /* transform (a <= b) to !(a > b)   */
344     bool ge_nlt;                /* transform (a >= b) to !(a < b)   */
345     bool ne_neq;                /* transform a != b --> ! (a == b)  */
346     bool eq_nne;                /* transform a == b --> ! (a != b)  */
347
348     bool arrayInitializerSuppported;
349     bool (*cseOk) (iCode *ic, iCode *pdic);
350     builtins *builtintable;     /* table of builtin functions */
351     int unqualified_pointer;    /* unqualified pointers type is  */
352     int reset_labelKey  ;       /* reset Label no 1 at the start of a function */
353     int globals_allowed ;       /* global & static locals not allowed ?  0 ONLY TININative*/
354 #define PORT_MAGIC 0xAC32
355 /** Used at runtime to detect if this structure has been completly filled in. */
356     int magic;
357   }
358 PORT;
359
360 extern PORT *port;
361
362 #if !OPT_DISABLE_MCS51
363 extern PORT mcs51_port;
364 #endif
365 #if !OPT_DISABLE_GBZ80
366 extern PORT gbz80_port;
367 #endif
368 #if !OPT_DISABLE_Z80
369 extern PORT z80_port;
370 #endif
371 #if !OPT_DISABLE_AVR
372 extern PORT avr_port;
373 #endif
374 #if !OPT_DISABLE_DS390
375 extern PORT ds390_port;
376 #endif
377 #if !OPT_DISABLE_PIC
378 extern PORT pic_port;
379 #endif
380 #if !OPT_DISABLE_PIC16
381 extern PORT pic16_port;
382 #endif
383 #if !OPT_DISABLE_TININative
384 extern PORT tininative_port;
385 #endif
386 #if !OPT_DISABLE_XA51
387 extern PORT xa51_port;
388 #endif
389 #if !OPT_DISABLE_DS400
390 extern PORT ds400_port;
391 #endif
392 #if !OPT_DISABLE_HC08
393 extern PORT hc08_port;
394 #endif
395
396 #endif /* PORT_INCLUDE*/