1 /* tc-h8300.c -- Assemble code for the Renesas H8/300
2 Copyright (C) 1991-2023 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* Written By Steve Chamberlain <sac@cygnus.com>. */
25 #include "dwarf2dbg.h"
28 #define h8_opcodes ops
29 #include "opcode/h8300.h"
30 #include "safe-ctype.h"
33 const char comment_chars
[] = ";";
34 const char line_comment_chars
[] = "#";
36 const char line_separator_chars
[] = "!";
38 const char line_separator_chars
[] = "";
41 static void sbranch (int);
42 static void h8300hmode (int);
43 static void h8300smode (int);
44 static void h8300hnmode (int);
45 static void h8300snmode (int);
46 static void h8300sxmode (int);
47 static void h8300sxnmode (int);
48 static void pint (int);
55 static int default_mach
= bfd_mach_h8300
;
57 #define PSIZE (Hmode && !Nmode ? L_32 : L_16)
59 static int bsize
= L_8
; /* Default branch displacement. */
67 const struct h8_opcode
*opcode
;
70 static struct h8_instruction
*h8_instructions
;
73 h8300hmode (int arg ATTRIBUTE_UNUSED
)
77 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
78 as_warn (_("could not set architecture and machine"));
82 h8300smode (int arg ATTRIBUTE_UNUSED
)
86 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
87 as_warn (_("could not set architecture and machine"));
91 h8300hnmode (int arg ATTRIBUTE_UNUSED
)
96 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300hn
))
97 as_warn (_("could not set architecture and machine"));
101 h8300snmode (int arg ATTRIBUTE_UNUSED
)
106 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sn
))
107 as_warn (_("could not set architecture and machine"));
111 h8300sxmode (int arg ATTRIBUTE_UNUSED
)
116 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sx
))
117 as_warn (_("could not set architecture and machine"));
121 h8300sxnmode (int arg ATTRIBUTE_UNUSED
)
127 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sxn
))
128 as_warn (_("could not set architecture and machine"));
138 pint (int arg ATTRIBUTE_UNUSED
)
140 cons (Hmode
? 4 : 2);
143 /* Like obj_elf_section, but issues a warning for new
144 sections which do not have an attribute specification. */
147 h8300_elf_section (int push
)
149 static const char * known_data_sections
[] = { ".rodata", ".tdata", ".tbss" };
150 static const char * known_data_prefixes
[] = { ".debug", ".zdebug", ".gnu.warning" };
151 char * saved_ilp
= input_line_pointer
;
154 name
= obj_elf_section_name ();
158 if (* input_line_pointer
!= ','
159 && bfd_get_section_by_name (stdoutput
, name
) == NULL
)
163 /* Ignore this warning for well known data sections. */
164 for (i
= ARRAY_SIZE (known_data_sections
); i
--;)
165 if (strcmp (name
, known_data_sections
[i
]) == 0)
169 for (i
= ARRAY_SIZE (known_data_prefixes
); i
--;)
170 if (startswith (name
, known_data_prefixes
[i
]))
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},
211 {"section", h8300_elf_section
, 0},
212 {"section.s", h8300_elf_section
, 0},
213 {"sect", h8300_elf_section
, 0},
214 {"sect.s", h8300_elf_section
, 0},
219 const char EXP_CHARS
[] = "eE";
221 /* Chars that mean this number is a floating point constant
224 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
226 static htab_t opcode_hash_control
; /* Opcode mnemonics. */
228 /* This function is called once, at assembler startup time. This
229 should set up all the tables, etc. that the MD part of the assembler
235 unsigned int nopcodes
;
236 struct h8_opcode
*p
, *p1
;
237 struct h8_instruction
*pi
;
240 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, default_mach
))
241 as_warn (_("could not set architecture and machine"));
243 opcode_hash_control
= str_htab_create ();
245 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
247 h8_instructions
= XNEWVEC (struct h8_instruction
, nopcodes
);
249 pi
= h8_instructions
;
251 /* We do a minimum amount of sorting on the opcode table; this is to
252 make it easy to describe the mova instructions without unnecessary
254 Sorting only takes place inside blocks of instructions of the form
255 X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */
258 struct h8_opcode
*first_skipped
= 0;
260 const char *src
= p1
->name
;
265 /* Strip off any . part when inserting the opcode and only enter
266 unique codes into the hash table. */
267 dst
= buffer
= notes_alloc (strlen (src
) + 1);
276 cmplen
= src
- p1
->name
+ 1;
283 str_hash_insert (opcode_hash_control
, buffer
, pi
, 0);
286 for (p
= p1
; p
->name
; p
++)
288 /* A negative TIME is used to indicate that we've added this opcode
292 if (strncmp (p
->name
, buffer
, cmplen
) != 0
293 || (p
->name
[cmplen
] != '\0' && p
->name
[cmplen
] != '.'
294 && p
->name
[cmplen
- 1] != '/'))
296 if (first_skipped
== 0)
300 if (strncmp (p
->name
, buffer
, len
) != 0)
302 if (first_skipped
== 0)
308 pi
->size
= p
->name
[len
] == '.' ? p
->name
[len
+ 1] : 0;
311 /* Find the number of operands. */
313 while (pi
->noperands
< 3 && p
->args
.nib
[pi
->noperands
] != (op_type
) E
)
316 /* Find the length of the opcode in bytes. */
318 while (p
->data
.nib
[pi
->length
* 2] != (op_type
) E
)
327 /* Add entry for the NULL vector terminator. */
344 static void clever_message (const struct h8_instruction
*, struct h8_op
*);
345 static void fix_operand_size (struct h8_op
*, int);
346 static void build_bytes (const struct h8_instruction
*, struct h8_op
*);
347 static void do_a_fix_imm (int, int, struct h8_op
*, int, const struct h8_instruction
*);
348 static void check_operand (struct h8_op
*, unsigned int, const char *);
349 static const struct h8_instruction
* get_specific (const struct h8_instruction
*, struct h8_op
*, int) ;
350 static char *get_operands (unsigned, char *, struct h8_op
*);
351 static void get_operand (char **, struct h8_op
*, int);
352 static int parse_reg (char *, op_type
*, unsigned *, int);
353 static char *skip_colonthing (char *, int *);
354 static char *parse_exp (char *, struct h8_op
*);
356 static int constant_fits_size_p (struct h8_op
*, int, int);
360 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
369 /* Try to parse a reg name. Return the number of chars consumed. */
372 parse_reg (char *src
, op_type
*mode
, unsigned int *reg
, int direction
)
377 /* Cribbed from get_symbol_name. */
378 if (!is_name_beginner (*src
) || *src
== '\001')
381 while ((is_part_of_name (*end
) && *end
!= '.') || *end
== '\001')
385 if (len
== 2 && TOLOWER (src
[0]) == 's' && TOLOWER (src
[1]) == 'p')
387 *mode
= PSIZE
| REG
| direction
;
392 TOLOWER (src
[0]) == 'c' &&
393 TOLOWER (src
[1]) == 'c' &&
394 TOLOWER (src
[2]) == 'r')
401 TOLOWER (src
[0]) == 'e' &&
402 TOLOWER (src
[1]) == 'x' &&
403 TOLOWER (src
[2]) == 'r')
410 TOLOWER (src
[0]) == 'v' &&
411 TOLOWER (src
[1]) == 'b' &&
412 TOLOWER (src
[2]) == 'r')
419 TOLOWER (src
[0]) == 's' &&
420 TOLOWER (src
[1]) == 'b' &&
421 TOLOWER (src
[2]) == 'r')
427 if (len
== 2 && TOLOWER (src
[0]) == 'f' && TOLOWER (src
[1]) == 'p')
429 *mode
= PSIZE
| REG
| direction
;
433 if (len
== 3 && TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
434 src
[2] >= '0' && src
[2] <= '7')
436 *mode
= L_32
| REG
| direction
;
439 as_warn (_("Reg not valid for H8/300"));
442 if (len
== 2 && TOLOWER (src
[0]) == 'e' && src
[1] >= '0' && src
[1] <= '7')
444 *mode
= L_16
| REG
| direction
;
445 *reg
= src
[1] - '0' + 8;
447 as_warn (_("Reg not valid for H8/300"));
451 if (TOLOWER (src
[0]) == 'r')
453 if (src
[1] >= '0' && src
[1] <= '7')
455 if (len
== 3 && TOLOWER (src
[2]) == 'l')
457 *mode
= L_8
| REG
| direction
;
458 *reg
= (src
[1] - '0') + 8;
461 if (len
== 3 && TOLOWER (src
[2]) == 'h')
463 *mode
= L_8
| REG
| direction
;
464 *reg
= (src
[1] - '0');
469 *mode
= L_16
| REG
| direction
;
470 *reg
= (src
[1] - '0');
480 /* Parse an immediate or address-related constant and store it in OP.
481 If the user also specifies the operand's size, store that size
482 in OP->MODE, otherwise leave it for later code to decide. */
485 parse_exp (char *src
, struct h8_op
*op
)
489 save
= input_line_pointer
;
490 input_line_pointer
= src
;
491 expression (&op
->exp
);
492 if (op
->exp
.X_op
== O_absent
)
493 as_bad (_("missing operand"));
494 src
= input_line_pointer
;
495 input_line_pointer
= save
;
497 return skip_colonthing (src
, &op
->mode
);
501 /* If SRC starts with an explicit operand size, skip it and store the size
502 in *MODE. Leave *MODE unchanged otherwise. */
505 skip_colonthing (char *src
, int *mode
)
511 if (src
[0] == '8' && !ISDIGIT (src
[1]))
513 else if (src
[0] == '2' && !ISDIGIT (src
[1]))
515 else if (src
[0] == '3' && !ISDIGIT (src
[1]))
517 else if (src
[0] == '4' && !ISDIGIT (src
[1]))
519 else if (src
[0] == '5' && !ISDIGIT (src
[1]))
521 else if (src
[0] == '2' && src
[1] == '4' && !ISDIGIT (src
[2]))
523 else if (src
[0] == '3' && src
[1] == '2' && !ISDIGIT (src
[2]))
525 else if (src
[0] == '1' && src
[1] == '6' && !ISDIGIT (src
[2]))
528 as_bad (_("invalid operand size requested"));
530 while (ISDIGIT (*src
))
536 /* The many forms of operand:
539 @Rn Register indirect
540 @(exp[:16], Rn) Register indirect with displacement
544 @aa:16 absolute 16 bit
547 #xx[:size] immediate data
548 @(exp:[8], pc) pc rel
549 @@aa[:8] memory indirect. */
552 constant_fits_width_p (struct h8_op
*operand
, offsetT width
)
556 num
= ((operand
->exp
.X_add_number
& 0xffffffff) ^ 0x80000000) - 0x80000000;
557 return (num
& ~width
) == 0 || (num
| width
) == ~0;
561 constant_fits_size_p (struct h8_op
*operand
, int size
, int no_symbols
)
566 && (operand
->exp
.X_add_symbol
!= 0 || operand
->exp
.X_op_symbol
!= 0))
568 num
= operand
->exp
.X_add_number
& 0xffffffff;
572 return (num
& ~3) == 0;
574 return (num
& ~7) == 0;
576 return num
>= 1 && num
< 8;
578 return (num
& ~15) == 0;
580 return num
>= 1 && num
< 32;
582 num
= (num
^ 0x80000000) - 0x80000000;
583 return (num
& ~0xFF) == 0 || (num
| 0x7F) == ~0;
585 return (num
& ~0xFF) == 0;
587 num
= (num
^ 0x80000000) - 0x80000000;
588 return (num
& ~0xFFFF) == 0 || (num
| 0x7FFF) == ~0;
590 return (num
& ~0xFFFF) == 0;
599 get_operand (char **ptr
, struct h8_op
*op
, int direction
)
608 /* Check for '(' and ')' for instructions ldm and stm. */
609 if (src
[0] == '(' && src
[8] == ')')
612 /* Gross. Gross. ldm and stm have a format not easily handled
613 by get_operand. We deal with it explicitly here. */
614 if (TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
615 ISDIGIT (src
[2]) && src
[3] == '-' &&
616 TOLOWER (src
[4]) == 'e' && TOLOWER (src
[5]) == 'r' && ISDIGIT (src
[6]))
623 /* Check register pair's validity as per tech note TN-H8*-193A/E
624 from Renesas for H8S and H8SX hardware manual. */
625 if ( !(low
== 0 && (high
== 1 || high
== 2 || high
== 3))
626 && !(low
== 1 && (high
== 2 || high
== 3 || high
== 4) && SXmode
)
627 && !(low
== 2 && (high
== 3 || ((high
== 4 || high
== 5) && SXmode
)))
628 && !(low
== 3 && (high
== 4 || high
== 5 || high
== 6) && SXmode
)
629 && !(low
== 4 && (high
== 5 || high
== 6))
630 && !(low
== 4 && high
== 7 && SXmode
)
631 && !(low
== 5 && (high
== 6 || high
== 7) && SXmode
)
632 && !(low
== 6 && high
== 7 && SXmode
))
633 as_bad (_("Invalid register list for ldm/stm\n"));
635 /* Even sicker. We encode two registers into op->reg. One
636 for the low register to save, the other for the high
637 register to save; we also set the high bit in op->reg
638 so we know this is "very special". */
639 op
->reg
= 0x80000000 | (high
<< 8) | low
;
648 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
654 int size
= op
->mode
& SIZE
;
659 as_warn (_("mismatch between register and suffix"));
660 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
663 if (size
!= L_32
&& size
!= L_16
)
664 as_warn (_("mismatch between register and suffix"));
665 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
666 op
->mode
= (op
->mode
& ~SIZE
) | L_16
;
669 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
670 if (size
!= L_32
&& size
!= L_8
)
671 as_warn (_("mismatch between register and suffix"));
672 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
673 op
->mode
= (op
->mode
& ~SIZE
) | L_8
;
676 as_warn (_("invalid suffix after register."));
690 *ptr
= parse_exp (src
+ 1, op
);
691 if (op
->exp
.X_add_number
>= 0x100)
696 /* FIXME : 2? or 4? */
697 if (op
->exp
.X_add_number
>= 0x400)
698 as_bad (_("address too high for vector table jmp/jsr"));
699 else if (op
->exp
.X_add_number
>= 0x200)
704 op
->exp
.X_add_number
= op
->exp
.X_add_number
/ divisor
- 0x80;
711 if (*src
== '-' || *src
== '+')
713 len
= parse_reg (src
+ 1, &mode
, &num
, direction
);
716 /* Oops, not a reg after all, must be ordinary exp. */
717 op
->mode
= ABS
| direction
;
718 *ptr
= parse_exp (src
, op
);
722 if (((mode
& SIZE
) != PSIZE
)
723 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
724 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
725 as_bad (_("Wrong size pointer register for architecture."));
727 op
->mode
= src
[0] == '-' ? RDPREDEC
: RDPREINC
;
729 *ptr
= src
+ 1 + len
;
736 /* See if this is @(ERn.x, PC). */
737 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
738 if (len
!= 0 && (mode
& MODE
) == REG
&& src
[len
] == '.')
740 switch (TOLOWER (src
[len
+ 1]))
743 mode
= PCIDXB
| direction
;
746 mode
= PCIDXW
| direction
;
749 mode
= PCIDXL
| direction
;
756 && src
[len
+ 2] == ','
757 && TOLOWER (src
[len
+ 3]) != 'p'
758 && TOLOWER (src
[len
+ 4]) != 'c'
759 && src
[len
+ 5] != ')')
761 *ptr
= src
+ len
+ 6;
765 /* Fall through into disp case - the grammar is somewhat
766 ambiguous, so we should try whether it's a DISP operand
767 after all ("ER3.L" might be a poorly named label...). */
772 /* Start off assuming a 16 bit offset. */
774 src
= parse_exp (src
, op
);
777 op
->mode
|= ABS
| direction
;
784 as_bad (_("expected @(exp, reg16)"));
789 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
790 if (len
== 0 || (mode
& MODE
) != REG
)
792 as_bad (_("expected @(exp, reg16)"));
798 switch (TOLOWER (src
[1]))
801 op
->mode
|= INDEXB
| direction
;
804 op
->mode
|= INDEXW
| direction
;
807 op
->mode
|= INDEXL
| direction
;
810 as_bad (_("expected .L, .W or .B for register in indexed addressing mode"));
816 op
->mode
|= DISP
| direction
;
817 src
= skip_colonthing (src
, &op
->mode
);
821 as_bad (_("expected @(exp, reg16)"));
827 len
= parse_reg (src
, &mode
, &num
, direction
);
832 if (*src
== '+' || *src
== '-')
834 if (((mode
& SIZE
) != PSIZE
)
835 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
836 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
837 as_bad (_("Wrong size pointer register for architecture."));
838 op
->mode
= *src
== '+' ? RSPOSTINC
: RSPOSTDEC
;
844 if (((mode
& SIZE
) != PSIZE
)
845 /* For Normal mode accept 16 bit and 32 bit pointer registers. */
846 && (!Nmode
|| ((mode
& SIZE
) != L_32
)))
847 as_bad (_("Wrong size pointer register for architecture."));
849 op
->mode
= direction
| IND
| PSIZE
;
857 /* must be a symbol */
859 op
->mode
= ABS
| direction
;
860 *ptr
= parse_exp (src
, op
);
868 *ptr
= parse_exp (src
+ 1, op
);
871 else if (startswith (src
, "mach") ||
872 startswith (src
, "macl") ||
873 startswith (src
, "MACH") ||
874 startswith (src
, "MACL"))
876 op
->reg
= TOLOWER (src
[3]) == 'l';
884 *ptr
= parse_exp (src
, op
);
889 get_operands (unsigned int noperands
, char *op_end
, struct h8_op
*operand
)
900 get_operand (&ptr
, operand
+ 0, SRC
);
904 get_operand (&ptr
, operand
+ 1, DST
);
910 get_operand (&ptr
, operand
+ 0, SRC
);
913 get_operand (&ptr
, operand
+ 1, DST
);
918 get_operand (&ptr
, operand
+ 0, SRC
);
921 get_operand (&ptr
, operand
+ 1, DST
);
924 get_operand (&ptr
, operand
+ 2, OP3
);
934 /* MOVA has special requirements. Rather than adding twice the amount of
935 addressing modes, we simply special case it a bit. */
937 get_mova_operands (char *op_end
, struct h8_op
*operand
)
941 if (ptr
[1] != '@' || ptr
[2] != '(')
945 ptr
= parse_exp (ptr
, &operand
[0]);
950 get_operand (&ptr
, operand
+ 1, DST
);
958 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
961 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
964 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
970 else if ((operand
[1].mode
& MODE
) == LOWREG
)
972 switch (operand
[1].mode
& SIZE
)
975 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
978 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
981 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
990 if (*ptr
++ != ')' || *ptr
++ != ',')
992 get_operand (&ptr
, operand
+ 2, OP3
);
993 /* See if we can use the short form of MOVA. */
994 if (((operand
[1].mode
& MODE
) == REG
|| (operand
[1].mode
& MODE
) == LOWREG
)
995 && (operand
[2].mode
& MODE
) == REG
996 && (operand
[1].reg
& 7) == (operand
[2].reg
& 7))
998 operand
[1].mode
= operand
[2].mode
= 0;
999 operand
[0].reg
= operand
[2].reg
& 7;
1004 as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
1008 get_rtsl_operands (char *ptr
, struct h8_op
*operand
)
1010 int mode
, len
, type
= 0;
1011 unsigned int num
, num2
;
1019 len
= parse_reg (ptr
, &mode
, &num
, SRC
);
1020 if (len
== 0 || (mode
& MODE
) != REG
)
1022 as_bad (_("expected register"));
1028 len
= parse_reg (++ptr
, &mode
, &num2
, SRC
);
1029 if (len
== 0 || (mode
& MODE
) != REG
)
1031 as_bad (_("expected register"));
1035 /* CONST_xxx are used as placeholders in the opcode table. */
1039 as_bad (_("invalid register list"));
1044 num2
= num
, num
= 0;
1045 if (type
== 1 && *ptr
++ != ')')
1047 as_bad (_("expected closing paren"));
1050 operand
[0].mode
= RS32
;
1051 operand
[1].mode
= RD32
;
1052 operand
[0].reg
= num
;
1053 operand
[1].reg
= num2
;
1056 /* Passed a pointer to a list of opcodes which use different
1057 addressing modes, return the opcode which matches the opcodes
1060 static const struct h8_instruction
*
1061 get_specific (const struct h8_instruction
*instruction
,
1062 struct h8_op
*operands
, int size
)
1064 const struct h8_instruction
*this_try
= instruction
;
1065 const struct h8_instruction
*found_other
= 0, *found_mismatched
= 0;
1067 int this_index
= instruction
->idx
;
1070 /* There's only one ldm/stm and it's easier to just
1071 get out quick for them. */
1072 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
1073 || OP_KIND (instruction
->opcode
->how
) == O_STM
)
1076 while (noperands
< 3 && operands
[noperands
].mode
!= 0)
1079 while (this_index
== instruction
->idx
&& !found
)
1084 this_try
= instruction
++;
1085 this_size
= this_try
->opcode
->how
& SN
;
1087 if (this_try
->noperands
!= noperands
)
1089 else if (this_try
->noperands
> 0)
1093 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
1095 op_type op
= this_try
->opcode
->args
.nib
[i
];
1096 int op_mode
= op
& MODE
;
1097 int op_size
= op
& SIZE
;
1098 int x
= operands
[i
].mode
;
1099 int x_mode
= x
& MODE
;
1100 int x_size
= x
& SIZE
;
1102 if (op_mode
== LOWREG
&& (x_mode
== REG
|| x_mode
== LOWREG
))
1104 if ((x_size
== L_8
&& (operands
[i
].reg
& 8) == 0)
1105 || (x_size
== L_16
&& (operands
[i
].reg
& 8) == 8))
1106 as_warn (_("can't use high part of register in operand %d"), i
);
1108 if (x_size
!= op_size
)
1111 else if (op_mode
== REG
)
1113 if (x_mode
== LOWREG
)
1119 x_size
= (Hmode
? L_32
: L_16
);
1121 op_size
= (Hmode
? L_32
: L_16
);
1123 /* The size of the reg is v important. */
1124 if (op_size
!= x_size
)
1127 else if (op_mode
& CTRL
) /* control register */
1129 if (!(x_mode
& CTRL
))
1135 if (op_mode
!= CCR
&&
1136 op_mode
!= CCR_EXR
&&
1137 op_mode
!= CC_EX_VB_SB
)
1141 if (op_mode
!= EXR
&&
1142 op_mode
!= CCR_EXR
&&
1143 op_mode
!= CC_EX_VB_SB
)
1147 if (op_mode
!= MACH
&&
1152 if (op_mode
!= MACL
&&
1157 if (op_mode
!= VBR
&&
1158 op_mode
!= VBR_SBR
&&
1159 op_mode
!= CC_EX_VB_SB
)
1163 if (op_mode
!= SBR
&&
1164 op_mode
!= VBR_SBR
&&
1165 op_mode
!= CC_EX_VB_SB
)
1170 else if ((op
& ABSJMP
) && (x_mode
== ABS
|| x_mode
== PCREL
))
1172 operands
[i
].mode
&= ~MODE
;
1173 operands
[i
].mode
|= ABSJMP
;
1174 /* But it may not be 24 bits long. */
1175 if (x_mode
== ABS
&& !Hmode
)
1177 operands
[i
].mode
&= ~SIZE
;
1178 operands
[i
].mode
|= L_16
;
1180 if ((operands
[i
].mode
& SIZE
) == L_32
1181 && (op_mode
& SIZE
) != L_32
)
1184 else if (x_mode
== IMM
&& op_mode
!= IMM
)
1186 offsetT num
= operands
[i
].exp
.X_add_number
& 0xffffffff;
1187 if (op_mode
== KBIT
|| op_mode
== DBIT
)
1188 /* This is ok if the immediate value is sensible. */;
1189 else if (op_mode
== CONST_2
)
1191 else if (op_mode
== CONST_4
)
1193 else if (op_mode
== CONST_8
)
1195 else if (op_mode
== CONST_16
)
1200 else if (op_mode
== PCREL
&& op_mode
== x_mode
)
1202 /* movsd, bsr/bc and bsr/bs only come in PCREL16 flavour:
1203 If x_size is L_8, promote it. */
1204 if (OP_KIND (this_try
->opcode
->how
) == O_MOVSD
1205 || OP_KIND (this_try
->opcode
->how
) == O_BSRBC
1206 || OP_KIND (this_try
->opcode
->how
) == O_BSRBS
)
1210 /* The size of the displacement is important. */
1211 if (op_size
!= x_size
)
1214 else if ((op_mode
== DISP
|| op_mode
== IMM
|| op_mode
== ABS
1215 || op_mode
== INDEXB
|| op_mode
== INDEXW
1216 || op_mode
== INDEXL
)
1217 && op_mode
== x_mode
)
1219 /* Promote a L_24 to L_32 if it makes us match. */
1220 if (x_size
== L_24
&& op_size
== L_32
)
1226 if (((x_size
== L_16
&& op_size
== L_16U
)
1227 || (x_size
== L_8
&& op_size
== L_8U
)
1228 || (x_size
== L_3
&& op_size
== L_3NZ
))
1229 /* We're deliberately more permissive for ABS modes. */
1231 || constant_fits_size_p (operands
+ i
, op_size
,
1235 if (x_size
!= 0 && op_size
!= x_size
)
1237 else if (x_size
== 0
1238 && ! constant_fits_size_p (operands
+ i
, op_size
,
1242 else if (op_mode
!= x_mode
)
1250 if ((this_try
->opcode
->available
== AV_H8SX
&& ! SXmode
)
1251 || (this_try
->opcode
->available
== AV_H8S
&& ! Smode
)
1252 || (this_try
->opcode
->available
== AV_H8H
&& ! Hmode
))
1253 found
= 0, found_other
= this_try
;
1254 else if (this_size
!= size
&& (this_size
!= SN
&& size
!= SN
))
1255 found_mismatched
= this_try
, found
= 0;
1263 as_warn (_("Opcode `%s' with these operand types not available in %s mode"),
1264 found_other
->opcode
->name
,
1265 (! Hmode
&& ! Smode
? "H8/300"
1270 else if (found_mismatched
)
1272 as_warn (_("mismatch between opcode size and operand size"));
1273 return found_mismatched
;
1279 check_operand (struct h8_op
*operand
, unsigned int width
, const char *string
)
1281 if (operand
->exp
.X_add_symbol
== 0
1282 && operand
->exp
.X_op_symbol
== 0)
1284 /* No symbol involved, let's look at offset, it's dangerous if
1285 any of the high bits are not 0 or ff's, find out by oring or
1286 anding with the width and seeing if the answer is 0 or all
1289 if (! constant_fits_width_p (operand
, width
))
1292 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
1294 /* Just ignore this one - which happens when trying to
1295 fit a 16 bit address truncated into an 8 bit address
1296 of something like bset. */
1298 else if (strcmp (string
, "@") == 0
1300 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
1302 /* Just ignore this one - which happens when trying to
1303 fit a 24 bit address truncated into a 16 bit address
1304 of something like mov.w. */
1308 as_warn (_("operand %s0x%lx out of range."), string
,
1309 (unsigned long) operand
->exp
.X_add_number
);
1315 /* RELAXMODE has one of 3 values:
1317 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
1319 1 Output a relaxable 24bit absolute mov.w address relocation
1320 (may relax into a 16bit absolute address).
1322 2 Output a relaxable 16/24 absolute mov.b address relocation
1323 (may relax into an 8bit absolute address). */
1326 do_a_fix_imm (int offset
, int nibble
, struct h8_op
*operand
, int relaxmode
, const struct h8_instruction
*this_try
)
1331 char *bytes
= frag_now
->fr_literal
+ offset
;
1333 const char *t
= ((operand
->mode
& MODE
) == IMM
) ? "#" : "@";
1335 if (operand
->exp
.X_add_symbol
== 0)
1337 switch (operand
->mode
& SIZE
)
1340 check_operand (operand
, 0x3, t
);
1341 bytes
[0] |= (operand
->exp
.X_add_number
& 3) << (nibble
? 0 : 4);
1345 check_operand (operand
, 0x7, t
);
1346 bytes
[0] |= (operand
->exp
.X_add_number
& 7) << (nibble
? 0 : 4);
1349 check_operand (operand
, 0xF, t
);
1350 bytes
[0] |= (operand
->exp
.X_add_number
& 15) << (nibble
? 0 : 4);
1353 check_operand (operand
, 0x1F, t
);
1354 bytes
[0] |= operand
->exp
.X_add_number
& 31;
1358 check_operand (operand
, 0xff, t
);
1359 bytes
[0] |= operand
->exp
.X_add_number
;
1363 check_operand (operand
, 0xffff, t
);
1364 bytes
[0] |= operand
->exp
.X_add_number
>> 8;
1365 bytes
[1] |= operand
->exp
.X_add_number
>> 0;
1366 /* MOVA needs both relocs to relax the second operand properly. */
1368 && (OP_KIND(this_try
->opcode
->how
) == O_MOVAB
1369 || OP_KIND(this_try
->opcode
->how
) == O_MOVAW
1370 || OP_KIND(this_try
->opcode
->how
) == O_MOVAL
))
1373 fix_new_exp (frag_now
, offset
, 2, &operand
->exp
, 0, idx
);
1377 check_operand (operand
, 0xffffff, t
);
1378 bytes
[0] |= operand
->exp
.X_add_number
>> 16;
1379 bytes
[1] |= operand
->exp
.X_add_number
>> 8;
1380 bytes
[2] |= operand
->exp
.X_add_number
>> 0;
1384 /* This should be done with bfd. */
1385 bytes
[0] |= operand
->exp
.X_add_number
>> 24;
1386 bytes
[1] |= operand
->exp
.X_add_number
>> 16;
1387 bytes
[2] |= operand
->exp
.X_add_number
>> 8;
1388 bytes
[3] |= operand
->exp
.X_add_number
>> 0;
1391 if ((operand
->mode
& MODE
) == DISP
&& relaxmode
== 1)
1392 idx
= BFD_RELOC_H8_DISP32A16
;
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;
1408 if ((operand
->mode
& MODE
) == DISP
&& relaxmode
== 1)
1409 idx
= BFD_RELOC_H8_DISP32A16
;
1410 else if (relaxmode
== 2)
1412 else if (relaxmode
== 1)
1418 as_bad (_("Can't work out size of operand.\n"));
1428 operand
->exp
.X_add_number
=
1429 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1430 operand
->exp
.X_add_number
|= (bytes
[0] << 8) | bytes
[1];
1436 operand
->exp
.X_add_number
=
1437 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1438 operand
->exp
.X_add_number
|= bytes
[0];
1441 fix_new_exp (frag_now
,
1450 /* Now we know what sort of opcodes it is, let's build the bytes. */
1453 build_bytes (const struct h8_instruction
*this_try
, struct h8_op
*operand
)
1456 char *output
= frag_more (this_try
->length
);
1457 const op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1459 unsigned int nibble_count
= 0;
1463 char asnibbles
[100];
1464 char *p
= asnibbles
;
1467 if (!Hmode
&& this_try
->opcode
->available
!= AV_H8
)
1468 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1469 this_try
->opcode
->name
);
1471 && this_try
->opcode
->available
!= AV_H8
1472 && this_try
->opcode
->available
!= AV_H8H
)
1473 as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"),
1474 this_try
->opcode
->name
);
1476 && this_try
->opcode
->available
!= AV_H8
1477 && this_try
->opcode
->available
!= AV_H8H
1478 && this_try
->opcode
->available
!= AV_H8S
)
1479 as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"),
1480 this_try
->opcode
->name
);
1482 while (*nibble_ptr
!= (op_type
) E
)
1489 d
= (c
& OP3
) == OP3
? 2 : (c
& DST
) == DST
? 1 : 0;
1497 if (c2
== REG
|| c2
== LOWREG
1498 || c2
== IND
|| c2
== PREINC
|| c2
== PREDEC
1499 || c2
== POSTINC
|| c2
== POSTDEC
)
1501 nib
= operand
[d
].reg
;
1506 else if (c
& CTRL
) /* Control reg operand. */
1507 nib
= operand
[d
].reg
;
1509 else if ((c
& DISPREG
) == (DISPREG
))
1511 nib
= operand
[d
].reg
;
1515 operand
[d
].mode
= c
;
1516 op_at
[d
] = nibble_count
;
1519 else if (c2
== IMM
|| c2
== PCREL
|| c2
== ABS
1520 || (c
& ABSJMP
) || c2
== DISP
)
1522 operand
[d
].mode
= c
;
1523 op_at
[d
] = nibble_count
;
1526 else if ((c
& IGNORE
) || (c
& DATA
))
1529 else if (c2
== DBIT
)
1531 switch (operand
[0].exp
.X_add_number
)
1540 as_bad (_("Need #1 or #2 here"));
1543 else if (c2
== KBIT
)
1545 switch (operand
[0].exp
.X_add_number
)
1555 as_warn (_("#4 not valid on H8/300."));
1560 as_bad (_("Need #1 or #2 here"));
1563 /* Stop it making a fix. */
1564 operand
[0].mode
= 0;
1568 operand
[d
].mode
|= MEMRELAX
;
1584 if (operand
[0].mode
== MACREG
)
1585 /* stmac has mac[hl] as the first operand. */
1586 nib
= 2 + operand
[0].reg
;
1588 /* ldmac has mac[hl] as the second operand. */
1589 nib
= 2 + operand
[1].reg
;
1597 /* Disgusting. Why, oh why didn't someone ask us for advice
1598 on the assembler format. */
1599 if (OP_KIND (this_try
->opcode
->how
) == O_LDM
)
1601 high
= (operand
[1].reg
>> 8) & 0xf;
1602 low
= (operand
[1].reg
) & 0xf;
1603 asnibbles
[2] = high
- low
;
1604 asnibbles
[7] = high
;
1606 else if (OP_KIND (this_try
->opcode
->how
) == O_STM
)
1608 high
= (operand
[0].reg
>> 8) & 0xf;
1609 low
= (operand
[0].reg
) & 0xf;
1610 asnibbles
[2] = high
- low
;
1614 for (i
= 0; i
< this_try
->length
; i
++)
1615 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1617 /* Note if this is a mov.b or a bit manipulation instruction
1618 there is a special relaxation which only applies. */
1619 if ( this_try
->opcode
->how
== O (O_MOV
, SB
)
1620 || this_try
->opcode
->how
== O (O_BCLR
, SB
)
1621 || this_try
->opcode
->how
== O (O_BAND
, SB
)
1622 || this_try
->opcode
->how
== O (O_BIAND
, SB
)
1623 || this_try
->opcode
->how
== O (O_BILD
, SB
)
1624 || this_try
->opcode
->how
== O (O_BIOR
, SB
)
1625 || this_try
->opcode
->how
== O (O_BIST
, SB
)
1626 || this_try
->opcode
->how
== O (O_BIXOR
, SB
)
1627 || this_try
->opcode
->how
== O (O_BLD
, SB
)
1628 || this_try
->opcode
->how
== O (O_BNOT
, SB
)
1629 || this_try
->opcode
->how
== O (O_BOR
, SB
)
1630 || this_try
->opcode
->how
== O (O_BSET
, SB
)
1631 || this_try
->opcode
->how
== O (O_BST
, SB
)
1632 || this_try
->opcode
->how
== O (O_BTST
, SB
)
1633 || this_try
->opcode
->how
== O (O_BXOR
, SB
))
1636 /* Output any fixes. */
1637 for (i
= 0; i
< this_try
->noperands
; i
++)
1639 int x
= operand
[i
].mode
;
1640 int x_mode
= x
& MODE
;
1642 if (x_mode
== IMM
|| x_mode
== DISP
)
1643 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1644 op_at
[i
] & 1, operand
+ i
, (x
& MEMRELAX
) != 0,
1646 else if (x_mode
== ABS
)
1647 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1648 op_at
[i
] & 1, operand
+ i
,
1649 (x
& MEMRELAX
) ? movb
+ 1 : 0,
1652 else if (x_mode
== PCREL
)
1654 int size16
= (x
& SIZE
) == L_16
;
1655 int size
= size16
? 2 : 1;
1656 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1659 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1661 if (operand
[i
].exp
.X_add_number
& 1)
1662 as_warn (_("branch operand has odd offset (%lx)\n"),
1663 (unsigned long) operand
->exp
.X_add_number
);
1666 operand
[i
].exp
.X_add_number
=
1667 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1671 operand
[i
].exp
.X_add_number
=
1672 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1677 operand
[i
].exp
.X_add_number
|= output
[op_at
[i
] / 2];
1679 fixP
= fix_new_exp (frag_now
,
1680 output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1685 fixP
->fx_signed
= 1;
1687 else if (x_mode
== MEMIND
)
1689 check_operand (operand
+ i
, 0xff, "@@");
1690 fix_new_exp (frag_now
,
1691 output
- frag_now
->fr_literal
+ 1,
1697 else if (x_mode
== VECIND
)
1699 check_operand (operand
+ i
, 0x7f, "@@");
1700 /* FIXME: approximating the effect of "B31" here...
1701 This is very hackish, and ought to be done a better way. */
1702 operand
[i
].exp
.X_add_number
|= 0x80;
1703 fix_new_exp (frag_now
,
1704 output
- frag_now
->fr_literal
+ 1,
1710 else if (x
& ABSJMP
)
1713 bfd_reloc_code_real_type reloc_type
= R_JMPL1
;
1715 /* To be compatible with the proposed H8 ELF format, we
1716 want the relocation's offset to point to the first byte
1717 that will be modified, not to the start of the instruction. */
1719 if ((operand
->mode
& SIZE
) == L_32
)
1722 reloc_type
= R_RELLONG
;
1727 /* This jmp may be a jump or a branch. */
1729 check_operand (operand
+ i
,
1730 SXmode
? 0xffffffff : Hmode
? 0xffffff : 0xffff,
1733 if (operand
[i
].exp
.X_add_number
& 1)
1734 as_warn (_("branch operand has odd offset (%lx)\n"),
1735 (unsigned long) operand
->exp
.X_add_number
);
1738 operand
[i
].exp
.X_add_number
=
1739 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1740 fix_new_exp (frag_now
,
1741 output
- frag_now
->fr_literal
+ where
,
1750 /* Try to give an intelligent error message for common and simple to
1754 clever_message (const struct h8_instruction
*instruction
,
1755 struct h8_op
*operand
)
1757 /* Find out if there was more than one possible opcode. */
1759 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1763 /* Only one opcode of this flavour, try to guess which operand
1765 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1767 switch (instruction
->opcode
->args
.nib
[argn
])
1770 if (operand
[argn
].mode
!= RD16
)
1772 as_bad (_("destination operand must be 16 bit register"));
1779 if (operand
[argn
].mode
!= RS8
)
1781 as_bad (_("source operand must be 8 bit register"));
1787 if (operand
[argn
].mode
!= ABS16DST
)
1789 as_bad (_("destination operand must be 16bit absolute address"));
1794 if (operand
[argn
].mode
!= RD8
)
1796 as_bad (_("destination operand must be 8 bit register"));
1802 if (operand
[argn
].mode
!= ABS16SRC
)
1804 as_bad (_("source operand must be 16bit absolute address"));
1812 as_bad (_("invalid operands"));
1816 /* If OPERAND is part of an address, adjust its size and value given
1817 that it addresses SIZE bytes.
1819 This function decides how big non-immediate constants are when no
1820 size was explicitly given. It also scales down the assembly-level
1821 displacement in an @(d:2,ERn) operand. */
1824 fix_operand_size (struct h8_op
*operand
, int size
)
1826 if (SXmode
&& (operand
->mode
& MODE
) == DISP
)
1828 /* If the user didn't specify an operand width, see if we
1829 can use @(d:2,ERn). */
1830 if ((operand
->mode
& SIZE
) == 0
1831 && operand
->exp
.X_add_symbol
== 0
1832 && operand
->exp
.X_op_symbol
== 0
1833 && (operand
->exp
.X_add_number
== size
1834 || operand
->exp
.X_add_number
== size
* 2
1835 || operand
->exp
.X_add_number
== size
* 3))
1836 operand
->mode
|= L_2
;
1838 /* Scale down the displacement in an @(d:2,ERn) operand.
1839 X_add_number then contains the desired field value. */
1840 if ((operand
->mode
& SIZE
) == L_2
)
1842 if (operand
->exp
.X_add_number
% size
!= 0)
1843 as_warn (_("operand/size mis-match"));
1844 operand
->exp
.X_add_number
/= size
;
1848 if ((operand
->mode
& SIZE
) == 0)
1849 switch (operand
->mode
& MODE
)
1856 /* Pick a 24-bit address unless we know that a 16-bit address
1857 is safe. get_specific() will relax L_24 into L_32 where
1861 && ((((addressT
) operand
->exp
.X_add_number
+ 0x8000)
1862 & 0xffffffff) > 0xffff
1863 || operand
->exp
.X_add_symbol
!= 0
1864 || operand
->exp
.X_op_symbol
!= 0))
1865 operand
->mode
|= L_24
;
1867 operand
->mode
|= L_16
;
1871 if ((((addressT
) operand
->exp
.X_add_number
+ 0x80)
1872 & 0xffffffff) <= 0xff)
1874 if (operand
->exp
.X_add_symbol
!= NULL
)
1875 operand
->mode
|= bsize
;
1877 operand
->mode
|= L_8
;
1880 operand
->mode
|= L_16
;
1886 /* This is the guts of the machine-dependent assembler. STR points to
1887 a machine dependent instruction. This function is supposed to emit
1888 the frags/bytes it assembles. */
1891 md_assemble (char *str
)
1895 struct h8_op operand
[3];
1896 const struct h8_instruction
*instruction
;
1897 const struct h8_instruction
*prev_instruction
;
1904 /* Drop leading whitespace. */
1908 /* Find the op code end. */
1909 for (op_start
= op_end
= str
;
1910 *op_end
!= 0 && *op_end
!= ' ';
1920 else if (*op_end
== '/' && ! slash
)
1924 if (op_end
== op_start
)
1926 as_bad (_("can't find opcode "));
1932 /* The assembler stops scanning the opcode at slashes, so it fails
1933 to make characters following them lower case. Fix them. */
1936 *slash
= TOLOWER (*slash
);
1938 instruction
= (const struct h8_instruction
*)
1939 str_hash_find (opcode_hash_control
, op_start
);
1941 if (instruction
== NULL
)
1943 as_bad (_("unknown opcode"));
1947 /* We used to set input_line_pointer to the result of get_operands,
1948 but that is wrong. Our caller assumes we don't change it. */
1950 operand
[0].mode
= 0;
1951 operand
[1].mode
= 0;
1952 operand
[2].mode
= 0;
1954 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
1955 || OP_KIND (instruction
->opcode
->how
) == O_MOVAW
1956 || OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
1957 get_mova_operands (op_end
, operand
);
1958 else if (OP_KIND (instruction
->opcode
->how
) == O_RTEL
1959 || OP_KIND (instruction
->opcode
->how
) == O_RTSL
)
1960 get_rtsl_operands (op_end
, operand
);
1962 get_operands (instruction
->noperands
, op_end
, operand
);
1965 prev_instruction
= instruction
;
1967 /* Now we have operands from instruction.
1968 Let's check them out for ldm and stm. */
1969 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
)
1971 /* The first operand must be @er7+, and the
1972 second operand must be a register pair. */
1973 if ((operand
[0].mode
!= RSINC
)
1974 || (operand
[0].reg
!= 7)
1975 || ((operand
[1].reg
& 0x80000000) == 0))
1976 as_bad (_("invalid operand in ldm"));
1978 else if (OP_KIND (instruction
->opcode
->how
) == O_STM
)
1980 /* The first operand must be a register pair,
1981 and the second operand must be @-er7. */
1982 if (((operand
[0].reg
& 0x80000000) == 0)
1983 || (operand
[1].mode
!= RDDEC
)
1984 || (operand
[1].reg
!= 7))
1985 as_bad (_("invalid operand in stm"));
1991 switch (TOLOWER (*dot
))
2006 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
||
2007 OP_KIND (instruction
->opcode
->how
) == O_MOVAW
||
2008 OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
2010 switch (operand
[0].mode
& MODE
)
2014 fix_operand_size (&operand
[1], 1);
2017 fix_operand_size (&operand
[1], 2);
2020 fix_operand_size (&operand
[1], 4);
2026 for (i
= 0; i
< 3 && operand
[i
].mode
!= 0; i
++)
2032 fix_operand_size (&operand
[i
], 1);
2035 fix_operand_size (&operand
[i
], 2);
2038 fix_operand_size (&operand
[i
], 4);
2043 instruction
= get_specific (instruction
, operand
, size
);
2045 if (instruction
== 0)
2047 /* Couldn't find an opcode which matched the operands. */
2048 char *where
= frag_more (2);
2052 clever_message (prev_instruction
, operand
);
2057 build_bytes (instruction
, operand
);
2059 dwarf2_emit_insn (instruction
->length
);
2063 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2068 /* Various routines to kill one day. */
2071 md_atof (int type
, char *litP
, int *sizeP
)
2073 return ieee_md_atof (type
, litP
, sizeP
, true);
2076 #define OPTION_H_TICK_HEX (OPTION_MD_BASE)
2077 #define OPTION_MACH (OPTION_MD_BASE+1)
2079 const char *md_shortopts
= "";
2080 struct option md_longopts
[] =
2082 { "h-tick-hex", no_argument
, NULL
, OPTION_H_TICK_HEX
},
2083 { "mach", required_argument
, NULL
, OPTION_MACH
},
2084 {NULL
, no_argument
, NULL
, 0}
2087 size_t md_longopts_size
= sizeof (md_longopts
);
2092 void (*func
) (void);
2102 default_mach
= bfd_mach_h8300h
;
2112 default_mach
= bfd_mach_h8300hn
;
2122 default_mach
= bfd_mach_h8300s
;
2132 default_mach
= bfd_mach_h8300sn
;
2142 default_mach
= bfd_mach_h8300sx
;
2146 mach_h8300sxn (void)
2152 default_mach
= bfd_mach_h8300sxn
;
2155 const struct mach_func mach_table
[] =
2157 {"h8300h", mach_h8300h
},
2158 {"h8300hn", mach_h8300hn
},
2159 {"h8300s", mach_h8300s
},
2160 {"h8300sn", mach_h8300sn
},
2161 {"h8300sx", mach_h8300sx
},
2162 {"h8300sxn", mach_h8300sxn
}
2166 md_parse_option (int c ATTRIBUTE_UNUSED
, const char *arg ATTRIBUTE_UNUSED
)
2171 case OPTION_H_TICK_HEX
:
2172 enable_h_tick_hex
= 1;
2175 for (i
= 0; i
< sizeof(mach_table
) / sizeof(struct mach_func
); i
++)
2177 if (strcasecmp (arg
, mach_table
[i
].name
) == 0)
2179 mach_table
[i
].func();
2183 if (i
>= sizeof(mach_table
) / sizeof(struct mach_func
))
2184 as_bad (_("Invalid argument to --mach option: %s"), arg
);
2193 md_show_usage (FILE *stream
)
2195 fprintf (stream
, _(" H8300-specific assembler options:\n"));
2196 fprintf (stream
, _("\
2197 -mach=<name> Set the H8300 machine type to one of:\n\
2198 h8300h, h8300hn, h8300s, h8300sn, h8300sx, h8300sxn\n"));
2199 fprintf (stream
, _("\
2200 -h-tick-hex Support H'00 style hex constants\n"));
2203 void tc_aout_fix_to_chars (void);
2206 tc_aout_fix_to_chars (void)
2208 printf (_("call to tc_aout_fix_to_chars \n"));
2213 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
,
2214 segT seg ATTRIBUTE_UNUSED
,
2215 fragS
*fragP ATTRIBUTE_UNUSED
)
2217 printf (_("call to md_convert_frag \n"));
2222 md_section_align (segT segment
, valueT size
)
2224 int align
= bfd_section_alignment (segment
);
2225 return ((size
+ (1 << align
) - 1) & (-1U << align
));
2229 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
2231 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2234 switch (fixP
->fx_size
)
2240 *buf
++ = (val
>> 8);
2244 *buf
++ = (val
>> 24);
2245 *buf
++ = (val
>> 16);
2246 *buf
++ = (val
>> 8);
2250 /* This can arise when the .quad or .8byte pseudo-ops are used.
2251 Returning here (without setting fx_done) will cause the code
2252 to attempt to generate a reloc which will then fail with the
2253 slightly more helpful error message: "Cannot represent
2254 relocation type BFD_RELOC_64". */
2260 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
2265 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
2266 segT segment_type ATTRIBUTE_UNUSED
)
2268 printf (_("call to md_estimate_size_before_relax \n"));
2272 /* Put number into target byte order. */
2274 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
2276 number_to_chars_bigendian (ptr
, use
, nbytes
);
2280 md_pcrel_from (fixS
*fixp
)
2282 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2283 _("Unexpected reference to a symbol in a non-code section"));
2288 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
2291 bfd_reloc_code_real_type r_type
;
2293 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2295 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2296 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2298 as_bad_subtract (fixp
);
2303 rel
= XNEW (arelent
);
2304 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
2305 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2306 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2307 rel
->addend
= fixp
->fx_offset
;
2309 r_type
= fixp
->fx_r_type
;
2313 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
2316 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
2317 if (rel
->howto
== NULL
)
2319 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2320 _("Cannot represent relocation type %s"),
2321 bfd_get_reloc_code_name (r_type
));