1 /* BFD library support routines for the AVR architecture.
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
3 Contributed by Denis Chertykov <denisc@overta.ru>
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
26 /* This routine is provided two arch_infos and works out which AVR
27 machine which would be compatible with both and returns a pointer
28 to its info structure. */
30 static const bfd_arch_info_type *
31 compatible (const bfd_arch_info_type * a,
32 const bfd_arch_info_type * b)
34 /* If a & b are for different architectures we can do nothing. */
35 if (a->arch != b->arch)
38 if (a->mach == b->mach)
41 /* avr-6 is compatible only with itself as its call convention is not
42 compatible with other avr (the mcu saves the return address on 3 bytes
44 if (a->mach == bfd_mach_avr6 || b->mach == bfd_mach_avr6)
47 if (a->mach < bfd_mach_avr6 && b->mach < bfd_mach_avr6)
49 /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4). */
50 if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4)
51 || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3))
54 if (a->mach <= b->mach)
57 if (a->mach >= b->mach)
61 if (a->mach == bfd_mach_avr2 && b->mach == bfd_mach_avr25)
63 if (a->mach == bfd_mach_avr25 && b->mach == bfd_mach_avr2)
66 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr31)
68 if (a->mach == bfd_mach_avr31 && b->mach == bfd_mach_avr3)
70 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr35)
72 if (a->mach == bfd_mach_avr35 && b->mach == bfd_mach_avr3)
75 if (a->mach == bfd_mach_avr5 && b->mach == bfd_mach_avr51)
77 if (a->mach == bfd_mach_avr51 && b->mach == bfd_mach_avr5)
83 #define N(addr_bits, machine, print, default, next) \
85 8, /* 8 bits in a word. */ \
86 addr_bits, /* bits in an address. */ \
87 8, /* 8 bits in a byte. */ \
89 machine, /* Machine number. */ \
90 "avr", /* Architecture name. */ \
91 print, /* Printable name. */ \
92 1, /* Section align power. */ \
93 default, /* Is this the default ? */ \
96 bfd_arch_default_fill, \
100 static const bfd_arch_info_type arch_info_struct[] =
102 /* Assembler only. */
103 N (16, bfd_mach_avr1, "avr:1", FALSE, & arch_info_struct[1]),
105 /* Classic, <= 8K. */
106 N (16, bfd_mach_avr2, "avr:2", FALSE, & arch_info_struct[2]),
108 /* Classic + MOVW, <= 8K. */
109 N (16, bfd_mach_avr25, "avr:25", FALSE, & arch_info_struct[3]),
111 /* Classic, > 8K, <= 64K. */
112 /* TODO: addr_bits should be 16, but set to 22 for some following
113 version of GCC (from 4.3) for backward compatibility. */
114 N (22, bfd_mach_avr3, "avr:3", FALSE, & arch_info_struct[4]),
116 /* Classic, == 128K. */
117 N (22, bfd_mach_avr31, "avr:31", FALSE, & arch_info_struct[5]),
119 /* Classic + MOVW + JMP/CALL, > 8K, <= 64K. */
120 N (16, bfd_mach_avr35, "avr:35", FALSE, & arch_info_struct[6]),
122 /* Enhanced, <= 8K. */
123 N (16, bfd_mach_avr4, "avr:4", FALSE, & arch_info_struct[7]),
125 /* Enhanced, > 8K, <= 64K. */
126 /* TODO: addr_bits should be 16, but set to 22 for some following
127 version of GCC (from 4.3) for backward compatibility. */
128 N (22, bfd_mach_avr5, "avr:5", FALSE, & arch_info_struct[8]),
130 /* Enhanced, == 128K. */
131 N (22, bfd_mach_avr51, "avr:51", FALSE, & arch_info_struct[9]),
134 N (22, bfd_mach_avr6, "avr:6", FALSE, & arch_info_struct[10]),
136 /* Tiny core (AVR Tiny). */
137 N (16, bfd_mach_avrtiny, "avr:100", FALSE, & arch_info_struct[11]),
140 N (24, bfd_mach_avrxmega1, "avr:101", FALSE, & arch_info_struct[12]),
143 N (24, bfd_mach_avrxmega2, "avr:102", FALSE, & arch_info_struct[13]),
146 N (24, bfd_mach_avrxmega3, "avr:103", FALSE, & arch_info_struct[14]),
149 N (24, bfd_mach_avrxmega4, "avr:104", FALSE, & arch_info_struct[15]),
152 N (24, bfd_mach_avrxmega5, "avr:105", FALSE, & arch_info_struct[16]),
155 N (24, bfd_mach_avrxmega6, "avr:106", FALSE, & arch_info_struct[17]),
158 N (24, bfd_mach_avrxmega7, "avr:107", FALSE, NULL)
162 const bfd_arch_info_type bfd_avr_arch =
163 N (16, bfd_mach_avr2, "avr", TRUE, & arch_info_struct[0]);