* gas/config/tc-avr.c: Change ISA for devices with USB support to
[deliverable/binutils-gdb.git] / gas / config / tc-avr.c
CommitLineData
adde6300
AM
1/* tc-avr.c -- Assembler code for the ATMEL AVR
2
71863e73 3 Copyright 1999-2013 Free Software Foundation, Inc.
adde6300
AM
4 Contributed by Denis Chertykov <denisc@overta.ru>
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
ec2655a6 10 the Free Software Foundation; either version 3, or (at your option)
adde6300
AM
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
4b4da160
NC
20 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
adde6300 22
adde6300 23#include "as.h"
3882b010 24#include "safe-ctype.h"
adde6300 25#include "subsegs.h"
fb5b7503 26#include "dwarf2dbg.h"
af3ecb4a
RH
27#include "dw2gencfi.h"
28
adde6300 29
1188e082
DC
30struct avr_opcodes_s
31{
dc191a8f
NC
32 char * name;
33 char * constraints;
8cc66334 34 char * opcode;
dc191a8f
NC
35 int insn_size; /* In words. */
36 int isa;
37 unsigned int bin_opcode;
1188e082
DC
38};
39
40#define AVR_INSN(NAME, CONSTR, OPCODE, SIZE, ISA, BIN) \
8cc66334 41{#NAME, CONSTR, OPCODE, SIZE, ISA, BIN},
1188e082
DC
42
43struct avr_opcodes_s avr_opcodes[] =
44{
45 #include "opcode/avr.h"
8cc66334 46 {NULL, NULL, NULL, 0, 0, 0}
1188e082
DC
47};
48
adde6300
AM
49const char comment_chars[] = ";";
50const char line_comment_chars[] = "#";
51const char line_separator_chars[] = "$";
52
adde6300
AM
53const char *md_shortopts = "m:";
54struct mcu_type_s
55{
56 char *name;
57 int isa;
58 int mach;
59};
60
1f8ae5e6 61/* XXX - devices that don't seem to exist (renamed, replaced with larger
7b21ac3f 62 ones, or planned but never produced), left here for compatibility. */
1f8ae5e6 63
adde6300
AM
64static struct mcu_type_s mcu_types[] =
65{
7b21ac3f
EW
66 {"avr1", AVR_ISA_AVR1, bfd_mach_avr1},
67/* TODO: insruction set for avr2 architecture should be AVR_ISA_AVR2,
99700d6f
NC
68 but set to AVR_ISA_AVR25 for some following version
69 of GCC (from 4.3) for backward compatibility. */
7b21ac3f
EW
70 {"avr2", AVR_ISA_AVR25, bfd_mach_avr2},
71 {"avr25", AVR_ISA_AVR25, bfd_mach_avr25},
99700d6f
NC
72/* TODO: insruction set for avr3 architecture should be AVR_ISA_AVR3,
73 but set to AVR_ISA_AVR3_ALL for some following version
7b21ac3f
EW
74 of GCC (from 4.3) for backward compatibility. */
75 {"avr3", AVR_ISA_AVR3_ALL, bfd_mach_avr3},
76 {"avr31", AVR_ISA_AVR31, bfd_mach_avr31},
77 {"avr35", AVR_ISA_AVR35, bfd_mach_avr35},
78 {"avr4", AVR_ISA_AVR4, bfd_mach_avr4},
99700d6f
NC
79/* TODO: insruction set for avr5 architecture should be AVR_ISA_AVR5,
80 but set to AVR_ISA_AVR51 for some following version
7b21ac3f
EW
81 of GCC (from 4.3) for backward compatibility. */
82 {"avr5", AVR_ISA_AVR51, bfd_mach_avr5},
83 {"avr51", AVR_ISA_AVR51, bfd_mach_avr51},
84 {"avr6", AVR_ISA_AVR6, bfd_mach_avr6},
8cc66334
EW
85 {"avrxmega1", AVR_ISA_XMEGA, bfd_mach_avrxmega1},
86 {"avrxmega2", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
87 {"avrxmega3", AVR_ISA_XMEGA, bfd_mach_avrxmega3},
88 {"avrxmega4", AVR_ISA_XMEGA, bfd_mach_avrxmega4},
89 {"avrxmega5", AVR_ISA_XMEGA, bfd_mach_avrxmega5},
90 {"avrxmega6", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
91 {"avrxmega7", AVR_ISA_XMEGA, bfd_mach_avrxmega7},
28c9d252 92 {"at90s1200", AVR_ISA_1200, bfd_mach_avr1},
7b21ac3f
EW
93 {"attiny11", AVR_ISA_AVR1, bfd_mach_avr1},
94 {"attiny12", AVR_ISA_AVR1, bfd_mach_avr1},
95 {"attiny15", AVR_ISA_AVR1, bfd_mach_avr1},
96 {"attiny28", AVR_ISA_AVR1, bfd_mach_avr1},
97 {"at90s2313", AVR_ISA_AVR2, bfd_mach_avr2},
98 {"at90s2323", AVR_ISA_AVR2, bfd_mach_avr2},
99 {"at90s2333", AVR_ISA_AVR2, bfd_mach_avr2}, /* XXX -> 4433 */
100 {"at90s2343", AVR_ISA_AVR2, bfd_mach_avr2},
101 {"attiny22", AVR_ISA_AVR2, bfd_mach_avr2}, /* XXX -> 2343 */
d669d37f 102 {"attiny26", AVR_ISA_2xxe, bfd_mach_avr2},
7b21ac3f
EW
103 {"at90s4414", AVR_ISA_AVR2, bfd_mach_avr2}, /* XXX -> 8515 */
104 {"at90s4433", AVR_ISA_AVR2, bfd_mach_avr2},
105 {"at90s4434", AVR_ISA_AVR2, bfd_mach_avr2}, /* XXX -> 8535 */
106 {"at90s8515", AVR_ISA_AVR2, bfd_mach_avr2},
107 {"at90c8534", AVR_ISA_AVR2, bfd_mach_avr2},
108 {"at90s8535", AVR_ISA_AVR2, bfd_mach_avr2},
109 {"attiny13", AVR_ISA_AVR25, bfd_mach_avr25},
110 {"attiny13a", AVR_ISA_AVR25, bfd_mach_avr25},
111 {"attiny2313", AVR_ISA_AVR25, bfd_mach_avr25},
8453da2e 112 {"attiny2313a",AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f 113 {"attiny24", AVR_ISA_AVR25, bfd_mach_avr25},
8453da2e
EW
114 {"attiny24a", AVR_ISA_AVR25, bfd_mach_avr25},
115 {"attiny4313", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f 116 {"attiny44", AVR_ISA_AVR25, bfd_mach_avr25},
8453da2e 117 {"attiny44a", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f 118 {"attiny84", AVR_ISA_AVR25, bfd_mach_avr25},
e760a81b 119 {"attiny84a", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f
EW
120 {"attiny25", AVR_ISA_AVR25, bfd_mach_avr25},
121 {"attiny45", AVR_ISA_AVR25, bfd_mach_avr25},
122 {"attiny85", AVR_ISA_AVR25, bfd_mach_avr25},
123 {"attiny261", AVR_ISA_AVR25, bfd_mach_avr25},
8453da2e 124 {"attiny261a", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f 125 {"attiny461", AVR_ISA_AVR25, bfd_mach_avr25},
e760a81b 126 {"attiny461a", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f 127 {"attiny861", AVR_ISA_AVR25, bfd_mach_avr25},
8453da2e 128 {"attiny861a", AVR_ISA_AVR25, bfd_mach_avr25},
2b02f87c 129 {"attiny87", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f
EW
130 {"attiny43u", AVR_ISA_AVR25, bfd_mach_avr25},
131 {"attiny48", AVR_ISA_AVR25, bfd_mach_avr25},
132 {"attiny88", AVR_ISA_AVR25, bfd_mach_avr25},
133 {"at86rf401", AVR_ISA_RF401, bfd_mach_avr25},
a53fddce 134 {"ata6289", AVR_ISA_AVR25, bfd_mach_avr25},
7b21ac3f
EW
135 {"at43usb355", AVR_ISA_AVR3, bfd_mach_avr3},
136 {"at76c711", AVR_ISA_AVR3, bfd_mach_avr3},
137 {"atmega103", AVR_ISA_AVR31, bfd_mach_avr31},
138 {"at43usb320", AVR_ISA_AVR31, bfd_mach_avr31},
139 {"attiny167", AVR_ISA_AVR35, bfd_mach_avr35},
140 {"at90usb82", AVR_ISA_AVR35, bfd_mach_avr35},
141 {"at90usb162", AVR_ISA_AVR35, bfd_mach_avr35},
11908008
EW
142 {"atmega8u2", AVR_ISA_AVR35, bfd_mach_avr35},
143 {"atmega16u2", AVR_ISA_AVR35, bfd_mach_avr35},
144 {"atmega32u2", AVR_ISA_AVR35, bfd_mach_avr35},
28c9d252 145 {"atmega8", AVR_ISA_M8, bfd_mach_avr4},
7b21ac3f 146 {"atmega48", AVR_ISA_AVR4, bfd_mach_avr4},
e760a81b 147 {"atmega48a", AVR_ISA_AVR4, bfd_mach_avr4},
7b21ac3f
EW
148 {"atmega48p", AVR_ISA_AVR4, bfd_mach_avr4},
149 {"atmega88", AVR_ISA_AVR4, bfd_mach_avr4},
e760a81b 150 {"atmega88a", AVR_ISA_AVR4, bfd_mach_avr4},
7b21ac3f 151 {"atmega88p", AVR_ISA_AVR4, bfd_mach_avr4},
e760a81b 152 {"atmega88pa", AVR_ISA_AVR4, bfd_mach_avr4},
28c9d252
NC
153 {"atmega8515", AVR_ISA_M8, bfd_mach_avr4},
154 {"atmega8535", AVR_ISA_M8, bfd_mach_avr4},
7b21ac3f
EW
155 {"atmega8hva", AVR_ISA_AVR4, bfd_mach_avr4},
156 {"at90pwm1", AVR_ISA_AVR4, bfd_mach_avr4},
157 {"at90pwm2", AVR_ISA_AVR4, bfd_mach_avr4},
158 {"at90pwm2b", AVR_ISA_AVR4, bfd_mach_avr4},
159 {"at90pwm3", AVR_ISA_AVR4, bfd_mach_avr4},
160 {"at90pwm3b", AVR_ISA_AVR4, bfd_mach_avr4},
2b02f87c 161 {"at90pwm81", AVR_ISA_AVR4, bfd_mach_avr4},
7b21ac3f 162 {"atmega16", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 163 {"atmega16a", AVR_ISA_AVR5, bfd_mach_avr5},
28c9d252 164 {"atmega161", AVR_ISA_M161, bfd_mach_avr5},
7b21ac3f 165 {"atmega162", AVR_ISA_AVR5, bfd_mach_avr5},
28c9d252 166 {"atmega163", AVR_ISA_M161, bfd_mach_avr5},
e760a81b 167 {"atmega164a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
168 {"atmega164p", AVR_ISA_AVR5, bfd_mach_avr5},
169 {"atmega165", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 170 {"atmega165a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
171 {"atmega165p", AVR_ISA_AVR5, bfd_mach_avr5},
172 {"atmega168", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 173 {"atmega168a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
174 {"atmega168p", AVR_ISA_AVR5, bfd_mach_avr5},
175 {"atmega169", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 176 {"atmega169a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 177 {"atmega169p", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 178 {"atmega169pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
179 {"atmega32", AVR_ISA_AVR5, bfd_mach_avr5},
180 {"atmega323", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 181 {"atmega324a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 182 {"atmega324p", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 183 {"atmega324pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 184 {"atmega325", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 185 {"atmega325a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 186 {"atmega325p", AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 187 {"atmega325pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 188 {"atmega3250", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 189 {"atmega3250a",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 190 {"atmega3250p",AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 191 {"atmega3250pa",AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 192 {"atmega328", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
193 {"atmega328p", AVR_ISA_AVR5, bfd_mach_avr5},
194 {"atmega329", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 195 {"atmega329a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 196 {"atmega329p", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 197 {"atmega329pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 198 {"atmega3290", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 199 {"atmega3290a",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 200 {"atmega3290p",AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 201 {"atmega3290pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
202 {"atmega406", AVR_ISA_AVR5, bfd_mach_avr5},
203 {"atmega64", AVR_ISA_AVR5, bfd_mach_avr5},
204 {"atmega640", AVR_ISA_AVR5, bfd_mach_avr5},
205 {"atmega644", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 206 {"atmega644a", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 207 {"atmega644p", AVR_ISA_AVR5, bfd_mach_avr5},
8453da2e 208 {"atmega644pa",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 209 {"atmega645", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b
EW
210 {"atmega645a", AVR_ISA_AVR5, bfd_mach_avr5},
211 {"atmega645p", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 212 {"atmega649", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b
EW
213 {"atmega649a", AVR_ISA_AVR5, bfd_mach_avr5},
214 {"atmega649p", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 215 {"atmega6450", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b
EW
216 {"atmega6450a",AVR_ISA_AVR5, bfd_mach_avr5},
217 {"atmega6450p",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 218 {"atmega6490", AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b
EW
219 {"atmega6490a",AVR_ISA_AVR5, bfd_mach_avr5},
220 {"atmega6490p",AVR_ISA_AVR5, bfd_mach_avr5},
4d13caa0
NC
221 {"atmega64rfr2",AVR_ISA_AVR5, bfd_mach_avr5},
222 {"atmega644rfr2",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 223 {"atmega16hva",AVR_ISA_AVR5, bfd_mach_avr5},
e760a81b 224 {"atmega16hva2",AVR_ISA_AVR5, bfd_mach_avr5},
2b02f87c 225 {"atmega16hvb",AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 226 {"atmega16hvbrevb",AVR_ISA_AVR5,bfd_mach_avr5},
2b02f87c 227 {"atmega32hvb",AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 228 {"atmega32hvbrevb",AVR_ISA_AVR5,bfd_mach_avr5},
e760a81b 229 {"atmega64hve",AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
230 {"at90can32" , AVR_ISA_AVR5, bfd_mach_avr5},
231 {"at90can64" , AVR_ISA_AVR5, bfd_mach_avr5},
b8c610a7 232 {"at90pwm161", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
233 {"at90pwm216", AVR_ISA_AVR5, bfd_mach_avr5},
234 {"at90pwm316", AVR_ISA_AVR5, bfd_mach_avr5},
235 {"atmega32c1", AVR_ISA_AVR5, bfd_mach_avr5},
2b02f87c
NC
236 {"atmega64c1", AVR_ISA_AVR5, bfd_mach_avr5},
237 {"atmega16m1", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 238 {"atmega32m1", AVR_ISA_AVR5, bfd_mach_avr5},
2b02f87c
NC
239 {"atmega64m1", AVR_ISA_AVR5, bfd_mach_avr5},
240 {"atmega16u4", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f 241 {"atmega32u4", AVR_ISA_AVR5, bfd_mach_avr5},
2b02f87c 242 {"atmega32u6", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
243 {"at90usb646", AVR_ISA_AVR5, bfd_mach_avr5},
244 {"at90usb647", AVR_ISA_AVR5, bfd_mach_avr5},
2b02f87c 245 {"at90scr100", AVR_ISA_AVR5, bfd_mach_avr5},
28c9d252 246 {"at94k", AVR_ISA_94K, bfd_mach_avr5},
e760a81b 247 {"m3000", AVR_ISA_AVR5, bfd_mach_avr5},
7b21ac3f
EW
248 {"atmega128", AVR_ISA_AVR51, bfd_mach_avr51},
249 {"atmega1280", AVR_ISA_AVR51, bfd_mach_avr51},
250 {"atmega1281", AVR_ISA_AVR51, bfd_mach_avr51},
251 {"atmega1284p",AVR_ISA_AVR51, bfd_mach_avr51},
17f4880d 252 {"atmega128rfa1",AVR_ISA_AVR51, bfd_mach_avr51},
4d13caa0
NC
253 {"atmega128rfr2",AVR_ISA_AVR51, bfd_mach_avr51},
254 {"atmega1284rfr2",AVR_ISA_AVR51, bfd_mach_avr51},
7b21ac3f
EW
255 {"at90can128", AVR_ISA_AVR51, bfd_mach_avr51},
256 {"at90usb1286",AVR_ISA_AVR51, bfd_mach_avr51},
257 {"at90usb1287",AVR_ISA_AVR51, bfd_mach_avr51},
258 {"atmega2560", AVR_ISA_AVR6, bfd_mach_avr6},
259 {"atmega2561", AVR_ISA_AVR6, bfd_mach_avr6},
4d13caa0
NC
260 {"atmega256rfr2", AVR_ISA_AVR6, bfd_mach_avr6},
261 {"atmega2564rfr2", AVR_ISA_AVR6, bfd_mach_avr6},
8cc66334
EW
262 {"atxmega16a4", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
263 {"atxmega16d4", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
6f8a4444 264 {"atxmega16x1", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
8cc66334
EW
265 {"atxmega32a4", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
266 {"atxmega32d4", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
6f8a4444 267 {"atxmega32x1", AVR_ISA_XMEGA, bfd_mach_avrxmega2},
8cc66334
EW
268 {"atxmega64a3", AVR_ISA_XMEGA, bfd_mach_avrxmega4},
269 {"atxmega64d3", AVR_ISA_XMEGA, bfd_mach_avrxmega4},
270 {"atxmega64a1", AVR_ISA_XMEGA, bfd_mach_avrxmega5},
7bab7634 271 {"atxmega64a1u",AVR_ISA_XMEGAU, bfd_mach_avrxmega5},
8cc66334 272 {"atxmega128a3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
7bab7634 273 {"atxmega128b1", AVR_ISA_XMEGAU, bfd_mach_avrxmega6},
8cc66334
EW
274 {"atxmega128d3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
275 {"atxmega192a3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
276 {"atxmega192d3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
277 {"atxmega256a3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
278 {"atxmega256a3b",AVR_ISA_XMEGA, bfd_mach_avrxmega6},
7bab7634 279 {"atxmega256a3bu",AVR_ISA_XMEGAU, bfd_mach_avrxmega6},
8cc66334
EW
280 {"atxmega256d3", AVR_ISA_XMEGA, bfd_mach_avrxmega6},
281 {"atxmega128a1", AVR_ISA_XMEGA, bfd_mach_avrxmega7},
7bab7634 282 {"atxmega128a1u", AVR_ISA_XMEGAU, bfd_mach_avrxmega7},
adde6300
AM
283 {NULL, 0, 0}
284};
285
adde6300 286/* Current MCU type. */
7b21ac3f 287static struct mcu_type_s default_mcu = {"avr2", AVR_ISA_AVR2, bfd_mach_avr2};
dc191a8f 288static struct mcu_type_s * avr_mcu = & default_mcu;
adde6300 289
00d2865b
NC
290/* AVR target-specific switches. */
291struct avr_opt_s
292{
dc191a8f
NC
293 int all_opcodes; /* -mall-opcodes: accept all known AVR opcodes. */
294 int no_skip_bug; /* -mno-skip-bug: no warnings for skipping 2-word insns. */
295 int no_wrap; /* -mno-wrap: reject rjmp/rcall with 8K wrap-around. */
00d2865b
NC
296};
297
298static struct avr_opt_s avr_opt = { 0, 0, 0 };
299
adde6300
AM
300const char EXP_CHARS[] = "eE";
301const char FLT_CHARS[] = "dD";
dc191a8f
NC
302
303static void avr_set_arch (int);
adde6300
AM
304
305/* The target specific pseudo-ops which we support. */
306const pseudo_typeS md_pseudo_table[] =
307{
308 {"arch", avr_set_arch, 0},
309 { NULL, NULL, 0}
310};
311
312#define LDI_IMMEDIATE(x) (((x) & 0xf) | (((x) << 4) & 0xf00))
adde6300 313
dc191a8f
NC
314#define EXP_MOD_NAME(i) exp_mod[i].name
315#define EXP_MOD_RELOC(i) exp_mod[i].reloc
316#define EXP_MOD_NEG_RELOC(i) exp_mod[i].neg_reloc
317#define HAVE_PM_P(i) exp_mod[i].have_pm
adde6300
AM
318
319struct exp_mod_s
320{
dc191a8f
NC
321 char * name;
322 bfd_reloc_code_real_type reloc;
323 bfd_reloc_code_real_type neg_reloc;
324 int have_pm;
adde6300
AM
325};
326
c6a7ab1f
NC
327static struct exp_mod_s exp_mod[] =
328{
adde6300
AM
329 {"hh8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 1},
330 {"pm_hh8", BFD_RELOC_AVR_HH8_LDI_PM, BFD_RELOC_AVR_HH8_LDI_PM_NEG, 0},
331 {"hi8", BFD_RELOC_AVR_HI8_LDI, BFD_RELOC_AVR_HI8_LDI_NEG, 1},
332 {"pm_hi8", BFD_RELOC_AVR_HI8_LDI_PM, BFD_RELOC_AVR_HI8_LDI_PM_NEG, 0},
333 {"lo8", BFD_RELOC_AVR_LO8_LDI, BFD_RELOC_AVR_LO8_LDI_NEG, 1},
334 {"pm_lo8", BFD_RELOC_AVR_LO8_LDI_PM, BFD_RELOC_AVR_LO8_LDI_PM_NEG, 0},
df406460 335 {"hlo8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 0},
e4efb665 336 {"hhi8", BFD_RELOC_AVR_MS8_LDI, BFD_RELOC_AVR_MS8_LDI_NEG, 0},
adde6300
AM
337};
338
8ad7c533
NC
339/* A union used to store indicies into the exp_mod[] array
340 in a hash table which expects void * data types. */
341typedef union
342{
343 void * ptr;
344 int index;
345} mod_index;
346
adde6300
AM
347/* Opcode hash table. */
348static struct hash_control *avr_hash;
349
350/* Reloc modifiers hash control (hh8,hi8,lo8,pm_xx). */
351static struct hash_control *avr_mod_hash;
352
00d2865b 353#define OPTION_MMCU 'm'
dc191a8f
NC
354enum options
355{
356 OPTION_ALL_OPCODES = OPTION_MD_BASE + 1,
357 OPTION_NO_SKIP_BUG,
358 OPTION_NO_WRAP
359};
adde6300 360
c6a7ab1f
NC
361struct option md_longopts[] =
362{
00d2865b
NC
363 { "mmcu", required_argument, NULL, OPTION_MMCU },
364 { "mall-opcodes", no_argument, NULL, OPTION_ALL_OPCODES },
365 { "mno-skip-bug", no_argument, NULL, OPTION_NO_SKIP_BUG },
366 { "mno-wrap", no_argument, NULL, OPTION_NO_WRAP },
367 { NULL, no_argument, NULL, 0 }
adde6300 368};
adde6300 369
c6a7ab1f 370size_t md_longopts_size = sizeof (md_longopts);
00d2865b
NC
371
372/* Display nicely formatted list of known MCU names. */
c6a7ab1f 373
00d2865b 374static void
dc191a8f 375show_mcu_list (FILE *stream)
00d2865b
NC
376{
377 int i, x;
378
379 fprintf (stream, _("Known MCU names:"));
380 x = 1000;
1dab94dd 381
00d2865b
NC
382 for (i = 0; mcu_types[i].name; i++)
383 {
384 int len = strlen (mcu_types[i].name);
1dab94dd 385
00d2865b 386 x += len + 1;
1dab94dd 387
00d2865b 388 if (x < 75)
c6a7ab1f 389 fprintf (stream, " %s", mcu_types[i].name);
00d2865b
NC
390 else
391 {
392 fprintf (stream, "\n %s", mcu_types[i].name);
393 x = len + 2;
394 }
395 }
1dab94dd 396
c6a7ab1f 397 fprintf (stream, "\n");
00d2865b
NC
398}
399
adde6300 400static inline char *
dc191a8f 401skip_space (char *s)
adde6300
AM
402{
403 while (*s == ' ' || *s == '\t')
404 ++s;
405 return s;
406}
407
408/* Extract one word from FROM and copy it to TO. */
c6a7ab1f 409
adde6300
AM
410static char *
411extract_word (char *from, char *to, int limit)
412{
adde6300
AM
413 char *op_end;
414 int size = 0;
415
416 /* Drop leading whitespace. */
417 from = skip_space (from);
418 *to = 0;
c6a7ab1f 419
adde6300 420 /* Find the op code end. */
87975d2a 421 for (op_end = from; *op_end != 0 && is_part_of_name (*op_end);)
adde6300
AM
422 {
423 to[size++] = *op_end++;
424 if (size + 1 >= limit)
425 break;
426 }
1dab94dd 427
adde6300
AM
428 to[size] = 0;
429 return op_end;
430}
431
432int
dc191a8f
NC
433md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
434 asection *seg ATTRIBUTE_UNUSED)
adde6300
AM
435{
436 abort ();
437 return 0;
438}
439
440void
dc191a8f 441md_show_usage (FILE *stream)
adde6300 442{
00d2865b 443 fprintf (stream,
4fb8d1c6 444 _("AVR Assembler options:\n"
adde6300
AM
445 " -mmcu=[avr-name] select microcontroller variant\n"
446 " [avr-name] can be:\n"
7b21ac3f
EW
447 " avr1 - classic AVR core without data RAM\n"
448 " avr2 - classic AVR core with up to 8K program memory\n"
449 " avr25 - classic AVR core with up to 8K program memory\n"
450 " plus the MOVW instruction\n"
451 " avr3 - classic AVR core with up to 64K program memory\n"
452 " avr31 - classic AVR core with up to 128K program memory\n"
453 " avr35 - classic AVR core with up to 64K program memory\n"
454 " plus the MOVW instruction\n"
455 " avr4 - enhanced AVR core with up to 8K program memory\n"
456 " avr5 - enhanced AVR core with up to 64K program memory\n"
457 " avr51 - enhanced AVR core with up to 128K program memory\n"
458 " avr6 - enhanced AVR core with up to 256K program memory\n"
8cc66334
EW
459 " avrxmega3 - XMEGA, > 8K, <= 64K FLASH, > 64K RAM\n"
460 " avrxmega4 - XMEGA, > 64K, <= 128K FLASH, <= 64K RAM\n"
461 " avrxmega5 - XMEGA, > 64K, <= 128K FLASH, > 64K RAM\n"
462 " avrxmega6 - XMEGA, > 128K, <= 256K FLASH, <= 64K RAM\n"
463 " avrxmega7 - XMEGA, > 128K, <= 256K FLASH, > 64K RAM\n"
adde6300 464 " or immediate microcontroller name.\n"));
00d2865b
NC
465 fprintf (stream,
466 _(" -mall-opcodes accept all AVR opcodes, even if not supported by MCU\n"
467 " -mno-skip-bug disable warnings for skipping two-word instructions\n"
468 " (default for avr4, avr5)\n"
469 " -mno-wrap reject rjmp/rcall instructions with 8K wrap-around\n"
470 " (default for avr3, avr5)\n"));
471 show_mcu_list (stream);
adde6300
AM
472}
473
474static void
dc191a8f 475avr_set_arch (int dummy ATTRIBUTE_UNUSED)
adde6300 476{
dc191a8f 477 char str[20];
1dab94dd 478
adde6300 479 input_line_pointer = extract_word (input_line_pointer, str, 20);
00d2865b 480 md_parse_option (OPTION_MMCU, str);
adde6300
AM
481 bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
482}
483
484int
dc191a8f 485md_parse_option (int c, char *arg)
adde6300 486{
00d2865b 487 switch (c)
adde6300 488 {
00d2865b
NC
489 case OPTION_MMCU:
490 {
491 int i;
492 char *s = alloca (strlen (arg) + 1);
adde6300 493
00d2865b
NC
494 {
495 char *t = s;
496 char *arg1 = arg;
497
498 do
3882b010 499 *t = TOLOWER (*arg1++);
00d2865b
NC
500 while (*t++);
501 }
502
503 for (i = 0; mcu_types[i].name; ++i)
504 if (strcmp (mcu_types[i].name, s) == 0)
505 break;
adde6300 506
00d2865b
NC
507 if (!mcu_types[i].name)
508 {
509 show_mcu_list (stderr);
510 as_fatal (_("unknown MCU: %s\n"), arg);
511 }
65aa24b6 512
00d2865b
NC
513 /* It is OK to redefine mcu type within the same avr[1-5] bfd machine
514 type - this for allows passing -mmcu=... via gcc ASM_SPEC as well
515 as .arch ... in the asm output at the same time. */
00d2865b
NC
516 if (avr_mcu == &default_mcu || avr_mcu->mach == mcu_types[i].mach)
517 avr_mcu = &mcu_types[i];
518 else
519 as_fatal (_("redefinition of mcu type `%s' to `%s'"),
520 avr_mcu->name, mcu_types[i].name);
521 return 1;
522 }
523 case OPTION_ALL_OPCODES:
524 avr_opt.all_opcodes = 1;
525 return 1;
526 case OPTION_NO_SKIP_BUG:
527 avr_opt.no_skip_bug = 1;
528 return 1;
529 case OPTION_NO_WRAP:
530 avr_opt.no_wrap = 1;
adde6300
AM
531 return 1;
532 }
1dab94dd 533
adde6300
AM
534 return 0;
535}
536
537symbolS *
dc191a8f 538md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
adde6300 539{
dc191a8f 540 return NULL;
adde6300
AM
541}
542
adde6300 543char *
dc191a8f 544md_atof (int type, char *litP, int *sizeP)
adde6300 545{
499ac353 546 return ieee_md_atof (type, litP, sizeP, FALSE);
adde6300
AM
547}
548
549void
dc191a8f
NC
550md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
551 asection *sec ATTRIBUTE_UNUSED,
552 fragS *fragP ATTRIBUTE_UNUSED)
adde6300
AM
553{
554 abort ();
555}
556
adde6300 557void
dc191a8f 558md_begin (void)
adde6300 559{
df136245 560 unsigned int i;
adde6300 561 struct avr_opcodes_s *opcode;
dc191a8f 562
c6a7ab1f 563 avr_hash = hash_new ();
adde6300
AM
564
565 /* Insert unique names into hash table. This hash table then provides a
566 quick index to the first opcode with a particular name in the opcode
567 table. */
adde6300
AM
568 for (opcode = avr_opcodes; opcode->name; opcode++)
569 hash_insert (avr_hash, opcode->name, (char *) opcode);
570
571 avr_mod_hash = hash_new ();
572
dc191a8f 573 for (i = 0; i < ARRAY_SIZE (exp_mod); ++i)
8ad7c533
NC
574 {
575 mod_index m;
576
577 m.index = i + 10;
578 hash_insert (avr_mod_hash, EXP_MOD_NAME (i), m.ptr);
579 }
c6a7ab1f 580
adde6300
AM
581 bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
582}
583
df136245 584/* Resolve STR as a constant expression and return the result.
c6a7ab1f 585 If result greater than MAX then error. */
df136245
DC
586
587static unsigned int
dc191a8f 588avr_get_constant (char *str, int max)
df136245
DC
589{
590 expressionS ex;
dc191a8f 591
df136245
DC
592 str = skip_space (str);
593 input_line_pointer = str;
dc191a8f 594 expression (& ex);
df136245
DC
595
596 if (ex.X_op != O_constant)
597 as_bad (_("constant value required"));
598
599 if (ex.X_add_number > max || ex.X_add_number < 0)
73f4d86e 600 as_bad (_("number must be positive and less than %d"), max + 1);
1dab94dd 601
df136245
DC
602 return ex.X_add_number;
603}
604
dc191a8f 605/* Parse for ldd/std offset. */
df136245 606
dc191a8f
NC
607static void
608avr_offset_expression (expressionS *exp)
adde6300 609{
dc191a8f
NC
610 char *str = input_line_pointer;
611 char *tmp;
612 char op[8];
adde6300 613
dc191a8f
NC
614 tmp = str;
615 str = extract_word (str, op, sizeof (op));
616
617 input_line_pointer = tmp;
618 expression (exp);
619
620 /* Warn about expressions that fail to use lo8 (). */
621 if (exp->X_op == O_constant)
adde6300 622 {
dc191a8f 623 int x = exp->X_add_number;
28c9d252 624
dc191a8f
NC
625 if (x < -255 || x > 255)
626 as_warn (_("constant out of 8-bit range: %d"), x);
627 }
628}
adde6300 629
dc191a8f 630/* Parse ordinary expression. */
adde6300 631
dc191a8f
NC
632static char *
633parse_exp (char *s, expressionS *op)
634{
635 input_line_pointer = s;
636 expression (op);
637 if (op->X_op == O_absent)
638 as_bad (_("missing operand"));
639 return input_line_pointer;
640}
1dab94dd 641
dc191a8f
NC
642/* Parse special expressions (needed for LDI command):
643 xx8 (address)
644 xx8 (-address)
645 pm_xx8 (address)
646 pm_xx8 (-address)
647 where xx is: hh, hi, lo. */
adde6300 648
dc191a8f
NC
649static bfd_reloc_code_real_type
650avr_ldi_expression (expressionS *exp)
651{
652 char *str = input_line_pointer;
653 char *tmp;
654 char op[8];
655 int mod;
28c9d252
NC
656 int linker_stubs_should_be_generated = 0;
657
dc191a8f 658 tmp = str;
adde6300 659
dc191a8f 660 str = extract_word (str, op, sizeof (op));
adde6300 661
dc191a8f
NC
662 if (op[0])
663 {
8ad7c533 664 mod_index m;
28c9d252 665
8ad7c533
NC
666 m.ptr = hash_find (avr_mod_hash, op);
667 mod = m.index;
1dab94dd 668
dc191a8f
NC
669 if (mod)
670 {
671 int closes = 0;
b170af93 672
dc191a8f
NC
673 mod -= 10;
674 str = skip_space (str);
00d2865b 675
dc191a8f
NC
676 if (*str == '(')
677 {
28c9d252 678 bfd_reloc_code_real_type reloc_to_return;
dc191a8f 679 int neg_p = 0;
00d2865b 680
dc191a8f 681 ++str;
00d2865b 682
dc191a8f 683 if (strncmp ("pm(", str, 3) == 0
28c9d252
NC
684 || strncmp ("gs(",str,3) == 0
685 || strncmp ("-(gs(",str,5) == 0
dc191a8f
NC
686 || strncmp ("-(pm(", str, 5) == 0)
687 {
688 if (HAVE_PM_P (mod))
689 {
690 ++mod;
691 ++closes;
692 }
693 else
694 as_bad (_("illegal expression"));
b170af93 695
28c9d252
NC
696 if (str[0] == 'g' || str[2] == 'g')
697 linker_stubs_should_be_generated = 1;
698
dc191a8f
NC
699 if (*str == '-')
700 {
701 neg_p = 1;
702 ++closes;
703 str += 5;
704 }
705 else
706 str += 3;
707 }
adde6300 708
dc191a8f
NC
709 if (*str == '-' && *(str + 1) == '(')
710 {
711 neg_p ^= 1;
712 ++closes;
713 str += 2;
714 }
750bce0e 715
dc191a8f
NC
716 input_line_pointer = str;
717 expression (exp);
750bce0e 718
dc191a8f
NC
719 do
720 {
721 if (*input_line_pointer != ')')
722 {
723 as_bad (_("`)' required"));
724 break;
725 }
726 input_line_pointer++;
727 }
728 while (closes--);
729
28c9d252
NC
730 reloc_to_return =
731 neg_p ? EXP_MOD_NEG_RELOC (mod) : EXP_MOD_RELOC (mod);
732 if (linker_stubs_should_be_generated)
733 {
734 switch (reloc_to_return)
735 {
736 case BFD_RELOC_AVR_LO8_LDI_PM:
737 reloc_to_return = BFD_RELOC_AVR_LO8_LDI_GS;
738 break;
739 case BFD_RELOC_AVR_HI8_LDI_PM:
740 reloc_to_return = BFD_RELOC_AVR_HI8_LDI_GS;
741 break;
742
743 default:
0a903bab
NC
744 /* PR 5523: Do not generate a warning here,
745 legitimate code can trigger this case. */
746 break;
28c9d252
NC
747 }
748 }
749 return reloc_to_return;
dc191a8f
NC
750 }
751 }
752 }
750bce0e
NC
753
754 input_line_pointer = tmp;
755 expression (exp);
756
757 /* Warn about expressions that fail to use lo8 (). */
758 if (exp->X_op == O_constant)
759 {
760 int x = exp->X_add_number;
dc191a8f 761
750bce0e
NC
762 if (x < -255 || x > 255)
763 as_warn (_("constant out of 8-bit range: %d"), x);
764 }
dc191a8f
NC
765
766 return BFD_RELOC_AVR_LDI;
750bce0e
NC
767}
768
df136245 769/* Parse one instruction operand.
c6a7ab1f
NC
770 Return operand bitmask. Also fixups can be generated. */
771
adde6300 772static unsigned int
dc191a8f
NC
773avr_operand (struct avr_opcodes_s *opcode,
774 int where,
775 char *op,
776 char **line)
adde6300 777{
adde6300 778 expressionS op_expr;
df136245
DC
779 unsigned int op_mask = 0;
780 char *str = skip_space (*line);
adde6300 781
adde6300
AM
782 switch (*op)
783 {
784 /* Any register operand. */
785 case 'w':
786 case 'd':
787 case 'r':
b170af93
DC
788 case 'a':
789 case 'v':
c6a7ab1f
NC
790 if (*str == 'r' || *str == 'R')
791 {
792 char r_name[20];
1dab94dd 793
c6a7ab1f 794 str = extract_word (str, r_name, sizeof (r_name));
65b1d096 795 op_mask = 0xff;
3882b010 796 if (ISDIGIT (r_name[1]))
c6a7ab1f
NC
797 {
798 if (r_name[2] == '\0')
799 op_mask = r_name[1] - '0';
800 else if (r_name[1] != '0'
3882b010 801 && ISDIGIT (r_name[2])
c6a7ab1f
NC
802 && r_name[3] == '\0')
803 op_mask = (r_name[1] - '0') * 10 + r_name[2] - '0';
804 }
805 }
806 else
807 {
808 op_mask = avr_get_constant (str, 31);
809 str = input_line_pointer;
810 }
1dab94dd 811
c6a7ab1f
NC
812 if (op_mask <= 31)
813 {
814 switch (*op)
815 {
816 case 'a':
817 if (op_mask < 16 || op_mask > 23)
818 as_bad (_("register r16-r23 required"));
819 op_mask -= 16;
820 break;
1dab94dd 821
c6a7ab1f
NC
822 case 'd':
823 if (op_mask < 16)
824 as_bad (_("register number above 15 required"));
825 op_mask -= 16;
826 break;
1dab94dd 827
c6a7ab1f
NC
828 case 'v':
829 if (op_mask & 1)
830 as_bad (_("even register number required"));
831 op_mask >>= 1;
832 break;
1dab94dd 833
c6a7ab1f 834 case 'w':
65b1d096 835 if ((op_mask & 1) || op_mask < 24)
c6a7ab1f 836 as_bad (_("register r24, r26, r28 or r30 required"));
65b1d096 837 op_mask = (op_mask - 24) >> 1;
c6a7ab1f
NC
838 break;
839 }
840 break;
841 }
842 as_bad (_("register name or number from 0 to 31 required"));
adde6300
AM
843 break;
844
845 case 'e':
846 {
847 char c;
1dab94dd 848
adde6300
AM
849 if (*str == '-')
850 {
c6a7ab1f 851 str = skip_space (str + 1);
adde6300
AM
852 op_mask = 0x1002;
853 }
3882b010 854 c = TOLOWER (*str);
adde6300
AM
855 if (c == 'x')
856 op_mask |= 0x100c;
857 else if (c == 'y')
858 op_mask |= 0x8;
859 else if (c != 'z')
00d2865b 860 as_bad (_("pointer register (X, Y or Z) required"));
adde6300 861
c6a7ab1f 862 str = skip_space (str + 1);
adde6300
AM
863 if (*str == '+')
864 {
865 ++str;
866 if (op_mask & 2)
00d2865b 867 as_bad (_("cannot both predecrement and postincrement"));
adde6300
AM
868 op_mask |= 0x1001;
869 }
e38c9cc2 870
1188e082 871 /* avr1 can do "ld r,Z" and "st Z,r" but no other pointer
e38c9cc2 872 registers, no predecrement, no postincrement. */
00d2865b
NC
873 if (!avr_opt.all_opcodes && (op_mask & 0x100F)
874 && !(avr_mcu->isa & AVR_ISA_SRAM))
875 as_bad (_("addressing mode not supported"));
adde6300
AM
876 }
877 break;
878
b170af93 879 case 'z':
c6a7ab1f
NC
880 if (*str == '-')
881 as_bad (_("can't predecrement"));
1dab94dd 882
c6a7ab1f
NC
883 if (! (*str == 'z' || *str == 'Z'))
884 as_bad (_("pointer register Z required"));
1dab94dd 885
c6a7ab1f
NC
886 str = skip_space (str + 1);
887
888 if (*str == '+')
889 {
890 ++str;
8cc66334
EW
891 char *s;
892 for (s = opcode->opcode; *s; ++s)
893 {
894 if (*s == '+')
895 op_mask |= (1 << (15 - (s - opcode->opcode)));
896 }
c6a7ab1f 897 }
d669d37f
NC
898
899 /* attiny26 can do "lpm" and "lpm r,Z" but not "lpm r,Z+". */
900 if (!avr_opt.all_opcodes
901 && (op_mask & 0x0001)
902 && !(avr_mcu->isa & AVR_ISA_MOVW))
903 as_bad (_("postincrement not supported"));
b170af93
DC
904 break;
905
adde6300
AM
906 case 'b':
907 {
3882b010 908 char c = TOLOWER (*str++);
1dab94dd 909
adde6300
AM
910 if (c == 'y')
911 op_mask |= 0x8;
912 else if (c != 'z')
00d2865b 913 as_bad (_("pointer register (Y or Z) required"));
adde6300
AM
914 str = skip_space (str);
915 if (*str++ == '+')
916 {
750bce0e
NC
917 input_line_pointer = str;
918 avr_offset_expression (& op_expr);
adde6300 919 str = input_line_pointer;
750bce0e
NC
920 fix_new_exp (frag_now, where, 3,
921 &op_expr, FALSE, BFD_RELOC_AVR_6);
adde6300
AM
922 }
923 }
924 break;
925
926 case 'h':
c6a7ab1f
NC
927 str = parse_exp (str, &op_expr);
928 fix_new_exp (frag_now, where, opcode->insn_size * 2,
b34976b6 929 &op_expr, FALSE, BFD_RELOC_AVR_CALL);
adde6300
AM
930 break;
931
932 case 'L':
c6a7ab1f
NC
933 str = parse_exp (str, &op_expr);
934 fix_new_exp (frag_now, where, opcode->insn_size * 2,
b34976b6 935 &op_expr, TRUE, BFD_RELOC_AVR_13_PCREL);
adde6300
AM
936 break;
937
938 case 'l':
c6a7ab1f
NC
939 str = parse_exp (str, &op_expr);
940 fix_new_exp (frag_now, where, opcode->insn_size * 2,
b34976b6 941 &op_expr, TRUE, BFD_RELOC_AVR_7_PCREL);
adde6300
AM
942 break;
943
944 case 'i':
c6a7ab1f
NC
945 str = parse_exp (str, &op_expr);
946 fix_new_exp (frag_now, where + 2, opcode->insn_size * 2,
b34976b6 947 &op_expr, FALSE, BFD_RELOC_16);
adde6300
AM
948 break;
949
950 case 'M':
951 {
952 bfd_reloc_code_real_type r_type;
1dab94dd 953
c6a7ab1f
NC
954 input_line_pointer = str;
955 r_type = avr_ldi_expression (&op_expr);
956 str = input_line_pointer;
adde6300 957 fix_new_exp (frag_now, where, 3,
b34976b6 958 &op_expr, FALSE, r_type);
adde6300
AM
959 }
960 break;
961
962 case 'n':
963 {
964 unsigned int x;
1dab94dd 965
adde6300
AM
966 x = ~avr_get_constant (str, 255);
967 str = input_line_pointer;
968 op_mask |= (x & 0xf) | ((x << 4) & 0xf00);
969 }
970 break;
971
972 case 'K':
750bce0e
NC
973 input_line_pointer = str;
974 avr_offset_expression (& op_expr);
975 str = input_line_pointer;
976 fix_new_exp (frag_now, where, 3,
977 & op_expr, FALSE, BFD_RELOC_AVR_6_ADIW);
adde6300
AM
978 break;
979
980 case 'S':
981 case 's':
982 {
983 unsigned int x;
1dab94dd 984
adde6300
AM
985 x = avr_get_constant (str, 7);
986 str = input_line_pointer;
987 if (*op == 'S')
988 x <<= 4;
989 op_mask |= x;
990 }
991 break;
992
993 case 'P':
994 {
995 unsigned int x;
1dab94dd 996
adde6300
AM
997 x = avr_get_constant (str, 63);
998 str = input_line_pointer;
999 op_mask |= (x & 0xf) | ((x & 0x30) << 5);
1000 }
1001 break;
1002
1003 case 'p':
1004 {
1005 unsigned int x;
1dab94dd 1006
adde6300
AM
1007 x = avr_get_constant (str, 31);
1008 str = input_line_pointer;
1009 op_mask |= x << 3;
1010 }
1011 break;
1dab94dd 1012
8cc66334
EW
1013 case 'E':
1014 {
1015 unsigned int x;
1016
1017 x = avr_get_constant (str, 15);
1018 str = input_line_pointer;
1019 op_mask |= (x << 4);
1020 }
1021 break;
99700d6f 1022
1188e082
DC
1023 case '?':
1024 break;
1dab94dd 1025
adde6300 1026 default:
00d2865b 1027 as_bad (_("unknown constraint `%c'"), *op);
adde6300 1028 }
1dab94dd 1029
adde6300
AM
1030 *line = str;
1031 return op_mask;
1032}
1033
dc191a8f
NC
1034/* Parse instruction operands.
1035 Return binary opcode. */
1036
1037static unsigned int
1038avr_operands (struct avr_opcodes_s *opcode, char **line)
1039{
1040 char *op = opcode->constraints;
1041 unsigned int bin = opcode->bin_opcode;
1042 char *frag = frag_more (opcode->insn_size * 2);
1043 char *str = *line;
1044 int where = frag - frag_now->fr_literal;
1045 static unsigned int prev = 0; /* Previous opcode. */
1046
1047 /* Opcode have operands. */
1048 if (*op)
1049 {
1050 unsigned int reg1 = 0;
1051 unsigned int reg2 = 0;
1052 int reg1_present = 0;
1053 int reg2_present = 0;
1054
1055 /* Parse first operand. */
1056 if (REGISTER_P (*op))
1057 reg1_present = 1;
1058 reg1 = avr_operand (opcode, where, op, &str);
1059 ++op;
1060
1061 /* Parse second operand. */
1062 if (*op)
1063 {
1064 if (*op == ',')
1065 ++op;
1066
1067 if (*op == '=')
1068 {
1069 reg2 = reg1;
1070 reg2_present = 1;
1071 }
1072 else
1073 {
1074 if (REGISTER_P (*op))
1075 reg2_present = 1;
1076
1077 str = skip_space (str);
1078 if (*str++ != ',')
1079 as_bad (_("`,' required"));
1080 str = skip_space (str);
1081
1082 reg2 = avr_operand (opcode, where, op, &str);
1083 }
1084
1085 if (reg1_present && reg2_present)
1086 reg2 = (reg2 & 0xf) | ((reg2 << 5) & 0x200);
1087 else if (reg2_present)
1088 reg2 <<= 4;
1089 }
1090 if (reg1_present)
1091 reg1 <<= 4;
1092 bin |= reg1 | reg2;
1093 }
1094
1095 /* Detect undefined combinations (like ld r31,Z+). */
1096 if (!avr_opt.all_opcodes && AVR_UNDEF_P (bin))
1097 as_warn (_("undefined combination of operands"));
1098
1099 if (opcode->insn_size == 2)
1100 {
1101 /* Warn if the previous opcode was cpse/sbic/sbis/sbrc/sbrs
1102 (AVR core bug, fixed in the newer devices). */
1103 if (!(avr_opt.no_skip_bug ||
1104 (avr_mcu->isa & (AVR_ISA_MUL | AVR_ISA_MOVW)))
1105 && AVR_SKIP_P (prev))
1106 as_warn (_("skipping two-word instruction"));
1107
1108 bfd_putl32 ((bfd_vma) bin, frag);
1109 }
1110 else
1111 bfd_putl16 ((bfd_vma) bin, frag);
1112
1113 prev = bin;
1114 *line = str;
1115 return bin;
1116}
1117
adde6300
AM
1118/* GAS will call this function for each section at the end of the assembly,
1119 to permit the CPU backend to adjust the alignment of a section. */
c6a7ab1f 1120
adde6300 1121valueT
dc191a8f 1122md_section_align (asection *seg, valueT addr)
adde6300
AM
1123{
1124 int align = bfd_get_section_alignment (stdoutput, seg);
1125 return ((addr + (1 << align) - 1) & (-1 << align));
1126}
1127
1128/* If you define this macro, it should return the offset between the
1129 address of a PC relative fixup and the position from which the PC
1130 relative adjustment should be made. On many processors, the base
1131 of a PC relative instruction is the next instruction, so this
1132 macro would return the length of an instruction. */
c6a7ab1f 1133
adde6300 1134long
dc191a8f 1135md_pcrel_from_section (fixS *fixp, segT sec)
adde6300 1136{
c6a7ab1f 1137 if (fixp->fx_addsy != (symbolS *) NULL
adde6300
AM
1138 && (!S_IS_DEFINED (fixp->fx_addsy)
1139 || (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
1140 return 0;
1dab94dd 1141
adde6300
AM
1142 return fixp->fx_frag->fr_address + fixp->fx_where;
1143}
1144
1145/* GAS will call this for each fixup. It should store the correct
c6a7ab1f
NC
1146 value in the object file. */
1147
94f592af 1148void
dc191a8f 1149md_apply_fix (fixS *fixP, valueT * valP, segT seg)
adde6300
AM
1150{
1151 unsigned char *where;
1152 unsigned long insn;
a161fe53 1153 long value = *valP;
adde6300 1154
94f592af
NC
1155 if (fixP->fx_addsy == (symbolS *) NULL)
1156 fixP->fx_done = 1;
1157
87733541
AM
1158 else if (fixP->fx_pcrel)
1159 {
1160 segT s = S_GET_SEGMENT (fixP->fx_addsy);
1161
1162 if (s == seg || s == absolute_section)
1163 {
1164 value += S_GET_VALUE (fixP->fx_addsy);
1165 fixP->fx_done = 1;
1166 }
1167 }
1168
a161fe53
AM
1169 /* We don't actually support subtracting a symbol. */
1170 if (fixP->fx_subsy != (symbolS *) NULL)
1171 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1dab94dd 1172
94f592af 1173 switch (fixP->fx_r_type)
adde6300
AM
1174 {
1175 default:
94f592af 1176 fixP->fx_no_overflow = 1;
adde6300
AM
1177 break;
1178 case BFD_RELOC_AVR_7_PCREL:
1179 case BFD_RELOC_AVR_13_PCREL:
1180 case BFD_RELOC_32:
1181 case BFD_RELOC_16:
1182 case BFD_RELOC_AVR_CALL:
1183 break;
1184 }
1185
94f592af 1186 if (fixP->fx_done)
adde6300
AM
1187 {
1188 /* Fetch the instruction, insert the fully resolved operand
1189 value, and stuff the instruction back again. */
2132e3a3 1190 where = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
adde6300
AM
1191 insn = bfd_getl16 (where);
1192
94f592af 1193 switch (fixP->fx_r_type)
adde6300
AM
1194 {
1195 case BFD_RELOC_AVR_7_PCREL:
1196 if (value & 1)
94f592af 1197 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300 1198 _("odd address operand: %ld"), value);
1dab94dd 1199
adde6300
AM
1200 /* Instruction addresses are always right-shifted by 1. */
1201 value >>= 1;
1202 --value; /* Correct PC. */
1dab94dd 1203
adde6300 1204 if (value < -64 || value > 63)
94f592af 1205 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300
AM
1206 _("operand out of range: %ld"), value);
1207 value = (value << 3) & 0x3f8;
1208 bfd_putl16 ((bfd_vma) (value | insn), where);
1209 break;
1210
1211 case BFD_RELOC_AVR_13_PCREL:
1212 if (value & 1)
94f592af 1213 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300 1214 _("odd address operand: %ld"), value);
1dab94dd 1215
adde6300
AM
1216 /* Instruction addresses are always right-shifted by 1. */
1217 value >>= 1;
1218 --value; /* Correct PC. */
adde6300
AM
1219
1220 if (value < -2048 || value > 2047)
1221 {
65aa24b6 1222 /* No wrap for devices with >8K of program memory. */
00d2865b 1223 if ((avr_mcu->isa & AVR_ISA_MEGA) || avr_opt.no_wrap)
94f592af 1224 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300
AM
1225 _("operand out of range: %ld"), value);
1226 }
1227
1228 value &= 0xfff;
1229 bfd_putl16 ((bfd_vma) (value | insn), where);
1230 break;
1231
1232 case BFD_RELOC_32:
0b649256 1233 bfd_putl32 ((bfd_vma) value, where);
adde6300
AM
1234 break;
1235
1236 case BFD_RELOC_16:
1237 bfd_putl16 ((bfd_vma) value, where);
1238 break;
1239
17e57237
NC
1240 case BFD_RELOC_8:
1241 if (value > 255 || value < -128)
1242 as_warn_where (fixP->fx_file, fixP->fx_line,
1243 _("operand out of range: %ld"), value);
1244 *where = value;
1245 break;
1246
adde6300 1247 case BFD_RELOC_AVR_16_PM:
c6a7ab1f 1248 bfd_putl16 ((bfd_vma) (value >> 1), where);
adde6300
AM
1249 break;
1250
750bce0e
NC
1251 case BFD_RELOC_AVR_LDI:
1252 if (value > 255)
1253 as_bad_where (fixP->fx_file, fixP->fx_line,
1254 _("operand out of range: %ld"), value);
1255 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
1256 break;
1257
1258 case BFD_RELOC_AVR_6:
1259 if ((value > 63) || (value < 0))
1260 as_bad_where (fixP->fx_file, fixP->fx_line,
1261 _("operand out of range: %ld"), value);
1262 bfd_putl16 ((bfd_vma) insn | ((value & 7) | ((value & (3 << 3)) << 7) | ((value & (1 << 5)) << 8)), where);
1263 break;
1264
1265 case BFD_RELOC_AVR_6_ADIW:
1266 if ((value > 63) || (value < 0))
1267 as_bad_where (fixP->fx_file, fixP->fx_line,
1268 _("operand out of range: %ld"), value);
1269 bfd_putl16 ((bfd_vma) insn | (value & 0xf) | ((value & 0x30) << 2), where);
1270 break;
1271
adde6300
AM
1272 case BFD_RELOC_AVR_LO8_LDI:
1273 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
1274 break;
1275
adde6300
AM
1276 case BFD_RELOC_AVR_HI8_LDI:
1277 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 8), where);
1278 break;
1279
df406460 1280 case BFD_RELOC_AVR_MS8_LDI:
adde6300
AM
1281 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 24), where);
1282 break;
1283
1284 case BFD_RELOC_AVR_HH8_LDI:
1285 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 16), where);
1286 break;
1287
1288 case BFD_RELOC_AVR_LO8_LDI_NEG:
1289 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value), where);
1290 break;
1291
adde6300
AM
1292 case BFD_RELOC_AVR_HI8_LDI_NEG:
1293 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 8), where);
1294 break;
1295
df406460 1296 case BFD_RELOC_AVR_MS8_LDI_NEG:
adde6300
AM
1297 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 24), where);
1298 break;
1299
1300 case BFD_RELOC_AVR_HH8_LDI_NEG:
1301 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 16), where);
1302 break;
1303
1304 case BFD_RELOC_AVR_LO8_LDI_PM:
1305 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 1), where);
1306 break;
1307
1308 case BFD_RELOC_AVR_HI8_LDI_PM:
1309 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 9), where);
1310 break;
1311
1312 case BFD_RELOC_AVR_HH8_LDI_PM:
1313 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 17), where);
1314 break;
1315
1316 case BFD_RELOC_AVR_LO8_LDI_PM_NEG:
1317 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 1), where);
1318 break;
1319
1320 case BFD_RELOC_AVR_HI8_LDI_PM_NEG:
1321 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 9), where);
1322 break;
1323
1324 case BFD_RELOC_AVR_HH8_LDI_PM_NEG:
1325 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 17), where);
1326 break;
1327
1328 case BFD_RELOC_AVR_CALL:
1329 {
1330 unsigned long x;
1dab94dd 1331
adde6300
AM
1332 x = bfd_getl16 (where);
1333 if (value & 1)
94f592af 1334 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300
AM
1335 _("odd address operand: %ld"), value);
1336 value >>= 1;
1337 x |= ((value & 0x10000) | ((value << 3) & 0x1f00000)) >> 16;
1338 bfd_putl16 ((bfd_vma) x, where);
c6a7ab1f 1339 bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
adde6300
AM
1340 }
1341 break;
1342
99700d6f
NC
1343 case BFD_RELOC_AVR_8_LO:
1344 *where = 0xff & value;
1345 break;
1346
1347 case BFD_RELOC_AVR_8_HI:
1348 *where = 0xff & (value >> 8);
1349 break;
1350
40551fb8 1351 case BFD_RELOC_AVR_8_HLO:
99700d6f
NC
1352 *where = 0xff & (value >> 16);
1353 break;
1354
1355 default:
c6a7ab1f 1356 as_fatal (_("line %d: unknown relocation type: 0x%x"),
94f592af 1357 fixP->fx_line, fixP->fx_r_type);
adde6300
AM
1358 break;
1359 }
1360 }
1361 else
1362 {
a61a9fbc 1363 switch ((int) fixP->fx_r_type)
adde6300
AM
1364 {
1365 case -BFD_RELOC_AVR_HI8_LDI_NEG:
1366 case -BFD_RELOC_AVR_HI8_LDI:
1367 case -BFD_RELOC_AVR_LO8_LDI_NEG:
1368 case -BFD_RELOC_AVR_LO8_LDI:
94f592af 1369 as_bad_where (fixP->fx_file, fixP->fx_line,
adde6300 1370 _("only constant expression allowed"));
94f592af 1371 fixP->fx_done = 1;
adde6300
AM
1372 break;
1373 default:
1374 break;
1375 }
adde6300 1376 }
adde6300
AM
1377}
1378
7be1c489
AM
1379/* GAS will call this to generate a reloc, passing the resulting reloc
1380 to `bfd_install_relocation'. This currently works poorly, as
1381 `bfd_install_relocation' often does the wrong thing, and instances of
1382 `tc_gen_reloc' have been written to work around the problems, which
1383 in turns makes it difficult to fix `bfd_install_relocation'. */
adde6300
AM
1384
1385/* If while processing a fixup, a reloc really needs to be created
1386 then it is done here. */
1387
1388arelent *
dc191a8f
NC
1389tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
1390 fixS *fixp)
adde6300
AM
1391{
1392 arelent *reloc;
1393
94d4433a 1394 if (fixp->fx_subsy != NULL)
df406460 1395 {
94d4433a 1396 as_bad_where (fixp->fx_file, fixp->fx_line, _("expression too complex"));
df406460
NC
1397 return NULL;
1398 }
1399
dc191a8f 1400 reloc = xmalloc (sizeof (arelent));
adde6300 1401
dc191a8f 1402 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
adde6300
AM
1403 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1404
1405 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1406 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1407 if (reloc->howto == (reloc_howto_type *) NULL)
1408 {
1409 as_bad_where (fixp->fx_file, fixp->fx_line,
c6a7ab1f
NC
1410 _("reloc %d not supported by object file format"),
1411 (int) fixp->fx_r_type);
adde6300
AM
1412 return NULL;
1413 }
1414
1415 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1416 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1417 reloc->address = fixp->fx_offset;
1418
1419 reloc->addend = fixp->fx_offset;
1420
1421 return reloc;
1422}
1423
adde6300 1424void
dc191a8f 1425md_assemble (char *str)
adde6300 1426{
c6a7ab1f 1427 struct avr_opcodes_s *opcode;
adde6300
AM
1428 char op[11];
1429
c6a7ab1f 1430 str = skip_space (extract_word (str, op, sizeof (op)));
adde6300
AM
1431
1432 if (!op[0])
00d2865b 1433 as_bad (_("can't find opcode "));
adde6300
AM
1434
1435 opcode = (struct avr_opcodes_s *) hash_find (avr_hash, op);
1436
1437 if (opcode == NULL)
1438 {
00d2865b 1439 as_bad (_("unknown opcode `%s'"), op);
adde6300
AM
1440 return;
1441 }
1442
b170af93 1443 /* Special case for opcodes with optional operands (lpm, elpm) -
1188e082 1444 version with operands exists in avr_opcodes[] in the next entry. */
c6a7ab1f 1445
1188e082
DC
1446 if (*str && *opcode->constraints == '?')
1447 ++opcode;
b170af93 1448
00d2865b
NC
1449 if (!avr_opt.all_opcodes && (opcode->isa & avr_mcu->isa) != opcode->isa)
1450 as_bad (_("illegal opcode %s for mcu %s"), opcode->name, avr_mcu->name);
adde6300 1451
d4f4f3fb
AM
1452 dwarf2_emit_insn (0);
1453
adde6300
AM
1454 /* We used to set input_line_pointer to the result of get_operands,
1455 but that is wrong. Our caller assumes we don't change it. */
1456 {
1457 char *t = input_line_pointer;
dc191a8f 1458
adde6300 1459 avr_operands (opcode, &str);
b170af93 1460 if (*skip_space (str))
00d2865b 1461 as_bad (_("garbage at end of line"));
adde6300
AM
1462 input_line_pointer = t;
1463 }
1464}
1465
99700d6f
NC
1466typedef struct
1467{
1468 /* Name of the expression modifier allowed with .byte, .word, etc. */
1469 const char *name;
1470
1471 /* Only allowed with n bytes of data. */
1472 int nbytes;
1473
1474 /* Associated RELOC. */
1475 bfd_reloc_code_real_type reloc;
1476
1477 /* Part of the error message. */
1478 const char *error;
1479} exp_mod_data_t;
1480
1481static const exp_mod_data_t exp_mod_data[] =
1482{
1483 /* Default, must be first. */
1484 { "", 0, BFD_RELOC_16, "" },
1485 /* Divides by 2 to get word address. Generate Stub. */
1486 { "gs", 2, BFD_RELOC_AVR_16_PM, "`gs' " },
1487 { "pm", 2, BFD_RELOC_AVR_16_PM, "`pm' " },
1488 /* The following are used together with avr-gcc's __memx address space
1489 in order to initialize a 24-bit pointer variable with a 24-bit address.
40551fb8
NC
1490 For address in flash, hlo8 will contain the flash segment if the
1491 symbol is located in flash. If the symbol is located in RAM; hlo8
99700d6f
NC
1492 will contain 0x80 which matches avr-gcc's notion of how 24-bit RAM/flash
1493 addresses linearize address space. */
1494 { "lo8", 1, BFD_RELOC_AVR_8_LO, "`lo8' " },
1495 { "hi8", 1, BFD_RELOC_AVR_8_HI, "`hi8' " },
40551fb8
NC
1496 { "hlo8", 1, BFD_RELOC_AVR_8_HLO, "`hlo8' " },
1497 { "hh8", 1, BFD_RELOC_AVR_8_HLO, "`hh8' " },
99700d6f
NC
1498 /* End of list. */
1499 { NULL, 0, 0, NULL }
1500};
1501
1502/* Data to pass between `avr_parse_cons_expression' and `avr_cons_fix_new'. */
1503static const exp_mod_data_t *pexp_mod_data = &exp_mod_data[0];
adde6300 1504
99700d6f
NC
1505/* Parse special CONS expression: pm (expression) or alternatively
1506 gs (expression). These are used for addressing program memory. Moreover,
40551fb8 1507 define lo8 (expression), hi8 (expression) and hlo8 (expression). */
c6a7ab1f 1508
adde6300 1509void
dc191a8f 1510avr_parse_cons_expression (expressionS *exp, int nbytes)
adde6300 1511{
99700d6f 1512 const exp_mod_data_t *pexp = &exp_mod_data[0];
c6a7ab1f 1513 char *tmp;
adde6300 1514
99700d6f 1515 pexp_mod_data = pexp;
adde6300
AM
1516
1517 tmp = input_line_pointer = skip_space (input_line_pointer);
1518
99700d6f
NC
1519 /* The first entry of exp_mod_data[] contains an entry if no
1520 expression modifier is present. Skip it. */
1521
1522 for (pexp++; pexp->name; pexp++)
adde6300 1523 {
99700d6f 1524 int len = strlen (pexp->name);
1dab94dd 1525
99700d6f
NC
1526 if (nbytes == pexp->nbytes
1527 && strncasecmp (input_line_pointer, pexp->name, len) == 0)
adde6300
AM
1528 {
1529 input_line_pointer = skip_space (input_line_pointer + len);
1dab94dd 1530
adde6300
AM
1531 if (*input_line_pointer == '(')
1532 {
1533 input_line_pointer = skip_space (input_line_pointer + 1);
99700d6f 1534 pexp_mod_data = pexp;
adde6300 1535 expression (exp);
1dab94dd 1536
adde6300
AM
1537 if (*input_line_pointer == ')')
1538 ++input_line_pointer;
1539 else
1540 {
00d2865b 1541 as_bad (_("`)' required"));
99700d6f 1542 pexp_mod_data = &exp_mod_data[0];
adde6300 1543 }
1dab94dd 1544
adde6300
AM
1545 return;
1546 }
1dab94dd 1547
adde6300 1548 input_line_pointer = tmp;
99700d6f
NC
1549
1550 break;
adde6300
AM
1551 }
1552 }
1dab94dd 1553
adde6300
AM
1554 expression (exp);
1555}
1556
1557void
dc191a8f
NC
1558avr_cons_fix_new (fragS *frag,
1559 int where,
1560 int nbytes,
1561 expressionS *exp)
adde6300 1562{
99700d6f
NC
1563 int bad = 0;
1564
1565 switch (pexp_mod_data->reloc)
adde6300 1566 {
99700d6f 1567 default:
17e57237
NC
1568 if (nbytes == 1)
1569 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_8);
1570 else if (nbytes == 2)
b34976b6 1571 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_16);
adde6300 1572 else if (nbytes == 4)
b34976b6 1573 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_32);
adde6300 1574 else
99700d6f
NC
1575 bad = 1;
1576 break;
1577
1578 case BFD_RELOC_AVR_16_PM:
1579 case BFD_RELOC_AVR_8_LO:
1580 case BFD_RELOC_AVR_8_HI:
40551fb8 1581 case BFD_RELOC_AVR_8_HLO:
99700d6f
NC
1582 if (nbytes == pexp_mod_data->nbytes)
1583 fix_new_exp (frag, where, nbytes, exp, FALSE, pexp_mod_data->reloc);
adde6300 1584 else
99700d6f
NC
1585 bad = 1;
1586 break;
adde6300 1587 }
99700d6f
NC
1588
1589 if (bad)
1590 as_bad (_("illegal %srelocation size: %d"), pexp_mod_data->error, nbytes);
1591
1592 pexp_mod_data = &exp_mod_data[0];
adde6300 1593}
af3ecb4a 1594
71863e73
NC
1595static bfd_boolean
1596mcu_has_3_byte_pc (void)
1597{
1598 int mach = avr_mcu->mach;
1599
1600 return mach == bfd_mach_avr6
1601 || mach == bfd_mach_avrxmega6
1602 || mach == bfd_mach_avrxmega7;
1603}
1604
af3ecb4a
RH
1605void
1606tc_cfi_frame_initial_instructions (void)
1607{
1608 /* AVR6 pushes 3 bytes for calls. */
71863e73 1609 int return_size = (mcu_has_3_byte_pc () ? 3 : 2);
af3ecb4a
RH
1610
1611 /* The CFA is the caller's stack location before the call insn. */
1612 /* Note that the stack pointer is dwarf register number 32. */
1613 cfi_add_CFA_def_cfa (32, return_size);
1614
1615 /* Note that AVR consistently uses post-decrement, which means that things
1616 do not line up the same way as for targers that use pre-decrement. */
1617 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, 1-return_size);
1618}
This page took 0.616589 seconds and 4 git commands to generate.