1f7cc78ecSespie /* BFD library support routines for the AVR architecture.
2*d2201f2fSdrahn Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
3f7cc78ecSespie Contributed by Denis Chertykov <denisc@overta.ru>
4f7cc78ecSespie
5f7cc78ecSespie This file is part of BFD, the Binary File Descriptor library.
6f7cc78ecSespie
7f7cc78ecSespie This program is free software; you can redistribute it and/or modify
8f7cc78ecSespie it under the terms of the GNU General Public License as published by
9f7cc78ecSespie the Free Software Foundation; either version 2 of the License, or
10f7cc78ecSespie (at your option) any later version.
11f7cc78ecSespie
12f7cc78ecSespie This program is distributed in the hope that it will be useful,
13f7cc78ecSespie but WITHOUT ANY WARRANTY; without even the implied warranty of
14f7cc78ecSespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15f7cc78ecSespie GNU General Public License for more details.
16f7cc78ecSespie
17f7cc78ecSespie You should have received a copy of the GNU General Public License
18f7cc78ecSespie along with this program; if not, write to the Free Software
19f7cc78ecSespie Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20f7cc78ecSespie
21f7cc78ecSespie #include "bfd.h"
22f7cc78ecSespie #include "sysdep.h"
23f7cc78ecSespie #include "libbfd.h"
24f7cc78ecSespie
25f7cc78ecSespie static const bfd_arch_info_type *compatible
26f7cc78ecSespie PARAMS ((const bfd_arch_info_type *, const bfd_arch_info_type *));
27f7cc78ecSespie
28f7cc78ecSespie #define N(addr_bits, machine, print, default, next) \
29f7cc78ecSespie { \
30f7cc78ecSespie 8, /* 8 bits in a word */ \
31f7cc78ecSespie addr_bits, /* bits in an address */ \
32f7cc78ecSespie 8, /* 8 bits in a byte */ \
33f7cc78ecSespie bfd_arch_avr, \
34f7cc78ecSespie machine, /* machine */ \
35f7cc78ecSespie "avr", /* arch_name */ \
36f7cc78ecSespie print, /* printable name */ \
37f7cc78ecSespie 1, /* section align power */ \
38f7cc78ecSespie default, /* the default machine */ \
39f7cc78ecSespie compatible, \
40f7cc78ecSespie bfd_default_scan, \
41f7cc78ecSespie next \
42f7cc78ecSespie }
43f7cc78ecSespie
44f7cc78ecSespie static const bfd_arch_info_type arch_info_struct[] =
45f7cc78ecSespie {
465f210c2aSfgsch /* AT90S1200, ATtiny1x, ATtiny28 */
47*d2201f2fSdrahn N (16, bfd_mach_avr1, "avr:1", FALSE, & arch_info_struct[1]),
48f7cc78ecSespie
495f210c2aSfgsch /* AT90S2xxx, AT90S4xxx, AT90S8xxx, ATtiny22 */
50*d2201f2fSdrahn N (16, bfd_mach_avr2, "avr:2", FALSE, & arch_info_struct[2]),
51f7cc78ecSespie
52f7cc78ecSespie /* ATmega103, ATmega603 */
53*d2201f2fSdrahn N (22, bfd_mach_avr3, "avr:3", FALSE, & arch_info_struct[3]),
54f7cc78ecSespie
555f210c2aSfgsch /* ATmega83, ATmega85 */
56*d2201f2fSdrahn N (16, bfd_mach_avr4, "avr:4", FALSE, & arch_info_struct[4]),
575f210c2aSfgsch
585f210c2aSfgsch /* ATmega161, ATmega163, ATmega32, AT94K */
59*d2201f2fSdrahn N (22, bfd_mach_avr5, "avr:5", FALSE, NULL)
60f7cc78ecSespie };
61f7cc78ecSespie
62f7cc78ecSespie const bfd_arch_info_type bfd_avr_arch =
63*d2201f2fSdrahn N (16, bfd_mach_avr2, "avr", TRUE, & arch_info_struct[0]);
64f7cc78ecSespie
65f7cc78ecSespie /* This routine is provided two arch_infos and works out which AVR
66f7cc78ecSespie machine which would be compatible with both and returns a pointer
67f7cc78ecSespie to its info structure. */
68f7cc78ecSespie
69f7cc78ecSespie static const bfd_arch_info_type *
compatible(a,b)70f7cc78ecSespie compatible (a,b)
71f7cc78ecSespie const bfd_arch_info_type * a;
72f7cc78ecSespie const bfd_arch_info_type * b;
73f7cc78ecSespie {
74f7cc78ecSespie /* If a & b are for different architectures we can do nothing. */
75f7cc78ecSespie if (a->arch != b->arch)
76f7cc78ecSespie return NULL;
77f7cc78ecSespie
785f210c2aSfgsch /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4). */
79*d2201f2fSdrahn if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4)
80*d2201f2fSdrahn || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3))
81f7cc78ecSespie return NULL;
82f7cc78ecSespie
83f7cc78ecSespie /* So far all newer AVR architecture cores are supersets of previous
84f7cc78ecSespie cores. */
85f7cc78ecSespie if (a->mach <= b->mach)
86f7cc78ecSespie return b;
87f7cc78ecSespie
885f210c2aSfgsch if (a->mach >= b->mach)
895f210c2aSfgsch return a;
905f210c2aSfgsch
91f7cc78ecSespie /* Never reached! */
92f7cc78ecSespie return NULL;
93f7cc78ecSespie }
94