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 Free Software Foundation, Inc.
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* Written By Steve Chamberlain <sac@cygnus.com>. */
30 #include "dwarf2dbg.h"
34 #define h8_opcodes ops
35 #include "opcode/h8300.h"
36 #include "safe-ctype.h"
42 const char comment_chars
[] = ";";
43 const char line_comment_chars
[] = "#";
44 const char line_separator_chars
[] = "";
46 void cons
PARAMS ((int));
47 void sbranch
PARAMS ((int));
48 void h8300hmode
PARAMS ((int));
49 void h8300smode
PARAMS ((int));
50 void h8300hnmode
PARAMS ((int));
51 void h8300snmode
PARAMS ((int));
52 void h8300sxmode
PARAMS ((int));
53 static void pint
PARAMS ((int));
60 #define PSIZE (Hmode ? L_32 : L_16)
61 #define DSYMMODE (Hmode ? L_24 : L_16)
63 int bsize
= L_8
; /* Default branch displacement. */
71 const struct h8_opcode
*opcode
;
74 struct h8_instruction
*h8_instructions
;
78 int arg ATTRIBUTE_UNUSED
;
83 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
84 as_warn (_("could not set architecture and machine"));
90 int arg ATTRIBUTE_UNUSED
;
95 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
96 as_warn (_("could not set architecture and machine"));
102 int arg ATTRIBUTE_UNUSED
;
108 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300hn
))
109 as_warn (_("could not set architecture and machine"));
115 int arg ATTRIBUTE_UNUSED
;
121 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sn
))
122 as_warn (_("could not set architecture and machine"));
128 int arg ATTRIBUTE_UNUSED
;
134 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sx
))
135 as_warn (_("could not set architecture and machine"));
141 int arg ATTRIBUTE_UNUSED
;
148 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sxn
))
149 as_warn (_("could not set architecture and machine"));
162 int arg ATTRIBUTE_UNUSED
;
164 cons (Hmode
? 4 : 2);
167 /* This table describes all the machine specific pseudo-ops the assembler
168 has to support. The fields are:
169 pseudo-op name without dot
170 function to call to execute this pseudo-op
171 Integer arg to pass to the function. */
173 const pseudo_typeS md_pseudo_table
[] =
175 {"h8300h", h8300hmode
, 0},
176 {"h8300hn", h8300hnmode
, 0},
177 {"h8300s", h8300smode
, 0},
178 {"h8300sn", h8300snmode
, 0},
179 {"h8300sx", h8300sxmode
, 0},
180 {"h8300sxn", h8300sxnmode
, 0},
181 {"sbranch", sbranch
, L_8
},
182 {"lbranch", sbranch
, L_16
},
188 {"form", listing_psize
, 0},
189 {"heading", listing_title
, 0},
190 {"import", s_ignore
, 0},
191 {"page", listing_eject
, 0},
192 {"program", s_ignore
, 0},
196 const int md_reloc_size
;
198 const char EXP_CHARS
[] = "eE";
200 /* Chars that mean this number is a floating point constant
203 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
205 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
207 /* This function is called once, at assembler startup time. This
208 should set up all the tables, etc. that the MD part of the assembler
214 unsigned int nopcodes
;
215 struct h8_opcode
*p
, *p1
;
216 struct h8_instruction
*pi
;
217 char prev_buffer
[100];
221 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
222 as_warn (_("could not set architecture and machine"));
225 opcode_hash_control
= hash_new ();
228 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
230 h8_instructions
= (struct h8_instruction
*)
231 xmalloc (nopcodes
* sizeof (struct h8_instruction
));
233 pi
= h8_instructions
;
235 /* We do a minimum amount of sorting on the opcode table; this is to
236 make it easy to describe the mova instructions without unnecessary
238 Sorting only takes place inside blocks of instructions of the form
239 X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */
242 struct h8_opcode
*first_skipped
= 0;
244 char *src
= p1
->name
;
249 /* Strip off any . part when inserting the opcode and only enter
250 unique codes into the hash table. */
251 dst
= buffer
= malloc (strlen (src
) + 1);
260 cmplen
= src
- p1
->name
+ 1;
267 hash_insert (opcode_hash_control
, buffer
, (char *) pi
);
268 strcpy (prev_buffer
, buffer
);
271 for (p
= p1
; p
->name
; p
++)
273 /* A negative TIME is used to indicate that we've added this opcode
277 if (strncmp (p
->name
, buffer
, cmplen
) != 0
278 || (p
->name
[cmplen
] != '\0' && p
->name
[cmplen
] != '.'
279 && p
->name
[cmplen
- 1] != '/'))
281 if (first_skipped
== 0)
285 if (strncmp (p
->name
, buffer
, len
) != 0)
287 if (first_skipped
== 0)
293 pi
->size
= p
->name
[len
] == '.' ? p
->name
[len
+ 1] : 0;
296 /* Find the number of operands. */
298 while (pi
->noperands
< 3 && p
->args
.nib
[pi
->noperands
] != (op_type
) E
)
301 /* Find the length of the opcode in bytes. */
303 while (p
->data
.nib
[pi
->length
* 2] != (op_type
) E
)
312 /* Add entry for the NULL vector terminator. */
336 static void clever_message
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
337 static void fix_operand_size
PARAMS ((struct h8_op
*, int));
338 static void build_bytes
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
339 static void do_a_fix_imm
PARAMS ((int, int, struct h8_op
*, int));
340 static void check_operand
PARAMS ((struct h8_op
*, unsigned int, char *));
341 static const struct h8_instruction
* get_specific
PARAMS ((const struct h8_instruction
*, struct h8_op
*, int));
342 static char * get_operands
PARAMS ((unsigned, char *, struct h8_op
*));
343 static void get_operand
PARAMS ((char **, struct h8_op
*, int));
344 static char * skip_colonthing
PARAMS ((char *, expressionS
*, int *));
345 static char * parse_exp
PARAMS ((char *, expressionS
*));
346 static int parse_reg
PARAMS ((char *, op_type
*, unsigned *, int));
347 char * colonmod24
PARAMS ((struct h8_op
*, char *));
349 static int constant_fits_width_p
PARAMS ((struct h8_op
*, unsigned int));
350 static int constant_fits_size_p
PARAMS ((struct h8_op
*, int, int));
354 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
363 /* Try to parse a reg name. Return the number of chars consumed. */
366 parse_reg (src
, mode
, reg
, direction
)
375 /* Cribbed from get_symbol_end. */
376 if (!is_name_beginner (*src
) || *src
== '\001')
379 while ((is_part_of_name (*end
) && *end
!= '.') || *end
== '\001')
383 if (len
== 2 && TOLOWER (src
[0]) == 's' && TOLOWER (src
[1]) == 'p')
385 *mode
= PSIZE
| REG
| direction
;
390 TOLOWER (src
[0]) == 'c' &&
391 TOLOWER (src
[1]) == 'c' &&
392 TOLOWER (src
[2]) == 'r')
399 TOLOWER (src
[0]) == 'e' &&
400 TOLOWER (src
[1]) == 'x' &&
401 TOLOWER (src
[2]) == 'r')
408 TOLOWER (src
[0]) == 'v' &&
409 TOLOWER (src
[1]) == 'b' &&
410 TOLOWER (src
[2]) == 'r')
417 TOLOWER (src
[0]) == 's' &&
418 TOLOWER (src
[1]) == 'b' &&
419 TOLOWER (src
[2]) == 'r')
425 if (len
== 2 && TOLOWER (src
[0]) == 'f' && TOLOWER (src
[1]) == 'p')
427 *mode
= PSIZE
| REG
| direction
;
431 if (len
== 3 && TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
432 src
[2] >= '0' && src
[2] <= '7')
434 *mode
= L_32
| REG
| direction
;
437 as_warn (_("Reg not valid for H8/300"));
440 if (len
== 2 && TOLOWER (src
[0]) == 'e' && src
[1] >= '0' && src
[1] <= '7')
442 *mode
= L_16
| REG
| direction
;
443 *reg
= src
[1] - '0' + 8;
445 as_warn (_("Reg not valid for H8/300"));
449 if (TOLOWER (src
[0]) == 'r')
451 if (src
[1] >= '0' && src
[1] <= '7')
453 if (len
== 3 && TOLOWER (src
[2]) == 'l')
455 *mode
= L_8
| REG
| direction
;
456 *reg
= (src
[1] - '0') + 8;
459 if (len
== 3 && TOLOWER (src
[2]) == 'h')
461 *mode
= L_8
| REG
| direction
;
462 *reg
= (src
[1] - '0');
467 *mode
= L_16
| REG
| direction
;
468 *reg
= (src
[1] - '0');
482 char *save
= input_line_pointer
;
485 input_line_pointer
= s
;
487 if (op
->X_op
== O_absent
)
488 as_bad (_("missing operand"));
489 new = input_line_pointer
;
490 input_line_pointer
= save
;
495 skip_colonthing (ptr
, exp
, mode
)
497 expressionS
*exp ATTRIBUTE_UNUSED
;
504 if (ptr
[0] == '8' && ! ISDIGIT (ptr
[1]))
506 else if (ptr
[0] == '2' && ! ISDIGIT (ptr
[1]))
508 else if (ptr
[0] == '3' && ! ISDIGIT (ptr
[1]))
510 else if (ptr
[0] == '4' && ! ISDIGIT (ptr
[1]))
512 else if (ptr
[0] == '5' && ! ISDIGIT (ptr
[1]))
514 else if (ptr
[0] == '2' && ptr
[1] == '4')
516 else if (ptr
[0] == '3' && ptr
[1] == '2')
518 else if (ptr
[0] == '1' && ptr
[1] == '6')
521 as_bad (_("invalid operand size requested"));
523 while (ISDIGIT (*ptr
))
529 /* The many forms of operand:
532 @Rn Register indirect
533 @(exp[:16], Rn) Register indirect with displacement
537 @aa:16 absolute 16 bit
540 #xx[:size] immediate data
541 @(exp:[8], pc) pc rel
542 @@aa[:8] memory indirect. */
550 src
= skip_colonthing (src
, &op
->exp
, &mode
);
554 /* If the operand is a 16-bit constant integer, leave fix_operand_size
555 to calculate its size. Otherwise choose a default here. */
556 if (op
->exp
.X_add_number
< -32768
557 || op
->exp
.X_add_number
> 32767)
564 else if (op
->exp
.X_add_symbol
565 || op
->exp
.X_op_symbol
)
574 constant_fits_width_p (operand
, width
)
575 struct h8_op
*operand
;
578 return ((operand
->exp
.X_add_number
& ~width
) == 0
579 || (operand
->exp
.X_add_number
| width
) == (unsigned)(~0));
583 constant_fits_size_p (operand
, size
, no_symbols
)
584 struct h8_op
*operand
;
585 int size
, no_symbols
;
587 offsetT num
= operand
->exp
.X_add_number
;
589 && (operand
->exp
.X_add_symbol
!= 0 || operand
->exp
.X_op_symbol
!= 0))
594 return (num
& ~3) == 0;
596 return (num
& ~7) == 0;
598 return num
>= 1 && num
< 8;
600 return (num
& ~15) == 0;
602 return num
>= 1 && num
< 32;
604 return (num
& ~0xFF) == 0 || ((unsigned)num
| 0x7F) == ~0u;
606 return (num
& ~0xFF) == 0;
608 return (num
& ~0xFFFF) == 0 || ((unsigned)num
| 0x7FFF) == ~0u;
610 return (num
& ~0xFFFF) == 0;
619 get_operand (ptr
, op
, direction
)
631 /* Check for '(' and ')' for instructions ldm and stm. */
632 if (src
[0] == '(' && src
[8] == ')')
635 /* Gross. Gross. ldm and stm have a format not easily handled
636 by get_operand. We deal with it explicitly here. */
637 if (TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
638 ISDIGIT (src
[2]) && src
[3] == '-' &&
639 TOLOWER (src
[4]) == 'e' && TOLOWER (src
[5]) == 'r' && ISDIGIT (src
[6]))
647 as_bad (_("Invalid register list for ldm/stm\n"));
650 as_bad (_("Invalid register list for ldm/stm\n"));
653 as_bad (_("Invalid register list for ldm/stm)\n"));
655 /* Even sicker. We encode two registers into op->reg. One
656 for the low register to save, the other for the high
657 register to save; we also set the high bit in op->reg
658 so we know this is "very special". */
659 op
->reg
= 0x80000000 | (high
<< 8) | low
;
668 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
674 int size
= op
->mode
& SIZE
;
679 as_warn (_("mismatch between register and suffix"));
680 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
683 if (size
!= L_32
&& size
!= L_16
)
684 as_warn (_("mismatch between register and suffix"));
685 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
686 op
->mode
= (op
->mode
& ~SIZE
) | L_16
;
689 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
690 if (size
!= L_32
&& size
!= L_8
)
691 as_warn (_("mismatch between register and suffix"));
692 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
693 op
->mode
= (op
->mode
& ~SIZE
) | L_8
;
696 as_warn ("invalid suffix after register.");
711 src
= parse_exp (src
, &op
->exp
);
713 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
717 if (op
->exp
.X_add_number
>= 0x100)
722 /* FIXME : 2? or 4? */
723 if (op
->exp
.X_add_number
>= 0x400)
724 as_bad (_("address too high for vector table jmp/jsr"));
725 else if (op
->exp
.X_add_number
>= 0x200)
730 op
->exp
.X_add_number
= op
->exp
.X_add_number
/ divisor
- 0x80;
738 if (*src
== '-' || *src
== '+')
742 len
= parse_reg (src
, &mode
, &num
, direction
);
745 /* Oops, not a reg after all, must be ordinary exp. */
747 /* Must be a symbol. */
748 op
->mode
= ABS
| PSIZE
| direction
;
749 *ptr
= skip_colonthing (parse_exp (src
, &op
->exp
),
750 &op
->exp
, &op
->mode
);
755 if ((mode
& SIZE
) != PSIZE
)
756 as_bad (_("Wrong size pointer register for architecture."));
757 op
->mode
= c
== '-' ? RDPREDEC
: RDPREINC
;
766 /* See if this is @(ERn.x, PC). */
767 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
768 if (len
!= 0 && (mode
& MODE
) == REG
&& src
[len
] == '.')
770 switch (TOLOWER (src
[len
+ 1]))
773 mode
= PCIDXB
| direction
;
776 mode
= PCIDXW
| direction
;
779 mode
= PCIDXL
| direction
;
786 && src
[len
+ 2] == ','
787 && TOLOWER (src
[len
+ 3]) != 'p'
788 && TOLOWER (src
[len
+ 4]) != 'c'
789 && src
[len
+ 5] != ')')
791 *ptr
= src
+ len
+ 6;
795 /* Fall through into disp case - the grammar is somewhat
796 ambiguous, so we should try whether it's a DISP operand
797 after all ("ER3.L" might be a poorly named label...). */
802 /* Start off assuming a 16 bit offset. */
804 src
= parse_exp (src
, &op
->exp
);
806 src
= colonmod24 (op
, src
);
811 op
->mode
|= ABS
| direction
;
818 as_bad (_("expected @(exp, reg16)"));
824 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
825 if (len
== 0 || (mode
& MODE
) != REG
)
827 as_bad (_("expected @(exp, reg16)"));
833 switch (TOLOWER (src
[1]))
836 op
->mode
|= INDEXB
| direction
;
839 op
->mode
|= INDEXW
| direction
;
842 op
->mode
|= INDEXL
| direction
;
845 as_bad (_("expected .L, .W or .B for register in indexed addressing mode"));
851 op
->mode
|= DISP
| direction
;
852 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
854 if (*src
!= ')' && '(')
856 as_bad (_("expected @(exp, reg16)"));
863 len
= parse_reg (src
, &mode
, &num
, direction
);
868 if (*src
== '+' || *src
== '-')
870 if ((mode
& SIZE
) != PSIZE
)
871 as_bad (_("Wrong size pointer register for architecture."));
872 op
->mode
= *src
== '+' ? RSPOSTINC
: RSPOSTDEC
;
878 if ((mode
& SIZE
) != PSIZE
)
879 as_bad (_("Wrong size pointer register for architecture."));
881 op
->mode
= direction
| IND
| PSIZE
;
889 /* must be a symbol */
891 op
->mode
= ABS
| direction
;
892 src
= parse_exp (src
, &op
->exp
);
894 *ptr
= colonmod24 (op
, src
);
904 src
= parse_exp (src
, &op
->exp
);
905 *ptr
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
909 else if (strncmp (src
, "mach", 4) == 0 ||
910 strncmp (src
, "macl", 4) == 0 ||
911 strncmp (src
, "MACH", 4) == 0 ||
912 strncmp (src
, "MACL", 4) == 0)
914 op
->reg
= TOLOWER (src
[3]) == 'l';
921 src
= parse_exp (src
, &op
->exp
);
922 /* Trailing ':' size ? */
925 if (src
[1] == '1' && src
[2] == '6')
927 op
->mode
= PCREL
| L_16
;
930 else if (src
[1] == '8')
932 op
->mode
= PCREL
| L_8
;
936 as_bad (_("expect :8 or :16 here"));
940 int val
= op
->exp
.X_add_number
;
943 if (-128 < val
&& val
< 127)
954 get_operands (noperands
, op_end
, operand
)
955 unsigned int noperands
;
957 struct h8_op
*operand
;
968 get_operand (&ptr
, operand
+ 0, SRC
);
972 get_operand (&ptr
, operand
+ 1, DST
);
978 get_operand (&ptr
, operand
+ 0, SRC
);
981 get_operand (&ptr
, operand
+ 1, DST
);
986 get_operand (&ptr
, operand
+ 0, SRC
);
989 get_operand (&ptr
, operand
+ 1, DST
);
992 get_operand (&ptr
, operand
+ 2, OP3
);
1002 /* MOVA has special requirements. Rather than adding twice the amount of
1003 addressing modes, we simply special case it a bit. */
1005 get_mova_operands (char *op_end
, struct h8_op
*operand
)
1009 if (ptr
[1] != '@' || ptr
[2] != '(')
1012 operand
[0].mode
= 0;
1013 ptr
= parse_exp (ptr
, &operand
[0].exp
);
1014 ptr
= colonmod24 (operand
+ 0, ptr
);
1019 get_operand (&ptr
, operand
+ 1, DST
);
1027 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
1030 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
1033 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
1039 else if ((operand
[1].mode
& MODE
) == LOWREG
)
1041 switch (operand
[1].mode
& SIZE
)
1044 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
1047 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
1050 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
1059 if (*ptr
++ != ')' || *ptr
++ != ',')
1061 get_operand (&ptr
, operand
+ 2, OP3
);
1062 /* See if we can use the short form of MOVA. */
1063 if (((operand
[1].mode
& MODE
) == REG
|| (operand
[1].mode
& MODE
) == LOWREG
)
1064 && (operand
[2].mode
& MODE
) == REG
1065 && (operand
[1].reg
& 7) == (operand
[2].reg
& 7))
1067 operand
[1].mode
= operand
[2].mode
= 0;
1068 operand
[0].reg
= operand
[2].reg
& 7;
1073 as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
1078 get_rtsl_operands (char *ptr
, struct h8_op
*operand
)
1080 int mode
, num
, num2
, len
, type
= 0;
1088 len
= parse_reg (ptr
, &mode
, &num
, SRC
);
1089 if (len
== 0 || (mode
& MODE
) != REG
)
1091 as_bad (_("expected register"));
1097 len
= parse_reg (++ptr
, &mode
, &num2
, SRC
);
1098 if (len
== 0 || (mode
& MODE
) != REG
)
1100 as_bad (_("expected register"));
1104 /* CONST_xxx are used as placeholders in the opcode table. */
1106 if (num
< 0 || num
> 3)
1108 as_bad (_("invalid register list"));
1113 num2
= num
, num
= 0;
1114 if (type
== 1 && *ptr
++ != ')')
1116 as_bad (_("expected closing paren"));
1119 operand
[0].mode
= RS32
;
1120 operand
[1].mode
= RD32
;
1121 operand
[0].reg
= num
;
1122 operand
[1].reg
= num2
;
1125 /* Passed a pointer to a list of opcodes which use different
1126 addressing modes, return the opcode which matches the opcodes
1129 static const struct h8_instruction
*
1130 get_specific (instruction
, operands
, size
)
1131 const struct h8_instruction
*instruction
;
1132 struct h8_op
*operands
;
1135 const struct h8_instruction
*this_try
= instruction
;
1136 const struct h8_instruction
*found_other
= 0, *found_mismatched
= 0;
1138 int this_index
= instruction
->idx
;
1141 /* There's only one ldm/stm and it's easier to just
1142 get out quick for them. */
1143 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
1144 || OP_KIND (instruction
->opcode
->how
) == O_STM
)
1147 while (noperands
< 3 && operands
[noperands
].mode
!= 0)
1150 while (this_index
== instruction
->idx
&& !found
)
1155 this_try
= instruction
++;
1156 this_size
= this_try
->opcode
->how
& SN
;
1158 if (this_try
->noperands
!= noperands
)
1160 else if (this_try
->noperands
> 0)
1164 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
1166 op_type op
= this_try
->opcode
->args
.nib
[i
];
1167 int op_mode
= op
& MODE
;
1168 int op_size
= op
& SIZE
;
1169 int x
= operands
[i
].mode
;
1170 int x_mode
= x
& MODE
;
1171 int x_size
= x
& SIZE
;
1173 if (op_mode
== LOWREG
&& (x_mode
== REG
|| x_mode
== LOWREG
))
1175 if ((x_size
== L_8
&& (operands
[i
].reg
& 8) == 0)
1176 || (x_size
== L_16
&& (operands
[i
].reg
& 8) == 8))
1177 as_warn (_("can't use high part of register in operand %d"), i
);
1179 if (x_size
!= op_size
)
1182 else if (op_mode
== REG
)
1184 if (x_mode
== LOWREG
)
1190 x_size
= (Hmode
? L_32
: L_16
);
1192 op_size
= (Hmode
? L_32
: L_16
);
1194 /* The size of the reg is v important. */
1195 if (op_size
!= x_size
)
1198 else if (op_mode
& CTRL
) /* control register */
1200 if (!(x_mode
& CTRL
))
1206 if (op_mode
!= CCR
&&
1207 op_mode
!= CCR_EXR
&&
1208 op_mode
!= CC_EX_VB_SB
)
1212 if (op_mode
!= EXR
&&
1213 op_mode
!= CCR_EXR
&&
1214 op_mode
!= CC_EX_VB_SB
)
1218 if (op_mode
!= MACH
&&
1223 if (op_mode
!= MACL
&&
1228 if (op_mode
!= VBR
&&
1229 op_mode
!= VBR_SBR
&&
1230 op_mode
!= CC_EX_VB_SB
)
1234 if (op_mode
!= SBR
&&
1235 op_mode
!= VBR_SBR
&&
1236 op_mode
!= CC_EX_VB_SB
)
1241 else if ((op
& ABSJMP
) && (x_mode
== ABS
|| x_mode
== PCREL
))
1243 operands
[i
].mode
&= ~MODE
;
1244 operands
[i
].mode
|= ABSJMP
;
1245 /* But it may not be 24 bits long. */
1246 if (x_mode
== ABS
&& !Hmode
)
1248 operands
[i
].mode
&= ~SIZE
;
1249 operands
[i
].mode
|= L_16
;
1251 if ((operands
[i
].mode
& SIZE
) == L_32
1252 && (op_mode
& SIZE
) != L_32
)
1255 else if (x_mode
== IMM
&& op_mode
!= IMM
)
1257 offsetT num
= operands
[i
].exp
.X_add_number
;
1258 if (op_mode
== KBIT
|| op_mode
== DBIT
)
1259 /* This is ok if the immediate value is sensible. */;
1260 else if (op_mode
== CONST_2
)
1262 else if (op_mode
== CONST_4
)
1264 else if (op_mode
== CONST_8
)
1266 else if (op_mode
== CONST_16
)
1271 else if (op_mode
== PCREL
&& op_mode
== x_mode
)
1273 /* movsd only comes in PCREL16 flavour:
1274 If x_size is L_8, promote it. */
1275 if (OP_KIND (this_try
->opcode
->how
) == O_MOVSD
)
1279 /* The size of the displacement is important. */
1280 if (op_size
!= x_size
)
1283 else if ((op_mode
== DISP
|| op_mode
== IMM
|| op_mode
== ABS
1284 || op_mode
== INDEXB
|| op_mode
== INDEXW
1285 || op_mode
== INDEXL
)
1286 && op_mode
== x_mode
)
1288 /* Promote a L_24 to L_32 if it makes us match. */
1289 if (x_size
== L_24
&& op_size
== L_32
)
1296 /* Promote an L8 to L_16 if it makes us match. */
1297 if ((op_mode
== ABS
|| op_mode
== DISP
) && x_size
== L_8
)
1299 if (op_size
== L_16
)
1304 if (((x_size
== L_16
&& op_size
== L_16U
)
1305 || (x_size
== L_8
&& op_size
== L_8U
)
1306 || (x_size
== L_3
&& op_size
== L_3NZ
))
1307 /* We're deliberately more permissive for ABS modes. */
1309 || constant_fits_size_p (operands
+ i
, op_size
,
1313 if (x_size
!= 0 && op_size
!= x_size
)
1315 else if (x_size
== 0
1316 && ! constant_fits_size_p (operands
+ i
, op_size
,
1320 else if (op_mode
!= x_mode
)
1328 if ((this_try
->opcode
->available
== AV_H8SX
&& ! SXmode
)
1329 || (this_try
->opcode
->available
== AV_H8S
&& ! Smode
)
1330 || (this_try
->opcode
->available
== AV_H8H
&& ! Hmode
))
1331 found
= 0, found_other
= this_try
;
1332 else if (this_size
!= size
&& (this_size
!= SN
&& size
!= SN
))
1333 found_mismatched
= this_try
, found
= 0;
1341 as_warn (_("Opcode `%s' with these operand types not available in %s mode"),
1342 found_other
->opcode
->name
,
1343 (! Hmode
&& ! Smode
? "H8/300"
1348 else if (found_mismatched
)
1350 as_warn (_("mismatch between opcode size and operand size"));
1351 return found_mismatched
;
1357 check_operand (operand
, width
, string
)
1358 struct h8_op
*operand
;
1362 if (operand
->exp
.X_add_symbol
== 0
1363 && operand
->exp
.X_op_symbol
== 0)
1365 /* No symbol involved, let's look at offset, it's dangerous if
1366 any of the high bits are not 0 or ff's, find out by oring or
1367 anding with the width and seeing if the answer is 0 or all
1370 if (! constant_fits_width_p (operand
, width
))
1373 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
1375 /* Just ignore this one - which happens when trying to
1376 fit a 16 bit address truncated into an 8 bit address
1377 of something like bset. */
1379 else if (strcmp (string
, "@") == 0
1381 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
1383 /* Just ignore this one - which happens when trying to
1384 fit a 24 bit address truncated into a 16 bit address
1385 of something like mov.w. */
1389 as_warn (_("operand %s0x%lx out of range."), string
,
1390 (unsigned long) operand
->exp
.X_add_number
);
1396 /* RELAXMODE has one of 3 values:
1398 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
1400 1 Output a relaxable 24bit absolute mov.w address relocation
1401 (may relax into a 16bit absolute address).
1403 2 Output a relaxable 16/24 absolute mov.b address relocation
1404 (may relax into an 8bit absolute address). */
1407 do_a_fix_imm (offset
, nibble
, operand
, relaxmode
)
1409 struct h8_op
*operand
;
1415 char *bytes
= frag_now
->fr_literal
+ offset
;
1417 char *t
= ((operand
->mode
& MODE
) == IMM
) ? "#" : "@";
1419 if (operand
->exp
.X_add_symbol
== 0)
1421 switch (operand
->mode
& SIZE
)
1424 check_operand (operand
, 0x3, t
);
1425 bytes
[0] |= (operand
->exp
.X_add_number
& 3) << (nibble
? 0 : 4);
1429 check_operand (operand
, 0x7, t
);
1430 bytes
[0] |= (operand
->exp
.X_add_number
& 7) << (nibble
? 0 : 4);
1433 check_operand (operand
, 0xF, t
);
1434 bytes
[0] |= (operand
->exp
.X_add_number
& 15) << (nibble
? 0 : 4);
1437 check_operand (operand
, 0x1F, t
);
1438 bytes
[0] |= operand
->exp
.X_add_number
& 31;
1442 check_operand (operand
, 0xff, t
);
1443 bytes
[0] |= operand
->exp
.X_add_number
;
1447 check_operand (operand
, 0xffff, t
);
1448 bytes
[0] |= operand
->exp
.X_add_number
>> 8;
1449 bytes
[1] |= operand
->exp
.X_add_number
>> 0;
1452 check_operand (operand
, 0xffffff, t
);
1453 bytes
[0] |= operand
->exp
.X_add_number
>> 16;
1454 bytes
[1] |= operand
->exp
.X_add_number
>> 8;
1455 bytes
[2] |= operand
->exp
.X_add_number
>> 0;
1459 /* This should be done with bfd. */
1460 bytes
[0] |= operand
->exp
.X_add_number
>> 24;
1461 bytes
[1] |= operand
->exp
.X_add_number
>> 16;
1462 bytes
[2] |= operand
->exp
.X_add_number
>> 8;
1463 bytes
[3] |= operand
->exp
.X_add_number
>> 0;
1466 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
1467 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
1474 switch (operand
->mode
& SIZE
)
1479 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
1482 else if (relaxmode
== 1)
1488 as_bad (_("Can't work out size of operand.\n"));
1497 operand
->exp
.X_add_number
=
1498 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1499 operand
->exp
.X_add_number
|= (bytes
[0] << 8) | bytes
[1];
1505 operand
->exp
.X_add_number
=
1506 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1507 operand
->exp
.X_add_number
|= bytes
[0];
1510 fix_new_exp (frag_now
,
1519 /* Now we know what sort of opcodes it is, let's build the bytes. */
1522 build_bytes (this_try
, operand
)
1523 const struct h8_instruction
*this_try
;
1524 struct h8_op
*operand
;
1527 char *output
= frag_more (this_try
->length
);
1528 op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1530 unsigned int nibble_count
= 0;
1534 char asnibbles
[100];
1535 char *p
= asnibbles
;
1538 if (!Hmode
&& this_try
->opcode
->available
!= AV_H8
)
1539 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1540 this_try
->opcode
->name
);
1542 && this_try
->opcode
->available
!= AV_H8
1543 && this_try
->opcode
->available
!= AV_H8H
)
1544 as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"),
1545 this_try
->opcode
->name
);
1547 && this_try
->opcode
->available
!= AV_H8
1548 && this_try
->opcode
->available
!= AV_H8H
1549 && this_try
->opcode
->available
!= AV_H8S
)
1550 as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"),
1551 this_try
->opcode
->name
);
1553 while (*nibble_ptr
!= (op_type
) E
)
1560 d
= (c
& OP3
) == OP3
? 2 : (c
& DST
) == DST
? 1 : 0;
1568 if (c2
== REG
|| c2
== LOWREG
1569 || c2
== IND
|| c2
== PREINC
|| c2
== PREDEC
1570 || c2
== POSTINC
|| c2
== POSTDEC
)
1572 nib
= operand
[d
].reg
;
1577 else if (c
& CTRL
) /* Control reg operand. */
1578 nib
= operand
[d
].reg
;
1580 else if ((c
& DISPREG
) == (DISPREG
))
1582 nib
= operand
[d
].reg
;
1586 operand
[d
].mode
= c
;
1587 op_at
[d
] = nibble_count
;
1590 else if (c2
== IMM
|| c2
== PCREL
|| c2
== ABS
1591 || (c
& ABSJMP
) || c2
== DISP
)
1593 operand
[d
].mode
= c
;
1594 op_at
[d
] = nibble_count
;
1597 else if ((c
& IGNORE
) || (c
& DATA
))
1600 else if (c2
== DBIT
)
1602 switch (operand
[0].exp
.X_add_number
)
1611 as_bad (_("Need #1 or #2 here"));
1614 else if (c2
== KBIT
)
1616 switch (operand
[0].exp
.X_add_number
)
1626 as_warn (_("#4 not valid on H8/300."));
1631 as_bad (_("Need #1 or #2 here"));
1634 /* Stop it making a fix. */
1635 operand
[0].mode
= 0;
1639 operand
[d
].mode
|= MEMRELAX
;
1655 if (operand
[0].mode
== MACREG
)
1656 /* stmac has mac[hl] as the first operand. */
1657 nib
= 2 + operand
[0].reg
;
1659 /* ldmac has mac[hl] as the second operand. */
1660 nib
= 2 + operand
[1].reg
;
1668 /* Disgusting. Why, oh why didn't someone ask us for advice
1669 on the assembler format. */
1670 if (OP_KIND (this_try
->opcode
->how
) == O_LDM
)
1672 high
= (operand
[1].reg
>> 8) & 0xf;
1673 low
= (operand
[1].reg
) & 0xf;
1674 asnibbles
[2] = high
- low
;
1675 asnibbles
[7] = high
;
1677 else if (OP_KIND (this_try
->opcode
->how
) == O_STM
)
1679 high
= (operand
[0].reg
>> 8) & 0xf;
1680 low
= (operand
[0].reg
) & 0xf;
1681 asnibbles
[2] = high
- low
;
1685 for (i
= 0; i
< this_try
->length
; i
++)
1686 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1688 /* Note if this is a movb instruction -- there's a special relaxation
1689 which only applies to them. */
1690 if (this_try
->opcode
->how
== O (O_MOV
, SB
))
1693 /* Output any fixes. */
1694 for (i
= 0; i
< this_try
->noperands
; i
++)
1696 int x
= operand
[i
].mode
;
1697 int x_mode
= x
& MODE
;
1699 if (x_mode
== IMM
|| x_mode
== DISP
)
1700 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1701 op_at
[i
] & 1, operand
+ i
, (x
& MEMRELAX
) != 0);
1703 else if (x_mode
== ABS
)
1704 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1705 op_at
[i
] & 1, operand
+ i
,
1706 (x
& MEMRELAX
) ? movb
+ 1 : 0);
1708 else if (x_mode
== PCREL
)
1710 int size16
= (x
& SIZE
) == L_16
;
1711 int size
= size16
? 2 : 1;
1712 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1715 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1717 if (operand
[i
].exp
.X_add_number
& 1)
1718 as_warn (_("branch operand has odd offset (%lx)\n"),
1719 (unsigned long) operand
->exp
.X_add_number
);
1721 /* The COFF port has always been off by one, changing it
1722 now would be an incompatible change, so we leave it as-is.
1724 We don't want to do this for ELF as we want to be
1725 compatible with the proposed ELF format from Hitachi. */
1726 operand
[i
].exp
.X_add_number
-= 1;
1730 operand
[i
].exp
.X_add_number
=
1731 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1735 operand
[i
].exp
.X_add_number
=
1736 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1741 operand
[i
].exp
.X_add_number
|= output
[op_at
[i
] / 2];
1743 fixP
= fix_new_exp (frag_now
,
1744 output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1749 fixP
->fx_signed
= 1;
1751 else if (x_mode
== MEMIND
)
1753 check_operand (operand
+ i
, 0xff, "@@");
1754 fix_new_exp (frag_now
,
1755 output
- frag_now
->fr_literal
+ 1,
1761 else if (x_mode
== VECIND
)
1763 check_operand (operand
+ i
, 0x7f, "@@");
1764 /* FIXME: approximating the effect of "B31" here...
1765 This is very hackish, and ought to be done a better way. */
1766 operand
[i
].exp
.X_add_number
|= 0x80;
1767 fix_new_exp (frag_now
,
1768 output
- frag_now
->fr_literal
+ 1,
1774 else if (x
& ABSJMP
)
1777 bfd_reloc_code_real_type reloc_type
= R_JMPL1
;
1780 /* To be compatible with the proposed H8 ELF format, we
1781 want the relocation's offset to point to the first byte
1782 that will be modified, not to the start of the instruction. */
1784 if ((operand
->mode
& SIZE
) == L_32
)
1787 reloc_type
= R_RELLONG
;
1793 /* This jmp may be a jump or a branch. */
1795 check_operand (operand
+ i
,
1796 SXmode
? 0xffffffff : Hmode
? 0xffffff : 0xffff,
1799 if (operand
[i
].exp
.X_add_number
& 1)
1800 as_warn (_("branch operand has odd offset (%lx)\n"),
1801 (unsigned long) operand
->exp
.X_add_number
);
1804 operand
[i
].exp
.X_add_number
=
1805 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1806 fix_new_exp (frag_now
,
1807 output
- frag_now
->fr_literal
+ where
,
1816 /* Try to give an intelligent error message for common and simple to
1820 clever_message (instruction
, operand
)
1821 const struct h8_instruction
*instruction
;
1822 struct h8_op
*operand
;
1824 /* Find out if there was more than one possible opcode. */
1826 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1830 /* Only one opcode of this flavour, try to guess which operand
1832 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1834 switch (instruction
->opcode
->args
.nib
[argn
])
1837 if (operand
[argn
].mode
!= RD16
)
1839 as_bad (_("destination operand must be 16 bit register"));
1846 if (operand
[argn
].mode
!= RS8
)
1848 as_bad (_("source operand must be 8 bit register"));
1854 if (operand
[argn
].mode
!= ABS16DST
)
1856 as_bad (_("destination operand must be 16bit absolute address"));
1861 if (operand
[argn
].mode
!= RD8
)
1863 as_bad (_("destination operand must be 8 bit register"));
1869 if (operand
[argn
].mode
!= ABS16SRC
)
1871 as_bad (_("source operand must be 16bit absolute address"));
1879 as_bad (_("invalid operands"));
1883 /* Adjust OPERAND's value and size given that it is accessing a field
1886 This function handles the choice between @(d:2,ERn) and @(d:16,ERn)
1887 when no size is explicitly given. It also scales down the assembly-level
1888 displacement in an @(d:2,ERn) operand. */
1891 fix_operand_size (operand
, size
)
1892 struct h8_op
*operand
;
1895 if ((operand
->mode
& MODE
) == DISP
)
1897 /* If the user didn't specify an operand width, see if we
1898 can use @(d:2,ERn). */
1900 && (operand
->mode
& SIZE
) == 0
1901 && (operand
->exp
.X_add_number
== size
1902 || operand
->exp
.X_add_number
== size
* 2
1903 || operand
->exp
.X_add_number
== size
* 3))
1904 operand
->mode
|= L_2
;
1906 /* Scale down the displacement in an @(d:2,ERn) operand.
1907 X_add_number then contains the desired field value. */
1908 if ((operand
->mode
& SIZE
) == L_2
)
1910 if (operand
->exp
.X_add_number
% size
!= 0)
1911 as_warn (_("operand/size mis-match"));
1912 operand
->exp
.X_add_number
/= size
;
1916 /* If the operand needs a size but doesn't have one yet, it must be
1917 a 16-bit integer (see colonmod24). */
1918 if ((operand
->mode
& SIZE
) == 0)
1919 switch (operand
->mode
& MODE
)
1926 operand
->mode
|= L_16
;
1932 /* This is the guts of the machine-dependent assembler. STR points to
1933 a machine dependent instruction. This function is supposed to emit
1934 the frags/bytes it assembles. */
1942 struct h8_op operand
[3];
1943 const struct h8_instruction
*instruction
;
1944 const struct h8_instruction
*prev_instruction
;
1950 /* Drop leading whitespace. */
1954 /* Find the op code end. */
1955 for (op_start
= op_end
= str
;
1956 *op_end
!= 0 && *op_end
!= ' ';
1968 if (op_end
== op_start
)
1970 as_bad (_("can't find opcode "));
1976 instruction
= (const struct h8_instruction
*)
1977 hash_find (opcode_hash_control
, op_start
);
1979 if (instruction
== NULL
)
1981 as_bad (_("unknown opcode"));
1985 /* We used to set input_line_pointer to the result of get_operands,
1986 but that is wrong. Our caller assumes we don't change it. */
1988 operand
[0].mode
= 0;
1989 operand
[1].mode
= 0;
1990 operand
[2].mode
= 0;
1992 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
1993 || OP_KIND (instruction
->opcode
->how
) == O_MOVAW
1994 || OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
1995 get_mova_operands (op_end
, operand
);
1996 else if (OP_KIND (instruction
->opcode
->how
) == O_RTEL
1997 || OP_KIND (instruction
->opcode
->how
) == O_RTSL
)
1998 get_rtsl_operands (op_end
, operand
);
2000 get_operands (instruction
->noperands
, op_end
, operand
);
2003 prev_instruction
= instruction
;
2023 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
||
2024 OP_KIND (instruction
->opcode
->how
) == O_MOVAW
||
2025 OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
2027 switch (operand
[0].mode
& MODE
)
2031 fix_operand_size (&operand
[1], 1);
2034 fix_operand_size (&operand
[1], 2);
2037 fix_operand_size (&operand
[1], 4);
2043 for (i
= 0; i
< 3 && operand
[i
].mode
!= 0; i
++)
2049 fix_operand_size (&operand
[i
], 1);
2052 fix_operand_size (&operand
[i
], 2);
2055 fix_operand_size (&operand
[i
], 4);
2060 instruction
= get_specific (instruction
, operand
, size
);
2062 if (instruction
== 0)
2064 /* Couldn't find an opcode which matched the operands. */
2065 char *where
= frag_more (2);
2069 clever_message (prev_instruction
, operand
);
2074 build_bytes (instruction
, operand
);
2076 #ifdef BFD_ASSEMBLER
2077 dwarf2_emit_insn (instruction
->length
);
2081 #ifndef BFD_ASSEMBLER
2083 tc_crawl_symbol_chain (headers
)
2084 object_headers
*headers ATTRIBUTE_UNUSED
;
2086 printf (_("call to tc_crawl_symbol_chain \n"));
2091 md_undefined_symbol (name
)
2092 char *name ATTRIBUTE_UNUSED
;
2097 #ifndef BFD_ASSEMBLER
2099 tc_headers_hook (headers
)
2100 object_headers
*headers ATTRIBUTE_UNUSED
;
2102 printf (_("call to tc_headers_hook \n"));
2106 /* Various routines to kill one day */
2107 /* Equal to MAX_PRECISION in atof-ieee.c */
2108 #define MAX_LITTLENUMS 6
2110 /* Turn a string in input_line_pointer into a floating point constant
2111 of type TYPE, and store the appropriate bytes in *LITP. The number
2112 of LITTLENUMS emitted is stored in *SIZEP. An error message is
2113 returned, or NULL on OK. */
2116 md_atof (type
, litP
, sizeP
)
2122 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2123 LITTLENUM_TYPE
*wordP
;
2154 return _("Bad call to MD_ATOF()");
2156 t
= atof_ieee (input_line_pointer
, type
, words
);
2158 input_line_pointer
= t
;
2160 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2161 for (wordP
= words
; prec
--;)
2163 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2164 litP
+= sizeof (LITTLENUM_TYPE
);
2169 const char *md_shortopts
= "";
2170 struct option md_longopts
[] = {
2171 {NULL
, no_argument
, NULL
, 0}
2174 size_t md_longopts_size
= sizeof (md_longopts
);
2177 md_parse_option (c
, arg
)
2178 int c ATTRIBUTE_UNUSED
;
2179 char *arg ATTRIBUTE_UNUSED
;
2185 md_show_usage (stream
)
2186 FILE *stream ATTRIBUTE_UNUSED
;
2190 void tc_aout_fix_to_chars
PARAMS ((void));
2193 tc_aout_fix_to_chars ()
2195 printf (_("call to tc_aout_fix_to_chars \n"));
2200 md_convert_frag (headers
, seg
, fragP
)
2201 #ifdef BFD_ASSEMBLER
2202 bfd
*headers ATTRIBUTE_UNUSED
;
2204 object_headers
*headers ATTRIBUTE_UNUSED
;
2206 segT seg ATTRIBUTE_UNUSED
;
2207 fragS
*fragP ATTRIBUTE_UNUSED
;
2209 printf (_("call to md_convert_frag \n"));
2213 #ifdef BFD_ASSEMBLER
2215 md_section_align (segment
, size
)
2219 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2220 return ((size
+ (1 << align
) - 1) & (-1 << align
));
2224 md_section_align (seg
, size
)
2228 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
2229 & (-1 << section_alignment
[(int) seg
]));
2235 md_apply_fix3 (fixP
, valP
, seg
)
2238 segT seg ATTRIBUTE_UNUSED
;
2240 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2243 switch (fixP
->fx_size
)
2249 *buf
++ = (val
>> 8);
2253 *buf
++ = (val
>> 24);
2254 *buf
++ = (val
>> 16);
2255 *buf
++ = (val
>> 8);
2262 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
2267 md_estimate_size_before_relax (fragP
, segment_type
)
2268 register fragS
*fragP ATTRIBUTE_UNUSED
;
2269 register segT segment_type ATTRIBUTE_UNUSED
;
2271 printf (_("call tomd_estimate_size_before_relax \n"));
2275 /* Put number into target byte order. */
2277 md_number_to_chars (ptr
, use
, nbytes
)
2282 number_to_chars_bigendian (ptr
, use
, nbytes
);
2286 md_pcrel_from (fixP
)
2287 fixS
*fixP ATTRIBUTE_UNUSED
;
2292 #ifndef BFD_ASSEMBLER
2294 tc_reloc_mangle (fix_ptr
, intr
, base
)
2296 struct internal_reloc
*intr
;
2300 symbolS
*symbol_ptr
;
2302 symbol_ptr
= fix_ptr
->fx_addsy
;
2304 /* If this relocation is attached to a symbol then it's ok
2306 if (fix_ptr
->fx_r_type
== TC_CONS_RELOC
)
2308 /* cons likes to create reloc32's whatever the size of the reloc..
2310 switch (fix_ptr
->fx_size
)
2313 intr
->r_type
= R_RELLONG
;
2316 intr
->r_type
= R_RELWORD
;
2319 intr
->r_type
= R_RELBYTE
;
2327 intr
->r_type
= fix_ptr
->fx_r_type
;
2330 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
2331 intr
->r_offset
= fix_ptr
->fx_offset
;
2335 if (symbol_ptr
->sy_number
!= -1)
2336 intr
->r_symndx
= symbol_ptr
->sy_number
;
2341 /* This case arises when a reference is made to `.'. */
2342 segsym
= seg_info (S_GET_SEGMENT (symbol_ptr
))->dot
;
2344 intr
->r_symndx
= -1;
2347 intr
->r_symndx
= segsym
->sy_number
;
2348 intr
->r_offset
+= S_GET_VALUE (symbol_ptr
);
2353 intr
->r_symndx
= -1;
2355 #else /* BFD_ASSEMBLER */
2357 tc_gen_reloc (section
, fixp
)
2358 asection
*section ATTRIBUTE_UNUSED
;
2362 bfd_reloc_code_real_type r_type
;
2364 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2366 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2367 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2369 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2370 "Difference of symbols in different sections is not supported");
2375 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2376 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2377 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2378 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2379 rel
->addend
= fixp
->fx_offset
;
2381 r_type
= fixp
->fx_r_type
;
2385 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
2388 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
2389 if (rel
->howto
== NULL
)
2391 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2392 _("Cannot represent relocation type %s"),
2393 bfd_get_reloc_code_name (r_type
));