avr-devices.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Anatoly Sokolov (aesok@post.ru)
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef IN_GEN_AVR_MMCU_TEXI
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "diagnostic.h"
  20. #include "tm.h"
  21. #endif /* IN_GEN_AVR_MMCU_TEXI */
  22. #include "avr-arch.h"
  23. /* List of all known AVR MCU architectures.
  24. Order as of enum avr_arch from avr.h. */
  25. const avr_arch_t
  26. avr_arch_types[] =
  27. {
  28. /* unknown device specified */
  29. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 32, NULL, AVR_MMCU_DEFAULT },
  30. /*
  31. A M J LM E E E X R T d S S O A
  32. S U M PO L L I M A I a t F ff r
  33. M L P MV P P J E M N t a R s c
  34. XW M M M G P Y a r e h
  35. X P A D t t ID */
  36. { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 32, "1", "avr1" },
  37. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0060, 32, "2", "avr2" },
  38. { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 32, "25", "avr25" },
  39. { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x0060, 32, "3", "avr3" },
  40. { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0x0060, 32, "31", "avr31" },
  41. { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 32, "35", "avr35" },
  42. { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0x0060, 32, "4", "avr4" },
  43. { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0x0060, 32, "5", "avr5" },
  44. { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0x0060, 32, "51", "avr51" },
  45. { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0x0060, 32, "6", "avr6" },
  46. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x0040, 0, "100", "avrtiny" },
  47. { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0x2000, 0, "102", "avrxmega2" },
  48. { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0x2000, 0, "104", "avrxmega4" },
  49. { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0x2000, 0, "105", "avrxmega5" },
  50. { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0x2000, 0, "106", "avrxmega6" },
  51. { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0x2000, 0, "107", "avrxmega7" }
  52. };
  53. const avr_arch_info_t
  54. avr_texinfo[] =
  55. {
  56. { ARCH_AVR1,
  57. "This ISA is implemented by the minimal AVR core and supported "
  58. "for assembler only." },
  59. { ARCH_AVR2,
  60. "``Classic'' devices with up to 8@tie{}KiB of program memory." },
  61. { ARCH_AVR25,
  62. "``Classic'' devices with up to 8@tie{}KiB of program memory and with "
  63. "the @code{MOVW} instruction." },
  64. { ARCH_AVR3,
  65. "``Classic'' devices with 16@tie{}KiB up to 64@tie{}KiB of "
  66. " program memory." },
  67. { ARCH_AVR31,
  68. "``Classic'' devices with 128@tie{}KiB of program memory." },
  69. { ARCH_AVR35,
  70. "``Classic'' devices with 16@tie{}KiB up to 64@tie{}KiB of "
  71. "program memory and with the @code{MOVW} instruction." },
  72. { ARCH_AVR4,
  73. "``Enhanced'' devices with up to 8@tie{}KiB of program memory." },
  74. { ARCH_AVR5,
  75. "``Enhanced'' devices with 16@tie{}KiB up to 64@tie{}KiB of "
  76. "program memory." },
  77. { ARCH_AVR51,
  78. "``Enhanced'' devices with 128@tie{}KiB of program memory." },
  79. { ARCH_AVR6,
  80. "``Enhanced'' devices with 3-byte PC, i.e.@: with more than 128@tie{}KiB "
  81. "of program memory." },
  82. { ARCH_AVRTINY,
  83. "``TINY'' Tiny core devices with 512@tie{}B up to 4@tie{}KiB of "
  84. "program memory." },
  85. { ARCH_AVRXMEGA2,
  86. "``XMEGA'' devices with more than 8@tie{}KiB and up to 64@tie{}KiB "
  87. "of program memory." },
  88. { ARCH_AVRXMEGA4,
  89. "``XMEGA'' devices with more than 64@tie{}KiB and up to 128@tie{}KiB "
  90. "of program memory." },
  91. { ARCH_AVRXMEGA5,
  92. "``XMEGA'' devices with more than 64@tie{}KiB and up to 128@tie{}KiB "
  93. "of program memory and more than 64@tie{}KiB of RAM." },
  94. { ARCH_AVRXMEGA6,
  95. "``XMEGA'' devices with more than 128@tie{}KiB of program memory." },
  96. { ARCH_AVRXMEGA7,
  97. "``XMEGA'' devices with more than 128@tie{}KiB of program memory "
  98. "and more than 64@tie{}KiB of RAM." }
  99. };
  100. const avr_mcu_t
  101. avr_mcu_types[] =
  102. {
  103. #define AVR_MCU(NAME, ARCH, DEV_ATTRIBUTE, MACRO, DATA_SEC, TEXT_SEC, N_FLASH)\
  104. { NAME, ARCH, DEV_ATTRIBUTE, MACRO, DATA_SEC, TEXT_SEC, N_FLASH },
  105. #include "avr-mcus.def"
  106. #undef AVR_MCU
  107. /* End of list. */
  108. { NULL, ARCH_UNKNOWN, AVR_ISA_NONE, NULL, 0, 0, 0 }
  109. };
  110. #ifndef IN_GEN_AVR_MMCU_TEXI
  111. /* Copy-pastes from `gen-avr-mmcu-texi.c' follow... */
  112. static const char*
  113. mcu_name[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
  114. static int
  115. comparator (const void *va, const void *vb)
  116. {
  117. const char *a = *(const char* const*) va;
  118. const char *b = *(const char* const*) vb;
  119. while (*a && *b)
  120. {
  121. /* Make letters smaller than digits so that `atmega16a' follows
  122. `atmega16' without `atmega161' etc. between them. */
  123. if (ISALPHA (*a) && ISDIGIT (*b))
  124. return -1;
  125. if (ISDIGIT (*a) && ISALPHA (*b))
  126. return 1;
  127. if (*a != *b)
  128. return *a - *b;
  129. a++;
  130. b++;
  131. }
  132. return *a - *b;
  133. }
  134. static char*
  135. avr_archs_str (void)
  136. {
  137. char *archs = concat ("", NULL);
  138. // Build of core architectures' names.
  139. for (const avr_mcu_t *mcu = avr_mcu_types; mcu->name; mcu++)
  140. if (!mcu->macro)
  141. archs = concat (archs, " ", avr_arch_types[mcu->arch_id].name, NULL);
  142. return archs;
  143. }
  144. static char*
  145. avr_mcus_str (void)
  146. {
  147. size_t n_mcus = 0;
  148. char *mcus = concat ("", NULL);
  149. // Build array of proper devices' names.
  150. for (const avr_mcu_t *mcu = avr_mcu_types; mcu->name; mcu++)
  151. if (mcu->macro)
  152. mcu_name[n_mcus++] = mcu->name;
  153. // Sort MCUs so that they are displayed in the same canonical order as
  154. // in doc/avr-mcus.texi.
  155. qsort (mcu_name, n_mcus, sizeof (char*), comparator);
  156. for (size_t i = 0; i < n_mcus; i++)
  157. mcus = concat (mcus, " ", mcu_name[i], NULL);
  158. return mcus;
  159. }
  160. void
  161. avr_inform_devices (void)
  162. {
  163. char *mcus = avr_mcus_str ();
  164. inform (input_location, "devices natively supported:%s", mcus);
  165. free (mcus);
  166. }
  167. void
  168. avr_inform_core_architectures (void)
  169. {
  170. char *archs = avr_archs_str ();
  171. inform (input_location, "supported core architectures:%s", archs);
  172. free (archs);
  173. }
  174. #endif // IN_GEN_AVR_MMCU_TEXI