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