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