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