2 Definitions for what a port must provide.
3 All ports are referenced in SDCCmain.c.
10 #include "SDCCpeeph.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 */
93 /* pragma structure */
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 */
108 /** Unique id for this target */
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 */
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.
130 int supported_models
;
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);
138 /* assembler related information */
141 /** Command to run and arguments (eg as-z80) */
143 /** Alternate macro based form. */
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 */
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
*);
158 /* linker related info */
161 /** Command to run (eg link-z80) */
163 /** Alternate macro based form. */
165 /** If non-null will be used to execute the link. */
166 void (*do_link
) (void);
167 /** Extension for object files (.rel, .obj, ...) */
169 /** 1 if port needs the .lnk file, 0 otherwise */
170 const int needLinkerScript
;
171 const char *const *crt
;
172 const char *const *libs
;
176 /** Default peephole 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
);
193 /** Basic type sizes */
201 int near_ptr_size
; // __near
202 int far_ptr_size
; // __far
203 int ptr_size
; // generic
205 int banked_funcptr_size
;
208 unsigned bitint_maxwidth
; // BITINT_MAXWIDTH - maximum size in bits
212 /** tags for far, near, xstack, code generic pointers */
222 /** memory regions related stuff */
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).
256 void (*genExtraAreaDeclaration
) (FILE *, bool);
257 void (*genExtraAreaLinkOptions
) (FILE *);
261 /* Default ABI version */
264 /* stack related information */
267 /** -1 for grows down (z80), +1 for grows up (mcs51) */
269 /** Extra overhead when calling between banks */
271 /** Extra overhead when the function is an ISR */
273 /** Standard overhead for a function call */
275 /** Re-enterant space */
277 /** 'banked' call overhead.
278 Mild overlap with bank_overhead */
280 /** 0 if sp points to last item pushed, 1 if sp points to next location to use */
287 /** Size of the biggest shift the port can handle. -1 if port can handle shifts of arbitrary size. */
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
;
299 void (*emitDebuggerSymbol
) (const char *);
302 int (*regNum
) (const struct reg_info
*);
319 int sizeofMatchJump
[3];
320 int sizeofRangeCompare
[3];
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.
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. */
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) */
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
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.
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. */
445 #if !OPT_DISABLE_MCS51
446 extern PORT mcs51_port
;
449 extern PORT z80_port
;
451 #if !OPT_DISABLE_Z180
452 extern PORT z180_port
;
455 extern PORT r2k_port
; // Rabbit 2000
457 #if !OPT_DISABLE_R2KA
458 extern PORT r2ka_port
; // Rabbit 2000A, 2000C, 2000C, 3000
460 #if !OPT_DISABLE_R3KA
461 extern PORT r3ka_port
; // Rabbit 3000A
463 #if !OPT_DISABLE_SM83
464 extern PORT sm83_port
;
466 #if !OPT_DISABLE_TLCS90
467 extern PORT tlcs90_port
;
469 #if !OPT_DISABLE_EZ80_Z80
470 extern PORT ez80_z80_port
;
472 #if !OPT_DISABLE_Z80N
473 extern PORT z80n_port
;
475 #if !OPT_DISABLE_R800
476 extern PORT r800_port
;
479 extern PORT avr_port
;
481 #if !OPT_DISABLE_DS390
482 extern PORT ds390_port
;
484 #if !OPT_DISABLE_PIC14
485 extern PORT pic_port
;
487 #if !OPT_DISABLE_PIC16
488 extern PORT pic16_port
;
490 #if !OPT_DISABLE_TININative
491 extern PORT tininative_port
;
493 #if !OPT_DISABLE_DS400
494 extern PORT ds400_port
;
496 #if !OPT_DISABLE_HC08
497 extern PORT hc08_port
;
500 extern PORT s08_port
;
502 #if !OPT_DISABLE_STM8
503 extern PORT stm8_port
;
505 #if !OPT_DISABLE_PDK13
506 extern PORT pdk13_port
;
508 #if !OPT_DISABLE_PDK14
509 extern PORT pdk14_port
;
511 #if !OPT_DISABLE_PDK15
512 extern PORT pdk15_port
;
514 #if !OPT_DISABLE_MOS6502
515 extern PORT mos6502_port
;
517 #if !OPT_DISABLE_MOS65C02
518 extern PORT mos65c02_port
;
524 #endif /* PORT_INCLUDE */