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