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