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