2007-11-16 Eric B. Weddington <eric.weddington@atmel.com>
[deliverable/binutils-gdb.git] / gas / config / tc-avr.c
1 /* tc-avr.c -- Assembler code for the ATMEL AVR
2
3 Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
5 Contributed by Denis Chertykov <denisc@overta.ru>
6
7 This file is part of GAS, the GNU Assembler.
8
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
22 Boston, MA 02110-1301, USA. */
23
24 #include "as.h"
25 #include "safe-ctype.h"
26 #include "subsegs.h"
27
28 struct avr_opcodes_s
29 {
30 char * name;
31 char * constraints;
32 int insn_size; /* In words. */
33 int isa;
34 unsigned int bin_opcode;
35 };
36
37 #define AVR_INSN(NAME, CONSTR, OPCODE, SIZE, ISA, BIN) \
38 {#NAME, CONSTR, SIZE, ISA, BIN},
39
40 struct avr_opcodes_s avr_opcodes[] =
41 {
42 #include "opcode/avr.h"
43 {NULL, NULL, 0, 0, 0}
44 };
45
46 const char comment_chars[] = ";";
47 const char line_comment_chars[] = "#";
48 const char line_separator_chars[] = "$";
49
50 const char *md_shortopts = "m:";
51 struct mcu_type_s
52 {
53 char *name;
54 int isa;
55 int mach;
56 };
57
58 /* XXX - devices that don't seem to exist (renamed, replaced with larger
59 ones, or planned but never produced), left here for compatibility.
60 TODO: hide them in show_mcu_list output? */
61
62 static struct mcu_type_s mcu_types[] =
63 {
64 {"avr1", AVR_ISA_TINY1, bfd_mach_avr1},
65 {"avr2", AVR_ISA_TINY2, bfd_mach_avr2},
66 {"avr3", AVR_ISA_M103, bfd_mach_avr3},
67 {"avr4", AVR_ISA_M8, bfd_mach_avr4},
68 {"avr5", AVR_ISA_ALL, bfd_mach_avr5},
69 {"avr6", AVR_ISA_ALL, bfd_mach_avr6},
70 {"at90s1200", AVR_ISA_1200, bfd_mach_avr1},
71 {"attiny11", AVR_ISA_TINY1, bfd_mach_avr1},
72 {"attiny12", AVR_ISA_TINY1, bfd_mach_avr1},
73 {"attiny15", AVR_ISA_TINY1, bfd_mach_avr1},
74 {"attiny28", AVR_ISA_TINY1, bfd_mach_avr1},
75 {"at90s2313", AVR_ISA_2xxx, bfd_mach_avr2},
76 {"at90s2323", AVR_ISA_2xxx, bfd_mach_avr2},
77 {"at90s2333", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 4433 */
78 {"at90s2343", AVR_ISA_2xxx, bfd_mach_avr2},
79 {"attiny22", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 2343 */
80 {"attiny26", AVR_ISA_2xxx, bfd_mach_avr2},
81 {"at90s4433", AVR_ISA_2xxx, bfd_mach_avr2},
82 {"at90s4414", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 8515 */
83 {"at90s4434", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 8535 */
84 {"at90s8515", AVR_ISA_2xxx, bfd_mach_avr2},
85 {"at90s8535", AVR_ISA_2xxx, bfd_mach_avr2},
86 {"at90c8534", AVR_ISA_2xxx, bfd_mach_avr2},
87 {"at86rf401", AVR_ISA_2xxx, bfd_mach_avr2},
88 {"attiny13", AVR_ISA_TINY2, bfd_mach_avr2},
89 {"attiny2313", AVR_ISA_TINY2, bfd_mach_avr2},
90 {"attiny261", AVR_ISA_TINY2, bfd_mach_avr2},
91 {"attiny461", AVR_ISA_TINY2, bfd_mach_avr2},
92 {"attiny861", AVR_ISA_TINY2, bfd_mach_avr2},
93 {"attiny24", AVR_ISA_TINY2, bfd_mach_avr2},
94 {"attiny44", AVR_ISA_TINY2, bfd_mach_avr2},
95 {"attiny84", AVR_ISA_TINY2, bfd_mach_avr2},
96 {"attiny25", AVR_ISA_TINY2, bfd_mach_avr2},
97 {"attiny45", AVR_ISA_TINY2, bfd_mach_avr2},
98 {"attiny85", AVR_ISA_TINY2, bfd_mach_avr2},
99 {"attiny43u", AVR_ISA_TINY2, bfd_mach_avr2},
100 {"attiny48", AVR_ISA_TINY2, bfd_mach_avr2},
101 {"attiny88", AVR_ISA_TINY2, bfd_mach_avr2},
102 {"atmega103", AVR_ISA_M103, bfd_mach_avr3},
103 {"at43usb320", AVR_ISA_M103, bfd_mach_avr3},
104 {"at43usb355", AVR_ISA_M603, bfd_mach_avr3},
105 {"at76c711", AVR_ISA_M603, bfd_mach_avr3},
106 {"atmega48", AVR_ISA_PWMx, bfd_mach_avr4},
107 {"atmega48p", AVR_ISA_PWMx, bfd_mach_avr4},
108 {"atmega8", AVR_ISA_M8, bfd_mach_avr4},
109 {"atmega88", AVR_ISA_PWMx, bfd_mach_avr4},
110 {"atmega88p", AVR_ISA_PWMx, bfd_mach_avr4},
111 {"atmega8515", AVR_ISA_M8, bfd_mach_avr4},
112 {"atmega8535", AVR_ISA_M8, bfd_mach_avr4},
113 {"atmega8hva", AVR_ISA_PWMx, bfd_mach_avr4},
114 {"at90pwm1", AVR_ISA_PWMx, bfd_mach_avr4},
115 {"at90pwm2", AVR_ISA_PWMx, bfd_mach_avr4},
116 {"at90pwm2b", AVR_ISA_PWMx, bfd_mach_avr4},
117 {"at90pwm3", AVR_ISA_PWMx, bfd_mach_avr4},
118 {"at90pwm3b", AVR_ISA_PWMx, bfd_mach_avr4},
119 {"atmega16", AVR_ISA_M323, bfd_mach_avr5},
120 {"atmega161", AVR_ISA_M161, bfd_mach_avr5},
121 {"atmega162", AVR_ISA_M323, bfd_mach_avr5},
122 {"atmega163", AVR_ISA_M161, bfd_mach_avr5},
123 {"atmega164p", AVR_ISA_M323, bfd_mach_avr5},
124 {"atmega165", AVR_ISA_M323, bfd_mach_avr5},
125 {"atmega165p", AVR_ISA_M323, bfd_mach_avr5},
126 {"atmega168", AVR_ISA_M323, bfd_mach_avr5},
127 {"atmega168p", AVR_ISA_M323, bfd_mach_avr5},
128 {"atmega169", AVR_ISA_M323, bfd_mach_avr5},
129 {"atmega169p", AVR_ISA_M323, bfd_mach_avr5},
130 {"atmega32", AVR_ISA_M323, bfd_mach_avr5},
131 {"atmega323", AVR_ISA_M323, bfd_mach_avr5},
132 {"atmega324p", AVR_ISA_M323, bfd_mach_avr5},
133 {"atmega325", AVR_ISA_M323, bfd_mach_avr5},
134 {"atmega325p", AVR_ISA_M323, bfd_mach_avr5},
135 {"atmega328p", AVR_ISA_M323, bfd_mach_avr5},
136 {"atmega329", AVR_ISA_M323, bfd_mach_avr5},
137 {"atmega329p", AVR_ISA_M323, bfd_mach_avr5},
138 {"atmega3250", AVR_ISA_M323, bfd_mach_avr5},
139 {"atmega3250p",AVR_ISA_M323, bfd_mach_avr5},
140 {"atmega3290", AVR_ISA_M323, bfd_mach_avr5},
141 {"atmega3290p",AVR_ISA_M323, bfd_mach_avr5},
142 {"atmega406", AVR_ISA_M323, bfd_mach_avr5},
143 {"atmega64", AVR_ISA_M323, bfd_mach_avr5},
144 {"atmega640", AVR_ISA_M323, bfd_mach_avr5},
145 {"atmega644", AVR_ISA_M323, bfd_mach_avr5},
146 {"atmega644p", AVR_ISA_M323, bfd_mach_avr5},
147 {"atmega128", AVR_ISA_M128, bfd_mach_avr5},
148 {"atmega1280", AVR_ISA_M128, bfd_mach_avr5},
149 {"atmega1281", AVR_ISA_M128, bfd_mach_avr5},
150 {"atmega1284p",AVR_ISA_M128, bfd_mach_avr5},
151 {"atmega645", AVR_ISA_M323, bfd_mach_avr5},
152 {"atmega649", AVR_ISA_M323, bfd_mach_avr5},
153 {"atmega6450", AVR_ISA_M323, bfd_mach_avr5},
154 {"atmega6490", AVR_ISA_M323, bfd_mach_avr5},
155 {"atmega16hva",AVR_ISA_M323, bfd_mach_avr5},
156 {"at90can32" , AVR_ISA_M323, bfd_mach_avr5},
157 {"at90can64" , AVR_ISA_M323, bfd_mach_avr5},
158 {"at90can128", AVR_ISA_M128, bfd_mach_avr5},
159 {"at90pwm216", AVR_ISA_M323, bfd_mach_avr5},
160 {"at90pwm316", AVR_ISA_M323, bfd_mach_avr5},
161 {"at90usb82", AVR_ISA_M323, bfd_mach_avr5},
162 {"at90usb162", AVR_ISA_M323, bfd_mach_avr5},
163 {"at90usb646", AVR_ISA_M323, bfd_mach_avr5},
164 {"at90usb647", AVR_ISA_M323, bfd_mach_avr5},
165 {"at90usb1286",AVR_ISA_M128, bfd_mach_avr5},
166 {"at90usb1287",AVR_ISA_M128, bfd_mach_avr5},
167 {"at94k", AVR_ISA_94K, bfd_mach_avr5},
168 {"atmega2560", AVR_ISA_ALL, bfd_mach_avr6},
169 {"atmega2561", AVR_ISA_ALL, bfd_mach_avr6},
170 {NULL, 0, 0}
171 };
172
173 /* Current MCU type. */
174 static struct mcu_type_s default_mcu = {"avr2", AVR_ISA_2xxx,bfd_mach_avr2};
175 static struct mcu_type_s * avr_mcu = & default_mcu;
176
177 /* AVR target-specific switches. */
178 struct avr_opt_s
179 {
180 int all_opcodes; /* -mall-opcodes: accept all known AVR opcodes. */
181 int no_skip_bug; /* -mno-skip-bug: no warnings for skipping 2-word insns. */
182 int no_wrap; /* -mno-wrap: reject rjmp/rcall with 8K wrap-around. */
183 };
184
185 static struct avr_opt_s avr_opt = { 0, 0, 0 };
186
187 const char EXP_CHARS[] = "eE";
188 const char FLT_CHARS[] = "dD";
189
190 static void avr_set_arch (int);
191
192 /* The target specific pseudo-ops which we support. */
193 const pseudo_typeS md_pseudo_table[] =
194 {
195 {"arch", avr_set_arch, 0},
196 { NULL, NULL, 0}
197 };
198
199 #define LDI_IMMEDIATE(x) (((x) & 0xf) | (((x) << 4) & 0xf00))
200
201 #define EXP_MOD_NAME(i) exp_mod[i].name
202 #define EXP_MOD_RELOC(i) exp_mod[i].reloc
203 #define EXP_MOD_NEG_RELOC(i) exp_mod[i].neg_reloc
204 #define HAVE_PM_P(i) exp_mod[i].have_pm
205
206 struct exp_mod_s
207 {
208 char * name;
209 bfd_reloc_code_real_type reloc;
210 bfd_reloc_code_real_type neg_reloc;
211 int have_pm;
212 };
213
214 static struct exp_mod_s exp_mod[] =
215 {
216 {"hh8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 1},
217 {"pm_hh8", BFD_RELOC_AVR_HH8_LDI_PM, BFD_RELOC_AVR_HH8_LDI_PM_NEG, 0},
218 {"hi8", BFD_RELOC_AVR_HI8_LDI, BFD_RELOC_AVR_HI8_LDI_NEG, 1},
219 {"pm_hi8", BFD_RELOC_AVR_HI8_LDI_PM, BFD_RELOC_AVR_HI8_LDI_PM_NEG, 0},
220 {"lo8", BFD_RELOC_AVR_LO8_LDI, BFD_RELOC_AVR_LO8_LDI_NEG, 1},
221 {"pm_lo8", BFD_RELOC_AVR_LO8_LDI_PM, BFD_RELOC_AVR_LO8_LDI_PM_NEG, 0},
222 {"hlo8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 0},
223 {"hhi8", BFD_RELOC_AVR_MS8_LDI, BFD_RELOC_AVR_MS8_LDI_NEG, 0},
224 };
225
226 /* A union used to store indicies into the exp_mod[] array
227 in a hash table which expects void * data types. */
228 typedef union
229 {
230 void * ptr;
231 int index;
232 } mod_index;
233
234 /* Opcode hash table. */
235 static struct hash_control *avr_hash;
236
237 /* Reloc modifiers hash control (hh8,hi8,lo8,pm_xx). */
238 static struct hash_control *avr_mod_hash;
239
240 #define OPTION_MMCU 'm'
241 enum options
242 {
243 OPTION_ALL_OPCODES = OPTION_MD_BASE + 1,
244 OPTION_NO_SKIP_BUG,
245 OPTION_NO_WRAP
246 };
247
248 struct option md_longopts[] =
249 {
250 { "mmcu", required_argument, NULL, OPTION_MMCU },
251 { "mall-opcodes", no_argument, NULL, OPTION_ALL_OPCODES },
252 { "mno-skip-bug", no_argument, NULL, OPTION_NO_SKIP_BUG },
253 { "mno-wrap", no_argument, NULL, OPTION_NO_WRAP },
254 { NULL, no_argument, NULL, 0 }
255 };
256
257 size_t md_longopts_size = sizeof (md_longopts);
258
259 /* Display nicely formatted list of known MCU names. */
260
261 static void
262 show_mcu_list (FILE *stream)
263 {
264 int i, x;
265
266 fprintf (stream, _("Known MCU names:"));
267 x = 1000;
268
269 for (i = 0; mcu_types[i].name; i++)
270 {
271 int len = strlen (mcu_types[i].name);
272
273 x += len + 1;
274
275 if (x < 75)
276 fprintf (stream, " %s", mcu_types[i].name);
277 else
278 {
279 fprintf (stream, "\n %s", mcu_types[i].name);
280 x = len + 2;
281 }
282 }
283
284 fprintf (stream, "\n");
285 }
286
287 static inline char *
288 skip_space (char *s)
289 {
290 while (*s == ' ' || *s == '\t')
291 ++s;
292 return s;
293 }
294
295 /* Extract one word from FROM and copy it to TO. */
296
297 static char *
298 extract_word (char *from, char *to, int limit)
299 {
300 char *op_start;
301 char *op_end;
302 int size = 0;
303
304 /* Drop leading whitespace. */
305 from = skip_space (from);
306 *to = 0;
307
308 /* Find the op code end. */
309 for (op_start = op_end = from; *op_end != 0 && is_part_of_name (*op_end);)
310 {
311 to[size++] = *op_end++;
312 if (size + 1 >= limit)
313 break;
314 }
315
316 to[size] = 0;
317 return op_end;
318 }
319
320 int
321 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
322 asection *seg ATTRIBUTE_UNUSED)
323 {
324 abort ();
325 return 0;
326 }
327
328 void
329 md_show_usage (FILE *stream)
330 {
331 fprintf (stream,
332 _("AVR options:\n"
333 " -mmcu=[avr-name] select microcontroller variant\n"
334 " [avr-name] can be:\n"
335 " avr1 - AT90S1200, ATtiny1x, ATtiny28\n"
336 " avr2 - AT90S2xxx, AT90S4xxx, AT90S8xxx, ATtiny22\n"
337 " avr3 - ATmega103\n"
338 " avr4 - ATmega8, ATmega88\n"
339 " avr5 - ATmega161, ATmega163, ATmega32, AT94K\n"
340 " or immediate microcontroller name.\n"));
341 fprintf (stream,
342 _(" -mall-opcodes accept all AVR opcodes, even if not supported by MCU\n"
343 " -mno-skip-bug disable warnings for skipping two-word instructions\n"
344 " (default for avr4, avr5)\n"
345 " -mno-wrap reject rjmp/rcall instructions with 8K wrap-around\n"
346 " (default for avr3, avr5)\n"));
347 show_mcu_list (stream);
348 }
349
350 static void
351 avr_set_arch (int dummy ATTRIBUTE_UNUSED)
352 {
353 char str[20];
354
355 input_line_pointer = extract_word (input_line_pointer, str, 20);
356 md_parse_option (OPTION_MMCU, str);
357 bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
358 }
359
360 int
361 md_parse_option (int c, char *arg)
362 {
363 switch (c)
364 {
365 case OPTION_MMCU:
366 {
367 int i;
368 char *s = alloca (strlen (arg) + 1);
369
370 {
371 char *t = s;
372 char *arg1 = arg;
373
374 do
375 *t = TOLOWER (*arg1++);
376 while (*t++);
377 }
378
379 for (i = 0; mcu_types[i].name; ++i)
380 if (strcmp (mcu_types[i].name, s) == 0)
381 break;
382
383 if (!mcu_types[i].name)
384 {
385 show_mcu_list (stderr);
386 as_fatal (_("unknown MCU: %s\n"), arg);
387 }
388
389 /* It is OK to redefine mcu type within the same avr[1-5] bfd machine
390 type - this for allows passing -mmcu=... via gcc ASM_SPEC as well
391 as .arch ... in the asm output at the same time. */
392 if (avr_mcu == &default_mcu || avr_mcu->mach == mcu_types[i].mach)
393 avr_mcu = &mcu_types[i];
394 else
395 as_fatal (_("redefinition of mcu type `%s' to `%s'"),
396 avr_mcu->name, mcu_types[i].name);
397 return 1;
398 }
399 case OPTION_ALL_OPCODES:
400 avr_opt.all_opcodes = 1;
401 return 1;
402 case OPTION_NO_SKIP_BUG:
403 avr_opt.no_skip_bug = 1;
404 return 1;
405 case OPTION_NO_WRAP:
406 avr_opt.no_wrap = 1;
407 return 1;
408 }
409
410 return 0;
411 }
412
413 symbolS *
414 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
415 {
416 return NULL;
417 }
418
419 char *
420 md_atof (int type, char *litP, int *sizeP)
421 {
422 return ieee_md_atof (type, litP, sizeP, FALSE);
423 }
424
425 void
426 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
427 asection *sec ATTRIBUTE_UNUSED,
428 fragS *fragP ATTRIBUTE_UNUSED)
429 {
430 abort ();
431 }
432
433 void
434 md_begin (void)
435 {
436 unsigned int i;
437 struct avr_opcodes_s *opcode;
438
439 avr_hash = hash_new ();
440
441 /* Insert unique names into hash table. This hash table then provides a
442 quick index to the first opcode with a particular name in the opcode
443 table. */
444 for (opcode = avr_opcodes; opcode->name; opcode++)
445 hash_insert (avr_hash, opcode->name, (char *) opcode);
446
447 avr_mod_hash = hash_new ();
448
449 for (i = 0; i < ARRAY_SIZE (exp_mod); ++i)
450 {
451 mod_index m;
452
453 m.index = i + 10;
454 hash_insert (avr_mod_hash, EXP_MOD_NAME (i), m.ptr);
455 }
456
457 bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
458 }
459
460 /* Resolve STR as a constant expression and return the result.
461 If result greater than MAX then error. */
462
463 static unsigned int
464 avr_get_constant (char *str, int max)
465 {
466 expressionS ex;
467
468 str = skip_space (str);
469 input_line_pointer = str;
470 expression (& ex);
471
472 if (ex.X_op != O_constant)
473 as_bad (_("constant value required"));
474
475 if (ex.X_add_number > max || ex.X_add_number < 0)
476 as_bad (_("number must be positive and less than %d"), max + 1);
477
478 return ex.X_add_number;
479 }
480
481 /* Parse for ldd/std offset. */
482
483 static void
484 avr_offset_expression (expressionS *exp)
485 {
486 char *str = input_line_pointer;
487 char *tmp;
488 char op[8];
489
490 tmp = str;
491 str = extract_word (str, op, sizeof (op));
492
493 input_line_pointer = tmp;
494 expression (exp);
495
496 /* Warn about expressions that fail to use lo8 (). */
497 if (exp->X_op == O_constant)
498 {
499 int x = exp->X_add_number;
500
501 if (x < -255 || x > 255)
502 as_warn (_("constant out of 8-bit range: %d"), x);
503 }
504 }
505
506 /* Parse ordinary expression. */
507
508 static char *
509 parse_exp (char *s, expressionS *op)
510 {
511 input_line_pointer = s;
512 expression (op);
513 if (op->X_op == O_absent)
514 as_bad (_("missing operand"));
515 return input_line_pointer;
516 }
517
518 /* Parse special expressions (needed for LDI command):
519 xx8 (address)
520 xx8 (-address)
521 pm_xx8 (address)
522 pm_xx8 (-address)
523 where xx is: hh, hi, lo. */
524
525 static bfd_reloc_code_real_type
526 avr_ldi_expression (expressionS *exp)
527 {
528 char *str = input_line_pointer;
529 char *tmp;
530 char op[8];
531 int mod;
532 int linker_stubs_should_be_generated = 0;
533
534 tmp = str;
535
536 str = extract_word (str, op, sizeof (op));
537
538 if (op[0])
539 {
540 mod_index m;
541
542 m.ptr = hash_find (avr_mod_hash, op);
543 mod = m.index;
544
545 if (mod)
546 {
547 int closes = 0;
548
549 mod -= 10;
550 str = skip_space (str);
551
552 if (*str == '(')
553 {
554 bfd_reloc_code_real_type reloc_to_return;
555 int neg_p = 0;
556
557 ++str;
558
559 if (strncmp ("pm(", str, 3) == 0
560 || strncmp ("gs(",str,3) == 0
561 || strncmp ("-(gs(",str,5) == 0
562 || strncmp ("-(pm(", str, 5) == 0)
563 {
564 if (HAVE_PM_P (mod))
565 {
566 ++mod;
567 ++closes;
568 }
569 else
570 as_bad (_("illegal expression"));
571
572 if (str[0] == 'g' || str[2] == 'g')
573 linker_stubs_should_be_generated = 1;
574
575 if (*str == '-')
576 {
577 neg_p = 1;
578 ++closes;
579 str += 5;
580 }
581 else
582 str += 3;
583 }
584
585 if (*str == '-' && *(str + 1) == '(')
586 {
587 neg_p ^= 1;
588 ++closes;
589 str += 2;
590 }
591
592 input_line_pointer = str;
593 expression (exp);
594
595 do
596 {
597 if (*input_line_pointer != ')')
598 {
599 as_bad (_("`)' required"));
600 break;
601 }
602 input_line_pointer++;
603 }
604 while (closes--);
605
606 reloc_to_return =
607 neg_p ? EXP_MOD_NEG_RELOC (mod) : EXP_MOD_RELOC (mod);
608 if (linker_stubs_should_be_generated)
609 {
610 switch (reloc_to_return)
611 {
612 case BFD_RELOC_AVR_LO8_LDI_PM:
613 reloc_to_return = BFD_RELOC_AVR_LO8_LDI_GS;
614 break;
615 case BFD_RELOC_AVR_HI8_LDI_PM:
616 reloc_to_return = BFD_RELOC_AVR_HI8_LDI_GS;
617 break;
618
619 default:
620 as_warn (_("expression dangerous with linker stubs"));
621 }
622 }
623 return reloc_to_return;
624 }
625 }
626 }
627
628 input_line_pointer = tmp;
629 expression (exp);
630
631 /* Warn about expressions that fail to use lo8 (). */
632 if (exp->X_op == O_constant)
633 {
634 int x = exp->X_add_number;
635
636 if (x < -255 || x > 255)
637 as_warn (_("constant out of 8-bit range: %d"), x);
638 }
639
640 return BFD_RELOC_AVR_LDI;
641 }
642
643 /* Parse one instruction operand.
644 Return operand bitmask. Also fixups can be generated. */
645
646 static unsigned int
647 avr_operand (struct avr_opcodes_s *opcode,
648 int where,
649 char *op,
650 char **line)
651 {
652 expressionS op_expr;
653 unsigned int op_mask = 0;
654 char *str = skip_space (*line);
655
656 switch (*op)
657 {
658 /* Any register operand. */
659 case 'w':
660 case 'd':
661 case 'r':
662 case 'a':
663 case 'v':
664 if (*str == 'r' || *str == 'R')
665 {
666 char r_name[20];
667
668 str = extract_word (str, r_name, sizeof (r_name));
669 op_mask = 0xff;
670 if (ISDIGIT (r_name[1]))
671 {
672 if (r_name[2] == '\0')
673 op_mask = r_name[1] - '0';
674 else if (r_name[1] != '0'
675 && ISDIGIT (r_name[2])
676 && r_name[3] == '\0')
677 op_mask = (r_name[1] - '0') * 10 + r_name[2] - '0';
678 }
679 }
680 else
681 {
682 op_mask = avr_get_constant (str, 31);
683 str = input_line_pointer;
684 }
685
686 if (op_mask <= 31)
687 {
688 switch (*op)
689 {
690 case 'a':
691 if (op_mask < 16 || op_mask > 23)
692 as_bad (_("register r16-r23 required"));
693 op_mask -= 16;
694 break;
695
696 case 'd':
697 if (op_mask < 16)
698 as_bad (_("register number above 15 required"));
699 op_mask -= 16;
700 break;
701
702 case 'v':
703 if (op_mask & 1)
704 as_bad (_("even register number required"));
705 op_mask >>= 1;
706 break;
707
708 case 'w':
709 if ((op_mask & 1) || op_mask < 24)
710 as_bad (_("register r24, r26, r28 or r30 required"));
711 op_mask = (op_mask - 24) >> 1;
712 break;
713 }
714 break;
715 }
716 as_bad (_("register name or number from 0 to 31 required"));
717 break;
718
719 case 'e':
720 {
721 char c;
722
723 if (*str == '-')
724 {
725 str = skip_space (str + 1);
726 op_mask = 0x1002;
727 }
728 c = TOLOWER (*str);
729 if (c == 'x')
730 op_mask |= 0x100c;
731 else if (c == 'y')
732 op_mask |= 0x8;
733 else if (c != 'z')
734 as_bad (_("pointer register (X, Y or Z) required"));
735
736 str = skip_space (str + 1);
737 if (*str == '+')
738 {
739 ++str;
740 if (op_mask & 2)
741 as_bad (_("cannot both predecrement and postincrement"));
742 op_mask |= 0x1001;
743 }
744
745 /* avr1 can do "ld r,Z" and "st Z,r" but no other pointer
746 registers, no predecrement, no postincrement. */
747 if (!avr_opt.all_opcodes && (op_mask & 0x100F)
748 && !(avr_mcu->isa & AVR_ISA_SRAM))
749 as_bad (_("addressing mode not supported"));
750 }
751 break;
752
753 case 'z':
754 if (*str == '-')
755 as_bad (_("can't predecrement"));
756
757 if (! (*str == 'z' || *str == 'Z'))
758 as_bad (_("pointer register Z required"));
759
760 str = skip_space (str + 1);
761
762 if (*str == '+')
763 {
764 ++str;
765 op_mask |= 1;
766 }
767 break;
768
769 case 'b':
770 {
771 char c = TOLOWER (*str++);
772
773 if (c == 'y')
774 op_mask |= 0x8;
775 else if (c != 'z')
776 as_bad (_("pointer register (Y or Z) required"));
777 str = skip_space (str);
778 if (*str++ == '+')
779 {
780 input_line_pointer = str;
781 avr_offset_expression (& op_expr);
782 str = input_line_pointer;
783 fix_new_exp (frag_now, where, 3,
784 &op_expr, FALSE, BFD_RELOC_AVR_6);
785 }
786 }
787 break;
788
789 case 'h':
790 str = parse_exp (str, &op_expr);
791 fix_new_exp (frag_now, where, opcode->insn_size * 2,
792 &op_expr, FALSE, BFD_RELOC_AVR_CALL);
793 break;
794
795 case 'L':
796 str = parse_exp (str, &op_expr);
797 fix_new_exp (frag_now, where, opcode->insn_size * 2,
798 &op_expr, TRUE, BFD_RELOC_AVR_13_PCREL);
799 break;
800
801 case 'l':
802 str = parse_exp (str, &op_expr);
803 fix_new_exp (frag_now, where, opcode->insn_size * 2,
804 &op_expr, TRUE, BFD_RELOC_AVR_7_PCREL);
805 break;
806
807 case 'i':
808 str = parse_exp (str, &op_expr);
809 fix_new_exp (frag_now, where + 2, opcode->insn_size * 2,
810 &op_expr, FALSE, BFD_RELOC_16);
811 break;
812
813 case 'M':
814 {
815 bfd_reloc_code_real_type r_type;
816
817 input_line_pointer = str;
818 r_type = avr_ldi_expression (&op_expr);
819 str = input_line_pointer;
820 fix_new_exp (frag_now, where, 3,
821 &op_expr, FALSE, r_type);
822 }
823 break;
824
825 case 'n':
826 {
827 unsigned int x;
828
829 x = ~avr_get_constant (str, 255);
830 str = input_line_pointer;
831 op_mask |= (x & 0xf) | ((x << 4) & 0xf00);
832 }
833 break;
834
835 case 'K':
836 input_line_pointer = str;
837 avr_offset_expression (& op_expr);
838 str = input_line_pointer;
839 fix_new_exp (frag_now, where, 3,
840 & op_expr, FALSE, BFD_RELOC_AVR_6_ADIW);
841 break;
842
843 case 'S':
844 case 's':
845 {
846 unsigned int x;
847
848 x = avr_get_constant (str, 7);
849 str = input_line_pointer;
850 if (*op == 'S')
851 x <<= 4;
852 op_mask |= x;
853 }
854 break;
855
856 case 'P':
857 {
858 unsigned int x;
859
860 x = avr_get_constant (str, 63);
861 str = input_line_pointer;
862 op_mask |= (x & 0xf) | ((x & 0x30) << 5);
863 }
864 break;
865
866 case 'p':
867 {
868 unsigned int x;
869
870 x = avr_get_constant (str, 31);
871 str = input_line_pointer;
872 op_mask |= x << 3;
873 }
874 break;
875
876 case '?':
877 break;
878
879 default:
880 as_bad (_("unknown constraint `%c'"), *op);
881 }
882
883 *line = str;
884 return op_mask;
885 }
886
887 /* Parse instruction operands.
888 Return binary opcode. */
889
890 static unsigned int
891 avr_operands (struct avr_opcodes_s *opcode, char **line)
892 {
893 char *op = opcode->constraints;
894 unsigned int bin = opcode->bin_opcode;
895 char *frag = frag_more (opcode->insn_size * 2);
896 char *str = *line;
897 int where = frag - frag_now->fr_literal;
898 static unsigned int prev = 0; /* Previous opcode. */
899
900 /* Opcode have operands. */
901 if (*op)
902 {
903 unsigned int reg1 = 0;
904 unsigned int reg2 = 0;
905 int reg1_present = 0;
906 int reg2_present = 0;
907
908 /* Parse first operand. */
909 if (REGISTER_P (*op))
910 reg1_present = 1;
911 reg1 = avr_operand (opcode, where, op, &str);
912 ++op;
913
914 /* Parse second operand. */
915 if (*op)
916 {
917 if (*op == ',')
918 ++op;
919
920 if (*op == '=')
921 {
922 reg2 = reg1;
923 reg2_present = 1;
924 }
925 else
926 {
927 if (REGISTER_P (*op))
928 reg2_present = 1;
929
930 str = skip_space (str);
931 if (*str++ != ',')
932 as_bad (_("`,' required"));
933 str = skip_space (str);
934
935 reg2 = avr_operand (opcode, where, op, &str);
936 }
937
938 if (reg1_present && reg2_present)
939 reg2 = (reg2 & 0xf) | ((reg2 << 5) & 0x200);
940 else if (reg2_present)
941 reg2 <<= 4;
942 }
943 if (reg1_present)
944 reg1 <<= 4;
945 bin |= reg1 | reg2;
946 }
947
948 /* Detect undefined combinations (like ld r31,Z+). */
949 if (!avr_opt.all_opcodes && AVR_UNDEF_P (bin))
950 as_warn (_("undefined combination of operands"));
951
952 if (opcode->insn_size == 2)
953 {
954 /* Warn if the previous opcode was cpse/sbic/sbis/sbrc/sbrs
955 (AVR core bug, fixed in the newer devices). */
956 if (!(avr_opt.no_skip_bug ||
957 (avr_mcu->isa & (AVR_ISA_MUL | AVR_ISA_MOVW)))
958 && AVR_SKIP_P (prev))
959 as_warn (_("skipping two-word instruction"));
960
961 bfd_putl32 ((bfd_vma) bin, frag);
962 }
963 else
964 bfd_putl16 ((bfd_vma) bin, frag);
965
966 prev = bin;
967 *line = str;
968 return bin;
969 }
970
971 /* GAS will call this function for each section at the end of the assembly,
972 to permit the CPU backend to adjust the alignment of a section. */
973
974 valueT
975 md_section_align (asection *seg, valueT addr)
976 {
977 int align = bfd_get_section_alignment (stdoutput, seg);
978 return ((addr + (1 << align) - 1) & (-1 << align));
979 }
980
981 /* If you define this macro, it should return the offset between the
982 address of a PC relative fixup and the position from which the PC
983 relative adjustment should be made. On many processors, the base
984 of a PC relative instruction is the next instruction, so this
985 macro would return the length of an instruction. */
986
987 long
988 md_pcrel_from_section (fixS *fixp, segT sec)
989 {
990 if (fixp->fx_addsy != (symbolS *) NULL
991 && (!S_IS_DEFINED (fixp->fx_addsy)
992 || (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
993 return 0;
994
995 return fixp->fx_frag->fr_address + fixp->fx_where;
996 }
997
998 /* GAS will call this for each fixup. It should store the correct
999 value in the object file. */
1000
1001 void
1002 md_apply_fix (fixS *fixP, valueT * valP, segT seg)
1003 {
1004 unsigned char *where;
1005 unsigned long insn;
1006 long value = *valP;
1007
1008 if (fixP->fx_addsy == (symbolS *) NULL)
1009 fixP->fx_done = 1;
1010
1011 else if (fixP->fx_pcrel)
1012 {
1013 segT s = S_GET_SEGMENT (fixP->fx_addsy);
1014
1015 if (s == seg || s == absolute_section)
1016 {
1017 value += S_GET_VALUE (fixP->fx_addsy);
1018 fixP->fx_done = 1;
1019 }
1020 }
1021
1022 /* We don't actually support subtracting a symbol. */
1023 if (fixP->fx_subsy != (symbolS *) NULL)
1024 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1025
1026 switch (fixP->fx_r_type)
1027 {
1028 default:
1029 fixP->fx_no_overflow = 1;
1030 break;
1031 case BFD_RELOC_AVR_7_PCREL:
1032 case BFD_RELOC_AVR_13_PCREL:
1033 case BFD_RELOC_32:
1034 case BFD_RELOC_16:
1035 case BFD_RELOC_AVR_CALL:
1036 break;
1037 }
1038
1039 if (fixP->fx_done)
1040 {
1041 /* Fetch the instruction, insert the fully resolved operand
1042 value, and stuff the instruction back again. */
1043 where = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
1044 insn = bfd_getl16 (where);
1045
1046 switch (fixP->fx_r_type)
1047 {
1048 case BFD_RELOC_AVR_7_PCREL:
1049 if (value & 1)
1050 as_bad_where (fixP->fx_file, fixP->fx_line,
1051 _("odd address operand: %ld"), value);
1052
1053 /* Instruction addresses are always right-shifted by 1. */
1054 value >>= 1;
1055 --value; /* Correct PC. */
1056
1057 if (value < -64 || value > 63)
1058 as_bad_where (fixP->fx_file, fixP->fx_line,
1059 _("operand out of range: %ld"), value);
1060 value = (value << 3) & 0x3f8;
1061 bfd_putl16 ((bfd_vma) (value | insn), where);
1062 break;
1063
1064 case BFD_RELOC_AVR_13_PCREL:
1065 if (value & 1)
1066 as_bad_where (fixP->fx_file, fixP->fx_line,
1067 _("odd address operand: %ld"), value);
1068
1069 /* Instruction addresses are always right-shifted by 1. */
1070 value >>= 1;
1071 --value; /* Correct PC. */
1072
1073 if (value < -2048 || value > 2047)
1074 {
1075 /* No wrap for devices with >8K of program memory. */
1076 if ((avr_mcu->isa & AVR_ISA_MEGA) || avr_opt.no_wrap)
1077 as_bad_where (fixP->fx_file, fixP->fx_line,
1078 _("operand out of range: %ld"), value);
1079 }
1080
1081 value &= 0xfff;
1082 bfd_putl16 ((bfd_vma) (value | insn), where);
1083 break;
1084
1085 case BFD_RELOC_32:
1086 bfd_putl16 ((bfd_vma) value, where);
1087 break;
1088
1089 case BFD_RELOC_16:
1090 bfd_putl16 ((bfd_vma) value, where);
1091 break;
1092
1093 case BFD_RELOC_AVR_16_PM:
1094 bfd_putl16 ((bfd_vma) (value >> 1), where);
1095 break;
1096
1097 case BFD_RELOC_AVR_LDI:
1098 if (value > 255)
1099 as_bad_where (fixP->fx_file, fixP->fx_line,
1100 _("operand out of range: %ld"), value);
1101 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
1102 break;
1103
1104 case BFD_RELOC_AVR_6:
1105 if ((value > 63) || (value < 0))
1106 as_bad_where (fixP->fx_file, fixP->fx_line,
1107 _("operand out of range: %ld"), value);
1108 bfd_putl16 ((bfd_vma) insn | ((value & 7) | ((value & (3 << 3)) << 7) | ((value & (1 << 5)) << 8)), where);
1109 break;
1110
1111 case BFD_RELOC_AVR_6_ADIW:
1112 if ((value > 63) || (value < 0))
1113 as_bad_where (fixP->fx_file, fixP->fx_line,
1114 _("operand out of range: %ld"), value);
1115 bfd_putl16 ((bfd_vma) insn | (value & 0xf) | ((value & 0x30) << 2), where);
1116 break;
1117
1118 case BFD_RELOC_AVR_LO8_LDI:
1119 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value), where);
1120 break;
1121
1122 case BFD_RELOC_AVR_HI8_LDI:
1123 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 8), where);
1124 break;
1125
1126 case BFD_RELOC_AVR_MS8_LDI:
1127 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 24), where);
1128 break;
1129
1130 case BFD_RELOC_AVR_HH8_LDI:
1131 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 16), where);
1132 break;
1133
1134 case BFD_RELOC_AVR_LO8_LDI_NEG:
1135 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value), where);
1136 break;
1137
1138 case BFD_RELOC_AVR_HI8_LDI_NEG:
1139 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 8), where);
1140 break;
1141
1142 case BFD_RELOC_AVR_MS8_LDI_NEG:
1143 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 24), where);
1144 break;
1145
1146 case BFD_RELOC_AVR_HH8_LDI_NEG:
1147 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 16), where);
1148 break;
1149
1150 case BFD_RELOC_AVR_LO8_LDI_PM:
1151 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 1), where);
1152 break;
1153
1154 case BFD_RELOC_AVR_HI8_LDI_PM:
1155 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 9), where);
1156 break;
1157
1158 case BFD_RELOC_AVR_HH8_LDI_PM:
1159 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (value >> 17), where);
1160 break;
1161
1162 case BFD_RELOC_AVR_LO8_LDI_PM_NEG:
1163 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 1), where);
1164 break;
1165
1166 case BFD_RELOC_AVR_HI8_LDI_PM_NEG:
1167 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 9), where);
1168 break;
1169
1170 case BFD_RELOC_AVR_HH8_LDI_PM_NEG:
1171 bfd_putl16 ((bfd_vma) insn | LDI_IMMEDIATE (-value >> 17), where);
1172 break;
1173
1174 case BFD_RELOC_AVR_CALL:
1175 {
1176 unsigned long x;
1177
1178 x = bfd_getl16 (where);
1179 if (value & 1)
1180 as_bad_where (fixP->fx_file, fixP->fx_line,
1181 _("odd address operand: %ld"), value);
1182 value >>= 1;
1183 x |= ((value & 0x10000) | ((value << 3) & 0x1f00000)) >> 16;
1184 bfd_putl16 ((bfd_vma) x, where);
1185 bfd_putl16 ((bfd_vma) (value & 0xffff), where + 2);
1186 }
1187 break;
1188
1189 default:
1190 as_fatal (_("line %d: unknown relocation type: 0x%x"),
1191 fixP->fx_line, fixP->fx_r_type);
1192 break;
1193 }
1194 }
1195 else
1196 {
1197 switch (fixP->fx_r_type)
1198 {
1199 case -BFD_RELOC_AVR_HI8_LDI_NEG:
1200 case -BFD_RELOC_AVR_HI8_LDI:
1201 case -BFD_RELOC_AVR_LO8_LDI_NEG:
1202 case -BFD_RELOC_AVR_LO8_LDI:
1203 as_bad_where (fixP->fx_file, fixP->fx_line,
1204 _("only constant expression allowed"));
1205 fixP->fx_done = 1;
1206 break;
1207 default:
1208 break;
1209 }
1210 }
1211 }
1212
1213 /* GAS will call this to generate a reloc, passing the resulting reloc
1214 to `bfd_install_relocation'. This currently works poorly, as
1215 `bfd_install_relocation' often does the wrong thing, and instances of
1216 `tc_gen_reloc' have been written to work around the problems, which
1217 in turns makes it difficult to fix `bfd_install_relocation'. */
1218
1219 /* If while processing a fixup, a reloc really needs to be created
1220 then it is done here. */
1221
1222 arelent *
1223 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
1224 fixS *fixp)
1225 {
1226 arelent *reloc;
1227
1228 if (fixp->fx_addsy && fixp->fx_subsy)
1229 {
1230 long value = 0;
1231
1232 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1233 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1234 {
1235 as_bad_where (fixp->fx_file, fixp->fx_line,
1236 "Difference of symbols in different sections is not supported");
1237 return NULL;
1238 }
1239
1240 /* We are dealing with two symbols defined in the same section.
1241 Let us fix-up them here. */
1242 value += S_GET_VALUE (fixp->fx_addsy);
1243 value -= S_GET_VALUE (fixp->fx_subsy);
1244
1245 /* When fx_addsy and fx_subsy both are zero, md_apply_fix
1246 only takes it's second operands for the fixup value. */
1247 fixp->fx_addsy = NULL;
1248 fixp->fx_subsy = NULL;
1249 md_apply_fix (fixp, (valueT *) &value, NULL);
1250
1251 return NULL;
1252 }
1253
1254 reloc = xmalloc (sizeof (arelent));
1255
1256 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
1257 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1258
1259 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1260 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1261 if (reloc->howto == (reloc_howto_type *) NULL)
1262 {
1263 as_bad_where (fixp->fx_file, fixp->fx_line,
1264 _("reloc %d not supported by object file format"),
1265 (int) fixp->fx_r_type);
1266 return NULL;
1267 }
1268
1269 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1270 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1271 reloc->address = fixp->fx_offset;
1272
1273 reloc->addend = fixp->fx_offset;
1274
1275 return reloc;
1276 }
1277
1278 void
1279 md_assemble (char *str)
1280 {
1281 struct avr_opcodes_s *opcode;
1282 char op[11];
1283
1284 str = skip_space (extract_word (str, op, sizeof (op)));
1285
1286 if (!op[0])
1287 as_bad (_("can't find opcode "));
1288
1289 opcode = (struct avr_opcodes_s *) hash_find (avr_hash, op);
1290
1291 if (opcode == NULL)
1292 {
1293 as_bad (_("unknown opcode `%s'"), op);
1294 return;
1295 }
1296
1297 /* Special case for opcodes with optional operands (lpm, elpm) -
1298 version with operands exists in avr_opcodes[] in the next entry. */
1299
1300 if (*str && *opcode->constraints == '?')
1301 ++opcode;
1302
1303 if (!avr_opt.all_opcodes && (opcode->isa & avr_mcu->isa) != opcode->isa)
1304 as_bad (_("illegal opcode %s for mcu %s"), opcode->name, avr_mcu->name);
1305
1306 /* We used to set input_line_pointer to the result of get_operands,
1307 but that is wrong. Our caller assumes we don't change it. */
1308 {
1309 char *t = input_line_pointer;
1310
1311 avr_operands (opcode, &str);
1312 if (*skip_space (str))
1313 as_bad (_("garbage at end of line"));
1314 input_line_pointer = t;
1315 }
1316 }
1317
1318 /* Flag to pass `pm' mode between `avr_parse_cons_expression' and
1319 `avr_cons_fix_new'. */
1320 static int exp_mod_pm = 0;
1321
1322 /* Parse special CONS expression: pm (expression)
1323 or alternatively: gs (expression).
1324 These are used for addressing program memory.
1325 Relocation: BFD_RELOC_AVR_16_PM. */
1326
1327 void
1328 avr_parse_cons_expression (expressionS *exp, int nbytes)
1329 {
1330 char *tmp;
1331
1332 exp_mod_pm = 0;
1333
1334 tmp = input_line_pointer = skip_space (input_line_pointer);
1335
1336 if (nbytes == 2)
1337 {
1338 char *pm_name1 = "pm";
1339 char *pm_name2 = "gs";
1340 int len = strlen (pm_name1);
1341 /* len must be the same for both pm identifiers. */
1342
1343 if (strncasecmp (input_line_pointer, pm_name1, len) == 0
1344 || strncasecmp (input_line_pointer, pm_name2, len) == 0)
1345 {
1346 input_line_pointer = skip_space (input_line_pointer + len);
1347
1348 if (*input_line_pointer == '(')
1349 {
1350 input_line_pointer = skip_space (input_line_pointer + 1);
1351 exp_mod_pm = 1;
1352 expression (exp);
1353
1354 if (*input_line_pointer == ')')
1355 ++input_line_pointer;
1356 else
1357 {
1358 as_bad (_("`)' required"));
1359 exp_mod_pm = 0;
1360 }
1361
1362 return;
1363 }
1364
1365 input_line_pointer = tmp;
1366 }
1367 }
1368
1369 expression (exp);
1370 }
1371
1372 void
1373 avr_cons_fix_new (fragS *frag,
1374 int where,
1375 int nbytes,
1376 expressionS *exp)
1377 {
1378 if (exp_mod_pm == 0)
1379 {
1380 if (nbytes == 2)
1381 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_16);
1382 else if (nbytes == 4)
1383 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_32);
1384 else
1385 as_bad (_("illegal %srelocation size: %d"), "", nbytes);
1386 }
1387 else
1388 {
1389 if (nbytes == 2)
1390 fix_new_exp (frag, where, nbytes, exp, FALSE, BFD_RELOC_AVR_16_PM);
1391 else
1392 as_bad (_("illegal %srelocation size: %d"), "`pm' ", nbytes);
1393 exp_mod_pm = 0;
1394 }
1395 }
This page took 0.062477 seconds and 5 git commands to generate.