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>. */
29 #define h8_opcodes ops
30 #include "opcode/h8300.h"
31 #include "safe-ctype.h"
37 const char comment_chars
[] = ";";
38 const char line_comment_chars
[] = "#";
39 const char line_separator_chars
[] = "";
41 void cons
PARAMS ((int));
42 void sbranch
PARAMS ((int));
43 void h8300hmode
PARAMS ((int));
44 void h8300smode
PARAMS ((int));
45 void h8300hnmode
PARAMS ((int));
46 void h8300snmode
PARAMS ((int));
47 static void pint
PARAMS ((int));
53 #define PSIZE (Hmode ? L_32 : L_16)
55 #define DSYMMODE (Hmode ? L_24 : L_16)
57 int bsize
= L_8
; /* Default branch displacement. */
65 const struct h8_opcode
*opcode
;
68 struct h8_instruction
*h8_instructions
;
72 int arg ATTRIBUTE_UNUSED
;
77 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
78 as_warn (_("could not set architecture and machine"));
84 int arg ATTRIBUTE_UNUSED
;
89 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
90 as_warn (_("could not set architecture and machine"));
96 int arg ATTRIBUTE_UNUSED
;
102 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300hn
))
103 as_warn (_("could not set architecture and machine"));
109 int arg ATTRIBUTE_UNUSED
;
115 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300sn
))
116 as_warn (_("could not set architecture and machine"));
129 int arg ATTRIBUTE_UNUSED
;
131 cons (Hmode
? 4 : 2);
134 /* This table describes all the machine specific pseudo-ops the assembler
135 has to support. The fields are:
136 pseudo-op name without dot
137 function to call to execute this pseudo-op
138 Integer arg to pass to the function. */
140 const pseudo_typeS md_pseudo_table
[] =
142 {"h8300h", h8300hmode
, 0},
143 {"h8300hn", h8300hnmode
, 0},
144 {"h8300s", h8300smode
, 0},
145 {"h8300sn", h8300snmode
, 0},
146 {"sbranch", sbranch
, L_8
},
147 {"lbranch", sbranch
, L_16
},
153 {"form", listing_psize
, 0},
154 {"heading", listing_title
, 0},
155 {"import", s_ignore
, 0},
156 {"page", listing_eject
, 0},
157 {"program", s_ignore
, 0},
161 const int md_reloc_size
;
163 const char EXP_CHARS
[] = "eE";
165 /* Chars that mean this number is a floating point constant
168 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
170 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
172 /* This function is called once, at assembler startup time. This
173 should set up all the tables, etc. that the MD part of the assembler
179 unsigned int nopcodes
;
180 const struct h8_opcode
*p
;
181 struct h8_instruction
*pi
;
182 char prev_buffer
[100];
186 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
187 as_warn (_("could not set architecture and machine"));
190 opcode_hash_control
= hash_new ();
193 nopcodes
= sizeof (h8_opcodes
) / sizeof (struct h8_opcode
);
195 h8_instructions
= (struct h8_instruction
*)
196 xmalloc (nopcodes
* sizeof (struct h8_instruction
));
198 for (p
= h8_opcodes
, pi
= h8_instructions
; p
->name
; p
++, pi
++)
200 /* Strip off any . part when inserting the opcode and only enter
201 unique codes into the hash table. */
203 unsigned int len
= strlen (src
);
204 char *dst
= malloc (len
+ 1);
219 if (strcmp (buffer
, prev_buffer
))
221 hash_insert (opcode_hash_control
, buffer
, (char *) pi
);
222 strcpy (prev_buffer
, buffer
);
227 /* Find the number of operands. */
229 while (p
->args
.nib
[pi
->noperands
] != E
)
232 /* Find the length of the opcode in bytes. */
234 while (p
->data
.nib
[pi
->length
* 2] != E
)
240 /* Add entry for the NULL vector terminator. */
258 int opsize
; /* Set when a register size is seen. */
267 static void clever_message
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
268 static void build_bytes
PARAMS ((const struct h8_instruction
*, struct h8_op
*));
269 static void do_a_fix_imm
PARAMS ((int, struct h8_op
*, int));
270 static void check_operand
PARAMS ((struct h8_op
*, unsigned int, char *));
271 static const struct h8_instruction
* get_specific
PARAMS ((const struct h8_instruction
*, struct h8_op
*, int));
272 static char * get_operands
PARAMS ((unsigned, char *, struct h8_op
*));
273 static void get_operand
PARAMS ((char **, struct h8_op
*, unsigned, int));
274 static char * skip_colonthing
PARAMS ((char *, expressionS
*, int *));
275 static char * parse_exp
PARAMS ((char *, expressionS
*));
276 static int parse_reg
PARAMS ((char *, op_type
*, unsigned *, int));
277 char * colonmod24
PARAMS ((struct h8_op
*, char *));
281 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
290 /* Try to parse a reg name. Return the number of chars consumed. */
293 parse_reg (src
, mode
, reg
, direction
)
302 /* Cribbed from get_symbol_end. */
303 if (!is_name_beginner (*src
) || *src
== '\001')
306 while (is_part_of_name (*end
) || *end
== '\001')
310 if (len
== 2 && src
[0] == 's' && src
[1] == 'p')
312 *mode
= PSIZE
| REG
| direction
;
316 if (len
== 3 && src
[0] == 'c' && src
[1] == 'c' && src
[2] == 'r')
322 if (len
== 3 && src
[0] == 'e' && src
[1] == 'x' && src
[2] == 'r')
328 if (len
== 2 && src
[0] == 'f' && src
[1] == 'p')
330 *mode
= PSIZE
| REG
| direction
;
334 if (len
== 3 && src
[0] == 'e' && src
[1] == 'r'
335 && src
[2] >= '0' && src
[2] <= '7')
337 *mode
= L_32
| REG
| direction
;
340 as_warn (_("Reg not valid for H8/300"));
343 if (len
== 2 && src
[0] == 'e' && src
[1] >= '0' && src
[1] <= '7')
345 *mode
= L_16
| REG
| direction
;
346 *reg
= src
[1] - '0' + 8;
348 as_warn (_("Reg not valid for H8/300"));
354 if (src
[1] >= '0' && src
[1] <= '7')
356 if (len
== 3 && src
[2] == 'l')
358 *mode
= L_8
| REG
| direction
;
359 *reg
= (src
[1] - '0') + 8;
362 if (len
== 3 && src
[2] == 'h')
364 *mode
= L_8
| REG
| direction
;
365 *reg
= (src
[1] - '0');
370 *mode
= L_16
| REG
| direction
;
371 *reg
= (src
[1] - '0');
385 char *save
= input_line_pointer
;
388 input_line_pointer
= s
;
390 if (op
->X_op
== O_absent
)
391 as_bad (_("missing operand"));
392 new = input_line_pointer
;
393 input_line_pointer
= save
;
398 skip_colonthing (ptr
, exp
, mode
)
400 expressionS
*exp ATTRIBUTE_UNUSED
;
410 /* ff fill any 8 bit quantity. */
411 /* exp->X_add_number -= 0x100; */
420 else if (*ptr
== '3')
424 else if (*ptr
== '1')
428 while (ISDIGIT (*ptr
))
435 /* The many forms of operand:
438 @Rn Register indirect
439 @(exp[:16], Rn) Register indirect with displacement
443 @aa:16 absolute 16 bit
446 #xx[:size] immediate data
447 @(exp:[8], pc) pc rel
448 @@aa[:8] memory indirect. */
456 src
= skip_colonthing (src
, &op
->exp
, &mode
);
460 /* Choose a default mode. */
461 if (op
->exp
.X_add_number
< -32768
462 || op
->exp
.X_add_number
> 32767)
469 else if (op
->exp
.X_add_symbol
470 || op
->exp
.X_op_symbol
)
481 get_operand (ptr
, op
, dst
, direction
)
484 unsigned int dst ATTRIBUTE_UNUSED
;
494 /* Check for '(' and ')' for instructions ldm and stm. */
495 if (src
[0] == '(' && src
[8] == ')')
498 /* Gross. Gross. ldm and stm have a format not easily handled
499 by get_operand. We deal with it explicitly here. */
500 if (src
[0] == 'e' && src
[1] == 'r' && ISDIGIT (src
[2])
501 && src
[3] == '-' && src
[4] == 'e' && src
[5] == 'r' && ISDIGIT (src
[6]))
509 as_bad (_("Invalid register list for ldm/stm\n"));
512 as_bad (_("Invalid register list for ldm/stm\n"));
515 as_bad (_("Invalid register list for ldm/stm\n"));
519 as_bad (_("Invalid register list for ldm/stm\n"));
521 /* Even sicker. We encode two registers into op->reg. One
522 for the low register to save, the other for the high
523 register to save; we also set the high bit in op->reg
524 so we know this is "very special". */
525 op
->reg
= 0x80000000 | (high
<< 8) | low
;
534 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
547 src
= parse_exp (src
, &op
->exp
);
549 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
560 len
= parse_reg (src
, &mode
, &num
, direction
);
563 /* Oops, not a reg after all, must be ordinary exp. */
565 /* Must be a symbol. */
566 op
->mode
= ABS
| PSIZE
| direction
;
567 *ptr
= skip_colonthing (parse_exp (src
, &op
->exp
),
568 &op
->exp
, &op
->mode
);
573 if ((mode
& SIZE
) != PSIZE
)
574 as_bad (_("Wrong size pointer register for architecture."));
585 /* Start off assuming a 16 bit offset. */
587 src
= parse_exp (src
, &op
->exp
);
589 src
= colonmod24 (op
, src
);
594 op
->mode
|= ABS
| direction
;
601 as_bad (_("expected @(exp, reg16)"));
607 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
608 if (len
== 0 || !(mode
& REG
))
610 as_bad (_("expected @(exp, reg16)"));
613 op
->mode
|= DISP
| direction
;
616 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
618 if (*src
!= ')' && '(')
620 as_bad (_("expected @(exp, reg16)"));
627 len
= parse_reg (src
, &mode
, &num
, direction
);
635 if ((mode
& SIZE
) != PSIZE
)
636 as_bad (_("Wrong size pointer register for architecture."));
642 if ((mode
& SIZE
) != PSIZE
)
643 as_bad (_("Wrong size pointer register for architecture."));
645 op
->mode
= direction
| IND
| PSIZE
;
653 /* must be a symbol */
655 op
->mode
= ABS
| direction
;
656 src
= parse_exp (src
, &op
->exp
);
658 *ptr
= colonmod24 (op
, src
);
668 src
= parse_exp (src
, &op
->exp
);
669 *ptr
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
673 else if (strncmp (src
, "mach", 4) == 0
674 || strncmp (src
, "macl", 4) == 0)
676 op
->reg
= src
[3] == 'l';
683 src
= parse_exp (src
, &op
->exp
);
684 /* Trailing ':' size ? */
687 if (src
[1] == '1' && src
[2] == '6')
689 op
->mode
= PCREL
| L_16
;
692 else if (src
[1] == '8')
694 op
->mode
= PCREL
| L_8
;
698 as_bad (_("expect :8 or :16 here"));
701 op
->mode
= PCREL
| bsize
;
708 get_operands (noperands
, op_end
, operand
)
709 unsigned int noperands
;
711 struct h8_op
*operand
;
724 get_operand (&ptr
, operand
+ 0, 0, SRC
);
728 get_operand (&ptr
, operand
+ 1, 1, DST
);
738 get_operand (&ptr
, operand
+ 0, 0, SRC
);
741 get_operand (&ptr
, operand
+ 1, 1, DST
);
751 /* Passed a pointer to a list of opcodes which use different
752 addressing modes, return the opcode which matches the opcodes
755 static const struct h8_instruction
*
756 get_specific (instruction
, operands
, size
)
757 const struct h8_instruction
*instruction
;
758 struct h8_op
*operands
;
761 const struct h8_instruction
*this_try
= instruction
;
763 int this_index
= instruction
->idx
;
765 /* There's only one ldm/stm and it's easier to just
766 get out quick for them. */
767 if (strcmp (instruction
->opcode
->name
, "stm.l") == 0
768 || strcmp (instruction
->opcode
->name
, "ldm.l") == 0)
771 while (this_index
== instruction
->idx
&& !found
)
775 this_try
= instruction
++;
776 if (this_try
->noperands
== 0)
780 this_size
= this_try
->opcode
->how
& SN
;
781 if (this_size
!= size
&& (this_size
!= SB
|| size
!= SN
))
788 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
790 op_type op
= this_try
->opcode
->args
.nib
[i
];
791 int x
= operands
[i
].mode
;
793 if ((op
& (DISP
| REG
)) == (DISP
| REG
)
794 && ((x
& (DISP
| REG
)) == (DISP
| REG
)))
796 dispreg
= operands
[i
].reg
;
804 x
= (x
& ~L_P
) | (Hmode
? L_32
: L_16
);
806 op
= (op
& ~L_P
) | (Hmode
? L_32
: L_16
);
810 /* The size of the reg is v important. */
811 if ((op
& SIZE
) != (x
& SIZE
))
814 else if ((op
& ABSJMP
) && (x
& ABS
))
816 operands
[i
].mode
&= ~ABS
;
817 operands
[i
].mode
|= ABSJMP
;
818 /* But it may not be 24 bits long. */
821 operands
[i
].mode
&= ~SIZE
;
822 operands
[i
].mode
|= L_16
;
825 else if ((op
& (KBIT
| DBIT
)) && (x
& IMM
))
827 /* This is ok if the immediate value is sensible. */
831 /* The size of the displacement is important. */
832 if ((op
& SIZE
) != (x
& SIZE
))
835 else if ((op
& (DISP
| IMM
| ABS
))
836 && (op
& (DISP
| IMM
| ABS
)) == (x
& (DISP
| IMM
| ABS
)))
838 /* Promote a L_24 to L_32 if it makes us match. */
839 if ((x
& L_24
) && (op
& L_32
))
844 /* Promote an L8 to L_16 if it makes us match. */
845 if (op
& ABS
&& op
& L_8
&& op
& DISP
)
850 else if ((x
& SIZE
) != 0
851 && ((op
& SIZE
) != (x
& SIZE
)))
854 else if ((op
& MACREG
) != (x
& MACREG
))
858 else if ((op
& MODE
) != (x
& MODE
))
872 check_operand (operand
, width
, string
)
873 struct h8_op
*operand
;
877 if (operand
->exp
.X_add_symbol
== 0
878 && operand
->exp
.X_op_symbol
== 0)
880 /* No symbol involved, let's look at offset, it's dangerous if
881 any of the high bits are not 0 or ff's, find out by oring or
882 anding with the width and seeing if the answer is 0 or all
885 if ((operand
->exp
.X_add_number
& ~width
) != 0 &&
886 (operand
->exp
.X_add_number
| width
) != (unsigned)(~0))
889 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
891 /* Just ignore this one - which happens when trying to
892 fit a 16 bit address truncated into an 8 bit address
893 of something like bset. */
895 else if (strcmp (string
, "@") == 0
897 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
899 /* Just ignore this one - which happens when trying to
900 fit a 24 bit address truncated into a 16 bit address
901 of something like mov.w. */
905 as_warn (_("operand %s0x%lx out of range."), string
,
906 (unsigned long) operand
->exp
.X_add_number
);
912 /* RELAXMODE has one of 3 values:
914 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
916 1 Output a relaxable 24bit absolute mov.w address relocation
917 (may relax into a 16bit absolute address).
919 2 Output a relaxable 16/24 absolute mov.b address relocation
920 (may relax into an 8bit absolute address). */
923 do_a_fix_imm (offset
, operand
, relaxmode
)
925 struct h8_op
*operand
;
932 char *t
= operand
->mode
& IMM
? "#" : "@";
934 if (operand
->exp
.X_add_symbol
== 0)
936 char *bytes
= frag_now
->fr_literal
+ offset
;
937 switch (operand
->mode
& SIZE
)
940 check_operand (operand
, 0x3, t
);
941 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
944 check_operand (operand
, 0x7, t
);
945 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
948 check_operand (operand
, 0xff, t
);
949 bytes
[0] = operand
->exp
.X_add_number
;
952 check_operand (operand
, 0xffff, t
);
953 bytes
[0] = operand
->exp
.X_add_number
>> 8;
954 bytes
[1] = operand
->exp
.X_add_number
>> 0;
957 check_operand (operand
, 0xffffff, t
);
958 bytes
[0] = operand
->exp
.X_add_number
>> 16;
959 bytes
[1] = operand
->exp
.X_add_number
>> 8;
960 bytes
[2] = operand
->exp
.X_add_number
>> 0;
964 /* This should be done with bfd. */
965 bytes
[0] = operand
->exp
.X_add_number
>> 24;
966 bytes
[1] = operand
->exp
.X_add_number
>> 16;
967 bytes
[2] = operand
->exp
.X_add_number
>> 8;
968 bytes
[3] = operand
->exp
.X_add_number
>> 0;
971 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
972 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
979 switch (operand
->mode
& SIZE
)
984 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
987 else if (relaxmode
== 1)
993 as_bad (_("Can't work out size of operand.\n"));
1001 operand
->exp
.X_add_number
=
1002 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1008 operand
->exp
.X_add_number
=
1009 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1012 fix_new_exp (frag_now
,
1021 /* Now we know what sort of opcodes it is, let's build the bytes. */
1024 build_bytes (this_try
, operand
)
1025 const struct h8_instruction
*this_try
;
1026 struct h8_op
*operand
;
1029 char *output
= frag_more (this_try
->length
);
1030 op_type
*nibble_ptr
= this_try
->opcode
->data
.nib
;
1032 unsigned int nibble_count
= 0;
1038 char *p
= asnibbles
;
1040 if (!(this_try
->opcode
->inbase
|| Hmode
))
1041 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
1042 this_try
->opcode
->name
);
1044 while (*nibble_ptr
!= E
)
1049 d
= (c
& (DST
| SRC_IN_DST
)) != 0;
1055 if (c
& (REG
| IND
| INC
| DEC
))
1056 nib
= operand
[d
].reg
;
1058 else if ((c
& DISPREG
) == (DISPREG
))
1063 operand
[d
].mode
= c
;
1064 absat
= nibble_count
/ 2;
1067 else if (c
& (IMM
| PCREL
| ABS
| ABSJMP
| DISP
))
1069 operand
[d
].mode
= c
;
1070 immat
= nibble_count
/ 2;
1073 else if (c
& IGNORE
)
1078 switch (operand
[0].exp
.X_add_number
)
1087 as_bad (_("Need #1 or #2 here"));
1092 switch (operand
[0].exp
.X_add_number
)
1102 as_warn (_("#4 not valid on H8/300."));
1107 as_bad (_("Need #1 or #2 here"));
1110 /* Stop it making a fix. */
1111 operand
[0].mode
= 0;
1115 operand
[d
].mode
|= MEMRELAX
;
1122 if (operand
[0].mode
== MACREG
)
1123 /* stmac has mac[hl] as the first operand. */
1124 nib
= 2 + operand
[0].reg
;
1126 /* ldmac has mac[hl] as the second operand. */
1127 nib
= 2 + operand
[1].reg
;
1135 /* Disgusting. Why, oh why didn't someone ask us for advice
1136 on the assembler format. */
1137 if (strcmp (this_try
->opcode
->name
, "stm.l") == 0
1138 || strcmp (this_try
->opcode
->name
, "ldm.l") == 0)
1141 high
= (operand
[this_try
->opcode
->name
[0] == 'l' ? 1 : 0].reg
>> 8) & 0xf;
1142 low
= operand
[this_try
->opcode
->name
[0] == 'l' ? 1 : 0].reg
& 0xf;
1144 asnibbles
[2] = high
- low
;
1145 asnibbles
[7] = (this_try
->opcode
->name
[0] == 'l') ? high
: low
;
1148 for (i
= 0; i
< this_try
->length
; i
++)
1149 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1151 /* Note if this is a movb instruction -- there's a special relaxation
1152 which only applies to them. */
1153 if (strcmp (this_try
->opcode
->name
, "mov.b") == 0)
1156 /* Output any fixes. */
1157 for (i
= 0; i
< 2; i
++)
1159 int x
= operand
[i
].mode
;
1161 if (x
& (IMM
| DISP
))
1162 do_a_fix_imm (output
- frag_now
->fr_literal
+ immat
,
1163 operand
+ i
, (x
& MEMRELAX
) != 0);
1166 do_a_fix_imm (output
- frag_now
->fr_literal
+ absat
,
1167 operand
+ i
, (x
& MEMRELAX
) ? movb
+ 1 : 0);
1171 int size16
= x
& (L_16
);
1172 int where
= size16
? 2 : 1;
1173 int size
= size16
? 2 : 1;
1174 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1177 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1179 if (operand
[i
].exp
.X_add_number
& 1)
1180 as_warn (_("branch operand has odd offset (%lx)\n"),
1181 (unsigned long) operand
->exp
.X_add_number
);
1183 /* The COFF port has always been off by one, changing it
1184 now would be an incompatible change, so we leave it as-is.
1186 We don't want to do this for ELF as we want to be
1187 compatible with the proposed ELF format from Hitachi. */
1188 operand
[i
].exp
.X_add_number
-= 1;
1190 operand
[i
].exp
.X_add_number
=
1191 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1193 fixP
= fix_new_exp (frag_now
,
1194 output
- frag_now
->fr_literal
+ where
,
1199 fixP
->fx_signed
= 1;
1201 else if (x
& MEMIND
)
1203 check_operand (operand
+ i
, 0xff, "@@");
1204 fix_new_exp (frag_now
,
1205 output
- frag_now
->fr_literal
+ 1,
1211 else if (x
& ABSJMP
)
1216 /* To be compatible with the proposed H8 ELF format, we
1217 want the relocation's offset to point to the first byte
1218 that will be modified, not to the start of the instruction. */
1222 /* This jmp may be a jump or a branch. */
1224 check_operand (operand
+ i
, Hmode
? 0xffffff : 0xffff, "@");
1226 if (operand
[i
].exp
.X_add_number
& 1)
1227 as_warn (_("branch operand has odd offset (%lx)\n"),
1228 (unsigned long) operand
->exp
.X_add_number
);
1231 operand
[i
].exp
.X_add_number
=
1232 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1233 fix_new_exp (frag_now
,
1234 output
- frag_now
->fr_literal
+ where
,
1243 /* Try to give an intelligent error message for common and simple to
1247 clever_message (instruction
, operand
)
1248 const struct h8_instruction
*instruction
;
1249 struct h8_op
*operand
;
1251 /* Find out if there was more than one possible opcode. */
1253 if ((instruction
+ 1)->idx
!= instruction
->idx
)
1257 /* Only one opcode of this flavour, try to guess which operand
1259 for (argn
= 0; argn
< instruction
->noperands
; argn
++)
1261 switch (instruction
->opcode
->args
.nib
[argn
])
1264 if (operand
[argn
].mode
!= RD16
)
1266 as_bad (_("destination operand must be 16 bit register"));
1273 if (operand
[argn
].mode
!= RS8
)
1275 as_bad (_("source operand must be 8 bit register"));
1281 if (operand
[argn
].mode
!= ABS16DST
)
1283 as_bad (_("destination operand must be 16bit absolute address"));
1288 if (operand
[argn
].mode
!= RD8
)
1290 as_bad (_("destination operand must be 8 bit register"));
1296 if (operand
[argn
].mode
!= ABS16SRC
)
1298 as_bad (_("source operand must be 16bit absolute address"));
1306 as_bad (_("invalid operands"));
1309 /* This is the guts of the machine-dependent assembler. STR points to
1310 a machine dependent instruction. This function is supposed to emit
1311 the frags/bytes it assembles. */
1319 struct h8_op operand
[2];
1320 const struct h8_instruction
*instruction
;
1321 const struct h8_instruction
*prev_instruction
;
1327 /* Drop leading whitespace. */
1331 /* Find the op code end. */
1332 for (op_start
= op_end
= str
;
1333 *op_end
!= 0 && *op_end
!= ' ';
1345 if (op_end
== op_start
)
1347 as_bad (_("can't find opcode "));
1353 instruction
= (const struct h8_instruction
*)
1354 hash_find (opcode_hash_control
, op_start
);
1356 if (instruction
== NULL
)
1358 as_bad (_("unknown opcode"));
1362 /* We used to set input_line_pointer to the result of get_operands,
1363 but that is wrong. Our caller assumes we don't change it. */
1365 (void) get_operands (instruction
->noperands
, op_end
, operand
);
1367 prev_instruction
= instruction
;
1387 instruction
= get_specific (instruction
, operand
, size
);
1389 if (instruction
== 0)
1391 /* Couldn't find an opcode which matched the operands. */
1392 char *where
= frag_more (2);
1396 clever_message (prev_instruction
, operand
);
1400 if (instruction
->size
&& dot
)
1402 if (instruction
->size
!= *dot
)
1404 as_warn (_("mismatch between opcode size and operand size"));
1408 build_bytes (instruction
, operand
);
1411 #ifndef BFD_ASSEMBLER
1413 tc_crawl_symbol_chain (headers
)
1414 object_headers
*headers ATTRIBUTE_UNUSED
;
1416 printf (_("call to tc_crawl_symbol_chain \n"));
1421 md_undefined_symbol (name
)
1422 char *name ATTRIBUTE_UNUSED
;
1427 #ifndef BFD_ASSEMBLER
1429 tc_headers_hook (headers
)
1430 object_headers
*headers ATTRIBUTE_UNUSED
;
1432 printf (_("call to tc_headers_hook \n"));
1436 /* Various routines to kill one day */
1437 /* Equal to MAX_PRECISION in atof-ieee.c */
1438 #define MAX_LITTLENUMS 6
1440 /* Turn a string in input_line_pointer into a floating point constant
1441 of type TYPE, and store the appropriate bytes in *LITP. The number
1442 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1443 returned, or NULL on OK. */
1446 md_atof (type
, litP
, sizeP
)
1452 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1453 LITTLENUM_TYPE
*wordP
;
1484 return _("Bad call to MD_ATOF()");
1486 t
= atof_ieee (input_line_pointer
, type
, words
);
1488 input_line_pointer
= t
;
1490 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1491 for (wordP
= words
; prec
--;)
1493 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1494 litP
+= sizeof (LITTLENUM_TYPE
);
1499 const char *md_shortopts
= "";
1500 struct option md_longopts
[] = {
1501 {NULL
, no_argument
, NULL
, 0}
1504 size_t md_longopts_size
= sizeof (md_longopts
);
1507 md_parse_option (c
, arg
)
1508 int c ATTRIBUTE_UNUSED
;
1509 char *arg ATTRIBUTE_UNUSED
;
1515 md_show_usage (stream
)
1516 FILE *stream ATTRIBUTE_UNUSED
;
1520 void tc_aout_fix_to_chars
PARAMS ((void));
1523 tc_aout_fix_to_chars ()
1525 printf (_("call to tc_aout_fix_to_chars \n"));
1530 md_convert_frag (headers
, seg
, fragP
)
1531 #ifdef BFD_ASSEMBLER
1532 bfd
*headers ATTRIBUTE_UNUSED
;
1534 object_headers
*headers ATTRIBUTE_UNUSED
;
1536 segT seg ATTRIBUTE_UNUSED
;
1537 fragS
*fragP ATTRIBUTE_UNUSED
;
1539 printf (_("call to md_convert_frag \n"));
1543 #ifdef BFD_ASSEMBLER
1545 md_section_align (segment
, size
)
1549 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1550 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1554 md_section_align (seg
, size
)
1558 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
1559 & (-1 << section_alignment
[(int) seg
]));
1565 md_apply_fix3 (fixP
, valP
, seg
)
1568 segT seg ATTRIBUTE_UNUSED
;
1570 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1573 switch (fixP
->fx_size
)
1579 *buf
++ = (val
>> 8);
1583 *buf
++ = (val
>> 24);
1584 *buf
++ = (val
>> 16);
1585 *buf
++ = (val
>> 8);
1592 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1597 md_estimate_size_before_relax (fragP
, segment_type
)
1598 register fragS
*fragP ATTRIBUTE_UNUSED
;
1599 register segT segment_type ATTRIBUTE_UNUSED
;
1601 printf (_("call tomd_estimate_size_before_relax \n"));
1605 /* Put number into target byte order. */
1607 md_number_to_chars (ptr
, use
, nbytes
)
1612 number_to_chars_bigendian (ptr
, use
, nbytes
);
1616 md_pcrel_from (fixP
)
1617 fixS
*fixP ATTRIBUTE_UNUSED
;
1622 #ifndef BFD_ASSEMBLER
1624 tc_reloc_mangle (fix_ptr
, intr
, base
)
1626 struct internal_reloc
*intr
;
1630 symbolS
*symbol_ptr
;
1632 symbol_ptr
= fix_ptr
->fx_addsy
;
1634 /* If this relocation is attached to a symbol then it's ok
1636 if (fix_ptr
->fx_r_type
== TC_CONS_RELOC
)
1638 /* cons likes to create reloc32's whatever the size of the reloc..
1640 switch (fix_ptr
->fx_size
)
1643 intr
->r_type
= R_RELLONG
;
1646 intr
->r_type
= R_RELWORD
;
1649 intr
->r_type
= R_RELBYTE
;
1657 intr
->r_type
= fix_ptr
->fx_r_type
;
1660 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
1661 intr
->r_offset
= fix_ptr
->fx_offset
;
1665 if (symbol_ptr
->sy_number
!= -1)
1666 intr
->r_symndx
= symbol_ptr
->sy_number
;
1671 /* This case arises when a reference is made to `.'. */
1672 segsym
= seg_info (S_GET_SEGMENT (symbol_ptr
))->dot
;
1674 intr
->r_symndx
= -1;
1677 intr
->r_symndx
= segsym
->sy_number
;
1678 intr
->r_offset
+= S_GET_VALUE (symbol_ptr
);
1683 intr
->r_symndx
= -1;
1685 #else /* BFD_ASSEMBLER */
1687 tc_gen_reloc (section
, fixp
)
1688 asection
*section ATTRIBUTE_UNUSED
;
1692 bfd_reloc_code_real_type r_type
;
1694 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
1696 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
1697 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
1699 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1700 "Difference of symbols in different sections is not supported");
1705 rel
= (arelent
*) xmalloc (sizeof (arelent
));
1706 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1707 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1708 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1709 rel
->addend
= fixp
->fx_offset
;
1711 r_type
= fixp
->fx_r_type
;
1715 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
1718 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
1719 if (rel
->howto
== NULL
)
1721 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1722 _("Cannot represent relocation type %s"),
1723 bfd_get_reloc_code_name (r_type
));