1 /* Copyright (C) 1998-2017 Free Software Foundation, Inc.
2 Contributed by Joern Rennecke
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
24 #define IN_TARGET_CODE 1
28 #define IN_GEN_AVR_MMCU_TEXI
30 #include "avr-devices.c"
32 // Get rid of "defaults.h". We just need tm.h for `WITH_AVRLIBC' and
33 // and `WITH_RTEMS'. */
34 #define GCC_DEFAULTS_H
38 // Mimic the include order as specified in config.gcc::tm_file.
42 #if defined (WITH_AVRLIBC)
47 #define SPECFILE_DOC_URL \
48 "https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html"
50 #define SPECFILE_USAGE_URL \
51 "https://gcc.gnu.org/gcc-5/changes.html"
53 /* Return true iff STR starts with PREFIX. */
56 str_prefix_p (const char *str
, const char *prefix
)
58 return strncmp (str
, prefix
, strlen (prefix
)) == 0;
62 static const char header
[] =
64 "# Generated by : ./gcc/config/avr/gen-avr-mmcu-specs.c\n"
65 "# Generated from : ./gcc/config/gcc.c\n"
66 "# ./gcc/config/avr/specs.h\n"
67 #if defined (WITH_AVRLIBC)
68 "# ./gcc/config/avr/avrlibc.h\n"
70 "# Used by : avr-gcc compiler driver\n"
71 "# Used for : building command options for sub-processes\n"
73 "# See <" SPECFILE_DOC_URL
">\n"
74 "# for a documentation of spec files.\n"
77 static const char help_copy_paste
[] =
78 "# If you intend to use an existing device specs file as a starting point\n"
79 "# for a new device spec file, make sure you are copying from a specs\n"
80 "# file for a device from the same core architecture and SP width.\n"
81 "# See <" SPECFILE_USAGE_URL
"> for a description\n"
82 "# of how to use such own spec files.\n";
84 #if defined (WITH_AVRLIBC)
85 static const char help_dev_lib_name
[] =
86 "# AVR-LibC's avr/io.h uses the device specifying macro to determine\n"
87 "# the name of the device header. For example, -mmcu=atmega8a triggers\n"
88 "# the definition of __AVR_ATmega8A__ and avr/io.h includes the device\n"
89 "# header 'iom8a.h' by means of:\n"
92 "# #elif defined (__AVR_ATmega8A__)\n"
93 "# # include <avr/iom8a.h>\n"
96 "# If no device macro is defined, AVR-LibC uses __AVR_DEV_LIB_NAME__\n"
97 "# as fallback to determine the name of the device header as\n"
99 "# \"avr/io\" + __AVR_DEV_LIB_NAME__ + \".h\"\n"
101 "# If you provide your own specs file for a device not yet known to\n"
102 "# AVR-LibC, you can now define the hook macro __AVR_DEV_LIB_NAME__\n"
103 "# as needed so that\n"
105 "# #include <avr/io.h>\n"
107 "# will include the desired device header. For ATmega8A the supplement\n"
108 "# to *cpp would read\n"
110 "# -D__AVR_DEV_LIB_NAME__=m8a\n"
112 #endif // WITH_AVRLIBC
115 print_mcu (const avr_mcu_t
*mcu
)
117 const char *sp8_spec
;
118 const char *rcall_spec
;
119 const avr_mcu_t
*arch_mcu
;
120 const avr_arch_t
*arch
;
121 enum avr_arch_id arch_id
= mcu
->arch_id
;
123 for (arch_mcu
= mcu
; arch_mcu
->macro
; )
125 if (arch_mcu
->arch_id
!= arch_id
)
128 arch
= &avr_arch_types
[arch_id
];
131 if (snprintf (name
, sizeof name
, "specs-%s", mcu
->name
) >= (int) sizeof name
)
134 FILE *f
= fopen (name
,"w");
136 bool absdata
= (mcu
->dev_attribute
& AVR_ISA_LDS
) != 0;
137 bool errata_skip
= (mcu
->dev_attribute
& AVR_ERRATA_SKIP
) != 0;
138 bool rmw
= (mcu
->dev_attribute
& AVR_ISA_RMW
) != 0;
139 bool sp8
= (mcu
->dev_attribute
& AVR_SHORT_SP
) != 0;
140 bool rcall
= (mcu
->dev_attribute
& AVR_ISA_RCALL
);
141 bool is_arch
= mcu
->macro
== NULL
;
142 bool is_device
= ! is_arch
;
145 && (ARCH_AVR2
== arch_id
146 || ARCH_AVR25
== arch_id
))
148 // Leave "avr2" and "avr25" alone. These two architectures are
149 // the only ones that mix devices with 8-bit SP and 16-bit SP.
154 sp8_spec
= sp8
? "-msp8" :"%<msp8";
158 && ARCH_AVRXMEGA3
== arch_id
)
160 // Leave "avrxmega3" alone. This architectures is the only one
161 // that mixes devices with and without JMP / CALL.
166 rcall_spec
= rcall
? "-mshort-calls" : "%<mshort-calls";
170 "# Auto-generated specs for AVR ");
172 fprintf (f
, "core architecture %s\n", arch
->name
);
174 fprintf (f
, "device %s (core %s, %d-bit SP%s)\n", mcu
->name
,
175 arch
->name
, sp8
? 8 : 16, rcall
? ", short-calls" : "");
176 fprintf (f
, "%s\n", header
);
179 fprintf (f
, "%s\n", help_copy_paste
);
181 #if defined (WITH_AVRLIBC)
182 // AVR-LibC specific. See avrlibc.h for the specs using them as subspecs.
186 fprintf (f
, "*avrlibc_startfile:\n");
187 fprintf (f
, "\tcrt%s.o%%s", mcu
->name
);
190 fprintf (f
, "*avrlibc_devicelib:\n");
191 fprintf (f
, "\t%%{!nodevicelib:-l%s}", mcu
->name
);
194 #endif // WITH_AVRLIBC
196 // avr-gcc specific specs for the compilation / the compiler proper.
198 int n_flash
= 1 + (mcu
->flash_size
- 1) / 0x10000;
200 fprintf (f
, "*cc1_n_flash:\n"
201 "\t%%{!mn-flash=*:-mn-flash=%d}\n\n", n_flash
);
203 fprintf (f
, "*cc1_rmw:\n%s\n\n", rmw
204 ? "\t%{!mno-rmw: -mrmw}"
207 fprintf (f
, "*cc1_errata_skip:\n%s\n\n", errata_skip
208 ? "\t%{!mno-skip-bug: -mskip-bug}"
209 : "\t%{!mskip-bug: -mno-skip-bug}");
211 fprintf (f
, "*cc1_absdata:\n%s\n\n", absdata
212 ? "\t%{!mno-absdata: -mabsdata}"
215 // avr-gcc specific specs for assembling / the assembler.
217 fprintf (f
, "*asm_arch:\n\t-mmcu=%s\n\n", arch
->name
);
219 #ifdef HAVE_AS_AVR_MLINK_RELAX_OPTION
220 fprintf (f
, "*asm_relax:\n\t%s\n\n", ASM_RELAX_SPEC
);
221 #endif // have avr-as --mlink-relax
223 #ifdef HAVE_AS_AVR_MRMW_OPTION
224 fprintf (f
, "*asm_rmw:\n%s\n\n", rmw
225 ? "\t%{!mno-rmw: -mrmw}"
227 #endif // have avr-as -mrmw
229 #ifdef HAVE_AS_AVR_MGCCISR_OPTION
230 fprintf (f
, "*asm_gccisr:\n%s\n\n",
231 "\t%{!mno-gas-isr-prologues: -mgcc-isr}");
232 #endif // have avr-as -mgcc-isr
234 fprintf (f
, "*asm_errata_skip:\n%s\n\n", errata_skip
235 ? "\t%{mno-skip-bug}"
236 : "\t%{!mskip-bug: -mno-skip-bug}");
238 // avr-specific specs for linking / the linker.
241 mcu
->flash_size
== 0x2000 ? 8
242 : mcu
->flash_size
== 0x4000 ? 16
243 : mcu
->flash_size
== 0x8000 ? 32
244 : mcu
->flash_size
== 0x10000 ? 64
247 fprintf (f
, "*link_pmem_wrap:\n");
249 fprintf (f
, "\t%%{!mno-pmem-wrap-around: --pmem-wrap-around=8k}");
251 fprintf (f
, "\t%%{mpmem-wrap-around: --pmem-wrap-around=%dk}", wrap_k
);
254 fprintf (f
, "*link_relax:\n\t%s\n\n", LINK_RELAX_SPEC
);
256 fprintf (f
, "*link_arch:\n\t%s\n\n", LINK_ARCH_SPEC
);
260 fprintf (f
, "*link_data_start:\n");
261 if (mcu
->data_section_start
262 != arch
->default_data_section_start
)
263 fprintf (f
, "\t%%{!Tdata:-Tdata 0x%lX}",
264 0x800000UL
+ mcu
->data_section_start
);
267 fprintf (f
, "*link_text_start:\n");
268 if (mcu
->text_section_start
!= 0x0)
269 fprintf (f
, "\t%%{!Ttext:-Ttext 0x%lX}", 0UL + mcu
->text_section_start
);
273 // Specs known to GCC.
277 fprintf (f
, "*self_spec:\n");
278 fprintf (f
, "\t%%{!mmcu=avr*: %%<mmcu=* -mmcu=%s} ", arch
->name
);
279 fprintf (f
, "%s ", rcall_spec
);
280 fprintf (f
, "%s\n\n", sp8_spec
);
282 #if defined (WITH_AVRLIBC)
283 fprintf (f
, "%s\n", help_dev_lib_name
);
284 #endif // WITH_AVRLIBC
286 fprintf (f
, "*cpp:\n");
287 fprintf (f
, "\t-D%s -D__AVR_DEVICE_NAME__=%s", mcu
->macro
, mcu
->name
);
291 fprintf (f
, "# End of file\n");
299 for (const avr_mcu_t
*mcu
= avr_mcu_types
; mcu
->name
; mcu
++)