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