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