1 /* tc-mn10200.c -- Assembler code for the Matsushita 10200
3 Copyright (C) 1996, 1997 Free Software Foundation.
5 This file is part of GAS, the GNU Assembler.
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)
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.
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
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "opcode/mn10200.h"
28 /* Structure to hold information about predefined registers. */
35 /* Generic assembler global variables which must be defined by all targets. */
37 /* Characters which always start a comment. */
38 const char comment_chars
[] = "#";
40 /* Characters which start a comment at the beginning of a line. */
41 const char line_comment_chars
[] = ";#";
43 /* Characters which may be used to separate multiple commands on a
45 const char line_separator_chars
[] = ";";
47 /* Characters which are used to indicate an exponent in a floating
49 const char EXP_CHARS
[] = "eE";
51 /* Characters which mean that a number is a floating point constant,
53 const char FLT_CHARS
[] = "dD";
56 const relax_typeS md_relax_table
[] = {
59 {0x7fff, -0x8000, 5, 2},
60 {0x7fffff, -0x8000000, 7, 0},
63 {0x7fff, -0x8000, 6, 5},
64 {0x7fffff, -0x8000000, 8, 0},
66 {0x7fff, -0x8000, 3, 7},
67 {0x7fffff, -0x8000000, 5, 0},
70 {0x7fff, -0x8000, 3, 10},
71 {0x7fffff, -0x8000000, 5, 0},
75 static void mn10200_insert_operand
PARAMS ((unsigned long *, unsigned long *,
76 const struct mn10200_operand
*,
77 offsetT
, char *, unsigned,
79 static unsigned long check_operand
PARAMS ((unsigned long,
80 const struct mn10200_operand
*,
82 static int reg_name_search
PARAMS ((const struct reg_name
*, int, const char *));
83 static boolean data_register_name
PARAMS ((expressionS
*expressionP
));
84 static boolean address_register_name
PARAMS ((expressionS
*expressionP
));
85 static boolean other_register_name
PARAMS ((expressionS
*expressionP
));
89 #define MAX_INSN_FIXUPS (5)
94 bfd_reloc_code_real_type reloc
;
96 struct mn10200_fixup fixups
[MAX_INSN_FIXUPS
];
99 const char *md_shortopts
= "";
100 struct option md_longopts
[] = {
101 {NULL
, no_argument
, NULL
, 0}
103 size_t md_longopts_size
= sizeof(md_longopts
);
105 /* The target specific pseudo-ops which we support. */
106 const pseudo_typeS md_pseudo_table
[] =
111 /* Opcode hash table. */
112 static struct hash_control
*mn10200_hash
;
114 /* This table is sorted. Suitable for searching by a binary search. */
115 static const struct reg_name data_registers
[] =
122 #define DATA_REG_NAME_CNT (sizeof(data_registers) / sizeof(struct reg_name))
124 static const struct reg_name address_registers
[] =
131 #define ADDRESS_REG_NAME_CNT (sizeof(address_registers) / sizeof(struct reg_name))
133 static const struct reg_name other_registers
[] =
138 #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name))
140 /* reg_name_search does a binary search of the given register table
141 to see if "name" is a valid regiter name. Returns the register
142 number from the array on success, or -1 on failure. */
145 reg_name_search (regs
, regcount
, name
)
146 const struct reg_name
*regs
;
150 int middle
, low
, high
;
158 middle
= (low
+ high
) / 2;
159 cmp
= strcasecmp (name
, regs
[middle
].name
);
165 return regs
[middle
].value
;
172 /* Summary of register_name().
174 * in: Input_line_pointer points to 1st char of operand.
176 * out: A expressionS.
177 * The operand may have been a register: in this case, X_op == O_register,
178 * X_add_number is set to the register number, and truth is returned.
179 * Input_line_pointer->(next non-blank) char after operand, or is in
180 * its original state.
183 data_register_name (expressionP
)
184 expressionS
*expressionP
;
191 /* Find the spelling of the operand */
192 start
= name
= input_line_pointer
;
194 c
= get_symbol_end ();
195 reg_number
= reg_name_search (data_registers
, DATA_REG_NAME_CNT
, name
);
197 /* look to see if it's in the register table */
200 expressionP
->X_op
= O_register
;
201 expressionP
->X_add_number
= reg_number
;
203 /* make the rest nice */
204 expressionP
->X_add_symbol
= NULL
;
205 expressionP
->X_op_symbol
= NULL
;
206 *input_line_pointer
= c
; /* put back the delimiting char */
211 /* reset the line as if we had not done anything */
212 *input_line_pointer
= c
; /* put back the delimiting char */
213 input_line_pointer
= start
; /* reset input_line pointer */
218 /* Summary of register_name().
220 * in: Input_line_pointer points to 1st char of operand.
222 * out: A expressionS.
223 * The operand may have been a register: in this case, X_op == O_register,
224 * X_add_number is set to the register number, and truth is returned.
225 * Input_line_pointer->(next non-blank) char after operand, or is in
226 * its original state.
229 address_register_name (expressionP
)
230 expressionS
*expressionP
;
237 /* Find the spelling of the operand */
238 start
= name
= input_line_pointer
;
240 c
= get_symbol_end ();
241 reg_number
= reg_name_search (address_registers
, ADDRESS_REG_NAME_CNT
, name
);
243 /* look to see if it's in the register table */
246 expressionP
->X_op
= O_register
;
247 expressionP
->X_add_number
= reg_number
;
249 /* make the rest nice */
250 expressionP
->X_add_symbol
= NULL
;
251 expressionP
->X_op_symbol
= NULL
;
252 *input_line_pointer
= c
; /* put back the delimiting char */
257 /* reset the line as if we had not done anything */
258 *input_line_pointer
= c
; /* put back the delimiting char */
259 input_line_pointer
= start
; /* reset input_line pointer */
264 /* Summary of register_name().
266 * in: Input_line_pointer points to 1st char of operand.
268 * out: A expressionS.
269 * The operand may have been a register: in this case, X_op == O_register,
270 * X_add_number is set to the register number, and truth is returned.
271 * Input_line_pointer->(next non-blank) char after operand, or is in
272 * its original state.
275 other_register_name (expressionP
)
276 expressionS
*expressionP
;
283 /* Find the spelling of the operand */
284 start
= name
= input_line_pointer
;
286 c
= get_symbol_end ();
287 reg_number
= reg_name_search (other_registers
, OTHER_REG_NAME_CNT
, name
);
289 /* look to see if it's in the register table */
292 expressionP
->X_op
= O_register
;
293 expressionP
->X_add_number
= reg_number
;
295 /* make the rest nice */
296 expressionP
->X_add_symbol
= NULL
;
297 expressionP
->X_op_symbol
= NULL
;
298 *input_line_pointer
= c
; /* put back the delimiting char */
303 /* reset the line as if we had not done anything */
304 *input_line_pointer
= c
; /* put back the delimiting char */
305 input_line_pointer
= start
; /* reset input_line pointer */
311 md_show_usage (stream
)
314 fprintf(stream
, "MN10200 options:\n\
319 md_parse_option (c
, arg
)
327 md_undefined_symbol (name
)
334 md_atof (type
, litp
, sizep
)
340 LITTLENUM_TYPE words
[4];
356 return "bad call to md_atof";
359 t
= atof_ieee (input_line_pointer
, type
, words
);
361 input_line_pointer
= t
;
365 for (i
= prec
- 1; i
>= 0; i
--)
367 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
376 md_convert_frag (abfd
, sec
, fragP
)
381 subseg_change (sec
, 0);
382 if (fragP
->fr_subtype
== 0)
384 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
385 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
389 else if (fragP
->fr_subtype
== 1)
391 /* Reverse the condition of the first branch. */
392 int offset
= fragP
->fr_fix
;
393 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
430 fragP
->fr_literal
[offset
] = opcode
;
432 /* Set the displacement bits so that we branch around
433 the unconditional branch. */
434 fragP
->fr_literal
[offset
+ 1] = 0x5;
436 /* Now create the unconditional branch + fixup to the
438 fragP
->fr_literal
[offset
+ 2] = 0xfc;
439 fix_new (fragP
, fragP
->fr_fix
+ 3, 2, fragP
->fr_symbol
,
440 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
444 else if (fragP
->fr_subtype
== 2)
446 /* Reverse the condition of the first branch. */
447 int offset
= fragP
->fr_fix
;
448 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
485 fragP
->fr_literal
[offset
] = opcode
;
487 /* Set the displacement bits so that we branch around
488 the unconditional branch. */
489 fragP
->fr_literal
[offset
+ 1] = 0x7;
491 /* Now create the unconditional branch + fixup to the
493 fragP
->fr_literal
[offset
+ 2] = 0xf4;
494 fragP
->fr_literal
[offset
+ 3] = 0xe0;
495 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
496 fragP
->fr_offset
+ 2, 1, BFD_RELOC_24_PCREL
);
500 else if (fragP
->fr_subtype
== 3)
502 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
503 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
507 else if (fragP
->fr_subtype
== 4)
509 /* Reverse the condition of the first branch. */
510 int offset
= fragP
->fr_fix
;
511 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
571 fragP
->fr_literal
[offset
+ 1] = opcode
;
573 /* Set the displacement bits so that we branch around
574 the unconditional branch. */
575 fragP
->fr_literal
[offset
+ 2] = 0x6;
577 /* Now create the unconditional branch + fixup to the
579 fragP
->fr_literal
[offset
+ 3] = 0xfc;
580 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
581 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
585 else if (fragP
->fr_subtype
== 5)
587 /* Reverse the condition of the first branch. */
588 int offset
= fragP
->fr_fix
;
589 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
649 fragP
->fr_literal
[offset
+ 1] = opcode
;
651 /* Set the displacement bits so that we branch around
652 the unconditional branch. */
653 fragP
->fr_literal
[offset
+ 2] = 0x8;
655 /* Now create the unconditional branch + fixup to the
657 fragP
->fr_literal
[offset
+ 3] = 0xf4;
658 fragP
->fr_literal
[offset
+ 4] = 0xe0;
659 fix_new (fragP
, fragP
->fr_fix
+ 5, 4, fragP
->fr_symbol
,
660 fragP
->fr_offset
+ 2, 1, BFD_RELOC_24_PCREL
);
664 else if (fragP
->fr_subtype
== 6)
666 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
667 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
671 else if (fragP
->fr_subtype
== 7)
673 int offset
= fragP
->fr_fix
;
674 fragP
->fr_literal
[offset
] = 0xf4;
675 fragP
->fr_literal
[offset
+ 1] = 0xe1;
677 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
678 fragP
->fr_offset
+ 2, 1, BFD_RELOC_24_PCREL
);
682 else if (fragP
->fr_subtype
== 8)
684 fragP
->fr_literal
[fragP
->fr_fix
] = 0xea;
685 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
686 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
690 else if (fragP
->fr_subtype
== 9)
692 int offset
= fragP
->fr_fix
;
693 fragP
->fr_literal
[offset
] = 0xfc;
695 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
696 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
700 else if (fragP
->fr_subtype
== 10)
702 int offset
= fragP
->fr_fix
;
703 fragP
->fr_literal
[offset
] = 0xf4;
704 fragP
->fr_literal
[offset
+ 1] = 0xe0;
706 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
707 fragP
->fr_offset
+ 2, 1, BFD_RELOC_24_PCREL
);
716 md_section_align (seg
, addr
)
720 int align
= bfd_get_section_alignment (stdoutput
, seg
);
721 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
727 char *prev_name
= "";
728 register const struct mn10200_opcode
*op
;
730 mn10200_hash
= hash_new();
732 /* Insert unique names into hash table. The MN10200 instruction set
733 has many identical opcode names that have different opcodes based
734 on the operands. This hash table then provides a quick index to
735 the first opcode with a particular name in the opcode table. */
737 op
= mn10200_opcodes
;
740 if (strcmp (prev_name
, op
->name
))
742 prev_name
= (char *) op
->name
;
743 hash_insert (mn10200_hash
, op
->name
, (char *) op
);
748 /* This is both a simplification (we don't have to write md_apply_fix)
749 and support for future optimizations (branch shortening and similar
750 stuff in the linker. */
759 struct mn10200_opcode
*opcode
;
760 struct mn10200_opcode
*next_opcode
;
761 const unsigned char *opindex_ptr
;
762 int next_opindex
, relaxable
;
763 unsigned long insn
, extension
, size
= 0;
768 /* Get the opcode. */
769 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
774 /* find the first opcode with the proper name */
775 opcode
= (struct mn10200_opcode
*)hash_find (mn10200_hash
, str
);
778 as_bad ("Unrecognized opcode: `%s'", str
);
783 while (isspace (*str
))
786 input_line_pointer
= str
;
790 const char *errmsg
= NULL
;
799 insn
= opcode
->opcode
;
801 for (op_idx
= 1, opindex_ptr
= opcode
->operands
;
803 opindex_ptr
++, op_idx
++)
805 const struct mn10200_operand
*operand
;
808 if (next_opindex
== 0)
810 operand
= &mn10200_operands
[*opindex_ptr
];
814 operand
= &mn10200_operands
[next_opindex
];
820 while (*str
== ' ' || *str
== ',')
823 if (operand
->flags
& MN10200_OPERAND_RELAX
)
826 /* Gather the operand. */
827 hold
= input_line_pointer
;
828 input_line_pointer
= str
;
830 if (operand
->flags
& MN10200_OPERAND_PAREN
)
832 if (*input_line_pointer
!= ')' && *input_line_pointer
!= '(')
834 input_line_pointer
= hold
;
838 input_line_pointer
++;
841 /* See if we can match the operands. */
842 else if (operand
->flags
& MN10200_OPERAND_DREG
)
844 if (!data_register_name (&ex
))
846 input_line_pointer
= hold
;
851 else if (operand
->flags
& MN10200_OPERAND_AREG
)
853 if (!address_register_name (&ex
))
855 input_line_pointer
= hold
;
860 else if (operand
->flags
& MN10200_OPERAND_PSW
)
862 char *start
= input_line_pointer
;
863 char c
= get_symbol_end ();
865 if (strcmp (start
, "psw") != 0)
867 *input_line_pointer
= c
;
868 input_line_pointer
= hold
;
872 *input_line_pointer
= c
;
875 else if (operand
->flags
& MN10200_OPERAND_MDR
)
877 char *start
= input_line_pointer
;
878 char c
= get_symbol_end ();
880 if (strcmp (start
, "mdr") != 0)
882 *input_line_pointer
= c
;
883 input_line_pointer
= hold
;
887 *input_line_pointer
= c
;
890 else if (data_register_name (&ex
))
892 input_line_pointer
= hold
;
896 else if (address_register_name (&ex
))
898 input_line_pointer
= hold
;
902 else if (other_register_name (&ex
))
904 input_line_pointer
= hold
;
908 else if (*str
== ')' || *str
== '(')
910 input_line_pointer
= hold
;
922 errmsg
= "illegal operand";
925 errmsg
= "missing operand";
929 & (MN10200_OPERAND_DREG
| MN10200_OPERAND_AREG
)) == 0)
931 input_line_pointer
= hold
;
936 if (opcode
->format
== FMT_2
|| opcode
->format
== FMT_5
)
938 else if (opcode
->format
== FMT_3
|| opcode
->format
== FMT_6
939 || opcode
->format
== FMT_7
)
944 mn10200_insert_operand (&insn
, &extension
, operand
,
945 ex
.X_add_number
, (char *) NULL
,
951 /* If this operand can be promoted, and it doesn't
952 fit into the allocated bitfield for this insn,
953 then promote it (ie this opcode does not match). */
954 if (operand
->flags
& MN10200_OPERAND_PROMOTE
955 && ! check_operand (insn
, operand
, ex
.X_add_number
))
957 input_line_pointer
= hold
;
962 mn10200_insert_operand (&insn
, &extension
, operand
,
963 ex
.X_add_number
, (char *) NULL
,
968 /* If this operand can be promoted, then this opcode didn't
969 match since we can't know if it needed promotion! */
970 if (operand
->flags
& MN10200_OPERAND_PROMOTE
)
972 input_line_pointer
= hold
;
977 /* We need to generate a fixup for this expression. */
978 if (fc
>= MAX_INSN_FIXUPS
)
979 as_fatal ("too many fixups");
981 fixups
[fc
].opindex
= *opindex_ptr
;
982 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
988 str
= input_line_pointer
;
989 input_line_pointer
= hold
;
991 while (*str
== ' ' || *str
== ',')
996 /* Make sure we used all the operands! */
1003 next_opcode
= opcode
+ 1;
1004 if (!strcmp(next_opcode
->name
, opcode
->name
))
1006 opcode
= next_opcode
;
1010 as_bad ("%s", errmsg
);
1016 while (isspace (*str
))
1020 as_bad ("junk at end of line: `%s'", str
);
1022 input_line_pointer
= str
;
1024 if (opcode
->format
== FMT_1
)
1026 else if (opcode
->format
== FMT_2
|| opcode
->format
== FMT_4
)
1028 else if (opcode
->format
== FMT_3
|| opcode
->format
== FMT_5
)
1030 else if (opcode
->format
== FMT_6
)
1032 else if (opcode
->format
== FMT_7
)
1037 /* Write out the instruction. */
1039 if (relaxable
&& fc
> 0)
1044 if (size
== 2 && opcode
->opcode
!= 0xfc0000)
1047 else if (size
== 3 && opcode
->opcode
== 0xfd0000)
1050 else if (size
== 3 && opcode
->opcode
== 0xfc0000)
1056 f
= frag_var (rs_machine_dependent
, 8, 8 - size
, type
,
1057 fixups
[0].exp
.X_add_symbol
,
1058 fixups
[0].exp
.X_add_number
,
1059 (char *)fixups
[0].opindex
);
1060 number_to_chars_bigendian (f
, insn
, size
);
1063 number_to_chars_bigendian (f
+ size
, 0, 4);
1064 number_to_chars_bigendian (f
+ size
+ 4, 0, 8 - size
- 4);
1067 number_to_chars_bigendian (f
+ size
, 0, 8 - size
);
1072 f
= frag_more (size
);
1074 /* Oh, what a mess. The instruction is in big endian format, but
1075 16 and 24bit immediates are little endian! */
1076 if (opcode
->format
== FMT_3
)
1078 number_to_chars_bigendian (f
, (insn
>> 16) & 0xff, 1);
1079 number_to_chars_littleendian (f
+ 1, insn
& 0xffff, 2);
1081 else if (opcode
->format
== FMT_6
)
1083 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1084 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
1086 else if (opcode
->format
== FMT_7
)
1088 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1089 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
1090 number_to_chars_littleendian (f
+ 4, extension
& 0xff, 1);
1094 number_to_chars_bigendian (f
, insn
, size
> 4 ? 4 : size
);
1097 /* Create any fixups. */
1098 for (i
= 0; i
< fc
; i
++)
1100 const struct mn10200_operand
*operand
;
1102 operand
= &mn10200_operands
[fixups
[i
].opindex
];
1103 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1105 reloc_howto_type
*reloc_howto
;
1110 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1115 size
= bfd_get_reloc_size (reloc_howto
);
1117 if (size
< 1 || size
> 4)
1121 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1124 reloc_howto
->pc_relative
,
1129 int reloc
, pcrel
, reloc_size
, offset
;
1132 reloc
= BFD_RELOC_NONE
;
1133 /* How big is the reloc? Remember SPLIT relocs are
1134 implicitly 32bits. */
1135 reloc_size
= operand
->bits
;
1137 offset
= size
- reloc_size
/ 8;
1139 /* Is the reloc pc-relative? */
1140 pcrel
= (operand
->flags
& MN10200_OPERAND_PCREL
) != 0;
1143 /* Choose a proper BFD relocation type. */
1146 if (reloc_size
== 8)
1147 reloc
= BFD_RELOC_8_PCREL
;
1148 else if (reloc_size
== 24)
1149 reloc
= BFD_RELOC_24_PCREL
;
1155 if (reloc_size
== 32)
1156 reloc
= BFD_RELOC_32
;
1157 else if (reloc_size
== 16)
1158 reloc
= BFD_RELOC_16
;
1159 else if (reloc_size
== 8)
1160 reloc
= BFD_RELOC_8
;
1161 else if (reloc_size
== 24)
1162 reloc
= BFD_RELOC_24
;
1167 /* Convert the size of the reloc into what fix_new_exp wants. */
1168 reloc_size
= reloc_size
/ 8;
1169 if (reloc_size
== 8)
1171 else if (reloc_size
== 16)
1173 else if (reloc_size
== 32 || reloc_size
== 24)
1176 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1177 reloc_size
, &fixups
[i
].exp
, pcrel
,
1178 ((bfd_reloc_code_real_type
) reloc
));
1180 fixP
->fx_offset
+= offset
;
1187 /* if while processing a fixup, a reloc really needs to be created */
1188 /* then it is done here */
1191 tc_gen_reloc (seg
, fixp
)
1196 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
1198 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1199 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1201 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1202 "reloc %d not supported by object file format",
1203 (int)fixp
->fx_r_type
);
1206 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1208 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
1210 reloc
->sym_ptr_ptr
= &bfd_abs_symbol
;
1211 reloc
->addend
= (S_GET_VALUE (fixp
->fx_addsy
)
1212 - S_GET_VALUE (fixp
->fx_subsy
) + fixp
->fx_offset
);
1216 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1217 reloc
->addend
= fixp
->fx_offset
;
1223 md_estimate_size_before_relax (fragp
, seg
)
1227 if (fragp
->fr_subtype
== 0)
1229 if (fragp
->fr_subtype
== 3)
1231 if (fragp
->fr_subtype
== 6)
1233 if (!S_IS_DEFINED (fragp
->fr_symbol
)
1234 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
))
1236 fragp
->fr_subtype
= 7;
1241 if (fragp
->fr_subtype
== 8)
1243 if (!S_IS_DEFINED (fragp
->fr_symbol
))
1245 fragp
->fr_subtype
= 10;
1253 md_pcrel_from (fixp
)
1256 return fixp
->fx_frag
->fr_address
;
1258 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1260 /* The symbol is undefined. Let the linker figure it out. */
1263 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1268 md_apply_fix3 (fixp
, valuep
, seg
)
1273 /* We shouldn't ever get here because linkrelax is nonzero. */
1279 /* Insert an operand value into an instruction. */
1282 mn10200_insert_operand (insnp
, extensionp
, operand
, val
, file
, line
, shift
)
1283 unsigned long *insnp
;
1284 unsigned long *extensionp
;
1285 const struct mn10200_operand
*operand
;
1291 /* No need to check 24 or 32bit operands for a bit. */
1292 if (operand
->bits
< 24
1293 && (operand
->flags
& MN10200_OPERAND_NOCHECK
) == 0)
1298 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
1300 max
= (1 << (operand
->bits
- 1)) - 1;
1301 min
= - (1 << (operand
->bits
- 1));
1305 max
= (1 << operand
->bits
) - 1;
1312 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1315 "operand out of range (%s not between %ld and %ld)";
1318 sprint_value (buf
, test
);
1319 if (file
== (char *) NULL
)
1320 as_warn (err
, buf
, min
, max
);
1322 as_warn_where (file
, line
, err
, buf
, min
, max
);
1326 if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) == 0)
1328 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
1329 << (operand
->shift
+ shift
));
1331 if ((operand
->flags
& MN10200_OPERAND_REPEATED
) != 0)
1332 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
1333 << (operand
->shift
+ shift
+ 2));
1337 *extensionp
|= (val
>> 16) & 0xff;
1338 *insnp
|= val
& 0xffff;
1342 static unsigned long
1343 check_operand (insn
, operand
, val
)
1345 const struct mn10200_operand
*operand
;
1348 /* No need to check 24bit or 32bit operands for a bit. */
1349 if (operand
->bits
< 24
1350 && (operand
->flags
& MN10200_OPERAND_NOCHECK
) == 0)
1355 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
1357 max
= (1 << (operand
->bits
- 1)) - 1;
1358 min
= - (1 << (operand
->bits
- 1));
1362 max
= (1 << operand
->bits
) - 1;
1369 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)