Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/bfd/cpu-avr.c
Line
Count
Source (jump to first uncovered line)
1
/* BFD library support routines for the AVR architecture.
2
   Copyright (C) 1999-2025 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
0
{
34
  /* If a & b are for different architectures we can do nothing.  */
35
0
  if (a->arch != b->arch)
36
0
    return NULL;
37
38
0
  if (a->mach == b->mach)
39
0
    return a;
40
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
0
  if (a->mach == bfd_mach_avr6 || b->mach == bfd_mach_avr6)
45
0
    return NULL;
46
47
0
  if (a->mach < bfd_mach_avr6 && b->mach < bfd_mach_avr6)
48
0
    {
49
      /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4).  */
50
0
      if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4)
51
0
   || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3))
52
0
       return NULL;
53
54
0
      if (a->mach <= b->mach)
55
0
       return b;
56
57
0
      if (a->mach >= b->mach)
58
0
       return a;
59
0
    }
60
61
0
  if (a->mach == bfd_mach_avr2 && b->mach == bfd_mach_avr25)
62
0
    return a;
63
0
  if (a->mach == bfd_mach_avr25 && b->mach == bfd_mach_avr2)
64
0
    return b;
65
66
0
  if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr31)
67
0
    return a;
68
0
  if (a->mach == bfd_mach_avr31 && b->mach == bfd_mach_avr3)
69
0
    return b;
70
0
  if (a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr35)
71
0
    return a;
72
0
  if (a->mach == bfd_mach_avr35 && b->mach == bfd_mach_avr3)
73
0
    return b;
74
75
0
  if (a->mach == bfd_mach_avr5 && b->mach == bfd_mach_avr51)
76
0
    return a;
77
0
  if (a->mach == bfd_mach_avr51 && b->mach == bfd_mach_avr5)
78
0
    return b;
79
80
0
  return NULL;
81
0
}
82
83
#define N(addr_bits, machine, print, default, next)   \
84
{               \
85
  8,        /* Bits in a word.  */    \
86
  addr_bits,      /* Bits in an address.  */  \
87
  8,        /* Bits in a byte.  */    \
88
  bfd_arch_avr,             \
89
  machine,      /* Machine number.  */    \
90
  "avr",      /* Architecture name.   */  \
91
  print,      /* Printable name.  */    \
92
  1,        /* Section align power.  */ \
93
  default,      /* Is this the default ?  */  \
94
  compatible,             \
95
  bfd_default_scan,           \
96
  bfd_arch_default_fill,          \
97
  next,               \
98
  0 /* Maximum offset of a reloc from the start of an insn.  */ \
99
}
100
101
static const bfd_arch_info_type arch_info_struct[] =
102
{
103
  /* Assembler only.  */
104
  N (16, bfd_mach_avr1, "avr:1", false, & arch_info_struct[1]),
105
106
  /* Classic, <= 8K.  */
107
  N (16, bfd_mach_avr2, "avr:2", false, & arch_info_struct[2]),
108
109
  /* Classic + MOVW, <= 8K.  */
110
  N (16, bfd_mach_avr25, "avr:25", false, & arch_info_struct[3]),
111
112
  /* Classic, > 8K, <= 64K.  */
113
  /* TODO:  addr_bits should be 16, but set to 22 for some following
114
     version of GCC (from 4.3) for backward compatibility.  */
115
  N (22, bfd_mach_avr3, "avr:3", false, & arch_info_struct[4]),
116
117
  /* Classic, == 128K.  */
118
  N (22, bfd_mach_avr31, "avr:31", false, & arch_info_struct[5]),
119
120
  /* Classic + MOVW + JMP/CALL, > 8K, <= 64K. */
121
  N (16, bfd_mach_avr35, "avr:35", false, & arch_info_struct[6]),
122
123
  /* Enhanced, <= 8K.  */
124
  N (16, bfd_mach_avr4, "avr:4", false, & arch_info_struct[7]),
125
126
  /* Enhanced, > 8K, <= 64K.  */
127
  /* TODO:  addr_bits should be 16, but set to 22 for some following
128
     version of GCC (from 4.3) for backward compatibility.  */
129
  N (22, bfd_mach_avr5, "avr:5", false, & arch_info_struct[8]),
130
131
  /* Enhanced, == 128K.  */
132
  N (22, bfd_mach_avr51, "avr:51", false, & arch_info_struct[9]),
133
134
  /* 3-Byte PC.  */
135
  N (22, bfd_mach_avr6, "avr:6", false, & arch_info_struct[10]),
136
137
  /* Tiny core (AVR Tiny).  */
138
  N (16, bfd_mach_avrtiny, "avr:100", false, & arch_info_struct[11]),
139
140
  /* Xmega 1.  */
141
  N (24, bfd_mach_avrxmega1, "avr:101", false, & arch_info_struct[12]),
142
143
  /* Xmega 2.  */
144
  N (24, bfd_mach_avrxmega2, "avr:102", false, & arch_info_struct[13]),
145
146
  /* Xmega 3.  */
147
  N (24, bfd_mach_avrxmega3, "avr:103", false, & arch_info_struct[14]),
148
149
  /* Xmega 4.  */
150
  N (24, bfd_mach_avrxmega4, "avr:104", false, & arch_info_struct[15]),
151
152
  /* Xmega 5.  */
153
  N (24, bfd_mach_avrxmega5, "avr:105", false, & arch_info_struct[16]),
154
155
  /* Xmega 6.  */
156
  N (24, bfd_mach_avrxmega6, "avr:106", false, & arch_info_struct[17]),
157
158
  /* Xmega 7.  */
159
  N (24, bfd_mach_avrxmega7, "avr:107", false, NULL)
160
161
};
162
163
const bfd_arch_info_type bfd_avr_arch =
164
  N (16, bfd_mach_avr2, "avr", true, & arch_info_struct[0]);