Update svn merge history.
[sdcc.git] / sdcc / src / port.h
blobda3258ace0bf0d1951b37e7fb630dfd21e6b1ede
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
8 #include "SDCCicode.h"
9 #include "SDCCargs.h"
10 #include "SDCCpeeph.h"
11 #include "dbuf.h"
13 #define TARGET_ID_MCS51 1
14 #define TARGET_ID_SM83 2
15 #define TARGET_ID_Z80 3
16 #define TARGET_ID_AVR 4
17 #define TARGET_ID_DS390 5
18 #define TARGET_ID_PIC14 6
19 #define TARGET_ID_PIC16 7
20 #define TARGET_ID_DS400 10
21 #define TARGET_ID_HC08 11
22 #define TARGET_ID_Z180 12
23 #define TARGET_ID_R2K 13
24 #define TARGET_ID_R3KA 14
25 #define TARGET_ID_S08 15
26 #define TARGET_ID_STM8 16
27 #define TARGET_ID_TLCS90 17
28 #define TARGET_ID_EZ80_Z80 18
29 #define TARGET_ID_PDK13 19
30 #define TARGET_ID_PDK14 20
31 #define TARGET_ID_PDK15 21
32 #define TARGET_ID_PDK16 22
33 #define TARGET_ID_Z80N 23
34 #define TARGET_ID_R2KA 24
35 #define TARGET_ID_MOS6502 25
36 #define TARGET_ID_MOS65C02 26
37 #define TARGET_ID_R800 27
38 #define TARGET_ID_F8 28
40 /* Macro to test the target we are compiling for.
41 Can only be used after SDCCmain has defined the port
43 #define TARGET_IS_MCS51 (port->id == TARGET_ID_MCS51)
44 #define TARGET_IS_AVR (port->id == TARGET_ID_AVR)
45 #define TARGET_IS_DS390 (port->id == TARGET_ID_DS390)
46 #define TARGET_IS_DS400 (port->id == TARGET_ID_DS400)
47 #define TARGET_IS_PIC14 (port->id == TARGET_ID_PIC14)
48 #define TARGET_IS_PIC16 (port->id == TARGET_ID_PIC16)
49 #define TARGET_IS_Z80 (port->id == TARGET_ID_Z80)
50 #define TARGET_IS_Z180 (port->id == TARGET_ID_Z180)
51 #define TARGET_IS_R2K (port->id == TARGET_ID_R2K)
52 #define TARGET_IS_R2KA (port->id == TARGET_ID_R2KA)
53 #define TARGET_IS_R3KA (port->id == TARGET_ID_R3KA)
54 #define TARGET_IS_SM83 (port->id == TARGET_ID_SM83)
55 #define TARGET_IS_TLCS90 (port->id == TARGET_ID_TLCS90)
56 #define TARGET_IS_EZ80_Z80 (port->id == TARGET_ID_EZ80_Z80)
57 #define TARGET_IS_Z80N (port->id == TARGET_ID_Z80N)
58 #define TARGET_IS_R800 (port->id == TARGET_ID_R800)
59 #define TARGET_IS_HC08 (port->id == TARGET_ID_HC08)
60 #define TARGET_IS_S08 (port->id == TARGET_ID_S08)
61 #define TARGET_IS_STM8 (port->id == TARGET_ID_STM8)
62 #define TARGET_IS_PDK13 (port->id == TARGET_ID_PDK13)
63 #define TARGET_IS_PDK14 (port->id == TARGET_ID_PDK14)
64 #define TARGET_IS_PDK15 (port->id == TARGET_ID_PDK15)
65 #define TARGET_IS_PDK16 (port->id == TARGET_ID_PDK16)
66 #define TARGET_IS_MOS6502 (port->id == TARGET_ID_MOS6502)
67 #define TARGET_IS_MOS65C02 (port->id == TARGET_ID_MOS65C02)
68 #define TARGET_IS_F8 (port->id == TARGET_ID_F8)
70 #define TARGET_MCS51_LIKE (TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_DS400)
71 #define TARGET_Z80_LIKE (TARGET_IS_Z80 || TARGET_IS_Z180 || TARGET_IS_SM83 || TARGET_IS_R2K || TARGET_IS_R2KA || TARGET_IS_R3KA || TARGET_IS_TLCS90 || TARGET_IS_EZ80_Z80 || TARGET_IS_Z80N || TARGET_IS_R800)
72 #define TARGET_IS_RABBIT (TARGET_IS_R2K || TARGET_IS_R2KA || TARGET_IS_R3KA)
73 #define TARGET_HC08_LIKE (TARGET_IS_HC08 || TARGET_IS_S08)
74 #define TARGET_PIC_LIKE (TARGET_IS_PIC14 || TARGET_IS_PIC16)
75 #define TARGET_PDK_LIKE (TARGET_IS_PDK13 || TARGET_IS_PDK14 || TARGET_IS_PDK15 || TARGET_IS_PDK16)
76 #define TARGET_MOS6502_LIKE (TARGET_IS_MOS6502 || TARGET_IS_MOS65C02)
78 /* is using sdas / sdld assembler / linker */
79 #define IS_SDASLD (TARGET_Z80_LIKE || TARGET_MCS51_LIKE || TARGET_HC08_LIKE)
81 #define MAX_BUILTIN_ARGS 16
82 /* definition of builtin functions */
83 typedef struct builtins
85 char *name; /* name of builtin function */
86 char *rtype; /* return type as string : see typeFromStr */
87 int nParms; /* number of parms : max 8 */
88 char *parm_types[MAX_BUILTIN_ARGS]; /* each parm type as string : see typeFromStr */
89 } builtins;
91 struct ebbIndex;
93 /* pragma structure */
94 struct pragma_s
96 const char *name;
97 int id;
98 char deprecated;
99 int (*func) (int id, const char *name, const char *cp);
102 /* defined in SDCClex.lex */
103 int process_pragma_tbl (const struct pragma_s *pragma_tbl, const char *s);
105 /* Processor specific names */
106 typedef struct
108 /** Unique id for this target */
109 const int id;
110 /** Target name used for -m */
111 const char *const target;
113 /** Target name string, used for --help */
114 const char *const target_name;
116 /** Specific processor for the given target family. specified by -p */
117 char *processor;
119 struct
121 /** Pointer to glue function */
122 void (*do_glue) (void);
123 /** TRUE if all types of glue functions should be inserted into
124 the file that also defines main.
125 We dont want this in cases like the z80 where the startup
126 code is provided by a separate module.
128 bool glue_up_main;
129 /* OR of MODEL_* */
130 int supported_models;
131 int default_model;
132 /** return the model string, used as library destination;
133 port->target is used as model string if get_model is NULL */
134 const char *(*get_model) (void);
136 general;
138 /* assembler related information */
139 struct
141 /** Command to run and arguments (eg as-z80) */
142 const char **cmd;
143 /** Alternate macro based form. */
144 const char *mcmd;
145 /** Arguments for debug mode. */
146 const char *debug_opts;
147 /** Arguments for normal assembly mode. */
148 const char *plain_opts;
149 /* print externs as global */
150 int externGlobal;
151 /* assembler file extension */
152 const char *file_ext;
153 /** If non-null will be used to execute the assembler. */
154 void (*do_assemble) (set *);
156 assembler;
158 /* linker related info */
159 struct
161 /** Command to run (eg link-z80) */
162 const char **cmd;
163 /** Alternate macro based form. */
164 const char *mcmd;
165 /** If non-null will be used to execute the link. */
166 void (*do_link) (void);
167 /** Extension for object files (.rel, .obj, ...) */
168 const char *rel_ext;
169 /** 1 if port needs the .lnk file, 0 otherwise */
170 const int needLinkerScript;
171 const char *const *crt;
172 const char *const *libs;
174 linker;
176 /** Default peephole rules */
177 struct
179 char *default_rules;
180 int (*getSize) (lineNode * line);
181 bitVect *(*getRegsRead) (lineNode * line);
182 bitVect *(*getRegsWritten) (lineNode * line);
183 bool (*deadMove) (const char *reg, lineNode * currPl, lineNode * head);
184 bool (*notUsed) (const char *reg, lineNode * currPl, lineNode * head);
185 bool (*canAssign) (const char *op1, const char *op2, const char *op3);
186 bool (*notUsedFrom) (const char *reg, const char *label, lineNode *head);
187 bool (*symmParmStack) (const char *name);
188 bool (*canJoinRegs) (const char **regs, char dst[20]);
189 bool (*canSplitReg) (const char *reg, char dst[][16], int nDst);
191 peep;
193 /** Basic type sizes */
194 struct
196 int char_size;
197 int short_size;
198 int int_size;
199 int long_size;
200 int longlong_size;
201 int near_ptr_size; // __near
202 int far_ptr_size; // __far
203 int ptr_size; // generic
204 int funcptr_size;
205 int banked_funcptr_size;
206 int bit_size;
207 int float_size;
208 unsigned bitint_maxwidth; // BITINT_MAXWIDTH - maximum size in bits
212 /** tags for far, near, xstack, code generic pointers */
213 struct
215 int tag_far;
216 int tag_near;
217 int tag_xstack;
218 int tag_code;
220 gp_tags;
222 /** memory regions related stuff */
223 struct
225 const char *const xstack_name;
226 const char *const istack_name;
227 const char *const code_name;
228 const char *const data_name;
229 const char *const idata_name;
230 const char *const pdata_name;
231 const char *const xdata_name;
232 const char *const bit_name;
233 const char *const reg_name;
234 const char *const static_name;
235 const char *const overlay_name;
236 const char *const post_static_name;
237 const char *const home_name;
238 const char *const xidata_name; // initialized xdata
239 const char *const xinit_name; // a code copy of xidata
240 const char *const const_name; // const data (code or not)
241 const char *const cabs_name; // const absolute data (code or not)
242 const char *const xabs_name; // absolute xdata/pdata
243 const char *const iabs_name; // absolute idata/data
244 const char *const initialized_name; // Initialized global (and static local) variables.
245 const char *const initializer_name; // A code copy of initialized_name (to be copied for fast initialization).
246 struct memmap *default_local_map; // default location for auto vars
247 struct memmap *default_globl_map; // default location for globl vars
248 int code_ro; // code space read-only 1=yes
249 bool sfrupointer; // unqualified pointer can point to __sfr,
250 unsigned int maxextalign; // maximum extended alignment supported, nonnegative power of 2 (C11 standard, section 6.2.8).
252 mem;
254 struct
256 void (*genExtraAreaDeclaration) (FILE *, bool);
257 void (*genExtraAreaLinkOptions) (FILE *);
259 extraAreas;
261 /* Default ABI version */
262 unsigned sdcccall;
264 /* stack related information */
265 struct
267 /** -1 for grows down (z80), +1 for grows up (mcs51) */
268 int direction;
269 /** Extra overhead when calling between banks */
270 int bank_overhead;
271 /** Extra overhead when the function is an ISR */
272 int isr_overhead;
273 /** Standard overhead for a function call */
274 int call_overhead;
275 /** Re-enterant space */
276 int reent_overhead;
277 /** 'banked' call overhead.
278 Mild overlap with bank_overhead */
279 int banked_overhead;
280 /** 0 if sp points to last item pushed, 1 if sp points to next location to use */
281 int offset;
283 stack;
285 struct
287 /** Size of the biggest shift the port can handle. -1 if port can handle shifts of arbitrary size. */
288 signed int shift;
290 // Has support routines for int x int -> long multiplication and unsigned int x unsigned int -> unsigned long multiplication
291 bool has_mulint2long;
292 // Has support routine for unsigned long x unsigned char -> unsigned long long multiplication.
293 bool has_mululonguchar2ulonglong;
295 support;
297 struct
299 void (*emitDebuggerSymbol) (const char *);
300 struct
302 int (*regNum) (const struct reg_info *);
303 bitVect *cfiSame;
304 bitVect *cfiUndef;
305 int addressSize;
306 int regNumRet;
307 int regNumSP;
308 int regNumBP;
309 int offsetSP;
311 dwarf;
313 debugger;
315 struct
317 int maxCount;
318 int sizeofElement;
319 int sizeofMatchJump[3];
320 int sizeofRangeCompare[3];
321 int sizeofSubtract;
322 int sizeofDispatch;
324 jumptableCost;
326 /** Prefix to add to a C function (eg "_") */
327 const char *fun_prefix;
329 /** Called once the processor target has been selected.
330 First chance to initialise and set any port specific variables.
331 'port' is set before calling this. May be NULL.
333 void (*init) (void);
334 /** Parses one option + its arguments */
335 bool (*parseOption) (int *pargc, char **argv, int *i);
336 /** Optional list of automatically parsed options. Should be
337 implemented to at least show the help text correctly. */
338 OPTION *poptions;
339 /** Initialise port spectific paths */
340 void (*initPaths) (void);
341 /** Called after all the options have been parsed. */
342 void (*finaliseOptions) (void);
343 /** Called after the port has been selected but before any
344 options are parsed. */
345 void (*setDefaultOptions) (void);
346 /** Does the dirty work. */
347 void (*assignRegisters) (struct ebbIndex *);
349 /** Returns the register name of a symbol.
350 Used so that 'reg_info' can be an incomplete type. */
351 const char *(*getRegName) (const struct reg_info *reg);
353 int (*getRegByName) (const char *name);
355 /** Try to keep track of register contents. */
356 bool (*rtrackUpdate)(const char* line);
358 /* list of keywords that are used by this
359 target (used by lexer) */
360 char **keywords;
362 /* Write any port specific assembler output. */
363 void (*genAssemblerStart) (FILE * of);
364 /* invoked at end assembler file */
365 void (*genAssemblerEnd) (FILE * of);
367 /* Write the port specific IVT. If genIVT is NULL or if
368 * it returns zero, default (8051) IVT generation code
369 * will be used.
371 int (*genIVT) (struct dbuf_s * oBuf, symbol ** intTable, int intCount);
373 void (*genXINIT) (FILE * of);
375 /* Write port specific startup code */
376 void (*genInitStartup) (FILE * of);
378 /* parameter passing in register related functions */
379 void (*reset_regparms) (struct sym_link *); /* reset the register count */
380 int (*reg_parm) (struct sym_link *, bool reentrant); /* will return 1 if can be passed in register */
382 /** Process the pragma string 'sz'. Returns 0 if recognised and
383 processed, 1 otherwise. May be NULL.
385 int (*process_pragma) (const char *sz);
387 /** Mangles a support function name to reflect the calling model.
389 const char *(*getMangledFunctionName) (const char *szOrginial);
391 /** Returns true if the port can multiply the two types nativly
392 without using support functions.
394 bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right);
396 /** Returns true if the port has implemented certain bit
397 manipulation iCodes (ROT, GETABIT, GETBYTE, GETWORD)
398 right parameter: value of right operand if in >= 0; negative if non-literal.
400 bool (*hasExtBitOp) (int op, sym_link *left, int right);
402 /** Returns true if the port has implemented certain bit
403 manipulation iCodes (ROT, GETABIT, GETBYTE, GETWORD)
406 /** Returns the relative expense of accessing a particular output
407 storage class. Larger values indicate higher expense.
409 int (*oclsExpense) (struct memmap * oclass);
411 /** If TRUE, then tprintf and !dw will be used for some initalisers
413 bool use_dw_for_init;
415 /** TRUE for targets with little endian byte ordering, FALSE for
416 targets with big endian byte ordering.
418 bool little_endian;
420 /* condition transformations */
421 bool lt_nge; /* transform (a < b) to !(a >= b) */
422 bool gt_nle; /* transform (a > b) to !(a <= b) */
423 bool le_ngt; /* transform (a <= b) to !(a > b) */
424 bool ge_nlt; /* transform (a >= b) to !(a < b) */
425 bool ne_neq; /* transform a != b --> ! (a == b) */
426 bool eq_nne; /* transform a == b --> ! (a != b) */
428 bool arrayInitializerSuppported;
429 bool (*cseOk) (iCode * ic, iCode * pdic);
430 builtins *builtintable; /* table of builtin functions */
431 int unqualified_pointer; /* unqualified pointers type is */
432 int reset_labelKey; /* reset Label no 1 at the start of a function */
433 int globals_allowed; /* global & static locals not allowed ? 0 ONLY TININative */
435 int num_regs; /* Number of registers handled in the tree-decomposition-based register allocator in SDCCralloc.hpp */
437 #define PORT_MAGIC 0xAC32
438 /** Used at runtime to detect if this structure has been completely filled in. */
439 int magic;
441 PORT;
443 extern PORT *port;
445 #if !OPT_DISABLE_MCS51
446 extern PORT mcs51_port;
447 #endif
448 #if !OPT_DISABLE_Z80
449 extern PORT z80_port;
450 #endif
451 #if !OPT_DISABLE_Z180
452 extern PORT z180_port;
453 #endif
454 #if !OPT_DISABLE_R2K
455 extern PORT r2k_port; // Rabbit 2000
456 #endif
457 #if !OPT_DISABLE_R2KA
458 extern PORT r2ka_port; // Rabbit 2000A, 2000C, 2000C, 3000
459 #endif
460 #if !OPT_DISABLE_R3KA
461 extern PORT r3ka_port; // Rabbit 3000A
462 #endif
463 #if !OPT_DISABLE_SM83
464 extern PORT sm83_port;
465 #endif
466 #if !OPT_DISABLE_TLCS90
467 extern PORT tlcs90_port;
468 #endif
469 #if !OPT_DISABLE_EZ80_Z80
470 extern PORT ez80_z80_port;
471 #endif
472 #if !OPT_DISABLE_Z80N
473 extern PORT z80n_port;
474 #endif
475 #if !OPT_DISABLE_R800
476 extern PORT r800_port;
477 #endif
478 #if !OPT_DISABLE_AVR
479 extern PORT avr_port;
480 #endif
481 #if !OPT_DISABLE_DS390
482 extern PORT ds390_port;
483 #endif
484 #if !OPT_DISABLE_PIC14
485 extern PORT pic_port;
486 #endif
487 #if !OPT_DISABLE_PIC16
488 extern PORT pic16_port;
489 #endif
490 #if !OPT_DISABLE_TININative
491 extern PORT tininative_port;
492 #endif
493 #if !OPT_DISABLE_DS400
494 extern PORT ds400_port;
495 #endif
496 #if !OPT_DISABLE_HC08
497 extern PORT hc08_port;
498 #endif
499 #if !OPT_DISABLE_S08
500 extern PORT s08_port;
501 #endif
502 #if !OPT_DISABLE_STM8
503 extern PORT stm8_port;
504 #endif
505 #if !OPT_DISABLE_PDK13
506 extern PORT pdk13_port;
507 #endif
508 #if !OPT_DISABLE_PDK14
509 extern PORT pdk14_port;
510 #endif
511 #if !OPT_DISABLE_PDK15
512 extern PORT pdk15_port;
513 #endif
514 #if !OPT_DISABLE_MOS6502
515 extern PORT mos6502_port;
516 #endif
517 #if !OPT_DISABLE_MOS65C02
518 extern PORT mos65c02_port;
519 #endif
520 #if !OPT_DISABLE_F8
521 extern PORT f8_port;
522 #endif
524 #endif /* PORT_INCLUDE */