* elf64-alpha.c (elf64_alpha_relocate_section): Soft fail
[binutils.git] / gas / config / tc-h8500.c
bloba13c94268ed453d21c11703c63d51708c09630c8
1 /* tc-h8500.c -- Assemble code for the Hitachi H8/500
2 Copyright 1993, 1994, 1995, 1998, 2000, 2001
3 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)
10 any later version.
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
20 02111-1307, USA. */
22 /* Written By Steve Chamberlain <sac@cygnus.com>. */
24 #include <stdio.h>
25 #include "as.h"
26 #include "bfd.h"
27 #include "subsegs.h"
28 #define DEFINE_TABLE
29 #define ASSEMBLER_TABLE
30 #include "opcodes/h8500-opc.h"
31 #include <ctype.h>
33 const char comment_chars[] = "!";
34 const char line_separator_chars[] = ";";
35 const char line_comment_chars[] = "!#";
37 /* This table describes all the machine specific pseudo-ops the assembler
38 has to support. The fields are:
39 pseudo-op name without dot
40 function to call to execute this pseudo-op
41 Integer arg to pass to the function
44 void cons ();
46 const pseudo_typeS md_pseudo_table[] =
48 {"int", cons, 2},
49 {"data.b", cons, 1},
50 {"data.w", cons, 2},
51 {"data.l", cons, 4},
52 {"form", listing_psize, 0},
53 {"heading", listing_title, 0},
54 {"import", s_ignore, 0},
55 {"page", listing_eject, 0},
56 {"program", s_ignore, 0},
57 {0, 0, 0}
60 const int md_reloc_size;
62 const char EXP_CHARS[] = "eE";
64 /* Chars that mean this number is a floating point constant */
65 /* As in 0f12.456 */
66 /* or 0d1.2345e12 */
67 const char FLT_CHARS[] = "rRsSfFdDxXpP";
69 #define C(a,b) ENCODE_RELAX(a,b)
70 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
72 #define GET_WHAT(x) ((x>>2))
74 #define BYTE_DISP 1
75 #define WORD_DISP 2
76 #define UNDEF_BYTE_DISP 0
77 #define UNDEF_WORD_DISP 3
79 #define BRANCH 1
80 #define SCB_F 2
81 #define SCB_TST 3
82 #define END 4
84 #define BYTE_F 127
85 #define BYTE_B -126
86 #define WORD_F 32767
87 #define WORD_B 32768
89 relax_typeS md_relax_table[C (END, 0)] = {
90 { 0, 0, 0, 0 },
91 { 0, 0, 0, 0 },
92 { 0, 0, 0, 0 },
93 { 0, 0, 0, 0 },
95 /* BRANCH */
96 { 0, 0, 0, 0 },
97 { BYTE_F, BYTE_B, 2, C (BRANCH, WORD_DISP) },
98 { WORD_F, WORD_B, 3, 0 },
99 { 0, 0, 3, 0 },
101 /* SCB_F */
102 { 0, 0, 0, 0 },
103 { BYTE_F, BYTE_B, 3, C (SCB_F, WORD_DISP) },
104 { WORD_F, WORD_B, 8, 0 },
105 { 0, 0, 8, 0 },
107 /* SCB_TST */
108 { 0, 0, 0, 0 },
109 { BYTE_F, BYTE_B, 3, C (SCB_TST, WORD_DISP) },
110 { WORD_F, WORD_B, 10, 0 },
111 { 0, 0, 10, 0 }
115 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
118 This function is called once, at assembler startup time. This should
119 set up all the tables, etc. that the MD part of the assembler needs
122 void
123 md_begin ()
125 h8500_opcode_info *opcode;
126 char prev_buffer[100];
127 int idx = 0;
129 opcode_hash_control = hash_new ();
130 prev_buffer[0] = 0;
132 /* Insert unique names into hash table */
133 for (opcode = h8500_table; opcode->name; opcode++)
135 if (idx != opcode->idx)
137 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
138 idx++;
143 static int rn; /* register number used by RN */
144 static int rs; /* register number used by RS */
145 static int rd; /* register number used by RD */
146 static int crb; /* byte size cr */
147 static int crw; /* word sized cr */
148 static int cr; /* unknown size cr */
150 static expressionS displacement;/* displacement expression */
151 static int displacement_size; /* and size if given */
153 static int immediate_inpage;
154 static expressionS immediate; /* immediate expression */
155 static int immediate_size; /* and size if given */
157 static expressionS absolute; /* absolute expression */
158 static int absolute_size; /* and size if given */
160 typedef struct
162 int type;
163 int reg;
164 expressionS exp;
165 int page;
168 h8500_operand_info;
170 /* Try to parse a reg name. Return the number of chars consumed. */
172 static int
173 parse_reg (src, mode, reg)
174 char *src;
175 int *mode;
176 int *reg;
178 char *end;
179 int len;
181 /* Cribbed from get_symbol_end(). */
182 if (!is_name_beginner (*src) || *src == '\001')
183 return 0;
184 end = src + 1;
185 while (is_part_of_name (*end) || *end == '\001')
186 end++;
187 len = end - src;
189 if (len == 2 && src[0] == 'r')
191 if (src[1] >= '0' && src[1] <= '7')
193 *mode = RN;
194 *reg = (src[1] - '0');
195 return len;
198 if (len == 2 && src[0] == 's' && src[1] == 'p')
200 *mode = RN;
201 *reg = 7;
202 return len;
204 if (len == 3 && src[0] == 'c' && src[1] == 'c' && src[2] == 'r')
206 *mode = CRB;
207 *reg = 1;
208 return len;
210 if (len == 2 && src[0] == 's' && src[1] == 'r')
212 *mode = CRW;
213 *reg = 0;
214 return len;
216 if (len == 2 && src[0] == 'b' && src[1] == 'r')
218 *mode = CRB;
219 *reg = 3;
220 return len;
222 if (len == 2 && src[0] == 'e' && src[1] == 'p')
224 *mode = CRB;
225 *reg = 4;
226 return len;
228 if (len == 2 && src[0] == 'd' && src[1] == 'p')
230 *mode = CRB;
231 *reg = 5;
232 return len;
234 if (len == 2 && src[0] == 't' && src[1] == 'p')
236 *mode = CRB;
237 *reg = 7;
238 return len;
240 if (len == 2 && src[0] == 'f' && src[1] == 'p')
242 *mode = RN;
243 *reg = 6;
244 return len;
246 return 0;
249 static char *
250 parse_exp (s, op, page)
251 char *s;
252 expressionS *op;
253 int *page;
255 char *save;
256 char *new;
258 save = input_line_pointer;
260 *page = 0;
261 if (s[0] == '%')
263 if (s[1] == 'p' && s[2] == 'a' && s[3] == 'g' && s[4] == 'e')
265 s += 5;
266 *page = 'p';
268 if (s[1] == 'h' && s[2] == 'i' && s[3] == '1' && s[4] == '6')
270 s += 5;
271 *page = 'h';
273 else if (s[1] == 'o' && s[2] == 'f' && s[3] == 'f')
275 s += 4;
276 *page = 'o';
280 input_line_pointer = s;
282 expression (op);
283 if (op->X_op == O_absent)
284 as_bad (_("missing operand"));
285 new = input_line_pointer;
286 input_line_pointer = save;
287 return new;
290 typedef enum
292 exp_signed, exp_unsigned, exp_sandu
293 } sign_type;
295 static char *
296 skip_colonthing (sign, ptr, exp, def, size8, size16, size24)
297 sign_type sign;
298 char *ptr;
299 h8500_operand_info *exp;
300 int def;
301 int size8;
302 int size16;
303 int size24;
305 ptr = parse_exp (ptr, &exp->exp, &exp->page);
306 if (*ptr == ':')
308 ptr++;
309 if (*ptr == '8')
311 ptr++;
312 exp->type = size8;
314 else if (ptr[0] == '1' & ptr[1] == '6')
316 ptr += 2;
317 exp->type = size16;
319 else if (ptr[0] == '2' & ptr[1] == '4')
321 if (!size24)
323 as_bad (_(":24 not valid for this opcode"));
325 ptr += 2;
326 exp->type = size24;
328 else
330 as_bad (_("expect :8,:16 or :24"));
331 exp->type = size16;
334 else
336 if (exp->page == 'p')
338 exp->type = IMM8;
340 else if (exp->page == 'h')
342 exp->type = IMM16;
344 else
346 /* Let's work out the size from the context */
347 int n = exp->exp.X_add_number;
348 if (size8
349 && exp->exp.X_op == O_constant
350 && ((sign == exp_signed && (n >= -128 && n <= 127))
351 || (sign == exp_unsigned && (n >= 0 && (n <= 255)))
352 || (sign == exp_sandu && (n >= -128 && (n <= 255)))))
354 exp->type = size8;
356 else
358 exp->type = def;
362 return ptr;
365 static int
366 parse_reglist (src, op)
367 char *src;
368 h8500_operand_info *op;
370 int mode;
371 int rn;
372 int mask = 0;
373 int rm;
374 int idx = 1; /* skip ( */
376 while (src[idx] && src[idx] != ')')
378 int done = parse_reg (src + idx, &mode, &rn);
380 if (done)
382 idx += done;
383 mask |= 1 << rn;
385 else
387 as_bad (_("syntax error in reg list"));
388 return 0;
390 if (src[idx] == '-')
392 idx++;
393 done = parse_reg (src + idx, &mode, &rm);
394 if (done)
396 idx += done;
397 while (rn <= rm)
399 mask |= 1 << rn;
400 rn++;
403 else
405 as_bad (_("missing final register in range"));
408 if (src[idx] == ',')
409 idx++;
411 idx++;
412 op->exp.X_add_symbol = 0;
413 op->exp.X_op_symbol = 0;
414 op->exp.X_add_number = mask;
415 op->exp.X_op = O_constant;
416 op->exp.X_unsigned = 1;
417 op->type = IMM8;
418 return idx;
422 /* The many forms of operand:
424 Rn Register direct
425 @Rn Register indirect
426 @(disp[:size], Rn) Register indirect with displacement
427 @Rn+
428 @-Rn
429 @aa[:size] absolute
430 #xx[:size] immediate data
434 static void
435 get_operand (ptr, op, ispage)
436 char **ptr;
437 h8500_operand_info *op;
438 char ispage;
440 char *src = *ptr;
441 int mode;
442 unsigned int num;
443 unsigned int len;
444 op->page = 0;
445 if (src[0] == '(' && src[1] == 'r')
447 /* This is a register list */
448 *ptr = src + parse_reglist (src, op);
449 return;
452 len = parse_reg (src, &op->type, &op->reg);
454 if (len)
456 *ptr = src + len;
457 return;
460 if (*src == '@')
462 src++;
463 if (*src == '-')
465 src++;
466 len = parse_reg (src, &mode, &num);
467 if (len == 0)
469 /* Oops, not a reg after all, must be ordinary exp */
470 src--;
471 /* must be a symbol */
472 *ptr = skip_colonthing (exp_unsigned, src,
473 op, ABS16, ABS8, ABS16, ABS24);
474 return;
477 op->type = RNDEC;
478 op->reg = num;
479 *ptr = src + len;
480 return;
482 if (*src == '(')
484 /* Disp */
485 src++;
487 src = skip_colonthing (exp_signed, src,
488 op, RNIND_D16, RNIND_D8, RNIND_D16, 0);
490 if (*src != ',')
492 as_bad (_("expected @(exp, Rn)"));
493 return;
495 src++;
496 len = parse_reg (src, &mode, &op->reg);
497 if (len == 0 || mode != RN)
499 as_bad (_("expected @(exp, Rn)"));
500 return;
502 src += len;
503 if (*src != ')')
505 as_bad (_("expected @(exp, Rn)"));
506 return;
508 *ptr = src + 1;
509 return;
511 len = parse_reg (src, &mode, &num);
513 if (len)
515 src += len;
516 if (*src == '+')
518 src++;
519 if (mode != RN)
521 as_bad (_("@Rn+ needs word register"));
522 return;
524 op->type = RNINC;
525 op->reg = num;
526 *ptr = src;
527 return;
529 if (mode != RN)
531 as_bad (_("@Rn needs word register"));
532 return;
534 op->type = RNIND;
535 op->reg = num;
536 *ptr = src;
537 return;
539 else
541 /* must be a symbol */
542 *ptr =
543 skip_colonthing (exp_unsigned, src, op,
544 ispage ? ABS24 : ABS16, ABS8, ABS16, ABS24);
545 return;
549 if (*src == '#')
551 src++;
552 *ptr = skip_colonthing (exp_sandu, src, op, IMM16, IMM8, IMM16, ABS24);
553 return;
555 else
557 *ptr = skip_colonthing (exp_signed, src, op,
558 ispage ? ABS24 : PCREL8, PCREL8, PCREL16, ABS24);
562 static char *
563 get_operands (info, args, operand)
564 h8500_opcode_info *info;
565 char *args;
566 h8500_operand_info *operand;
569 char *ptr = args;
571 switch (info->nargs)
573 case 0:
574 operand[0].type = 0;
575 operand[1].type = 0;
576 break;
578 case 1:
579 ptr++;
580 get_operand (&ptr, operand + 0, info->name[0] == 'p');
581 operand[1].type = 0;
582 break;
584 case 2:
585 ptr++;
586 get_operand (&ptr, operand + 0, 0);
587 if (*ptr == ',')
588 ptr++;
589 get_operand (&ptr, operand + 1, 0);
590 break;
592 default:
593 abort ();
596 return ptr;
599 /* Passed a pointer to a list of opcodes which use different
600 addressing modes, return the opcode which matches the opcodes
601 provided. */
603 int pcrel8; /* Set when we've seen a pcrel operand */
605 static h8500_opcode_info *
606 get_specific (opcode, operands)
607 h8500_opcode_info *opcode;
608 h8500_operand_info *operands;
610 h8500_opcode_info *this_try = opcode;
611 int found = 0;
612 unsigned int noperands = opcode->nargs;
614 unsigned int this_index = opcode->idx;
616 while (this_index == opcode->idx && !found)
618 unsigned int i;
620 this_try = opcode++;
622 /* look at both operands needed by the opcodes and provided by
623 the user*/
624 for (i = 0; i < noperands; i++)
626 h8500_operand_info *user = operands + i;
628 switch (this_try->arg_type[i])
630 case FPIND_D8:
631 /* Opcode needs (disp:8,fp) */
632 if (user->type == RNIND_D8 && user->reg == 6)
634 displacement = user->exp;
635 continue;
637 break;
638 case RDIND_D16:
639 if (user->type == RNIND_D16)
641 displacement = user->exp;
642 rd = user->reg;
643 continue;
645 break;
646 case RDIND_D8:
647 if (user->type == RNIND_D8)
649 displacement = user->exp;
650 rd = user->reg;
651 continue;
653 break;
654 case RNIND_D16:
655 case RNIND_D8:
656 if (user->type == this_try->arg_type[i])
658 displacement = user->exp;
659 rn = user->reg;
660 continue;
662 break;
664 case SPDEC:
665 if (user->type == RNDEC && user->reg == 7)
667 continue;
669 break;
670 case SPINC:
671 if (user->type == RNINC && user->reg == 7)
673 continue;
675 break;
676 case ABS16:
677 if (user->type == ABS16)
679 absolute = user->exp;
680 continue;
682 break;
683 case ABS8:
684 if (user->type == ABS8)
686 absolute = user->exp;
687 continue;
689 break;
690 case ABS24:
691 if (user->type == ABS24)
693 absolute = user->exp;
694 continue;
696 break;
698 case CRB:
699 if ((user->type == CRB || user->type == CR) && user->reg != 0)
701 crb = user->reg;
702 continue;
704 break;
705 case CRW:
706 if ((user->type == CRW || user->type == CR) && user->reg == 0)
708 crw = user->reg;
709 continue;
711 break;
712 case DISP16:
713 if (user->type == DISP16)
715 displacement = user->exp;
716 continue;
718 break;
719 case DISP8:
720 if (user->type == DISP8)
722 displacement = user->exp;
723 continue;
725 break;
726 case FP:
727 if (user->type == RN && user->reg == 6)
729 continue;
731 break;
732 case PCREL16:
733 if (user->type == PCREL16)
735 displacement = user->exp;
736 continue;
738 break;
739 case PCREL8:
740 if (user->type == PCREL8)
742 displacement = user->exp;
743 pcrel8 = 1;
744 continue;
746 break;
748 case IMM16:
749 if (user->type == IMM16
750 || user->type == IMM8)
752 immediate_inpage = user->page;
753 immediate = user->exp;
754 continue;
756 break;
757 case RLIST:
758 case IMM8:
759 if (user->type == IMM8)
761 immediate_inpage = user->page;
762 immediate = user->exp;
763 continue;
765 break;
766 case IMM4:
767 if (user->type == IMM8)
769 immediate_inpage = user->page;
770 immediate = user->exp;
771 continue;
773 break;
774 case QIM:
775 if (user->type == IMM8
776 && user->exp.X_op == O_constant
778 (user->exp.X_add_number == -2
779 || user->exp.X_add_number == -1
780 || user->exp.X_add_number == 1
781 || user->exp.X_add_number == 2))
783 immediate_inpage = user->page;
784 immediate = user->exp;
785 continue;
787 break;
788 case RD:
789 if (user->type == RN)
791 rd = user->reg;
792 continue;
794 break;
795 case RS:
796 if (user->type == RN)
798 rs = user->reg;
799 continue;
801 break;
802 case RDIND:
803 if (user->type == RNIND)
805 rd = user->reg;
806 continue;
809 break;
810 case RNINC:
811 case RNIND:
812 case RNDEC:
813 case RN:
815 if (user->type == this_try->arg_type[i])
817 rn = user->reg;
818 continue;
820 break;
821 case SP:
822 if (user->type == RN && user->reg == 7)
824 continue;
826 break;
827 default:
828 printf (_("unhandled %d\n"), this_try->arg_type[i]);
829 break;
832 /* If we get here this didn't work out */
833 goto fail;
835 found = 1;
836 fail:;
840 if (found)
841 return this_try;
842 else
843 return 0;
847 check (operand, low, high)
848 expressionS *operand;
849 int low;
850 int high;
852 if (operand->X_op != O_constant
853 || operand->X_add_number < low
854 || operand->X_add_number > high)
856 as_bad (_("operand must be absolute in range %d..%d"), low, high);
858 return operand->X_add_number;
861 static void
862 insert (output, index, exp, reloc, pcrel)
863 char *output;
864 int index;
865 expressionS *exp;
866 int reloc;
867 int pcrel;
869 fix_new_exp (frag_now,
870 output - frag_now->fr_literal + index,
871 4, /* always say size is 4, but we know better */
872 exp,
873 pcrel,
874 reloc);
877 void
878 build_relaxable_instruction (opcode, operand)
879 h8500_opcode_info *opcode;
880 h8500_operand_info *operand;
882 /* All relaxable instructions start life as two bytes but can become
883 three bytes long if a lonely branch and up to 9 bytes if long
884 scb. */
885 char *p;
886 int len;
887 int type;
889 if (opcode->bytes[0].contents == 0x01)
891 type = SCB_F;
893 else if (opcode->bytes[0].contents == 0x06
894 || opcode->bytes[0].contents == 0x07)
896 type = SCB_TST;
898 else
900 type = BRANCH;
903 p = frag_var (rs_machine_dependent,
904 md_relax_table[C (type, WORD_DISP)].rlx_length,
905 len = md_relax_table[C (type, BYTE_DISP)].rlx_length,
906 C (type, UNDEF_BYTE_DISP),
907 displacement.X_add_symbol,
908 displacement.X_add_number,
911 p[0] = opcode->bytes[0].contents;
912 if (type != BRANCH)
914 p[1] = opcode->bytes[1].contents | rs;
918 /* Now we know what sort of opcodes it is, let's build the bytes. */
920 static void
921 build_bytes (opcode, operand)
922 h8500_opcode_info *opcode;
923 h8500_operand_info *operand;
926 int index;
928 if (pcrel8)
930 pcrel8 = 0;
931 build_relaxable_instruction (opcode, operand);
933 else
935 char *output = frag_more (opcode->length);
937 memset (output, 0, opcode->length);
938 for (index = 0; index < opcode->length; index++)
940 output[index] = opcode->bytes[index].contents;
942 switch (opcode->bytes[index].insert)
944 default:
945 printf (_("failed for %d\n"), opcode->bytes[index].insert);
946 break;
947 case 0:
948 break;
949 case RN:
950 output[index] |= rn;
951 break;
952 case RD:
953 case RDIND:
954 output[index] |= rd;
955 break;
956 case RS:
957 output[index] |= rs;
958 break;
959 case DISP16:
960 insert (output, index, &displacement, R_H8500_IMM16, 0);
961 index++;
962 break;
963 case DISP8:
964 case FPIND_D8:
965 insert (output, index, &displacement, R_H8500_IMM8, 0);
966 break;
967 case IMM16:
969 int p;
971 switch (immediate_inpage)
973 case 'p':
974 p = R_H8500_HIGH16;
975 break;
976 case 'h':
977 p = R_H8500_HIGH16;
978 break;
979 default:
980 p = R_H8500_IMM16;
981 break;
983 insert (output, index, &immediate, p, 0);
985 index++;
986 break;
987 case RLIST:
988 case IMM8:
989 if (immediate_inpage)
990 insert (output, index, &immediate, R_H8500_HIGH8, 0);
991 else
992 insert (output, index, &immediate, R_H8500_IMM8, 0);
993 break;
994 case PCREL16:
995 insert (output, index, &displacement, R_H8500_PCREL16, 1);
996 index++;
997 break;
998 case PCREL8:
999 insert (output, index, &displacement, R_H8500_PCREL8, 1);
1000 break;
1001 case IMM4:
1002 output[index] |= check (&immediate, 0, 15);
1003 break;
1004 case CR:
1005 output[index] |= cr;
1006 if (cr == 0)
1007 output[0] |= 0x8;
1008 else
1009 output[0] &= ~0x8;
1010 break;
1011 case CRB:
1012 output[index] |= crb;
1013 output[0] &= ~0x8;
1014 break;
1015 case CRW:
1016 output[index] |= crw;
1017 output[0] |= 0x8;
1018 break;
1019 case ABS24:
1020 insert (output, index, &absolute, R_H8500_IMM24, 0);
1021 index += 2;
1022 break;
1023 case ABS16:
1024 insert (output, index, &absolute, R_H8500_IMM16, 0);
1025 index++;
1026 break;
1027 case ABS8:
1028 insert (output, index, &absolute, R_H8500_IMM8, 0);
1029 break;
1030 case QIM:
1031 switch (immediate.X_add_number)
1033 case -2:
1034 output[index] |= 0x5;
1035 break;
1036 case -1:
1037 output[index] |= 0x4;
1038 break;
1039 case 1:
1040 output[index] |= 0;
1041 break;
1042 case 2:
1043 output[index] |= 1;
1044 break;
1046 break;
1052 /* This is the guts of the machine-dependent assembler. STR points to
1053 a machine dependent instruction. This function is supposed to emit
1054 the frags/bytes it assembles to. */
1056 void
1057 md_assemble (str)
1058 char *str;
1060 char *op_start;
1061 char *op_end;
1062 h8500_operand_info operand[2];
1063 h8500_opcode_info *opcode;
1064 h8500_opcode_info *prev_opcode;
1065 char name[11];
1067 int nlen = 0;
1069 /* Drop leading whitespace. */
1070 while (*str == ' ')
1071 str++;
1073 /* Find the op code end. */
1074 for (op_start = op_end = str;
1075 !is_end_of_line[(unsigned char) *op_end] && *op_end != ' ';
1076 op_end++)
1078 if ( /**op_end != '.'
1079 && *op_end != ':'
1080 && */ nlen < 10)
1082 name[nlen++] = *op_end;
1085 name[nlen] = 0;
1087 if (op_end == op_start)
1088 as_bad (_("can't find opcode "));
1090 opcode = (h8500_opcode_info *) hash_find (opcode_hash_control, name);
1092 if (opcode == NULL)
1094 as_bad (_("unknown opcode"));
1095 return;
1098 get_operands (opcode, op_end, operand);
1099 prev_opcode = opcode;
1101 opcode = get_specific (opcode, operand);
1103 if (opcode == 0)
1105 /* Couldn't find an opcode which matched the operands */
1106 char *where = frag_more (2);
1108 where[0] = 0x0;
1109 where[1] = 0x0;
1110 as_bad (_("invalid operands for opcode"));
1111 return;
1114 build_bytes (opcode, operand);
1117 void
1118 tc_crawl_symbol_chain (headers)
1119 object_headers *headers;
1121 printf (_("call to tc_crawl_symbol_chain \n"));
1124 symbolS *
1125 md_undefined_symbol (name)
1126 char *name;
1128 return 0;
1131 void
1132 tc_headers_hook (headers)
1133 object_headers *headers;
1135 printf (_("call to tc_headers_hook \n"));
1138 /* Various routines to kill one day. */
1139 /* Equal to MAX_PRECISION in atof-ieee.c. */
1140 #define MAX_LITTLENUMS 6
1142 /* Turn a string in input_line_pointer into a floating point constant
1143 of type type, and store the appropriate bytes in *LITP. The number
1144 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1145 returned, or NULL on OK. */
1147 char *
1148 md_atof (type, litP, sizeP)
1149 char type;
1150 char *litP;
1151 int *sizeP;
1153 int prec;
1154 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1155 LITTLENUM_TYPE *wordP;
1156 char *t;
1157 char *atof_ieee ();
1159 switch (type)
1161 case 'f':
1162 case 'F':
1163 case 's':
1164 case 'S':
1165 prec = 2;
1166 break;
1168 case 'd':
1169 case 'D':
1170 case 'r':
1171 case 'R':
1172 prec = 4;
1173 break;
1175 case 'x':
1176 case 'X':
1177 prec = 6;
1178 break;
1180 case 'p':
1181 case 'P':
1182 prec = 6;
1183 break;
1185 default:
1186 *sizeP = 0;
1187 return _("Bad call to MD_ATOF()");
1189 t = atof_ieee (input_line_pointer, type, words);
1190 if (t)
1191 input_line_pointer = t;
1193 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1194 for (wordP = words; prec--;)
1196 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1197 litP += sizeof (LITTLENUM_TYPE);
1199 return 0;
1202 CONST char *md_shortopts = "";
1203 struct option md_longopts[] = {
1204 {NULL, no_argument, NULL, 0}
1206 size_t md_longopts_size = sizeof (md_longopts);
1209 md_parse_option (c, arg)
1210 int c;
1211 char *arg;
1213 return 0;
1216 void
1217 md_show_usage (stream)
1218 FILE *stream;
1222 void
1223 tc_aout_fix_to_chars ()
1225 printf (_("call to tc_aout_fix_to_chars \n"));
1226 abort ();
1229 static void
1230 wordify_scb (buffer, disp_size, inst_size)
1231 char *buffer;
1232 int *disp_size;
1233 int *inst_size;
1235 int rn = buffer[1] & 0x7;
1237 switch (buffer[0])
1239 case 0x0e: /* BSR */
1240 case 0x20:
1241 case 0x21:
1242 case 0x22:
1243 case 0x23:
1244 case 0x24:
1245 case 0x25:
1246 case 0x26:
1247 case 0x27:
1248 case 0x28:
1249 case 0x29:
1250 case 0x2a:
1251 case 0x2b:
1252 case 0x2c:
1253 case 0x2d:
1254 case 0x2e:
1255 case 0x2f:
1256 buffer[0] |= 0x10;
1257 buffer[1] = 0;
1258 buffer[2] = 0;
1259 *disp_size = 2;
1260 *inst_size = 1;
1261 return;
1262 default:
1263 abort ();
1265 case 0x01:
1266 *inst_size = 6;
1267 *disp_size = 2;
1268 break;
1269 case 0x06:
1270 *inst_size = 8;
1271 *disp_size = 2;
1273 *buffer++ = 0x26; /* bne + 8 */
1274 *buffer++ = 0x08;
1275 break;
1276 case 0x07:
1277 *inst_size = 8;
1278 *disp_size = 2;
1279 *buffer++ = 0x27; /* bne + 8 */
1280 *buffer++ = 0x08;
1281 break;
1284 *buffer++ = 0xa8 | rn; /* addq -1,rn */
1285 *buffer++ = 0x0c;
1286 *buffer++ = 0x04; /* cmp #0xff:8, rn */
1287 *buffer++ = 0xff;
1288 *buffer++ = 0x70 | rn;
1289 *buffer++ = 0x36; /* bne ... */
1290 *buffer++ = 0;
1291 *buffer++ = 0;
1294 /* Called after relaxing, change the frags so they know how big they
1295 are. */
1297 void
1298 md_convert_frag (headers, seg, fragP)
1299 object_headers *headers;
1300 segT seg;
1301 fragS *fragP;
1303 int disp_size = 0;
1304 int inst_size = 0;
1305 char *buffer = fragP->fr_fix + fragP->fr_literal;
1307 switch (fragP->fr_subtype)
1309 case C (BRANCH, BYTE_DISP):
1310 disp_size = 1;
1311 inst_size = 1;
1312 break;
1314 case C (SCB_F, BYTE_DISP):
1315 case C (SCB_TST, BYTE_DISP):
1316 disp_size = 1;
1317 inst_size = 2;
1318 break;
1320 /* Branches to a known 16 bit displacement. */
1322 /* Turn on the 16bit bit. */
1323 case C (BRANCH, WORD_DISP):
1324 case C (SCB_F, WORD_DISP):
1325 case C (SCB_TST, WORD_DISP):
1326 wordify_scb (buffer, &disp_size, &inst_size);
1327 break;
1329 case C (BRANCH, UNDEF_WORD_DISP):
1330 case C (SCB_F, UNDEF_WORD_DISP):
1331 case C (SCB_TST, UNDEF_WORD_DISP):
1332 /* This tried to be relaxed, but didn't manage it, it now needs
1333 a fix. */
1334 wordify_scb (buffer, &disp_size, &inst_size);
1336 /* Make a reloc */
1337 fix_new (fragP,
1338 fragP->fr_fix + inst_size,
1340 fragP->fr_symbol,
1341 fragP->fr_offset,
1343 R_H8500_PCREL16);
1345 fragP->fr_fix += disp_size + inst_size;
1346 return;
1347 break;
1348 default:
1349 abort ();
1351 if (inst_size)
1353 /* Get the address of the end of the instruction */
1354 int next_inst = fragP->fr_fix + fragP->fr_address + disp_size + inst_size;
1355 int targ_addr = (S_GET_VALUE (fragP->fr_symbol) +
1356 fragP->fr_offset);
1357 int disp = targ_addr - next_inst;
1359 md_number_to_chars (buffer + inst_size, disp, disp_size);
1360 fragP->fr_fix += disp_size + inst_size;
1364 valueT
1365 md_section_align (seg, size)
1366 segT seg ;
1367 valueT size;
1369 return ((size + (1 << section_alignment[(int) seg]) - 1)
1370 & (-1 << section_alignment[(int) seg]));
1374 void
1375 md_apply_fix (fixP, val)
1376 fixS *fixP;
1377 long val;
1379 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1381 if (fixP->fx_r_type == 0)
1383 fixP->fx_r_type = fixP->fx_size == 4 ? R_H8500_IMM32 : R_H8500_IMM16;
1386 switch (fixP->fx_r_type)
1389 case R_H8500_IMM8:
1390 case R_H8500_PCREL8:
1391 *buf++ = val;
1392 break;
1393 case R_H8500_IMM16:
1394 case R_H8500_LOW16:
1395 case R_H8500_PCREL16:
1396 *buf++ = (val >> 8);
1397 *buf++ = val;
1398 break;
1399 case R_H8500_HIGH8:
1400 *buf++ = val >> 16;
1401 break;
1402 case R_H8500_HIGH16:
1403 *buf++ = val >> 24;
1404 *buf++ = val >> 16;
1405 break;
1406 case R_H8500_IMM24:
1407 *buf++ = (val >> 16);
1408 *buf++ = (val >> 8);
1409 *buf++ = val;
1410 break;
1411 case R_H8500_IMM32:
1412 *buf++ = (val >> 24);
1413 *buf++ = (val >> 16);
1414 *buf++ = (val >> 8);
1415 *buf++ = val;
1416 break;
1417 default:
1418 abort ();
1424 called just before address relaxation, return the length
1425 by which a fragment must grow to reach it's destination
1428 md_estimate_size_before_relax (fragP, segment_type)
1429 register fragS *fragP;
1430 register segT segment_type;
1432 int what;
1434 switch (fragP->fr_subtype)
1436 default:
1437 abort ();
1439 case C (BRANCH, UNDEF_BYTE_DISP):
1440 case C (SCB_F, UNDEF_BYTE_DISP):
1441 case C (SCB_TST, UNDEF_BYTE_DISP):
1442 what = GET_WHAT (fragP->fr_subtype);
1443 /* used to be a branch to somewhere which was unknown */
1444 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
1446 /* Got a symbol and it's defined in this segment, become byte
1447 sized - maybe it will fix up. */
1448 fragP->fr_subtype = C (what, BYTE_DISP);
1450 else
1452 /* Its got a segment, but its not ours, so it will always be
1453 long. */
1454 fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
1456 break;
1458 case C (BRANCH, BYTE_DISP):
1459 case C (BRANCH, WORD_DISP):
1460 case C (BRANCH, UNDEF_WORD_DISP):
1461 case C (SCB_F, BYTE_DISP):
1462 case C (SCB_F, WORD_DISP):
1463 case C (SCB_F, UNDEF_WORD_DISP):
1464 case C (SCB_TST, BYTE_DISP):
1465 case C (SCB_TST, WORD_DISP):
1466 case C (SCB_TST, UNDEF_WORD_DISP):
1467 /* When relaxing a section for the second time, we don't need to
1468 do anything besides return the current size. */
1469 break;
1472 return md_relax_table[fragP->fr_subtype].rlx_length;
1475 /* Put number into target byte order. */
1477 void
1478 md_number_to_chars (ptr, use, nbytes)
1479 char *ptr;
1480 valueT use;
1481 int nbytes;
1483 number_to_chars_bigendian (ptr, use, nbytes);
1486 long
1487 md_pcrel_from (fixP)
1488 fixS *fixP;
1490 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1493 void
1494 tc_coff_symbol_emit_hook (ignore)
1495 symbolS *ignore;
1499 short
1500 tc_coff_fix2rtype (fix_ptr)
1501 fixS *fix_ptr;
1503 if (fix_ptr->fx_r_type == RELOC_32)
1505 /* cons likes to create reloc32's whatever the size of the reloc..
1507 switch (fix_ptr->fx_size)
1509 case 2:
1510 return R_H8500_IMM16;
1511 break;
1512 case 1:
1513 return R_H8500_IMM8;
1514 break;
1515 default:
1516 abort ();
1519 return fix_ptr->fx_r_type;
1522 void
1523 tc_reloc_mangle (fix_ptr, intr, base)
1524 fixS *fix_ptr;
1525 struct internal_reloc *intr;
1526 bfd_vma base;
1529 symbolS *symbol_ptr;
1531 symbol_ptr = fix_ptr->fx_addsy;
1533 /* If this relocation is attached to a symbol then it's ok
1534 to output it */
1535 if (fix_ptr->fx_r_type == RELOC_32)
1537 /* cons likes to create reloc32's whatever the size of the reloc..
1539 switch (fix_ptr->fx_size)
1541 case 2:
1542 intr->r_type = R_IMM16;
1543 break;
1544 case 1:
1545 intr->r_type = R_IMM8;
1546 break;
1547 default:
1548 abort ();
1551 else
1553 intr->r_type = fix_ptr->fx_r_type;
1556 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1557 intr->r_offset = fix_ptr->fx_offset;
1559 /* Turn the segment of the symbol into an offset. */
1560 if (symbol_ptr)
1562 symbolS *dot;
1564 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
1565 if (dot)
1567 #if 0
1568 intr->r_offset -=
1569 segment_info[S_GET_SEGMENT (symbol_ptr)].scnhdr.s_paddr;
1570 #endif
1571 intr->r_offset += S_GET_VALUE (symbol_ptr);
1572 intr->r_symndx = dot->sy_number;
1574 else
1576 intr->r_symndx = symbol_ptr->sy_number;
1580 else
1582 intr->r_symndx = -1;
1588 start_label (ptr)
1589 char *ptr;
1591 /* Check for :s.w */
1592 if (isalpha (ptr[1]) && ptr[2] == '.')
1593 return 0;
1594 /* Check for :s */
1595 if (isalpha (ptr[1]) && !isalpha (ptr[2]))
1596 return 0;
1597 return 1;
1601 tc_coff_sizemachdep (frag)
1602 fragS *frag;
1604 return md_relax_table[frag->fr_subtype].rlx_length;