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