1 /* tc-h8300.c -- Assemble code for the Hitachi H8/300
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 2001, 2002 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 static void pint
PARAMS ((int));
50 #define PSIZE (Hmode ? L_32 : L_16)
52 #define DSYMMODE (Hmode ? L_24 : L_16)
54 int bsize
= L_8
; /* default branch displacement */
58 int arg ATTRIBUTE_UNUSED
;
63 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300h
))
64 as_warn (_("could not set architecture and machine"));
70 int arg ATTRIBUTE_UNUSED
;
75 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300s
))
76 as_warn (_("could not set architecture and machine"));
89 int arg ATTRIBUTE_UNUSED
;
94 /* This table describes all the machine specific pseudo-ops the assembler
95 has to support. The fields are:
96 pseudo-op name without dot
97 function to call to execute this pseudo-op
98 Integer arg to pass to the function. */
100 const pseudo_typeS md_pseudo_table
[] =
102 {"h8300h", h8300hmode
, 0},
103 {"h8300s", h8300smode
, 0},
104 {"sbranch", sbranch
, L_8
},
105 {"lbranch", sbranch
, L_16
},
111 {"form", listing_psize
, 0},
112 {"heading", listing_title
, 0},
113 {"import", s_ignore
, 0},
114 {"page", listing_eject
, 0},
115 {"program", s_ignore
, 0},
119 const int md_reloc_size
;
121 const char EXP_CHARS
[] = "eE";
123 /* Chars that mean this number is a floating point constant
126 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
128 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics. */
130 /* This function is called once, at assembler startup time. This
131 should set up all the tables, etc. that the MD part of the assembler
137 struct h8_opcode
*opcode
;
138 char prev_buffer
[100];
142 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_h8300
, bfd_mach_h8300
))
143 as_warn (_("could not set architecture and machine"));
146 opcode_hash_control
= hash_new ();
149 for (opcode
= h8_opcodes
; opcode
->name
; opcode
++)
151 /* Strip off any . part when inserting the opcode and only enter
152 unique codes into the hash table. */
153 char *src
= opcode
->name
;
154 unsigned int len
= strlen (src
);
155 char *dst
= malloc (len
+ 1);
170 if (strcmp (buffer
, prev_buffer
))
172 hash_insert (opcode_hash_control
, buffer
, (char *) opcode
);
173 strcpy (prev_buffer
, buffer
);
178 /* Find the number of operands. */
179 opcode
->noperands
= 0;
180 while (opcode
->args
.nib
[opcode
->noperands
] != E
)
183 /* Find the length of the opcode in bytes. */
185 while (opcode
->data
.nib
[opcode
->length
* 2] != E
)
200 int opsize
; /* Set when a register size is seen. */
209 static void clever_message
PARAMS ((struct h8_opcode
*, struct h8_op
*));
210 static void build_bytes
PARAMS ((struct h8_opcode
*, struct h8_op
*));
211 static void do_a_fix_imm
PARAMS ((int, struct h8_op
*, int));
212 static void check_operand
PARAMS ((struct h8_op
*, unsigned int, char *));
213 static struct h8_opcode
* get_specific
PARAMS ((struct h8_opcode
*, struct h8_op
*, int));
214 static char * get_operands
PARAMS ((unsigned, char *, struct h8_op
*));
215 static void get_operand
PARAMS ((char **, struct h8_op
*, unsigned, int));
216 static char * skip_colonthing
PARAMS ((char *, expressionS
*, int *));
217 static char * parse_exp
PARAMS ((char *, expressionS
*));
218 static int parse_reg
PARAMS ((char *, op_type
*, unsigned *, int));
219 char * colonmod24
PARAMS ((struct h8_op
*, char *));
223 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
232 /* Try to parse a reg name. Return the number of chars consumed. */
235 parse_reg (src
, mode
, reg
, direction
)
244 /* Cribbed from get_symbol_end. */
245 if (!is_name_beginner (*src
) || *src
== '\001')
248 while (is_part_of_name (*end
) || *end
== '\001')
252 if (len
== 2 && src
[0] == 's' && src
[1] == 'p')
254 *mode
= PSIZE
| REG
| direction
;
258 if (len
== 3 && src
[0] == 'c' && src
[1] == 'c' && src
[2] == 'r')
264 if (len
== 3 && src
[0] == 'e' && src
[1] == 'x' && src
[2] == 'r')
270 if (len
== 2 && src
[0] == 'f' && src
[1] == 'p')
272 *mode
= PSIZE
| REG
| direction
;
276 if (len
== 3 && src
[0] == 'e' && src
[1] == 'r'
277 && src
[2] >= '0' && src
[2] <= '7')
279 *mode
= L_32
| REG
| direction
;
282 as_warn (_("Reg not valid for H8/300"));
285 if (len
== 2 && src
[0] == 'e' && src
[1] >= '0' && src
[1] <= '7')
287 *mode
= L_16
| REG
| direction
;
288 *reg
= src
[1] - '0' + 8;
290 as_warn (_("Reg not valid for H8/300"));
296 if (src
[1] >= '0' && src
[1] <= '7')
298 if (len
== 3 && src
[2] == 'l')
300 *mode
= L_8
| REG
| direction
;
301 *reg
= (src
[1] - '0') + 8;
304 if (len
== 3 && src
[2] == 'h')
306 *mode
= L_8
| REG
| direction
;
307 *reg
= (src
[1] - '0');
312 *mode
= L_16
| REG
| direction
;
313 *reg
= (src
[1] - '0');
327 char *save
= input_line_pointer
;
330 input_line_pointer
= s
;
332 if (op
->X_op
== O_absent
)
333 as_bad (_("missing operand"));
334 new = input_line_pointer
;
335 input_line_pointer
= save
;
340 skip_colonthing (ptr
, exp
, mode
)
342 expressionS
*exp ATTRIBUTE_UNUSED
;
352 /* ff fill any 8 bit quantity. */
353 /* exp->X_add_number -= 0x100; */
362 else if (*ptr
== '3')
366 else if (*ptr
== '1')
370 while (ISDIGIT (*ptr
))
377 /* The many forms of operand:
380 @Rn Register indirect
381 @(exp[:16], Rn) Register indirect with displacement
385 @aa:16 absolute 16 bit
388 #xx[:size] immediate data
389 @(exp:[8], pc) pc rel
390 @@aa[:8] memory indirect. */
398 src
= skip_colonthing (src
, &op
->exp
, &mode
);
402 /* Choose a default mode. */
403 if (op
->exp
.X_add_number
< -32768
404 || op
->exp
.X_add_number
> 32767)
411 else if (op
->exp
.X_add_symbol
412 || op
->exp
.X_op_symbol
)
423 get_operand (ptr
, op
, dst
, direction
)
426 unsigned int dst ATTRIBUTE_UNUSED
;
436 /* Check for '(' and ')' for instructions ldm and stm. */
437 if (src
[0] == '(' && src
[8] == ')')
440 /* Gross. Gross. ldm and stm have a format not easily handled
441 by get_operand. We deal with it explicitly here. */
442 if (src
[0] == 'e' && src
[1] == 'r' && ISDIGIT (src
[2])
443 && src
[3] == '-' && src
[4] == 'e' && src
[5] == 'r' && ISDIGIT (src
[6]))
451 as_bad (_("Invalid register list for ldm/stm\n"));
454 as_bad (_("Invalid register list for ldm/stm\n"));
457 as_bad (_("Invalid register list for ldm/stm\n"));
461 as_bad (_("Invalid register list for ldm/stm\n"));
463 /* Even sicker. We encode two registers into op->reg. One
464 for the low register to save, the other for the high
465 register to save; we also set the high bit in op->reg
466 so we know this is "very special". */
467 op
->reg
= 0x80000000 | (high
<< 8) | low
;
476 len
= parse_reg (src
, &op
->mode
, &op
->reg
, direction
);
489 src
= parse_exp (src
, &op
->exp
);
491 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
502 len
= parse_reg (src
, &mode
, &num
, direction
);
505 /* Oops, not a reg after all, must be ordinary exp. */
507 /* Must be a symbol. */
508 op
->mode
= ABS
| PSIZE
| direction
;
509 *ptr
= skip_colonthing (parse_exp (src
, &op
->exp
),
510 &op
->exp
, &op
->mode
);
515 if ((mode
& SIZE
) != PSIZE
)
516 as_bad (_("Wrong size pointer register for architecture."));
527 /* Start off assuming a 16 bit offset. */
529 src
= parse_exp (src
, &op
->exp
);
531 src
= colonmod24 (op
, src
);
536 op
->mode
|= ABS
| direction
;
543 as_bad (_("expected @(exp, reg16)"));
549 len
= parse_reg (src
, &mode
, &op
->reg
, direction
);
550 if (len
== 0 || !(mode
& REG
))
552 as_bad (_("expected @(exp, reg16)"));
555 op
->mode
|= DISP
| direction
;
558 src
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
560 if (*src
!= ')' && '(')
562 as_bad (_("expected @(exp, reg16)"));
569 len
= parse_reg (src
, &mode
, &num
, direction
);
577 if ((mode
& SIZE
) != PSIZE
)
578 as_bad (_("Wrong size pointer register for architecture."));
584 if ((mode
& SIZE
) != PSIZE
)
585 as_bad (_("Wrong size pointer register for architecture."));
587 op
->mode
= direction
| IND
| PSIZE
;
595 /* must be a symbol */
597 op
->mode
= ABS
| direction
;
598 src
= parse_exp (src
, &op
->exp
);
600 *ptr
= colonmod24 (op
, src
);
610 src
= parse_exp (src
, &op
->exp
);
611 *ptr
= skip_colonthing (src
, &op
->exp
, &op
->mode
);
615 else if (strncmp (src
, "mach", 4) == 0
616 || strncmp (src
, "macl", 4) == 0)
618 op
->reg
= src
[3] == 'l';
625 src
= parse_exp (src
, &op
->exp
);
626 /* Trailing ':' size ? */
629 if (src
[1] == '1' && src
[2] == '6')
631 op
->mode
= PCREL
| L_16
;
634 else if (src
[1] == '8')
636 op
->mode
= PCREL
| L_8
;
640 as_bad (_("expect :8 or :16 here"));
643 op
->mode
= PCREL
| bsize
;
650 get_operands (noperands
, op_end
, operand
)
651 unsigned int noperands
;
653 struct h8_op
*operand
;
666 get_operand (&ptr
, operand
+ 0, 0, SRC
);
670 get_operand (&ptr
, operand
+ 1, 1, DST
);
680 get_operand (&ptr
, operand
+ 0, 0, SRC
);
683 get_operand (&ptr
, operand
+ 1, 1, DST
);
693 /* Passed a pointer to a list of opcodes which use different
694 addressing modes, return the opcode which matches the opcodes
697 static struct h8_opcode
*
698 get_specific (opcode
, operands
, size
)
699 struct h8_opcode
*opcode
;
700 struct h8_op
*operands
;
703 struct h8_opcode
*this_try
= opcode
;
705 int this_index
= opcode
->idx
;
707 /* There's only one ldm/stm and it's easier to just
708 get out quick for them. */
709 if (strcmp (opcode
->name
, "stm.l") == 0
710 || strcmp (opcode
->name
, "ldm.l") == 0)
713 while (this_index
== opcode
->idx
&& !found
)
718 if (this_try
->noperands
== 0)
722 this_size
= this_try
->how
& SN
;
723 if (this_size
!= size
&& (this_size
!= SB
|| size
!= SN
))
730 for (i
= 0; i
< this_try
->noperands
&& found
; i
++)
732 op_type op
= this_try
->args
.nib
[i
];
733 int x
= operands
[i
].mode
;
735 if ((op
& (DISP
| REG
)) == (DISP
| REG
)
736 && ((x
& (DISP
| REG
)) == (DISP
| REG
)))
738 dispreg
= operands
[i
].reg
;
746 x
= (x
& ~L_P
) | (Hmode
? L_32
: L_16
);
748 op
= (op
& ~L_P
) | (Hmode
? L_32
: L_16
);
752 /* The size of the reg is v important. */
753 if ((op
& SIZE
) != (x
& SIZE
))
756 else if ((op
& ABSJMP
) && (x
& ABS
))
758 operands
[i
].mode
&= ~ABS
;
759 operands
[i
].mode
|= ABSJMP
;
760 /* But it may not be 24 bits long. */
763 operands
[i
].mode
&= ~SIZE
;
764 operands
[i
].mode
|= L_16
;
767 else if ((op
& (KBIT
| DBIT
)) && (x
& IMM
))
769 /* This is ok if the immediate value is sensible. */
773 /* The size of the displacement is important. */
774 if ((op
& SIZE
) != (x
& SIZE
))
777 else if ((op
& (DISP
| IMM
| ABS
))
778 && (op
& (DISP
| IMM
| ABS
)) == (x
& (DISP
| IMM
| ABS
)))
780 /* Promote a L_24 to L_32 if it makes us match. */
781 if ((x
& L_24
) && (op
& L_32
))
786 /* Promote an L8 to L_16 if it makes us match. */
787 if (op
& ABS
&& op
& L_8
&& op
& DISP
)
792 else if ((x
& SIZE
) != 0
793 && ((op
& SIZE
) != (x
& SIZE
)))
796 else if ((op
& MACREG
) != (x
& MACREG
))
800 else if ((op
& MODE
) != (x
& MODE
))
814 check_operand (operand
, width
, string
)
815 struct h8_op
*operand
;
819 if (operand
->exp
.X_add_symbol
== 0
820 && operand
->exp
.X_op_symbol
== 0)
822 /* No symbol involved, let's look at offset, it's dangerous if
823 any of the high bits are not 0 or ff's, find out by oring or
824 anding with the width and seeing if the answer is 0 or all
827 if ((operand
->exp
.X_add_number
& ~width
) != 0 &&
828 (operand
->exp
.X_add_number
| width
) != (unsigned)(~0))
831 && (operand
->exp
.X_add_number
& 0xff00) == 0xff00)
833 /* Just ignore this one - which happens when trying to
834 fit a 16 bit address truncated into an 8 bit address
835 of something like bset. */
837 else if (strcmp (string
, "@") == 0
839 && (operand
->exp
.X_add_number
& 0xff8000) == 0xff8000)
841 /* Just ignore this one - which happens when trying to
842 fit a 24 bit address truncated into a 16 bit address
843 of something like mov.w. */
847 as_warn (_("operand %s0x%lx out of range."), string
,
848 (unsigned long) operand
->exp
.X_add_number
);
854 /* RELAXMODE has one of 3 values:
856 0 Output a "normal" reloc, no relaxing possible for this insn/reloc
858 1 Output a relaxable 24bit absolute mov.w address relocation
859 (may relax into a 16bit absolute address).
861 2 Output a relaxable 16/24 absolute mov.b address relocation
862 (may relax into an 8bit absolute address). */
865 do_a_fix_imm (offset
, operand
, relaxmode
)
867 struct h8_op
*operand
;
874 char *t
= operand
->mode
& IMM
? "#" : "@";
876 if (operand
->exp
.X_add_symbol
== 0)
878 char *bytes
= frag_now
->fr_literal
+ offset
;
879 switch (operand
->mode
& SIZE
)
882 check_operand (operand
, 0x3, t
);
883 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
886 check_operand (operand
, 0x7, t
);
887 bytes
[0] |= (operand
->exp
.X_add_number
) << 4;
890 check_operand (operand
, 0xff, t
);
891 bytes
[0] = operand
->exp
.X_add_number
;
894 check_operand (operand
, 0xffff, t
);
895 bytes
[0] = operand
->exp
.X_add_number
>> 8;
896 bytes
[1] = operand
->exp
.X_add_number
>> 0;
899 check_operand (operand
, 0xffffff, t
);
900 bytes
[0] = operand
->exp
.X_add_number
>> 16;
901 bytes
[1] = operand
->exp
.X_add_number
>> 8;
902 bytes
[2] = operand
->exp
.X_add_number
>> 0;
906 /* This should be done with bfd. */
907 bytes
[0] = operand
->exp
.X_add_number
>> 24;
908 bytes
[1] = operand
->exp
.X_add_number
>> 16;
909 bytes
[2] = operand
->exp
.X_add_number
>> 8;
910 bytes
[3] = operand
->exp
.X_add_number
>> 0;
913 idx
= (relaxmode
== 2) ? R_MOV24B1
: R_MOVL1
;
914 fix_new_exp (frag_now
, offset
, 4, &operand
->exp
, 0, idx
);
921 switch (operand
->mode
& SIZE
)
926 where
= (operand
->mode
& SIZE
) == L_24
? -1 : 0;
929 else if (relaxmode
== 1)
935 as_bad (_("Can't work out size of operand.\n"));
943 operand
->exp
.X_add_number
=
944 ((operand
->exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
950 operand
->exp
.X_add_number
=
951 ((operand
->exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
954 fix_new_exp (frag_now
,
963 /* Now we know what sort of opcodes it is, let's build the bytes. */
966 build_bytes (this_try
, operand
)
967 struct h8_opcode
*this_try
;
968 struct h8_op
*operand
;
971 char *output
= frag_more (this_try
->length
);
972 op_type
*nibble_ptr
= this_try
->data
.nib
;
974 unsigned int nibble_count
= 0;
982 if (!(this_try
->inbase
|| Hmode
))
983 as_warn (_("Opcode `%s' with these operand types not available in H8/300 mode"),
986 while (*nibble_ptr
!= E
)
991 d
= (c
& (DST
| SRC_IN_DST
)) != 0;
997 if (c
& (REG
| IND
| INC
| DEC
))
998 nib
= operand
[d
].reg
;
1000 else if ((c
& DISPREG
) == (DISPREG
))
1005 operand
[d
].mode
= c
;
1006 absat
= nibble_count
/ 2;
1009 else if (c
& (IMM
| PCREL
| ABS
| ABSJMP
| DISP
))
1011 operand
[d
].mode
= c
;
1012 immat
= nibble_count
/ 2;
1015 else if (c
& IGNORE
)
1020 switch (operand
[0].exp
.X_add_number
)
1029 as_bad (_("Need #1 or #2 here"));
1034 switch (operand
[0].exp
.X_add_number
)
1044 as_warn (_("#4 not valid on H8/300."));
1049 as_bad (_("Need #1 or #2 here"));
1052 /* Stop it making a fix. */
1053 operand
[0].mode
= 0;
1057 operand
[d
].mode
|= MEMRELAX
;
1064 if (operand
[0].mode
== MACREG
)
1065 /* stmac has mac[hl] as the first operand. */
1066 nib
= 2 + operand
[0].reg
;
1068 /* ldmac has mac[hl] as the second operand. */
1069 nib
= 2 + operand
[1].reg
;
1077 /* Disgusting. Why, oh why didn't someone ask us for advice
1078 on the assembler format. */
1079 if (strcmp (this_try
->name
, "stm.l") == 0
1080 || strcmp (this_try
->name
, "ldm.l") == 0)
1083 high
= (operand
[this_try
->name
[0] == 'l' ? 1 : 0].reg
>> 8) & 0xf;
1084 low
= operand
[this_try
->name
[0] == 'l' ? 1 : 0].reg
& 0xf;
1086 asnibbles
[2] = high
- low
;
1087 asnibbles
[7] = (this_try
->name
[0] == 'l') ? high
: low
;
1090 for (i
= 0; i
< this_try
->length
; i
++)
1091 output
[i
] = (asnibbles
[i
* 2] << 4) | asnibbles
[i
* 2 + 1];
1093 /* Note if this is a movb instruction -- there's a special relaxation
1094 which only applies to them. */
1095 if (strcmp (this_try
->name
, "mov.b") == 0)
1098 /* Output any fixes. */
1099 for (i
= 0; i
< 2; i
++)
1101 int x
= operand
[i
].mode
;
1103 if (x
& (IMM
| DISP
))
1104 do_a_fix_imm (output
- frag_now
->fr_literal
+ immat
,
1105 operand
+ i
, (x
& MEMRELAX
) != 0);
1108 do_a_fix_imm (output
- frag_now
->fr_literal
+ absat
,
1109 operand
+ i
, (x
& MEMRELAX
) ? movb
+ 1 : 0);
1113 int size16
= x
& (L_16
);
1114 int where
= size16
? 2 : 1;
1115 int size
= size16
? 2 : 1;
1116 int type
= size16
? R_PCRWORD
: R_PCRBYTE
;
1119 check_operand (operand
+ i
, size16
? 0x7fff : 0x7f, "@");
1121 if (operand
[i
].exp
.X_add_number
& 1)
1122 as_warn (_("branch operand has odd offset (%lx)\n"),
1123 (unsigned long) operand
->exp
.X_add_number
);
1125 /* The COFF port has always been off by one, changing it
1126 now would be an incompatible change, so we leave it as-is.
1128 We don't want to do this for ELF as we want to be
1129 compatible with the proposed ELF format from Hitachi. */
1130 operand
[i
].exp
.X_add_number
-= 1;
1132 operand
[i
].exp
.X_add_number
=
1133 ((operand
[i
].exp
.X_add_number
& 0xff) ^ 0x80) - 0x80;
1135 fixP
= fix_new_exp (frag_now
,
1136 output
- frag_now
->fr_literal
+ where
,
1141 fixP
->fx_signed
= 1;
1143 else if (x
& MEMIND
)
1145 check_operand (operand
+ i
, 0xff, "@@");
1146 fix_new_exp (frag_now
,
1147 output
- frag_now
->fr_literal
+ 1,
1153 else if (x
& ABSJMP
)
1158 /* To be compatible with the proposed H8 ELF format, we
1159 want the relocation's offset to point to the first byte
1160 that will be modified, not to the start of the instruction. */
1164 /* This jmp may be a jump or a branch. */
1166 check_operand (operand
+ i
, Hmode
? 0xffffff : 0xffff, "@");
1168 if (operand
[i
].exp
.X_add_number
& 1)
1169 as_warn (_("branch operand has odd offset (%lx)\n"),
1170 (unsigned long) operand
->exp
.X_add_number
);
1173 operand
[i
].exp
.X_add_number
=
1174 ((operand
[i
].exp
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
1175 fix_new_exp (frag_now
,
1176 output
- frag_now
->fr_literal
+ where
,
1185 /* Try to give an intelligent error message for common and simple to
1189 clever_message (opcode
, operand
)
1190 struct h8_opcode
*opcode
;
1191 struct h8_op
*operand
;
1193 /* Find out if there was more than one possible opcode. */
1195 if ((opcode
+ 1)->idx
!= opcode
->idx
)
1199 /* Only one opcode of this flavour, try to guess which operand
1201 for (argn
= 0; argn
< opcode
->noperands
; argn
++)
1203 switch (opcode
->args
.nib
[argn
])
1206 if (operand
[argn
].mode
!= RD16
)
1208 as_bad (_("destination operand must be 16 bit register"));
1215 if (operand
[argn
].mode
!= RS8
)
1217 as_bad (_("source operand must be 8 bit register"));
1223 if (operand
[argn
].mode
!= ABS16DST
)
1225 as_bad (_("destination operand must be 16bit absolute address"));
1230 if (operand
[argn
].mode
!= RD8
)
1232 as_bad (_("destination operand must be 8 bit register"));
1238 if (operand
[argn
].mode
!= ABS16SRC
)
1240 as_bad (_("source operand must be 16bit absolute address"));
1248 as_bad (_("invalid operands"));
1251 /* This is the guts of the machine-dependent assembler. STR points to
1252 a machine dependent instruction. This function is supposed to emit
1253 the frags/bytes it assembles. */
1261 struct h8_op operand
[2];
1262 struct h8_opcode
*opcode
;
1263 struct h8_opcode
*prev_opcode
;
1269 /* Drop leading whitespace. */
1273 /* Find the op code end. */
1274 for (op_start
= op_end
= str
;
1275 *op_end
!= 0 && *op_end
!= ' ';
1287 if (op_end
== op_start
)
1289 as_bad (_("can't find opcode "));
1295 opcode
= (struct h8_opcode
*) hash_find (opcode_hash_control
,
1300 as_bad (_("unknown opcode"));
1304 /* We used to set input_line_pointer to the result of get_operands,
1305 but that is wrong. Our caller assumes we don't change it. */
1307 (void) get_operands (opcode
->noperands
, op_end
, operand
);
1309 prev_opcode
= opcode
;
1329 opcode
= get_specific (opcode
, operand
, size
);
1333 /* Couldn't find an opcode which matched the operands. */
1334 char *where
= frag_more (2);
1338 clever_message (prev_opcode
, operand
);
1342 if (opcode
->size
&& dot
)
1344 if (opcode
->size
!= *dot
)
1346 as_warn (_("mismatch between opcode size and operand size"));
1350 build_bytes (opcode
, operand
);
1353 #ifndef BFD_ASSEMBLER
1355 tc_crawl_symbol_chain (headers
)
1356 object_headers
*headers ATTRIBUTE_UNUSED
;
1358 printf (_("call to tc_crawl_symbol_chain \n"));
1363 md_undefined_symbol (name
)
1364 char *name ATTRIBUTE_UNUSED
;
1369 #ifndef BFD_ASSEMBLER
1371 tc_headers_hook (headers
)
1372 object_headers
*headers ATTRIBUTE_UNUSED
;
1374 printf (_("call to tc_headers_hook \n"));
1378 /* Various routines to kill one day */
1379 /* Equal to MAX_PRECISION in atof-ieee.c */
1380 #define MAX_LITTLENUMS 6
1382 /* Turn a string in input_line_pointer into a floating point constant
1383 of type TYPE, and store the appropriate bytes in *LITP. The number
1384 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1385 returned, or NULL on OK. */
1388 md_atof (type
, litP
, sizeP
)
1394 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1395 LITTLENUM_TYPE
*wordP
;
1426 return _("Bad call to MD_ATOF()");
1428 t
= atof_ieee (input_line_pointer
, type
, words
);
1430 input_line_pointer
= t
;
1432 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1433 for (wordP
= words
; prec
--;)
1435 md_number_to_chars (litP
, (long) (*wordP
++), sizeof (LITTLENUM_TYPE
));
1436 litP
+= sizeof (LITTLENUM_TYPE
);
1441 const char *md_shortopts
= "";
1442 struct option md_longopts
[] = {
1443 {NULL
, no_argument
, NULL
, 0}
1446 size_t md_longopts_size
= sizeof (md_longopts
);
1449 md_parse_option (c
, arg
)
1450 int c ATTRIBUTE_UNUSED
;
1451 char *arg ATTRIBUTE_UNUSED
;
1457 md_show_usage (stream
)
1458 FILE *stream ATTRIBUTE_UNUSED
;
1462 void tc_aout_fix_to_chars
PARAMS ((void));
1465 tc_aout_fix_to_chars ()
1467 printf (_("call to tc_aout_fix_to_chars \n"));
1472 md_convert_frag (headers
, seg
, fragP
)
1473 #ifdef BFD_ASSEMBLER
1474 bfd
*headers ATTRIBUTE_UNUSED
;
1476 object_headers
*headers ATTRIBUTE_UNUSED
;
1478 segT seg ATTRIBUTE_UNUSED
;
1479 fragS
*fragP ATTRIBUTE_UNUSED
;
1481 printf (_("call to md_convert_frag \n"));
1485 #ifdef BFD_ASSEMBLER
1487 md_section_align (segment
, size
)
1491 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1492 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1496 md_section_align (seg
, size
)
1500 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
1501 & (-1 << section_alignment
[(int) seg
]));
1507 md_apply_fix3 (fixP
, valP
, seg
)
1510 segT seg ATTRIBUTE_UNUSED
;
1512 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1513 long val
= * (long *) valP
;
1515 switch (fixP
->fx_size
)
1521 *buf
++ = (val
>> 8);
1525 *buf
++ = (val
>> 24);
1526 *buf
++ = (val
>> 16);
1527 *buf
++ = (val
>> 8);
1534 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1539 md_estimate_size_before_relax (fragP
, segment_type
)
1540 register fragS
*fragP ATTRIBUTE_UNUSED
;
1541 register segT segment_type ATTRIBUTE_UNUSED
;
1543 printf (_("call tomd_estimate_size_before_relax \n"));
1547 /* Put number into target byte order. */
1549 md_number_to_chars (ptr
, use
, nbytes
)
1554 number_to_chars_bigendian (ptr
, use
, nbytes
);
1558 md_pcrel_from (fixP
)
1559 fixS
*fixP ATTRIBUTE_UNUSED
;
1564 #ifndef BFD_ASSEMBLER
1566 tc_reloc_mangle (fix_ptr
, intr
, base
)
1568 struct internal_reloc
*intr
;
1572 symbolS
*symbol_ptr
;
1574 symbol_ptr
= fix_ptr
->fx_addsy
;
1576 /* If this relocation is attached to a symbol then it's ok
1578 if (fix_ptr
->fx_r_type
== TC_CONS_RELOC
)
1580 /* cons likes to create reloc32's whatever the size of the reloc..
1582 switch (fix_ptr
->fx_size
)
1585 intr
->r_type
= R_RELLONG
;
1588 intr
->r_type
= R_RELWORD
;
1591 intr
->r_type
= R_RELBYTE
;
1599 intr
->r_type
= fix_ptr
->fx_r_type
;
1602 intr
->r_vaddr
= fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
+ base
;
1603 intr
->r_offset
= fix_ptr
->fx_offset
;
1607 if (symbol_ptr
->sy_number
!= -1)
1608 intr
->r_symndx
= symbol_ptr
->sy_number
;
1613 /* This case arises when a reference is made to `.'. */
1614 segsym
= seg_info (S_GET_SEGMENT (symbol_ptr
))->dot
;
1616 intr
->r_symndx
= -1;
1619 intr
->r_symndx
= segsym
->sy_number
;
1620 intr
->r_offset
+= S_GET_VALUE (symbol_ptr
);
1625 intr
->r_symndx
= -1;
1627 #else /* BFD_ASSEMBLER */
1629 tc_gen_reloc (section
, fixp
)
1630 asection
*section ATTRIBUTE_UNUSED
;
1634 bfd_reloc_code_real_type r_type
;
1636 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
1638 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
1639 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
1641 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1642 "Difference of symbols in different sections is not supported");
1647 rel
= (arelent
*) xmalloc (sizeof (arelent
));
1648 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1649 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1650 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1651 rel
->addend
= fixp
->fx_offset
;
1653 r_type
= fixp
->fx_r_type
;
1657 fprintf (stderr
, "%s\n", bfd_get_reloc_code_name (r_type
));
1660 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
1661 if (rel
->howto
== NULL
)
1663 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1664 _("Cannot represent relocation type %s"),
1665 bfd_get_reloc_code_name (r_type
));