1 /* Definitions of target machine for GNU compiler,
2 for ATMEL AVR at90s8515, ATmega103/103L, ATmega603/603L microcontrollers.
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 Free Software Foundation, Inc.
6 Contributed by Denis Chertykov (chertykov@gmail.com)
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* Names to predefine in the preprocessor for this target machine. */
31 /* Core have 'MUL*' instructions. */
34 /* Core have 'CALL' and 'JMP' instructions. */
37 /* Core have 'MOVW' and 'LPM Rx,Z' instructions. */
40 /* Core have 'ELPM' instructions. */
43 /* Core have 'ELPM Rx,Z' instructions. */
46 /* Core have 'EICALL' and 'EIJMP' instructions. */
47 int have_eijmp_eicall
;
49 /* This is an XMEGA core. */
52 /* This core has the RAMPD special function register
53 and thus also the RAMPX, RAMPY and RAMPZ registers. */
56 /* Default start of data section address for architecture. */
57 int default_data_section_start
;
59 /* Offset between SFR address and RAM address:
60 SFR-address = RAM-address - sfr_offset */
63 /* Number of 64k segments in the flash. */
66 /* Architecture id to built-in define __AVR_ARCH__ (NULL -> no macro) */
67 const char *const macro
;
69 /* Architecture name. */
70 const char *const arch_name
;
73 /* These names are used as the index into the avr_arch_types[] table
98 const char *const name
;
100 /* Index in avr_arch_types[]. */
103 /* Must lie outside user's namespace. NULL == no macro. */
104 const char *const macro
;
106 /* Stack pointer have 8 bits width. */
109 /* Some AVR devices have a core erratum when skipping a 2-word instruction.
110 Skip instructions are: SBRC, SBRS, SBIC, SBIS, CPSE.
111 Problems will occur with return address is IRQ executes during the
114 A support ticket from Atmel returned the following information:
116 Subject: (ATTicket:644469) On AVR skip-bug core Erratum
117 From: avr@atmel.com Date: 2011-07-27
118 (Please keep the subject when replying to this mail)
120 This errata exists only in AT90S8515 and ATmega103 devices.
122 For information please refer the following respective errata links
123 http://www.atmel.com/dyn/resources/prod_documents/doc2494.pdf
124 http://www.atmel.com/dyn/resources/prod_documents/doc1436.pdf */
126 /* Core Erratum: Must not skip 2-word instruction. */
129 /* Start of data section. */
130 int data_section_start
;
132 /* Name of device library. */
133 const char *const library_name
;
136 /* Preprocessor macros to define depending on MCU type. */
137 extern const char *avr_extra_arch_macro
;
138 extern const struct base_arch_s
*avr_current_arch
;
139 extern const struct mcu_type_s
*avr_current_device
;
140 extern const struct mcu_type_s avr_mcu_types
[];
141 extern const struct base_arch_s avr_arch_types
[];
145 /* Id of the address space as used in c_register_addr_space */
148 /* Flavour of memory: 0 = RAM, 1 = Flash */
151 /* Width of pointer (in bytes) */
154 /* Name of the address space as visible to the user */
157 /* Segment (i.e. 64k memory chunk) number. */
161 extern const avr_addrspace_t avr_addrspace
[];
163 /* Known address spaces */
177 #define TARGET_CPU_CPP_BUILTINS() avr_cpu_cpp_builtins (pfile)
179 #define AVR_HAVE_JMP_CALL (avr_current_arch->have_jmp_call && !TARGET_SHORT_CALLS)
180 #define AVR_HAVE_MUL (avr_current_arch->have_mul)
181 #define AVR_HAVE_MOVW (avr_current_arch->have_movw_lpmx)
182 #define AVR_HAVE_LPMX (avr_current_arch->have_movw_lpmx)
183 #define AVR_HAVE_ELPM (avr_current_arch->have_elpm)
184 #define AVR_HAVE_ELPMX (avr_current_arch->have_elpmx)
185 #define AVR_HAVE_RAMPD (avr_current_arch->have_rampd)
186 #define AVR_HAVE_RAMPX (avr_current_arch->have_rampd)
187 #define AVR_HAVE_RAMPY (avr_current_arch->have_rampd)
188 #define AVR_HAVE_RAMPZ (avr_current_arch->have_elpm \
189 || avr_current_arch->have_rampd)
190 #define AVR_HAVE_EIJMP_EICALL (avr_current_arch->have_eijmp_eicall)
191 #define AVR_HAVE_8BIT_SP (avr_current_device->short_sp || TARGET_TINY_STACK)
193 #define AVR_2_BYTE_PC (!AVR_HAVE_EIJMP_EICALL)
194 #define AVR_3_BYTE_PC (AVR_HAVE_EIJMP_EICALL)
196 #define AVR_XMEGA (avr_current_arch->xmega_p)
198 #define BITS_BIG_ENDIAN 0
199 #define BYTES_BIG_ENDIAN 0
200 #define WORDS_BIG_ENDIAN 0
203 /* This is to get correct SI and DI modes in libgcc2.c (32 and 64 bits). */
204 #define UNITS_PER_WORD 4
206 /* Width of a word, in units (bytes). */
207 #define UNITS_PER_WORD 1
210 #define POINTER_SIZE 16
213 /* Maximum sized of reasonable data type
214 DImode or Dfmode ... */
215 #define MAX_FIXED_MODE_SIZE 32
217 #define PARM_BOUNDARY 8
219 #define FUNCTION_BOUNDARY 8
221 #define EMPTY_FIELD_BOUNDARY 8
223 /* No data type wants to be aligned rounder than this. */
224 #define BIGGEST_ALIGNMENT 8
226 #define TARGET_VTABLE_ENTRY_ALIGN 8
228 #define STRICT_ALIGNMENT 0
230 #define INT_TYPE_SIZE (TARGET_INT8 ? 8 : 16)
231 #define SHORT_TYPE_SIZE (INT_TYPE_SIZE == 8 ? INT_TYPE_SIZE : 16)
232 #define LONG_TYPE_SIZE (INT_TYPE_SIZE == 8 ? 16 : 32)
233 #define LONG_LONG_TYPE_SIZE (INT_TYPE_SIZE == 8 ? 32 : 64)
234 #define FLOAT_TYPE_SIZE 32
235 #define DOUBLE_TYPE_SIZE 32
236 #define LONG_DOUBLE_TYPE_SIZE 32
238 #define DEFAULT_SIGNED_CHAR 1
240 #define SIZE_TYPE (INT_TYPE_SIZE == 8 ? "long unsigned int" : "unsigned int")
241 #define PTRDIFF_TYPE (INT_TYPE_SIZE == 8 ? "long int" :"int")
243 #define WCHAR_TYPE_SIZE 16
245 #define FIRST_PSEUDO_REGISTER 36
247 #define FIXED_REGISTERS {\
265 1,1 /* arg pointer */ }
267 #define CALL_USED_REGISTERS { \
285 1,1 /* arg pointer */ }
287 #define REG_ALLOC_ORDER { \
295 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2, \
300 #define ADJUST_REG_ALLOC_ORDER order_regs_for_local_alloc ()
303 #define HARD_REGNO_NREGS(REGNO, MODE) ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
305 #define HARD_REGNO_MODE_OK(REGNO, MODE) avr_hard_regno_mode_ok(REGNO, MODE)
307 #define MODES_TIEABLE_P(MODE1, MODE2) 1
312 POINTER_X_REGS
, /* r26 - r27 */
313 POINTER_Y_REGS
, /* r28 - r29 */
314 POINTER_Z_REGS
, /* r30 - r31 */
315 STACK_REG
, /* STACK */
316 BASE_POINTER_REGS
, /* r28 - r31 */
317 POINTER_REGS
, /* r26 - r31 */
318 ADDW_REGS
, /* r24 - r31 */
319 SIMPLE_LD_REGS
, /* r16 - r23 */
320 LD_REGS
, /* r16 - r31 */
321 NO_LD_REGS
, /* r0 - r15 */
322 GENERAL_REGS
, /* r0 - r31 */
323 ALL_REGS
, LIM_REG_CLASSES
327 #define N_REG_CLASSES (int)LIM_REG_CLASSES
329 #define REG_CLASS_NAMES { \
332 "POINTER_X_REGS", /* r26 - r27 */ \
333 "POINTER_Y_REGS", /* r28 - r29 */ \
334 "POINTER_Z_REGS", /* r30 - r31 */ \
335 "STACK_REG", /* STACK */ \
336 "BASE_POINTER_REGS", /* r28 - r31 */ \
337 "POINTER_REGS", /* r26 - r31 */ \
338 "ADDW_REGS", /* r24 - r31 */ \
339 "SIMPLE_LD_REGS", /* r16 - r23 */ \
340 "LD_REGS", /* r16 - r31 */ \
341 "NO_LD_REGS", /* r0 - r15 */ \
342 "GENERAL_REGS", /* r0 - r31 */ \
345 #define REG_CLASS_CONTENTS { \
346 {0x00000000,0x00000000}, /* NO_REGS */ \
347 {0x00000001,0x00000000}, /* R0_REG */ \
348 {3 << REG_X,0x00000000}, /* POINTER_X_REGS, r26 - r27 */ \
349 {3 << REG_Y,0x00000000}, /* POINTER_Y_REGS, r28 - r29 */ \
350 {3 << REG_Z,0x00000000}, /* POINTER_Z_REGS, r30 - r31 */ \
351 {0x00000000,0x00000003}, /* STACK_REG, STACK */ \
352 {(3 << REG_Y) | (3 << REG_Z), \
353 0x00000000}, /* BASE_POINTER_REGS, r28 - r31 */ \
354 {(3 << REG_X) | (3 << REG_Y) | (3 << REG_Z), \
355 0x00000000}, /* POINTER_REGS, r26 - r31 */ \
356 {(3 << REG_X) | (3 << REG_Y) | (3 << REG_Z) | (3 << REG_W), \
357 0x00000000}, /* ADDW_REGS, r24 - r31 */ \
358 {0x00ff0000,0x00000000}, /* SIMPLE_LD_REGS r16 - r23 */ \
359 {(3 << REG_X)|(3 << REG_Y)|(3 << REG_Z)|(3 << REG_W)|(0xff << 16), \
360 0x00000000}, /* LD_REGS, r16 - r31 */ \
361 {0x0000ffff,0x00000000}, /* NO_LD_REGS r0 - r15 */ \
362 {0xffffffff,0x00000000}, /* GENERAL_REGS, r0 - r31 */ \
363 {0xffffffff,0x00000003} /* ALL_REGS */ \
366 #define REGNO_REG_CLASS(R) avr_regno_reg_class(R)
368 #define MODE_CODE_BASE_REG_CLASS(mode, as, outer_code, index_code) \
369 avr_mode_code_base_reg_class (mode, as, outer_code, index_code)
371 #define INDEX_REG_CLASS NO_REGS
373 #define REGNO_MODE_CODE_OK_FOR_BASE_P(num, mode, as, outer_code, index_code) \
374 avr_regno_mode_code_ok_for_base_p (num, mode, as, outer_code, index_code)
376 #define REGNO_OK_FOR_INDEX_P(NUM) 0
378 #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
380 #define STACK_PUSH_CODE POST_DEC
382 #define STACK_GROWS_DOWNWARD
384 #define STARTING_FRAME_OFFSET avr_starting_frame_offset()
386 #define STACK_POINTER_OFFSET 1
388 #define FIRST_PARM_OFFSET(FUNDECL) 0
390 #define STACK_BOUNDARY 8
392 #define STACK_POINTER_REGNUM 32
394 #define FRAME_POINTER_REGNUM REG_Y
396 #define ARG_POINTER_REGNUM 34
398 #define STATIC_CHAIN_REGNUM 2
400 #define ELIMINABLE_REGS { \
401 {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
402 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM} \
403 ,{FRAME_POINTER_REGNUM+1,STACK_POINTER_REGNUM+1}}
405 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
406 OFFSET = avr_initial_elimination_offset (FROM, TO)
408 #define RETURN_ADDR_RTX(count, tem) avr_return_addr_rtx (count, tem)
410 /* Don't use Push rounding. expr.c: emit_single_push_insn is broken
411 for POST_DEC targets (PR27386). */
412 /*#define PUSH_ROUNDING(NPUSHED) (NPUSHED)*/
414 typedef struct avr_args
{
415 int nregs
; /* # registers available for passing */
416 int regno
; /* next available register number */
419 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
420 init_cumulative_args (&(CUM), FNTYPE, LIBNAME, FNDECL)
422 #define FUNCTION_ARG_REGNO_P(r) function_arg_regno_p(r)
424 #define DEFAULT_PCC_STRUCT_RETURN 0
426 #define EPILOGUE_USES(REGNO) avr_epilogue_uses(REGNO)
428 #define HAVE_POST_INCREMENT 1
429 #define HAVE_PRE_DECREMENT 1
431 #define MAX_REGS_PER_ADDRESS 1
433 #define LEGITIMIZE_RELOAD_ADDRESS(X,MODE,OPNUM,TYPE,IND_L,WIN) \
435 rtx new_x = avr_legitimize_reload_address (&(X), MODE, OPNUM, TYPE, \
437 IND_L, make_memloc); \
445 #define BRANCH_COST(speed_p, predictable_p) avr_branch_cost
447 #define SLOW_BYTE_ACCESS 0
449 #define NO_FUNCTION_CSE
451 #define REGISTER_TARGET_PRAGMAS() \
453 avr_register_target_pragmas(); \
456 #define TEXT_SECTION_ASM_OP "\t.text"
458 #define DATA_SECTION_ASM_OP "\t.data"
460 #define BSS_SECTION_ASM_OP "\t.section .bss"
462 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
463 There are no shared libraries on this target, and these sections are
464 placed in the read-only program memory, so they are not writable. */
466 #undef CTORS_SECTION_ASM_OP
467 #define CTORS_SECTION_ASM_OP "\t.section .ctors,\"a\",@progbits"
469 #undef DTORS_SECTION_ASM_OP
470 #define DTORS_SECTION_ASM_OP "\t.section .dtors,\"a\",@progbits"
472 #define TARGET_ASM_CONSTRUCTOR avr_asm_out_ctor
474 #define TARGET_ASM_DESTRUCTOR avr_asm_out_dtor
476 #define SUPPORTS_INIT_PRIORITY 0
478 #define JUMP_TABLES_IN_TEXT_SECTION 0
480 #define ASM_COMMENT_START " ; "
482 #define ASM_APP_ON "/* #APP */\n"
484 #define ASM_APP_OFF "/* #NOAPP */\n"
486 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == '\n' || ((C) == '$'))
488 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(STREAM, DECL, NAME, SIZE, ALIGN) \
489 avr_asm_output_aligned_decl_common (STREAM, DECL, NAME, SIZE, ALIGN, false)
491 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
492 asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
494 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(STREAM, DECL, NAME, SIZE, ALIGN) \
495 avr_asm_output_aligned_decl_common (STREAM, DECL, NAME, SIZE, ALIGN, true)
497 /* Globalizing directive for a label. */
498 #define GLOBAL_ASM_OP ".global\t"
500 #define SUPPORTS_WEAK 1
502 #define HAS_INIT_SECTION 1
504 #define REGISTER_NAMES { \
505 "r0","r1","r2","r3","r4","r5","r6","r7", \
506 "r8","r9","r10","r11","r12","r13","r14","r15", \
507 "r16","r17","r18","r19","r20","r21","r22","r23", \
508 "r24","r25","r26","r27","r28","r29","r30","r31", \
509 "__SP_L__","__SP_H__","argL","argH"}
511 #define FINAL_PRESCAN_INSN(insn, operand, nop) final_prescan_insn (insn, operand,nop)
513 #define ASM_OUTPUT_REG_PUSH(STREAM, REGNO) \
515 gcc_assert (REGNO < 32); \
516 fprintf (STREAM, "\tpush\tr%d", REGNO); \
519 #define ASM_OUTPUT_REG_POP(STREAM, REGNO) \
521 gcc_assert (REGNO < 32); \
522 fprintf (STREAM, "\tpop\tr%d", REGNO); \
525 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
526 avr_output_addr_vec_elt(STREAM, VALUE)
528 #define ASM_OUTPUT_ALIGN(STREAM, POWER) \
531 fprintf (STREAM, "\t.p2align\t%d\n", POWER); \
534 #define CASE_VECTOR_MODE HImode
536 #undef WORD_REGISTER_OPERATIONS
540 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
544 #define FUNCTION_MODE HImode
546 #define DOLLARS_IN_IDENTIFIERS 0
548 #define TRAMPOLINE_SIZE 4
550 /* Store in cc_status the expressions
551 that the condition codes will describe
552 after execution of an instruction whose pattern is EXP.
553 Do not alter them if the instruction would not alter the cc's. */
555 #define NOTICE_UPDATE_CC(EXP, INSN) notice_update_cc(EXP, INSN)
557 /* The add insns don't set overflow in a usable way. */
558 #define CC_OVERFLOW_UNUSABLE 01000
559 /* The mov,and,or,xor insns don't set carry. That's ok though as the
560 Z bit is all we need when doing unsigned comparisons on the result of
561 these insns (since they're always with 0). However, conditions.h has
562 CC_NO_OVERFLOW defined for this purpose. Rename it to something more
564 #define CC_NO_CARRY CC_NO_OVERFLOW
567 /* Output assembler code to FILE to increment profiler label # LABELNO
568 for profiling a function entry. */
570 #define FUNCTION_PROFILER(FILE, LABELNO) \
571 fprintf (FILE, "/* profiler %d */", (LABELNO))
573 #define ADJUST_INSN_LENGTH(INSN, LENGTH) (LENGTH =\
574 adjust_insn_length (INSN, LENGTH))
576 extern const char *avr_device_to_arch (int argc
, const char **argv
);
577 extern const char *avr_device_to_data_start (int argc
, const char **argv
);
578 extern const char *avr_device_to_startfiles (int argc
, const char **argv
);
579 extern const char *avr_device_to_devicelib (int argc
, const char **argv
);
581 #define EXTRA_SPEC_FUNCTIONS \
582 { "device_to_arch", avr_device_to_arch }, \
583 { "device_to_data_start", avr_device_to_data_start }, \
584 { "device_to_startfile", avr_device_to_startfiles }, \
585 { "device_to_devicelib", avr_device_to_devicelib },
591 #define CC1PLUS_SPEC "%{!frtti:-fno-rtti} \
592 %{!fenforce-eh-specs:-fno-enforce-eh-specs} \
593 %{!fexceptions:-fno-exceptions}"
594 /* A C string constant that tells the GCC driver program options to
595 pass to `cc1plus'. */
597 #define ASM_SPEC "%{mmcu=avr25:-mmcu=avr2;mmcu=avr35:-mmcu=avr3;mmcu=avr31:-mmcu=avr3;mmcu=avr51:-mmcu=avr5;\
602 %{mpmem-wrap-around:%{mmcu=at90usb8*:--pmem-wrap-around=8k}\
603 %{mmcu=atmega16*:--pmem-wrap-around=16k}\
605 mmcu=at90can32*:--pmem-wrap-around=32k}\
608 mmcu=at90usb64*:--pmem-wrap-around=64k}}}\
609 %:device_to_arch(%{mmcu=*:%*})\
610 %:device_to_data_start(%{mmcu=*:%*})"
613 "%{!mmcu=at90s1*:%{!mmcu=attiny11:%{!mmcu=attiny12:%{!mmcu=attiny15:%{!mmcu=attiny28: -lc }}}}}"
615 #define LIBSTDCXX "gcc"
616 /* No libstdc++ for now. Empty string doesn't work. */
618 #define LIBGCC_SPEC \
619 "%{!mmcu=at90s1*:%{!mmcu=attiny11:%{!mmcu=attiny12:%{!mmcu=attiny15:%{!mmcu=attiny28: -lgcc }}}}}"
621 #define STARTFILE_SPEC "%:device_to_startfile(%{mmcu=*:%*})"
623 #define ENDFILE_SPEC ""
625 /* This is the default without any -mmcu=* option (AT90S*). */
626 #define MULTILIB_DEFAULTS { "mmcu=avr2" }
628 #define TEST_HARD_REG_CLASS(CLASS, REGNO) \
629 TEST_HARD_REG_BIT (reg_class_contents[ (int) (CLASS)], REGNO)
631 #define CR_TAB "\n\t"
633 #define DWARF2_ADDR_SIZE 4
635 #define INCOMING_RETURN_ADDR_RTX avr_incoming_return_addr_rtx ()
636 #define INCOMING_FRAME_SP_OFFSET (AVR_3_BYTE_PC ? 3 : 2)
638 /* The caller's stack pointer value immediately before the call
639 is one byte below the first argument. */
640 #define ARG_POINTER_CFA_OFFSET(FNDECL) -1
642 #define HARD_REGNO_RENAME_OK(OLD_REG, NEW_REG) \
643 avr_hard_regno_rename_ok (OLD_REG, NEW_REG)
645 /* A C structure for machine-specific, per-function data.
646 This is added to the cfun structure. */
647 struct GTY(()) machine_function
649 /* 'true' - if current function is a naked function. */
652 /* 'true' - if current function is an interrupt function
653 as specified by the "interrupt" attribute. */
656 /* 'true' - if current function is a signal function
657 as specified by the "signal" attribute. */
660 /* 'true' - if current function is a 'task' function
661 as specified by the "OS_task" attribute. */
664 /* 'true' - if current function is a 'main' function
665 as specified by the "OS_main" attribute. */
668 /* Current function stack size. */
671 /* 'true' if a callee might be tail called */
675 /* AVR does not round pushes, but the existance of this macro is
676 required in order for pushes to be generated. */
677 #define PUSH_ROUNDING(X) (X)
679 #define ACCUMULATE_OUTGOING_ARGS avr_accumulate_outgoing_args()
681 #define INIT_EXPANDERS avr_init_expanders()