1 /* tc-h8300.c -- Assemble code for the Renesas H8/300
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* Written By Steve Chamberlain <sac@cygnus.com>. */
27 #include "dwarf2dbg.h"
30 #define h8_opcodes ops
31 #include "opcode/h8300.h"
32 #include "safe-ctype.h"
38 const char comment_chars
[] = ";";
39 const char line_comment_chars
[] = "#";
40 const char line_separator_chars
[] = "";
42 static void sbranch (int);
43 static void h8300hmode (int);
44 static void h8300smode (int);
45 static void h8300hnmode (int);
46 static void h8300snmode (int);
47 static void h8300sxmode (int);
48 static void h8300sxnmode (int);
49 static void pint (int);
56 #define PSIZE (Hmode && !Nmode ? L_32 : L_16)
58 static int bsize
= L_8
; /* Default branch displacement. */
66 const struct h8_opcode
*opcode
;
69 static struct h8_instruction
*h8_instructions
;
72 h8300hmode (int arg ATTRIBUTE_UNUSED
)
76 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
77 as_warn (_("could not set architecture and machine"));
81 h8300smode (int arg ATTRIBUTE_UNUSED
)
85 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
86 as_warn (_("could not set architecture and machine"));
90 h8300hnmode (int arg ATTRIBUTE_UNUSED
)
95 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300hn
))
96 as_warn (_("could not set architecture and machine"));
100 h8300snmode (int arg ATTRIBUTE_UNUSED
)
105 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sn
))
106 as_warn (_("could not set architecture and machine"));
110 h8300sxmode (int arg ATTRIBUTE_UNUSED
)
115 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sx
))
116 as_warn (_("could not set architecture and machine"));
120 h8300sxnmode (int arg ATTRIBUTE_UNUSED
)
126 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sxn
))
127 as_warn (_("could not set architecture and machine"));
137 pint (int arg ATTRIBUTE_UNUSED
)
139 cons (Hmode
? 4 : 2);
142 /* Like obj_elf_section, but issues a warning for new
143 sections which do not have an attribute specification. */
146 h8300_elf_section (int push
)
148 static const char * known_data_sections
[] = { ".rodata", ".tdata", ".tbss" };
149 static const char * known_data_prefixes
[] = { ".debug", ".zdebug", ".gnu.warning" };
150 char * saved_ilp
= input_line_pointer
;
153 name
= obj_elf_section_name ();
157 if (* input_line_pointer
!= ','
158 && bfd_get_section_by_name (stdoutput
, name
) == NULL
)
162 /* Ignore this warning for well known data sections. */
163 for (i
= ARRAY_SIZE (known_data_sections
); i
--;)
164 if (strcmp (name
, known_data_sections
[i
]) == 0)
168 for (i
= ARRAY_SIZE (known_data_prefixes
); i
--;)
169 if (strncmp (name
, known_data_prefixes
[i
],
170 strlen (known_data_prefixes
[i
])) == 0)
174 as_warn (_("new section '%s' defined without attributes - this might cause problems"), name
);
177 /* FIXME: We ought to free the memory allocated by obj_elf_section_name()
178 for 'name', but we do not know if it was taken from the obstack, via
179 demand_copy_C_string(), or xmalloc()ed. */
180 input_line_pointer
= saved_ilp
;
181 obj_elf_section (push
);
184 /* This table describes all the machine specific pseudo-ops the assembler
185 has to support. The fields are:
186 pseudo-op name without dot
187 function to call to execute this pseudo-op
188 Integer arg to pass to the function. */
190 const pseudo_typeS md_pseudo_table
[] =
192 {"h8300h", h8300hmode
, 0},
193 {"h8300hn", h8300hnmode
, 0},
194 {"h8300s", h8300smode
, 0},
195 {"h8300sn", h8300snmode
, 0},
196 {"h8300sx", h8300sxmode
, 0},
197 {"h8300sxn", h8300sxnmode
, 0},
198 {"sbranch", sbranch
, L_8
},
199 {"lbranch", sbranch
, L_16
},
205 {"form", listing_psize
, 0},
206 {"heading", listing_title
, 0},
207 {"import", s_ignore
, 0},
208 {"page", listing_eject
, 0},
209 {"program", s_ignore
, 0},
212 {"section", h8300_elf_section
, 0},
213 {"section.s", h8300_elf_section
, 0},
214 {"sect", h8300_elf_section
, 0},
215 {"sect.s", h8300_elf_section
, 0},
221 const char EXP_CHARS
[] = "eE";
223 /* Chars that mean this number is a floating point constant
226 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
228 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
230 /* This function is called once, at assembler startup time. This
231 should set up all the tables, etc. that the MD part of the assembler
237 unsigned int nopcodes
;
238 struct h8_opcode
*p
, *p1
;
239 struct h8_instruction
*pi
;
240 char prev_buffer
[100];
243 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
244 as_warn (_("could not set architecture and machine"));
246 opcode_hash_control
= hash_new ();
249 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
251 h8_instructions
= (struct h8_instruction
*)
252 xmalloc (nopcodes
* sizeof (struct h8_instruction
));
254 pi
= h8_instructions
;
256 /* We do a minimum amount of sorting on the opcode table; this is to
257 make it easy to describe the mova instructions without unnecessary
259 Sorting only takes place inside blocks of instructions of the form
260 X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */
263 struct h8_opcode
*first_skipped
= 0;
265 char *src
= p1
->name
;
270 /* Strip off any . part when inserting the opcode and only enter
271 unique codes into the hash table. */
272 dst
= buffer
= malloc (strlen (src
) + 1);
281 cmplen
= src
- p1
->name
+ 1;
288 hash_insert (opcode_hash_control
, buffer
, (char *) pi
);
289 strcpy (prev_buffer
, buffer
);
292 for (p
= p1
; p
->name
; p
++)
294 /* A negative TIME is used to indicate that we've added this opcode
298 if (strncmp (p
->name
, buffer
, cmplen
) != 0
299 || (p
->name
[cmplen
] != '\0' && p
->name
[cmplen
] != '.'
300 && p
->name
[cmplen
- 1] != '/'))
302 if (first_skipped
== 0)
306 if (strncmp (p
->name
, buffer
, len
) != 0)
308 if (first_skipped
== 0)
314 pi
->size
= p
->name
[len
] == '.' ? p
->name
[len
+ 1] : 0;
317 /* Find the number of operands. */
319 while (pi
->noperands
< 3 && p
->args
.nib
[pi
->noperands
] != (op_type
) E
)
322 /* Find the length of the opcode in bytes. */
324 while (p
->data
.nib
[pi
->length
* 2] != (op_type
) E
)
333 /* Add entry for the NULL vector terminator. */
350 static void clever_message (const struct h8_instruction
*, struct h8_op
*);
351 static void fix_operand_size (struct h8_op
*, int);
352 static void build_bytes (const struct h8_instruction
*, struct h8_op
*);
353 static void do_a_fix_imm (int, int, struct h8_op
*, int, const struct h8_instruction
*);
354 static void check_operand (struct h8_op
*, unsigned int, char *);
355 static const struct h8_instruction
* get_specific (const struct h8_instruction
*, struct h8_op
*, int) ;
356 static char *get_operands (unsigned, char *, struct h8_op
*);
357 static void get_operand (char **, struct h8_op
*, int);
358 static int parse_reg (char *, op_type
*, unsigned *, int);
359 static char *skip_colonthing (char *, int *);
360 static char *parse_exp (char *, struct h8_op
*);
362 static int constant_fits_width_p (struct h8_op
*, unsigned int);
363 static int constant_fits_size_p (struct h8_op
*, int, int);
367 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
376 /* Try to parse a reg name. Return the number of chars consumed. */
379 parse_reg (char *src
, op_type
*mode
, unsigned int *reg
, int direction
)
384 /* Cribbed from get_symbol_end. */
385 if (!is_name_beginner (*src
) || *src
== '\001')
388 while ((is_part_of_name (*end
) && *end
!= '.') || *end
== '\001')
392 if (len
== 2 && TOLOWER (src
[0]) == 's' && TOLOWER (src
[1]) == 'p')
394 *mode
= PSIZE
| REG
| direction
;
399 TOLOWER (src
[0]) == 'c' &&
400 TOLOWER (src
[1]) == 'c' &&
401 TOLOWER (src
[2]) == 'r')
408 TOLOWER (src
[0]) == 'e' &&
409 TOLOWER (src
[1]) == 'x' &&
410 TOLOWER (src
[2]) == 'r')
417 TOLOWER (src
[0]) == 'v' &&
418 TOLOWER (src
[1]) == 'b' &&
419 TOLOWER (src
[2]) == 'r')
426 TOLOWER (src
[0]) == 's' &&
427 TOLOWER (src
[1]) == 'b' &&
428 TOLOWER (src
[2]) == 'r')
434 if (len
== 2 && TOLOWER (src
[0]) == 'f' && TOLOWER (src
[1]) == 'p')
436 *mode
= PSIZE
| REG
| direction
;
440 if (len
== 3 && TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
441 src
[2] >= '0' && src
[2] <= '7')
443 *mode
= L_32
| REG
| direction
;
446 as_warn (_("Reg not valid for H8/300"));
449 if (len
== 2 && TOLOWER (src
[0]) == 'e' && src
[1] >= '0' && src
[1] <= '7')
451 *mode
= L_16
| REG
| direction
;
452 *reg
= src
[1] - '0' + 8;
454 as_warn (_("Reg not valid for H8/300"));
458 if (TOLOWER (src
[0]) == 'r')
460 if (src
[1] >= '0' && src
[1] <= '7')
462 if (len
== 3 && TOLOWER (src
[2]) == 'l')
464 *mode
= L_8
| REG
| direction
;
465 *reg
= (src
[1] - '0') + 8;
468 if (len
== 3 && TOLOWER (src
[2]) == 'h')
470 *mode
= L_8
| REG
| direction
;
471 *reg
= (src
[1] - '0');
476 *mode
= L_16
| REG
| direction
;
477 *reg
= (src
[1] - '0');
487 /* Parse an immediate or address-related constant and store it in OP.
488 If the user also specifies the operand's size, store that size
489 in OP->MODE, otherwise leave it for later code to decide. */
492 parse_exp (char *src
, struct h8_op
*op
)
496 save
= input_line_pointer
;
497 input_line_pointer
= src
;
498 expression (&op
->exp
);
499 if (op
->exp
.X_op
== O_absent
)
500 as_bad (_("missing operand"));
501 src
= input_line_pointer
;
502 input_line_pointer
= save
;
504 return skip_colonthing (src
, &op
->mode
);
508 /* If SRC starts with an explicit operand size, skip it and store the size
509 in *MODE. Leave *MODE unchanged otherwise. */
512 skip_colonthing (char *src
, int *mode
)
518 if (src
[0] == '8' && !ISDIGIT (src
[1]))
520 else if (src
[0] == '2' && !ISDIGIT (src
[1]))
522 else if (src
[0] == '3' && !ISDIGIT (src
[1]))
524 else if (src
[0] == '4' && !ISDIGIT (src
[1]))
526 else if (src
[0] == '5' && !ISDIGIT (src
[1]))
528 else if (src
[0] == '2' && src
[1] == '4' && !ISDIGIT (src
[2]))
530 else if (src
[0] == '3' && src
[1] == '2' && !ISDIGIT (src
[2]))
532 else if (src
[0] == '1' && src
[1] == '6' && !ISDIGIT (src
[2]))
535 as_bad (_("invalid operand size requested"));
537 while (ISDIGIT (*src
))
543 /* The many forms of operand:
546 @Rn Register indirect
547 @(exp[:16], Rn) Register indirect with displacement
551 @aa:16 absolute 16 bit
554 #xx[:size] immediate data
555 @(exp:[8], pc) pc rel
556 @@aa[:8] memory indirect. */
559 constant_fits_width_p (struct h8_op
*operand
, unsigned int width
)
561 return ((operand
->exp
.X_add_number
& ~width
) == 0
562 || (operand
->exp
.X_add_number
| (offsetT
) width
) == (offsetT
)(~0));
566 constant_fits_size_p (struct h8_op
*operand
, int size
, int no_symbols
)
568 offsetT num
= operand
->exp
.X_add_number
;
570 && (operand
->exp
.X_add_symbol
!= 0 || operand
->exp
.X_op_symbol
!= 0))
575 return (num
& ~3) == 0;
577 return (num
& ~7) == 0;
579 return num
>= 1 && num
< 8;
581 return (num
& ~15) == 0;
583 return num
>= 1 && num
< 32;
585 return (num
& ~0xFF) == 0 || ((unsigned)num
| 0x7F) == ~0u;
587 return (num
& ~0xFF) == 0;
589 return (num
& ~0xFFFF) == 0 || ((unsigned)num
| 0x7FFF) == ~0u;
591 return (num
& ~0xFFFF) == 0;
600 get_operand (char **ptr
, struct h8_op
*op
, int direction
)
609 /* Check for '(' and ')' for instructions ldm and stm. */
610 if (src
[0] == '(' && src
[8] == ')')
613 /* Gross. Gross. ldm and stm have a format not easily handled
614 by get_operand. We deal with it explicitly here. */
615 if (TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
616 ISDIGIT (src
[2]) && src
[3] == '-' &&
617 TOLOWER (src
[4]) == 'e' && TOLOWER (src
[5]) == 'r' && ISDIGIT (src
[6]))
624 /* Check register pair's validity as per tech note TN-H8*-193A/E
625 from Renesas for H8S and H8SX hardware manual. */
626 if ( !(low
== 0 && (high
== 1 || high
== 2 || high
== 3))
627 && !(low
== 1 && (high
== 2 || high
== 3 || high
== 4) && SXmode
)
628 && !(low
== 2 && (high
== 3 || ((high
== 4 || high
== 5) && SXmode
)))
629 && !(low
== 3 && (high
== 4 || high
== 5 || high
== 6) && SXmode
)
630 && !(low
== 4 && (high
== 5 || high
== 6))
631 && !(low
== 4 && high
== 7 && SXmode
)
632 && !(low
== 5 && (high
== 6 || high
== 7) && SXmode
)
633 && !(low
== 6 && high
== 7 && SXmode
))
634 as_bad (_("Invalid register list for ldm/stm\n"));
636 /* Even sicker. We encode two registers into op->reg. One
637 for the low register to save, the other for the high
638 register to save; we also set the high bit in op->reg
639 so we know this is "very special". */
640 op
->reg
= 0x80000000 | (high
<< 8) | low
;
649 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
655 int size
= op
->mode
& SIZE
;
660 as_warn (_("mismatch between register and suffix"));
661 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
664 if (size
!= L_32
&& size
!= L_16
)
665 as_warn (_("mismatch between register and suffix"));
666 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
667 op
->mode
= (op
->mode
& ~SIZE
) | L_16
;
670 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
671 if (size
!= L_32
&& size
!= L_8
)
672 as_warn (_("mismatch between register and suffix"));
673 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
674 op
->mode
= (op
->mode
& ~SIZE
) | L_8
;
677 as_warn (_("invalid suffix after register."));
691 *ptr
= parse_exp (src
+ 1, op
);
692 if (op
->exp
.X_add_number
>= 0x100)
697 /* FIXME : 2? or 4? */
698 if (op
->exp
.X_add_number
>= 0x400)
699 as_bad (_("address too high for vector table jmp/jsr"));
700 else if (op
->exp
.X_add_number
>= 0x200)
705 op
->exp
.X_add_number
= op
->exp
.X_add_number
/ divisor
- 0x80;
712 if (*src
== '-' || *src
== '+')
714 len
= parse_reg (src
+ 1, &mode
, &num
, direction
);
717 /* Oops, not a reg after all, must be ordinary exp. */
718 op
->mode
= ABS
| direction
;
719 *ptr
= parse_exp (src
, op
);
723 if (((mode
& SIZE
) != PSIZE
)
724 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
725 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
726 as_bad (_("Wrong size pointer register for architecture."));
728 op
->mode
= src
[0] == '-' ? RDPREDEC
: RDPREINC
;
730 *ptr
= src
+ 1 + len
;
737 /* See if this is @(ERn.x, PC). */
738 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
739 if (len
!= 0 && (mode
& MODE
) == REG
&& src
[len
] == '.')
741 switch (TOLOWER (src
[len
+ 1]))
744 mode
= PCIDXB
| direction
;
747 mode
= PCIDXW
| direction
;
750 mode
= PCIDXL
| direction
;
757 && src
[len
+ 2] == ','
758 && TOLOWER (src
[len
+ 3]) != 'p'
759 && TOLOWER (src
[len
+ 4]) != 'c'
760 && src
[len
+ 5] != ')')
762 *ptr
= src
+ len
+ 6;
766 /* Fall through into disp case - the grammar is somewhat
767 ambiguous, so we should try whether it's a DISP operand
768 after all ("ER3.L" might be a poorly named label...). */
773 /* Start off assuming a 16 bit offset. */
775 src
= parse_exp (src
, op
);
778 op
->mode
|= ABS
| direction
;
785 as_bad (_("expected @(exp, reg16)"));
790 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
791 if (len
== 0 || (mode
& MODE
) != REG
)
793 as_bad (_("expected @(exp, reg16)"));
799 switch (TOLOWER (src
[1]))
802 op
->mode
|= INDEXB
| direction
;
805 op
->mode
|= INDEXW
| direction
;
808 op
->mode
|= INDEXL
| direction
;
811 as_bad (_("expected .L, .W or .B for register in indexed addressing mode"));
817 op
->mode
|= DISP
| direction
;
818 src
= skip_colonthing (src
, &op
->mode
);
820 if (*src
!= ')' && '(')
822 as_bad (_("expected @(exp, reg16)"));
828 len
= parse_reg (src
, &mode
, &num
, direction
);
833 if (*src
== '+' || *src
== '-')
835 if (((mode
& SIZE
) != PSIZE
)
836 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
837 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
838 as_bad (_("Wrong size pointer register for architecture."));
839 op
->mode
= *src
== '+' ? RSPOSTINC
: RSPOSTDEC
;
845 if (((mode
& SIZE
) != PSIZE
)
846 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
847 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
848 as_bad (_("Wrong size pointer register for architecture."));
850 op
->mode
= direction
| IND
| PSIZE
;
858 /* must be a symbol */
860 op
->mode
= ABS
| direction
;
861 *ptr
= parse_exp (src
, op
);
869 *ptr
= parse_exp (src
+ 1, op
);
872 else if (strncmp (src
, "mach", 4) == 0 ||
873 strncmp (src
, "macl", 4) == 0 ||
874 strncmp (src
, "MACH", 4) == 0 ||
875 strncmp (src
, "MACL", 4) == 0)
877 op
->reg
= TOLOWER (src
[3]) == 'l';
885 *ptr
= parse_exp (src
, op
);
890 get_operands (unsigned int noperands
, char *op_end
, struct h8_op
*operand
)
901 get_operand (&ptr
, operand
+ 0, SRC
);
905 get_operand (&ptr
, operand
+ 1, DST
);
911 get_operand (&ptr
, operand
+ 0, SRC
);
914 get_operand (&ptr
, operand
+ 1, DST
);
919 get_operand (&ptr
, operand
+ 0, SRC
);
922 get_operand (&ptr
, operand
+ 1, DST
);
925 get_operand (&ptr
, operand
+ 2, OP3
);
935 /* MOVA has special requirements. Rather than adding twice the amount of
936 addressing modes, we simply special case it a bit. */
938 get_mova_operands (char *op_end
, struct h8_op
*operand
)
942 if (ptr
[1] != '@' || ptr
[2] != '(')
946 ptr
= parse_exp (ptr
, &operand
[0]);
951 get_operand (&ptr
, operand
+ 1, DST
);
959 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
962 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
965 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
971 else if ((operand
[1].mode
& MODE
) == LOWREG
)
973 switch (operand
[1].mode
& SIZE
)
976 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
979 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
982 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
991 if (*ptr
++ != ')' || *ptr
++ != ',')
993 get_operand (&ptr
, operand
+ 2, OP3
);
994 /* See if we can use the short form of MOVA. */
995 if (((operand
[1].mode
& MODE
) == REG
|| (operand
[1].mode
& MODE
) == LOWREG
)
996 && (operand
[2].mode
& MODE
) == REG
997 && (operand
[1].reg
& 7) == (operand
[2].reg
& 7))
999 operand
[1].mode
= operand
[2].mode
= 0;
1000 operand
[0].reg
= operand
[2].reg
& 7;
1005 as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
1009 get_rtsl_operands (char *ptr
, struct h8_op
*operand
)
1011 int mode
, len
, type
= 0;
1012 unsigned int num
, num2
;
1020 len
= parse_reg (ptr
, &mode
, &num
, SRC
);
1021 if (len
== 0 || (mode
& MODE
) != REG
)
1023 as_bad (_("expected register"));
1029 len
= parse_reg (++ptr
, &mode
, &num2
, SRC
);
1030 if (len
== 0 || (mode
& MODE
) != REG
)
1032 as_bad (_("expected register"));
1036 /* CONST_xxx are used as placeholders in the opcode table. */
1040 as_bad (_("invalid register list"));
1045 num2
= num
, num
= 0;
1046 if (type
== 1 && *ptr
++ != ')')
1048 as_bad (_("expected closing paren"));
1051 operand
[0].mode
= RS32
;
1052 operand
[1].mode
= RD32
;
1053 operand
[0].reg
= num
;
1054 operand
[1].reg
= num2
;
1057 /* Passed a pointer to a list of opcodes which use different
1058 addressing modes, return the opcode which matches the opcodes
1061 static const struct h8_instruction
*
1062 get_specific (const struct h8_instruction
*instruction
,
1063 struct h8_op
*operands
, int size
)
1065 const struct h8_instruction
*this_try
= instruction
;
1066 const struct h8_instruction
*found_other
= 0, *found_mismatched
= 0;
1068 int this_index
= instruction
->idx
;
1071 /* There's only one ldm/stm and it's easier to just
1072 get out quick for them. */
1073 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
1074 || OP_KIND (instruction
->opcode
->how
) == O_STM
)
1077 while (noperands
< 3 && operands
[noperands
].mode
!= 0)
1080 while (this_index
== instruction
->idx
&& !found
)
1085 this_try
= instruction
++;
1086 this_size
= this_try
->opcode
->how
& SN
;
1088 if (this_try
->noperands
!= noperands
)
1090 else if (this_try
->noperands
> 0)
1094 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
1096 op_type op
= this_try
->opcode
->args
.nib
[i
];
1097 int op_mode
= op
& MODE
;
1098 int op_size
= op
& SIZE
;
1099 int x
= operands
[i
].mode
;
1100 int x_mode
= x
& MODE
;
1101 int x_size
= x
& SIZE
;
1103 if (op_mode
== LOWREG
&& (x_mode
== REG
|| x_mode
== LOWREG
))
1105 if ((x_size
== L_8
&& (operands
[i
].reg
& 8) == 0)
1106 || (x_size
== L_16
&& (operands
[i
].reg
& 8) == 8))
1107 as_warn (_("can't use high part of register in operand %d"), i
);
1109 if (x_size
!= op_size
)
1112 else if (op_mode
== REG
)
1114 if (x_mode
== LOWREG
)
1120 x_size
= (Hmode
? L_32
: L_16
);
1122 op_size
= (Hmode
? L_32
: L_16
);
1124 /* The size of the reg is v important. */
1125 if (op_size
!= x_size
)
1128 else if (op_mode
& CTRL
) /* control register */
1130 if (!(x_mode
& CTRL
))
1136 if (op_mode
!= CCR
&&
1137 op_mode
!= CCR_EXR
&&
1138 op_mode
!= CC_EX_VB_SB
)
1142 if (op_mode
!= EXR
&&
1143 op_mode
!= CCR_EXR
&&
1144 op_mode
!= CC_EX_VB_SB
)
1148 if (op_mode
!= MACH
&&
1153 if (op_mode
!= MACL
&&
1158 if (op_mode
!= VBR
&&
1159 op_mode
!= VBR_SBR
&&
1160 op_mode
!= CC_EX_VB_SB
)
1164 if (op_mode
!= SBR
&&
1165 op_mode
!= VBR_SBR
&&
1166 op_mode
!= CC_EX_VB_SB
)
1171 else if ((op
& ABSJMP
) && (x_mode
== ABS
|| x_mode
== PCREL
))
1173 operands
[i
].mode
&= ~MODE
;
1174 operands
[i
].mode
|= ABSJMP
;
1175 /* But it may not be 24 bits long. */
1176 if (x_mode
== ABS
&& !Hmode
)
1178 operands
[i
].mode
&= ~SIZE
;
1179 operands
[i
].mode
|= L_16
;
1181 if ((operands
[i
].mode
& SIZE
) == L_32
1182 && (op_mode
& SIZE
) != L_32
)
1185 else if (x_mode
== IMM
&& op_mode
!= IMM
)
1187 offsetT num
= operands
[i
].exp
.X_add_number
;
1188 if (op_mode
== KBIT
|| op_mode
== DBIT
)
1189 /* This is ok if the immediate value is sensible. */;
1190 else if (op_mode
== CONST_2
)
1192 else if (op_mode
== CONST_4
)
1194 else if (op_mode
== CONST_8
)
1196 else if (op_mode
== CONST_16
)
1201 else if (op_mode
== PCREL
&& op_mode
== x_mode
)
1203 /* movsd, bsr/bc and bsr/bs only come in PCREL16 flavour:
1204 If x_size is L_8, promote it. */
1205 if (OP_KIND (this_try
->opcode
->how
) == O_MOVSD
1206 || OP_KIND (this_try
->opcode
->how
) == O_BSRBC
1207 || OP_KIND (this_try
->opcode
->how
) == O_BSRBS
)
1211 /* The size of the displacement is important. */
1212 if (op_size
!= x_size
)
1215 else if ((op_mode
== DISP
|| op_mode
== IMM
|| op_mode
== ABS
1216 || op_mode
== INDEXB
|| op_mode
== INDEXW
1217 || op_mode
== INDEXL
)
1218 && op_mode
== x_mode
)
1220 /* Promote a L_24 to L_32 if it makes us match. */
1221 if (x_size
== L_24
&& op_size
== L_32
)
1227 if (((x_size
== L_16
&& op_size
== L_16U
)
1228 || (x_size
== L_8
&& op_size
== L_8U
)
1229 || (x_size
== L_3
&& op_size
== L_3NZ
))
1230 /* We're deliberately more permissive for ABS modes. */
1232 || constant_fits_size_p (operands
+ i
, op_size
,
1236 if (x_size
!= 0 && op_size
!= x_size
)
1238 else if (x_size
== 0
1239 && ! constant_fits_size_p (operands
+ i
, op_size
,
1243 else if (op_mode
!= x_mode
)
1251 if ((this_try
->opcode
->available
== AV_H8SX
&& ! SXmode
)
1252 || (this_try
->opcode
->available
== AV_H8S
&& ! Smode
)
1253 || (this_try
->opcode
->available
== AV_H8H
&& ! Hmode
))
1254 found
= 0, found_other
= this_try
;
1255 else if (this_size
!= size
&& (this_size
!= SN
&& size
!= SN
))
1256 found_mismatched
= this_try
, found
= 0;
1264 as_warn (_("Opcode `%s' with these operand types not available in %s mode"),
1265 found_other
->opcode
->name
,
1266 (! Hmode
&& ! Smode
? "H8/300"
1271 else if (found_mismatched
)
1273 as_warn (_("mismatch between opcode size and operand size"));
1274 return found_mismatched
;
1280 check_operand (struct h8_op
*operand
, unsigned int width
, char *string
)
1282 if (operand
->exp
.X_add_symbol
== 0
1283 && operand
->exp
.X_op_symbol
== 0)
1285 /* No symbol involved, let's look at offset, it's dangerous if
1286 any of the high bits are not 0 or ff's, find out by oring or
1287 anding with the width and seeing if the answer is 0 or all
1290 if (! constant_fits_width_p (operand
, width
))
1293 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
1295 /* Just ignore this one - which happens when trying to
1296 fit a 16 bit address truncated into an 8 bit address
1297 of something like bset. */
1299 else if (strcmp (string
, "@") == 0
1301 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
1303 /* Just ignore this one - which happens when trying to
1304 fit a 24 bit address truncated into a 16 bit address
1305 of something like mov.w. */
1309 as_warn (_("operand %s0x%lx out of range."), string
,
1310 (unsigned long) operand
->exp
.X_add_number
);
1316 /* RELAXMODE has one of 3 values:
1318 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
1320 1 Output a relaxable 24bit absolute mov.w address relocation
1321 (may relax into a 16bit absolute address).
1323 2 Output a relaxable 16/24 absolute mov.b address relocation
1324 (may relax into an 8bit absolute address). */
1327 do_a_fix_imm (int offset
, int nibble
, struct h8_op
*operand
, int relaxmode
, const struct h8_instruction
*this_try
)
1332 char *bytes
= frag_now
->fr_literal
+ offset
;
1334 char *t
= ((operand
->mode
& MODE
) == IMM
) ? "#" : "@";
1336 if (operand
->exp
.X_add_symbol
== 0)
1338 switch (operand
->mode
& SIZE
)
1341 check_operand (operand
, 0x3, t
);
1342 bytes
[0] |= (operand
->exp
.X_add_number
& 3) << (nibble
? 0 : 4);
1346 check_operand (operand
, 0x7, t
);
1347 bytes
[0] |= (operand
->exp
.X_add_number
& 7) << (nibble
? 0 : 4);
1350 check_operand (operand
, 0xF, t
);
1351 bytes
[0] |= (operand
->exp
.X_add_number
& 15) << (nibble
? 0 : 4);
1354 check_operand (operand
, 0x1F, t
);
1355 bytes
[0] |= operand
->exp
.X_add_number
& 31;
1359 check_operand (operand
, 0xff, t
);
1360 bytes
[0] |= operand
->exp
.X_add_number
;
1364 check_operand (operand
, 0xffff, t
);
1365 bytes
[0] |= operand
->exp
.X_add_number
>> 8;
1366 bytes
[1] |= operand
->exp
.X_add_number
>> 0;
1368 /* MOVA needs both relocs to relax the second operand properly. */
1370 && (OP_KIND(this_try
->opcode
->how
) == O_MOVAB
1371 || OP_KIND(this_try
->opcode
->how
) == O_MOVAW
1372 || OP_KIND(this_try
->opcode
->how
) == O_MOVAL
))
1375 fix_new_exp (frag_now
, offset
, 2, &operand
->exp
, 0, idx
);
1380 check_operand (operand
, 0xffffff, t
);
1381 bytes
[0] |= operand
->exp
.X_add_number
>> 16;
1382 bytes
[1] |= operand
->exp
.X_add_number
>> 8;
1383 bytes
[2] |= operand
->exp
.X_add_number
>> 0;
1387 /* This should be done with bfd. */
1388 bytes
[0] |= operand
->exp
.X_add_number
>> 24;
1389 bytes
[1] |= operand
->exp
.X_add_number
>> 16;
1390 bytes
[2] |= operand
->exp
.X_add_number
>> 8;
1391 bytes
[3] |= operand
->exp
.X_add_number
>> 0;
1394 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
1395 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
1402 switch (operand
->mode
& SIZE
)
1407 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
1410 else if (relaxmode
== 1)
1416 as_bad (_("Can't work out size of operand.\n"));
1425 operand
->exp
.X_add_number
=
1426 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1427 operand
->exp
.X_add_number
|= (bytes
[0] << 8) | bytes
[1];
1433 operand
->exp
.X_add_number
=
1434 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1435 operand
->exp
.X_add_number
|= bytes
[0];
1438 fix_new_exp (frag_now
,
1447 /* Now we know what sort of opcodes it is, let's build the bytes. */
1450 build_bytes (const struct h8_instruction
*this_try
, struct h8_op
*operand
)
1453 char *output
= frag_more (this_try
->length
);
1454 const op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1456 unsigned int nibble_count
= 0;
1460 char asnibbles
[100];
1461 char *p
= asnibbles
;
1464 if (!Hmode
&& this_try
->opcode
->available
!= AV_H8
)
1465 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1466 this_try
->opcode
->name
);
1468 && this_try
->opcode
->available
!= AV_H8
1469 && this_try
->opcode
->available
!= AV_H8H
)
1470 as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"),
1471 this_try
->opcode
->name
);
1473 && this_try
->opcode
->available
!= AV_H8
1474 && this_try
->opcode
->available
!= AV_H8H
1475 && this_try
->opcode
->available
!= AV_H8S
)
1476 as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"),
1477 this_try
->opcode
->name
);
1479 while (*nibble_ptr
!= (op_type
) E
)
1486 d
= (c
& OP3
) == OP3
? 2 : (c
& DST
) == DST
? 1 : 0;
1494 if (c2
== REG
|| c2
== LOWREG
1495 || c2
== IND
|| c2
== PREINC
|| c2
== PREDEC
1496 || c2
== POSTINC
|| c2
== POSTDEC
)
1498 nib
= operand
[d
].reg
;
1503 else if (c
& CTRL
) /* Control reg operand. */
1504 nib
= operand
[d
].reg
;
1506 else if ((c
& DISPREG
) == (DISPREG
))
1508 nib
= operand
[d
].reg
;
1512 operand
[d
].mode
= c
;
1513 op_at
[d
] = nibble_count
;
1516 else if (c2
== IMM
|| c2
== PCREL
|| c2
== ABS
1517 || (c
& ABSJMP
) || c2
== DISP
)
1519 operand
[d
].mode
= c
;
1520 op_at
[d
] = nibble_count
;
1523 else if ((c
& IGNORE
) || (c
& DATA
))
1526 else if (c2
== DBIT
)
1528 switch (operand
[0].exp
.X_add_number
)
1537 as_bad (_("Need #1 or #2 here"));
1540 else if (c2
== KBIT
)
1542 switch (operand
[0].exp
.X_add_number
)
1552 as_warn (_("#4 not valid on H8/300."));
1557 as_bad (_("Need #1 or #2 here"));
1560 /* Stop it making a fix. */
1561 operand
[0].mode
= 0;
1565 operand
[d
].mode
|= MEMRELAX
;
1581 if (operand
[0].mode
== MACREG
)
1582 /* stmac has mac[hl] as the first operand. */
1583 nib
= 2 + operand
[0].reg
;
1585 /* ldmac has mac[hl] as the second operand. */
1586 nib
= 2 + operand
[1].reg
;
1594 /* Disgusting. Why, oh why didn't someone ask us for advice
1595 on the assembler format. */
1596 if (OP_KIND (this_try
->opcode
->how
) == O_LDM
)
1598 high
= (operand
[1].reg
>> 8) & 0xf;
1599 low
= (operand
[1].reg
) & 0xf;
1600 asnibbles
[2] = high
- low
;
1601 asnibbles
[7] = high
;
1603 else if (OP_KIND (this_try
->opcode
->how
) == O_STM
)
1605 high
= (operand
[0].reg
>> 8) & 0xf;
1606 low
= (operand
[0].reg
) & 0xf;
1607 asnibbles
[2] = high
- low
;
1611 for (i
= 0; i
< this_try
->length
; i
++)
1612 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1614 /* Note if this is a movb or a bit manipulation instruction
1615 there is a special relaxation which only applies. */
1616 if ( this_try
->opcode
->how
== O (O_MOV
, SB
)
1617 || this_try
->opcode
->how
== O (O_BCLR
, SB
)
1618 || this_try
->opcode
->how
== O (O_BAND
, SB
)
1619 || this_try
->opcode
->how
== O (O_BIAND
, SB
)
1620 || this_try
->opcode
->how
== O (O_BILD
, SB
)
1621 || this_try
->opcode
->how
== O (O_BIOR
, SB
)
1622 || this_try
->opcode
->how
== O (O_BIST
, SB
)
1623 || this_try
->opcode
->how
== O (O_BIXOR
, SB
)
1624 || this_try
->opcode
->how
== O (O_BLD
, SB
)
1625 || this_try
->opcode
->how
== O (O_BNOT
, SB
)
1626 || this_try
->opcode
->how
== O (O_BOR
, SB
)
1627 || this_try
->opcode
->how
== O (O_BSET
, SB
)
1628 || this_try
->opcode
->how
== O (O_BST
, SB
)
1629 || this_try
->opcode
->how
== O (O_BTST
, SB
)
1630 || this_try
->opcode
->how
== O (O_BXOR
, SB
))
1633 /* Output any fixes. */
1634 for (i
= 0; i
< this_try
->noperands
; i
++)
1636 int x
= operand
[i
].mode
;
1637 int x_mode
= x
& MODE
;
1639 if (x_mode
== IMM
|| x_mode
== DISP
)
1640 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1641 op_at
[i
] & 1, operand
+ i
, (x
& MEMRELAX
) != 0,
1644 else if (x_mode
== ABS
)
1645 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1646 op_at
[i
] & 1, operand
+ i
,
1647 (x
& MEMRELAX
) ? movb
+ 1 : 0,
1650 else if (x_mode
== PCREL
)
1652 int size16
= (x
& SIZE
) == L_16
;
1653 int size
= size16
? 2 : 1;
1654 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1657 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1659 if (operand
[i
].exp
.X_add_number
& 1)
1660 as_warn (_("branch operand has odd offset (%lx)\n"),
1661 (unsigned long) operand
->exp
.X_add_number
);
1663 /* The COFF port has always been off by one, changing it
1664 now would be an incompatible change, so we leave it as-is.
1666 We don't want to do this for ELF as we want to be
1667 compatible with the proposed ELF format from Hitachi. */
1668 operand
[i
].exp
.X_add_number
-= 1;
1672 operand
[i
].exp
.X_add_number
=
1673 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1677 operand
[i
].exp
.X_add_number
=
1678 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1683 operand
[i
].exp
.X_add_number
|= output
[op_at
[i
] / 2];
1685 fixP
= fix_new_exp (frag_now
,
1686 output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1691 fixP
->fx_signed
= 1;
1693 else if (x_mode
== MEMIND
)
1695 check_operand (operand
+ i
, 0xff, "@@");
1696 fix_new_exp (frag_now
,
1697 output
- frag_now
->fr_literal
+ 1,
1703 else if (x_mode
== VECIND
)
1705 check_operand (operand
+ i
, 0x7f, "@@");
1706 /* FIXME: approximating the effect of "B31" here...
1707 This is very hackish, and ought to be done a better way. */
1708 operand
[i
].exp
.X_add_number
|= 0x80;
1709 fix_new_exp (frag_now
,
1710 output
- frag_now
->fr_literal
+ 1,
1716 else if (x
& ABSJMP
)
1719 bfd_reloc_code_real_type reloc_type
= R_JMPL1
;
1722 /* To be compatible with the proposed H8 ELF format, we
1723 want the relocation's offset to point to the first byte
1724 that will be modified, not to the start of the instruction. */
1726 if ((operand
->mode
& SIZE
) == L_32
)
1729 reloc_type
= R_RELLONG
;
1735 /* This jmp may be a jump or a branch. */
1737 check_operand (operand
+ i
,
1738 SXmode
? 0xffffffff : Hmode
? 0xffffff : 0xffff,
1741 if (operand
[i
].exp
.X_add_number
& 1)
1742 as_warn (_("branch operand has odd offset (%lx)\n"),
1743 (unsigned long) operand
->exp
.X_add_number
);
1746 operand
[i
].exp
.X_add_number
=
1747 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1748 fix_new_exp (frag_now
,
1749 output
- frag_now
->fr_literal
+ where
,
1758 /* Try to give an intelligent error message for common and simple to
1762 clever_message (const struct h8_instruction
*instruction
,
1763 struct h8_op
*operand
)
1765 /* Find out if there was more than one possible opcode. */
1767 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1771 /* Only one opcode of this flavour, try to guess which operand
1773 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1775 switch (instruction
->opcode
->args
.nib
[argn
])
1778 if (operand
[argn
].mode
!= RD16
)
1780 as_bad (_("destination operand must be 16 bit register"));
1787 if (operand
[argn
].mode
!= RS8
)
1789 as_bad (_("source operand must be 8 bit register"));
1795 if (operand
[argn
].mode
!= ABS16DST
)
1797 as_bad (_("destination operand must be 16bit absolute address"));
1802 if (operand
[argn
].mode
!= RD8
)
1804 as_bad (_("destination operand must be 8 bit register"));
1810 if (operand
[argn
].mode
!= ABS16SRC
)
1812 as_bad (_("source operand must be 16bit absolute address"));
1820 as_bad (_("invalid operands"));
1824 /* If OPERAND is part of an address, adjust its size and value given
1825 that it addresses SIZE bytes.
1827 This function decides how big non-immediate constants are when no
1828 size was explicitly given. It also scales down the assembly-level
1829 displacement in an @(d:2,ERn) operand. */
1832 fix_operand_size (struct h8_op
*operand
, int size
)
1834 if (SXmode
&& (operand
->mode
& MODE
) == DISP
)
1836 /* If the user didn't specify an operand width, see if we
1837 can use @(d:2,ERn). */
1838 if ((operand
->mode
& SIZE
) == 0
1839 && operand
->exp
.X_add_symbol
== 0
1840 && operand
->exp
.X_op_symbol
== 0
1841 && (operand
->exp
.X_add_number
== size
1842 || operand
->exp
.X_add_number
== size
* 2
1843 || operand
->exp
.X_add_number
== size
* 3))
1844 operand
->mode
|= L_2
;
1846 /* Scale down the displacement in an @(d:2,ERn) operand.
1847 X_add_number then contains the desired field value. */
1848 if ((operand
->mode
& SIZE
) == L_2
)
1850 if (operand
->exp
.X_add_number
% size
!= 0)
1851 as_warn (_("operand/size mis-match"));
1852 operand
->exp
.X_add_number
/= size
;
1856 if ((operand
->mode
& SIZE
) == 0)
1857 switch (operand
->mode
& MODE
)
1864 /* Pick a 24-bit address unless we know that a 16-bit address
1865 is safe. get_specific() will relax L_24 into L_32 where
1869 && (operand
->exp
.X_add_number
< -32768
1870 || operand
->exp
.X_add_number
> 32767
1871 || operand
->exp
.X_add_symbol
!= 0
1872 || operand
->exp
.X_op_symbol
!= 0))
1873 operand
->mode
|= L_24
;
1875 operand
->mode
|= L_16
;
1879 /* This condition is long standing, though somewhat suspect. */
1880 if (operand
->exp
.X_add_number
> -128
1881 && operand
->exp
.X_add_number
< 127)
1883 if (operand
->exp
.X_add_symbol
!= NULL
)
1884 operand
->mode
|= bsize
;
1886 operand
->mode
|= L_8
;
1889 operand
->mode
|= L_16
;
1895 /* This is the guts of the machine-dependent assembler. STR points to
1896 a machine dependent instruction. This function is supposed to emit
1897 the frags/bytes it assembles. */
1900 md_assemble (char *str
)
1904 struct h8_op operand
[3];
1905 const struct h8_instruction
*instruction
;
1906 const struct h8_instruction
*prev_instruction
;
1913 /* Drop leading whitespace. */
1917 /* Find the op code end. */
1918 for (op_start
= op_end
= str
;
1919 *op_end
!= 0 && *op_end
!= ' ';
1929 else if (*op_end
== '/' && ! slash
)
1933 if (op_end
== op_start
)
1935 as_bad (_("can't find opcode "));
1941 /* The assembler stops scanning the opcode at slashes, so it fails
1942 to make characters following them lower case. Fix them. */
1945 *slash
= TOLOWER (*slash
);
1947 instruction
= (const struct h8_instruction
*)
1948 hash_find (opcode_hash_control
, op_start
);
1950 if (instruction
== NULL
)
1952 as_bad (_("unknown opcode"));
1956 /* We used to set input_line_pointer to the result of get_operands,
1957 but that is wrong. Our caller assumes we don't change it. */
1959 operand
[0].mode
= 0;
1960 operand
[1].mode
= 0;
1961 operand
[2].mode
= 0;
1963 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
1964 || OP_KIND (instruction
->opcode
->how
) == O_MOVAW
1965 || OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
1966 get_mova_operands (op_end
, operand
);
1967 else if (OP_KIND (instruction
->opcode
->how
) == O_RTEL
1968 || OP_KIND (instruction
->opcode
->how
) == O_RTSL
)
1969 get_rtsl_operands (op_end
, operand
);
1971 get_operands (instruction
->noperands
, op_end
, operand
);
1974 prev_instruction
= instruction
;
1976 /* Now we have operands from instruction.
1977 Let's check them out for ldm and stm. */
1978 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
)
1980 /* The first operand must be @er7+, and the
1981 second operand must be a register pair. */
1982 if ((operand
[0].mode
!= RSINC
)
1983 || (operand
[0].reg
!= 7)
1984 || ((operand
[1].reg
& 0x80000000) == 0))
1985 as_bad (_("invalid operand in ldm"));
1987 else if (OP_KIND (instruction
->opcode
->how
) == O_STM
)
1989 /* The first operand must be a register pair,
1990 and the second operand must be @-er7. */
1991 if (((operand
[0].reg
& 0x80000000) == 0)
1992 || (operand
[1].mode
!= RDDEC
)
1993 || (operand
[1].reg
!= 7))
1994 as_bad (_("invalid operand in stm"));
2000 switch (TOLOWER (*dot
))
2015 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
||
2016 OP_KIND (instruction
->opcode
->how
) == O_MOVAW
||
2017 OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
2019 switch (operand
[0].mode
& MODE
)
2023 fix_operand_size (&operand
[1], 1);
2026 fix_operand_size (&operand
[1], 2);
2029 fix_operand_size (&operand
[1], 4);
2035 for (i
= 0; i
< 3 && operand
[i
].mode
!= 0; i
++)
2041 fix_operand_size (&operand
[i
], 1);
2044 fix_operand_size (&operand
[i
], 2);
2047 fix_operand_size (&operand
[i
], 4);
2052 instruction
= get_specific (instruction
, operand
, size
);
2054 if (instruction
== 0)
2056 /* Couldn't find an opcode which matched the operands. */
2057 char *where
= frag_more (2);
2061 clever_message (prev_instruction
, operand
);
2066 build_bytes (instruction
, operand
);
2068 dwarf2_emit_insn (instruction
->length
);
2072 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2077 /* Various routines to kill one day. */
2080 md_atof (int type
, char *litP
, int *sizeP
)
2082 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
2085 #define OPTION_H_TICK_HEX (OPTION_MD_BASE)
2087 const char *md_shortopts
= "";
2088 struct option md_longopts
[] = {
2089 { "h-tick-hex", no_argument
, NULL
, OPTION_H_TICK_HEX
},
2090 {NULL
, no_argument
, NULL
, 0}
2093 size_t md_longopts_size
= sizeof (md_longopts
);
2096 md_parse_option (int c ATTRIBUTE_UNUSED
, char *arg ATTRIBUTE_UNUSED
)
2100 case OPTION_H_TICK_HEX
:
2101 enable_h_tick_hex
= 1;
2111 md_show_usage (FILE *stream ATTRIBUTE_UNUSED
)
2115 void tc_aout_fix_to_chars (void);
2118 tc_aout_fix_to_chars (void)
2120 printf (_("call to tc_aout_fix_to_chars \n"));
2125 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
,
2126 segT seg ATTRIBUTE_UNUSED
,
2127 fragS
*fragP ATTRIBUTE_UNUSED
)
2129 printf (_("call to md_convert_frag \n"));
2134 md_section_align (segT segment
, valueT size
)
2136 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2137 return ((size
+ (1 << align
) - 1) & (-1 << align
));
2141 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2143 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2146 switch (fixP
->fx_size
)
2152 *buf
++ = (val
>> 8);
2156 *buf
++ = (val
>> 24);
2157 *buf
++ = (val
>> 16);
2158 *buf
++ = (val
>> 8);
2162 /* This can arise when the .quad or .8byte pseudo-ops are used.
2163 Returning here (without setting fx_done) will cause the code
2164 to attempt to generate a reloc which will then fail with the
2165 slightly more helpful error message: "Cannot represent
2166 relocation type BFD_RELOC_64". */
2172 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
2177 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
2178 segT segment_type ATTRIBUTE_UNUSED
)
2180 printf (_("call to md_estimate_size_before_relax \n"));
2184 /* Put number into target byte order. */
2186 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
2188 number_to_chars_bigendian (ptr
, use
, nbytes
);
2192 md_pcrel_from (fixS
*fixp
)
2194 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2195 _("Unexpected reference to a symbol in a non-code section"));
2200 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
2203 bfd_reloc_code_real_type r_type
;
2205 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2207 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2208 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2210 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2211 _("Difference of symbols in different sections is not supported"));
2216 rel
= xmalloc (sizeof (arelent
));
2217 rel
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2218 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2219 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2220 rel
->addend
= fixp
->fx_offset
;
2222 r_type
= fixp
->fx_r_type
;
2226 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
2229 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
2230 if (rel
->howto
== NULL
)
2232 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2233 _("Cannot represent relocation type %s"),
2234 bfd_get_reloc_code_name (r_type
));