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