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