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