qimode_for_vec_perm
[official-gcc.git] / gcc / config / avr / gen-avr-mmcu-specs.c
blob08ef1664716fafa411deb23feb6ed6c0ed405f31
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)
9 any later version.
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/>. */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
24 #define IN_TARGET_CODE 1
26 #include "config.h"
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
36 #include "tm.h"
38 // Mimic the include order as specified in config.gcc::tm_file.
40 #include "specs.h"
42 #if defined (WITH_AVRLIBC)
43 #include "avrlibc.h"
44 #endif
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. */
55 static bool
56 str_prefix_p (const char *str, const char *prefix)
58 return strncmp (str, prefix, strlen (prefix)) == 0;
62 static const char header[] =
63 "#\n"
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"
69 #endif
70 "# Used by : avr-gcc compiler driver\n"
71 "# Used for : building command options for sub-processes\n"
72 "#\n"
73 "# See <" SPECFILE_DOC_URL ">\n"
74 "# for a documentation of spec files.\n"
75 "\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"
90 "#\n"
91 "# ...\n"
92 "# #elif defined (__AVR_ATmega8A__)\n"
93 "# # include <avr/iom8a.h>\n"
94 "# #elif ...\n"
95 "# \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"
98 "#\n"
99 "# \"avr/io\" + __AVR_DEV_LIB_NAME__ + \".h\"\n"
100 "#\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"
104 "#\n"
105 "# #include <avr/io.h>\n"
106 "#\n"
107 "# will include the desired device header. For ATmega8A the supplement\n"
108 "# to *cpp would read\n"
109 "#\n"
110 "# -D__AVR_DEV_LIB_NAME__=m8a\n"
111 "\n";
112 #endif // WITH_AVRLIBC
114 static void
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; )
124 arch_mcu--;
125 if (arch_mcu->arch_id != arch_id)
126 exit (EXIT_FAILURE);
128 arch = &avr_arch_types[arch_id];
130 char name[100];
131 if (snprintf (name, sizeof name, "specs-%s", mcu->name) >= (int) sizeof name)
132 exit (EXIT_FAILURE);
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;
144 if (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.
150 sp8_spec = "";
152 else
154 sp8_spec = sp8 ? "-msp8" :"%<msp8";
157 if (is_arch
158 && ARCH_AVRXMEGA3 == arch_id)
160 // Leave "avrxmega3" alone. This architectures is the only one
161 // that mixes devices with and without JMP / CALL.
162 rcall_spec = "";
164 else
166 rcall_spec = rcall ? "-mshort-calls" : "%<mshort-calls";
169 fprintf (f, "#\n"
170 "# Auto-generated specs for AVR ");
171 if (is_arch)
172 fprintf (f, "core architecture %s\n", arch->name);
173 else
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);
178 if (is_device)
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.
184 if (is_device)
186 fprintf (f, "*avrlibc_startfile:\n");
187 fprintf (f, "\tcrt%s.o%%s", mcu->name);
188 fprintf (f, "\n\n");
190 fprintf (f, "*avrlibc_devicelib:\n");
191 fprintf (f, "\t%%{!nodevicelib:-l%s}", mcu->name);
192 fprintf (f, "\n\n");
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}"
205 : "\t%{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}"
213 : "\t%{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}"
226 : "\t%{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.
240 int wrap_k =
241 mcu->flash_size == 0x2000 ? 8
242 : mcu->flash_size == 0x4000 ? 16
243 : mcu->flash_size == 0x8000 ? 32
244 : mcu->flash_size == 0x10000 ? 64
245 : 0;
247 fprintf (f, "*link_pmem_wrap:\n");
248 if (wrap_k == 8)
249 fprintf (f, "\t%%{!mno-pmem-wrap-around: --pmem-wrap-around=8k}");
250 else if (wrap_k > 8)
251 fprintf (f, "\t%%{mpmem-wrap-around: --pmem-wrap-around=%dk}", wrap_k);
252 fprintf (f, "\n\n");
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);
258 if (is_device)
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);
265 fprintf (f, "\n\n");
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);
270 fprintf (f, "\n\n");
273 // Specs known to GCC.
275 if (is_device)
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);
288 fprintf (f, "\n\n");
291 fprintf (f, "# End of file\n");
293 fclose (f);
297 int main (void)
299 for (const avr_mcu_t *mcu = avr_mcu_types; mcu->name; mcu++)
300 print_mcu (mcu);
302 return EXIT_SUCCESS;