]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | /* Copyright (C) 1998-2016 Free Software Foundation, Inc. |
c0d7a1d0 | 2 | Contributed by Joern Rennecke |
3 | ||
4 | This file is part of GCC. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
19 | ||
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | ||
fb51f994 | 24 | #include "config.h" |
25 | ||
c0d7a1d0 | 26 | #define IN_GEN_AVR_MMCU_TEXI |
27 | ||
c0d7a1d0 | 28 | #include "avr-devices.c" |
29 | ||
f0aa7fe2 | 30 | // Get rid of "defaults.h". We just need tm.h for `WITH_AVRLIBS' and |
31 | // and `WITH_RTEMS'. */ | |
2aa6267d | 32 | #define GCC_DEFAULTS_H |
33 | ||
34 | #include "tm.h" | |
35 | ||
f0aa7fe2 | 36 | // Mimic the include order as specified in config.gcc::tm_file. |
37 | ||
38 | #include "specs.h" | |
39 | ||
2aa6267d | 40 | #if defined (WITH_AVRLIBC) |
f0aa7fe2 | 41 | #include "avrlibc.h" |
42 | #endif | |
43 | ||
44 | #if defined (WITH_RTEMS) | |
45 | #include "../rtems.h" | |
46 | #include "rtems.h" | |
47 | #endif | |
2aa6267d | 48 | |
49 | ||
f0aa7fe2 | 50 | #define SPECFILE_DOC_URL \ |
4073a6d0 | 51 | "https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html" |
52 | ||
53 | #define SPECFILE_USAGE_URL \ | |
54 | "https://gcc.gnu.org/gcc-5/changes.html" | |
f0aa7fe2 | 55 | |
2aa6267d | 56 | /* Return true iff STR starts with PREFIX. */ |
57 | ||
58 | static bool | |
59 | str_prefix_p (const char *str, const char *prefix) | |
60 | { | |
61 | return 0 == strncmp (str, prefix, strlen (prefix)); | |
62 | } | |
63 | ||
64 | ||
f0aa7fe2 | 65 | static const char header[] = |
66 | "#\n" | |
67 | "# Generated by : ./gcc/config/avr/gen-avr-mmcu-specs.c\n" | |
68 | "# Generated from : ./gcc/config/gcc.c\n" | |
69 | "# ./gcc/config/avr/specs.h\n" | |
70 | #if defined (WITH_RTEMS) | |
71 | "# ./gcc/config/rtems.h\n" | |
72 | "# ./gcc/config/avr/rtems.h\n" | |
73 | #endif | |
74 | #if defined (WITH_AVRLIBC) | |
75 | "# ./gcc/config/avr/avrlibc.h\n" | |
76 | #endif | |
77 | "# Used by : avr-gcc compiler driver\n" | |
78 | "# Used for : building command options for sub-processes\n" | |
79 | "#\n" | |
80 | "# See <" SPECFILE_DOC_URL ">\n" | |
81 | "# for a documentation of spec files.\n" | |
82 | "\n"; | |
83 | ||
22e771f8 | 84 | static const char help_copy_paste[] = |
85 | "# If you intend to use an existing device specs file as a starting point\n" | |
86 | "# for a new device spec file, make sure you are copying from a specs\n" | |
4073a6d0 | 87 | "# file for a device from the same core architecture and SP width.\n" |
88 | "# See <" SPECFILE_USAGE_URL "> for a description\n" | |
89 | "# of how to use such own spec files.\n"; | |
22e771f8 | 90 | |
91 | #if defined (WITH_AVRLIBC) | |
92 | static const char help_dev_lib_name[] = | |
93 | "# AVR-LibC's avr/io.h uses the device specifying macro to determine\n" | |
94 | "# the name of the device header. For example, -mmcu=atmega8a triggers\n" | |
95 | "# the definition of __AVR_ATmega8A__ and avr/io.h includes the device\n" | |
96 | "# header 'iom8a.h' by means of:\n" | |
97 | "#\n" | |
98 | "# ...\n" | |
99 | "# #elif defined (__AVR_ATmega8A__)\n" | |
100 | "# # include <avr/iom8a.h>\n" | |
101 | "# #elif ...\n" | |
102 | "# \n" | |
103 | "# If no device macro is defined, AVR-LibC uses __AVR_DEV_LIB_NAME__\n" | |
104 | "# as fallback to determine the name of the device header as\n" | |
105 | "#\n" | |
106 | "# \"avr/io\" + __AVR_DEV_LIB_NAME__ + \".h\"\n" | |
107 | "#\n" | |
108 | "# If you provide your own specs file for a device not yet known to\n" | |
109 | "# AVR-LibC, you can now define the hook macro __AVR_DEV_LIB_NAME__\n" | |
110 | "# as needed so that\n" | |
111 | "#\n" | |
112 | "# #include <avr/io.h>\n" | |
113 | "#\n" | |
114 | "# will include the desired device header. For ATmega8A the supplement\n" | |
115 | "# to *cpp would read\n" | |
116 | "#\n" | |
117 | "# -D__AVR_DEV_LIB_NAME__=m8a\n" | |
118 | "\n"; | |
119 | #endif // WITH_AVRLIBC | |
f0aa7fe2 | 120 | |
c0d7a1d0 | 121 | static void |
122 | print_mcu (const avr_mcu_t *mcu) | |
123 | { | |
2aa6267d | 124 | const char *sp8_spec; |
c0d7a1d0 | 125 | const avr_mcu_t *arch_mcu; |
f0aa7fe2 | 126 | const avr_arch_t *arch; |
127 | enum avr_arch_id arch_id = mcu->arch_id; | |
c0d7a1d0 | 128 | |
129 | for (arch_mcu = mcu; arch_mcu->macro; ) | |
130 | arch_mcu--; | |
f0aa7fe2 | 131 | if (arch_mcu->arch_id != arch_id) |
c0d7a1d0 | 132 | exit (EXIT_FAILURE); |
133 | ||
f0aa7fe2 | 134 | arch = &avr_arch_types[arch_id]; |
135 | ||
c0d7a1d0 | 136 | char name[100]; |
2aa6267d | 137 | if (snprintf (name, sizeof name, "specs-%s", mcu->name) >= (int) sizeof name) |
c0d7a1d0 | 138 | exit (EXIT_FAILURE); |
139 | ||
140 | FILE *f = fopen (name ,"w"); | |
141 | ||
2aa6267d | 142 | bool errata_skip = 0 != (mcu->dev_attribute & AVR_ERRATA_SKIP); |
143 | bool rmw = 0 != (mcu->dev_attribute & AVR_ISA_RMW); | |
144 | bool sp8 = 0 != (mcu->dev_attribute & AVR_SHORT_SP); | |
f0aa7fe2 | 145 | bool is_arch = NULL == mcu->macro; |
146 | bool is_device = ! is_arch; | |
2aa6267d | 147 | |
f0aa7fe2 | 148 | if (is_arch |
149 | && (ARCH_AVR2 == arch_id | |
150 | || ARCH_AVR25 == arch_id)) | |
2aa6267d | 151 | { |
152 | // Leave "avr2" and "avr25" alone. These two architectures are | |
153 | // the only ones that mix devices with 8-bit SP and 16-bit SP. | |
154 | sp8_spec = ""; | |
155 | } | |
156 | else | |
157 | { | |
f0aa7fe2 | 158 | sp8_spec = sp8 ? "-msp8" :"%<msp8"; |
2aa6267d | 159 | } |
c0d7a1d0 | 160 | |
f0aa7fe2 | 161 | fprintf (f, "#\n" |
162 | "# Auto-generated specs for AVR "); | |
163 | if (is_arch) | |
164 | fprintf (f, "core architecture %s\n", arch->name); | |
165 | else | |
166 | fprintf (f, "device %s (core %s, %d-bit SP)\n", | |
167 | mcu->name, arch->name, sp8 ? 8 : 16); | |
168 | fprintf (f, "%s\n", header); | |
169 | ||
f0aa7fe2 | 170 | if (is_device) |
22e771f8 | 171 | fprintf (f, "%s\n", help_copy_paste); |
172 | ||
173 | #if defined (WITH_AVRLIBC) | |
174 | // AVR-LibC specific. See avrlibc.h for the specs using them as subspecs. | |
c0d7a1d0 | 175 | |
f0aa7fe2 | 176 | if (is_device) |
22e771f8 | 177 | { |
178 | fprintf (f, "*avrlibc_startfile:\n"); | |
719eb899 | 179 | fprintf (f, "\tcrt%s.o%%s", mcu->name); |
22e771f8 | 180 | fprintf (f, "\n\n"); |
181 | ||
182 | fprintf (f, "*avrlibc_devicelib:\n"); | |
719eb899 | 183 | fprintf (f, "\t%%{!nodevicelib:-l%s}", mcu->name); |
22e771f8 | 184 | fprintf (f, "\n\n"); |
185 | } | |
186 | #endif // WITH_AVRLIBC | |
c0d7a1d0 | 187 | |
22e771f8 | 188 | // avr-gcc specific specs for the compilation / the compiler proper. |
c0d7a1d0 | 189 | |
f0aa7fe2 | 190 | fprintf (f, "*cc1_n_flash:\n" |
191 | "\t%%{!mn-flash=*:-mn-flash=%d}\n\n", mcu->n_flash); | |
192 | ||
193 | fprintf (f, "*cc1_rmw:\n%s\n\n", rmw | |
194 | ? "\t%{!mno-rmw: -mrmw}" | |
195 | : "\t%{mrmw}"); | |
196 | ||
197 | fprintf (f, "*cc1_errata_skip:\n%s\n\n", errata_skip | |
198 | ? "\t%{!mno-skip-bug: -mskip-bug}" | |
199 | : "\t%{!mskip-bug: -mno-skip-bug}"); | |
200 | ||
22e771f8 | 201 | // avr-gcc specific specs for assembling / the assembler. |
f0aa7fe2 | 202 | |
203 | fprintf (f, "*asm_arch:\n\t-mmcu=%s\n\n", arch->name); | |
204 | ||
fb51f994 | 205 | #ifdef HAVE_AS_AVR_MLINK_RELAX_OPTION |
f0aa7fe2 | 206 | fprintf (f, "*asm_relax:\n\t%s\n\n", ASM_RELAX_SPEC); |
22e771f8 | 207 | #endif // have avr-as --mlink-relax |
c0d7a1d0 | 208 | |
fb51f994 | 209 | #ifdef HAVE_AS_AVR_MRMW_OPTION |
f0aa7fe2 | 210 | fprintf (f, "*asm_rmw:\n%s\n\n", rmw |
211 | ? "\t%{!mno-rmw: -mrmw}" | |
212 | : "\t%{mrmw}"); | |
22e771f8 | 213 | #endif // have avr-as -mrmw |
f0aa7fe2 | 214 | |
215 | fprintf (f, "*asm_errata_skip:\n%s\n\n", errata_skip | |
216 | ? "\t%{mno-skip-bug}" | |
217 | : "\t%{!mskip-bug: -mno-skip-bug}"); | |
218 | ||
219 | // avr-specific specs for linking / the linker. | |
220 | ||
221 | int wrap_k = | |
222 | str_prefix_p (mcu->name, "at90usb8") ? 8 | |
223 | : str_prefix_p (mcu->name, "atmega16") ? 16 | |
224 | : (str_prefix_p (mcu->name, "atmega32") | |
225 | || str_prefix_p (mcu->name, "at90can32")) ? 32 | |
226 | : (str_prefix_p (mcu->name, "atmega64") | |
227 | || str_prefix_p (mcu->name, "at90can64") | |
228 | || str_prefix_p (mcu->name, "at90usb64")) ? 64 | |
229 | : 0; | |
230 | ||
231 | fprintf (f, "*link_pmem_wrap:\n"); | |
232 | if (wrap_k) | |
233 | fprintf (f, "\t%%{mpmem-wrap-around: --pmem-wrap-around=%dk}", wrap_k); | |
c0d7a1d0 | 234 | fprintf (f, "\n\n"); |
2aa6267d | 235 | |
f0aa7fe2 | 236 | fprintf (f, "*link_relax:\n\t%s\n\n", LINK_RELAX_SPEC); |
237 | ||
238 | fprintf (f, "*link_arch:\n\t%s\n\n", LINK_ARCH_SPEC); | |
2aa6267d | 239 | |
f0aa7fe2 | 240 | if (is_device) |
22e771f8 | 241 | { |
242 | fprintf (f, "*link_data_start:\n"); | |
243 | if (mcu->data_section_start | |
244 | != arch->default_data_section_start) | |
245 | fprintf (f, "\t-Tdata 0x%lX", 0x800000UL + mcu->data_section_start); | |
246 | fprintf (f, "\n\n"); | |
247 | ||
248 | fprintf (f, "*link_text_start:\n"); | |
249 | if (mcu->text_section_start != 0x0) | |
250 | fprintf (f, "\t-Ttext 0x%lX", 0UL + mcu->text_section_start); | |
251 | fprintf (f, "\n\n"); | |
252 | } | |
f0aa7fe2 | 253 | |
22e771f8 | 254 | // Specs known to GCC. |
f0aa7fe2 | 255 | |
22e771f8 | 256 | if (is_device) |
257 | { | |
258 | fprintf (f, "*self_spec:\n"); | |
259 | fprintf (f, "\t%%{!mmcu=avr*: %%<mmcu=* -mmcu=%s} ", arch->name); | |
260 | fprintf (f, "%s\n\n", sp8_spec); | |
f0aa7fe2 | 261 | |
22e771f8 | 262 | #if defined (WITH_AVRLIBC) |
263 | fprintf (f, "%s\n", help_dev_lib_name); | |
264 | #endif // WITH_AVRLIBC | |
f0aa7fe2 | 265 | |
22e771f8 | 266 | fprintf (f, "*cpp:\n"); |
267 | fprintf (f, "\t-D%s -D__AVR_DEVICE_NAME__=%s", mcu->macro, mcu->name); | |
268 | fprintf (f, "\n\n"); | |
269 | } | |
c0d7a1d0 | 270 | |
f0aa7fe2 | 271 | fprintf (f, "# End of file\n"); |
4073a6d0 | 272 | |
273 | fclose (f); | |
c0d7a1d0 | 274 | } |
275 | ||
2aa6267d | 276 | |
c0d7a1d0 | 277 | int main (void) |
278 | { | |
2aa6267d | 279 | for (const avr_mcu_t *mcu = avr_mcu_types; mcu->name; mcu++) |
c0d7a1d0 | 280 | print_mcu (mcu); |
281 | ||
282 | return EXIT_SUCCESS; | |
283 | } |