1 /* Copyright (C) 2009, 2010, 2011, 2012
2 Free Software Foundation, Inc.
3 Contributed by Anatoly Sokolov (aesok@post.ru)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Not included in avr.c since this requires C front end. */
25 #include "coretypes.h"
30 #include "c-family/c-common.h"
31 #include "langhooks.h"
34 /* Implement `REGISTER_TARGET_PRAGMAS'. */
37 avr_register_target_pragmas (void)
41 gcc_assert (ADDR_SPACE_GENERIC
== ADDR_SPACE_RAM
);
43 /* Register address spaces. The order must be the same as in the respective
44 enum from avr.h (or designated initialized must be used in avr.c). */
46 for (i
= 0; i
< ADDR_SPACE_COUNT
; i
++)
48 gcc_assert (i
== avr_addrspace
[i
].id
);
50 if (!ADDR_SPACE_GENERIC_P (i
))
51 c_register_addr_space (avr_addrspace
[i
].name
, avr_addrspace
[i
].id
);
56 /* Transorm LO into uppercase and write the result to UP.
57 You must provide enough space for UP. Return UP. */
60 avr_toupper (char *up
, const char *lo
)
64 for (; *lo
; lo
++, up
++)
72 /* Worker function for TARGET_CPU_CPP_BUILTINS. */
74 static const char *const avr_builtin_name
[] =
76 #define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) NAME,
77 #include "builtins.def"
83 avr_cpu_cpp_builtins (struct cpp_reader
*pfile
)
87 builtin_define_std ("AVR");
89 if (avr_current_arch
->macro
)
90 cpp_define_formatted (pfile
, "__AVR_ARCH__=%s", avr_current_arch
->macro
);
91 if (avr_current_device
->macro
)
92 cpp_define (pfile
, avr_current_device
->macro
);
93 if (AVR_HAVE_RAMPD
) cpp_define (pfile
, "__AVR_HAVE_RAMPD__");
94 if (AVR_HAVE_RAMPX
) cpp_define (pfile
, "__AVR_HAVE_RAMPX__");
95 if (AVR_HAVE_RAMPY
) cpp_define (pfile
, "__AVR_HAVE_RAMPY__");
96 if (AVR_HAVE_RAMPZ
) cpp_define (pfile
, "__AVR_HAVE_RAMPZ__");
97 if (AVR_HAVE_ELPM
) cpp_define (pfile
, "__AVR_HAVE_ELPM__");
98 if (AVR_HAVE_ELPMX
) cpp_define (pfile
, "__AVR_HAVE_ELPMX__");
99 if (AVR_HAVE_MOVW
) cpp_define (pfile
, "__AVR_HAVE_MOVW__");
100 if (AVR_HAVE_LPMX
) cpp_define (pfile
, "__AVR_HAVE_LPMX__");
102 if (avr_current_arch
->asm_only
)
103 cpp_define (pfile
, "__AVR_ASM_ONLY__");
106 cpp_define (pfile
, "__AVR_ENHANCED__");
107 cpp_define (pfile
, "__AVR_HAVE_MUL__");
109 if (avr_current_arch
->have_jmp_call
)
111 cpp_define (pfile
, "__AVR_MEGA__");
112 cpp_define (pfile
, "__AVR_HAVE_JMP_CALL__");
115 cpp_define (pfile
, "__AVR_XMEGA__");
116 if (avr_current_arch
->have_eijmp_eicall
)
118 cpp_define (pfile
, "__AVR_HAVE_EIJMP_EICALL__");
119 cpp_define (pfile
, "__AVR_3_BYTE_PC__");
123 cpp_define (pfile
, "__AVR_2_BYTE_PC__");
126 if (AVR_HAVE_8BIT_SP
)
127 cpp_define (pfile
, "__AVR_HAVE_8BIT_SP__");
129 cpp_define (pfile
, "__AVR_HAVE_16BIT_SP__");
132 cpp_define (pfile
, "__AVR_SP8__");
135 cpp_define (pfile
, "__AVR_HAVE_SPH__");
137 if (TARGET_NO_INTERRUPTS
)
138 cpp_define (pfile
, "__NO_INTERRUPTS__");
140 if (avr_current_device
->errata_skip
)
142 cpp_define (pfile
, "__AVR_ERRATA_SKIP__");
144 if (avr_current_arch
->have_jmp_call
)
145 cpp_define (pfile
, "__AVR_ERRATA_SKIP_JMP_CALL__");
148 cpp_define_formatted (pfile
, "__AVR_SFR_OFFSET__=0x%x",
149 avr_current_arch
->sfr_offset
);
152 cpp_define (pfile
, "__WITH_AVRLIBC__");
153 #endif /* WITH_AVRLIBC */
155 /* Define builtin macros so that the user can easily query if or if not
156 non-generic address spaces (and which) are supported.
157 This is only supported for C. For C++, a language extension is needed
158 (as mentioned in ISO/IEC DTR 18037; Annex F.2) which is not
159 implemented in GCC up to now. */
161 if (!strcmp (lang_hooks
.name
, "GNU C"))
163 for (i
= 0; i
< ADDR_SPACE_COUNT
; i
++)
164 if (!ADDR_SPACE_GENERIC_P (i
)
165 /* Only supply __FLASH<n> macro if the address space is reasonable
166 for this target. The address space qualifier itself is still
167 supported, but using it will throw an error. */
168 && avr_addrspace
[i
].segment
< avr_current_device
->n_flash
)
170 const char *name
= avr_addrspace
[i
].name
;
171 char *Name
= (char*) alloca (1 + strlen (name
));
173 cpp_define_formatted (pfile
, "%s=%s",
174 avr_toupper (Name
, name
), name
);
178 /* Define builtin macros so that the user can easily query if or
179 if not a specific builtin is available. */
181 for (i
= 0; avr_builtin_name
[i
]; i
++)
183 const char *name
= avr_builtin_name
[i
];
184 char *Name
= (char*) alloca (1 + strlen (name
));
186 cpp_define (pfile
, avr_toupper (Name
, name
));
189 /* Builtin macros for the __int24 and __uint24 type. */
191 cpp_define (pfile
, "__INT24_MAX__=8388607L");
192 cpp_define (pfile
, "__INT24_MIN__=(-__INT24_MAX__-1)");
193 cpp_define (pfile
, "__UINT24_MAX__=16777215UL");