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