#include "avr-arch.h"
#include "avr-devices.c"
+#define GCC_DEFAULTS_H
+
+#include "tm.h"
+
+#if defined (WITH_AVRLIBC)
+static const bool with_avrlibc = true;
+#else
+static const bool with_avrlibc = false;
+#endif /* WITH_AVRLIBC */
+
+
+/* Return true iff STR starts with PREFIX. */
+
+static bool
+str_prefix_p (const char *str, const char *prefix)
+{
+ return 0 == strncmp (str, prefix, strlen (prefix));
+}
+
+
static void
print_mcu (const avr_mcu_t *mcu)
{
+ const char *sp8_spec;
const avr_mcu_t *arch_mcu;
for (arch_mcu = mcu; arch_mcu->macro; )
exit (EXIT_FAILURE);
char name[100];
- if (snprintf (name, sizeof name, "specs-%s", mcu->name) >= sizeof name)
+ if (snprintf (name, sizeof name, "specs-%s", mcu->name) >= (int) sizeof name)
exit (EXIT_FAILURE);
FILE *f = fopen (name ,"w");
- const char *sp8, *errata_skip, *rmw;
- /* Leave "avr2" and "avr25" alone. These two architectures are
- the only ones that mix devices with 8-bit SP and 16-bit SP. */
+ bool errata_skip = 0 != (mcu->dev_attribute & AVR_ERRATA_SKIP);
+ bool rmw = 0 != (mcu->dev_attribute & AVR_ISA_RMW);
+ bool sp8 = 0 != (mcu->dev_attribute & AVR_SHORT_SP);
+
if (mcu->macro == NULL
&& (mcu->arch == ARCH_AVR2 || mcu->arch == ARCH_AVR25))
- sp8 = "";
+ {
+ // 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";
+ }
- sp8 = ((mcu->dev_attribute & AVR_SHORT_SP)
- ? " -msp8" : " %<msp8");
+ const char *errata_skip_spec = errata_skip
+ ? " %{!mno-skip-bug:-mskip-bug}"
+ : " %{!mskip-bug:-mno-skip-bug}";
- errata_skip = (mcu->dev_attribute & AVR_ERRATA_SKIP) ? " -mskip-bug" : "";
- rmw = (mcu->dev_attribute & AVR_ISA_RMW) ? "%{!mno-rmw: -mrmw}" : "";
+ const char *rmw_spec = rmw
+ ? " %{!mno-rmw: -mrmw}"
+ : " %{mrmw}";
const char *arch_name = avr_arch_types[mcu->arch].arch_name;
- fprintf (f, "*self_spec:\n%%{!march=*:-march=%s}%s\n\n", arch_name, sp8);
+ fprintf (f, "*self_spec:\n"
+ " %%{!march=*:-march=%s}"
+ " %s\n\n", arch_name, sp8_spec);
if (mcu->macro)
fprintf (f, "*cpp:\n-D__AVR_DEV_LIB_NAME__=%s -D%s "
"-D__AVR_DEVICE_NAME__=%s\n\n",
mcu->library_name, mcu->macro, mcu->name);
- fprintf (f, "*cc1:\n%s%s", errata_skip, rmw);
+ fprintf (f, "*cc1:\n%s%s", errata_skip_spec, rmw_spec);
if (mcu->n_flash != arch_mcu->n_flash)
fprintf (f, " %%{!mn-flash:-mn-flash=%d}", mcu->n_flash);
fprintf (f, "\n\n");
- fprintf (f, "*cc1plus:\n%s%s ", errata_skip, rmw);
+
+ fprintf (f, "*cc1plus:\n%s%s ", errata_skip_spec, rmw_spec);
if (mcu->n_flash != arch_mcu->n_flash)
- fprintf (f, "%%{!mn-flash:-mn-flash=%d}", mcu->n_flash);
- fprintf (f, "%%{!frtti: -fno-rtti}"
- "%%{!fenforce-eh-specs: -fno-enforce-eh-specs}"
- "%%{!fexceptions: -fno-exceptions}\n\n");
-
- fprintf (f, "*asm:\n%%{march=*:-mmcu=%%*}%{mrelax: --mlink-relax}%s\n\n",
- *errata_skip ? "" : " -mno-skip-bug");
-
- fprintf (f, "*link:\n%%{mrelax:--relax");
- if (strncmp (mcu->name, "at90usb8", strlen ("at90usb8")) == 0)
- fprintf (f, "%%{mpmem-wrap-around: --pmem-wrap-around=8k}");
- if (strncmp (mcu->name, "atmega16", strlen ("atmega16")) == 0)
- fprintf (f, "%%{mpmem-wrap-around: --pmem-wrap-around=16k}");
- if (strncmp (mcu->name, "atmega32", strlen ("atmega32")) == 0
- || strncmp (mcu->name, "at90can32", strlen ("at90can32")) == 0)
- fprintf (f, "%%{mpmem-wrap-around: --pmem-wrap-around=32k}");
- if (strncmp (mcu->name, "atmega64", strlen ("atmega64")) == 0
- || strncmp (mcu->name, "at90can64", strlen ("at90can64")) == 0
- || strncmp (mcu->name, "at90usb64", strlen ("at90usb64")) == 0)
- fprintf (f, "%%{mpmem-wrap-around: --pmem-wrap-around=64k}");
- fprintf (f, "} %%{march=*:-m%%*}");
+ fprintf (f, " %%{!mn-flash:-mn-flash=%d}", mcu->n_flash);
+ fprintf (f, (" %%{!frtti: -fno-rtti}"
+ " %%{!fenforce-eh-specs: -fno-enforce-eh-specs}"
+ " %%{!fexceptions: -fno-exceptions}\n\n"));
+
+ fprintf (f, "*asm:\n"
+ " %%{march=*:-mmcu=%%*}"
+ " %%{mrelax: --mlink-relax}"
+ " %s%s\n\n", rmw_spec, (errata_skip
+ ? " %{mno-skip-bug}"
+ : " %{!mskip-bug:-mno-skip-bug}"));
+ fprintf (f, "*link:\n"
+ " %%{mrelax:--relax");
+ {
+ int wrap_k =
+ str_prefix_p (mcu->name, "at90usb8") ? 8
+ : str_prefix_p (mcu->name, "atmega16") ? 16
+ : (str_prefix_p (mcu->name, "atmega32")
+ || str_prefix_p (mcu->name, "at90can32")) ? 32
+ : (str_prefix_p (mcu->name, "atmega64")
+ || str_prefix_p (mcu->name, "at90can64")
+ || str_prefix_p (mcu->name, "at90usb64")) ? 64
+ : 0;
+
+ if (wrap_k)
+ fprintf (f, " %%{mpmem-wrap-around: --pmem-wrap-around=%dk}", wrap_k);
+ }
+ fprintf (f, "}"
+ " %%{march=*:-m%%*}");
+
if (mcu->data_section_start
!= avr_arch_types[mcu->arch].default_data_section_start)
fprintf (f, " -Tdata 0x%lX", 0x800000UL + mcu->data_section_start);
+
if (mcu->text_section_start != 0x0)
- fprintf (f, " -Ttext 0x%lX", mcu->text_section_start);
+ fprintf (f, " -Ttext 0x%lX", 0UL + mcu->text_section_start);
fprintf (f, " %%{shared:%%eshared is not supported}\n\n");
+ bool has_libs = mcu->arch != ARCH_AVR1;
+
fprintf (f, "*lib:\n");
- if (strncmp (mcu->name, "mmcu=at90s1", strlen ("mmcu=at90s1")) != 0
- && strncmp (mcu->name, "mmcu=attiny11", strlen ("mmcu=attiny11")) != 0
- && strncmp (mcu->name, "mmcu=attiny12", strlen ("mmcu=attiny12")) != 0
- && strncmp (mcu->name, "mmcu=attiny15", strlen ("mmcu=attiny15")) != 0
- && strncmp (mcu->name, "mmcu=attiny28", strlen ("mmcu=attiny28")) != 0)
+ if (has_libs)
{
fprintf (f, "-lc");
- if (mcu->macro)
+ if (with_avrlibc
+ && mcu->macro)
fprintf (f, " dev/%s/libdev.a%%s", mcu->name);
}
fprintf (f, "\n\n");
fprintf (f, "*libgcc:\n");
- if (strncmp (mcu->name, "mmcu=at90s1", strlen ("mmcu=at90s1")) != 0
- && strncmp (mcu->name, "mmcu=attiny11", strlen ("mmcu=attiny11")) != 0
- && strncmp (mcu->name, "mmcu=attiny12", strlen ("mmcu=attiny12")) != 0
- && strncmp (mcu->name, "mmcu=attiny15", strlen ("mmcu=attiny15")) != 0
- && strncmp (mcu->name, "mmcu=attiny28", strlen ("mmcu=attiny28")) != 0)
- fprintf (f, "-lgcc");
+ if (has_libs)
+ fprintf (f, with_avrlibc
+ ? "-lgcc -lm"
+ : "-lgcc");
fprintf (f, "\n\n");
- fprintf (f, "*startfile:\ndev/%s/crt1.o%%s\n\n", mcu->name);
+ fprintf (f, "*startfile:\n"
+ "dev/%s/crt1.o%%s\n\n", mcu->name);
}
+
int main (void)
{
- enum avr_arch arch = ARCH_UNKNOWN;
- size_t i, n_mcus = 0;
- const avr_mcu_t *mcu;
-
- for (mcu = avr_mcu_types; mcu->name; mcu++)
+ for (const avr_mcu_t *mcu = avr_mcu_types; mcu->name; mcu++)
print_mcu (mcu);
return EXIT_SUCCESS;