cpu-avr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* BFD library support routines for the AVR architecture.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. Contributed by Denis Chertykov <denisc@overta.ru>
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. /* This routine is provided two arch_infos and works out which AVR
  21. machine which would be compatible with both and returns a pointer
  22. to its info structure. */
  23. static const bfd_arch_info_type *
  24. compatible (const bfd_arch_info_type * a,
  25. const bfd_arch_info_type * b)
  26. {
  27. /* If a & b are for different architectures we can do nothing. */
  28. if (a->arch != b->arch)
  29. return NULL;
  30. if (a->mach == b->mach)
  31. return a;
  32. /* avr-6 is compatible only with itself as its call convention is not
  33. compatible with other avr (the mcu saves the return address on 3 bytes
  34. instead of 2). */
  35. if (a->mach == bfd_mach_avr6 || b->mach == bfd_mach_avr6)
  36. return NULL;
  37. if (a->mach < bfd_mach_avr6 && b->mach < bfd_mach_avr6)
  38. {
  39. /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4). */
  40. if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4)
  41. || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3))
  42. return NULL;
  43. if (a->mach <= b->mach)
  44. return b;
  45. if (a->mach >= b->mach)
  46. return a;
  47. }
  48. if (a->mach == bfd_mach_avr2 && b->mach == bfd_mach_avr25)
  49. return a;
  50. if (a->mach == bfd_mach_avr25 && b->mach == bfd_mach_avr2)
  51. return b;
  52. if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr31)
  53. return a;
  54. if (a->mach == bfd_mach_avr31 && b->mach == bfd_mach_avr3)
  55. return b;
  56. if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr35)
  57. return a;
  58. if (a->mach == bfd_mach_avr35 && b->mach == bfd_mach_avr3)
  59. return b;
  60. if (a->mach == bfd_mach_avr5 && b->mach == bfd_mach_avr51)
  61. return a;
  62. if (a->mach == bfd_mach_avr51 && b->mach == bfd_mach_avr5)
  63. return b;
  64. return NULL;
  65. }
  66. #define N(addr_bits, machine, print, default, next) \
  67. { \
  68. 8, /* Bits in a word. */ \
  69. addr_bits, /* Bits in an address. */ \
  70. 8, /* Bits in a byte. */ \
  71. bfd_arch_avr, \
  72. machine, /* Machine number. */ \
  73. "avr", /* Architecture name. */ \
  74. print, /* Printable name. */ \
  75. 1, /* Section align power. */ \
  76. default, /* Is this the default ? */ \
  77. compatible, \
  78. bfd_default_scan, \
  79. bfd_arch_default_fill, \
  80. next, \
  81. 0 /* Maximum offset of a reloc from the start of an insn. */ \
  82. }
  83. static const bfd_arch_info_type arch_info_struct[] =
  84. {
  85. /* Assembler only. */
  86. N (16, bfd_mach_avr1, "avr:1", false, & arch_info_struct[1]),
  87. /* Classic, <= 8K. */
  88. N (16, bfd_mach_avr2, "avr:2", false, & arch_info_struct[2]),
  89. /* Classic + MOVW, <= 8K. */
  90. N (16, bfd_mach_avr25, "avr:25", false, & arch_info_struct[3]),
  91. /* Classic, > 8K, <= 64K. */
  92. /* TODO: addr_bits should be 16, but set to 22 for some following
  93. version of GCC (from 4.3) for backward compatibility. */
  94. N (22, bfd_mach_avr3, "avr:3", false, & arch_info_struct[4]),
  95. /* Classic, == 128K. */
  96. N (22, bfd_mach_avr31, "avr:31", false, & arch_info_struct[5]),
  97. /* Classic + MOVW + JMP/CALL, > 8K, <= 64K. */
  98. N (16, bfd_mach_avr35, "avr:35", false, & arch_info_struct[6]),
  99. /* Enhanced, <= 8K. */
  100. N (16, bfd_mach_avr4, "avr:4", false, & arch_info_struct[7]),
  101. /* Enhanced, > 8K, <= 64K. */
  102. /* TODO: addr_bits should be 16, but set to 22 for some following
  103. version of GCC (from 4.3) for backward compatibility. */
  104. N (22, bfd_mach_avr5, "avr:5", false, & arch_info_struct[8]),
  105. /* Enhanced, == 128K. */
  106. N (22, bfd_mach_avr51, "avr:51", false, & arch_info_struct[9]),
  107. /* 3-Byte PC. */
  108. N (22, bfd_mach_avr6, "avr:6", false, & arch_info_struct[10]),
  109. /* Tiny core (AVR Tiny). */
  110. N (16, bfd_mach_avrtiny, "avr:100", false, & arch_info_struct[11]),
  111. /* Xmega 1. */
  112. N (24, bfd_mach_avrxmega1, "avr:101", false, & arch_info_struct[12]),
  113. /* Xmega 2. */
  114. N (24, bfd_mach_avrxmega2, "avr:102", false, & arch_info_struct[13]),
  115. /* Xmega 3. */
  116. N (24, bfd_mach_avrxmega3, "avr:103", false, & arch_info_struct[14]),
  117. /* Xmega 4. */
  118. N (24, bfd_mach_avrxmega4, "avr:104", false, & arch_info_struct[15]),
  119. /* Xmega 5. */
  120. N (24, bfd_mach_avrxmega5, "avr:105", false, & arch_info_struct[16]),
  121. /* Xmega 6. */
  122. N (24, bfd_mach_avrxmega6, "avr:106", false, & arch_info_struct[17]),
  123. /* Xmega 7. */
  124. N (24, bfd_mach_avrxmega7, "avr:107", false, NULL)
  125. };
  126. const bfd_arch_info_type bfd_avr_arch =
  127. N (16, bfd_mach_avr2, "avr", true, & arch_info_struct[0]);