1 /* BFD library support routines for the AVR architecture. 2 Copyright 1999, 2000, 2002, 2006, 2007 Free Software Foundation, Inc. 3 Contributed by Denis Chertykov <denisc@overta.ru> 4 5 This file is part of BFD, the Binary File Descriptor library. 6 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. 11 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. 16 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. */ 21 22 #include "sysdep.h" 23 #include "bfd.h" 24 #include "libbfd.h" 25 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 30 static const bfd_arch_info_type * 31 compatible (const bfd_arch_info_type * a, 32 const bfd_arch_info_type * b) 33 { 34 /* If a & b are for different architectures we can do nothing. */ 35 if (a->arch != b->arch) 36 return NULL; 37 38 if (a->mach == b->mach) 39 return a; 40 41 if (a->mach <= bfd_mach_avr6 && b->mach <= bfd_mach_avr6) 42 { 43 /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4). */ 44 if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4) 45 || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3)) 46 return NULL; 47 48 if (a->mach <= b->mach) 49 return b; 50 51 if (a->mach >= b->mach) 52 return a; 53 } 54 55 if (a->mach == bfd_mach_avr2 && b->mach == bfd_mach_avr25) 56 return a; 57 if (a->mach == bfd_mach_avr25 && b->mach == bfd_mach_avr2) 58 return b; 59 60 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr31) 61 return a; 62 if (a->mach == bfd_mach_avr31 && b->mach == bfd_mach_avr3) 63 return b; 64 65 if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr35) 66 return a; 67 if (a->mach == bfd_mach_avr35 && b->mach == bfd_mach_avr3) 68 return b; 69 70 if (a->mach == bfd_mach_avr5 && b->mach == bfd_mach_avr51) 71 return a; 72 if (a->mach == bfd_mach_avr51 && b->mach == bfd_mach_avr5) 73 return b; 74 75 76 return NULL; 77 } 78 79 #define N(addr_bits, machine, print, default, next) \ 80 { \ 81 8, /* 8 bits in a word. */ \ 82 addr_bits, /* bits in an address. */ \ 83 8, /* 8 bits in a byte. */ \ 84 bfd_arch_avr, \ 85 machine, /* Machine number. */ \ 86 "avr", /* Architecture name. */ \ 87 print, /* Printable name. */ \ 88 1, /* Section align power. */ \ 89 default, /* Is this the default ? */ \ 90 compatible, \ 91 bfd_default_scan, \ 92 next \ 93 } 94 95 static const bfd_arch_info_type arch_info_struct[] = 96 { 97 /* Assembler only. */ 98 N (16, bfd_mach_avr1, "avr:1", FALSE, & arch_info_struct[1]), 99 100 /* Classic, <= 8K. */ 101 N (16, bfd_mach_avr2, "avr:2", FALSE, & arch_info_struct[2]), 102 103 /* Classic + MOVW, <= 8K. */ 104 N (16, bfd_mach_avr25, "avr:25", FALSE, & arch_info_struct[3]), 105 106 /* Classic, > 8K, <= 64K. */ 107 /* TODO: addr_bits should be 16, but set to 22 for some following 108 version of GCC (from 4.3) for backward compatibility. */ 109 N (22, bfd_mach_avr3, "avr:3", FALSE, & arch_info_struct[4]), 110 111 /* Classic, == 128K. */ 112 N (22, bfd_mach_avr31, "avr:31", FALSE, & arch_info_struct[5]), 113 114 /* Classic + MOVW + JMP/CALL, > 8K, <= 64K. */ 115 N (16, bfd_mach_avr35, "avr:35", FALSE, & arch_info_struct[6]), 116 117 /* Enhanced, <= 8K. */ 118 N (16, bfd_mach_avr4, "avr:4", FALSE, & arch_info_struct[7]), 119 120 /* Enhanced, > 8K, <= 64K. */ 121 /* TODO: addr_bits should be 16, but set to 22 for some following 122 version of GCC (from 4.3) for backward compatibility. */ 123 N (22, bfd_mach_avr5, "avr:5", FALSE, & arch_info_struct[8]), 124 125 /* Enhanced, == 128K. */ 126 N (22, bfd_mach_avr51, "avr:51", FALSE, & arch_info_struct[9]), 127 128 /* 3-Byte PC. */ 129 N (22, bfd_mach_avr6, "avr:6", FALSE, NULL) 130 }; 131 132 const bfd_arch_info_type bfd_avr_arch = 133 N (16, bfd_mach_avr2, "avr", TRUE, & arch_info_struct[0]); 134