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