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 static void pint
PARAMS ((int));
58 #define PSIZE (Hmode ? L_32 : L_16)
60 #define DSYMMODE (Hmode ? L_24 : L_16)
62 int bsize
= L_8
; /* Default branch displacement. */
70 const struct h8_opcode
*opcode
;
73 struct h8_instruction
*h8_instructions
;
77 int arg ATTRIBUTE_UNUSED
;
82 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
83 as_warn (_("could not set architecture and machine"));
89 int arg ATTRIBUTE_UNUSED
;
94 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
95 as_warn (_("could not set architecture and machine"));
101 int arg ATTRIBUTE_UNUSED
;
107 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300hn
))
108 as_warn (_("could not set architecture and machine"));
114 int arg ATTRIBUTE_UNUSED
;
120 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sn
))
121 as_warn (_("could not set architecture and machine"));
134 int arg ATTRIBUTE_UNUSED
;
136 cons (Hmode
? 4 : 2);
139 /* This table describes all the machine specific pseudo-ops the assembler
140 has to support. The fields are:
141 pseudo-op name without dot
142 function to call to execute this pseudo-op
143 Integer arg to pass to the function. */
145 const pseudo_typeS md_pseudo_table
[] =
147 {"h8300h", h8300hmode
, 0},
148 {"h8300hn", h8300hnmode
, 0},
149 {"h8300s", h8300smode
, 0},
150 {"h8300sn", h8300snmode
, 0},
151 {"sbranch", sbranch
, L_8
},
152 {"lbranch", sbranch
, L_16
},
158 {"form", listing_psize
, 0},
159 {"heading", listing_title
, 0},
160 {"import", s_ignore
, 0},
161 {"page", listing_eject
, 0},
162 {"program", s_ignore
, 0},
166 const int md_reloc_size
;
168 const char EXP_CHARS
[] = "eE";
170 /* Chars that mean this number is a floating point constant
173 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
175 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
177 /* This function is called once, at assembler startup time. This
178 should set up all the tables, etc. that the MD part of the assembler
184 unsigned int nopcodes
;
185 const struct h8_opcode
*p
;
186 struct h8_instruction
*pi
;
187 char prev_buffer
[100];
191 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
192 as_warn (_("could not set architecture and machine"));
195 opcode_hash_control
= hash_new ();
198 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
200 h8_instructions
= (struct h8_instruction
*)
201 xmalloc (nopcodes
* sizeof (struct h8_instruction
));
203 for (p
= h8_opcodes
, pi
= h8_instructions
; p
->name
; p
++, pi
++)
205 /* Strip off any . part when inserting the opcode and only enter
206 unique codes into the hash table. */
208 unsigned int len
= strlen (src
);
209 char *dst
= malloc (len
+ 1);
224 if (strcmp (buffer
, prev_buffer
))
226 hash_insert (opcode_hash_control
, buffer
, (char *) pi
);
227 strcpy (prev_buffer
, buffer
);
232 /* Find the number of operands. */
234 while (p
->args
.nib
[pi
->noperands
] != E
)
237 /* Find the length of the opcode in bytes. */
239 while (p
->data
.nib
[pi
->length
* 2] != E
)
245 /* Add entry for the NULL vector terminator. */
263 int opsize
; /* Set when a register size is seen. */
272 static void clever_message
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
273 static void build_bytes
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
274 static void do_a_fix_imm
PARAMS ((int, struct h8_op
*, int));
275 static void check_operand
PARAMS ((struct h8_op
*, unsigned int, char *));
276 static const struct h8_instruction
* get_specific
PARAMS ((const struct h8_instruction
*, struct h8_op
*, int));
277 static char * get_operands
PARAMS ((unsigned, char *, struct h8_op
*));
278 static void get_operand
PARAMS ((char **, struct h8_op
*, unsigned, int));
279 static char * skip_colonthing
PARAMS ((char *, expressionS
*, int *));
280 static char * parse_exp
PARAMS ((char *, expressionS
*));
281 static int parse_reg
PARAMS ((char *, op_type
*, unsigned *, int));
282 char * colonmod24
PARAMS ((struct h8_op
*, char *));
286 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
295 /* Try to parse a reg name. Return the number of chars consumed. */
298 parse_reg (src
, mode
, reg
, direction
)
307 /* Cribbed from get_symbol_end. */
308 if (!is_name_beginner (*src
) || *src
== '\001')
311 while (is_part_of_name (*end
) || *end
== '\001')
315 if (len
== 2 && src
[0] == 's' && src
[1] == 'p')
317 *mode
= PSIZE
| REG
| direction
;
321 if (len
== 3 && src
[0] == 'c' && src
[1] == 'c' && src
[2] == 'r')
327 if (len
== 3 && src
[0] == 'e' && src
[1] == 'x' && src
[2] == 'r')
333 if (len
== 2 && src
[0] == 'f' && src
[1] == 'p')
335 *mode
= PSIZE
| REG
| direction
;
339 if (len
== 3 && src
[0] == 'e' && src
[1] == 'r'
340 && src
[2] >= '0' && src
[2] <= '7')
342 *mode
= L_32
| REG
| direction
;
345 as_warn (_("Reg not valid for H8/300"));
348 if (len
== 2 && src
[0] == 'e' && src
[1] >= '0' && src
[1] <= '7')
350 *mode
= L_16
| REG
| direction
;
351 *reg
= src
[1] - '0' + 8;
353 as_warn (_("Reg not valid for H8/300"));
359 if (src
[1] >= '0' && src
[1] <= '7')
361 if (len
== 3 && src
[2] == 'l')
363 *mode
= L_8
| REG
| direction
;
364 *reg
= (src
[1] - '0') + 8;
367 if (len
== 3 && src
[2] == 'h')
369 *mode
= L_8
| REG
| direction
;
370 *reg
= (src
[1] - '0');
375 *mode
= L_16
| REG
| direction
;
376 *reg
= (src
[1] - '0');
390 char *save
= input_line_pointer
;
393 input_line_pointer
= s
;
395 if (op
->X_op
== O_absent
)
396 as_bad (_("missing operand"));
397 new = input_line_pointer
;
398 input_line_pointer
= save
;
403 skip_colonthing (ptr
, exp
, mode
)
405 expressionS
*exp ATTRIBUTE_UNUSED
;
415 /* ff fill any 8 bit quantity. */
416 /* exp->X_add_number -= 0x100; */
425 else if (*ptr
== '3')
429 else if (*ptr
== '1')
433 while (ISDIGIT (*ptr
))
440 /* The many forms of operand:
443 @Rn Register indirect
444 @(exp[:16], Rn) Register indirect with displacement
448 @aa:16 absolute 16 bit
451 #xx[:size] immediate data
452 @(exp:[8], pc) pc rel
453 @@aa[:8] memory indirect. */
461 src
= skip_colonthing (src
, &op
->exp
, &mode
);
465 /* Choose a default mode. */
466 if (op
->exp
.X_add_number
< -32768
467 || op
->exp
.X_add_number
> 32767)
474 else if (op
->exp
.X_add_symbol
475 || op
->exp
.X_op_symbol
)
486 get_operand (ptr
, op
, dst
, direction
)
489 unsigned int dst ATTRIBUTE_UNUSED
;
499 /* Check for '(' and ')' for instructions ldm and stm. */
500 if (src
[0] == '(' && src
[8] == ')')
503 /* Gross. Gross. ldm and stm have a format not easily handled
504 by get_operand. We deal with it explicitly here. */
505 if (src
[0] == 'e' && src
[1] == 'r' && ISDIGIT (src
[2])
506 && src
[3] == '-' && src
[4] == 'e' && src
[5] == 'r' && ISDIGIT (src
[6]))
514 as_bad (_("Invalid register list for ldm/stm\n"));
517 as_bad (_("Invalid register list for ldm/stm\n"));
520 as_bad (_("Invalid register list for ldm/stm\n"));
524 as_bad (_("Invalid register list for ldm/stm\n"));
526 /* Even sicker. We encode two registers into op->reg. One
527 for the low register to save, the other for the high
528 register to save; we also set the high bit in op->reg
529 so we know this is "very special". */
530 op
->reg
= 0x80000000 | (high
<< 8) | low
;
539 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
552 src
= parse_exp (src
, &op
->exp
);
554 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
565 len
= parse_reg (src
, &mode
, &num
, direction
);
568 /* Oops, not a reg after all, must be ordinary exp. */
570 /* Must be a symbol. */
571 op
->mode
= ABS
| PSIZE
| direction
;
572 *ptr
= skip_colonthing (parse_exp (src
, &op
->exp
),
573 &op
->exp
, &op
->mode
);
578 if ((mode
& SIZE
) != PSIZE
)
579 as_bad (_("Wrong size pointer register for architecture."));
590 /* Start off assuming a 16 bit offset. */
592 src
= parse_exp (src
, &op
->exp
);
594 src
= colonmod24 (op
, src
);
599 op
->mode
|= ABS
| direction
;
606 as_bad (_("expected @(exp, reg16)"));
612 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
613 if (len
== 0 || !(mode
& REG
))
615 as_bad (_("expected @(exp, reg16)"));
618 op
->mode
|= DISP
| direction
;
621 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
623 if (*src
!= ')' && '(')
625 as_bad (_("expected @(exp, reg16)"));
632 len
= parse_reg (src
, &mode
, &num
, direction
);
640 if ((mode
& SIZE
) != PSIZE
)
641 as_bad (_("Wrong size pointer register for architecture."));
647 if ((mode
& SIZE
) != PSIZE
)
648 as_bad (_("Wrong size pointer register for architecture."));
650 op
->mode
= direction
| IND
| PSIZE
;
658 /* must be a symbol */
660 op
->mode
= ABS
| direction
;
661 src
= parse_exp (src
, &op
->exp
);
663 *ptr
= colonmod24 (op
, src
);
673 src
= parse_exp (src
, &op
->exp
);
674 *ptr
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
678 else if (strncmp (src
, "mach", 4) == 0
679 || strncmp (src
, "macl", 4) == 0)
681 op
->reg
= src
[3] == 'l';
688 src
= parse_exp (src
, &op
->exp
);
689 /* Trailing ':' size ? */
692 if (src
[1] == '1' && src
[2] == '6')
694 op
->mode
= PCREL
| L_16
;
697 else if (src
[1] == '8')
699 op
->mode
= PCREL
| L_8
;
703 as_bad (_("expect :8 or :16 here"));
706 op
->mode
= PCREL
| bsize
;
713 get_operands (noperands
, op_end
, operand
)
714 unsigned int noperands
;
716 struct h8_op
*operand
;
729 get_operand (&ptr
, operand
+ 0, 0, SRC
);
733 get_operand (&ptr
, operand
+ 1, 1, DST
);
743 get_operand (&ptr
, operand
+ 0, 0, SRC
);
746 get_operand (&ptr
, operand
+ 1, 1, DST
);
756 /* Passed a pointer to a list of opcodes which use different
757 addressing modes, return the opcode which matches the opcodes
760 static const struct h8_instruction
*
761 get_specific (instruction
, operands
, size
)
762 const struct h8_instruction
*instruction
;
763 struct h8_op
*operands
;
766 const struct h8_instruction
*this_try
= instruction
;
768 int this_index
= instruction
->idx
;
770 /* There's only one ldm/stm and it's easier to just
771 get out quick for them. */
772 if (strcmp (instruction
->opcode
->name
, "stm.l") == 0
773 || strcmp (instruction
->opcode
->name
, "ldm.l") == 0)
776 while (this_index
== instruction
->idx
&& !found
)
780 this_try
= instruction
++;
781 if (this_try
->noperands
== 0)
785 this_size
= this_try
->opcode
->how
& SN
;
786 if (this_size
!= size
&& (this_size
!= SB
|| size
!= SN
))
793 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
795 op_type op
= this_try
->opcode
->args
.nib
[i
];
796 int x
= operands
[i
].mode
;
798 if ((op
& (DISP
| REG
)) == (DISP
| REG
)
799 && ((x
& (DISP
| REG
)) == (DISP
| REG
)))
801 dispreg
= operands
[i
].reg
;
809 x
= (x
& ~L_P
) | (Hmode
? L_32
: L_16
);
811 op
= (op
& ~L_P
) | (Hmode
? L_32
: L_16
);
815 /* The size of the reg is v important. */
816 if ((op
& SIZE
) != (x
& SIZE
))
819 else if ((op
& ABSJMP
) && (x
& ABS
))
821 operands
[i
].mode
&= ~ABS
;
822 operands
[i
].mode
|= ABSJMP
;
823 /* But it may not be 24 bits long. */
826 operands
[i
].mode
&= ~SIZE
;
827 operands
[i
].mode
|= L_16
;
830 else if ((op
& (KBIT
| DBIT
)) && (x
& IMM
))
832 /* This is ok if the immediate value is sensible. */
836 /* The size of the displacement is important. */
837 if ((op
& SIZE
) != (x
& SIZE
))
840 else if ((op
& (DISP
| IMM
| ABS
))
841 && (op
& (DISP
| IMM
| ABS
)) == (x
& (DISP
| IMM
| ABS
)))
843 /* Promote a L_24 to L_32 if it makes us match. */
844 if ((x
& L_24
) && (op
& L_32
))
849 /* Promote an L8 to L_16 if it makes us match. */
850 if (op
& ABS
&& op
& L_8
&& op
& DISP
)
855 else if ((x
& SIZE
) != 0
856 && ((op
& SIZE
) != (x
& SIZE
)))
859 else if ((op
& MACREG
) != (x
& MACREG
))
863 else if ((op
& MODE
) != (x
& MODE
))
877 check_operand (operand
, width
, string
)
878 struct h8_op
*operand
;
882 if (operand
->exp
.X_add_symbol
== 0
883 && operand
->exp
.X_op_symbol
== 0)
885 /* No symbol involved, let's look at offset, it's dangerous if
886 any of the high bits are not 0 or ff's, find out by oring or
887 anding with the width and seeing if the answer is 0 or all
890 if ((operand
->exp
.X_add_number
& ~width
) != 0 &&
891 (operand
->exp
.X_add_number
| width
) != (unsigned)(~0))
894 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
896 /* Just ignore this one - which happens when trying to
897 fit a 16 bit address truncated into an 8 bit address
898 of something like bset. */
900 else if (strcmp (string
, "@") == 0
902 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
904 /* Just ignore this one - which happens when trying to
905 fit a 24 bit address truncated into a 16 bit address
906 of something like mov.w. */
910 as_warn (_("operand %s0x%lx out of range."), string
,
911 (unsigned long) operand
->exp
.X_add_number
);
917 /* RELAXMODE has one of 3 values:
919 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
921 1 Output a relaxable 24bit absolute mov.w address relocation
922 (may relax into a 16bit absolute address).
924 2 Output a relaxable 16/24 absolute mov.b address relocation
925 (may relax into an 8bit absolute address). */
928 do_a_fix_imm (offset
, operand
, relaxmode
)
930 struct h8_op
*operand
;
937 char *t
= operand
->mode
& IMM
? "#" : "@";
939 if (operand
->exp
.X_add_symbol
== 0)
941 char *bytes
= frag_now
->fr_literal
+ offset
;
942 switch (operand
->mode
& SIZE
)
945 check_operand (operand
, 0x3, t
);
946 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
949 check_operand (operand
, 0x7, t
);
950 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
953 check_operand (operand
, 0xff, t
);
954 bytes
[0] = operand
->exp
.X_add_number
;
957 check_operand (operand
, 0xffff, t
);
958 bytes
[0] = operand
->exp
.X_add_number
>> 8;
959 bytes
[1] = operand
->exp
.X_add_number
>> 0;
962 check_operand (operand
, 0xffffff, t
);
963 bytes
[0] = operand
->exp
.X_add_number
>> 16;
964 bytes
[1] = operand
->exp
.X_add_number
>> 8;
965 bytes
[2] = operand
->exp
.X_add_number
>> 0;
969 /* This should be done with bfd. */
970 bytes
[0] = operand
->exp
.X_add_number
>> 24;
971 bytes
[1] = operand
->exp
.X_add_number
>> 16;
972 bytes
[2] = operand
->exp
.X_add_number
>> 8;
973 bytes
[3] = operand
->exp
.X_add_number
>> 0;
976 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
977 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
984 switch (operand
->mode
& SIZE
)
989 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
992 else if (relaxmode
== 1)
998 as_bad (_("Can't work out size of operand.\n"));
1006 operand
->exp
.X_add_number
=
1007 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1013 operand
->exp
.X_add_number
=
1014 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1017 fix_new_exp (frag_now
,
1026 /* Now we know what sort of opcodes it is, let's build the bytes. */
1029 build_bytes (this_try
, operand
)
1030 const struct h8_instruction
*this_try
;
1031 struct h8_op
*operand
;
1034 char *output
= frag_more (this_try
->length
);
1035 op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1037 unsigned int nibble_count
= 0;
1043 char *p
= asnibbles
;
1045 if (!(this_try
->opcode
->inbase
|| Hmode
))
1046 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1047 this_try
->opcode
->name
);
1049 while (*nibble_ptr
!= E
)
1054 d
= (c
& (DST
| SRC_IN_DST
)) != 0;
1060 if (c
& (REG
| IND
| INC
| DEC
))
1061 nib
= operand
[d
].reg
;
1063 else if ((c
& DISPREG
) == (DISPREG
))
1068 operand
[d
].mode
= c
;
1069 absat
= nibble_count
/ 2;
1072 else if (c
& (IMM
| PCREL
| ABS
| ABSJMP
| DISP
))
1074 operand
[d
].mode
= c
;
1075 immat
= nibble_count
/ 2;
1078 else if (c
& IGNORE
)
1083 switch (operand
[0].exp
.X_add_number
)
1092 as_bad (_("Need #1 or #2 here"));
1097 switch (operand
[0].exp
.X_add_number
)
1107 as_warn (_("#4 not valid on H8/300."));
1112 as_bad (_("Need #1 or #2 here"));
1115 /* Stop it making a fix. */
1116 operand
[0].mode
= 0;
1120 operand
[d
].mode
|= MEMRELAX
;
1127 if (operand
[0].mode
== MACREG
)
1128 /* stmac has mac[hl] as the first operand. */
1129 nib
= 2 + operand
[0].reg
;
1131 /* ldmac has mac[hl] as the second operand. */
1132 nib
= 2 + operand
[1].reg
;
1140 /* Disgusting. Why, oh why didn't someone ask us for advice
1141 on the assembler format. */
1142 if (strcmp (this_try
->opcode
->name
, "stm.l") == 0
1143 || strcmp (this_try
->opcode
->name
, "ldm.l") == 0)
1146 high
= (operand
[this_try
->opcode
->name
[0] == 'l' ? 1 : 0].reg
>> 8) & 0xf;
1147 low
= operand
[this_try
->opcode
->name
[0] == 'l' ? 1 : 0].reg
& 0xf;
1149 asnibbles
[2] = high
- low
;
1150 asnibbles
[7] = (this_try
->opcode
->name
[0] == 'l') ? high
: low
;
1153 for (i
= 0; i
< this_try
->length
; i
++)
1154 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1156 /* Note if this is a movb instruction -- there's a special relaxation
1157 which only applies to them. */
1158 if (strcmp (this_try
->opcode
->name
, "mov.b") == 0)
1161 /* Output any fixes. */
1162 for (i
= 0; i
< 2; i
++)
1164 int x
= operand
[i
].mode
;
1166 if (x
& (IMM
| DISP
))
1167 do_a_fix_imm (output
- frag_now
->fr_literal
+ immat
,
1168 operand
+ i
, (x
& MEMRELAX
) != 0);
1171 do_a_fix_imm (output
- frag_now
->fr_literal
+ absat
,
1172 operand
+ i
, (x
& MEMRELAX
) ? movb
+ 1 : 0);
1176 int size16
= x
& (L_16
);
1177 int where
= size16
? 2 : 1;
1178 int size
= size16
? 2 : 1;
1179 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1182 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1184 if (operand
[i
].exp
.X_add_number
& 1)
1185 as_warn (_("branch operand has odd offset (%lx)\n"),
1186 (unsigned long) operand
->exp
.X_add_number
);
1188 /* The COFF port has always been off by one, changing it
1189 now would be an incompatible change, so we leave it as-is.
1191 We don't want to do this for ELF as we want to be
1192 compatible with the proposed ELF format from Hitachi. */
1193 operand
[i
].exp
.X_add_number
-= 1;
1195 operand
[i
].exp
.X_add_number
=
1196 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1198 fixP
= fix_new_exp (frag_now
,
1199 output
- frag_now
->fr_literal
+ where
,
1204 fixP
->fx_signed
= 1;
1206 else if (x
& MEMIND
)
1208 check_operand (operand
+ i
, 0xff, "@@");
1209 fix_new_exp (frag_now
,
1210 output
- frag_now
->fr_literal
+ 1,
1216 else if (x
& ABSJMP
)
1221 /* To be compatible with the proposed H8 ELF format, we
1222 want the relocation's offset to point to the first byte
1223 that will be modified, not to the start of the instruction. */
1227 /* This jmp may be a jump or a branch. */
1229 check_operand (operand
+ i
, Hmode
? 0xffffff : 0xffff, "@");
1231 if (operand
[i
].exp
.X_add_number
& 1)
1232 as_warn (_("branch operand has odd offset (%lx)\n"),
1233 (unsigned long) operand
->exp
.X_add_number
);
1236 operand
[i
].exp
.X_add_number
=
1237 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1238 fix_new_exp (frag_now
,
1239 output
- frag_now
->fr_literal
+ where
,
1248 /* Try to give an intelligent error message for common and simple to
1252 clever_message (instruction
, operand
)
1253 const struct h8_instruction
*instruction
;
1254 struct h8_op
*operand
;
1256 /* Find out if there was more than one possible opcode. */
1258 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1262 /* Only one opcode of this flavour, try to guess which operand
1264 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1266 switch (instruction
->opcode
->args
.nib
[argn
])
1269 if (operand
[argn
].mode
!= RD16
)
1271 as_bad (_("destination operand must be 16 bit register"));
1278 if (operand
[argn
].mode
!= RS8
)
1280 as_bad (_("source operand must be 8 bit register"));
1286 if (operand
[argn
].mode
!= ABS16DST
)
1288 as_bad (_("destination operand must be 16bit absolute address"));
1293 if (operand
[argn
].mode
!= RD8
)
1295 as_bad (_("destination operand must be 8 bit register"));
1301 if (operand
[argn
].mode
!= ABS16SRC
)
1303 as_bad (_("source operand must be 16bit absolute address"));
1311 as_bad (_("invalid operands"));
1314 /* This is the guts of the machine-dependent assembler. STR points to
1315 a machine dependent instruction. This function is supposed to emit
1316 the frags/bytes it assembles. */
1324 struct h8_op operand
[2];
1325 const struct h8_instruction
*instruction
;
1326 const struct h8_instruction
*prev_instruction
;
1332 /* Drop leading whitespace. */
1336 /* Find the op code end. */
1337 for (op_start
= op_end
= str
;
1338 *op_end
!= 0 && *op_end
!= ' ';
1350 if (op_end
== op_start
)
1352 as_bad (_("can't find opcode "));
1358 instruction
= (const struct h8_instruction
*)
1359 hash_find (opcode_hash_control
, op_start
);
1361 if (instruction
== NULL
)
1363 as_bad (_("unknown opcode"));
1367 /* We used to set input_line_pointer to the result of get_operands,
1368 but that is wrong. Our caller assumes we don't change it. */
1370 (void) get_operands (instruction
->noperands
, op_end
, operand
);
1372 prev_instruction
= instruction
;
1392 instruction
= get_specific (instruction
, operand
, size
);
1394 if (instruction
== 0)
1396 /* Couldn't find an opcode which matched the operands. */
1397 char *where
= frag_more (2);
1401 clever_message (prev_instruction
, operand
);
1405 if (instruction
->size
&& dot
)
1407 if (instruction
->size
!= *dot
)
1409 as_warn (_("mismatch between opcode size and operand size"));
1413 build_bytes (instruction
, operand
);
1415 #ifdef BFD_ASSEMBLER
1416 dwarf2_emit_insn (instruction
->length
);
1420 #ifndef BFD_ASSEMBLER
1422 tc_crawl_symbol_chain (headers
)
1423 object_headers
*headers ATTRIBUTE_UNUSED
;
1425 printf (_("call to tc_crawl_symbol_chain \n"));
1430 md_undefined_symbol (name
)
1431 char *name ATTRIBUTE_UNUSED
;
1436 #ifndef BFD_ASSEMBLER
1438 tc_headers_hook (headers
)
1439 object_headers
*headers ATTRIBUTE_UNUSED
;
1441 printf (_("call to tc_headers_hook \n"));
1445 /* Various routines to kill one day */
1446 /* Equal to MAX_PRECISION in atof-ieee.c */
1447 #define MAX_LITTLENUMS 6
1449 /* Turn a string in input_line_pointer into a floating point constant
1450 of type TYPE, and store the appropriate bytes in *LITP. The number
1451 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1452 returned, or NULL on OK. */
1455 md_atof (type
, litP
, sizeP
)
1461 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1462 LITTLENUM_TYPE
*wordP
;
1493 return _("Bad call to MD_ATOF()");
1495 t
= atof_ieee (input_line_pointer
, type
, words
);
1497 input_line_pointer
= t
;
1499 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1500 for (wordP
= words
; prec
--;)
1502 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1503 litP
+= sizeof (LITTLENUM_TYPE
);
1508 const char *md_shortopts
= "";
1509 struct option md_longopts
[] = {
1510 {NULL
, no_argument
, NULL
, 0}
1513 size_t md_longopts_size
= sizeof (md_longopts
);
1516 md_parse_option (c
, arg
)
1517 int c ATTRIBUTE_UNUSED
;
1518 char *arg ATTRIBUTE_UNUSED
;
1524 md_show_usage (stream
)
1525 FILE *stream ATTRIBUTE_UNUSED
;
1529 void tc_aout_fix_to_chars
PARAMS ((void));
1532 tc_aout_fix_to_chars ()
1534 printf (_("call to tc_aout_fix_to_chars \n"));
1539 md_convert_frag (headers
, seg
, fragP
)
1540 #ifdef BFD_ASSEMBLER
1541 bfd
*headers ATTRIBUTE_UNUSED
;
1543 object_headers
*headers ATTRIBUTE_UNUSED
;
1545 segT seg ATTRIBUTE_UNUSED
;
1546 fragS
*fragP ATTRIBUTE_UNUSED
;
1548 printf (_("call to md_convert_frag \n"));
1552 #ifdef BFD_ASSEMBLER
1554 md_section_align (segment
, size
)
1558 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1559 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1563 md_section_align (seg
, size
)
1567 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
1568 & (-1 << section_alignment
[(int) seg
]));
1574 md_apply_fix3 (fixP
, valP
, seg
)
1577 segT seg ATTRIBUTE_UNUSED
;
1579 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1582 switch (fixP
->fx_size
)
1588 *buf
++ = (val
>> 8);
1592 *buf
++ = (val
>> 24);
1593 *buf
++ = (val
>> 16);
1594 *buf
++ = (val
>> 8);
1601 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1606 md_estimate_size_before_relax (fragP
, segment_type
)
1607 register fragS
*fragP ATTRIBUTE_UNUSED
;
1608 register segT segment_type ATTRIBUTE_UNUSED
;
1610 printf (_("call tomd_estimate_size_before_relax \n"));
1614 /* Put number into target byte order. */
1616 md_number_to_chars (ptr
, use
, nbytes
)
1621 number_to_chars_bigendian (ptr
, use
, nbytes
);
1625 md_pcrel_from (fixP
)
1626 fixS
*fixP ATTRIBUTE_UNUSED
;
1631 #ifndef BFD_ASSEMBLER
1633 tc_reloc_mangle (fix_ptr
, intr
, base
)
1635 struct internal_reloc
*intr
;
1639 symbolS
*symbol_ptr
;
1641 symbol_ptr
= fix_ptr
->fx_addsy
;
1643 /* If this relocation is attached to a symbol then it's ok
1645 if (fix_ptr
->fx_r_type
== TC_CONS_RELOC
)
1647 /* cons likes to create reloc32's whatever the size of the reloc..
1649 switch (fix_ptr
->fx_size
)
1652 intr
->r_type
= R_RELLONG
;
1655 intr
->r_type
= R_RELWORD
;
1658 intr
->r_type
= R_RELBYTE
;
1666 intr
->r_type
= fix_ptr
->fx_r_type
;
1669 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
1670 intr
->r_offset
= fix_ptr
->fx_offset
;
1674 if (symbol_ptr
->sy_number
!= -1)
1675 intr
->r_symndx
= symbol_ptr
->sy_number
;
1680 /* This case arises when a reference is made to `.'. */
1681 segsym
= seg_info (S_GET_SEGMENT (symbol_ptr
))->dot
;
1683 intr
->r_symndx
= -1;
1686 intr
->r_symndx
= segsym
->sy_number
;
1687 intr
->r_offset
+= S_GET_VALUE (symbol_ptr
);
1692 intr
->r_symndx
= -1;
1694 #else /* BFD_ASSEMBLER */
1696 tc_gen_reloc (section
, fixp
)
1697 asection
*section ATTRIBUTE_UNUSED
;
1701 bfd_reloc_code_real_type r_type
;
1703 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
1705 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
1706 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
1708 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1709 "Difference of symbols in different sections is not supported");
1714 rel
= (arelent
*) xmalloc (sizeof (arelent
));
1715 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1716 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1717 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1718 rel
->addend
= fixp
->fx_offset
;
1720 r_type
= fixp
->fx_r_type
;
1724 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
1727 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
1728 if (rel
->howto
== NULL
)
1730 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1731 _("Cannot represent relocation type %s"),
1732 bfd_get_reloc_code_name (r_type
));