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