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