tc-h8300.c revision 1.1.1.3 1 1.1 skrll /* tc-h8300.c -- Assemble code for the Renesas H8/300
2 1.1 skrll Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 1.1.1.3 christos 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012
4 1.1.1.2 christos Free Software Foundation, Inc.
5 1.1 skrll
6 1.1 skrll This file is part of GAS, the GNU Assembler.
7 1.1 skrll
8 1.1 skrll GAS is free software; you can redistribute it and/or modify
9 1.1 skrll it under the terms of the GNU General Public License as published by
10 1.1 skrll the Free Software Foundation; either version 3, or (at your option)
11 1.1 skrll any later version.
12 1.1 skrll
13 1.1 skrll GAS is distributed in the hope that it will be useful,
14 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 skrll GNU General Public License for more details.
17 1.1 skrll
18 1.1 skrll You should have received a copy of the GNU General Public License
19 1.1 skrll along with GAS; see the file COPYING. If not, write to the Free
20 1.1 skrll Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 1.1 skrll 02110-1301, USA. */
22 1.1 skrll
23 1.1 skrll /* Written By Steve Chamberlain <sac (at) cygnus.com>. */
24 1.1 skrll
25 1.1 skrll #include "as.h"
26 1.1 skrll #include "subsegs.h"
27 1.1 skrll #include "dwarf2dbg.h"
28 1.1 skrll
29 1.1 skrll #define DEFINE_TABLE
30 1.1 skrll #define h8_opcodes ops
31 1.1 skrll #include "opcode/h8300.h"
32 1.1 skrll #include "safe-ctype.h"
33 1.1 skrll
34 1.1 skrll #ifdef OBJ_ELF
35 1.1 skrll #include "elf/h8.h"
36 1.1 skrll #endif
37 1.1 skrll
38 1.1 skrll const char comment_chars[] = ";";
39 1.1 skrll const char line_comment_chars[] = "#";
40 1.1 skrll const char line_separator_chars[] = "";
41 1.1 skrll
42 1.1 skrll static void sbranch (int);
43 1.1 skrll static void h8300hmode (int);
44 1.1 skrll static void h8300smode (int);
45 1.1 skrll static void h8300hnmode (int);
46 1.1 skrll static void h8300snmode (int);
47 1.1 skrll static void h8300sxmode (int);
48 1.1 skrll static void h8300sxnmode (int);
49 1.1 skrll static void pint (int);
50 1.1 skrll
51 1.1 skrll int Hmode;
52 1.1 skrll int Smode;
53 1.1 skrll int Nmode;
54 1.1 skrll int SXmode;
55 1.1 skrll
56 1.1 skrll #define PSIZE (Hmode && !Nmode ? L_32 : L_16)
57 1.1 skrll
58 1.1 skrll static int bsize = L_8; /* Default branch displacement. */
59 1.1 skrll
60 1.1 skrll struct h8_instruction
61 1.1 skrll {
62 1.1 skrll int length;
63 1.1 skrll int noperands;
64 1.1 skrll int idx;
65 1.1 skrll int size;
66 1.1 skrll const struct h8_opcode *opcode;
67 1.1 skrll };
68 1.1 skrll
69 1.1 skrll static struct h8_instruction *h8_instructions;
70 1.1 skrll
71 1.1 skrll static void
72 1.1 skrll h8300hmode (int arg ATTRIBUTE_UNUSED)
73 1.1 skrll {
74 1.1 skrll Hmode = 1;
75 1.1 skrll Smode = 0;
76 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300h))
77 1.1 skrll as_warn (_("could not set architecture and machine"));
78 1.1 skrll }
79 1.1 skrll
80 1.1 skrll static void
81 1.1 skrll h8300smode (int arg ATTRIBUTE_UNUSED)
82 1.1 skrll {
83 1.1 skrll Smode = 1;
84 1.1 skrll Hmode = 1;
85 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300s))
86 1.1 skrll as_warn (_("could not set architecture and machine"));
87 1.1 skrll }
88 1.1 skrll
89 1.1 skrll static void
90 1.1 skrll h8300hnmode (int arg ATTRIBUTE_UNUSED)
91 1.1 skrll {
92 1.1 skrll Hmode = 1;
93 1.1 skrll Smode = 0;
94 1.1 skrll Nmode = 1;
95 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300hn))
96 1.1 skrll as_warn (_("could not set architecture and machine"));
97 1.1 skrll }
98 1.1 skrll
99 1.1 skrll static void
100 1.1 skrll h8300snmode (int arg ATTRIBUTE_UNUSED)
101 1.1 skrll {
102 1.1 skrll Smode = 1;
103 1.1 skrll Hmode = 1;
104 1.1 skrll Nmode = 1;
105 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sn))
106 1.1 skrll as_warn (_("could not set architecture and machine"));
107 1.1 skrll }
108 1.1 skrll
109 1.1 skrll static void
110 1.1 skrll h8300sxmode (int arg ATTRIBUTE_UNUSED)
111 1.1 skrll {
112 1.1 skrll Smode = 1;
113 1.1 skrll Hmode = 1;
114 1.1 skrll SXmode = 1;
115 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sx))
116 1.1 skrll as_warn (_("could not set architecture and machine"));
117 1.1 skrll }
118 1.1 skrll
119 1.1 skrll static void
120 1.1 skrll h8300sxnmode (int arg ATTRIBUTE_UNUSED)
121 1.1 skrll {
122 1.1 skrll Smode = 1;
123 1.1 skrll Hmode = 1;
124 1.1 skrll SXmode = 1;
125 1.1 skrll Nmode = 1;
126 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sxn))
127 1.1 skrll as_warn (_("could not set architecture and machine"));
128 1.1 skrll }
129 1.1 skrll
130 1.1 skrll static void
131 1.1 skrll sbranch (int size)
132 1.1 skrll {
133 1.1 skrll bsize = size;
134 1.1 skrll }
135 1.1 skrll
136 1.1 skrll static void
137 1.1 skrll pint (int arg ATTRIBUTE_UNUSED)
138 1.1 skrll {
139 1.1 skrll cons (Hmode ? 4 : 2);
140 1.1 skrll }
141 1.1 skrll
142 1.1.1.2 christos /* Like obj_elf_section, but issues a warning for new
143 1.1.1.2 christos sections which do not have an attribute specification. */
144 1.1.1.2 christos
145 1.1.1.2 christos static void
146 1.1.1.2 christos h8300_elf_section (int push)
147 1.1.1.2 christos {
148 1.1.1.2 christos static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
149 1.1.1.2 christos static const char * known_data_prefixes [] = { ".debug", ".zdebug", ".gnu.warning" };
150 1.1.1.2 christos char * saved_ilp = input_line_pointer;
151 1.1.1.2 christos char * name;
152 1.1.1.2 christos
153 1.1.1.2 christos name = obj_elf_section_name ();
154 1.1.1.2 christos if (name == NULL)
155 1.1.1.2 christos return;
156 1.1.1.2 christos
157 1.1.1.2 christos if (* input_line_pointer != ','
158 1.1.1.2 christos && bfd_get_section_by_name (stdoutput, name) == NULL)
159 1.1.1.2 christos {
160 1.1.1.2 christos signed int i;
161 1.1.1.2 christos
162 1.1.1.2 christos /* Ignore this warning for well known data sections. */
163 1.1.1.2 christos for (i = ARRAY_SIZE (known_data_sections); i--;)
164 1.1.1.2 christos if (strcmp (name, known_data_sections[i]) == 0)
165 1.1.1.2 christos break;
166 1.1.1.2 christos
167 1.1.1.2 christos if (i < 0)
168 1.1.1.2 christos for (i = ARRAY_SIZE (known_data_prefixes); i--;)
169 1.1.1.2 christos if (strncmp (name, known_data_prefixes[i],
170 1.1.1.2 christos strlen (known_data_prefixes[i])) == 0)
171 1.1.1.2 christos break;
172 1.1.1.2 christos
173 1.1.1.2 christos if (i < 0)
174 1.1.1.2 christos as_warn (_("new section '%s' defined without attributes - this might cause problems"), name);
175 1.1.1.2 christos }
176 1.1.1.2 christos
177 1.1.1.2 christos /* FIXME: We ought to free the memory allocated by obj_elf_section_name()
178 1.1.1.2 christos for 'name', but we do not know if it was taken from the obstack, via
179 1.1.1.2 christos demand_copy_C_string(), or xmalloc()ed. */
180 1.1.1.2 christos input_line_pointer = saved_ilp;
181 1.1.1.2 christos obj_elf_section (push);
182 1.1.1.2 christos }
183 1.1.1.2 christos
184 1.1 skrll /* This table describes all the machine specific pseudo-ops the assembler
185 1.1 skrll has to support. The fields are:
186 1.1 skrll pseudo-op name without dot
187 1.1 skrll function to call to execute this pseudo-op
188 1.1 skrll Integer arg to pass to the function. */
189 1.1 skrll
190 1.1 skrll const pseudo_typeS md_pseudo_table[] =
191 1.1 skrll {
192 1.1 skrll {"h8300h", h8300hmode, 0},
193 1.1 skrll {"h8300hn", h8300hnmode, 0},
194 1.1 skrll {"h8300s", h8300smode, 0},
195 1.1 skrll {"h8300sn", h8300snmode, 0},
196 1.1 skrll {"h8300sx", h8300sxmode, 0},
197 1.1 skrll {"h8300sxn", h8300sxnmode, 0},
198 1.1 skrll {"sbranch", sbranch, L_8},
199 1.1 skrll {"lbranch", sbranch, L_16},
200 1.1 skrll
201 1.1 skrll {"int", pint, 0},
202 1.1 skrll {"data.b", cons, 1},
203 1.1 skrll {"data.w", cons, 2},
204 1.1 skrll {"data.l", cons, 4},
205 1.1 skrll {"form", listing_psize, 0},
206 1.1 skrll {"heading", listing_title, 0},
207 1.1 skrll {"import", s_ignore, 0},
208 1.1 skrll {"page", listing_eject, 0},
209 1.1 skrll {"program", s_ignore, 0},
210 1.1.1.2 christos
211 1.1.1.2 christos #ifdef OBJ_ELF
212 1.1.1.2 christos {"section", h8300_elf_section, 0},
213 1.1.1.2 christos {"section.s", h8300_elf_section, 0},
214 1.1.1.2 christos {"sect", h8300_elf_section, 0},
215 1.1.1.2 christos {"sect.s", h8300_elf_section, 0},
216 1.1.1.2 christos #endif
217 1.1.1.2 christos
218 1.1 skrll {0, 0, 0}
219 1.1 skrll };
220 1.1 skrll
221 1.1 skrll const char EXP_CHARS[] = "eE";
222 1.1 skrll
223 1.1 skrll /* Chars that mean this number is a floating point constant
224 1.1 skrll As in 0f12.456
225 1.1 skrll or 0d1.2345e12. */
226 1.1 skrll const char FLT_CHARS[] = "rRsSfFdDxXpP";
227 1.1 skrll
228 1.1 skrll static struct hash_control *opcode_hash_control; /* Opcode mnemonics. */
229 1.1 skrll
230 1.1 skrll /* This function is called once, at assembler startup time. This
231 1.1 skrll should set up all the tables, etc. that the MD part of the assembler
232 1.1 skrll needs. */
233 1.1 skrll
234 1.1 skrll void
235 1.1 skrll md_begin (void)
236 1.1 skrll {
237 1.1 skrll unsigned int nopcodes;
238 1.1 skrll struct h8_opcode *p, *p1;
239 1.1 skrll struct h8_instruction *pi;
240 1.1 skrll char prev_buffer[100];
241 1.1 skrll int idx = 0;
242 1.1 skrll
243 1.1 skrll if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300))
244 1.1 skrll as_warn (_("could not set architecture and machine"));
245 1.1 skrll
246 1.1 skrll opcode_hash_control = hash_new ();
247 1.1 skrll prev_buffer[0] = 0;
248 1.1 skrll
249 1.1 skrll nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode);
250 1.1 skrll
251 1.1 skrll h8_instructions = (struct h8_instruction *)
252 1.1 skrll xmalloc (nopcodes * sizeof (struct h8_instruction));
253 1.1 skrll
254 1.1 skrll pi = h8_instructions;
255 1.1 skrll p1 = h8_opcodes;
256 1.1 skrll /* We do a minimum amount of sorting on the opcode table; this is to
257 1.1 skrll make it easy to describe the mova instructions without unnecessary
258 1.1 skrll code duplication.
259 1.1 skrll Sorting only takes place inside blocks of instructions of the form
260 1.1 skrll X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */
261 1.1 skrll while (p1)
262 1.1 skrll {
263 1.1 skrll struct h8_opcode *first_skipped = 0;
264 1.1 skrll int len, cmplen = 0;
265 1.1 skrll char *src = p1->name;
266 1.1 skrll char *dst, *buffer;
267 1.1 skrll
268 1.1 skrll if (p1->name == 0)
269 1.1 skrll break;
270 1.1 skrll /* Strip off any . part when inserting the opcode and only enter
271 1.1 skrll unique codes into the hash table. */
272 1.1 skrll dst = buffer = malloc (strlen (src) + 1);
273 1.1 skrll while (*src)
274 1.1 skrll {
275 1.1 skrll if (*src == '.')
276 1.1 skrll {
277 1.1 skrll src++;
278 1.1 skrll break;
279 1.1 skrll }
280 1.1 skrll if (*src == '/')
281 1.1 skrll cmplen = src - p1->name + 1;
282 1.1 skrll *dst++ = *src++;
283 1.1 skrll }
284 1.1 skrll *dst = 0;
285 1.1 skrll len = dst - buffer;
286 1.1 skrll if (cmplen == 0)
287 1.1 skrll cmplen = len;
288 1.1 skrll hash_insert (opcode_hash_control, buffer, (char *) pi);
289 1.1 skrll strcpy (prev_buffer, buffer);
290 1.1 skrll idx++;
291 1.1 skrll
292 1.1 skrll for (p = p1; p->name; p++)
293 1.1 skrll {
294 1.1 skrll /* A negative TIME is used to indicate that we've added this opcode
295 1.1 skrll already. */
296 1.1 skrll if (p->time == -1)
297 1.1 skrll continue;
298 1.1 skrll if (strncmp (p->name, buffer, cmplen) != 0
299 1.1 skrll || (p->name[cmplen] != '\0' && p->name[cmplen] != '.'
300 1.1 skrll && p->name[cmplen - 1] != '/'))
301 1.1 skrll {
302 1.1 skrll if (first_skipped == 0)
303 1.1 skrll first_skipped = p;
304 1.1 skrll break;
305 1.1 skrll }
306 1.1 skrll if (strncmp (p->name, buffer, len) != 0)
307 1.1 skrll {
308 1.1 skrll if (first_skipped == 0)
309 1.1 skrll first_skipped = p;
310 1.1 skrll continue;
311 1.1 skrll }
312 1.1 skrll
313 1.1 skrll p->time = -1;
314 1.1 skrll pi->size = p->name[len] == '.' ? p->name[len + 1] : 0;
315 1.1 skrll pi->idx = idx;
316 1.1 skrll
317 1.1 skrll /* Find the number of operands. */
318 1.1 skrll pi->noperands = 0;
319 1.1 skrll while (pi->noperands < 3 && p->args.nib[pi->noperands] != (op_type) E)
320 1.1 skrll pi->noperands++;
321 1.1 skrll
322 1.1 skrll /* Find the length of the opcode in bytes. */
323 1.1 skrll pi->length = 0;
324 1.1 skrll while (p->data.nib[pi->length * 2] != (op_type) E)
325 1.1 skrll pi->length++;
326 1.1 skrll
327 1.1 skrll pi->opcode = p;
328 1.1 skrll pi++;
329 1.1 skrll }
330 1.1 skrll p1 = first_skipped;
331 1.1 skrll }
332 1.1 skrll
333 1.1 skrll /* Add entry for the NULL vector terminator. */
334 1.1 skrll pi->length = 0;
335 1.1 skrll pi->noperands = 0;
336 1.1 skrll pi->idx = 0;
337 1.1 skrll pi->size = 0;
338 1.1 skrll pi->opcode = 0;
339 1.1 skrll
340 1.1 skrll linkrelax = 1;
341 1.1 skrll }
342 1.1 skrll
343 1.1 skrll struct h8_op
344 1.1 skrll {
345 1.1 skrll op_type mode;
346 1.1 skrll unsigned reg;
347 1.1 skrll expressionS exp;
348 1.1 skrll };
349 1.1 skrll
350 1.1 skrll static void clever_message (const struct h8_instruction *, struct h8_op *);
351 1.1 skrll static void fix_operand_size (struct h8_op *, int);
352 1.1 skrll static void build_bytes (const struct h8_instruction *, struct h8_op *);
353 1.1.1.2 christos static void do_a_fix_imm (int, int, struct h8_op *, int, const struct h8_instruction *);
354 1.1 skrll static void check_operand (struct h8_op *, unsigned int, char *);
355 1.1 skrll static const struct h8_instruction * get_specific (const struct h8_instruction *, struct h8_op *, int) ;
356 1.1 skrll static char *get_operands (unsigned, char *, struct h8_op *);
357 1.1 skrll static void get_operand (char **, struct h8_op *, int);
358 1.1 skrll static int parse_reg (char *, op_type *, unsigned *, int);
359 1.1 skrll static char *skip_colonthing (char *, int *);
360 1.1 skrll static char *parse_exp (char *, struct h8_op *);
361 1.1 skrll
362 1.1 skrll static int constant_fits_size_p (struct h8_op *, int, int);
363 1.1 skrll
364 1.1 skrll /*
365 1.1 skrll parse operands
366 1.1 skrll WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
367 1.1 skrll r0l,r0h,..r7l,r7h
368 1.1 skrll @WREG
369 1.1 skrll @WREG+
370 1.1 skrll @-WREG
371 1.1 skrll #const
372 1.1 skrll ccr
373 1.1 skrll */
374 1.1 skrll
375 1.1 skrll /* Try to parse a reg name. Return the number of chars consumed. */
376 1.1 skrll
377 1.1 skrll static int
378 1.1 skrll parse_reg (char *src, op_type *mode, unsigned int *reg, int direction)
379 1.1 skrll {
380 1.1 skrll char *end;
381 1.1 skrll int len;
382 1.1 skrll
383 1.1 skrll /* Cribbed from get_symbol_end. */
384 1.1 skrll if (!is_name_beginner (*src) || *src == '\001')
385 1.1 skrll return 0;
386 1.1 skrll end = src + 1;
387 1.1 skrll while ((is_part_of_name (*end) && *end != '.') || *end == '\001')
388 1.1 skrll end++;
389 1.1 skrll len = end - src;
390 1.1 skrll
391 1.1 skrll if (len == 2 && TOLOWER (src[0]) == 's' && TOLOWER (src[1]) == 'p')
392 1.1 skrll {
393 1.1 skrll *mode = PSIZE | REG | direction;
394 1.1 skrll *reg = 7;
395 1.1 skrll return len;
396 1.1 skrll }
397 1.1 skrll if (len == 3 &&
398 1.1 skrll TOLOWER (src[0]) == 'c' &&
399 1.1 skrll TOLOWER (src[1]) == 'c' &&
400 1.1 skrll TOLOWER (src[2]) == 'r')
401 1.1 skrll {
402 1.1 skrll *mode = CCR;
403 1.1 skrll *reg = 0;
404 1.1 skrll return len;
405 1.1 skrll }
406 1.1 skrll if (len == 3 &&
407 1.1 skrll TOLOWER (src[0]) == 'e' &&
408 1.1 skrll TOLOWER (src[1]) == 'x' &&
409 1.1 skrll TOLOWER (src[2]) == 'r')
410 1.1 skrll {
411 1.1 skrll *mode = EXR;
412 1.1 skrll *reg = 1;
413 1.1 skrll return len;
414 1.1 skrll }
415 1.1 skrll if (len == 3 &&
416 1.1 skrll TOLOWER (src[0]) == 'v' &&
417 1.1 skrll TOLOWER (src[1]) == 'b' &&
418 1.1 skrll TOLOWER (src[2]) == 'r')
419 1.1 skrll {
420 1.1 skrll *mode = VBR;
421 1.1 skrll *reg = 6;
422 1.1 skrll return len;
423 1.1 skrll }
424 1.1 skrll if (len == 3 &&
425 1.1 skrll TOLOWER (src[0]) == 's' &&
426 1.1 skrll TOLOWER (src[1]) == 'b' &&
427 1.1 skrll TOLOWER (src[2]) == 'r')
428 1.1 skrll {
429 1.1 skrll *mode = SBR;
430 1.1 skrll *reg = 7;
431 1.1 skrll return len;
432 1.1 skrll }
433 1.1 skrll if (len == 2 && TOLOWER (src[0]) == 'f' && TOLOWER (src[1]) == 'p')
434 1.1 skrll {
435 1.1 skrll *mode = PSIZE | REG | direction;
436 1.1 skrll *reg = 6;
437 1.1 skrll return len;
438 1.1 skrll }
439 1.1 skrll if (len == 3 && TOLOWER (src[0]) == 'e' && TOLOWER (src[1]) == 'r' &&
440 1.1 skrll src[2] >= '0' && src[2] <= '7')
441 1.1 skrll {
442 1.1 skrll *mode = L_32 | REG | direction;
443 1.1 skrll *reg = src[2] - '0';
444 1.1 skrll if (!Hmode)
445 1.1 skrll as_warn (_("Reg not valid for H8/300"));
446 1.1 skrll return len;
447 1.1 skrll }
448 1.1 skrll if (len == 2 && TOLOWER (src[0]) == 'e' && src[1] >= '0' && src[1] <= '7')
449 1.1 skrll {
450 1.1 skrll *mode = L_16 | REG | direction;
451 1.1 skrll *reg = src[1] - '0' + 8;
452 1.1 skrll if (!Hmode)
453 1.1 skrll as_warn (_("Reg not valid for H8/300"));
454 1.1 skrll return len;
455 1.1 skrll }
456 1.1 skrll
457 1.1 skrll if (TOLOWER (src[0]) == 'r')
458 1.1 skrll {
459 1.1 skrll if (src[1] >= '0' && src[1] <= '7')
460 1.1 skrll {
461 1.1 skrll if (len == 3 && TOLOWER (src[2]) == 'l')
462 1.1 skrll {
463 1.1 skrll *mode = L_8 | REG | direction;
464 1.1 skrll *reg = (src[1] - '0') + 8;
465 1.1 skrll return len;
466 1.1 skrll }
467 1.1 skrll if (len == 3 && TOLOWER (src[2]) == 'h')
468 1.1 skrll {
469 1.1 skrll *mode = L_8 | REG | direction;
470 1.1 skrll *reg = (src[1] - '0');
471 1.1 skrll return len;
472 1.1 skrll }
473 1.1 skrll if (len == 2)
474 1.1 skrll {
475 1.1 skrll *mode = L_16 | REG | direction;
476 1.1 skrll *reg = (src[1] - '0');
477 1.1 skrll return len;
478 1.1 skrll }
479 1.1 skrll }
480 1.1 skrll }
481 1.1 skrll
482 1.1 skrll return 0;
483 1.1 skrll }
484 1.1 skrll
485 1.1 skrll
486 1.1 skrll /* Parse an immediate or address-related constant and store it in OP.
487 1.1 skrll If the user also specifies the operand's size, store that size
488 1.1 skrll in OP->MODE, otherwise leave it for later code to decide. */
489 1.1 skrll
490 1.1 skrll static char *
491 1.1 skrll parse_exp (char *src, struct h8_op *op)
492 1.1 skrll {
493 1.1 skrll char *save;
494 1.1 skrll
495 1.1 skrll save = input_line_pointer;
496 1.1 skrll input_line_pointer = src;
497 1.1 skrll expression (&op->exp);
498 1.1 skrll if (op->exp.X_op == O_absent)
499 1.1 skrll as_bad (_("missing operand"));
500 1.1 skrll src = input_line_pointer;
501 1.1 skrll input_line_pointer = save;
502 1.1 skrll
503 1.1 skrll return skip_colonthing (src, &op->mode);
504 1.1 skrll }
505 1.1 skrll
506 1.1 skrll
507 1.1 skrll /* If SRC starts with an explicit operand size, skip it and store the size
508 1.1 skrll in *MODE. Leave *MODE unchanged otherwise. */
509 1.1 skrll
510 1.1 skrll static char *
511 1.1 skrll skip_colonthing (char *src, int *mode)
512 1.1 skrll {
513 1.1 skrll if (*src == ':')
514 1.1 skrll {
515 1.1 skrll src++;
516 1.1 skrll *mode &= ~SIZE;
517 1.1 skrll if (src[0] == '8' && !ISDIGIT (src[1]))
518 1.1 skrll *mode |= L_8;
519 1.1 skrll else if (src[0] == '2' && !ISDIGIT (src[1]))
520 1.1 skrll *mode |= L_2;
521 1.1 skrll else if (src[0] == '3' && !ISDIGIT (src[1]))
522 1.1 skrll *mode |= L_3;
523 1.1 skrll else if (src[0] == '4' && !ISDIGIT (src[1]))
524 1.1 skrll *mode |= L_4;
525 1.1 skrll else if (src[0] == '5' && !ISDIGIT (src[1]))
526 1.1 skrll *mode |= L_5;
527 1.1 skrll else if (src[0] == '2' && src[1] == '4' && !ISDIGIT (src[2]))
528 1.1 skrll *mode |= L_24;
529 1.1 skrll else if (src[0] == '3' && src[1] == '2' && !ISDIGIT (src[2]))
530 1.1 skrll *mode |= L_32;
531 1.1 skrll else if (src[0] == '1' && src[1] == '6' && !ISDIGIT (src[2]))
532 1.1 skrll *mode |= L_16;
533 1.1 skrll else
534 1.1 skrll as_bad (_("invalid operand size requested"));
535 1.1 skrll
536 1.1 skrll while (ISDIGIT (*src))
537 1.1 skrll src++;
538 1.1 skrll }
539 1.1 skrll return src;
540 1.1 skrll }
541 1.1 skrll
542 1.1 skrll /* The many forms of operand:
543 1.1 skrll
544 1.1 skrll Rn Register direct
545 1.1 skrll @Rn Register indirect
546 1.1 skrll @(exp[:16], Rn) Register indirect with displacement
547 1.1 skrll @Rn+
548 1.1 skrll @-Rn
549 1.1 skrll @aa:8 absolute 8 bit
550 1.1 skrll @aa:16 absolute 16 bit
551 1.1 skrll @aa absolute 16 bit
552 1.1 skrll
553 1.1 skrll #xx[:size] immediate data
554 1.1 skrll @(exp:[8], pc) pc rel
555 1.1 skrll @@aa[:8] memory indirect. */
556 1.1 skrll
557 1.1 skrll static int
558 1.1.1.3 christos constant_fits_width_p (struct h8_op *operand, offsetT width)
559 1.1 skrll {
560 1.1.1.3 christos offsetT num;
561 1.1.1.3 christos
562 1.1.1.3 christos num = ((operand->exp.X_add_number & 0xffffffff) ^ 0x80000000) - 0x80000000;
563 1.1.1.3 christos return (num & ~width) == 0 || (num | width) == ~0;
564 1.1 skrll }
565 1.1 skrll
566 1.1 skrll static int
567 1.1 skrll constant_fits_size_p (struct h8_op *operand, int size, int no_symbols)
568 1.1 skrll {
569 1.1.1.3 christos offsetT num;
570 1.1.1.3 christos
571 1.1 skrll if (no_symbols
572 1.1 skrll && (operand->exp.X_add_symbol != 0 || operand->exp.X_op_symbol != 0))
573 1.1 skrll return 0;
574 1.1.1.3 christos num = operand->exp.X_add_number & 0xffffffff;
575 1.1 skrll switch (size)
576 1.1 skrll {
577 1.1 skrll case L_2:
578 1.1 skrll return (num & ~3) == 0;
579 1.1 skrll case L_3:
580 1.1 skrll return (num & ~7) == 0;
581 1.1 skrll case L_3NZ:
582 1.1 skrll return num >= 1 && num < 8;
583 1.1 skrll case L_4:
584 1.1 skrll return (num & ~15) == 0;
585 1.1 skrll case L_5:
586 1.1 skrll return num >= 1 && num < 32;
587 1.1 skrll case L_8:
588 1.1.1.3 christos num = (num ^ 0x80000000) - 0x80000000;
589 1.1.1.3 christos return (num & ~0xFF) == 0 || (num | 0x7F) == ~0;
590 1.1 skrll case L_8U:
591 1.1 skrll return (num & ~0xFF) == 0;
592 1.1 skrll case L_16:
593 1.1.1.3 christos num = (num ^ 0x80000000) - 0x80000000;
594 1.1.1.3 christos return (num & ~0xFFFF) == 0 || (num | 0x7FFF) == ~0;
595 1.1 skrll case L_16U:
596 1.1 skrll return (num & ~0xFFFF) == 0;
597 1.1 skrll case L_32:
598 1.1 skrll return 1;
599 1.1 skrll default:
600 1.1 skrll abort ();
601 1.1 skrll }
602 1.1 skrll }
603 1.1 skrll
604 1.1 skrll static void
605 1.1 skrll get_operand (char **ptr, struct h8_op *op, int direction)
606 1.1 skrll {
607 1.1 skrll char *src = *ptr;
608 1.1 skrll op_type mode;
609 1.1 skrll unsigned int num;
610 1.1 skrll unsigned int len;
611 1.1 skrll
612 1.1 skrll op->mode = 0;
613 1.1 skrll
614 1.1 skrll /* Check for '(' and ')' for instructions ldm and stm. */
615 1.1 skrll if (src[0] == '(' && src[8] == ')')
616 1.1 skrll ++ src;
617 1.1 skrll
618 1.1 skrll /* Gross. Gross. ldm and stm have a format not easily handled
619 1.1 skrll by get_operand. We deal with it explicitly here. */
620 1.1 skrll if (TOLOWER (src[0]) == 'e' && TOLOWER (src[1]) == 'r' &&
621 1.1 skrll ISDIGIT (src[2]) && src[3] == '-' &&
622 1.1 skrll TOLOWER (src[4]) == 'e' && TOLOWER (src[5]) == 'r' && ISDIGIT (src[6]))
623 1.1 skrll {
624 1.1 skrll int low, high;
625 1.1 skrll
626 1.1 skrll low = src[2] - '0';
627 1.1 skrll high = src[6] - '0';
628 1.1 skrll
629 1.1 skrll /* Check register pair's validity as per tech note TN-H8*-193A/E
630 1.1 skrll from Renesas for H8S and H8SX hardware manual. */
631 1.1 skrll if ( !(low == 0 && (high == 1 || high == 2 || high == 3))
632 1.1 skrll && !(low == 1 && (high == 2 || high == 3 || high == 4) && SXmode)
633 1.1 skrll && !(low == 2 && (high == 3 || ((high == 4 || high == 5) && SXmode)))
634 1.1 skrll && !(low == 3 && (high == 4 || high == 5 || high == 6) && SXmode)
635 1.1 skrll && !(low == 4 && (high == 5 || high == 6))
636 1.1 skrll && !(low == 4 && high == 7 && SXmode)
637 1.1 skrll && !(low == 5 && (high == 6 || high == 7) && SXmode)
638 1.1 skrll && !(low == 6 && high == 7 && SXmode))
639 1.1 skrll as_bad (_("Invalid register list for ldm/stm\n"));
640 1.1 skrll
641 1.1 skrll /* Even sicker. We encode two registers into op->reg. One
642 1.1 skrll for the low register to save, the other for the high
643 1.1 skrll register to save; we also set the high bit in op->reg
644 1.1 skrll so we know this is "very special". */
645 1.1 skrll op->reg = 0x80000000 | (high << 8) | low;
646 1.1 skrll op->mode = REG;
647 1.1 skrll if (src[7] == ')')
648 1.1 skrll *ptr = src + 8;
649 1.1 skrll else
650 1.1 skrll *ptr = src + 7;
651 1.1 skrll return;
652 1.1 skrll }
653 1.1 skrll
654 1.1 skrll len = parse_reg (src, &op->mode, &op->reg, direction);
655 1.1 skrll if (len)
656 1.1 skrll {
657 1.1 skrll src += len;
658 1.1 skrll if (*src == '.')
659 1.1 skrll {
660 1.1 skrll int size = op->mode & SIZE;
661 1.1 skrll switch (src[1])
662 1.1 skrll {
663 1.1 skrll case 'l': case 'L':
664 1.1 skrll if (size != L_32)
665 1.1 skrll as_warn (_("mismatch between register and suffix"));
666 1.1 skrll op->mode = (op->mode & ~MODE) | LOWREG;
667 1.1 skrll break;
668 1.1 skrll case 'w': case 'W':
669 1.1 skrll if (size != L_32 && size != L_16)
670 1.1 skrll as_warn (_("mismatch between register and suffix"));
671 1.1 skrll op->mode = (op->mode & ~MODE) | LOWREG;
672 1.1 skrll op->mode = (op->mode & ~SIZE) | L_16;
673 1.1 skrll break;
674 1.1 skrll case 'b': case 'B':
675 1.1 skrll op->mode = (op->mode & ~MODE) | LOWREG;
676 1.1 skrll if (size != L_32 && size != L_8)
677 1.1 skrll as_warn (_("mismatch between register and suffix"));
678 1.1 skrll op->mode = (op->mode & ~MODE) | LOWREG;
679 1.1 skrll op->mode = (op->mode & ~SIZE) | L_8;
680 1.1 skrll break;
681 1.1 skrll default:
682 1.1.1.2 christos as_warn (_("invalid suffix after register."));
683 1.1 skrll break;
684 1.1 skrll }
685 1.1 skrll src += 2;
686 1.1 skrll }
687 1.1 skrll *ptr = src;
688 1.1 skrll return;
689 1.1 skrll }
690 1.1 skrll
691 1.1 skrll if (*src == '@')
692 1.1 skrll {
693 1.1 skrll src++;
694 1.1 skrll if (*src == '@')
695 1.1 skrll {
696 1.1 skrll *ptr = parse_exp (src + 1, op);
697 1.1 skrll if (op->exp.X_add_number >= 0x100)
698 1.1 skrll {
699 1.1 skrll int divisor = 1;
700 1.1 skrll
701 1.1 skrll op->mode = VECIND;
702 1.1 skrll /* FIXME : 2? or 4? */
703 1.1 skrll if (op->exp.X_add_number >= 0x400)
704 1.1 skrll as_bad (_("address too high for vector table jmp/jsr"));
705 1.1 skrll else if (op->exp.X_add_number >= 0x200)
706 1.1 skrll divisor = 4;
707 1.1 skrll else
708 1.1 skrll divisor = 2;
709 1.1 skrll
710 1.1 skrll op->exp.X_add_number = op->exp.X_add_number / divisor - 0x80;
711 1.1 skrll }
712 1.1 skrll else
713 1.1 skrll op->mode = MEMIND;
714 1.1 skrll return;
715 1.1 skrll }
716 1.1 skrll
717 1.1 skrll if (*src == '-' || *src == '+')
718 1.1 skrll {
719 1.1 skrll len = parse_reg (src + 1, &mode, &num, direction);
720 1.1 skrll if (len == 0)
721 1.1 skrll {
722 1.1 skrll /* Oops, not a reg after all, must be ordinary exp. */
723 1.1 skrll op->mode = ABS | direction;
724 1.1 skrll *ptr = parse_exp (src, op);
725 1.1 skrll return;
726 1.1 skrll }
727 1.1 skrll
728 1.1 skrll if (((mode & SIZE) != PSIZE)
729 1.1 skrll /* For Normal mode accept 16 bit and 32 bit pointer registers. */
730 1.1 skrll && (!Nmode || ((mode & SIZE) != L_32)))
731 1.1 skrll as_bad (_("Wrong size pointer register for architecture."));
732 1.1 skrll
733 1.1 skrll op->mode = src[0] == '-' ? RDPREDEC : RDPREINC;
734 1.1 skrll op->reg = num;
735 1.1 skrll *ptr = src + 1 + len;
736 1.1 skrll return;
737 1.1 skrll }
738 1.1 skrll if (*src == '(')
739 1.1 skrll {
740 1.1 skrll src++;
741 1.1 skrll
742 1.1 skrll /* See if this is @(ERn.x, PC). */
743 1.1 skrll len = parse_reg (src, &mode, &op->reg, direction);
744 1.1 skrll if (len != 0 && (mode & MODE) == REG && src[len] == '.')
745 1.1 skrll {
746 1.1 skrll switch (TOLOWER (src[len + 1]))
747 1.1 skrll {
748 1.1 skrll case 'b':
749 1.1 skrll mode = PCIDXB | direction;
750 1.1 skrll break;
751 1.1 skrll case 'w':
752 1.1 skrll mode = PCIDXW | direction;
753 1.1 skrll break;
754 1.1 skrll case 'l':
755 1.1 skrll mode = PCIDXL | direction;
756 1.1 skrll break;
757 1.1 skrll default:
758 1.1 skrll mode = 0;
759 1.1 skrll break;
760 1.1 skrll }
761 1.1 skrll if (mode
762 1.1 skrll && src[len + 2] == ','
763 1.1 skrll && TOLOWER (src[len + 3]) != 'p'
764 1.1 skrll && TOLOWER (src[len + 4]) != 'c'
765 1.1 skrll && src[len + 5] != ')')
766 1.1 skrll {
767 1.1 skrll *ptr = src + len + 6;
768 1.1 skrll op->mode |= mode;
769 1.1 skrll return;
770 1.1 skrll }
771 1.1 skrll /* Fall through into disp case - the grammar is somewhat
772 1.1 skrll ambiguous, so we should try whether it's a DISP operand
773 1.1 skrll after all ("ER3.L" might be a poorly named label...). */
774 1.1 skrll }
775 1.1 skrll
776 1.1 skrll /* Disp. */
777 1.1 skrll
778 1.1 skrll /* Start off assuming a 16 bit offset. */
779 1.1 skrll
780 1.1 skrll src = parse_exp (src, op);
781 1.1 skrll if (*src == ')')
782 1.1 skrll {
783 1.1 skrll op->mode |= ABS | direction;
784 1.1 skrll *ptr = src + 1;
785 1.1 skrll return;
786 1.1 skrll }
787 1.1 skrll
788 1.1 skrll if (*src != ',')
789 1.1 skrll {
790 1.1 skrll as_bad (_("expected @(exp, reg16)"));
791 1.1 skrll return;
792 1.1 skrll }
793 1.1 skrll src++;
794 1.1 skrll
795 1.1 skrll len = parse_reg (src, &mode, &op->reg, direction);
796 1.1 skrll if (len == 0 || (mode & MODE) != REG)
797 1.1 skrll {
798 1.1 skrll as_bad (_("expected @(exp, reg16)"));
799 1.1 skrll return;
800 1.1 skrll }
801 1.1 skrll src += len;
802 1.1 skrll if (src[0] == '.')
803 1.1 skrll {
804 1.1 skrll switch (TOLOWER (src[1]))
805 1.1 skrll {
806 1.1 skrll case 'b':
807 1.1 skrll op->mode |= INDEXB | direction;
808 1.1 skrll break;
809 1.1 skrll case 'w':
810 1.1 skrll op->mode |= INDEXW | direction;
811 1.1 skrll break;
812 1.1 skrll case 'l':
813 1.1 skrll op->mode |= INDEXL | direction;
814 1.1 skrll break;
815 1.1 skrll default:
816 1.1 skrll as_bad (_("expected .L, .W or .B for register in indexed addressing mode"));
817 1.1 skrll }
818 1.1 skrll src += 2;
819 1.1 skrll op->reg &= 7;
820 1.1 skrll }
821 1.1 skrll else
822 1.1 skrll op->mode |= DISP | direction;
823 1.1 skrll src = skip_colonthing (src, &op->mode);
824 1.1 skrll
825 1.1 skrll if (*src != ')' && '(')
826 1.1 skrll {
827 1.1 skrll as_bad (_("expected @(exp, reg16)"));
828 1.1 skrll return;
829 1.1 skrll }
830 1.1 skrll *ptr = src + 1;
831 1.1 skrll return;
832 1.1 skrll }
833 1.1 skrll len = parse_reg (src, &mode, &num, direction);
834 1.1 skrll
835 1.1 skrll if (len)
836 1.1 skrll {
837 1.1 skrll src += len;
838 1.1 skrll if (*src == '+' || *src == '-')
839 1.1 skrll {
840 1.1 skrll if (((mode & SIZE) != PSIZE)
841 1.1 skrll /* For Normal mode accept 16 bit and 32 bit pointer registers. */
842 1.1 skrll && (!Nmode || ((mode & SIZE) != L_32)))
843 1.1 skrll as_bad (_("Wrong size pointer register for architecture."));
844 1.1 skrll op->mode = *src == '+' ? RSPOSTINC : RSPOSTDEC;
845 1.1 skrll op->reg = num;
846 1.1 skrll src++;
847 1.1 skrll *ptr = src;
848 1.1 skrll return;
849 1.1 skrll }
850 1.1 skrll if (((mode & SIZE) != PSIZE)
851 1.1 skrll /* For Normal mode accept 16 bit and 32 bit pointer registers. */
852 1.1 skrll && (!Nmode || ((mode & SIZE) != L_32)))
853 1.1 skrll as_bad (_("Wrong size pointer register for architecture."));
854 1.1 skrll
855 1.1 skrll op->mode = direction | IND | PSIZE;
856 1.1 skrll op->reg = num;
857 1.1 skrll *ptr = src;
858 1.1 skrll
859 1.1 skrll return;
860 1.1 skrll }
861 1.1 skrll else
862 1.1 skrll {
863 1.1 skrll /* must be a symbol */
864 1.1 skrll
865 1.1 skrll op->mode = ABS | direction;
866 1.1 skrll *ptr = parse_exp (src, op);
867 1.1 skrll return;
868 1.1 skrll }
869 1.1 skrll }
870 1.1 skrll
871 1.1 skrll if (*src == '#')
872 1.1 skrll {
873 1.1 skrll op->mode = IMM;
874 1.1 skrll *ptr = parse_exp (src + 1, op);
875 1.1 skrll return;
876 1.1 skrll }
877 1.1 skrll else if (strncmp (src, "mach", 4) == 0 ||
878 1.1 skrll strncmp (src, "macl", 4) == 0 ||
879 1.1 skrll strncmp (src, "MACH", 4) == 0 ||
880 1.1 skrll strncmp (src, "MACL", 4) == 0)
881 1.1 skrll {
882 1.1 skrll op->reg = TOLOWER (src[3]) == 'l';
883 1.1 skrll op->mode = MACREG;
884 1.1 skrll *ptr = src + 4;
885 1.1 skrll return;
886 1.1 skrll }
887 1.1 skrll else
888 1.1 skrll {
889 1.1 skrll op->mode = PCREL;
890 1.1 skrll *ptr = parse_exp (src, op);
891 1.1 skrll }
892 1.1 skrll }
893 1.1 skrll
894 1.1 skrll static char *
895 1.1 skrll get_operands (unsigned int noperands, char *op_end, struct h8_op *operand)
896 1.1 skrll {
897 1.1 skrll char *ptr = op_end;
898 1.1 skrll
899 1.1 skrll switch (noperands)
900 1.1 skrll {
901 1.1 skrll case 0:
902 1.1 skrll break;
903 1.1 skrll
904 1.1 skrll case 1:
905 1.1 skrll ptr++;
906 1.1 skrll get_operand (&ptr, operand + 0, SRC);
907 1.1 skrll if (*ptr == ',')
908 1.1 skrll {
909 1.1 skrll ptr++;
910 1.1 skrll get_operand (&ptr, operand + 1, DST);
911 1.1 skrll }
912 1.1 skrll break;
913 1.1 skrll
914 1.1 skrll case 2:
915 1.1 skrll ptr++;
916 1.1 skrll get_operand (&ptr, operand + 0, SRC);
917 1.1 skrll if (*ptr == ',')
918 1.1 skrll ptr++;
919 1.1 skrll get_operand (&ptr, operand + 1, DST);
920 1.1 skrll break;
921 1.1 skrll
922 1.1 skrll case 3:
923 1.1 skrll ptr++;
924 1.1 skrll get_operand (&ptr, operand + 0, SRC);
925 1.1 skrll if (*ptr == ',')
926 1.1 skrll ptr++;
927 1.1 skrll get_operand (&ptr, operand + 1, DST);
928 1.1 skrll if (*ptr == ',')
929 1.1 skrll ptr++;
930 1.1 skrll get_operand (&ptr, operand + 2, OP3);
931 1.1 skrll break;
932 1.1 skrll
933 1.1 skrll default:
934 1.1 skrll abort ();
935 1.1 skrll }
936 1.1 skrll
937 1.1 skrll return ptr;
938 1.1 skrll }
939 1.1 skrll
940 1.1 skrll /* MOVA has special requirements. Rather than adding twice the amount of
941 1.1 skrll addressing modes, we simply special case it a bit. */
942 1.1 skrll static void
943 1.1 skrll get_mova_operands (char *op_end, struct h8_op *operand)
944 1.1 skrll {
945 1.1 skrll char *ptr = op_end;
946 1.1 skrll
947 1.1 skrll if (ptr[1] != '@' || ptr[2] != '(')
948 1.1 skrll goto error;
949 1.1 skrll ptr += 3;
950 1.1 skrll operand[0].mode = 0;
951 1.1 skrll ptr = parse_exp (ptr, &operand[0]);
952 1.1 skrll
953 1.1 skrll if (*ptr !=',')
954 1.1 skrll goto error;
955 1.1 skrll ptr++;
956 1.1 skrll get_operand (&ptr, operand + 1, DST);
957 1.1 skrll
958 1.1 skrll if (*ptr =='.')
959 1.1 skrll {
960 1.1 skrll ptr++;
961 1.1 skrll switch (*ptr++)
962 1.1 skrll {
963 1.1 skrll case 'b': case 'B':
964 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXB;
965 1.1 skrll break;
966 1.1 skrll case 'w': case 'W':
967 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXW;
968 1.1 skrll break;
969 1.1 skrll case 'l': case 'L':
970 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXL;
971 1.1 skrll break;
972 1.1 skrll default:
973 1.1 skrll goto error;
974 1.1 skrll }
975 1.1 skrll }
976 1.1 skrll else if ((operand[1].mode & MODE) == LOWREG)
977 1.1 skrll {
978 1.1 skrll switch (operand[1].mode & SIZE)
979 1.1 skrll {
980 1.1 skrll case L_8:
981 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXB;
982 1.1 skrll break;
983 1.1 skrll case L_16:
984 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXW;
985 1.1 skrll break;
986 1.1 skrll case L_32:
987 1.1 skrll operand[0].mode = (operand[0].mode & ~MODE) | INDEXL;
988 1.1 skrll break;
989 1.1 skrll default:
990 1.1 skrll goto error;
991 1.1 skrll }
992 1.1 skrll }
993 1.1 skrll else
994 1.1 skrll goto error;
995 1.1 skrll
996 1.1 skrll if (*ptr++ != ')' || *ptr++ != ',')
997 1.1 skrll goto error;
998 1.1 skrll get_operand (&ptr, operand + 2, OP3);
999 1.1 skrll /* See if we can use the short form of MOVA. */
1000 1.1 skrll if (((operand[1].mode & MODE) == REG || (operand[1].mode & MODE) == LOWREG)
1001 1.1 skrll && (operand[2].mode & MODE) == REG
1002 1.1 skrll && (operand[1].reg & 7) == (operand[2].reg & 7))
1003 1.1 skrll {
1004 1.1 skrll operand[1].mode = operand[2].mode = 0;
1005 1.1 skrll operand[0].reg = operand[2].reg & 7;
1006 1.1 skrll }
1007 1.1 skrll return;
1008 1.1 skrll
1009 1.1 skrll error:
1010 1.1 skrll as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
1011 1.1 skrll }
1012 1.1 skrll
1013 1.1 skrll static void
1014 1.1 skrll get_rtsl_operands (char *ptr, struct h8_op *operand)
1015 1.1 skrll {
1016 1.1 skrll int mode, len, type = 0;
1017 1.1 skrll unsigned int num, num2;
1018 1.1 skrll
1019 1.1 skrll ptr++;
1020 1.1 skrll if (*ptr == '(')
1021 1.1 skrll {
1022 1.1 skrll ptr++;
1023 1.1 skrll type = 1;
1024 1.1 skrll }
1025 1.1 skrll len = parse_reg (ptr, &mode, &num, SRC);
1026 1.1 skrll if (len == 0 || (mode & MODE) != REG)
1027 1.1 skrll {
1028 1.1 skrll as_bad (_("expected register"));
1029 1.1 skrll return;
1030 1.1 skrll }
1031 1.1 skrll ptr += len;
1032 1.1 skrll if (*ptr == '-')
1033 1.1 skrll {
1034 1.1 skrll len = parse_reg (++ptr, &mode, &num2, SRC);
1035 1.1 skrll if (len == 0 || (mode & MODE) != REG)
1036 1.1 skrll {
1037 1.1 skrll as_bad (_("expected register"));
1038 1.1 skrll return;
1039 1.1 skrll }
1040 1.1 skrll ptr += len;
1041 1.1 skrll /* CONST_xxx are used as placeholders in the opcode table. */
1042 1.1 skrll num = num2 - num;
1043 1.1 skrll if (num > 3)
1044 1.1 skrll {
1045 1.1 skrll as_bad (_("invalid register list"));
1046 1.1 skrll return;
1047 1.1 skrll }
1048 1.1 skrll }
1049 1.1 skrll else
1050 1.1 skrll num2 = num, num = 0;
1051 1.1 skrll if (type == 1 && *ptr++ != ')')
1052 1.1 skrll {
1053 1.1 skrll as_bad (_("expected closing paren"));
1054 1.1 skrll return;
1055 1.1 skrll }
1056 1.1 skrll operand[0].mode = RS32;
1057 1.1 skrll operand[1].mode = RD32;
1058 1.1 skrll operand[0].reg = num;
1059 1.1 skrll operand[1].reg = num2;
1060 1.1 skrll }
1061 1.1 skrll
1062 1.1 skrll /* Passed a pointer to a list of opcodes which use different
1063 1.1 skrll addressing modes, return the opcode which matches the opcodes
1064 1.1 skrll provided. */
1065 1.1 skrll
1066 1.1 skrll static const struct h8_instruction *
1067 1.1 skrll get_specific (const struct h8_instruction *instruction,
1068 1.1 skrll struct h8_op *operands, int size)
1069 1.1 skrll {
1070 1.1 skrll const struct h8_instruction *this_try = instruction;
1071 1.1 skrll const struct h8_instruction *found_other = 0, *found_mismatched = 0;
1072 1.1 skrll int found = 0;
1073 1.1 skrll int this_index = instruction->idx;
1074 1.1 skrll int noperands = 0;
1075 1.1 skrll
1076 1.1 skrll /* There's only one ldm/stm and it's easier to just
1077 1.1 skrll get out quick for them. */
1078 1.1 skrll if (OP_KIND (instruction->opcode->how) == O_LDM
1079 1.1 skrll || OP_KIND (instruction->opcode->how) == O_STM)
1080 1.1 skrll return this_try;
1081 1.1 skrll
1082 1.1 skrll while (noperands < 3 && operands[noperands].mode != 0)
1083 1.1 skrll noperands++;
1084 1.1 skrll
1085 1.1 skrll while (this_index == instruction->idx && !found)
1086 1.1 skrll {
1087 1.1 skrll int this_size;
1088 1.1 skrll
1089 1.1 skrll found = 1;
1090 1.1 skrll this_try = instruction++;
1091 1.1 skrll this_size = this_try->opcode->how & SN;
1092 1.1 skrll
1093 1.1 skrll if (this_try->noperands != noperands)
1094 1.1 skrll found = 0;
1095 1.1 skrll else if (this_try->noperands > 0)
1096 1.1 skrll {
1097 1.1 skrll int i;
1098 1.1 skrll
1099 1.1 skrll for (i = 0; i < this_try->noperands && found; i++)
1100 1.1 skrll {
1101 1.1 skrll op_type op = this_try->opcode->args.nib[i];
1102 1.1 skrll int op_mode = op & MODE;
1103 1.1 skrll int op_size = op & SIZE;
1104 1.1 skrll int x = operands[i].mode;
1105 1.1 skrll int x_mode = x & MODE;
1106 1.1 skrll int x_size = x & SIZE;
1107 1.1 skrll
1108 1.1 skrll if (op_mode == LOWREG && (x_mode == REG || x_mode == LOWREG))
1109 1.1 skrll {
1110 1.1 skrll if ((x_size == L_8 && (operands[i].reg & 8) == 0)
1111 1.1 skrll || (x_size == L_16 && (operands[i].reg & 8) == 8))
1112 1.1 skrll as_warn (_("can't use high part of register in operand %d"), i);
1113 1.1 skrll
1114 1.1 skrll if (x_size != op_size)
1115 1.1 skrll found = 0;
1116 1.1 skrll }
1117 1.1 skrll else if (op_mode == REG)
1118 1.1 skrll {
1119 1.1 skrll if (x_mode == LOWREG)
1120 1.1 skrll x_mode = REG;
1121 1.1 skrll if (x_mode != REG)
1122 1.1 skrll found = 0;
1123 1.1 skrll
1124 1.1 skrll if (x_size == L_P)
1125 1.1 skrll x_size = (Hmode ? L_32 : L_16);
1126 1.1 skrll if (op_size == L_P)
1127 1.1 skrll op_size = (Hmode ? L_32 : L_16);
1128 1.1 skrll
1129 1.1 skrll /* The size of the reg is v important. */
1130 1.1 skrll if (op_size != x_size)
1131 1.1 skrll found = 0;
1132 1.1 skrll }
1133 1.1 skrll else if (op_mode & CTRL) /* control register */
1134 1.1 skrll {
1135 1.1 skrll if (!(x_mode & CTRL))
1136 1.1 skrll found = 0;
1137 1.1 skrll
1138 1.1 skrll switch (x_mode)
1139 1.1 skrll {
1140 1.1 skrll case CCR:
1141 1.1 skrll if (op_mode != CCR &&
1142 1.1 skrll op_mode != CCR_EXR &&
1143 1.1 skrll op_mode != CC_EX_VB_SB)
1144 1.1 skrll found = 0;
1145 1.1 skrll break;
1146 1.1 skrll case EXR:
1147 1.1 skrll if (op_mode != EXR &&
1148 1.1 skrll op_mode != CCR_EXR &&
1149 1.1 skrll op_mode != CC_EX_VB_SB)
1150 1.1 skrll found = 0;
1151 1.1 skrll break;
1152 1.1 skrll case MACH:
1153 1.1 skrll if (op_mode != MACH &&
1154 1.1 skrll op_mode != MACREG)
1155 1.1 skrll found = 0;
1156 1.1 skrll break;
1157 1.1 skrll case MACL:
1158 1.1 skrll if (op_mode != MACL &&
1159 1.1 skrll op_mode != MACREG)
1160 1.1 skrll found = 0;
1161 1.1 skrll break;
1162 1.1 skrll case VBR:
1163 1.1 skrll if (op_mode != VBR &&
1164 1.1 skrll op_mode != VBR_SBR &&
1165 1.1 skrll op_mode != CC_EX_VB_SB)
1166 1.1 skrll found = 0;
1167 1.1 skrll break;
1168 1.1 skrll case SBR:
1169 1.1 skrll if (op_mode != SBR &&
1170 1.1 skrll op_mode != VBR_SBR &&
1171 1.1 skrll op_mode != CC_EX_VB_SB)
1172 1.1 skrll found = 0;
1173 1.1 skrll break;
1174 1.1 skrll }
1175 1.1 skrll }
1176 1.1 skrll else if ((op & ABSJMP) && (x_mode == ABS || x_mode == PCREL))
1177 1.1 skrll {
1178 1.1 skrll operands[i].mode &= ~MODE;
1179 1.1 skrll operands[i].mode |= ABSJMP;
1180 1.1 skrll /* But it may not be 24 bits long. */
1181 1.1 skrll if (x_mode == ABS && !Hmode)
1182 1.1 skrll {
1183 1.1 skrll operands[i].mode &= ~SIZE;
1184 1.1 skrll operands[i].mode |= L_16;
1185 1.1 skrll }
1186 1.1 skrll if ((operands[i].mode & SIZE) == L_32
1187 1.1 skrll && (op_mode & SIZE) != L_32)
1188 1.1 skrll found = 0;
1189 1.1 skrll }
1190 1.1 skrll else if (x_mode == IMM && op_mode != IMM)
1191 1.1 skrll {
1192 1.1.1.3 christos offsetT num = operands[i].exp.X_add_number & 0xffffffff;
1193 1.1 skrll if (op_mode == KBIT || op_mode == DBIT)
1194 1.1 skrll /* This is ok if the immediate value is sensible. */;
1195 1.1 skrll else if (op_mode == CONST_2)
1196 1.1 skrll found = num == 2;
1197 1.1 skrll else if (op_mode == CONST_4)
1198 1.1 skrll found = num == 4;
1199 1.1 skrll else if (op_mode == CONST_8)
1200 1.1 skrll found = num == 8;
1201 1.1 skrll else if (op_mode == CONST_16)
1202 1.1 skrll found = num == 16;
1203 1.1 skrll else
1204 1.1 skrll found = 0;
1205 1.1 skrll }
1206 1.1 skrll else if (op_mode == PCREL && op_mode == x_mode)
1207 1.1 skrll {
1208 1.1 skrll /* movsd, bsr/bc and bsr/bs only come in PCREL16 flavour:
1209 1.1 skrll If x_size is L_8, promote it. */
1210 1.1 skrll if (OP_KIND (this_try->opcode->how) == O_MOVSD
1211 1.1 skrll || OP_KIND (this_try->opcode->how) == O_BSRBC
1212 1.1 skrll || OP_KIND (this_try->opcode->how) == O_BSRBS)
1213 1.1 skrll if (x_size == L_8)
1214 1.1 skrll x_size = L_16;
1215 1.1 skrll
1216 1.1 skrll /* The size of the displacement is important. */
1217 1.1 skrll if (op_size != x_size)
1218 1.1 skrll found = 0;
1219 1.1 skrll }
1220 1.1 skrll else if ((op_mode == DISP || op_mode == IMM || op_mode == ABS
1221 1.1 skrll || op_mode == INDEXB || op_mode == INDEXW
1222 1.1 skrll || op_mode == INDEXL)
1223 1.1 skrll && op_mode == x_mode)
1224 1.1 skrll {
1225 1.1 skrll /* Promote a L_24 to L_32 if it makes us match. */
1226 1.1 skrll if (x_size == L_24 && op_size == L_32)
1227 1.1 skrll {
1228 1.1 skrll x &= ~SIZE;
1229 1.1 skrll x |= x_size = L_32;
1230 1.1 skrll }
1231 1.1 skrll
1232 1.1 skrll if (((x_size == L_16 && op_size == L_16U)
1233 1.1 skrll || (x_size == L_8 && op_size == L_8U)
1234 1.1 skrll || (x_size == L_3 && op_size == L_3NZ))
1235 1.1 skrll /* We're deliberately more permissive for ABS modes. */
1236 1.1 skrll && (op_mode == ABS
1237 1.1 skrll || constant_fits_size_p (operands + i, op_size,
1238 1.1 skrll op & NO_SYMBOLS)))
1239 1.1 skrll x_size = op_size;
1240 1.1 skrll
1241 1.1 skrll if (x_size != 0 && op_size != x_size)
1242 1.1 skrll found = 0;
1243 1.1 skrll else if (x_size == 0
1244 1.1 skrll && ! constant_fits_size_p (operands + i, op_size,
1245 1.1 skrll op & NO_SYMBOLS))
1246 1.1 skrll found = 0;
1247 1.1 skrll }
1248 1.1 skrll else if (op_mode != x_mode)
1249 1.1 skrll {
1250 1.1 skrll found = 0;
1251 1.1 skrll }
1252 1.1 skrll }
1253 1.1 skrll }
1254 1.1 skrll if (found)
1255 1.1 skrll {
1256 1.1 skrll if ((this_try->opcode->available == AV_H8SX && ! SXmode)
1257 1.1 skrll || (this_try->opcode->available == AV_H8S && ! Smode)
1258 1.1 skrll || (this_try->opcode->available == AV_H8H && ! Hmode))
1259 1.1 skrll found = 0, found_other = this_try;
1260 1.1 skrll else if (this_size != size && (this_size != SN && size != SN))
1261 1.1 skrll found_mismatched = this_try, found = 0;
1262 1.1 skrll
1263 1.1 skrll }
1264 1.1 skrll }
1265 1.1 skrll if (found)
1266 1.1 skrll return this_try;
1267 1.1 skrll if (found_other)
1268 1.1 skrll {
1269 1.1 skrll as_warn (_("Opcode `%s' with these operand types not available in %s mode"),
1270 1.1 skrll found_other->opcode->name,
1271 1.1 skrll (! Hmode && ! Smode ? "H8/300"
1272 1.1 skrll : SXmode ? "H8sx"
1273 1.1 skrll : Smode ? "H8/300S"
1274 1.1 skrll : "H8/300H"));
1275 1.1 skrll }
1276 1.1 skrll else if (found_mismatched)
1277 1.1 skrll {
1278 1.1 skrll as_warn (_("mismatch between opcode size and operand size"));
1279 1.1 skrll return found_mismatched;
1280 1.1 skrll }
1281 1.1 skrll return 0;
1282 1.1 skrll }
1283 1.1 skrll
1284 1.1 skrll static void
1285 1.1 skrll check_operand (struct h8_op *operand, unsigned int width, char *string)
1286 1.1 skrll {
1287 1.1 skrll if (operand->exp.X_add_symbol == 0
1288 1.1 skrll && operand->exp.X_op_symbol == 0)
1289 1.1 skrll {
1290 1.1 skrll /* No symbol involved, let's look at offset, it's dangerous if
1291 1.1 skrll any of the high bits are not 0 or ff's, find out by oring or
1292 1.1 skrll anding with the width and seeing if the answer is 0 or all
1293 1.1 skrll fs. */
1294 1.1 skrll
1295 1.1 skrll if (! constant_fits_width_p (operand, width))
1296 1.1 skrll {
1297 1.1 skrll if (width == 255
1298 1.1 skrll && (operand->exp.X_add_number & 0xff00) == 0xff00)
1299 1.1 skrll {
1300 1.1 skrll /* Just ignore this one - which happens when trying to
1301 1.1 skrll fit a 16 bit address truncated into an 8 bit address
1302 1.1 skrll of something like bset. */
1303 1.1 skrll }
1304 1.1 skrll else if (strcmp (string, "@") == 0
1305 1.1 skrll && width == 0xffff
1306 1.1 skrll && (operand->exp.X_add_number & 0xff8000) == 0xff8000)
1307 1.1 skrll {
1308 1.1 skrll /* Just ignore this one - which happens when trying to
1309 1.1 skrll fit a 24 bit address truncated into a 16 bit address
1310 1.1 skrll of something like mov.w. */
1311 1.1 skrll }
1312 1.1 skrll else
1313 1.1 skrll {
1314 1.1 skrll as_warn (_("operand %s0x%lx out of range."), string,
1315 1.1 skrll (unsigned long) operand->exp.X_add_number);
1316 1.1 skrll }
1317 1.1 skrll }
1318 1.1 skrll }
1319 1.1 skrll }
1320 1.1 skrll
1321 1.1 skrll /* RELAXMODE has one of 3 values:
1322 1.1 skrll
1323 1.1 skrll 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
1324 1.1 skrll
1325 1.1 skrll 1 Output a relaxable 24bit absolute mov.w address relocation
1326 1.1 skrll (may relax into a 16bit absolute address).
1327 1.1 skrll
1328 1.1 skrll 2 Output a relaxable 16/24 absolute mov.b address relocation
1329 1.1 skrll (may relax into an 8bit absolute address). */
1330 1.1 skrll
1331 1.1 skrll static void
1332 1.1.1.2 christos do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, const struct h8_instruction *this_try)
1333 1.1 skrll {
1334 1.1 skrll int idx;
1335 1.1 skrll int size;
1336 1.1 skrll int where;
1337 1.1 skrll char *bytes = frag_now->fr_literal + offset;
1338 1.1 skrll
1339 1.1 skrll char *t = ((operand->mode & MODE) == IMM) ? "#" : "@";
1340 1.1 skrll
1341 1.1 skrll if (operand->exp.X_add_symbol == 0)
1342 1.1 skrll {
1343 1.1 skrll switch (operand->mode & SIZE)
1344 1.1 skrll {
1345 1.1 skrll case L_2:
1346 1.1 skrll check_operand (operand, 0x3, t);
1347 1.1 skrll bytes[0] |= (operand->exp.X_add_number & 3) << (nibble ? 0 : 4);
1348 1.1 skrll break;
1349 1.1 skrll case L_3:
1350 1.1 skrll case L_3NZ:
1351 1.1 skrll check_operand (operand, 0x7, t);
1352 1.1 skrll bytes[0] |= (operand->exp.X_add_number & 7) << (nibble ? 0 : 4);
1353 1.1 skrll break;
1354 1.1 skrll case L_4:
1355 1.1 skrll check_operand (operand, 0xF, t);
1356 1.1 skrll bytes[0] |= (operand->exp.X_add_number & 15) << (nibble ? 0 : 4);
1357 1.1 skrll break;
1358 1.1 skrll case L_5:
1359 1.1 skrll check_operand (operand, 0x1F, t);
1360 1.1 skrll bytes[0] |= operand->exp.X_add_number & 31;
1361 1.1 skrll break;
1362 1.1 skrll case L_8:
1363 1.1 skrll case L_8U:
1364 1.1 skrll check_operand (operand, 0xff, t);
1365 1.1 skrll bytes[0] |= operand->exp.X_add_number;
1366 1.1 skrll break;
1367 1.1 skrll case L_16:
1368 1.1 skrll case L_16U:
1369 1.1 skrll check_operand (operand, 0xffff, t);
1370 1.1 skrll bytes[0] |= operand->exp.X_add_number >> 8;
1371 1.1 skrll bytes[1] |= operand->exp.X_add_number >> 0;
1372 1.1.1.2 christos #ifdef OBJ_ELF
1373 1.1.1.2 christos /* MOVA needs both relocs to relax the second operand properly. */
1374 1.1.1.2 christos if (relaxmode != 0
1375 1.1.1.2 christos && (OP_KIND(this_try->opcode->how) == O_MOVAB
1376 1.1.1.2 christos || OP_KIND(this_try->opcode->how) == O_MOVAW
1377 1.1.1.2 christos || OP_KIND(this_try->opcode->how) == O_MOVAL))
1378 1.1.1.2 christos {
1379 1.1.1.2 christos idx = BFD_RELOC_16;
1380 1.1.1.2 christos fix_new_exp (frag_now, offset, 2, &operand->exp, 0, idx);
1381 1.1.1.2 christos }
1382 1.1.1.2 christos #endif
1383 1.1 skrll break;
1384 1.1 skrll case L_24:
1385 1.1 skrll check_operand (operand, 0xffffff, t);
1386 1.1 skrll bytes[0] |= operand->exp.X_add_number >> 16;
1387 1.1 skrll bytes[1] |= operand->exp.X_add_number >> 8;
1388 1.1 skrll bytes[2] |= operand->exp.X_add_number >> 0;
1389 1.1 skrll break;
1390 1.1 skrll
1391 1.1 skrll case L_32:
1392 1.1 skrll /* This should be done with bfd. */
1393 1.1 skrll bytes[0] |= operand->exp.X_add_number >> 24;
1394 1.1 skrll bytes[1] |= operand->exp.X_add_number >> 16;
1395 1.1 skrll bytes[2] |= operand->exp.X_add_number >> 8;
1396 1.1 skrll bytes[3] |= operand->exp.X_add_number >> 0;
1397 1.1 skrll if (relaxmode != 0)
1398 1.1 skrll {
1399 1.1 skrll idx = (relaxmode == 2) ? R_MOV24B1 : R_MOVL1;
1400 1.1 skrll fix_new_exp (frag_now, offset, 4, &operand->exp, 0, idx);
1401 1.1 skrll }
1402 1.1 skrll break;
1403 1.1 skrll }
1404 1.1 skrll }
1405 1.1 skrll else
1406 1.1 skrll {
1407 1.1 skrll switch (operand->mode & SIZE)
1408 1.1 skrll {
1409 1.1 skrll case L_24:
1410 1.1 skrll case L_32:
1411 1.1 skrll size = 4;
1412 1.1 skrll where = (operand->mode & SIZE) == L_24 ? -1 : 0;
1413 1.1 skrll if (relaxmode == 2)
1414 1.1 skrll idx = R_MOV24B1;
1415 1.1 skrll else if (relaxmode == 1)
1416 1.1 skrll idx = R_MOVL1;
1417 1.1 skrll else
1418 1.1 skrll idx = R_RELLONG;
1419 1.1 skrll break;
1420 1.1 skrll default:
1421 1.1 skrll as_bad (_("Can't work out size of operand.\n"));
1422 1.1 skrll case L_16:
1423 1.1 skrll case L_16U:
1424 1.1 skrll size = 2;
1425 1.1 skrll where = 0;
1426 1.1 skrll if (relaxmode == 2)
1427 1.1 skrll idx = R_MOV16B1;
1428 1.1 skrll else
1429 1.1 skrll idx = R_RELWORD;
1430 1.1 skrll operand->exp.X_add_number =
1431 1.1 skrll ((operand->exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1432 1.1 skrll operand->exp.X_add_number |= (bytes[0] << 8) | bytes[1];
1433 1.1 skrll break;
1434 1.1 skrll case L_8:
1435 1.1 skrll size = 1;
1436 1.1 skrll where = 0;
1437 1.1 skrll idx = R_RELBYTE;
1438 1.1 skrll operand->exp.X_add_number =
1439 1.1 skrll ((operand->exp.X_add_number & 0xff) ^ 0x80) - 0x80;
1440 1.1 skrll operand->exp.X_add_number |= bytes[0];
1441 1.1 skrll }
1442 1.1 skrll
1443 1.1 skrll fix_new_exp (frag_now,
1444 1.1 skrll offset + where,
1445 1.1 skrll size,
1446 1.1 skrll &operand->exp,
1447 1.1 skrll 0,
1448 1.1 skrll idx);
1449 1.1 skrll }
1450 1.1 skrll }
1451 1.1 skrll
1452 1.1 skrll /* Now we know what sort of opcodes it is, let's build the bytes. */
1453 1.1 skrll
1454 1.1 skrll static void
1455 1.1 skrll build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
1456 1.1 skrll {
1457 1.1 skrll int i;
1458 1.1 skrll char *output = frag_more (this_try->length);
1459 1.1 skrll const op_type *nibble_ptr = this_try->opcode->data.nib;
1460 1.1 skrll op_type c;
1461 1.1 skrll unsigned int nibble_count = 0;
1462 1.1 skrll int op_at[3];
1463 1.1 skrll int nib = 0;
1464 1.1 skrll int movb = 0;
1465 1.1 skrll char asnibbles[100];
1466 1.1 skrll char *p = asnibbles;
1467 1.1 skrll int high, low;
1468 1.1 skrll
1469 1.1 skrll if (!Hmode && this_try->opcode->available != AV_H8)
1470 1.1 skrll as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1471 1.1 skrll this_try->opcode->name);
1472 1.1 skrll else if (!Smode
1473 1.1 skrll && this_try->opcode->available != AV_H8
1474 1.1 skrll && this_try->opcode->available != AV_H8H)
1475 1.1 skrll as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"),
1476 1.1 skrll this_try->opcode->name);
1477 1.1 skrll else if (!SXmode
1478 1.1 skrll && this_try->opcode->available != AV_H8
1479 1.1 skrll && this_try->opcode->available != AV_H8H
1480 1.1 skrll && this_try->opcode->available != AV_H8S)
1481 1.1 skrll as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"),
1482 1.1 skrll this_try->opcode->name);
1483 1.1 skrll
1484 1.1 skrll while (*nibble_ptr != (op_type) E)
1485 1.1 skrll {
1486 1.1 skrll int d;
1487 1.1 skrll
1488 1.1 skrll nib = 0;
1489 1.1 skrll c = *nibble_ptr++;
1490 1.1 skrll
1491 1.1 skrll d = (c & OP3) == OP3 ? 2 : (c & DST) == DST ? 1 : 0;
1492 1.1 skrll
1493 1.1 skrll if (c < 16)
1494 1.1 skrll nib = c;
1495 1.1 skrll else
1496 1.1 skrll {
1497 1.1 skrll int c2 = c & MODE;
1498 1.1 skrll
1499 1.1 skrll if (c2 == REG || c2 == LOWREG
1500 1.1 skrll || c2 == IND || c2 == PREINC || c2 == PREDEC
1501 1.1 skrll || c2 == POSTINC || c2 == POSTDEC)
1502 1.1 skrll {
1503 1.1 skrll nib = operand[d].reg;
1504 1.1 skrll if (c2 == LOWREG)
1505 1.1 skrll nib &= 7;
1506 1.1 skrll }
1507 1.1 skrll
1508 1.1 skrll else if (c & CTRL) /* Control reg operand. */
1509 1.1 skrll nib = operand[d].reg;
1510 1.1 skrll
1511 1.1 skrll else if ((c & DISPREG) == (DISPREG))
1512 1.1 skrll {
1513 1.1 skrll nib = operand[d].reg;
1514 1.1 skrll }
1515 1.1 skrll else if (c2 == ABS)
1516 1.1 skrll {
1517 1.1 skrll operand[d].mode = c;
1518 1.1 skrll op_at[d] = nibble_count;
1519 1.1 skrll nib = 0;
1520 1.1 skrll }
1521 1.1 skrll else if (c2 == IMM || c2 == PCREL || c2 == ABS
1522 1.1 skrll || (c & ABSJMP) || c2 == DISP)
1523 1.1 skrll {
1524 1.1 skrll operand[d].mode = c;
1525 1.1 skrll op_at[d] = nibble_count;
1526 1.1 skrll nib = 0;
1527 1.1 skrll }
1528 1.1 skrll else if ((c & IGNORE) || (c & DATA))
1529 1.1 skrll nib = 0;
1530 1.1 skrll
1531 1.1 skrll else if (c2 == DBIT)
1532 1.1 skrll {
1533 1.1 skrll switch (operand[0].exp.X_add_number)
1534 1.1 skrll {
1535 1.1 skrll case 1:
1536 1.1 skrll nib = c;
1537 1.1 skrll break;
1538 1.1 skrll case 2:
1539 1.1 skrll nib = 0x8 | c;
1540 1.1 skrll break;
1541 1.1 skrll default:
1542 1.1 skrll as_bad (_("Need #1 or #2 here"));
1543 1.1 skrll }
1544 1.1 skrll }
1545 1.1 skrll else if (c2 == KBIT)
1546 1.1 skrll {
1547 1.1 skrll switch (operand[0].exp.X_add_number)
1548 1.1 skrll {
1549 1.1 skrll case 1:
1550 1.1 skrll nib = 0;
1551 1.1 skrll break;
1552 1.1 skrll case 2:
1553 1.1 skrll nib = 8;
1554 1.1 skrll break;
1555 1.1 skrll case 4:
1556 1.1 skrll if (!Hmode)
1557 1.1 skrll as_warn (_("#4 not valid on H8/300."));
1558 1.1 skrll nib = 9;
1559 1.1 skrll break;
1560 1.1 skrll
1561 1.1 skrll default:
1562 1.1 skrll as_bad (_("Need #1 or #2 here"));
1563 1.1 skrll break;
1564 1.1 skrll }
1565 1.1 skrll /* Stop it making a fix. */
1566 1.1 skrll operand[0].mode = 0;
1567 1.1 skrll }
1568 1.1 skrll
1569 1.1 skrll if (c & MEMRELAX)
1570 1.1 skrll operand[d].mode |= MEMRELAX;
1571 1.1 skrll
1572 1.1 skrll if (c & B31)
1573 1.1 skrll nib |= 0x8;
1574 1.1 skrll
1575 1.1 skrll if (c & B21)
1576 1.1 skrll nib |= 0x4;
1577 1.1 skrll
1578 1.1 skrll if (c & B11)
1579 1.1 skrll nib |= 0x2;
1580 1.1 skrll
1581 1.1 skrll if (c & B01)
1582 1.1 skrll nib |= 0x1;
1583 1.1 skrll
1584 1.1 skrll if (c2 == MACREG)
1585 1.1 skrll {
1586 1.1 skrll if (operand[0].mode == MACREG)
1587 1.1 skrll /* stmac has mac[hl] as the first operand. */
1588 1.1 skrll nib = 2 + operand[0].reg;
1589 1.1 skrll else
1590 1.1 skrll /* ldmac has mac[hl] as the second operand. */
1591 1.1 skrll nib = 2 + operand[1].reg;
1592 1.1 skrll }
1593 1.1 skrll }
1594 1.1 skrll nibble_count++;
1595 1.1 skrll
1596 1.1 skrll *p++ = nib;
1597 1.1 skrll }
1598 1.1 skrll
1599 1.1 skrll /* Disgusting. Why, oh why didn't someone ask us for advice
1600 1.1 skrll on the assembler format. */
1601 1.1 skrll if (OP_KIND (this_try->opcode->how) == O_LDM)
1602 1.1 skrll {
1603 1.1 skrll high = (operand[1].reg >> 8) & 0xf;
1604 1.1 skrll low = (operand[1].reg) & 0xf;
1605 1.1 skrll asnibbles[2] = high - low;
1606 1.1 skrll asnibbles[7] = high;
1607 1.1 skrll }
1608 1.1 skrll else if (OP_KIND (this_try->opcode->how) == O_STM)
1609 1.1 skrll {
1610 1.1 skrll high = (operand[0].reg >> 8) & 0xf;
1611 1.1 skrll low = (operand[0].reg) & 0xf;
1612 1.1 skrll asnibbles[2] = high - low;
1613 1.1 skrll asnibbles[7] = low;
1614 1.1 skrll }
1615 1.1 skrll
1616 1.1 skrll for (i = 0; i < this_try->length; i++)
1617 1.1 skrll output[i] = (asnibbles[i * 2] << 4) | asnibbles[i * 2 + 1];
1618 1.1 skrll
1619 1.1 skrll /* Note if this is a movb or a bit manipulation instruction
1620 1.1 skrll there is a special relaxation which only applies. */
1621 1.1 skrll if ( this_try->opcode->how == O (O_MOV, SB)
1622 1.1 skrll || this_try->opcode->how == O (O_BCLR, SB)
1623 1.1 skrll || this_try->opcode->how == O (O_BAND, SB)
1624 1.1 skrll || this_try->opcode->how == O (O_BIAND, SB)
1625 1.1 skrll || this_try->opcode->how == O (O_BILD, SB)
1626 1.1 skrll || this_try->opcode->how == O (O_BIOR, SB)
1627 1.1 skrll || this_try->opcode->how == O (O_BIST, SB)
1628 1.1 skrll || this_try->opcode->how == O (O_BIXOR, SB)
1629 1.1 skrll || this_try->opcode->how == O (O_BLD, SB)
1630 1.1 skrll || this_try->opcode->how == O (O_BNOT, SB)
1631 1.1 skrll || this_try->opcode->how == O (O_BOR, SB)
1632 1.1 skrll || this_try->opcode->how == O (O_BSET, SB)
1633 1.1 skrll || this_try->opcode->how == O (O_BST, SB)
1634 1.1 skrll || this_try->opcode->how == O (O_BTST, SB)
1635 1.1 skrll || this_try->opcode->how == O (O_BXOR, SB))
1636 1.1 skrll movb = 1;
1637 1.1 skrll
1638 1.1 skrll /* Output any fixes. */
1639 1.1 skrll for (i = 0; i < this_try->noperands; i++)
1640 1.1 skrll {
1641 1.1 skrll int x = operand[i].mode;
1642 1.1 skrll int x_mode = x & MODE;
1643 1.1 skrll
1644 1.1 skrll if (x_mode == IMM || x_mode == DISP)
1645 1.1 skrll do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2,
1646 1.1.1.2 christos op_at[i] & 1, operand + i, (x & MEMRELAX) != 0,
1647 1.1.1.2 christos this_try);
1648 1.1 skrll
1649 1.1 skrll else if (x_mode == ABS)
1650 1.1 skrll do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2,
1651 1.1 skrll op_at[i] & 1, operand + i,
1652 1.1.1.2 christos (x & MEMRELAX) ? movb + 1 : 0,
1653 1.1.1.2 christos this_try);
1654 1.1 skrll
1655 1.1 skrll else if (x_mode == PCREL)
1656 1.1 skrll {
1657 1.1 skrll int size16 = (x & SIZE) == L_16;
1658 1.1 skrll int size = size16 ? 2 : 1;
1659 1.1 skrll int type = size16 ? R_PCRWORD : R_PCRBYTE;
1660 1.1 skrll fixS *fixP;
1661 1.1 skrll
1662 1.1 skrll check_operand (operand + i, size16 ? 0x7fff : 0x7f, "@");
1663 1.1 skrll
1664 1.1 skrll if (operand[i].exp.X_add_number & 1)
1665 1.1 skrll as_warn (_("branch operand has odd offset (%lx)\n"),
1666 1.1 skrll (unsigned long) operand->exp.X_add_number);
1667 1.1 skrll #ifndef OBJ_ELF
1668 1.1 skrll /* The COFF port has always been off by one, changing it
1669 1.1 skrll now would be an incompatible change, so we leave it as-is.
1670 1.1 skrll
1671 1.1 skrll We don't want to do this for ELF as we want to be
1672 1.1 skrll compatible with the proposed ELF format from Hitachi. */
1673 1.1 skrll operand[i].exp.X_add_number -= 1;
1674 1.1 skrll #endif
1675 1.1 skrll if (size16)
1676 1.1 skrll {
1677 1.1 skrll operand[i].exp.X_add_number =
1678 1.1 skrll ((operand[i].exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1679 1.1 skrll }
1680 1.1 skrll else
1681 1.1 skrll {
1682 1.1 skrll operand[i].exp.X_add_number =
1683 1.1 skrll ((operand[i].exp.X_add_number & 0xff) ^ 0x80) - 0x80;
1684 1.1 skrll }
1685 1.1 skrll
1686 1.1 skrll /* For BRA/S. */
1687 1.1 skrll if (! size16)
1688 1.1 skrll operand[i].exp.X_add_number |= output[op_at[i] / 2];
1689 1.1 skrll
1690 1.1 skrll fixP = fix_new_exp (frag_now,
1691 1.1 skrll output - frag_now->fr_literal + op_at[i] / 2,
1692 1.1 skrll size,
1693 1.1 skrll &operand[i].exp,
1694 1.1 skrll 1,
1695 1.1 skrll type);
1696 1.1 skrll fixP->fx_signed = 1;
1697 1.1 skrll }
1698 1.1 skrll else if (x_mode == MEMIND)
1699 1.1 skrll {
1700 1.1 skrll check_operand (operand + i, 0xff, "@@");
1701 1.1 skrll fix_new_exp (frag_now,
1702 1.1 skrll output - frag_now->fr_literal + 1,
1703 1.1 skrll 1,
1704 1.1 skrll &operand[i].exp,
1705 1.1 skrll 0,
1706 1.1 skrll R_MEM_INDIRECT);
1707 1.1 skrll }
1708 1.1 skrll else if (x_mode == VECIND)
1709 1.1 skrll {
1710 1.1 skrll check_operand (operand + i, 0x7f, "@@");
1711 1.1 skrll /* FIXME: approximating the effect of "B31" here...
1712 1.1 skrll This is very hackish, and ought to be done a better way. */
1713 1.1 skrll operand[i].exp.X_add_number |= 0x80;
1714 1.1 skrll fix_new_exp (frag_now,
1715 1.1 skrll output - frag_now->fr_literal + 1,
1716 1.1 skrll 1,
1717 1.1 skrll &operand[i].exp,
1718 1.1 skrll 0,
1719 1.1 skrll R_MEM_INDIRECT);
1720 1.1 skrll }
1721 1.1 skrll else if (x & ABSJMP)
1722 1.1 skrll {
1723 1.1 skrll int where = 0;
1724 1.1 skrll bfd_reloc_code_real_type reloc_type = R_JMPL1;
1725 1.1 skrll
1726 1.1 skrll #ifdef OBJ_ELF
1727 1.1 skrll /* To be compatible with the proposed H8 ELF format, we
1728 1.1 skrll want the relocation's offset to point to the first byte
1729 1.1 skrll that will be modified, not to the start of the instruction. */
1730 1.1 skrll
1731 1.1 skrll if ((operand->mode & SIZE) == L_32)
1732 1.1 skrll {
1733 1.1 skrll where = 2;
1734 1.1 skrll reloc_type = R_RELLONG;
1735 1.1 skrll }
1736 1.1 skrll else
1737 1.1 skrll where = 1;
1738 1.1 skrll #endif
1739 1.1 skrll
1740 1.1 skrll /* This jmp may be a jump or a branch. */
1741 1.1 skrll
1742 1.1 skrll check_operand (operand + i,
1743 1.1 skrll SXmode ? 0xffffffff : Hmode ? 0xffffff : 0xffff,
1744 1.1 skrll "@");
1745 1.1 skrll
1746 1.1 skrll if (operand[i].exp.X_add_number & 1)
1747 1.1 skrll as_warn (_("branch operand has odd offset (%lx)\n"),
1748 1.1 skrll (unsigned long) operand->exp.X_add_number);
1749 1.1 skrll
1750 1.1 skrll if (!Hmode)
1751 1.1 skrll operand[i].exp.X_add_number =
1752 1.1 skrll ((operand[i].exp.X_add_number & 0xffff) ^ 0x8000) - 0x8000;
1753 1.1 skrll fix_new_exp (frag_now,
1754 1.1 skrll output - frag_now->fr_literal + where,
1755 1.1 skrll 4,
1756 1.1 skrll &operand[i].exp,
1757 1.1 skrll 0,
1758 1.1 skrll reloc_type);
1759 1.1 skrll }
1760 1.1 skrll }
1761 1.1 skrll }
1762 1.1 skrll
1763 1.1 skrll /* Try to give an intelligent error message for common and simple to
1764 1.1 skrll detect errors. */
1765 1.1 skrll
1766 1.1 skrll static void
1767 1.1 skrll clever_message (const struct h8_instruction *instruction,
1768 1.1 skrll struct h8_op *operand)
1769 1.1 skrll {
1770 1.1 skrll /* Find out if there was more than one possible opcode. */
1771 1.1 skrll
1772 1.1 skrll if ((instruction + 1)->idx != instruction->idx)
1773 1.1 skrll {
1774 1.1 skrll int argn;
1775 1.1 skrll
1776 1.1 skrll /* Only one opcode of this flavour, try to guess which operand
1777 1.1 skrll didn't match. */
1778 1.1 skrll for (argn = 0; argn < instruction->noperands; argn++)
1779 1.1 skrll {
1780 1.1 skrll switch (instruction->opcode->args.nib[argn])
1781 1.1 skrll {
1782 1.1 skrll case RD16:
1783 1.1 skrll if (operand[argn].mode != RD16)
1784 1.1 skrll {
1785 1.1 skrll as_bad (_("destination operand must be 16 bit register"));
1786 1.1 skrll return;
1787 1.1 skrll
1788 1.1 skrll }
1789 1.1 skrll break;
1790 1.1 skrll
1791 1.1 skrll case RS8:
1792 1.1 skrll if (operand[argn].mode != RS8)
1793 1.1 skrll {
1794 1.1 skrll as_bad (_("source operand must be 8 bit register"));
1795 1.1 skrll return;
1796 1.1 skrll }
1797 1.1 skrll break;
1798 1.1 skrll
1799 1.1 skrll case ABS16DST:
1800 1.1 skrll if (operand[argn].mode != ABS16DST)
1801 1.1 skrll {
1802 1.1 skrll as_bad (_("destination operand must be 16bit absolute address"));
1803 1.1 skrll return;
1804 1.1 skrll }
1805 1.1 skrll break;
1806 1.1 skrll case RD8:
1807 1.1 skrll if (operand[argn].mode != RD8)
1808 1.1 skrll {
1809 1.1 skrll as_bad (_("destination operand must be 8 bit register"));
1810 1.1 skrll return;
1811 1.1 skrll }
1812 1.1 skrll break;
1813 1.1 skrll
1814 1.1 skrll case ABS16SRC:
1815 1.1 skrll if (operand[argn].mode != ABS16SRC)
1816 1.1 skrll {
1817 1.1 skrll as_bad (_("source operand must be 16bit absolute address"));
1818 1.1 skrll return;
1819 1.1 skrll }
1820 1.1 skrll break;
1821 1.1 skrll
1822 1.1 skrll }
1823 1.1 skrll }
1824 1.1 skrll }
1825 1.1 skrll as_bad (_("invalid operands"));
1826 1.1 skrll }
1827 1.1 skrll
1828 1.1 skrll
1829 1.1 skrll /* If OPERAND is part of an address, adjust its size and value given
1830 1.1 skrll that it addresses SIZE bytes.
1831 1.1 skrll
1832 1.1 skrll This function decides how big non-immediate constants are when no
1833 1.1 skrll size was explicitly given. It also scales down the assembly-level
1834 1.1 skrll displacement in an @(d:2,ERn) operand. */
1835 1.1 skrll
1836 1.1 skrll static void
1837 1.1 skrll fix_operand_size (struct h8_op *operand, int size)
1838 1.1 skrll {
1839 1.1 skrll if (SXmode && (operand->mode & MODE) == DISP)
1840 1.1 skrll {
1841 1.1 skrll /* If the user didn't specify an operand width, see if we
1842 1.1 skrll can use @(d:2,ERn). */
1843 1.1 skrll if ((operand->mode & SIZE) == 0
1844 1.1 skrll && operand->exp.X_add_symbol == 0
1845 1.1 skrll && operand->exp.X_op_symbol == 0
1846 1.1 skrll && (operand->exp.X_add_number == size
1847 1.1 skrll || operand->exp.X_add_number == size * 2
1848 1.1 skrll || operand->exp.X_add_number == size * 3))
1849 1.1 skrll operand->mode |= L_2;
1850 1.1 skrll
1851 1.1 skrll /* Scale down the displacement in an @(d:2,ERn) operand.
1852 1.1 skrll X_add_number then contains the desired field value. */
1853 1.1 skrll if ((operand->mode & SIZE) == L_2)
1854 1.1 skrll {
1855 1.1 skrll if (operand->exp.X_add_number % size != 0)
1856 1.1 skrll as_warn (_("operand/size mis-match"));
1857 1.1 skrll operand->exp.X_add_number /= size;
1858 1.1 skrll }
1859 1.1 skrll }
1860 1.1 skrll
1861 1.1 skrll if ((operand->mode & SIZE) == 0)
1862 1.1 skrll switch (operand->mode & MODE)
1863 1.1 skrll {
1864 1.1 skrll case DISP:
1865 1.1 skrll case INDEXB:
1866 1.1 skrll case INDEXW:
1867 1.1 skrll case INDEXL:
1868 1.1 skrll case ABS:
1869 1.1 skrll /* Pick a 24-bit address unless we know that a 16-bit address
1870 1.1 skrll is safe. get_specific() will relax L_24 into L_32 where
1871 1.1 skrll necessary. */
1872 1.1 skrll if (Hmode
1873 1.1 skrll && !Nmode
1874 1.1.1.3 christos && ((((addressT) operand->exp.X_add_number + 0x8000)
1875 1.1.1.3 christos & 0xffffffff) > 0xffff
1876 1.1 skrll || operand->exp.X_add_symbol != 0
1877 1.1 skrll || operand->exp.X_op_symbol != 0))
1878 1.1 skrll operand->mode |= L_24;
1879 1.1 skrll else
1880 1.1 skrll operand->mode |= L_16;
1881 1.1 skrll break;
1882 1.1 skrll
1883 1.1 skrll case PCREL:
1884 1.1.1.3 christos if ((((addressT) operand->exp.X_add_number + 0x80)
1885 1.1.1.3 christos & 0xffffffff) <= 0xff)
1886 1.1 skrll {
1887 1.1 skrll if (operand->exp.X_add_symbol != NULL)
1888 1.1 skrll operand->mode |= bsize;
1889 1.1 skrll else
1890 1.1 skrll operand->mode |= L_8;
1891 1.1 skrll }
1892 1.1 skrll else
1893 1.1 skrll operand->mode |= L_16;
1894 1.1 skrll break;
1895 1.1 skrll }
1896 1.1 skrll }
1897 1.1 skrll
1898 1.1 skrll
1899 1.1 skrll /* This is the guts of the machine-dependent assembler. STR points to
1900 1.1 skrll a machine dependent instruction. This function is supposed to emit
1901 1.1 skrll the frags/bytes it assembles. */
1902 1.1 skrll
1903 1.1 skrll void
1904 1.1 skrll md_assemble (char *str)
1905 1.1 skrll {
1906 1.1 skrll char *op_start;
1907 1.1 skrll char *op_end;
1908 1.1 skrll struct h8_op operand[3];
1909 1.1 skrll const struct h8_instruction *instruction;
1910 1.1 skrll const struct h8_instruction *prev_instruction;
1911 1.1 skrll
1912 1.1 skrll char *dot = 0;
1913 1.1 skrll char *slash = 0;
1914 1.1 skrll char c;
1915 1.1 skrll int size, i;
1916 1.1 skrll
1917 1.1 skrll /* Drop leading whitespace. */
1918 1.1 skrll while (*str == ' ')
1919 1.1 skrll str++;
1920 1.1 skrll
1921 1.1 skrll /* Find the op code end. */
1922 1.1 skrll for (op_start = op_end = str;
1923 1.1 skrll *op_end != 0 && *op_end != ' ';
1924 1.1 skrll op_end++)
1925 1.1 skrll {
1926 1.1 skrll if (*op_end == '.')
1927 1.1 skrll {
1928 1.1 skrll dot = op_end + 1;
1929 1.1 skrll *op_end = 0;
1930 1.1 skrll op_end += 2;
1931 1.1 skrll break;
1932 1.1 skrll }
1933 1.1 skrll else if (*op_end == '/' && ! slash)
1934 1.1 skrll slash = op_end;
1935 1.1 skrll }
1936 1.1 skrll
1937 1.1 skrll if (op_end == op_start)
1938 1.1 skrll {
1939 1.1 skrll as_bad (_("can't find opcode "));
1940 1.1 skrll }
1941 1.1 skrll c = *op_end;
1942 1.1 skrll
1943 1.1 skrll *op_end = 0;
1944 1.1 skrll
1945 1.1 skrll /* The assembler stops scanning the opcode at slashes, so it fails
1946 1.1 skrll to make characters following them lower case. Fix them. */
1947 1.1 skrll if (slash)
1948 1.1 skrll while (*++slash)
1949 1.1 skrll *slash = TOLOWER (*slash);
1950 1.1 skrll
1951 1.1 skrll instruction = (const struct h8_instruction *)
1952 1.1 skrll hash_find (opcode_hash_control, op_start);
1953 1.1 skrll
1954 1.1 skrll if (instruction == NULL)
1955 1.1 skrll {
1956 1.1 skrll as_bad (_("unknown opcode"));
1957 1.1 skrll return;
1958 1.1 skrll }
1959 1.1 skrll
1960 1.1 skrll /* We used to set input_line_pointer to the result of get_operands,
1961 1.1 skrll but that is wrong. Our caller assumes we don't change it. */
1962 1.1 skrll
1963 1.1 skrll operand[0].mode = 0;
1964 1.1 skrll operand[1].mode = 0;
1965 1.1 skrll operand[2].mode = 0;
1966 1.1 skrll
1967 1.1 skrll if (OP_KIND (instruction->opcode->how) == O_MOVAB
1968 1.1 skrll || OP_KIND (instruction->opcode->how) == O_MOVAW
1969 1.1 skrll || OP_KIND (instruction->opcode->how) == O_MOVAL)
1970 1.1 skrll get_mova_operands (op_end, operand);
1971 1.1 skrll else if (OP_KIND (instruction->opcode->how) == O_RTEL
1972 1.1 skrll || OP_KIND (instruction->opcode->how) == O_RTSL)
1973 1.1 skrll get_rtsl_operands (op_end, operand);
1974 1.1 skrll else
1975 1.1 skrll get_operands (instruction->noperands, op_end, operand);
1976 1.1 skrll
1977 1.1 skrll *op_end = c;
1978 1.1 skrll prev_instruction = instruction;
1979 1.1 skrll
1980 1.1 skrll /* Now we have operands from instruction.
1981 1.1 skrll Let's check them out for ldm and stm. */
1982 1.1 skrll if (OP_KIND (instruction->opcode->how) == O_LDM)
1983 1.1 skrll {
1984 1.1 skrll /* The first operand must be @er7+, and the
1985 1.1 skrll second operand must be a register pair. */
1986 1.1 skrll if ((operand[0].mode != RSINC)
1987 1.1 skrll || (operand[0].reg != 7)
1988 1.1 skrll || ((operand[1].reg & 0x80000000) == 0))
1989 1.1 skrll as_bad (_("invalid operand in ldm"));
1990 1.1 skrll }
1991 1.1 skrll else if (OP_KIND (instruction->opcode->how) == O_STM)
1992 1.1 skrll {
1993 1.1 skrll /* The first operand must be a register pair,
1994 1.1 skrll and the second operand must be @-er7. */
1995 1.1 skrll if (((operand[0].reg & 0x80000000) == 0)
1996 1.1 skrll || (operand[1].mode != RDDEC)
1997 1.1 skrll || (operand[1].reg != 7))
1998 1.1 skrll as_bad (_("invalid operand in stm"));
1999 1.1 skrll }
2000 1.1 skrll
2001 1.1 skrll size = SN;
2002 1.1 skrll if (dot)
2003 1.1 skrll {
2004 1.1 skrll switch (TOLOWER (*dot))
2005 1.1 skrll {
2006 1.1 skrll case 'b':
2007 1.1 skrll size = SB;
2008 1.1 skrll break;
2009 1.1 skrll
2010 1.1 skrll case 'w':
2011 1.1 skrll size = SW;
2012 1.1 skrll break;
2013 1.1 skrll
2014 1.1 skrll case 'l':
2015 1.1 skrll size = SL;
2016 1.1 skrll break;
2017 1.1 skrll }
2018 1.1 skrll }
2019 1.1 skrll if (OP_KIND (instruction->opcode->how) == O_MOVAB ||
2020 1.1 skrll OP_KIND (instruction->opcode->how) == O_MOVAW ||
2021 1.1 skrll OP_KIND (instruction->opcode->how) == O_MOVAL)
2022 1.1 skrll {
2023 1.1 skrll switch (operand[0].mode & MODE)
2024 1.1 skrll {
2025 1.1 skrll case INDEXB:
2026 1.1 skrll default:
2027 1.1 skrll fix_operand_size (&operand[1], 1);
2028 1.1 skrll break;
2029 1.1 skrll case INDEXW:
2030 1.1 skrll fix_operand_size (&operand[1], 2);
2031 1.1 skrll break;
2032 1.1 skrll case INDEXL:
2033 1.1 skrll fix_operand_size (&operand[1], 4);
2034 1.1 skrll break;
2035 1.1 skrll }
2036 1.1 skrll }
2037 1.1 skrll else
2038 1.1 skrll {
2039 1.1 skrll for (i = 0; i < 3 && operand[i].mode != 0; i++)
2040 1.1 skrll switch (size)
2041 1.1 skrll {
2042 1.1 skrll case SN:
2043 1.1 skrll case SB:
2044 1.1 skrll default:
2045 1.1 skrll fix_operand_size (&operand[i], 1);
2046 1.1 skrll break;
2047 1.1 skrll case SW:
2048 1.1 skrll fix_operand_size (&operand[i], 2);
2049 1.1 skrll break;
2050 1.1 skrll case SL:
2051 1.1 skrll fix_operand_size (&operand[i], 4);
2052 1.1 skrll break;
2053 1.1 skrll }
2054 1.1 skrll }
2055 1.1 skrll
2056 1.1 skrll instruction = get_specific (instruction, operand, size);
2057 1.1 skrll
2058 1.1 skrll if (instruction == 0)
2059 1.1 skrll {
2060 1.1 skrll /* Couldn't find an opcode which matched the operands. */
2061 1.1 skrll char *where = frag_more (2);
2062 1.1 skrll
2063 1.1 skrll where[0] = 0x0;
2064 1.1 skrll where[1] = 0x0;
2065 1.1 skrll clever_message (prev_instruction, operand);
2066 1.1 skrll
2067 1.1 skrll return;
2068 1.1 skrll }
2069 1.1 skrll
2070 1.1 skrll build_bytes (instruction, operand);
2071 1.1 skrll
2072 1.1 skrll dwarf2_emit_insn (instruction->length);
2073 1.1 skrll }
2074 1.1 skrll
2075 1.1 skrll symbolS *
2076 1.1 skrll md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
2077 1.1 skrll {
2078 1.1 skrll return 0;
2079 1.1 skrll }
2080 1.1 skrll
2081 1.1 skrll /* Various routines to kill one day. */
2082 1.1 skrll
2083 1.1 skrll char *
2084 1.1 skrll md_atof (int type, char *litP, int *sizeP)
2085 1.1 skrll {
2086 1.1 skrll return ieee_md_atof (type, litP, sizeP, TRUE);
2087 1.1 skrll }
2088 1.1 skrll
2089 1.1 skrll #define OPTION_H_TICK_HEX (OPTION_MD_BASE)
2091 1.1 skrll
2092 1.1 skrll const char *md_shortopts = "";
2093 1.1 skrll struct option md_longopts[] = {
2094 1.1 skrll { "h-tick-hex", no_argument, NULL, OPTION_H_TICK_HEX },
2095 1.1 skrll {NULL, no_argument, NULL, 0}
2096 1.1 skrll };
2097 1.1 skrll
2098 1.1 skrll size_t md_longopts_size = sizeof (md_longopts);
2099 1.1 skrll
2100 1.1 skrll int
2101 1.1 skrll md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
2102 1.1 skrll {
2103 1.1 skrll switch (c)
2104 1.1 skrll {
2105 1.1 skrll case OPTION_H_TICK_HEX:
2106 1.1 skrll enable_h_tick_hex = 1;
2107 1.1 skrll break;
2108 1.1 skrll
2109 1.1 skrll default:
2110 1.1 skrll return 0;
2111 1.1 skrll }
2112 1.1 skrll return 1;
2113 1.1 skrll }
2114 1.1 skrll
2115 1.1 skrll void
2116 1.1 skrll md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
2117 1.1 skrll {
2118 1.1 skrll }
2119 1.1 skrll
2120 1.1 skrll void tc_aout_fix_to_chars (void);
2122 1.1 skrll
2123 1.1 skrll void
2124 1.1 skrll tc_aout_fix_to_chars (void)
2125 1.1 skrll {
2126 1.1 skrll printf (_("call to tc_aout_fix_to_chars \n"));
2127 1.1 skrll abort ();
2128 1.1 skrll }
2129 1.1 skrll
2130 1.1 skrll void
2131 1.1 skrll md_convert_frag (bfd *headers ATTRIBUTE_UNUSED,
2132 1.1 skrll segT seg ATTRIBUTE_UNUSED,
2133 1.1 skrll fragS *fragP ATTRIBUTE_UNUSED)
2134 1.1 skrll {
2135 1.1 skrll printf (_("call to md_convert_frag \n"));
2136 1.1 skrll abort ();
2137 1.1 skrll }
2138 1.1 skrll
2139 1.1 skrll valueT
2140 1.1 skrll md_section_align (segT segment, valueT size)
2141 1.1 skrll {
2142 1.1 skrll int align = bfd_get_section_alignment (stdoutput, segment);
2143 1.1 skrll return ((size + (1 << align) - 1) & (-1 << align));
2144 1.1 skrll }
2145 1.1 skrll
2146 1.1 skrll void
2147 1.1 skrll md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
2148 1.1 skrll {
2149 1.1 skrll char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2150 1.1 skrll long val = *valP;
2151 1.1 skrll
2152 1.1 skrll switch (fixP->fx_size)
2153 1.1 skrll {
2154 1.1 skrll case 1:
2155 1.1 skrll *buf++ = val;
2156 1.1 skrll break;
2157 1.1 skrll case 2:
2158 1.1 skrll *buf++ = (val >> 8);
2159 1.1 skrll *buf++ = val;
2160 1.1 skrll break;
2161 1.1 skrll case 4:
2162 1.1 skrll *buf++ = (val >> 24);
2163 1.1 skrll *buf++ = (val >> 16);
2164 1.1 skrll *buf++ = (val >> 8);
2165 1.1 skrll *buf++ = val;
2166 1.1 skrll break;
2167 1.1 skrll case 8:
2168 1.1 skrll /* This can arise when the .quad or .8byte pseudo-ops are used.
2169 1.1 skrll Returning here (without setting fx_done) will cause the code
2170 1.1 skrll to attempt to generate a reloc which will then fail with the
2171 1.1 skrll slightly more helpful error message: "Cannot represent
2172 1.1 skrll relocation type BFD_RELOC_64". */
2173 1.1 skrll return;
2174 1.1 skrll default:
2175 1.1 skrll abort ();
2176 1.1 skrll }
2177 1.1 skrll
2178 1.1 skrll if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
2179 1.1 skrll fixP->fx_done = 1;
2180 1.1 skrll }
2181 1.1 skrll
2182 1.1 skrll int
2183 1.1 skrll md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
2184 1.1 skrll segT segment_type ATTRIBUTE_UNUSED)
2185 1.1 skrll {
2186 1.1 skrll printf (_("call to md_estimate_size_before_relax \n"));
2187 1.1 skrll abort ();
2188 1.1 skrll }
2189 1.1 skrll
2190 1.1 skrll /* Put number into target byte order. */
2191 1.1 skrll void
2192 1.1 skrll md_number_to_chars (char *ptr, valueT use, int nbytes)
2193 1.1 skrll {
2194 1.1 skrll number_to_chars_bigendian (ptr, use, nbytes);
2195 1.1 skrll }
2196 1.1.1.2 christos
2197 1.1 skrll long
2198 1.1.1.2 christos md_pcrel_from (fixS *fixp)
2199 1.1.1.2 christos {
2200 1.1.1.2 christos as_bad_where (fixp->fx_file, fixp->fx_line,
2201 1.1 skrll _("Unexpected reference to a symbol in a non-code section"));
2202 1.1 skrll return 0;
2203 1.1 skrll }
2204 1.1 skrll
2205 1.1 skrll arelent *
2206 1.1 skrll tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
2207 1.1 skrll {
2208 1.1 skrll arelent *rel;
2209 1.1 skrll bfd_reloc_code_real_type r_type;
2210 1.1 skrll
2211 1.1 skrll if (fixp->fx_addsy && fixp->fx_subsy)
2212 1.1 skrll {
2213 1.1 skrll if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
2214 1.1 skrll || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
2215 1.1 skrll {
2216 1.1 skrll as_bad_where (fixp->fx_file, fixp->fx_line,
2217 1.1 skrll _("Difference of symbols in different sections is not supported"));
2218 1.1 skrll return NULL;
2219 1.1 skrll }
2220 1.1 skrll }
2221 1.1 skrll
2222 1.1 skrll rel = xmalloc (sizeof (arelent));
2223 1.1 skrll rel->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
2224 1.1 skrll *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2225 1.1 skrll rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2226 1.1 skrll rel->addend = fixp->fx_offset;
2227 1.1 skrll
2228 1.1 skrll r_type = fixp->fx_r_type;
2229 1.1 skrll
2230 1.1 skrll #define DEBUG 0
2231 1.1 skrll #if DEBUG
2232 1.1 skrll fprintf (stderr, "%s\n", bfd_get_reloc_code_name (r_type));
2233 1.1 skrll fflush (stderr);
2234 1.1 skrll #endif
2235 1.1 skrll rel->howto = bfd_reloc_type_lookup (stdoutput, r_type);
2236 1.1 skrll if (rel->howto == NULL)
2237 1.1 skrll {
2238 1.1 skrll as_bad_where (fixp->fx_file, fixp->fx_line,
2239 1.1 skrll _("Cannot represent relocation type %s"),
2240 1.1 skrll bfd_get_reloc_code_name (r_type));
2241 1.1 skrll return NULL;
2242 1.1 skrll }
2243 1.1 skrll
2244 return rel;
2245 }
2246