]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/cpu-avr.c
Update copyright years
[thirdparty/binutils-gdb.git] / bfd / cpu-avr.c
CommitLineData
adde6300 1/* BFD library support routines for the AVR architecture.
4b95cf5c 2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
adde6300
AM
3 Contributed by Denis Chertykov <denisc@overta.ru>
4
4cdc7696 5 This file is part of BFD, the Binary File Descriptor library.
adde6300 6
4cdc7696
NC
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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
4cdc7696 10 (at your option) any later version.
adde6300 11
4cdc7696
NC
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.
adde6300 16
4cdc7696
NC
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
adde6300 21
adde6300 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
adde6300
AM
24#include "libbfd.h"
25
adde6300
AM
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. */
29
30static const bfd_arch_info_type *
4cdc7696
NC
31compatible (const bfd_arch_info_type * a,
32 const bfd_arch_info_type * b)
adde6300
AM
33{
34 /* If a & b are for different architectures we can do nothing. */
35 if (a->arch != b->arch)
36 return NULL;
37
7b21ac3f
EW
38 if (a->mach == b->mach)
39 return a;
adde6300 40
3e22044a
TG
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
43 instead of 2). */
44 if (a->mach == bfd_mach_avr6 || b->mach == bfd_mach_avr6)
45 return NULL;
46
47 if (a->mach < bfd_mach_avr6 && b->mach < bfd_mach_avr6)
7b21ac3f
EW
48 {
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))
52 return NULL;
53
54 if (a->mach <= b->mach)
55 return b;
68ffbac6 56
7b21ac3f
EW
57 if (a->mach >= b->mach)
58 return a;
59 }
60
61 if (a->mach == bfd_mach_avr2 && b->mach == bfd_mach_avr25)
62 return a;
63 if (a->mach == bfd_mach_avr25 && b->mach == bfd_mach_avr2)
64 return b;
68ffbac6 65
7b21ac3f
EW
66 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr31)
67 return a;
68 if (a->mach == bfd_mach_avr31 && b->mach == bfd_mach_avr3)
adde6300
AM
69 return b;
70
7b21ac3f 71 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr35)
65aa24b6 72 return a;
7b21ac3f
EW
73 if (a->mach == bfd_mach_avr35 && b->mach == bfd_mach_avr3)
74 return b;
75
76 if (a->mach == bfd_mach_avr5 && b->mach == bfd_mach_avr51)
77 return a;
78 if (a->mach == bfd_mach_avr51 && b->mach == bfd_mach_avr5)
79 return b;
80
65aa24b6 81
adde6300
AM
82 return NULL;
83}
4cdc7696
NC
84
85#define N(addr_bits, machine, print, default, next) \
86{ \
87 8, /* 8 bits in a word. */ \
88 addr_bits, /* bits in an address. */ \
89 8, /* 8 bits in a byte. */ \
90 bfd_arch_avr, \
91 machine, /* Machine number. */ \
92 "avr", /* Architecture name. */ \
93 print, /* Printable name. */ \
94 1, /* Section align power. */ \
95 default, /* Is this the default ? */ \
96 compatible, \
97 bfd_default_scan, \
b7761f11 98 bfd_arch_default_fill, \
4cdc7696
NC
99 next \
100}
101
102static const bfd_arch_info_type arch_info_struct[] =
103{
7b21ac3f 104 /* Assembler only. */
4cdc7696
NC
105 N (16, bfd_mach_avr1, "avr:1", FALSE, & arch_info_struct[1]),
106
7b21ac3f 107 /* Classic, <= 8K. */
4cdc7696
NC
108 N (16, bfd_mach_avr2, "avr:2", FALSE, & arch_info_struct[2]),
109
7b21ac3f
EW
110 /* Classic + MOVW, <= 8K. */
111 N (16, bfd_mach_avr25, "avr:25", FALSE, & arch_info_struct[3]),
112
113 /* Classic, > 8K, <= 64K. */
68ffbac6 114 /* TODO: addr_bits should be 16, but set to 22 for some following
7b21ac3f
EW
115 version of GCC (from 4.3) for backward compatibility. */
116 N (22, bfd_mach_avr3, "avr:3", FALSE, & arch_info_struct[4]),
117
118 /* Classic, == 128K. */
119 N (22, bfd_mach_avr31, "avr:31", FALSE, & arch_info_struct[5]),
120
121 /* Classic + MOVW + JMP/CALL, > 8K, <= 64K. */
122 N (16, bfd_mach_avr35, "avr:35", FALSE, & arch_info_struct[6]),
4cdc7696 123
7b21ac3f
EW
124 /* Enhanced, <= 8K. */
125 N (16, bfd_mach_avr4, "avr:4", FALSE, & arch_info_struct[7]),
4cdc7696 126
7b21ac3f 127 /* Enhanced, > 8K, <= 64K. */
68ffbac6 128 /* TODO: addr_bits should be 16, but set to 22 for some following
7b21ac3f
EW
129 version of GCC (from 4.3) for backward compatibility. */
130 N (22, bfd_mach_avr5, "avr:5", FALSE, & arch_info_struct[8]),
68ffbac6 131
7b21ac3f
EW
132 /* Enhanced, == 128K. */
133 N (22, bfd_mach_avr51, "avr:51", FALSE, & arch_info_struct[9]),
28c9d252 134
7b21ac3f 135 /* 3-Byte PC. */
8cc66334 136 N (22, bfd_mach_avr6, "avr:6", FALSE, & arch_info_struct[10]),
68ffbac6 137
8cc66334
EW
138 /* Xmega 1 */
139 N (24, bfd_mach_avrxmega1, "avr:101", FALSE, & arch_info_struct[11]),
140
141 /* Xmega 2 */
142 N (24, bfd_mach_avrxmega2, "avr:102", FALSE, & arch_info_struct[12]),
68ffbac6 143
8cc66334
EW
144 /* Xmega 3 */
145 N (24, bfd_mach_avrxmega3, "avr:103", FALSE, & arch_info_struct[13]),
68ffbac6 146
8cc66334
EW
147 /* Xmega 4 */
148 N (24, bfd_mach_avrxmega4, "avr:104", FALSE, & arch_info_struct[14]),
68ffbac6 149
8cc66334
EW
150 /* Xmega 5 */
151 N (24, bfd_mach_avrxmega5, "avr:105", FALSE, & arch_info_struct[15]),
68ffbac6 152
8cc66334
EW
153 /* Xmega 6 */
154 N (24, bfd_mach_avrxmega6, "avr:106", FALSE, & arch_info_struct[16]),
68ffbac6 155
8cc66334
EW
156 /* Xmega 7 */
157 N (24, bfd_mach_avrxmega7, "avr:107", FALSE, NULL)
68ffbac6 158
4cdc7696
NC
159};
160
161const bfd_arch_info_type bfd_avr_arch =
162 N (16, bfd_mach_avr2, "avr", TRUE, & arch_info_struct[0]);