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