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