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"));
148 int arg ATTRIBUTE_UNUSED
;
150 cons (Hmode
? 4 : 2);
153 /* This table describes all the machine specific pseudo-ops the assembler
154 has to support. The fields are:
155 pseudo-op name without dot
156 function to call to execute this pseudo-op
157 Integer arg to pass to the function. */
159 const pseudo_typeS md_pseudo_table
[] =
161 {"h8300h", h8300hmode
, 0},
162 {"h8300hn", h8300hnmode
, 0},
163 {"h8300s", h8300smode
, 0},
164 {"h8300sn", h8300snmode
, 0},
165 {"h8300sx", h8300sxmode
, 0},
166 {"sbranch", sbranch
, L_8
},
167 {"lbranch", sbranch
, L_16
},
173 {"form", listing_psize
, 0},
174 {"heading", listing_title
, 0},
175 {"import", s_ignore
, 0},
176 {"page", listing_eject
, 0},
177 {"program", s_ignore
, 0},
181 const int md_reloc_size
;
183 const char EXP_CHARS
[] = "eE";
185 /* Chars that mean this number is a floating point constant
188 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
190 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
192 /* This function is called once, at assembler startup time. This
193 should set up all the tables, etc. that the MD part of the assembler
199 unsigned int nopcodes
;
200 struct h8_opcode
*p
, *p1
;
201 struct h8_instruction
*pi
;
202 char prev_buffer
[100];
206 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
207 as_warn (_("could not set architecture and machine"));
210 opcode_hash_control
= hash_new ();
213 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
215 h8_instructions
= (struct h8_instruction
*)
216 xmalloc (nopcodes
* sizeof (struct h8_instruction
));
218 pi
= h8_instructions
;
220 /* We do a minimum amount of sorting on the opcode table; this is to
221 make it easy to describe the mova instructions without unnecessary
223 Sorting only takes place inside blocks of instructions of the form
224 X/Y, so for example mova/b, mova/w and mova/l can be intermixed. */
227 struct h8_opcode
*first_skipped
= 0;
229 char *src
= p1
->name
;
234 /* Strip off any . part when inserting the opcode and only enter
235 unique codes into the hash table. */
236 dst
= buffer
= malloc (strlen (src
) + 1);
245 cmplen
= src
- p1
->name
+ 1;
252 hash_insert (opcode_hash_control
, buffer
, (char *) pi
);
253 strcpy (prev_buffer
, buffer
);
256 for (p
= p1
; p
->name
; p
++)
258 /* A negative TIME is used to indicate that we've added this opcode
262 if (strncmp (p
->name
, buffer
, cmplen
) != 0
263 || (p
->name
[cmplen
] != '\0' && p
->name
[cmplen
] != '.'
264 && p
->name
[cmplen
- 1] != '/'))
266 if (first_skipped
== 0)
270 if (strncmp (p
->name
, buffer
, len
) != 0)
272 if (first_skipped
== 0)
278 pi
->size
= p
->name
[len
] == '.' ? p
->name
[len
+ 1] : 0;
281 /* Find the number of operands. */
283 while (pi
->noperands
< 3 && p
->args
.nib
[pi
->noperands
] != (op_type
) E
)
286 /* Find the length of the opcode in bytes. */
288 while (p
->data
.nib
[pi
->length
* 2] != (op_type
) E
)
297 /* Add entry for the NULL vector terminator. */
321 static void clever_message
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
322 static void fix_operand_size
PARAMS ((struct h8_op
*, int));
323 static void build_bytes
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
324 static void do_a_fix_imm
PARAMS ((int, int, struct h8_op
*, int));
325 static void check_operand
PARAMS ((struct h8_op
*, unsigned int, char *));
326 static const struct h8_instruction
* get_specific
PARAMS ((const struct h8_instruction
*, struct h8_op
*, int));
327 static char * get_operands
PARAMS ((unsigned, char *, struct h8_op
*));
328 static void get_operand
PARAMS ((char **, struct h8_op
*, int));
329 static char * skip_colonthing
PARAMS ((char *, expressionS
*, int *));
330 static char * parse_exp
PARAMS ((char *, expressionS
*));
331 static int parse_reg
PARAMS ((char *, op_type
*, unsigned *, int));
332 char * colonmod24
PARAMS ((struct h8_op
*, char *));
334 static int constant_fits_width_p
PARAMS ((struct h8_op
*, unsigned int));
335 static int constant_fits_size_p
PARAMS ((struct h8_op
*, int, int));
339 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
348 /* Try to parse a reg name. Return the number of chars consumed. */
351 parse_reg (src
, mode
, reg
, direction
)
360 /* Cribbed from get_symbol_end. */
361 if (!is_name_beginner (*src
) || *src
== '\001')
364 while ((is_part_of_name (*end
) && *end
!= '.') || *end
== '\001')
368 if (len
== 2 && TOLOWER (src
[0]) == 's' && TOLOWER (src
[1]) == 'p')
370 *mode
= PSIZE
| REG
| direction
;
375 TOLOWER (src
[0]) == 'c' &&
376 TOLOWER (src
[1]) == 'c' &&
377 TOLOWER (src
[2]) == 'r')
384 TOLOWER (src
[0]) == 'e' &&
385 TOLOWER (src
[1]) == 'x' &&
386 TOLOWER (src
[2]) == 'r')
393 TOLOWER (src
[0]) == 'v' &&
394 TOLOWER (src
[1]) == 'b' &&
395 TOLOWER (src
[2]) == 'r')
402 TOLOWER (src
[0]) == 's' &&
403 TOLOWER (src
[1]) == 'b' &&
404 TOLOWER (src
[2]) == 'r')
410 if (len
== 2 && TOLOWER (src
[0]) == 'f' && TOLOWER (src
[1]) == 'p')
412 *mode
= PSIZE
| REG
| direction
;
416 if (len
== 3 && TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
417 src
[2] >= '0' && src
[2] <= '7')
419 *mode
= L_32
| REG
| direction
;
422 as_warn (_("Reg not valid for H8/300"));
425 if (len
== 2 && TOLOWER (src
[0]) == 'e' && src
[1] >= '0' && src
[1] <= '7')
427 *mode
= L_16
| REG
| direction
;
428 *reg
= src
[1] - '0' + 8;
430 as_warn (_("Reg not valid for H8/300"));
434 if (TOLOWER (src
[0]) == 'r')
436 if (src
[1] >= '0' && src
[1] <= '7')
438 if (len
== 3 && TOLOWER (src
[2]) == 'l')
440 *mode
= L_8
| REG
| direction
;
441 *reg
= (src
[1] - '0') + 8;
444 if (len
== 3 && TOLOWER (src
[2]) == 'h')
446 *mode
= L_8
| REG
| direction
;
447 *reg
= (src
[1] - '0');
452 *mode
= L_16
| REG
| direction
;
453 *reg
= (src
[1] - '0');
467 char *save
= input_line_pointer
;
470 input_line_pointer
= s
;
472 if (op
->X_op
== O_absent
)
473 as_bad (_("missing operand"));
474 new = input_line_pointer
;
475 input_line_pointer
= save
;
480 skip_colonthing (ptr
, exp
, mode
)
482 expressionS
*exp ATTRIBUTE_UNUSED
;
489 if (ptr
[0] == '8' && ! ISDIGIT (ptr
[1]))
491 else if (ptr
[0] == '2' && ! ISDIGIT (ptr
[1]))
493 else if (ptr
[0] == '3' && ! ISDIGIT (ptr
[1]))
495 else if (ptr
[0] == '4' && ! ISDIGIT (ptr
[1]))
497 else if (ptr
[0] == '5' && ! ISDIGIT (ptr
[1]))
499 else if (ptr
[0] == '2' && ptr
[1] == '4')
501 else if (ptr
[0] == '3' && ptr
[1] == '2')
503 else if (ptr
[0] == '1' && ptr
[1] == '6')
506 as_bad (_("invalid operand size requested"));
508 while (ISDIGIT (*ptr
))
514 /* The many forms of operand:
517 @Rn Register indirect
518 @(exp[:16], Rn) Register indirect with displacement
522 @aa:16 absolute 16 bit
525 #xx[:size] immediate data
526 @(exp:[8], pc) pc rel
527 @@aa[:8] memory indirect. */
535 src
= skip_colonthing (src
, &op
->exp
, &mode
);
539 /* If the operand is a 16-bit constant integer, leave fix_operand_size
540 to calculate its size. Otherwise choose a default here. */
541 if (op
->exp
.X_add_number
< -32768
542 || op
->exp
.X_add_number
> 32767)
549 else if (op
->exp
.X_add_symbol
550 || op
->exp
.X_op_symbol
)
559 constant_fits_width_p (operand
, width
)
560 struct h8_op
*operand
;
563 return ((operand
->exp
.X_add_number
& ~width
) == 0
564 || (operand
->exp
.X_add_number
| width
) == (unsigned)(~0));
568 constant_fits_size_p (operand
, size
, no_symbols
)
569 struct h8_op
*operand
;
570 int size
, no_symbols
;
572 offsetT num
= operand
->exp
.X_add_number
;
574 && (operand
->exp
.X_add_symbol
!= 0 || operand
->exp
.X_op_symbol
!= 0))
579 return (num
& ~3) == 0;
581 return (num
& ~7) == 0;
583 return num
>= 1 && num
< 8;
585 return (num
& ~15) == 0;
587 return num
>= 1 && num
< 32;
589 return (num
& ~0xFF) == 0 || ((unsigned)num
| 0x7F) == ~0u;
591 return (num
& ~0xFF) == 0;
593 return (num
& ~0xFFFF) == 0 || ((unsigned)num
| 0x7FFF) == ~0u;
595 return (num
& ~0xFFFF) == 0;
604 get_operand (ptr
, op
, direction
)
616 /* Check for '(' and ')' for instructions ldm and stm. */
617 if (src
[0] == '(' && src
[8] == ')')
620 /* Gross. Gross. ldm and stm have a format not easily handled
621 by get_operand. We deal with it explicitly here. */
622 if (TOLOWER (src
[0]) == 'e' && TOLOWER (src
[1]) == 'r' &&
623 ISDIGIT (src
[2]) && src
[3] == '-' &&
624 TOLOWER (src
[4]) == 'e' && TOLOWER (src
[5]) == 'r' && ISDIGIT (src
[6]))
632 as_bad (_("Invalid register list for ldm/stm\n"));
635 as_bad (_("Invalid register list for ldm/stm\n"));
638 as_bad (_("Invalid register list for ldm/stm)\n"));
640 /* Even sicker. We encode two registers into op->reg. One
641 for the low register to save, the other for the high
642 register to save; we also set the high bit in op->reg
643 so we know this is "very special". */
644 op
->reg
= 0x80000000 | (high
<< 8) | low
;
653 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
659 int size
= op
->mode
& SIZE
;
664 as_warn (_("mismatch between register and suffix"));
665 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
668 if (size
!= L_32
&& size
!= L_16
)
669 as_warn (_("mismatch between register and suffix"));
670 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
671 op
->mode
= (op
->mode
& ~SIZE
) | L_16
;
674 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
675 if (size
!= L_32
&& size
!= L_8
)
676 as_warn (_("mismatch between register and suffix"));
677 op
->mode
= (op
->mode
& ~MODE
) | LOWREG
;
678 op
->mode
= (op
->mode
& ~SIZE
) | L_8
;
681 as_warn ("invalid suffix after register.");
696 src
= parse_exp (src
, &op
->exp
);
698 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
702 if (op
->exp
.X_add_number
>= 0x100)
707 /* FIXME : 2? or 4? */
708 if (op
->exp
.X_add_number
>= 0x400)
709 as_bad (_("address too high for vector table jmp/jsr"));
710 else if (op
->exp
.X_add_number
>= 0x200)
715 op
->exp
.X_add_number
= op
->exp
.X_add_number
/ divisor
- 0x80;
723 if (*src
== '-' || *src
== '+')
727 len
= parse_reg (src
, &mode
, &num
, direction
);
730 /* Oops, not a reg after all, must be ordinary exp. */
732 /* Must be a symbol. */
733 op
->mode
= ABS
| PSIZE
| direction
;
734 *ptr
= skip_colonthing (parse_exp (src
, &op
->exp
),
735 &op
->exp
, &op
->mode
);
740 if ((mode
& SIZE
) != PSIZE
)
741 as_bad (_("Wrong size pointer register for architecture."));
742 op
->mode
= c
== '-' ? RDPREDEC
: RDPREINC
;
751 /* See if this is @(ERn.x, PC). */
752 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
753 if (len
!= 0 && (mode
& MODE
) == REG
&& src
[len
] == '.')
755 switch (TOLOWER (src
[len
+ 1]))
758 mode
= PCIDXB
| direction
;
761 mode
= PCIDXW
| direction
;
764 mode
= PCIDXL
| direction
;
771 && src
[len
+ 2] == ','
772 && TOLOWER (src
[len
+ 3]) != 'p'
773 && TOLOWER (src
[len
+ 4]) != 'c'
774 && src
[len
+ 5] != ')')
776 *ptr
= src
+ len
+ 6;
780 /* Fall through into disp case - the grammar is somewhat
781 ambiguous, so we should try whether it's a DISP operand
782 after all ("ER3.L" might be a poorly named label...). */
787 /* Start off assuming a 16 bit offset. */
789 src
= parse_exp (src
, &op
->exp
);
791 src
= colonmod24 (op
, src
);
796 op
->mode
|= ABS
| direction
;
803 as_bad (_("expected @(exp, reg16)"));
809 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
810 if (len
== 0 || (mode
& MODE
) != REG
)
812 as_bad (_("expected @(exp, reg16)"));
818 switch (TOLOWER (src
[1]))
821 op
->mode
|= INDEXB
| direction
;
824 op
->mode
|= INDEXW
| direction
;
827 op
->mode
|= INDEXL
| direction
;
830 as_bad (_("expected .L, .W or .B for register in indexed addressing mode"));
836 op
->mode
|= DISP
| direction
;
837 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
839 if (*src
!= ')' && '(')
841 as_bad (_("expected @(exp, reg16)"));
848 len
= parse_reg (src
, &mode
, &num
, direction
);
853 if (*src
== '+' || *src
== '-')
855 if ((mode
& SIZE
) != PSIZE
)
856 as_bad (_("Wrong size pointer register for architecture."));
857 op
->mode
= *src
== '+' ? RSPOSTINC
: RSPOSTDEC
;
863 if ((mode
& SIZE
) != PSIZE
)
864 as_bad (_("Wrong size pointer register for architecture."));
866 op
->mode
= direction
| IND
| PSIZE
;
874 /* must be a symbol */
876 op
->mode
= ABS
| direction
;
877 src
= parse_exp (src
, &op
->exp
);
879 *ptr
= colonmod24 (op
, src
);
889 src
= parse_exp (src
, &op
->exp
);
890 *ptr
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
894 else if (strncmp (src
, "mach", 4) == 0 ||
895 strncmp (src
, "macl", 4) == 0 ||
896 strncmp (src
, "MACH", 4) == 0 ||
897 strncmp (src
, "MACL", 4) == 0)
899 op
->reg
= TOLOWER (src
[3]) == 'l';
906 src
= parse_exp (src
, &op
->exp
);
907 /* Trailing ':' size ? */
910 if (src
[1] == '1' && src
[2] == '6')
912 op
->mode
= PCREL
| L_16
;
915 else if (src
[1] == '8')
917 op
->mode
= PCREL
| L_8
;
921 as_bad (_("expect :8 or :16 here"));
925 int val
= op
->exp
.X_add_number
;
928 if (-128 < val
&& val
< 127)
939 get_operands (noperands
, op_end
, operand
)
940 unsigned int noperands
;
942 struct h8_op
*operand
;
953 get_operand (&ptr
, operand
+ 0, SRC
);
957 get_operand (&ptr
, operand
+ 1, DST
);
963 get_operand (&ptr
, operand
+ 0, SRC
);
966 get_operand (&ptr
, operand
+ 1, DST
);
971 get_operand (&ptr
, operand
+ 0, SRC
);
974 get_operand (&ptr
, operand
+ 1, DST
);
977 get_operand (&ptr
, operand
+ 2, OP3
);
987 /* MOVA has special requirements. Rather than adding twice the amount of
988 addressing modes, we simply special case it a bit. */
990 get_mova_operands (char *op_end
, struct h8_op
*operand
)
994 if (ptr
[1] != '@' || ptr
[2] != '(')
998 ptr
= parse_exp (ptr
, &operand
[0].exp
);
999 ptr
= colonmod24 (operand
+ 0, ptr
);
1004 get_operand (&ptr
, operand
+ 1, DST
);
1012 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
1015 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
1018 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
1024 else if ((operand
[1].mode
& MODE
) == LOWREG
)
1026 switch (operand
[1].mode
& SIZE
)
1029 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXB
;
1032 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXW
;
1035 operand
[0].mode
= (operand
[0].mode
& ~MODE
) | INDEXL
;
1044 if (*ptr
++ != ')' || *ptr
++ != ',')
1046 get_operand (&ptr
, operand
+ 2, OP3
);
1047 /* See if we can use the short form of MOVA. */
1048 if (((operand
[1].mode
& MODE
) == REG
|| (operand
[1].mode
& MODE
) == LOWREG
)
1049 && (operand
[2].mode
& MODE
) == REG
1050 && (operand
[1].reg
& 7) == (operand
[2].reg
& 7))
1052 operand
[1].mode
= operand
[2].mode
= 0;
1053 operand
[0].reg
= operand
[2].reg
& 7;
1058 as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
1063 get_rtsl_operands (char *ptr
, struct h8_op
*operand
)
1065 int mode
, num
, num2
, len
, type
= 0;
1073 len
= parse_reg (ptr
, &mode
, &num
, SRC
);
1074 if (len
== 0 || (mode
& MODE
) != REG
)
1076 as_bad (_("expected register"));
1084 as_bad (_("expected register list"));
1087 len
= parse_reg (ptr
, &mode
, &num2
, SRC
);
1088 if (len
== 0 || (mode
& MODE
) != REG
)
1090 as_bad (_("expected register"));
1096 as_bad (_("expected closing paren"));
1099 /* CONST_xxx are used as placeholders in the opcode table. */
1101 if (num
< 1 || num
> 3)
1103 as_bad (_("invalid register list"));
1108 num2
= num
, num
= 0;
1109 operand
[0].mode
= RS32
;
1110 operand
[1].mode
= RD32
;
1111 operand
[0].reg
= num
;
1112 operand
[1].reg
= num2
;
1115 /* Passed a pointer to a list of opcodes which use different
1116 addressing modes, return the opcode which matches the opcodes
1119 static const struct h8_instruction
*
1120 get_specific (instruction
, operands
, size
)
1121 const struct h8_instruction
*instruction
;
1122 struct h8_op
*operands
;
1125 const struct h8_instruction
*this_try
= instruction
;
1126 const struct h8_instruction
*found_other
= 0, *found_mismatched
= 0;
1128 int this_index
= instruction
->idx
;
1131 /* There's only one ldm/stm and it's easier to just
1132 get out quick for them. */
1133 if (OP_KIND (instruction
->opcode
->how
) == O_LDM
1134 || OP_KIND (instruction
->opcode
->how
) == O_STM
)
1137 while (noperands
< 3 && operands
[noperands
].mode
!= 0)
1140 while (this_index
== instruction
->idx
&& !found
)
1145 this_try
= instruction
++;
1146 this_size
= this_try
->opcode
->how
& SN
;
1148 if (this_try
->noperands
!= noperands
)
1150 else if (this_try
->noperands
> 0)
1154 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
1156 op_type op
= this_try
->opcode
->args
.nib
[i
];
1157 int op_mode
= op
& MODE
;
1158 int op_size
= op
& SIZE
;
1159 int x
= operands
[i
].mode
;
1160 int x_mode
= x
& MODE
;
1161 int x_size
= x
& SIZE
;
1163 if (op_mode
== LOWREG
&& (x_mode
== REG
|| x_mode
== LOWREG
))
1165 if ((x_size
== L_8
&& (operands
[i
].reg
& 8) == 0)
1166 || (x_size
== L_16
&& (operands
[i
].reg
& 8) == 8))
1167 as_warn (_("can't use high part of register in operand %d"), i
);
1169 if (x_size
!= op_size
)
1172 else if (op_mode
== REG
)
1174 if (x_mode
== LOWREG
)
1180 x_size
= (Hmode
? L_32
: L_16
);
1182 op_size
= (Hmode
? L_32
: L_16
);
1184 /* The size of the reg is v important. */
1185 if (op_size
!= x_size
)
1188 else if (op_mode
& CTRL
) /* control register */
1190 if (!(x_mode
& CTRL
))
1196 if (op_mode
!= CCR
&&
1197 op_mode
!= CCR_EXR
&&
1198 op_mode
!= CC_EX_VB_SB
)
1202 if (op_mode
!= EXR
&&
1203 op_mode
!= CCR_EXR
&&
1204 op_mode
!= CC_EX_VB_SB
)
1208 if (op_mode
!= MACH
&&
1213 if (op_mode
!= MACL
&&
1218 if (op_mode
!= VBR
&&
1219 op_mode
!= VBR_SBR
&&
1220 op_mode
!= CC_EX_VB_SB
)
1224 if (op_mode
!= SBR
&&
1225 op_mode
!= VBR_SBR
&&
1226 op_mode
!= CC_EX_VB_SB
)
1231 else if ((op
& ABSJMP
) && (x_mode
== ABS
|| x_mode
== PCREL
))
1233 operands
[i
].mode
&= ~MODE
;
1234 operands
[i
].mode
|= ABSJMP
;
1235 /* But it may not be 24 bits long. */
1236 if (x_mode
== ABS
&& !Hmode
)
1238 operands
[i
].mode
&= ~SIZE
;
1239 operands
[i
].mode
|= L_16
;
1241 if ((operands
[i
].mode
& SIZE
) == L_32
1242 && (op_mode
& SIZE
) != L_32
)
1245 else if (x_mode
== IMM
&& op_mode
!= IMM
)
1247 offsetT num
= operands
[i
].exp
.X_add_number
;
1248 if (op_mode
== KBIT
|| op_mode
== DBIT
)
1249 /* This is ok if the immediate value is sensible. */;
1250 else if (op_mode
== CONST_2
)
1252 else if (op_mode
== CONST_4
)
1254 else if (op_mode
== CONST_8
)
1256 else if (op_mode
== CONST_16
)
1261 else if (op_mode
== PCREL
&& op_mode
== x_mode
)
1263 /* movsd only comes in PCREL16 flavour:
1264 If x_size is L_8, promote it. */
1265 if (OP_KIND (this_try
->opcode
->how
) == O_MOVSD
)
1269 /* The size of the displacement is important. */
1270 if (op_size
!= x_size
)
1273 else if ((op_mode
== DISP
|| op_mode
== IMM
|| op_mode
== ABS
1274 || op_mode
== INDEXB
|| op_mode
== INDEXW
1275 || op_mode
== INDEXL
)
1276 && op_mode
== x_mode
)
1278 /* Promote a L_24 to L_32 if it makes us match. */
1279 if (x_size
== L_24
&& op_size
== L_32
)
1286 /* Promote an L8 to L_16 if it makes us match. */
1287 if ((op_mode
== ABS
|| op_mode
== DISP
) && x_size
== L_8
)
1289 if (op_size
== L_16
)
1294 if (((x_size
== L_16
&& op_size
== L_16U
)
1295 || (x_size
== L_3
&& op_size
== L_3NZ
))
1296 /* We're deliberately more permissive for ABS modes. */
1298 || constant_fits_size_p (operands
+ i
, op_size
,
1302 if (x_size
!= 0 && op_size
!= x_size
)
1304 else if (x_size
== 0
1305 && ! constant_fits_size_p (operands
+ i
, op_size
,
1309 else if (op_mode
!= x_mode
)
1317 if ((this_try
->opcode
->available
== AV_H8SX
&& ! SXmode
)
1318 || (this_try
->opcode
->available
== AV_H8S
&& ! Smode
)
1319 || (this_try
->opcode
->available
== AV_H8H
&& ! Hmode
))
1320 found
= 0, found_other
= this_try
;
1321 else if (this_size
!= size
&& (this_size
!= SN
&& size
!= SN
))
1322 found_mismatched
= this_try
, found
= 0;
1330 as_warn (_("Opcode `%s' with these operand types not available in %s mode"),
1331 found_other
->opcode
->name
,
1332 (! Hmode
&& ! Smode
? "H8/300"
1337 else if (found_mismatched
)
1339 as_warn (_("mismatch between opcode size and operand size"));
1340 return found_mismatched
;
1346 check_operand (operand
, width
, string
)
1347 struct h8_op
*operand
;
1351 if (operand
->exp
.X_add_symbol
== 0
1352 && operand
->exp
.X_op_symbol
== 0)
1354 /* No symbol involved, let's look at offset, it's dangerous if
1355 any of the high bits are not 0 or ff's, find out by oring or
1356 anding with the width and seeing if the answer is 0 or all
1359 if (! constant_fits_width_p (operand
, width
))
1362 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
1364 /* Just ignore this one - which happens when trying to
1365 fit a 16 bit address truncated into an 8 bit address
1366 of something like bset. */
1368 else if (strcmp (string
, "@") == 0
1370 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
1372 /* Just ignore this one - which happens when trying to
1373 fit a 24 bit address truncated into a 16 bit address
1374 of something like mov.w. */
1378 as_warn (_("operand %s0x%lx out of range."), string
,
1379 (unsigned long) operand
->exp
.X_add_number
);
1385 /* RELAXMODE has one of 3 values:
1387 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
1389 1 Output a relaxable 24bit absolute mov.w address relocation
1390 (may relax into a 16bit absolute address).
1392 2 Output a relaxable 16/24 absolute mov.b address relocation
1393 (may relax into an 8bit absolute address). */
1396 do_a_fix_imm (offset
, nibble
, operand
, relaxmode
)
1398 struct h8_op
*operand
;
1404 char *bytes
= frag_now
->fr_literal
+ offset
;
1406 char *t
= ((operand
->mode
& MODE
) == IMM
) ? "#" : "@";
1408 if (operand
->exp
.X_add_symbol
== 0)
1410 switch (operand
->mode
& SIZE
)
1413 check_operand (operand
, 0x3, t
);
1414 bytes
[0] |= (operand
->exp
.X_add_number
& 3) << (nibble
? 0 : 4);
1418 check_operand (operand
, 0x7, t
);
1419 bytes
[0] |= (operand
->exp
.X_add_number
& 7) << (nibble
? 0 : 4);
1422 check_operand (operand
, 0xF, t
);
1423 bytes
[0] |= (operand
->exp
.X_add_number
& 15) << (nibble
? 0 : 4);
1426 check_operand (operand
, 0x1F, t
);
1427 bytes
[0] |= operand
->exp
.X_add_number
& 31;
1431 check_operand (operand
, 0xff, t
);
1432 bytes
[0] |= operand
->exp
.X_add_number
;
1436 check_operand (operand
, 0xffff, t
);
1437 bytes
[0] |= operand
->exp
.X_add_number
>> 8;
1438 bytes
[1] |= operand
->exp
.X_add_number
>> 0;
1441 check_operand (operand
, 0xffffff, t
);
1442 bytes
[0] |= operand
->exp
.X_add_number
>> 16;
1443 bytes
[1] |= operand
->exp
.X_add_number
>> 8;
1444 bytes
[2] |= operand
->exp
.X_add_number
>> 0;
1448 /* This should be done with bfd. */
1449 bytes
[0] |= operand
->exp
.X_add_number
>> 24;
1450 bytes
[1] |= operand
->exp
.X_add_number
>> 16;
1451 bytes
[2] |= operand
->exp
.X_add_number
>> 8;
1452 bytes
[3] |= operand
->exp
.X_add_number
>> 0;
1455 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
1456 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
1463 switch (operand
->mode
& SIZE
)
1468 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
1471 else if (relaxmode
== 1)
1477 as_bad (_("Can't work out size of operand.\n"));
1486 operand
->exp
.X_add_number
=
1487 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1488 operand
->exp
.X_add_number
|= (bytes
[0] << 8) | bytes
[1];
1494 operand
->exp
.X_add_number
=
1495 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1496 operand
->exp
.X_add_number
|= bytes
[0];
1499 fix_new_exp (frag_now
,
1508 /* Now we know what sort of opcodes it is, let's build the bytes. */
1511 build_bytes (this_try
, operand
)
1512 const struct h8_instruction
*this_try
;
1513 struct h8_op
*operand
;
1516 char *output
= frag_more (this_try
->length
);
1517 op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1519 unsigned int nibble_count
= 0;
1523 char asnibbles
[100];
1524 char *p
= asnibbles
;
1527 if (!Hmode
&& this_try
->opcode
->available
!= AV_H8
)
1528 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1529 this_try
->opcode
->name
);
1531 && this_try
->opcode
->available
!= AV_H8
1532 && this_try
->opcode
->available
!= AV_H8H
)
1533 as_warn (_("Opcode `%s' with these operand types not available in H8/300H mode"),
1534 this_try
->opcode
->name
);
1536 && this_try
->opcode
->available
!= AV_H8
1537 && this_try
->opcode
->available
!= AV_H8H
1538 && this_try
->opcode
->available
!= AV_H8S
)
1539 as_warn (_("Opcode `%s' with these operand types not available in H8/300S mode"),
1540 this_try
->opcode
->name
);
1542 while (*nibble_ptr
!= (op_type
) E
)
1549 d
= (c
& OP3
) == OP3
? 2 : (c
& DST
) == DST
? 1 : 0;
1557 if (c2
== REG
|| c2
== LOWREG
1558 || c2
== IND
|| c2
== PREINC
|| c2
== PREDEC
1559 || c2
== POSTINC
|| c2
== POSTDEC
)
1561 nib
= operand
[d
].reg
;
1566 else if (c
& CTRL
) /* Control reg operand. */
1567 nib
= operand
[d
].reg
;
1569 else if ((c
& DISPREG
) == (DISPREG
))
1571 nib
= operand
[d
].reg
;
1575 operand
[d
].mode
= c
;
1576 op_at
[d
] = nibble_count
;
1579 else if (c2
== IMM
|| c2
== PCREL
|| c2
== ABS
1580 || (c
& ABSJMP
) || c2
== DISP
)
1582 operand
[d
].mode
= c
;
1583 op_at
[d
] = nibble_count
;
1586 else if ((c
& IGNORE
) || (c
& DATA
))
1589 else if (c2
== DBIT
)
1591 switch (operand
[0].exp
.X_add_number
)
1600 as_bad (_("Need #1 or #2 here"));
1603 else if (c2
== KBIT
)
1605 switch (operand
[0].exp
.X_add_number
)
1615 as_warn (_("#4 not valid on H8/300."));
1620 as_bad (_("Need #1 or #2 here"));
1623 /* Stop it making a fix. */
1624 operand
[0].mode
= 0;
1628 operand
[d
].mode
|= MEMRELAX
;
1644 if (operand
[0].mode
== MACREG
)
1645 /* stmac has mac[hl] as the first operand. */
1646 nib
= 2 + operand
[0].reg
;
1648 /* ldmac has mac[hl] as the second operand. */
1649 nib
= 2 + operand
[1].reg
;
1657 /* Disgusting. Why, oh why didn't someone ask us for advice
1658 on the assembler format. */
1659 if (OP_KIND (this_try
->opcode
->how
) == O_LDM
)
1661 high
= (operand
[1].reg
>> 8) & 0xf;
1662 low
= (operand
[1].reg
) & 0xf;
1663 asnibbles
[2] = high
- low
;
1664 asnibbles
[7] = high
;
1666 else if (OP_KIND (this_try
->opcode
->how
) == O_STM
)
1668 high
= (operand
[0].reg
>> 8) & 0xf;
1669 low
= (operand
[0].reg
) & 0xf;
1670 asnibbles
[2] = high
- low
;
1674 for (i
= 0; i
< this_try
->length
; i
++)
1675 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1677 /* Note if this is a movb instruction -- there's a special relaxation
1678 which only applies to them. */
1679 if (this_try
->opcode
->how
== O (O_MOV
, SB
))
1682 /* Output any fixes. */
1683 for (i
= 0; i
< this_try
->noperands
; i
++)
1685 int x
= operand
[i
].mode
;
1686 int x_mode
= x
& MODE
;
1688 if (x_mode
== IMM
|| x_mode
== DISP
)
1689 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1690 op_at
[i
] & 1, operand
+ i
, (x
& MEMRELAX
) != 0);
1692 else if (x_mode
== ABS
)
1693 do_a_fix_imm (output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1694 op_at
[i
] & 1, operand
+ i
,
1695 (x
& MEMRELAX
) ? movb
+ 1 : 0);
1697 else if (x_mode
== PCREL
)
1699 int size16
= (x
& SIZE
) == L_16
;
1700 int size
= size16
? 2 : 1;
1701 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1704 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1706 if (operand
[i
].exp
.X_add_number
& 1)
1707 as_warn (_("branch operand has odd offset (%lx)\n"),
1708 (unsigned long) operand
->exp
.X_add_number
);
1710 /* The COFF port has always been off by one, changing it
1711 now would be an incompatible change, so we leave it as-is.
1713 We don't want to do this for ELF as we want to be
1714 compatible with the proposed ELF format from Hitachi. */
1715 operand
[i
].exp
.X_add_number
-= 1;
1719 operand
[i
].exp
.X_add_number
=
1720 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1724 operand
[i
].exp
.X_add_number
=
1725 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1730 operand
[i
].exp
.X_add_number
|= output
[op_at
[i
] / 2];
1732 fixP
= fix_new_exp (frag_now
,
1733 output
- frag_now
->fr_literal
+ op_at
[i
] / 2,
1738 fixP
->fx_signed
= 1;
1740 else if (x_mode
== MEMIND
)
1742 check_operand (operand
+ i
, 0xff, "@@");
1743 fix_new_exp (frag_now
,
1744 output
- frag_now
->fr_literal
+ 1,
1750 else if (x_mode
== VECIND
)
1752 check_operand (operand
+ i
, 0x7f, "@@");
1753 /* FIXME: approximating the effect of "B31" here...
1754 This is very hackish, and ought to be done a better way. */
1755 operand
[i
].exp
.X_add_number
|= 0x80;
1756 fix_new_exp (frag_now
,
1757 output
- frag_now
->fr_literal
+ 1,
1763 else if (x
& ABSJMP
)
1766 bfd_reloc_code_real_type reloc_type
= R_JMPL1
;
1769 /* To be compatible with the proposed H8 ELF format, we
1770 want the relocation's offset to point to the first byte
1771 that will be modified, not to the start of the instruction. */
1773 if ((operand
->mode
& SIZE
) == L_32
)
1776 reloc_type
= R_RELLONG
;
1782 /* This jmp may be a jump or a branch. */
1784 check_operand (operand
+ i
,
1785 SXmode
? 0xffffffff : Hmode
? 0xffffff : 0xffff,
1788 if (operand
[i
].exp
.X_add_number
& 1)
1789 as_warn (_("branch operand has odd offset (%lx)\n"),
1790 (unsigned long) operand
->exp
.X_add_number
);
1793 operand
[i
].exp
.X_add_number
=
1794 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1795 fix_new_exp (frag_now
,
1796 output
- frag_now
->fr_literal
+ where
,
1805 /* Try to give an intelligent error message for common and simple to
1809 clever_message (instruction
, operand
)
1810 const struct h8_instruction
*instruction
;
1811 struct h8_op
*operand
;
1813 /* Find out if there was more than one possible opcode. */
1815 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1819 /* Only one opcode of this flavour, try to guess which operand
1821 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1823 switch (instruction
->opcode
->args
.nib
[argn
])
1826 if (operand
[argn
].mode
!= RD16
)
1828 as_bad (_("destination operand must be 16 bit register"));
1835 if (operand
[argn
].mode
!= RS8
)
1837 as_bad (_("source operand must be 8 bit register"));
1843 if (operand
[argn
].mode
!= ABS16DST
)
1845 as_bad (_("destination operand must be 16bit absolute address"));
1850 if (operand
[argn
].mode
!= RD8
)
1852 as_bad (_("destination operand must be 8 bit register"));
1858 if (operand
[argn
].mode
!= ABS16SRC
)
1860 as_bad (_("source operand must be 16bit absolute address"));
1868 as_bad (_("invalid operands"));
1872 /* Adjust OPERAND's value and size given that it is accessing a field
1875 This function handles the choice between @(d:2,ERn) and @(d:16,ERn)
1876 when no size is explicitly given. It also scales down the assembly-level
1877 displacement in an @(d:2,ERn) operand. */
1880 fix_operand_size (operand
, size
)
1881 struct h8_op
*operand
;
1884 if ((operand
->mode
& MODE
) == DISP
)
1886 /* If the user didn't specify an operand width, see if we
1887 can use @(d:2,ERn). */
1889 && (operand
->mode
& SIZE
) == 0
1890 && (operand
->exp
.X_add_number
== size
1891 || operand
->exp
.X_add_number
== size
* 2
1892 || operand
->exp
.X_add_number
== size
* 3))
1893 operand
->mode
|= L_2
;
1895 /* Scale down the displacement in an @(d:2,ERn) operand.
1896 X_add_number then contains the desired field value. */
1897 if ((operand
->mode
& SIZE
) == L_2
)
1899 if (operand
->exp
.X_add_number
% size
!= 0)
1900 as_warn (_("operand/size mis-match"));
1901 operand
->exp
.X_add_number
/= size
;
1905 /* If the operand needs a size but doesn't have one yet, it must be
1906 a 16-bit integer (see colonmod24). */
1907 if ((operand
->mode
& SIZE
) == 0)
1908 switch (operand
->mode
& MODE
)
1915 operand
->mode
|= L_16
;
1921 /* This is the guts of the machine-dependent assembler. STR points to
1922 a machine dependent instruction. This function is supposed to emit
1923 the frags/bytes it assembles. */
1931 struct h8_op operand
[3];
1932 const struct h8_instruction
*instruction
;
1933 const struct h8_instruction
*prev_instruction
;
1939 /* Drop leading whitespace. */
1943 /* Find the op code end. */
1944 for (op_start
= op_end
= str
;
1945 *op_end
!= 0 && *op_end
!= ' ';
1957 if (op_end
== op_start
)
1959 as_bad (_("can't find opcode "));
1965 instruction
= (const struct h8_instruction
*)
1966 hash_find (opcode_hash_control
, op_start
);
1968 if (instruction
== NULL
)
1970 as_bad (_("unknown opcode"));
1974 /* We used to set input_line_pointer to the result of get_operands,
1975 but that is wrong. Our caller assumes we don't change it. */
1977 operand
[0].mode
= 0;
1978 operand
[1].mode
= 0;
1979 operand
[2].mode
= 0;
1981 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
1982 || OP_KIND (instruction
->opcode
->how
) == O_MOVAW
1983 || OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
1984 get_mova_operands (op_end
, operand
);
1985 else if (OP_KIND (instruction
->opcode
->how
) == O_RTEL
1986 || OP_KIND (instruction
->opcode
->how
) == O_RTSL
)
1987 get_rtsl_operands (op_end
, operand
);
1989 get_operands (instruction
->noperands
, op_end
, operand
);
1992 prev_instruction
= instruction
;
2012 if (OP_KIND (instruction
->opcode
->how
) == O_MOVAB
||
2013 OP_KIND (instruction
->opcode
->how
) == O_MOVAW
||
2014 OP_KIND (instruction
->opcode
->how
) == O_MOVAL
)
2016 switch (operand
[0].mode
& MODE
)
2020 fix_operand_size (&operand
[1], 1);
2023 fix_operand_size (&operand
[1], 2);
2026 fix_operand_size (&operand
[1], 4);
2032 for (i
= 0; i
< 3 && operand
[i
].mode
!= 0; i
++)
2038 fix_operand_size (&operand
[i
], 1);
2041 fix_operand_size (&operand
[i
], 2);
2044 fix_operand_size (&operand
[i
], 4);
2049 instruction
= get_specific (instruction
, operand
, size
);
2051 if (instruction
== 0)
2053 /* Couldn't find an opcode which matched the operands. */
2054 char *where
= frag_more (2);
2058 clever_message (prev_instruction
, operand
);
2063 build_bytes (instruction
, operand
);
2065 #ifdef BFD_ASSEMBLER
2066 dwarf2_emit_insn (instruction
->length
);
2070 #ifndef BFD_ASSEMBLER
2072 tc_crawl_symbol_chain (headers
)
2073 object_headers
*headers ATTRIBUTE_UNUSED
;
2075 printf (_("call to tc_crawl_symbol_chain \n"));
2080 md_undefined_symbol (name
)
2081 char *name ATTRIBUTE_UNUSED
;
2086 #ifndef BFD_ASSEMBLER
2088 tc_headers_hook (headers
)
2089 object_headers
*headers ATTRIBUTE_UNUSED
;
2091 printf (_("call to tc_headers_hook \n"));
2095 /* Various routines to kill one day */
2096 /* Equal to MAX_PRECISION in atof-ieee.c */
2097 #define MAX_LITTLENUMS 6
2099 /* Turn a string in input_line_pointer into a floating point constant
2100 of type TYPE, and store the appropriate bytes in *LITP. The number
2101 of LITTLENUMS emitted is stored in *SIZEP. An error message is
2102 returned, or NULL on OK. */
2105 md_atof (type
, litP
, sizeP
)
2111 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2112 LITTLENUM_TYPE
*wordP
;
2143 return _("Bad call to MD_ATOF()");
2145 t
= atof_ieee (input_line_pointer
, type
, words
);
2147 input_line_pointer
= t
;
2149 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2150 for (wordP
= words
; prec
--;)
2152 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2153 litP
+= sizeof (LITTLENUM_TYPE
);
2158 const char *md_shortopts
= "";
2159 struct option md_longopts
[] = {
2160 {NULL
, no_argument
, NULL
, 0}
2163 size_t md_longopts_size
= sizeof (md_longopts
);
2166 md_parse_option (c
, arg
)
2167 int c ATTRIBUTE_UNUSED
;
2168 char *arg ATTRIBUTE_UNUSED
;
2174 md_show_usage (stream
)
2175 FILE *stream ATTRIBUTE_UNUSED
;
2179 void tc_aout_fix_to_chars
PARAMS ((void));
2182 tc_aout_fix_to_chars ()
2184 printf (_("call to tc_aout_fix_to_chars \n"));
2189 md_convert_frag (headers
, seg
, fragP
)
2190 #ifdef BFD_ASSEMBLER
2191 bfd
*headers ATTRIBUTE_UNUSED
;
2193 object_headers
*headers ATTRIBUTE_UNUSED
;
2195 segT seg ATTRIBUTE_UNUSED
;
2196 fragS
*fragP ATTRIBUTE_UNUSED
;
2198 printf (_("call to md_convert_frag \n"));
2202 #ifdef BFD_ASSEMBLER
2204 md_section_align (segment
, size
)
2208 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2209 return ((size
+ (1 << align
) - 1) & (-1 << align
));
2213 md_section_align (seg
, size
)
2217 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
2218 & (-1 << section_alignment
[(int) seg
]));
2224 md_apply_fix3 (fixP
, valP
, seg
)
2227 segT seg ATTRIBUTE_UNUSED
;
2229 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2232 switch (fixP
->fx_size
)
2238 *buf
++ = (val
>> 8);
2242 *buf
++ = (val
>> 24);
2243 *buf
++ = (val
>> 16);
2244 *buf
++ = (val
>> 8);
2251 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
2256 md_estimate_size_before_relax (fragP
, segment_type
)
2257 register fragS
*fragP ATTRIBUTE_UNUSED
;
2258 register segT segment_type ATTRIBUTE_UNUSED
;
2260 printf (_("call tomd_estimate_size_before_relax \n"));
2264 /* Put number into target byte order. */
2266 md_number_to_chars (ptr
, use
, nbytes
)
2271 number_to_chars_bigendian (ptr
, use
, nbytes
);
2275 md_pcrel_from (fixP
)
2276 fixS
*fixP ATTRIBUTE_UNUSED
;
2281 #ifndef BFD_ASSEMBLER
2283 tc_reloc_mangle (fix_ptr
, intr
, base
)
2285 struct internal_reloc
*intr
;
2289 symbolS
*symbol_ptr
;
2291 symbol_ptr
= fix_ptr
->fx_addsy
;
2293 /* If this relocation is attached to a symbol then it's ok
2295 if (fix_ptr
->fx_r_type
== TC_CONS_RELOC
)
2297 /* cons likes to create reloc32's whatever the size of the reloc..
2299 switch (fix_ptr
->fx_size
)
2302 intr
->r_type
= R_RELLONG
;
2305 intr
->r_type
= R_RELWORD
;
2308 intr
->r_type
= R_RELBYTE
;
2316 intr
->r_type
= fix_ptr
->fx_r_type
;
2319 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
2320 intr
->r_offset
= fix_ptr
->fx_offset
;
2324 if (symbol_ptr
->sy_number
!= -1)
2325 intr
->r_symndx
= symbol_ptr
->sy_number
;
2330 /* This case arises when a reference is made to `.'. */
2331 segsym
= seg_info (S_GET_SEGMENT (symbol_ptr
))->dot
;
2333 intr
->r_symndx
= -1;
2336 intr
->r_symndx
= segsym
->sy_number
;
2337 intr
->r_offset
+= S_GET_VALUE (symbol_ptr
);
2342 intr
->r_symndx
= -1;
2344 #else /* BFD_ASSEMBLER */
2346 tc_gen_reloc (section
, fixp
)
2347 asection
*section ATTRIBUTE_UNUSED
;
2351 bfd_reloc_code_real_type r_type
;
2353 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2355 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2356 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2358 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2359 "Difference of symbols in different sections is not supported");
2364 rel
= (arelent
*) xmalloc (sizeof (arelent
));
2365 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2366 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2367 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2368 rel
->addend
= fixp
->fx_offset
;
2370 r_type
= fixp
->fx_r_type
;
2374 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
2377 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
2378 if (rel
->howto
== NULL
)
2380 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2381 _("Cannot represent relocation type %s"),
2382 bfd_get_reloc_code_name (r_type
));