1 /* tc-d10v.c -- Assembler code for the Mitsubishi D10V
3 Copyright (C) 1996 Free Software Foundation.
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
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "opcode/d10v.h"
29 const char comment_chars
[] = "#;";
30 const char line_comment_chars
[] = "#";
31 const char line_separator_chars
[] = "";
32 const char *md_shortopts
= "O";
33 const char EXP_CHARS
[] = "eE";
34 const char FLT_CHARS
[] = "dD";
39 #define MAX_INSN_FIXUPS (5)
47 typedef struct _fixups
50 struct d10v_fixup fix
[MAX_INSN_FIXUPS
];
54 static Fixups FixUps
[2];
55 static Fixups
*fixups
;
58 static int reg_name_search
PARAMS ((char *name
));
59 static int register_name
PARAMS ((expressionS
*expressionP
));
60 static int check_range
PARAMS ((unsigned long num
, int bits
, int flags
));
61 static int postfix
PARAMS ((char *p
));
62 static bfd_reloc_code_real_type get_reloc
PARAMS ((struct d10v_operand
*op
));
63 static int get_operands
PARAMS ((expressionS exp
[]));
64 static struct d10v_opcode
*find_opcode
PARAMS ((struct d10v_opcode
*opcode
, expressionS ops
[]));
65 static unsigned long build_insn
PARAMS ((struct d10v_opcode
*opcode
, expressionS
*opers
, unsigned long insn
));
66 static void write_long
PARAMS ((struct d10v_opcode
*opcode
, unsigned long insn
, Fixups
*fx
));
67 static void write_1_short
PARAMS ((struct d10v_opcode
*opcode
, unsigned long insn
, Fixups
*fx
));
68 static int write_2_short
PARAMS ((struct d10v_opcode
*opcode1
, unsigned long insn1
,
69 struct d10v_opcode
*opcode2
, unsigned long insn2
, int exec_type
, Fixups
*fx
));
70 static unsigned long do_assemble
PARAMS ((char *str
, struct d10v_opcode
**opcode
));
71 static unsigned long d10v_insert_operand
PARAMS (( unsigned long insn
, int op_type
,
72 offsetT value
, int left
, fixS
*fix
));
73 static int parallel_ok
PARAMS ((struct d10v_opcode
*opcode1
, unsigned long insn1
,
74 struct d10v_opcode
*opcode2
, unsigned long insn2
));
77 struct option md_longopts
[] = {
78 {NULL
, no_argument
, NULL
, 0}
80 size_t md_longopts_size
= sizeof(md_longopts
);
82 /* The target specific pseudo-ops which we support. */
83 const pseudo_typeS md_pseudo_table
[] =
88 /* Opcode hash table. */
89 static struct hash_control
*d10v_hash
;
91 /* reg_name_search does a binary search of the pre_defined_registers
92 array to see if "name" is a valid regiter name. Returns the register
93 number from the array on success, or -1 on failure. */
96 reg_name_search (name
)
99 int middle
, low
, high
;
103 high
= reg_name_cnt() - 1;
107 middle
= (low
+ high
) / 2;
108 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
114 return pre_defined_registers
[middle
].value
;
120 /* register_name() checks the string at input_line_pointer
121 to see if it is a valid register name */
124 register_name (expressionP
)
125 expressionS
*expressionP
;
128 char c
, *p
= input_line_pointer
;
130 while (*p
&& *p
!='\n' && *p
!='\r' && *p
!=',' && *p
!=' ' && *p
!=')')
137 /* look to see if it's in the register table */
138 reg_number
= reg_name_search (input_line_pointer
);
141 expressionP
->X_op
= O_register
;
142 /* temporarily store a pointer to the string here */
143 expressionP
->X_op_symbol
= (struct symbol
*)input_line_pointer
;
144 expressionP
->X_add_number
= reg_number
;
145 input_line_pointer
= p
;
155 check_range (num
, bits
, flags
)
163 /* don't bother checking 16-bit values */
167 if (flags
& OPERAND_SHIFT
)
169 /* all special shift operands are unsigned */
170 /* and <= 16. We allow 0 for now. */
177 if (flags
& OPERAND_SIGNED
)
179 max
= (1 << (bits
- 1))-1;
180 min
= - (1 << (bits
- 1));
181 if (((long)num
> max
) || ((long)num
< min
))
186 max
= (1 << bits
) - 1;
188 if ((num
> max
) || (num
< min
))
196 md_show_usage (stream
)
199 fprintf(stream
, "D10V options:\n\
200 -O optimize. Will do some operations in parallel.\n");
204 md_parse_option (c
, arg
)
211 /* Optimize. Will attempt to parallelize operations */
221 md_undefined_symbol (name
)
227 /* Turn a string in input_line_pointer into a floating point constant of type
228 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
229 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
232 md_atof (type
, litP
, sizeP
)
238 LITTLENUM_TYPE words
[4];
252 return "bad call to md_atof";
255 t
= atof_ieee (input_line_pointer
, type
, words
);
257 input_line_pointer
= t
;
261 for (i
= 0; i
< prec
; i
++)
263 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
270 md_convert_frag (abfd
, sec
, fragP
)
275 printf ("call to md_convert_frag \n");
280 md_section_align (seg
, addr
)
284 int align
= bfd_get_section_alignment (stdoutput
, seg
);
285 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
292 char *prev_name
= "";
293 struct d10v_opcode
*opcode
;
294 d10v_hash
= hash_new();
296 /* Insert unique names into hash table. The D10v instruction set
297 has many identical opcode names that have different opcodes based
298 on the operands. This hash table then provides a quick index to
299 the first opcode with a particular name in the opcode table. */
301 for (opcode
= (struct d10v_opcode
*)d10v_opcodes
; opcode
->name
; opcode
++)
303 if (strcmp (prev_name
, opcode
->name
))
305 prev_name
= (char *)opcode
->name
;
306 hash_insert (d10v_hash
, opcode
->name
, (char *) opcode
);
311 FixUps
[0].next
= &FixUps
[1];
312 FixUps
[1].next
= &FixUps
[0];
316 /* this function removes the postincrement or postdecrement
317 operator ( '+' or '-' ) from an expression */
319 static int postfix (p
)
322 while (*p
!= '-' && *p
!= '+')
324 if (*p
==0 || *p
=='\n' || *p
=='\r')
344 static bfd_reloc_code_real_type
346 struct d10v_operand
*op
;
350 /* printf("get_reloc: bits=%d address=%d\n",bits,op->flags & OPERAND_ADDR); */
354 if (op
->flags
& OPERAND_ADDR
)
357 return (BFD_RELOC_D10V_10_PCREL_R
);
359 return (BFD_RELOC_D10V_18_PCREL
);
362 return (BFD_RELOC_16
);
365 /* get_operands parses a string of operands and returns
366 an array of expressions */
372 char *p
= input_line_pointer
;
378 while (*p
== ' ' || *p
== '\t' || *p
== ',')
380 if (*p
==0 || *p
=='\n' || *p
=='\r')
386 exp
[numops
].X_op
= O_absent
;
390 exp
[numops
].X_add_number
= OPERAND_ATPAR
;
395 exp
[numops
].X_add_number
= OPERAND_ATMINUS
;
399 exp
[numops
].X_add_number
= OPERAND_ATSIGN
;
408 /* just skip the trailing paren */
413 input_line_pointer
= p
;
416 /* check to see if it might be a register name */
417 if (!register_name (&exp
[numops
]))
419 /* parse as an expression */
420 expression (&exp
[numops
]);
423 if (exp
[numops
].X_op
== O_illegal
)
424 as_bad ("illegal operand");
425 else if (exp
[numops
].X_op
== O_absent
)
426 as_bad ("missing operand");
429 p
= input_line_pointer
;
434 case -1: /* postdecrement mode */
435 exp
[numops
].X_op
= O_absent
;
436 exp
[numops
++].X_add_number
= OPERAND_MINUS
;
438 case 1: /* postincrement mode */
439 exp
[numops
].X_op
= O_absent
;
440 exp
[numops
++].X_add_number
= OPERAND_PLUS
;
444 exp
[numops
].X_op
= 0;
449 d10v_insert_operand (insn
, op_type
, value
, left
, fix
)
458 shift
= d10v_operands
[op_type
].shift
;
462 bits
= d10v_operands
[op_type
].bits
;
464 /* truncate to the proper number of bits */
465 if (check_range (value
, bits
, d10v_operands
[op_type
].flags
))
466 as_bad_where (fix
->fx_file
, fix
->fx_line
, "operand out of range: %d", value
);
468 value
&= 0x7FFFFFFF >> (31 - bits
);
469 insn
|= (value
<< shift
);
475 /* build_insn takes a pointer to the opcode entry in the opcode table
476 and the array of operand expressions and returns the instruction */
479 build_insn (opcode
, opers
, insn
)
480 struct d10v_opcode
*opcode
;
484 int i
, bits
, shift
, flags
, format
;
487 /* the insn argument is only used for the DIVS kludge */
492 insn
= opcode
->opcode
;
493 format
= opcode
->format
;
496 for (i
=0;opcode
->operands
[i
];i
++)
498 flags
= d10v_operands
[opcode
->operands
[i
]].flags
;
499 bits
= d10v_operands
[opcode
->operands
[i
]].bits
;
500 shift
= d10v_operands
[opcode
->operands
[i
]].shift
;
501 number
= opers
[i
].X_add_number
;
503 if (flags
& OPERAND_REG
)
505 number
&= REGISTER_MASK
;
506 if (format
== LONG_L
)
510 if (opers
[i
].X_op
!= O_register
&& opers
[i
].X_op
!= O_constant
)
512 /* now create a fixup */
515 printf("need a fixup: ");
516 print_expr_1(stdout,&opers[i]);
520 if (fixups
->fc
>= MAX_INSN_FIXUPS
)
521 as_fatal ("too many fixups");
522 fixups
->fix
[fixups
->fc
].exp
= opers
[i
];
523 fixups
->fix
[fixups
->fc
].operand
= opcode
->operands
[i
];
524 fixups
->fix
[fixups
->fc
].pcrel
= (flags
& OPERAND_ADDR
) ? true : false;
528 /* truncate to the proper number of bits */
529 if ((opers
[i
].X_op
== O_constant
) && check_range (number
, bits
, flags
))
530 as_bad("operand out of range: %d",number
);
531 number
&= 0x7FFFFFFF >> (31 - bits
);
532 insn
= insn
| (number
<< shift
);
535 /* kludge: for DIVS, we need to put the operands in twice */
536 /* on the second pass, format is changed to LONG_R to force */
537 /* the second set of operands to not be shifted over 15 */
538 if ((opcode
->opcode
== OPCODE_DIVS
) && (format
==LONG_L
))
539 insn
= build_insn (opcode
, opers
, insn
);
544 /* write out a long form instruction */
546 write_long (opcode
, insn
, fx
)
547 struct d10v_opcode
*opcode
;
552 char *f
= frag_more(4);
555 /* printf("INSN: %08x\n",insn); */
556 number_to_chars_bigendian (f
, insn
, 4);
558 for (i
=0; i
< fx
->fc
; i
++)
560 if (get_reloc((struct d10v_operand
*)&d10v_operands
[fx
->fix
[i
].operand
]))
563 printf("fix_new_exp: where:%x size:4\n ",f - frag_now->fr_literal);
564 print_expr_1(stdout,&(fx->fix[i].exp));
568 fix_new_exp (frag_now
,
569 f
- frag_now
->fr_literal
,
573 fx
->fix
[i
].operand
|2048);
580 /* write out a short form instruction by itself */
582 write_1_short (opcode
, insn
, fx
)
583 struct d10v_opcode
*opcode
;
587 char *f
= frag_more(4);
590 if (opcode
->exec_type
& PARONLY
)
591 as_fatal ("Instruction must be executed in parallel with another instruction.");
593 /* the other container needs to be NOP */
594 /* according to 4.3.1: for FM=00, sub-instructions performed only
595 by IU cannot be encoded in L-container. */
596 if (opcode
->unit
== IU
)
597 insn
|= FM00
| (NOP
<< 15); /* right container */
599 insn
= FM00
| (insn
<< 15) | NOP
; /* left container */
601 /* printf("INSN: %08x\n",insn); */
602 number_to_chars_bigendian (f
, insn
, 4);
603 for (i
=0; i
< fx
->fc
; i
++)
605 bfd_reloc_code_real_type reloc
;
606 reloc
= get_reloc((struct d10v_operand
*)&d10v_operands
[fx
->fix
[i
].operand
]);
610 printf("fix_new_exp: where:%x size:4\n ",f - frag_now->fr_literal);
611 print_expr_1(stdout,&(fx->fix[i].exp));
615 /* if it's an R reloc, we may have to switch it to L */
616 if ( (reloc
== BFD_RELOC_D10V_10_PCREL_R
) && (opcode
->unit
!= IU
) )
617 fx
->fix
[i
].operand
|= 1024;
619 fix_new_exp (frag_now
,
620 f
- frag_now
->fr_literal
,
624 fx
->fix
[i
].operand
|2048);
630 /* write out a short form instruction if possible */
631 /* return number of instructions not written out */
633 write_2_short (opcode1
, insn1
, opcode2
, insn2
, exec_type
, fx
)
634 struct d10v_opcode
*opcode1
, *opcode2
;
635 unsigned long insn1
, insn2
;
643 if ( (exec_type
!= 1) && ((opcode1
->exec_type
& PARONLY
)
644 || (opcode2
->exec_type
& PARONLY
)))
645 as_fatal("Instruction must be executed in parallel");
647 if ( (opcode1
->format
& LONG_OPCODE
) || (opcode2
->format
& LONG_OPCODE
))
648 as_fatal ("Long instructions may not be combined.");
650 if(opcode1
->exec_type
& BRANCH_LINK
)
652 /* subroutines must be called from 32-bit boundaries */
653 /* so the return address will be correct */
654 write_1_short (opcode1
, insn1
, fx
->next
);
660 case 0: /* order not specified */
661 if ( Optimizing
&& parallel_ok (opcode1
, insn1
, opcode2
, insn2
))
664 if (opcode1
->unit
== IU
)
665 insn
= FM00
| (insn2
<< 15) | insn1
;
666 else if (opcode2
->unit
== MU
)
667 insn
= FM00
| (insn2
<< 15) | insn1
;
670 insn
= FM00
| (insn1
<< 15) | insn2
;
674 else if (opcode1
->unit
== IU
)
676 /* reverse sequential */
677 insn
= FM10
| (insn2
<< 15) | insn1
;
682 insn
= FM01
| (insn1
<< 15) | insn2
;
686 case 1: /* parallel */
687 if (opcode1
->exec_type
& SEQ
|| opcode2
->exec_type
& SEQ
)
688 as_fatal ("One of these instructions may not be executed in parallel.");
690 if (opcode1
->unit
== IU
)
692 if (opcode2
->unit
== IU
)
693 as_fatal ("Two IU instructions may not be executed in parallel");
694 as_warn ("Swapping instruction order");
695 insn
= FM00
| (insn2
<< 15) | insn1
;
697 else if (opcode2
->unit
== MU
)
699 if (opcode1
->unit
== MU
)
700 as_fatal ("Two MU instructions may not be executed in parallel");
701 as_warn ("Swapping instruction order");
702 insn
= FM00
| (insn2
<< 15) | insn1
;
706 insn
= FM00
| (insn1
<< 15) | insn2
;
710 case 2: /* sequential */
711 if (opcode1
->unit
== IU
)
712 as_fatal ("IU instruction may not be in the left container");
713 insn
= FM01
| (insn1
<< 15) | insn2
;
716 case 3: /* reverse sequential */
717 if (opcode2
->unit
== MU
)
718 as_fatal ("MU instruction may not be in the right container");
719 insn
= FM10
| (insn1
<< 15) | insn2
;
723 as_fatal("unknown execution type passed to write_2_short()");
726 /* printf("INSN: %08x\n",insn); */
728 number_to_chars_bigendian (f
, insn
, 4);
732 bfd_reloc_code_real_type reloc
;
733 for (i
=0; i
< fx
->fc
; i
++)
735 reloc
= get_reloc((struct d10v_operand
*)&d10v_operands
[fx
->fix
[i
].operand
]);
738 if ( (reloc
== BFD_RELOC_D10V_10_PCREL_R
) && (j
== 0) )
739 fx
->fix
[i
].operand
|= 1024;
742 printf("fix_new_exp: where:%x reloc:%d\n ",f - frag_now->fr_literal,fx->fix[i].operand);
743 print_expr_1(stdout,&(fx->fix[i].exp));
746 fix_new_exp (frag_now
,
747 f
- frag_now
->fr_literal
,
751 fx
->fix
[i
].operand
|2048);
761 /* Check 2 instructions and determine if they can be safely */
762 /* executed in parallel. Returns 1 if they can be. */
764 parallel_ok (op1
, insn1
, op2
, insn2
)
765 struct d10v_opcode
*op1
, *op2
;
766 unsigned long insn1
, insn2
;
768 int i
, j
, flags
, mask
, shift
, regno
;
769 unsigned long ins
, mod
[2], used
[2];
770 struct d10v_opcode
*op
;
772 if (op1
->exec_type
& SEQ
|| op2
->exec_type
& SEQ
)
775 /* The idea here is to create two sets of bitmasks (mod and used) */
776 /* which indicate which registers are modified or used by each instruction. */
777 /* The operation can only be done in parallel if instruction 1 and instruction 2 */
778 /* modify different registers, and neither instruction modifies any registers */
779 /* the other is using. Accesses to control registers, PSW, and memory are treated */
780 /* as accesses to a single register. So if both instructions write memory or one */
781 /* instruction writes memory and the other reads, then they cannot be done in parallel. */
782 /* Likewise, if one instruction mucks with the psw and the other reads the PSW */
783 /* (which includes C, F0, and F1), then they cannot operate safely in parallel. */
785 /* the bitmasks (mod and used) look like this (bit 31 = MSB) */
788 /* cr (not psw) 18 */
804 mod
[j
] = used
[j
] = 0;
805 for (i
= 0; op
->operands
[i
]; i
++)
807 flags
= d10v_operands
[op
->operands
[i
]].flags
;
808 shift
= d10v_operands
[op
->operands
[i
]].shift
;
809 mask
= 0x7FFFFFFF >> (31 - d10v_operands
[op
->operands
[i
]].bits
);
810 if (flags
& OPERAND_REG
)
812 regno
= (ins
>> shift
) & mask
;
813 if (flags
& OPERAND_ACC
)
815 else if (flags
& OPERAND_CONTROL
) /* mvtc or mvfc */
822 else if (flags
& OPERAND_FLAG
)
825 if ( flags
& OPERAND_DEST
)
827 mod
[j
] |= 1 << regno
;
828 if (flags
& OPERAND_EVEN
)
829 mod
[j
] |= 1 << (regno
+ 1);
833 used
[j
] |= 1 << regno
;
834 if (flags
& OPERAND_EVEN
)
835 used
[j
] |= 1 << (regno
+ 1);
839 if (op
->exec_type
& RMEM
)
841 else if (op
->exec_type
& WMEM
)
843 else if (op
->exec_type
& RF0
)
845 else if (op
->exec_type
& WF0
)
847 else if (op
->exec_type
& WCAR
)
850 if ((mod
[0] & mod
[1]) == 0 && (mod
[0] & used
[1]) == 0 && (mod
[1] & used
[0]) == 0)
856 /* This is the main entry point for the machine-dependent assembler. str points to a
857 machine-dependent instruction. This function is supposed to emit the frags/bytes
858 it assembles to. For the D10V, it mostly handles the special VLIW parsing and packing
859 and leaves the difficult stuff to do_assemble().
862 static unsigned long prev_insn
;
863 static struct d10v_opcode
*prev_opcode
= 0;
864 static subsegT prev_subseg
;
865 static segT prev_seg
;
871 struct d10v_opcode
*opcode
;
873 int extype
=0; /* execution type; parallel, etc */
874 static int etype
=0; /* saved extype. used for multiline instructions */
877 /* printf("md_assemble: str=%s\n",str); */
881 /* look for the special multiple instruction separators */
882 str2
= strstr (str
, "||");
887 str2
= strstr (str
, "->");
892 str2
= strstr (str
, "<-");
897 /* str2 points to the separator, if one */
902 /* if two instructions are present and we already have one saved
903 then first write it out */
905 write_1_short (prev_opcode
, prev_insn
, fixups
->next
);
907 /* assemble first instruction and save it */
908 prev_insn
= do_assemble (str
, &prev_opcode
);
910 as_fatal ("can't find opcode ");
911 fixups
= fixups
->next
;
916 insn
= do_assemble (str
, &opcode
);
924 as_fatal ("can't find opcode ");
933 /* if this is a long instruction, write it and any previous short instruction */
934 if (opcode
->format
& LONG_OPCODE
)
937 as_fatal("Unable to mix instructions as specified");
940 write_1_short (prev_opcode
, prev_insn
, fixups
->next
);
943 write_long (opcode
, insn
, fixups
);
948 if (prev_opcode
&& (write_2_short (prev_opcode
, prev_insn
, opcode
, insn
, extype
, fixups
) == 0))
950 /* no instructions saved */
956 as_fatal("Unable to mix instructions as specified");
957 /* save off last instruction so it may be packed on next pass */
958 prev_opcode
= opcode
;
961 prev_subseg
= now_subseg
;
962 fixups
= fixups
->next
;
967 /* do_assemble assembles a single instruction and returns an opcode */
968 /* it returns -1 (an invalid opcode) on error */
971 do_assemble (str
, opcode
)
973 struct d10v_opcode
**opcode
;
975 unsigned char *op_start
, *save
;
976 unsigned char *op_end
;
979 expressionS myops
[6];
982 /* printf("do_assemble: str=%s\n",str); */
984 /* Drop leading whitespace */
988 /* find the opcode end */
989 for (op_start
= op_end
= (unsigned char *) (str
);
992 && !is_end_of_line
[*op_end
] && *op_end
!= ' ';
995 name
[nlen
] = op_start
[nlen
];
1003 /* find the first opcode with the proper name */
1004 *opcode
= (struct d10v_opcode
*)hash_find (d10v_hash
, name
);
1005 if (*opcode
== NULL
)
1006 as_fatal ("unknown opcode: %s",name
);
1008 save
= input_line_pointer
;
1009 input_line_pointer
= op_end
;
1010 *opcode
= find_opcode (*opcode
, myops
);
1013 input_line_pointer
= save
;
1015 insn
= build_insn ((*opcode
), myops
, 0);
1016 /* printf("sub-insn = %lx\n",insn); */
1020 /* find_opcode() gets a pointer to an entry in the opcode table. */
1021 /* It must look at all opcodes with the same name and use the operands */
1022 /* to choose the correct opcode. */
1024 static struct d10v_opcode
*
1025 find_opcode (opcode
, myops
)
1026 struct d10v_opcode
*opcode
;
1027 expressionS myops
[];
1029 int i
, match
, done
, numops
;
1030 struct d10v_opcode
*next_opcode
;
1032 /* get all the operands and save them as expressions */
1033 numops
= get_operands (myops
);
1035 /* now see if the operand is a fake. If so, find the correct size */
1036 /* instruction, if possible */
1037 if (opcode
->format
== OPCODE_FAKE
)
1039 int opnum
= opcode
->operands
[0];
1041 if (myops
[opnum
].X_op
== O_register
)
1043 myops
[opnum
].X_op
= O_symbol
;
1044 myops
[opnum
].X_add_symbol
= symbol_find_or_make ((char *)myops
[opnum
].X_op_symbol
);
1045 myops
[opnum
].X_add_number
= 0;
1046 myops
[opnum
].X_op_symbol
= NULL
;
1049 if (myops
[opnum
].X_op
== O_constant
|| (myops
[opnum
].X_op
== O_symbol
&&
1050 S_IS_DEFINED(myops
[opnum
].X_add_symbol
) &&
1051 (S_GET_SEGMENT(myops
[opnum
].X_add_symbol
) == now_seg
)))
1053 next_opcode
=opcode
+1;
1054 for (i
=0; opcode
->operands
[i
+1]; i
++)
1056 int bits
= d10v_operands
[next_opcode
->operands
[opnum
]].bits
;
1057 int flags
= d10v_operands
[next_opcode
->operands
[opnum
]].flags
;
1058 if (flags
& OPERAND_ADDR
)
1060 if (myops
[opnum
].X_op
== O_constant
)
1062 if (!check_range (myops
[opnum
].X_add_number
, bits
, flags
))
1067 int value
= obstack_next_free(&frchain_now
->frch_obstack
) - frag_now
->fr_literal
-
1068 S_GET_VALUE(myops
[opnum
].X_add_symbol
);
1069 if (!check_range (value
, bits
, flags
))
1074 as_fatal ("value out of range");
1078 /* not a constant, so use a long instruction */
1085 /* now search the opcode table table for one with operands */
1086 /* that matches what we've got */
1090 for (i
= 0; opcode
->operands
[i
]; i
++)
1092 int flags
= d10v_operands
[opcode
->operands
[i
]].flags
;
1093 int X_op
= myops
[i
].X_op
;
1094 int num
= myops
[i
].X_add_number
;
1102 if (flags
& OPERAND_REG
)
1104 if ((X_op
!= O_register
) ||
1105 ((flags
& OPERAND_ACC
) != (num
& OPERAND_ACC
)) ||
1106 ((flags
& OPERAND_FLAG
) != (num
& OPERAND_FLAG
)) ||
1107 ((flags
& OPERAND_CONTROL
) != (num
& OPERAND_CONTROL
)))
1114 if (((flags
& OPERAND_MINUS
) && ((X_op
!= O_absent
) || (num
!= OPERAND_MINUS
))) ||
1115 ((flags
& OPERAND_PLUS
) && ((X_op
!= O_absent
) || (num
!= OPERAND_PLUS
))) ||
1116 ((flags
& OPERAND_ATMINUS
) && ((X_op
!= O_absent
) || (num
!= OPERAND_ATMINUS
))) ||
1117 ((flags
& OPERAND_ATPAR
) && ((X_op
!= O_absent
) || (num
!= OPERAND_ATPAR
))) ||
1118 ((flags
& OPERAND_ATSIGN
) && ((X_op
!= O_absent
) || (num
!= OPERAND_ATSIGN
))))
1125 /* we're only done if the operands matched so far AND there
1126 are no more to check */
1127 if (match
&& myops
[i
].X_op
==0)
1130 next_opcode
= opcode
+1;
1131 if (next_opcode
->opcode
== 0)
1133 if (strcmp(next_opcode
->name
, opcode
->name
))
1135 opcode
= next_opcode
;
1141 as_bad ("bad opcode or operands");
1145 /* Check that all registers that are required to be even are. */
1146 /* Also, if any operands were marked as registers, but were really symbols */
1147 /* fix that here. */
1148 for (i
=0; opcode
->operands
[i
]; i
++)
1150 if ((d10v_operands
[opcode
->operands
[i
]].flags
& OPERAND_EVEN
) &&
1151 (myops
[i
].X_add_number
& 1))
1152 as_fatal("Register number must be EVEN");
1153 if (myops
[i
].X_op
== O_register
)
1155 if (!(d10v_operands
[opcode
->operands
[i
]].flags
& OPERAND_REG
))
1157 myops
[i
].X_op
= O_symbol
;
1158 myops
[i
].X_add_symbol
= symbol_find_or_make ((char *)myops
[i
].X_op_symbol
);
1159 myops
[i
].X_add_number
= 0;
1160 myops
[i
].X_op_symbol
= NULL
;
1167 /* if while processing a fixup, a reloc really needs to be created */
1168 /* then it is done here */
1171 tc_gen_reloc (seg
, fixp
)
1176 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
1177 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1178 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1179 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1180 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1182 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1183 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1186 reloc
->addend
= fixp
->fx_addnumber
;
1187 /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */
1192 md_estimate_size_before_relax (fragp
, seg
)
1201 md_pcrel_from_section (fixp
, sec
)
1205 if (fixp
->fx_addsy
!= (symbolS
*)NULL
&& !S_IS_DEFINED (fixp
->fx_addsy
))
1207 /* printf("pcrel_from_section: %x\n", fixp->fx_frag->fr_address + fixp->fx_where); */
1208 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1212 md_apply_fix3 (fixp
, valuep
, seg
)
1223 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1228 else if (fixp
->fx_pcrel
)
1232 value
= fixp
->fx_offset
;
1233 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1235 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1236 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1239 /* We don't actually support subtracting a symbol. */
1240 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1241 "expression too complex");
1246 /* printf("md_apply_fix: value=0x%x type=0x%x where=0x%x size=%d line=%d\n", value, fixp->fx_r_type,fixp->fx_where,fixp->fx_size, fixp->fx_line); */
1248 op_type
= fixp
->fx_r_type
;
1255 fixp
->fx_r_type
= BFD_RELOC_D10V_10_PCREL_L
;
1259 fixp
->fx_r_type
= get_reloc((struct d10v_operand
*)&d10v_operands
[op_type
]);
1262 /* Fetch the instruction, insert the fully resolved operand
1263 value, and stuff the instruction back again. */
1264 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1265 insn
= bfd_getb32 ((unsigned char *) where
);
1267 switch (fixp
->fx_r_type
)
1269 case BFD_RELOC_D10V_10_PCREL_L
:
1270 case BFD_RELOC_D10V_10_PCREL_R
:
1271 case BFD_RELOC_D10V_18_PCREL
:
1272 /* instruction addresses are always right-shifted by 2 */
1276 bfd_putb32 ((bfd_vma
) value
, (unsigned char *) where
);
1279 if (fixp
->fx_size
== 2)
1281 bfd_putb16 ((bfd_vma
) value
, (unsigned char *) where
);
1288 /* printf(" insn=%x value=%x where=%x pcrel=%x\n",insn,value,fixp->fx_where,fixp->fx_pcrel); */
1289 insn
= d10v_insert_operand (insn
, op_type
, (offsetT
)value
, left
, fixp
);
1290 /* printf(" new insn=%x\n",insn); */
1292 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
1297 fixp
->fx_addnumber
= value
;
1302 /* d10v_cleanup() is called after the assembler has finished parsing the input
1303 file or after a label is defined. Because the D10V assembler sometimes saves short
1304 instructions to see if it can package them with the next instruction, there may
1305 be a short instruction that still needs written. */
1313 if ( prev_opcode
&& (done
|| (now_seg
== prev_seg
) && (now_subseg
== prev_subseg
)))
1316 subseg
= now_subseg
;
1317 subseg_set (prev_seg
, prev_subseg
);
1318 write_1_short (prev_opcode
, prev_insn
, fixups
->next
);
1319 subseg_set (seg
, subseg
);