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