Home | History | Annotate | Line # | Download | only in config
tc-v850.c revision 1.1.1.2
      1      1.1     skrll /* tc-v850.c -- Assembler code for the NEC V850
      2      1.1     skrll    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
      3  1.1.1.2  christos    2006, 2007, 2009, 2010, 2011  Free Software Foundation, Inc.
      4      1.1     skrll 
      5      1.1     skrll    This file is part of GAS, the GNU Assembler.
      6      1.1     skrll 
      7      1.1     skrll    GAS is free software; you can redistribute it and/or modify
      8      1.1     skrll    it under the terms of the GNU General Public License as published by
      9      1.1     skrll    the Free Software Foundation; either version 3, or (at your option)
     10      1.1     skrll    any later version.
     11      1.1     skrll 
     12      1.1     skrll    GAS is distributed in the hope that it will be useful,
     13      1.1     skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1     skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1     skrll    GNU General Public License for more details.
     16      1.1     skrll 
     17      1.1     skrll    You should have received a copy of the GNU General Public License
     18      1.1     skrll    along with GAS; see the file COPYING.  If not, write to
     19      1.1     skrll    the Free Software Foundation, 51 Franklin Street - Fifth Floor,
     20      1.1     skrll    Boston, MA 02110-1301, USA.  */
     21      1.1     skrll 
     22      1.1     skrll #include "as.h"
     23      1.1     skrll #include "safe-ctype.h"
     24      1.1     skrll #include "subsegs.h"
     25      1.1     skrll #include "opcode/v850.h"
     26      1.1     skrll #include "dwarf2dbg.h"
     27      1.1     skrll 
     28      1.1     skrll /* Sign-extend a 16-bit number.  */
     29      1.1     skrll #define SEXT16(x)	((((x) & 0xffff) ^ (~0x7fff)) + 0x8000)
     30      1.1     skrll 
     31      1.1     skrll /* Temporarily holds the reloc in a cons expression.  */
     32      1.1     skrll static bfd_reloc_code_real_type hold_cons_reloc = BFD_RELOC_UNUSED;
     33      1.1     skrll 
     34      1.1     skrll /* Set to TRUE if we want to be pedantic about signed overflows.  */
     35      1.1     skrll static bfd_boolean warn_signed_overflows   = FALSE;
     36      1.1     skrll static bfd_boolean warn_unsigned_overflows = FALSE;
     37      1.1     skrll 
     38      1.1     skrll /* Indicates the target BFD machine number.  */
     39      1.1     skrll static int machine = -1;
     40      1.1     skrll 
     41      1.1     skrll /* Indicates the target processor(s) for the assemble.  */
     42  1.1.1.2  christos static int processor_mask = 0;
     43      1.1     skrll 
     44      1.1     skrll /* Structure to hold information about predefined registers.  */
     46      1.1     skrll struct reg_name
     47      1.1     skrll {
     48      1.1     skrll   const char *name;
     49  1.1.1.2  christos   int value;
     50      1.1     skrll   unsigned int processors;
     51      1.1     skrll };
     52      1.1     skrll 
     53      1.1     skrll /* Generic assembler global variables which must be defined by all
     54      1.1     skrll    targets.  */
     55      1.1     skrll 
     56      1.1     skrll /* Characters which always start a comment.  */
     57      1.1     skrll const char comment_chars[] = "#";
     58      1.1     skrll 
     59      1.1     skrll /* Characters which start a comment at the beginning of a line.  */
     60      1.1     skrll const char line_comment_chars[] = ";#";
     61      1.1     skrll 
     62      1.1     skrll /* Characters which may be used to separate multiple commands on a
     63      1.1     skrll    single line.  */
     64      1.1     skrll const char line_separator_chars[] = ";";
     65      1.1     skrll 
     66      1.1     skrll /* Characters which are used to indicate an exponent in a floating
     67      1.1     skrll    point number.  */
     68      1.1     skrll const char EXP_CHARS[] = "eE";
     69      1.1     skrll 
     70      1.1     skrll /* Characters which mean that a number is a floating point constant,
     71      1.1     skrll    as in 0d1.0.  */
     72      1.1     skrll const char FLT_CHARS[] = "dD";
     73      1.1     skrll 
     74      1.1     skrll const relax_typeS md_relax_table[] =
     76  1.1.1.2  christos {
     77  1.1.1.2  christos   /* Conditional branches.(V850/V850E, max 22bit)  */
     78  1.1.1.2  christos #define SUBYPTE_COND_9_22	0
     79  1.1.1.2  christos   {0xfe,	 -0x100,        2, SUBYPTE_COND_9_22 + 1},
     80  1.1.1.2  christos   {0x1ffffe + 2, -0x200000 + 2, 6, 0},
     81  1.1.1.2  christos   /* Conditional branches.(V850/V850E, max 22bit)  */
     82  1.1.1.2  christos #define SUBYPTE_SA_9_22	2
     83  1.1.1.2  christos   {0xfe,         -0x100,      2, SUBYPTE_SA_9_22 + 1},
     84  1.1.1.2  christos   {0x1ffffe + 4, -0x200000 + 4, 8, 0},
     85  1.1.1.2  christos   /* Unconditional branches.(V850/V850E, max 22bit)  */
     86  1.1.1.2  christos #define SUBYPTE_UNCOND_9_22	4
     87  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_UNCOND_9_22 + 1},
     88  1.1.1.2  christos   {0x1ffffe, -0x200000, 4, 0},
     89  1.1.1.2  christos   /* Conditional branches.(V850E2, max 32bit)  */
     90  1.1.1.2  christos #define SUBYPTE_COND_9_22_32	6
     91  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_COND_9_22_32 + 1},
     92  1.1.1.2  christos   {0x1fffff + 2, -0x200000 + 2, 6, SUBYPTE_COND_9_22_32 + 2},
     93  1.1.1.2  christos   {0x7ffffffe, -0x80000000, 8, 0},
     94  1.1.1.2  christos   /* Conditional branches.(V850E2, max 32bit)  */
     95  1.1.1.2  christos #define SUBYPTE_SA_9_22_32	9
     96  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_SA_9_22_32 + 1},
     97  1.1.1.2  christos   {0x1ffffe + 4, -0x200000 + 4, 8, SUBYPTE_SA_9_22_32 + 2},
     98  1.1.1.2  christos   {0x7ffffffe, -0x80000000, 10, 0},
     99  1.1.1.2  christos   /* Unconditional branches.(V850E2, max 32bit)  */
    100  1.1.1.2  christos #define SUBYPTE_UNCOND_9_22_32	12
    101  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_UNCOND_9_22_32 + 1},
    102  1.1.1.2  christos   {0x1ffffe, -0x200000, 4, SUBYPTE_UNCOND_9_22_32 + 2},
    103  1.1.1.2  christos   {0x7ffffffe, -0x80000000, 6, 0},
    104  1.1.1.2  christos   /* Conditional branches.(V850E2R max 22bit)  */
    105  1.1.1.2  christos #define SUBYPTE_COND_9_17_22	15
    106  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_COND_9_17_22 + 1},
    107  1.1.1.2  christos   {0xfffe, -0x10000,	4, SUBYPTE_COND_9_17_22 + 2},
    108  1.1.1.2  christos   {0x1ffffe + 2, -0x200000 + 2, 6, 0},
    109  1.1.1.2  christos   /* Conditional branches.(V850E2R max 22bit)  */
    110  1.1.1.2  christos #define SUBYPTE_SA_9_17_22	18
    111  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_SA_9_17_22 + 1},
    112  1.1.1.2  christos   {0xfffe, -0x10000,	4, SUBYPTE_SA_9_17_22 + 2},
    113  1.1.1.2  christos   {0x1ffffe + 4, -0x200000 + 4, 8, 0},
    114  1.1.1.2  christos   /* Conditional branches.(V850E2R max 32bit)  */
    115  1.1.1.2  christos #define SUBYPTE_COND_9_17_22_32	21
    116  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_COND_9_17_22_32 + 1},
    117  1.1.1.2  christos   {0xfffe, -0x10000,	4, SUBYPTE_COND_9_17_22_32 + 2},
    118  1.1.1.2  christos   {0x1ffffe + 2, -0x200000 + 2, 6, SUBYPTE_COND_9_17_22_32 + 3},
    119  1.1.1.2  christos   {0x7ffffffe, -0x80000000, 8, 0},
    120  1.1.1.2  christos   /* Conditional branches.(V850E2R max 32bit)  */
    121  1.1.1.2  christos #define SUBYPTE_SA_9_17_22_32	25
    122  1.1.1.2  christos   {0xfe,     -0x100,    2, SUBYPTE_SA_9_17_22_32 + 1},
    123  1.1.1.2  christos   {0xfffe, -0x10000,	4, SUBYPTE_SA_9_17_22_32 + 2},
    124      1.1     skrll   {0x1ffffe + 4, -0x200000 + 4, 8, SUBYPTE_SA_9_17_22_32 + 3},
    125      1.1     skrll   {0x7ffffffe, -0x80000000, 10, 0},
    126  1.1.1.2  christos };
    127  1.1.1.2  christos 
    128  1.1.1.2  christos static int v850_relax = 0;
    129  1.1.1.2  christos 
    130  1.1.1.2  christos /* Default branch disp size 22 or 32.  */
    131  1.1.1.2  christos static int default_disp_size = 22;
    132  1.1.1.2  christos 
    133  1.1.1.2  christos /* Default no using bcond17.  */
    134  1.1.1.2  christos static int no_bcond17 = 0;
    135  1.1.1.2  christos 
    136      1.1     skrll /* Default no using ld/st 23bit offset.  */
    137      1.1     skrll static int no_stld23 = 0;
    138      1.1     skrll 
    139      1.1     skrll /* Fixups.  */
    140      1.1     skrll #define MAX_INSN_FIXUPS   5
    141      1.1     skrll 
    142      1.1     skrll struct v850_fixup
    143      1.1     skrll {
    144      1.1     skrll   expressionS exp;
    145      1.1     skrll   int opindex;
    146      1.1     skrll   bfd_reloc_code_real_type reloc;
    147      1.1     skrll };
    148      1.1     skrll 
    149      1.1     skrll struct v850_fixup fixups[MAX_INSN_FIXUPS];
    150      1.1     skrll static int fc;
    151      1.1     skrll 
    152      1.1     skrll struct v850_seg_entry
    153      1.1     skrll {
    154      1.1     skrll   segT s;
    155      1.1     skrll   const char *name;
    156      1.1     skrll   flagword flags;
    157      1.1     skrll };
    158      1.1     skrll 
    159      1.1     skrll struct v850_seg_entry v850_seg_table[] =
    160      1.1     skrll {
    161      1.1     skrll   { NULL, ".sdata",
    162      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
    163      1.1     skrll     | SEC_SMALL_DATA },
    164      1.1     skrll   { NULL, ".tdata",
    165      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
    166      1.1     skrll   { NULL, ".zdata",
    167      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
    168      1.1     skrll   { NULL, ".sbss",
    169      1.1     skrll     SEC_ALLOC | SEC_SMALL_DATA },
    170      1.1     skrll   { NULL, ".tbss",
    171      1.1     skrll     SEC_ALLOC },
    172      1.1     skrll   { NULL, ".zbss",
    173      1.1     skrll     SEC_ALLOC},
    174      1.1     skrll   { NULL, ".rosdata",
    175      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_DATA
    176      1.1     skrll     | SEC_HAS_CONTENTS | SEC_SMALL_DATA },
    177      1.1     skrll   { NULL, ".rozdata",
    178      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_DATA
    179      1.1     skrll     | SEC_HAS_CONTENTS },
    180      1.1     skrll   { NULL, ".scommon",
    181      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
    182      1.1     skrll     | SEC_SMALL_DATA | SEC_IS_COMMON },
    183      1.1     skrll   { NULL, ".tcommon",
    184      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
    185      1.1     skrll     | SEC_IS_COMMON },
    186      1.1     skrll   { NULL, ".zcommon",
    187      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
    188      1.1     skrll     | SEC_IS_COMMON },
    189      1.1     skrll   { NULL, ".call_table_data",
    190      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
    191      1.1     skrll   { NULL, ".call_table_text",
    192      1.1     skrll     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_CODE
    193      1.1     skrll     | SEC_HAS_CONTENTS},
    194      1.1     skrll   { NULL, ".bss",
    195      1.1     skrll     SEC_ALLOC }
    196      1.1     skrll };
    197      1.1     skrll 
    198      1.1     skrll #define SDATA_SECTION		0
    199      1.1     skrll #define TDATA_SECTION		1
    200      1.1     skrll #define ZDATA_SECTION		2
    201      1.1     skrll #define SBSS_SECTION		3
    202      1.1     skrll #define TBSS_SECTION		4
    203      1.1     skrll #define ZBSS_SECTION		5
    204      1.1     skrll #define ROSDATA_SECTION		6
    205      1.1     skrll #define ROZDATA_SECTION		7
    206      1.1     skrll #define SCOMMON_SECTION		8
    207      1.1     skrll #define TCOMMON_SECTION		9
    208      1.1     skrll #define ZCOMMON_SECTION		10
    209      1.1     skrll #define CALL_TABLE_DATA_SECTION	11
    210      1.1     skrll #define CALL_TABLE_TEXT_SECTION	12
    211      1.1     skrll #define BSS_SECTION		13
    212      1.1     skrll 
    213      1.1     skrll static void
    214      1.1     skrll do_v850_seg (int i, subsegT sub)
    215      1.1     skrll {
    216      1.1     skrll   struct v850_seg_entry *seg = v850_seg_table + i;
    217      1.1     skrll 
    218      1.1     skrll   obj_elf_section_change_hook ();
    219      1.1     skrll 
    220      1.1     skrll   if (seg->s != NULL)
    221      1.1     skrll     subseg_set (seg->s, sub);
    222      1.1     skrll   else
    223      1.1     skrll     {
    224      1.1     skrll       seg->s = subseg_new (seg->name, sub);
    225      1.1     skrll       bfd_set_section_flags (stdoutput, seg->s, seg->flags);
    226      1.1     skrll       if ((seg->flags & SEC_LOAD) == 0)
    227      1.1     skrll 	seg_info (seg->s)->bss = 1;
    228      1.1     skrll     }
    229      1.1     skrll }
    230      1.1     skrll 
    231      1.1     skrll static void
    232      1.1     skrll v850_seg (int i)
    233      1.1     skrll {
    234      1.1     skrll   subsegT sub = get_absolute_expression ();
    235      1.1     skrll 
    236      1.1     skrll   do_v850_seg (i, sub);
    237      1.1     skrll   demand_empty_rest_of_line ();
    238      1.1     skrll }
    239      1.1     skrll 
    240      1.1     skrll static void
    241      1.1     skrll v850_offset (int ignore ATTRIBUTE_UNUSED)
    242      1.1     skrll {
    243      1.1     skrll   char *pfrag;
    244      1.1     skrll   int temp = get_absolute_expression ();
    245      1.1     skrll 
    246      1.1     skrll   pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, (symbolS *)0,
    247      1.1     skrll 		    (offsetT) temp, (char *) 0);
    248      1.1     skrll   *pfrag = 0;
    249      1.1     skrll 
    250      1.1     skrll   demand_empty_rest_of_line ();
    251      1.1     skrll }
    252      1.1     skrll 
    253      1.1     skrll /* Copied from obj_elf_common() in gas/config/obj-elf.c.  */
    254      1.1     skrll 
    255      1.1     skrll static void
    256      1.1     skrll v850_comm (int area)
    257      1.1     skrll {
    258      1.1     skrll   char *name;
    259      1.1     skrll   char c;
    260      1.1     skrll   char *p;
    261      1.1     skrll   int temp;
    262      1.1     skrll   unsigned int size;
    263      1.1     skrll   symbolS *symbolP;
    264      1.1     skrll   int have_align;
    265      1.1     skrll 
    266      1.1     skrll   name = input_line_pointer;
    267      1.1     skrll   c = get_symbol_end ();
    268      1.1     skrll 
    269      1.1     skrll   /* Just after name is now '\0'.  */
    270      1.1     skrll   p = input_line_pointer;
    271      1.1     skrll   *p = c;
    272      1.1     skrll 
    273      1.1     skrll   SKIP_WHITESPACE ();
    274      1.1     skrll 
    275      1.1     skrll   if (*input_line_pointer != ',')
    276      1.1     skrll     {
    277      1.1     skrll       as_bad (_("Expected comma after symbol-name"));
    278      1.1     skrll       ignore_rest_of_line ();
    279      1.1     skrll       return;
    280      1.1     skrll     }
    281      1.1     skrll 
    282      1.1     skrll   /* Skip ','.  */
    283      1.1     skrll   input_line_pointer++;
    284      1.1     skrll 
    285      1.1     skrll   if ((temp = get_absolute_expression ()) < 0)
    286      1.1     skrll     {
    287      1.1     skrll       /* xgettext:c-format  */
    288      1.1     skrll       as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
    289      1.1     skrll       ignore_rest_of_line ();
    290      1.1     skrll       return;
    291      1.1     skrll     }
    292      1.1     skrll 
    293      1.1     skrll   size = temp;
    294      1.1     skrll   *p = 0;
    295      1.1     skrll   symbolP = symbol_find_or_make (name);
    296      1.1     skrll   *p = c;
    297      1.1     skrll 
    298      1.1     skrll   if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
    299      1.1     skrll     {
    300      1.1     skrll       as_bad (_("Ignoring attempt to re-define symbol"));
    301      1.1     skrll       ignore_rest_of_line ();
    302      1.1     skrll       return;
    303      1.1     skrll     }
    304      1.1     skrll 
    305      1.1     skrll   if (S_GET_VALUE (symbolP) != 0)
    306      1.1     skrll     {
    307      1.1     skrll       if (S_GET_VALUE (symbolP) != size)
    308      1.1     skrll 	/* xgettext:c-format  */
    309      1.1     skrll 	as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
    310      1.1     skrll 		 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
    311      1.1     skrll     }
    312      1.1     skrll 
    313      1.1     skrll   know (symbol_get_frag (symbolP) == &zero_address_frag);
    314      1.1     skrll 
    315      1.1     skrll   if (*input_line_pointer != ',')
    316      1.1     skrll     have_align = 0;
    317      1.1     skrll   else
    318      1.1     skrll     {
    319      1.1     skrll       have_align = 1;
    320      1.1     skrll       input_line_pointer++;
    321      1.1     skrll       SKIP_WHITESPACE ();
    322      1.1     skrll     }
    323      1.1     skrll 
    324      1.1     skrll   if (! have_align || *input_line_pointer != '"')
    325      1.1     skrll     {
    326      1.1     skrll       if (! have_align)
    327      1.1     skrll 	temp = 0;
    328      1.1     skrll       else
    329      1.1     skrll 	{
    330      1.1     skrll 	  temp = get_absolute_expression ();
    331      1.1     skrll 
    332      1.1     skrll 	  if (temp < 0)
    333      1.1     skrll 	    {
    334      1.1     skrll 	      temp = 0;
    335      1.1     skrll 	      as_warn (_("Common alignment negative; 0 assumed"));
    336      1.1     skrll 	    }
    337      1.1     skrll 	}
    338      1.1     skrll 
    339      1.1     skrll       if (symbol_get_obj (symbolP)->local)
    340      1.1     skrll 	{
    341      1.1     skrll 	  segT old_sec;
    342      1.1     skrll 	  int old_subsec;
    343      1.1     skrll 	  char *pfrag;
    344      1.1     skrll 	  int align;
    345      1.1     skrll 	  flagword applicable;
    346      1.1     skrll 
    347      1.1     skrll 	  old_sec = now_seg;
    348      1.1     skrll 	  old_subsec = now_subseg;
    349      1.1     skrll 
    350      1.1     skrll 	  applicable = bfd_applicable_section_flags (stdoutput);
    351      1.1     skrll 
    352      1.1     skrll 	  applicable &= SEC_ALLOC;
    353      1.1     skrll 
    354      1.1     skrll 	  switch (area)
    355      1.1     skrll 	    {
    356      1.1     skrll 	    case SCOMMON_SECTION:
    357      1.1     skrll 	      do_v850_seg (SBSS_SECTION, 0);
    358      1.1     skrll 	      break;
    359      1.1     skrll 
    360      1.1     skrll 	    case ZCOMMON_SECTION:
    361      1.1     skrll 	      do_v850_seg (ZBSS_SECTION, 0);
    362      1.1     skrll 	      break;
    363      1.1     skrll 
    364      1.1     skrll 	    case TCOMMON_SECTION:
    365      1.1     skrll 	      do_v850_seg (TBSS_SECTION, 0);
    366      1.1     skrll 	      break;
    367      1.1     skrll 	    }
    368      1.1     skrll 
    369      1.1     skrll 	  if (temp)
    370      1.1     skrll 	    {
    371      1.1     skrll 	      /* Convert to a power of 2 alignment.  */
    372      1.1     skrll 	      for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
    373      1.1     skrll 		;
    374      1.1     skrll 
    375      1.1     skrll 	      if (temp != 1)
    376      1.1     skrll 		{
    377      1.1     skrll 		  as_bad (_("Common alignment not a power of 2"));
    378      1.1     skrll 		  ignore_rest_of_line ();
    379      1.1     skrll 		  return;
    380      1.1     skrll 		}
    381      1.1     skrll 	    }
    382      1.1     skrll 	  else
    383      1.1     skrll 	    align = 0;
    384      1.1     skrll 
    385      1.1     skrll 	  record_alignment (now_seg, align);
    386      1.1     skrll 
    387      1.1     skrll 	  if (align)
    388      1.1     skrll 	    frag_align (align, 0, 0);
    389      1.1     skrll 
    390      1.1     skrll 	  switch (area)
    391      1.1     skrll 	    {
    392      1.1     skrll 	    case SCOMMON_SECTION:
    393      1.1     skrll 	      if (S_GET_SEGMENT (symbolP) == v850_seg_table[SBSS_SECTION].s)
    394      1.1     skrll 		symbol_get_frag (symbolP)->fr_symbol = 0;
    395      1.1     skrll 	      break;
    396      1.1     skrll 
    397      1.1     skrll 	    case ZCOMMON_SECTION:
    398      1.1     skrll 	      if (S_GET_SEGMENT (symbolP) == v850_seg_table[ZBSS_SECTION].s)
    399      1.1     skrll 		symbol_get_frag (symbolP)->fr_symbol = 0;
    400      1.1     skrll 	      break;
    401      1.1     skrll 
    402      1.1     skrll 	    case TCOMMON_SECTION:
    403      1.1     skrll 	      if (S_GET_SEGMENT (symbolP) == v850_seg_table[TBSS_SECTION].s)
    404      1.1     skrll 		symbol_get_frag (symbolP)->fr_symbol = 0;
    405      1.1     skrll 	      break;
    406      1.1     skrll 
    407      1.1     skrll 	    default:
    408      1.1     skrll 	      abort ();
    409      1.1     skrll 	    }
    410      1.1     skrll 
    411      1.1     skrll 	  symbol_set_frag (symbolP, frag_now);
    412      1.1     skrll 	  pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
    413      1.1     skrll 			    (offsetT) size, (char *) 0);
    414      1.1     skrll 	  *pfrag = 0;
    415      1.1     skrll 	  S_SET_SIZE (symbolP, size);
    416      1.1     skrll 
    417      1.1     skrll 	  switch (area)
    418      1.1     skrll 	    {
    419      1.1     skrll 	    case SCOMMON_SECTION:
    420      1.1     skrll 	      S_SET_SEGMENT (symbolP, v850_seg_table[SBSS_SECTION].s);
    421      1.1     skrll 	      break;
    422      1.1     skrll 
    423      1.1     skrll 	    case ZCOMMON_SECTION:
    424      1.1     skrll 	      S_SET_SEGMENT (symbolP, v850_seg_table[ZBSS_SECTION].s);
    425      1.1     skrll 	      break;
    426      1.1     skrll 
    427      1.1     skrll 	    case TCOMMON_SECTION:
    428      1.1     skrll 	      S_SET_SEGMENT (symbolP, v850_seg_table[TBSS_SECTION].s);
    429      1.1     skrll 	      break;
    430      1.1     skrll 
    431      1.1     skrll 	    default:
    432      1.1     skrll 	      abort ();
    433      1.1     skrll 	    }
    434      1.1     skrll 
    435      1.1     skrll 	  S_CLEAR_EXTERNAL (symbolP);
    436      1.1     skrll 	  obj_elf_section_change_hook ();
    437      1.1     skrll 	  subseg_set (old_sec, old_subsec);
    438      1.1     skrll 	}
    439      1.1     skrll       else
    440      1.1     skrll 	{
    441      1.1     skrll 	  segT   old_sec;
    442      1.1     skrll 	  int    old_subsec;
    443      1.1     skrll 
    444      1.1     skrll 	allocate_common:
    445      1.1     skrll 	  old_sec = now_seg;
    446      1.1     skrll 	  old_subsec = now_subseg;
    447      1.1     skrll 
    448      1.1     skrll 	  S_SET_VALUE (symbolP, (valueT) size);
    449      1.1     skrll 	  S_SET_ALIGN (symbolP, temp);
    450      1.1     skrll 	  S_SET_EXTERNAL (symbolP);
    451      1.1     skrll 
    452      1.1     skrll 	  switch (area)
    453      1.1     skrll 	    {
    454      1.1     skrll 	    case SCOMMON_SECTION:
    455      1.1     skrll 	    case ZCOMMON_SECTION:
    456      1.1     skrll 	    case TCOMMON_SECTION:
    457      1.1     skrll 	      do_v850_seg (area, 0);
    458      1.1     skrll 	      S_SET_SEGMENT (symbolP, v850_seg_table[area].s);
    459      1.1     skrll 	      break;
    460      1.1     skrll 
    461      1.1     skrll 	    default:
    462      1.1     skrll 	      abort ();
    463      1.1     skrll 	    }
    464      1.1     skrll 
    465      1.1     skrll 	  obj_elf_section_change_hook ();
    466      1.1     skrll 	  subseg_set (old_sec, old_subsec);
    467      1.1     skrll 	}
    468      1.1     skrll     }
    469      1.1     skrll   else
    470      1.1     skrll     {
    471      1.1     skrll       input_line_pointer++;
    472      1.1     skrll 
    473      1.1     skrll       /* @@ Some use the dot, some don't.  Can we get some consistency??  */
    474      1.1     skrll       if (*input_line_pointer == '.')
    475      1.1     skrll 	input_line_pointer++;
    476      1.1     skrll 
    477      1.1     skrll       /* @@ Some say data, some say bss.  */
    478      1.1     skrll       if (strncmp (input_line_pointer, "bss\"", 4)
    479      1.1     skrll 	  && strncmp (input_line_pointer, "data\"", 5))
    480      1.1     skrll 	{
    481      1.1     skrll 	  while (*--input_line_pointer != '"')
    482      1.1     skrll 	    ;
    483      1.1     skrll 	  input_line_pointer--;
    484      1.1     skrll 	  goto bad_common_segment;
    485      1.1     skrll 	}
    486      1.1     skrll 
    487      1.1     skrll       while (*input_line_pointer++ != '"')
    488      1.1     skrll 	;
    489      1.1     skrll 
    490      1.1     skrll       goto allocate_common;
    491      1.1     skrll     }
    492      1.1     skrll 
    493      1.1     skrll   symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
    494      1.1     skrll 
    495      1.1     skrll   demand_empty_rest_of_line ();
    496      1.1     skrll   return;
    497      1.1     skrll 
    498      1.1     skrll   {
    499      1.1     skrll   bad_common_segment:
    500      1.1     skrll     p = input_line_pointer;
    501      1.1     skrll     while (*p && *p != '\n')
    502      1.1     skrll       p++;
    503      1.1     skrll     c = *p;
    504      1.1     skrll     *p = '\0';
    505      1.1     skrll     as_bad (_("bad .common segment %s"), input_line_pointer + 1);
    506      1.1     skrll     *p = c;
    507      1.1     skrll     input_line_pointer = p;
    508      1.1     skrll     ignore_rest_of_line ();
    509      1.1     skrll     return;
    510      1.1     skrll   }
    511      1.1     skrll }
    512      1.1     skrll 
    513      1.1     skrll static void
    514      1.1     skrll set_machine (int number)
    515      1.1     skrll {
    516      1.1     skrll   machine = number;
    517      1.1     skrll   bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
    518      1.1     skrll 
    519  1.1.1.2  christos   switch (machine)
    520  1.1.1.2  christos     {
    521  1.1.1.2  christos     case 0:                SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850);    break;
    522  1.1.1.2  christos     case bfd_mach_v850:    SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850);    break;
    523  1.1.1.2  christos     case bfd_mach_v850e:   SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);   break;
    524  1.1.1.2  christos     case bfd_mach_v850e1:  SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);   break;
    525      1.1     skrll     case bfd_mach_v850e2:  SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2);  break;
    526      1.1     skrll     case bfd_mach_v850e2v3:SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2V3); break;
    527      1.1     skrll     }
    528      1.1     skrll }
    529      1.1     skrll 
    530      1.1     skrll static void
    531      1.1     skrll v850_longcode (int type)
    532      1.1     skrll {
    533      1.1     skrll   expressionS ex;
    534      1.1     skrll 
    535      1.1     skrll   if (! v850_relax)
    536  1.1.1.2  christos     {
    537      1.1     skrll       if (type == 1)
    538  1.1.1.2  christos 	as_warn (_(".longcall pseudo-op seen when not relaxing"));
    539      1.1     skrll       else
    540      1.1     skrll 	as_warn (_(".longjump pseudo-op seen when not relaxing"));
    541      1.1     skrll     }
    542      1.1     skrll 
    543      1.1     skrll   expression (&ex);
    544      1.1     skrll 
    545  1.1.1.2  christos   if (ex.X_op != O_symbol || ex.X_add_number != 0)
    546      1.1     skrll     {
    547      1.1     skrll       as_bad (_("bad .longcall format"));
    548      1.1     skrll       ignore_rest_of_line ();
    549      1.1     skrll 
    550      1.1     skrll       return;
    551      1.1     skrll     }
    552      1.1     skrll 
    553      1.1     skrll   if (type == 1)
    554      1.1     skrll     fix_new_exp (frag_now, frag_now_fix (), 4, & ex, 1,
    555      1.1     skrll 		 BFD_RELOC_V850_LONGCALL);
    556      1.1     skrll   else
    557      1.1     skrll     fix_new_exp (frag_now, frag_now_fix (), 4, & ex, 1,
    558      1.1     skrll 		 BFD_RELOC_V850_LONGJUMP);
    559      1.1     skrll 
    560      1.1     skrll   demand_empty_rest_of_line ();
    561      1.1     skrll }
    562      1.1     skrll 
    563      1.1     skrll /* The target specific pseudo-ops which we support.  */
    564      1.1     skrll const pseudo_typeS md_pseudo_table[] =
    565      1.1     skrll {
    566      1.1     skrll   { "sdata",		v850_seg,		SDATA_SECTION		},
    567      1.1     skrll   { "tdata",		v850_seg,		TDATA_SECTION		},
    568      1.1     skrll   { "zdata",		v850_seg,		ZDATA_SECTION		},
    569      1.1     skrll   { "sbss",		v850_seg,		SBSS_SECTION		},
    570      1.1     skrll   { "tbss",		v850_seg,		TBSS_SECTION		},
    571      1.1     skrll   { "zbss",		v850_seg,		ZBSS_SECTION		},
    572      1.1     skrll   { "rosdata",		v850_seg,		ROSDATA_SECTION 	},
    573      1.1     skrll   { "rozdata",		v850_seg,		ROZDATA_SECTION 	},
    574      1.1     skrll   { "bss",		v850_seg,		BSS_SECTION		},
    575      1.1     skrll   { "offset",		v850_offset,		0			},
    576      1.1     skrll   { "word",		cons,			4			},
    577      1.1     skrll   { "zcomm",		v850_comm,		ZCOMMON_SECTION 	},
    578      1.1     skrll   { "scomm",		v850_comm,		SCOMMON_SECTION 	},
    579      1.1     skrll   { "tcomm",		v850_comm,		TCOMMON_SECTION 	},
    580      1.1     skrll   { "v850",		set_machine,		0			},
    581      1.1     skrll   { "call_table_data",	v850_seg,		CALL_TABLE_DATA_SECTION	},
    582  1.1.1.2  christos   { "call_table_text",	v850_seg,		CALL_TABLE_TEXT_SECTION	},
    583  1.1.1.2  christos   { "v850e",		set_machine,		bfd_mach_v850e		},
    584  1.1.1.2  christos   { "v850e1",		set_machine,		bfd_mach_v850e1         },
    585      1.1     skrll   { "v850e2",		set_machine,		bfd_mach_v850e2 	},
    586      1.1     skrll   { "v850e2v3",		set_machine,		bfd_mach_v850e2v3 	},
    587      1.1     skrll   { "longcall",		v850_longcode,		1			},
    588      1.1     skrll   { "longjump",		v850_longcode,		2			},
    589      1.1     skrll   { NULL,		NULL,			0			}
    590      1.1     skrll };
    591      1.1     skrll 
    592      1.1     skrll /* Opcode hash table.  */
    593      1.1     skrll static struct hash_control *v850_hash;
    594      1.1     skrll 
    595      1.1     skrll /* This table is sorted.  Suitable for searching by a binary search.  */
    596  1.1.1.2  christos static const struct reg_name pre_defined_registers[] =
    597  1.1.1.2  christos {
    598  1.1.1.2  christos   { "ep",  30, PROCESSOR_ALL },		/* ep - element ptr.  */
    599  1.1.1.2  christos   { "gp",   4, PROCESSOR_ALL },		/* gp - global ptr.  */
    600  1.1.1.2  christos   { "hp",   2, PROCESSOR_ALL },		/* hp - handler stack ptr.  */
    601  1.1.1.2  christos   { "lp",  31, PROCESSOR_ALL },		/* lp - link ptr.  */
    602  1.1.1.2  christos   { "r0",   0, PROCESSOR_ALL },
    603  1.1.1.2  christos   { "r1",   1, PROCESSOR_ALL },
    604  1.1.1.2  christos   { "r10", 10, PROCESSOR_ALL },
    605  1.1.1.2  christos   { "r11", 11, PROCESSOR_ALL },
    606  1.1.1.2  christos   { "r12", 12, PROCESSOR_ALL },
    607  1.1.1.2  christos   { "r13", 13, PROCESSOR_ALL },
    608  1.1.1.2  christos   { "r14", 14, PROCESSOR_ALL },
    609  1.1.1.2  christos   { "r15", 15, PROCESSOR_ALL },
    610  1.1.1.2  christos   { "r16", 16, PROCESSOR_ALL },
    611  1.1.1.2  christos   { "r17", 17, PROCESSOR_ALL },
    612  1.1.1.2  christos   { "r18", 18, PROCESSOR_ALL },
    613  1.1.1.2  christos   { "r19", 19, PROCESSOR_ALL },
    614  1.1.1.2  christos   { "r2",   2, PROCESSOR_ALL },
    615  1.1.1.2  christos   { "r20", 20, PROCESSOR_ALL },
    616  1.1.1.2  christos   { "r21", 21, PROCESSOR_ALL },
    617  1.1.1.2  christos   { "r22", 22, PROCESSOR_ALL },
    618  1.1.1.2  christos   { "r23", 23, PROCESSOR_ALL },
    619  1.1.1.2  christos   { "r24", 24, PROCESSOR_ALL },
    620  1.1.1.2  christos   { "r25", 25, PROCESSOR_ALL },
    621  1.1.1.2  christos   { "r26", 26, PROCESSOR_ALL },
    622  1.1.1.2  christos   { "r27", 27, PROCESSOR_ALL },
    623  1.1.1.2  christos   { "r28", 28, PROCESSOR_ALL },
    624  1.1.1.2  christos   { "r29", 29, PROCESSOR_ALL },
    625  1.1.1.2  christos   { "r3",   3, PROCESSOR_ALL },
    626  1.1.1.2  christos   { "r30", 30, PROCESSOR_ALL },
    627  1.1.1.2  christos   { "r31", 31, PROCESSOR_ALL },
    628  1.1.1.2  christos   { "r4",   4, PROCESSOR_ALL },
    629  1.1.1.2  christos   { "r5",   5, PROCESSOR_ALL },
    630  1.1.1.2  christos   { "r6",   6, PROCESSOR_ALL },
    631  1.1.1.2  christos   { "r7",   7, PROCESSOR_ALL },
    632  1.1.1.2  christos   { "r8",   8, PROCESSOR_ALL },
    633  1.1.1.2  christos   { "r9",   9, PROCESSOR_ALL },
    634  1.1.1.2  christos   { "sp",   3, PROCESSOR_ALL },		/* sp - stack ptr.  */
    635      1.1     skrll   { "tp",   5, PROCESSOR_ALL },		/* tp - text ptr.  */
    636      1.1     skrll   { "zero", 0, PROCESSOR_ALL },
    637      1.1     skrll };
    638      1.1     skrll 
    639      1.1     skrll #define REG_NAME_CNT						\
    640      1.1     skrll   (sizeof (pre_defined_registers) / sizeof (struct reg_name))
    641      1.1     skrll 
    642  1.1.1.2  christos static const struct reg_name system_registers[] =
    643  1.1.1.2  christos {
    644  1.1.1.2  christos   { "asid",        23, PROCESSOR_NOT_V850 },
    645  1.1.1.2  christos   { "bpam",        25, PROCESSOR_NOT_V850 },
    646  1.1.1.2  christos   { "bpav",        24, PROCESSOR_NOT_V850 },
    647  1.1.1.2  christos   { "bpc",         22, PROCESSOR_NOT_V850 },
    648  1.1.1.2  christos   { "bpdm",        27, PROCESSOR_NOT_V850 },
    649  1.1.1.2  christos   { "bpdv",        26, PROCESSOR_NOT_V850 },
    650  1.1.1.2  christos   { "bsel",        31, PROCESSOR_V850E2_ALL },
    651  1.1.1.2  christos   { "cfg",          7, PROCESSOR_V850E2V3 },
    652  1.1.1.2  christos   { "ctbp",        20, PROCESSOR_NOT_V850 },
    653  1.1.1.2  christos   { "ctpc",        16, PROCESSOR_NOT_V850 },
    654  1.1.1.2  christos   { "ctpsw",       17, PROCESSOR_NOT_V850 },
    655  1.1.1.2  christos   { "dbic",        15, PROCESSOR_V850E2_ALL },
    656  1.1.1.2  christos   { "dbpc",        18, PROCESSOR_NOT_V850 },
    657  1.1.1.2  christos   { "dbpsw",       19, PROCESSOR_NOT_V850 },
    658  1.1.1.2  christos   { "dbwr",        30, PROCESSOR_V850E2_ALL },
    659  1.1.1.2  christos   { "dir",         21, PROCESSOR_NOT_V850 },
    660  1.1.1.2  christos   { "dpa0l",       16, PROCESSOR_V850E2V3 },
    661  1.1.1.2  christos   { "dpa0u",       17, PROCESSOR_V850E2V3 },
    662  1.1.1.2  christos   { "dpa1l",       18, PROCESSOR_V850E2V3 },
    663  1.1.1.2  christos   { "dpa1u",       19, PROCESSOR_V850E2V3 },
    664  1.1.1.2  christos   { "dpa2l",       20, PROCESSOR_V850E2V3 },
    665  1.1.1.2  christos   { "dpa2u",       21, PROCESSOR_V850E2V3 },
    666  1.1.1.2  christos   { "dpa3l",       22, PROCESSOR_V850E2V3 },
    667  1.1.1.2  christos   { "dpa3u",       23, PROCESSOR_V850E2V3 },
    668  1.1.1.2  christos   { "dpa4l",       24, PROCESSOR_V850E2V3 },
    669  1.1.1.2  christos   { "dpa4u",       25, PROCESSOR_V850E2V3 },
    670  1.1.1.2  christos   { "dpa5l",       26, PROCESSOR_V850E2V3 },
    671  1.1.1.2  christos   { "dpa5u",       27, PROCESSOR_V850E2V3 },
    672  1.1.1.2  christos   { "ecr",          4, PROCESSOR_ALL },
    673  1.1.1.2  christos   { "eh_base",      3, PROCESSOR_V850E2V3 },
    674  1.1.1.2  christos   { "eh_cfg",       1, PROCESSOR_V850E2V3 },
    675  1.1.1.2  christos   { "eh_reset",     2, PROCESSOR_V850E2V3 },
    676  1.1.1.2  christos   { "eiic",        13, PROCESSOR_V850E2_ALL },
    677  1.1.1.2  christos   { "eipc",         0, PROCESSOR_ALL },
    678  1.1.1.2  christos   { "eipsw",        1, PROCESSOR_ALL },
    679  1.1.1.2  christos   { "eiwr",        28, PROCESSOR_V850E2_ALL },
    680  1.1.1.2  christos   { "feic",        14, PROCESSOR_V850E2_ALL },
    681  1.1.1.2  christos   { "fepc",         2, PROCESSOR_ALL },
    682  1.1.1.2  christos   { "fepsw",        3, PROCESSOR_ALL },
    683  1.1.1.2  christos   { "fewr",        29, PROCESSOR_V850E2_ALL },
    684  1.1.1.2  christos   { "fpcc",         9, PROCESSOR_V850E2V3 },
    685  1.1.1.2  christos   { "fpcfg",       10, PROCESSOR_V850E2V3 },
    686  1.1.1.2  christos   { "fpec",        11, PROCESSOR_V850E2V3 },
    687  1.1.1.2  christos   { "fpepc",        7, PROCESSOR_V850E2V3 },
    688  1.1.1.2  christos   { "fpspc",       27, PROCESSOR_V850E2V3 },
    689  1.1.1.2  christos   { "fpsr",         6, PROCESSOR_V850E2V3 },
    690  1.1.1.2  christos   { "fpst",         8, PROCESSOR_V850E2V3 },
    691  1.1.1.2  christos   { "ipa0l",        6, PROCESSOR_V850E2V3 },
    692  1.1.1.2  christos   { "ipa0u",        7, PROCESSOR_V850E2V3 },
    693  1.1.1.2  christos   { "ipa1l",        8, PROCESSOR_V850E2V3 },
    694  1.1.1.2  christos   { "ipa1u",        9, PROCESSOR_V850E2V3 },
    695  1.1.1.2  christos   { "ipa2l",       10, PROCESSOR_V850E2V3 },
    696  1.1.1.2  christos   { "ipa2u",       11, PROCESSOR_V850E2V3 },
    697  1.1.1.2  christos   { "ipa3l",       12, PROCESSOR_V850E2V3 },
    698  1.1.1.2  christos   { "ipa3u",       13, PROCESSOR_V850E2V3 },
    699  1.1.1.2  christos   { "ipa4l",       14, PROCESSOR_V850E2V3 },
    700  1.1.1.2  christos   { "ipa4u",       15, PROCESSOR_V850E2V3 },
    701  1.1.1.2  christos   { "mca",         24, PROCESSOR_V850E2V3 },
    702  1.1.1.2  christos   { "mcc",         26, PROCESSOR_V850E2V3 },
    703  1.1.1.2  christos   { "mcr",         27, PROCESSOR_V850E2V3 },
    704  1.1.1.2  christos   { "mcs",         25, PROCESSOR_V850E2V3 },
    705  1.1.1.2  christos   { "mpc",          1, PROCESSOR_V850E2V3 },
    706  1.1.1.2  christos   { "mpm",          0, PROCESSOR_V850E2V3 },
    707  1.1.1.2  christos   { "mpu10_dpa0l", 16, PROCESSOR_V850E2V3 },
    708  1.1.1.2  christos   { "mpu10_dpa0u", 17, PROCESSOR_V850E2V3 },
    709  1.1.1.2  christos   { "mpu10_dpa1l", 18, PROCESSOR_V850E2V3 },
    710  1.1.1.2  christos   { "mpu10_dpa1u", 19, PROCESSOR_V850E2V3 },
    711  1.1.1.2  christos   { "mpu10_dpa2l", 20, PROCESSOR_V850E2V3 },
    712  1.1.1.2  christos   { "mpu10_dpa2u", 21, PROCESSOR_V850E2V3 },
    713  1.1.1.2  christos   { "mpu10_dpa3l", 22, PROCESSOR_V850E2V3 },
    714  1.1.1.2  christos   { "mpu10_dpa3u", 23, PROCESSOR_V850E2V3 },
    715  1.1.1.2  christos   { "mpu10_dpa4l", 24, PROCESSOR_V850E2V3 },
    716  1.1.1.2  christos   { "mpu10_dpa4u", 25, PROCESSOR_V850E2V3 },
    717  1.1.1.2  christos   { "mpu10_dpa5l", 26, PROCESSOR_V850E2V3 },
    718  1.1.1.2  christos   { "mpu10_dpa5u", 27, PROCESSOR_V850E2V3 },
    719  1.1.1.2  christos   { "mpu10_ipa0l",  6, PROCESSOR_V850E2V3 },
    720  1.1.1.2  christos   { "mpu10_ipa0u",  7, PROCESSOR_V850E2V3 },
    721  1.1.1.2  christos   { "mpu10_ipa1l",  8, PROCESSOR_V850E2V3 },
    722  1.1.1.2  christos   { "mpu10_ipa1u",  9, PROCESSOR_V850E2V3 },
    723  1.1.1.2  christos   { "mpu10_ipa2l", 10, PROCESSOR_V850E2V3 },
    724  1.1.1.2  christos   { "mpu10_ipa2u", 11, PROCESSOR_V850E2V3 },
    725  1.1.1.2  christos   { "mpu10_ipa3l", 12, PROCESSOR_V850E2V3 },
    726  1.1.1.2  christos   { "mpu10_ipa3u", 13, PROCESSOR_V850E2V3 },
    727  1.1.1.2  christos   { "mpu10_ipa4l", 14, PROCESSOR_V850E2V3 },
    728  1.1.1.2  christos   { "mpu10_ipa4u", 15, PROCESSOR_V850E2V3 },
    729  1.1.1.2  christos   { "mpu10_mpc",    1, PROCESSOR_V850E2V3 },
    730  1.1.1.2  christos   { "mpu10_mpm",    0, PROCESSOR_V850E2V3 },
    731  1.1.1.2  christos   { "mpu10_tid",    2, PROCESSOR_V850E2V3 },
    732  1.1.1.2  christos   { "mpu10_vmadr",  5, PROCESSOR_V850E2V3 },
    733  1.1.1.2  christos   { "mpu10_vmecr",  3, PROCESSOR_V850E2V3 },
    734  1.1.1.2  christos   { "mpu10_vmtid",  4, PROCESSOR_V850E2V3 },
    735  1.1.1.2  christos   { "pid",          6, PROCESSOR_V850E2V3 },
    736  1.1.1.2  christos   { "pmcr0",        4, PROCESSOR_V850E2V3 },
    737  1.1.1.2  christos   { "pmis2",       14, PROCESSOR_V850E2V3 },
    738  1.1.1.2  christos   { "psw",          5, PROCESSOR_ALL },
    739  1.1.1.2  christos   { "scbp",        12, PROCESSOR_V850E2V3 },
    740  1.1.1.2  christos   { "sccfg",       11, PROCESSOR_V850E2V3 },
    741  1.1.1.2  christos   { "sr0",          0, PROCESSOR_ALL },
    742  1.1.1.2  christos   { "sr1",          1, PROCESSOR_ALL },
    743  1.1.1.2  christos   { "sr10",        10, PROCESSOR_ALL },
    744  1.1.1.2  christos   { "sr11",        11, PROCESSOR_ALL },
    745  1.1.1.2  christos   { "sr12",        12, PROCESSOR_ALL },
    746  1.1.1.2  christos   { "sr13",        13, PROCESSOR_ALL },
    747  1.1.1.2  christos   { "sr14",        14, PROCESSOR_ALL },
    748  1.1.1.2  christos   { "sr15",        15, PROCESSOR_ALL },
    749  1.1.1.2  christos   { "sr16",        16, PROCESSOR_ALL },
    750  1.1.1.2  christos   { "sr17",        17, PROCESSOR_ALL },
    751  1.1.1.2  christos   { "sr18",        18, PROCESSOR_ALL },
    752  1.1.1.2  christos   { "sr19",        19, PROCESSOR_ALL },
    753  1.1.1.2  christos   { "sr2",          2, PROCESSOR_ALL },
    754  1.1.1.2  christos   { "sr20",        20, PROCESSOR_ALL },
    755  1.1.1.2  christos   { "sr21",        21, PROCESSOR_ALL },
    756  1.1.1.2  christos   { "sr22",        22, PROCESSOR_ALL },
    757  1.1.1.2  christos   { "sr23",        23, PROCESSOR_ALL },
    758  1.1.1.2  christos   { "sr24",        24, PROCESSOR_ALL },
    759  1.1.1.2  christos   { "sr25",        25, PROCESSOR_ALL },
    760  1.1.1.2  christos   { "sr26",        26, PROCESSOR_ALL },
    761  1.1.1.2  christos   { "sr27",        27, PROCESSOR_ALL },
    762  1.1.1.2  christos   { "sr28",        28, PROCESSOR_ALL },
    763  1.1.1.2  christos   { "sr29",        29, PROCESSOR_ALL },
    764  1.1.1.2  christos   { "sr3",          3, PROCESSOR_ALL },
    765  1.1.1.2  christos   { "sr30",        30, PROCESSOR_ALL },
    766  1.1.1.2  christos   { "sr31",        31, PROCESSOR_ALL },
    767  1.1.1.2  christos   { "sr4",          4, PROCESSOR_ALL },
    768  1.1.1.2  christos   { "sr5",          5, PROCESSOR_ALL },
    769  1.1.1.2  christos   { "sr6",          6, PROCESSOR_ALL },
    770  1.1.1.2  christos   { "sr7",          7, PROCESSOR_ALL },
    771  1.1.1.2  christos   { "sr8",          8, PROCESSOR_ALL },
    772  1.1.1.2  christos   { "sr9",          9, PROCESSOR_ALL },
    773  1.1.1.2  christos   { "sw_base",      3, PROCESSOR_V850E2V3 },
    774  1.1.1.2  christos   { "sw_cfg",       1, PROCESSOR_V850E2V3 },
    775  1.1.1.2  christos   { "sw_ctl",       0, PROCESSOR_V850E2V3 },
    776  1.1.1.2  christos   { "tid",          2, PROCESSOR_V850E2V3 },
    777  1.1.1.2  christos   { "vmadr",        6, PROCESSOR_V850E2V3 },
    778  1.1.1.2  christos   { "vmecr",        4, PROCESSOR_V850E2V3 },
    779  1.1.1.2  christos   { "vmtid",        5, PROCESSOR_V850E2V3 },
    780  1.1.1.2  christos   { "vsadr",        2, PROCESSOR_V850E2V3 },
    781      1.1     skrll   { "vsecr",        0, PROCESSOR_V850E2V3 },
    782      1.1     skrll   { "vstid",        1, PROCESSOR_V850E2V3 },
    783      1.1     skrll };
    784      1.1     skrll 
    785      1.1     skrll #define SYSREG_NAME_CNT						\
    786      1.1     skrll   (sizeof (system_registers) / sizeof (struct reg_name))
    787      1.1     skrll 
    788      1.1     skrll 
    789  1.1.1.2  christos static const struct reg_name cc_names[] =
    790  1.1.1.2  christos {
    791  1.1.1.2  christos   { "c",  0x1, PROCESSOR_ALL },
    792  1.1.1.2  christos   { "e",  0x2, PROCESSOR_ALL },
    793  1.1.1.2  christos   { "ge", 0xe, PROCESSOR_ALL },
    794  1.1.1.2  christos   { "gt", 0xf, PROCESSOR_ALL },
    795  1.1.1.2  christos   { "h",  0xb, PROCESSOR_ALL },
    796  1.1.1.2  christos   { "l",  0x1, PROCESSOR_ALL },
    797  1.1.1.2  christos   { "le", 0x7, PROCESSOR_ALL },
    798  1.1.1.2  christos   { "lt", 0x6, PROCESSOR_ALL },
    799  1.1.1.2  christos   { "n",  0x4, PROCESSOR_ALL },
    800  1.1.1.2  christos   { "nc", 0x9, PROCESSOR_ALL },
    801  1.1.1.2  christos   { "ne", 0xa, PROCESSOR_ALL },
    802  1.1.1.2  christos   { "nh", 0x3, PROCESSOR_ALL },
    803  1.1.1.2  christos   { "nl", 0x9, PROCESSOR_ALL },
    804  1.1.1.2  christos   { "ns", 0xc, PROCESSOR_ALL },
    805  1.1.1.2  christos   { "nv", 0x8, PROCESSOR_ALL },
    806  1.1.1.2  christos   { "nz", 0xa, PROCESSOR_ALL },
    807  1.1.1.2  christos   { "p",  0xc, PROCESSOR_ALL },
    808  1.1.1.2  christos   { "s",  0x4, PROCESSOR_ALL },
    809  1.1.1.2  christos #define COND_SA_NUM 0xd
    810  1.1.1.2  christos   { "sa", COND_SA_NUM, PROCESSOR_ALL },
    811  1.1.1.2  christos   { "t",  0x5, PROCESSOR_ALL },
    812      1.1     skrll   { "v",  0x0, PROCESSOR_ALL },
    813      1.1     skrll   { "z",  0x2, PROCESSOR_ALL },
    814      1.1     skrll };
    815      1.1     skrll 
    816      1.1     skrll #define CC_NAME_CNT					\
    817  1.1.1.2  christos   (sizeof (cc_names) / sizeof (struct reg_name))
    818  1.1.1.2  christos 
    819  1.1.1.2  christos static const struct reg_name float_cc_names[] =
    820  1.1.1.2  christos {
    821  1.1.1.2  christos   { "eq",  0x2, PROCESSOR_V850E2V3 },	/* true.  */
    822  1.1.1.2  christos   { "f",   0x0, PROCESSOR_V850E2V3 },	/* true.  */
    823  1.1.1.2  christos   { "ge",  0xd, PROCESSOR_V850E2V3 },	/* false.  */
    824  1.1.1.2  christos   { "gl",  0xb, PROCESSOR_V850E2V3 },	/* false.  */
    825  1.1.1.2  christos   { "gle", 0x9, PROCESSOR_V850E2V3 },	/* false.  */
    826  1.1.1.2  christos   { "gt",  0xf, PROCESSOR_V850E2V3 },	/* false.  */
    827  1.1.1.2  christos   { "le",  0xe, PROCESSOR_V850E2V3 },	/* true.  */
    828  1.1.1.2  christos   { "lt",  0xc, PROCESSOR_V850E2V3 },	/* true.  */
    829  1.1.1.2  christos   { "neq", 0x2, PROCESSOR_V850E2V3 },	/* false.  */
    830  1.1.1.2  christos   { "nge", 0xd, PROCESSOR_V850E2V3 },	/* true.  */
    831  1.1.1.2  christos   { "ngl", 0xb, PROCESSOR_V850E2V3 },	/* true.  */
    832  1.1.1.2  christos   { "ngle",0x9, PROCESSOR_V850E2V3 },	/* true.  */
    833  1.1.1.2  christos   { "ngt", 0xf, PROCESSOR_V850E2V3 },	/* true.  */
    834  1.1.1.2  christos   { "nle", 0xe, PROCESSOR_V850E2V3 },	/* false.  */
    835  1.1.1.2  christos   { "nlt", 0xc, PROCESSOR_V850E2V3 },	/* false.  */
    836  1.1.1.2  christos   { "oge", 0x5, PROCESSOR_V850E2V3 },	/* false.  */
    837  1.1.1.2  christos   { "ogl", 0x3, PROCESSOR_V850E2V3 },	/* false.  */
    838  1.1.1.2  christos   { "ogt", 0x7, PROCESSOR_V850E2V3 },	/* false.  */
    839  1.1.1.2  christos   { "ole", 0x6, PROCESSOR_V850E2V3 },	/* true.  */
    840  1.1.1.2  christos   { "olt", 0x4, PROCESSOR_V850E2V3 },	/* true.  */
    841  1.1.1.2  christos   { "or",  0x1, PROCESSOR_V850E2V3 },	/* false.  */
    842  1.1.1.2  christos   { "seq", 0xa, PROCESSOR_V850E2V3 },	/* true.  */
    843  1.1.1.2  christos   { "sf",  0x8, PROCESSOR_V850E2V3 },	/* true.  */
    844  1.1.1.2  christos   { "sne", 0xa, PROCESSOR_V850E2V3 },	/* false.  */
    845  1.1.1.2  christos   { "st",  0x8, PROCESSOR_V850E2V3 },	/* false.  */
    846  1.1.1.2  christos   { "t",   0x0, PROCESSOR_V850E2V3 },	/* false.  */
    847  1.1.1.2  christos   { "ueq", 0x3, PROCESSOR_V850E2V3 },	/* true.  */
    848  1.1.1.2  christos   { "uge", 0x4, PROCESSOR_V850E2V3 },	/* false.  */
    849  1.1.1.2  christos   { "ugt", 0x6, PROCESSOR_V850E2V3 },	/* false.  */
    850  1.1.1.2  christos   { "ule", 0x7, PROCESSOR_V850E2V3 },	/* true.  */
    851  1.1.1.2  christos   { "ult", 0x5, PROCESSOR_V850E2V3 },	/* true.  */
    852  1.1.1.2  christos   { "un",  0x1, PROCESSOR_V850E2V3 },	/* true.  */
    853  1.1.1.2  christos };
    854  1.1.1.2  christos 
    855  1.1.1.2  christos #define FLOAT_CC_NAME_CNT					\
    856      1.1     skrll   (sizeof (float_cc_names) / sizeof (struct reg_name))
    857      1.1     skrll 
    858      1.1     skrll /* Do a binary search of the given register table to see if NAME is a
    859      1.1     skrll    valid regiter name.  Return the register number from the array on
    860      1.1     skrll    success, or -1 on failure.  */
    861      1.1     skrll 
    862      1.1     skrll static int
    863      1.1     skrll reg_name_search (const struct reg_name *regs,
    864      1.1     skrll 		 int regcount,
    865      1.1     skrll 		 const char *name,
    866      1.1     skrll 		 bfd_boolean accept_numbers)
    867      1.1     skrll {
    868      1.1     skrll   int middle, low, high;
    869      1.1     skrll   int cmp;
    870      1.1     skrll   symbolS *symbolP;
    871      1.1     skrll 
    872      1.1     skrll   /* If the register name is a symbol, then evaluate it.  */
    873      1.1     skrll   if ((symbolP = symbol_find (name)) != NULL)
    874      1.1     skrll     {
    875      1.1     skrll       /* If the symbol is an alias for another name then use that.
    876      1.1     skrll 	 If the symbol is an alias for a number, then return the number.  */
    877      1.1     skrll       if (symbol_equated_p (symbolP))
    878      1.1     skrll 	name
    879      1.1     skrll 	  = S_GET_NAME (symbol_get_value_expression (symbolP)->X_add_symbol);
    880      1.1     skrll       else if (accept_numbers)
    881  1.1.1.2  christos 	{
    882      1.1     skrll 	  int reg = S_GET_VALUE (symbolP);
    883      1.1     skrll 	  return reg;
    884      1.1     skrll 	}
    885      1.1     skrll 
    886      1.1     skrll       /* Otherwise drop through and try parsing name normally.  */
    887      1.1     skrll     }
    888      1.1     skrll 
    889      1.1     skrll   low = 0;
    890      1.1     skrll   high = regcount - 1;
    891      1.1     skrll 
    892      1.1     skrll   do
    893      1.1     skrll     {
    894      1.1     skrll       middle = (low + high) / 2;
    895      1.1     skrll       cmp = strcasecmp (name, regs[middle].name);
    896      1.1     skrll       if (cmp < 0)
    897      1.1     skrll 	high = middle - 1;
    898      1.1     skrll       else if (cmp > 0)
    899  1.1.1.2  christos 	low = middle + 1;
    900  1.1.1.2  christos       else
    901  1.1.1.2  christos 	return ((regs[middle].processors & processor_mask)
    902      1.1     skrll 		? regs[middle].value
    903      1.1     skrll 		: -1);
    904      1.1     skrll     }
    905      1.1     skrll   while (low <= high);
    906      1.1     skrll   return -1;
    907      1.1     skrll }
    908      1.1     skrll 
    909      1.1     skrll /* Summary of register_name().
    910      1.1     skrll 
    911      1.1     skrll    in: Input_line_pointer points to 1st char of operand.
    912      1.1     skrll 
    913      1.1     skrll    out: An expressionS.
    914      1.1     skrll   	The operand may have been a register: in this case, X_op == O_register,
    915      1.1     skrll   	X_add_number is set to the register number, and truth is returned.
    916      1.1     skrll   	Input_line_pointer->(next non-blank) char after operand, or is in
    917      1.1     skrll   	its original state.  */
    918      1.1     skrll 
    919      1.1     skrll static bfd_boolean
    920      1.1     skrll register_name (expressionS *expressionP)
    921      1.1     skrll {
    922      1.1     skrll   int reg_number;
    923      1.1     skrll   char *name;
    924      1.1     skrll   char *start;
    925      1.1     skrll   char c;
    926      1.1     skrll 
    927      1.1     skrll   /* Find the spelling of the operand.  */
    928      1.1     skrll   start = name = input_line_pointer;
    929      1.1     skrll 
    930      1.1     skrll   c = get_symbol_end ();
    931      1.1     skrll 
    932      1.1     skrll   reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT,
    933      1.1     skrll 				name, FALSE);
    934      1.1     skrll 
    935      1.1     skrll   /* Put back the delimiting char.  */
    936  1.1.1.2  christos   *input_line_pointer = c;
    937  1.1.1.2  christos 
    938  1.1.1.2  christos   expressionP->X_add_symbol = NULL;
    939      1.1     skrll   expressionP->X_op_symbol  = NULL;
    940      1.1     skrll 
    941      1.1     skrll   /* Look to see if it's in the register table.  */
    942      1.1     skrll   if (reg_number >= 0)
    943      1.1     skrll     {
    944      1.1     skrll       expressionP->X_op		= O_register;
    945      1.1     skrll       expressionP->X_add_number = reg_number;
    946      1.1     skrll 
    947      1.1     skrll       return TRUE;
    948  1.1.1.2  christos     }
    949  1.1.1.2  christos 
    950  1.1.1.2  christos   /* Reset the line as if we had not done anything.  */
    951  1.1.1.2  christos   input_line_pointer = start;
    952  1.1.1.2  christos 
    953  1.1.1.2  christos   expressionP->X_op = O_illegal;
    954      1.1     skrll 
    955      1.1     skrll   return FALSE;
    956      1.1     skrll }
    957      1.1     skrll 
    958      1.1     skrll /* Summary of system_register_name().
    959      1.1     skrll 
    960      1.1     skrll    in:  INPUT_LINE_POINTER points to 1st char of operand.
    961      1.1     skrll 	EXPRESSIONP points to an expression structure to be filled in.
    962      1.1     skrll 	ACCEPT_NUMBERS is true iff numerical register names may be used.
    963      1.1     skrll 
    964      1.1     skrll    out: An expressionS structure in expressionP.
    965      1.1     skrll   	The operand may have been a register: in this case, X_op == O_register,
    966      1.1     skrll   	X_add_number is set to the register number, and truth is returned.
    967      1.1     skrll   	Input_line_pointer->(next non-blank) char after operand, or is in
    968      1.1     skrll   	its original state.  */
    969      1.1     skrll 
    970  1.1.1.2  christos static bfd_boolean
    971      1.1     skrll system_register_name (expressionS *expressionP,
    972      1.1     skrll 		      bfd_boolean accept_numbers)
    973      1.1     skrll {
    974      1.1     skrll   int reg_number;
    975      1.1     skrll   char *name;
    976      1.1     skrll   char *start;
    977      1.1     skrll   char c;
    978      1.1     skrll 
    979      1.1     skrll   /* Find the spelling of the operand.  */
    980      1.1     skrll   start = name = input_line_pointer;
    981      1.1     skrll 
    982      1.1     skrll   c = get_symbol_end ();
    983      1.1     skrll   reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
    984      1.1     skrll 				accept_numbers);
    985      1.1     skrll 
    986      1.1     skrll   /* Put back the delimiting char.  */
    987      1.1     skrll   *input_line_pointer = c;
    988      1.1     skrll 
    989      1.1     skrll   if (reg_number < 0
    990      1.1     skrll       && accept_numbers)
    991      1.1     skrll     {
    992      1.1     skrll       /* Reset input_line pointer.  */
    993      1.1     skrll       input_line_pointer = start;
    994      1.1     skrll 
    995  1.1.1.2  christos       if (ISDIGIT (*input_line_pointer))
    996      1.1     skrll 	{
    997      1.1     skrll 	  reg_number = strtol (input_line_pointer, &input_line_pointer, 0);
    998      1.1     skrll 	}
    999  1.1.1.2  christos     }
   1000  1.1.1.2  christos 
   1001  1.1.1.2  christos   expressionP->X_add_symbol = NULL;
   1002      1.1     skrll   expressionP->X_op_symbol  = NULL;
   1003      1.1     skrll 
   1004      1.1     skrll   /* Look to see if it's in the register table.  */
   1005      1.1     skrll   if (reg_number >= 0)
   1006      1.1     skrll     {
   1007      1.1     skrll       expressionP->X_op		= O_register;
   1008      1.1     skrll       expressionP->X_add_number = reg_number;
   1009      1.1     skrll 
   1010      1.1     skrll       return TRUE;
   1011  1.1.1.2  christos     }
   1012  1.1.1.2  christos 
   1013  1.1.1.2  christos   /* Reset the line as if we had not done anything.  */
   1014  1.1.1.2  christos   input_line_pointer = start;
   1015  1.1.1.2  christos 
   1016  1.1.1.2  christos   expressionP->X_op = O_illegal;
   1017      1.1     skrll 
   1018      1.1     skrll   return FALSE;
   1019      1.1     skrll }
   1020      1.1     skrll 
   1021      1.1     skrll /* Summary of cc_name().
   1022      1.1     skrll 
   1023      1.1     skrll    in: INPUT_LINE_POINTER points to 1st char of operand.
   1024      1.1     skrll 
   1025      1.1     skrll    out: An expressionS.
   1026      1.1     skrll   	The operand may have been a register: in this case, X_op == O_register,
   1027      1.1     skrll   	X_add_number is set to the register number, and truth is returned.
   1028      1.1     skrll   	Input_line_pointer->(next non-blank) char after operand, or is in
   1029      1.1     skrll   	its original state.  */
   1030  1.1.1.2  christos 
   1031  1.1.1.2  christos static bfd_boolean
   1032      1.1     skrll cc_name (expressionS *expressionP,
   1033      1.1     skrll 	 bfd_boolean accept_numbers)
   1034      1.1     skrll {
   1035      1.1     skrll   int reg_number;
   1036      1.1     skrll   char *name;
   1037      1.1     skrll   char *start;
   1038      1.1     skrll   char c;
   1039      1.1     skrll 
   1040      1.1     skrll   /* Find the spelling of the operand.  */
   1041      1.1     skrll   start = name = input_line_pointer;
   1042  1.1.1.2  christos 
   1043      1.1     skrll   c = get_symbol_end ();
   1044      1.1     skrll   reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, accept_numbers);
   1045      1.1     skrll 
   1046      1.1     skrll   /* Put back the delimiting char.  */
   1047  1.1.1.2  christos   *input_line_pointer = c;
   1048  1.1.1.2  christos 
   1049  1.1.1.2  christos   if (reg_number < 0
   1050  1.1.1.2  christos       && accept_numbers)
   1051  1.1.1.2  christos     {
   1052  1.1.1.2  christos       /* Reset input_line pointer.  */
   1053  1.1.1.2  christos       input_line_pointer = start;
   1054  1.1.1.2  christos 
   1055  1.1.1.2  christos       if (ISDIGIT (*input_line_pointer))
   1056  1.1.1.2  christos 	{
   1057  1.1.1.2  christos 	  reg_number = strtol (input_line_pointer, &input_line_pointer, 0);
   1058  1.1.1.2  christos 	}
   1059  1.1.1.2  christos     }
   1060  1.1.1.2  christos 
   1061  1.1.1.2  christos   expressionP->X_add_symbol = NULL;
   1062      1.1     skrll   expressionP->X_op_symbol  = NULL;
   1063      1.1     skrll 
   1064      1.1     skrll   /* Look to see if it's in the register table.  */
   1065      1.1     skrll   if (reg_number >= 0)
   1066      1.1     skrll     {
   1067      1.1     skrll       expressionP->X_op		= O_constant;
   1068      1.1     skrll       expressionP->X_add_number = reg_number;
   1069      1.1     skrll 
   1070  1.1.1.2  christos       return TRUE;
   1071  1.1.1.2  christos     }
   1072  1.1.1.2  christos 
   1073  1.1.1.2  christos   /* Reset the line as if we had not done anything.  */
   1074  1.1.1.2  christos   input_line_pointer = start;
   1075  1.1.1.2  christos 
   1076  1.1.1.2  christos   expressionP->X_op = O_illegal;
   1077  1.1.1.2  christos   expressionP->X_add_number = 0;
   1078  1.1.1.2  christos 
   1079  1.1.1.2  christos   return FALSE;
   1080  1.1.1.2  christos }
   1081  1.1.1.2  christos 
   1082  1.1.1.2  christos static bfd_boolean
   1083  1.1.1.2  christos float_cc_name (expressionS *expressionP,
   1084  1.1.1.2  christos 	       bfd_boolean accept_numbers)
   1085  1.1.1.2  christos {
   1086  1.1.1.2  christos   int reg_number;
   1087  1.1.1.2  christos   char *name;
   1088  1.1.1.2  christos   char *start;
   1089  1.1.1.2  christos   char c;
   1090  1.1.1.2  christos 
   1091  1.1.1.2  christos   /* Find the spelling of the operand.  */
   1092  1.1.1.2  christos   start = name = input_line_pointer;
   1093  1.1.1.2  christos 
   1094  1.1.1.2  christos   c = get_symbol_end ();
   1095  1.1.1.2  christos   reg_number = reg_name_search (float_cc_names, FLOAT_CC_NAME_CNT, name, accept_numbers);
   1096  1.1.1.2  christos 
   1097  1.1.1.2  christos   /* Put back the delimiting char.  */
   1098  1.1.1.2  christos   *input_line_pointer = c;
   1099  1.1.1.2  christos 
   1100      1.1     skrll   if (reg_number < 0
   1101  1.1.1.2  christos       && accept_numbers)
   1102      1.1     skrll     {
   1103      1.1     skrll       /* Reset input_line pointer.  */
   1104  1.1.1.2  christos       input_line_pointer = start;
   1105  1.1.1.2  christos 
   1106  1.1.1.2  christos       if (ISDIGIT (*input_line_pointer))
   1107  1.1.1.2  christos 	{
   1108  1.1.1.2  christos 	  reg_number = strtol (input_line_pointer, &input_line_pointer, 0);
   1109  1.1.1.2  christos 	}
   1110  1.1.1.2  christos     }
   1111  1.1.1.2  christos 
   1112  1.1.1.2  christos   expressionP->X_add_symbol = NULL;
   1113  1.1.1.2  christos   expressionP->X_op_symbol  = NULL;
   1114  1.1.1.2  christos 
   1115  1.1.1.2  christos   /* Look to see if it's in the register table.  */
   1116  1.1.1.2  christos   if (reg_number >= 0)
   1117  1.1.1.2  christos     {
   1118  1.1.1.2  christos       expressionP->X_op		= O_constant;
   1119  1.1.1.2  christos       expressionP->X_add_number = reg_number;
   1120      1.1     skrll 
   1121  1.1.1.2  christos       return TRUE;
   1122  1.1.1.2  christos     }
   1123  1.1.1.2  christos 
   1124  1.1.1.2  christos   /* Reset the line as if we had not done anything.  */
   1125  1.1.1.2  christos   input_line_pointer = start;
   1126  1.1.1.2  christos 
   1127  1.1.1.2  christos   expressionP->X_op = O_illegal;
   1128  1.1.1.2  christos   expressionP->X_add_number = 0;
   1129      1.1     skrll 
   1130      1.1     skrll   return FALSE;
   1131      1.1     skrll }
   1132      1.1     skrll 
   1133      1.1     skrll static void
   1134      1.1     skrll skip_white_space (void)
   1135      1.1     skrll {
   1136      1.1     skrll   while (*input_line_pointer == ' '
   1137      1.1     skrll 	 || *input_line_pointer == '\t')
   1138      1.1     skrll     ++input_line_pointer;
   1139      1.1     skrll }
   1140      1.1     skrll 
   1141      1.1     skrll /* Summary of parse_register_list ().
   1142      1.1     skrll 
   1143      1.1     skrll    in: INPUT_LINE_POINTER  points to 1st char of a list of registers.
   1144      1.1     skrll        INSN		   is the partially constructed instruction.
   1145      1.1     skrll        OPERAND		   is the operand being inserted.
   1146      1.1     skrll 
   1147      1.1     skrll    out: NULL if the parse completed successfully, otherwise a
   1148      1.1     skrll 	pointer to an error message is returned.  If the parse
   1149      1.1     skrll 	completes the correct bit fields in the instruction
   1150      1.1     skrll 	will be filled in.
   1151      1.1     skrll 
   1152      1.1     skrll    Parses register lists with the syntax:
   1153      1.1     skrll 
   1154      1.1     skrll      { rX }
   1155      1.1     skrll      { rX, rY }
   1156      1.1     skrll      { rX - rY }
   1157      1.1     skrll      { rX - rY, rZ }
   1158      1.1     skrll      etc
   1159      1.1     skrll 
   1160      1.1     skrll    and also parses constant expressions whoes bits indicate the
   1161      1.1     skrll    registers in the lists.  The LSB in the expression refers to
   1162      1.1     skrll    the lowest numbered permissible register in the register list,
   1163      1.1     skrll    and so on upwards.  System registers are considered to be very
   1164      1.1     skrll    high numbers.  */
   1165      1.1     skrll 
   1166      1.1     skrll static char *
   1167      1.1     skrll parse_register_list (unsigned long *insn,
   1168      1.1     skrll 		     const struct v850_operand *operand)
   1169      1.1     skrll {
   1170      1.1     skrll   static int type1_regs[32] =
   1171      1.1     skrll   {
   1172      1.1     skrll     30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
   1173  1.1.1.2  christos      0,  0,  0,  0,  0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
   1174      1.1     skrll   };
   1175      1.1     skrll 
   1176      1.1     skrll   int *regs;
   1177      1.1     skrll   expressionS exp;
   1178      1.1     skrll 
   1179      1.1     skrll   /* Select a register array to parse.  */
   1180      1.1     skrll   switch (operand->shift)
   1181      1.1     skrll     {
   1182      1.1     skrll     case 0xffe00001: regs = type1_regs; break;
   1183      1.1     skrll     default:
   1184      1.1     skrll       as_bad (_("unknown operand shift: %x\n"), operand->shift);
   1185      1.1     skrll       return _("internal failure in parse_register_list");
   1186      1.1     skrll     }
   1187      1.1     skrll 
   1188      1.1     skrll   skip_white_space ();
   1189      1.1     skrll 
   1190      1.1     skrll   /* If the expression starts with a curly brace it is a register list.
   1191      1.1     skrll      Otherwise it is a constant expression, whoes bits indicate which
   1192      1.1     skrll      registers are to be included in the list.  */
   1193      1.1     skrll   if (*input_line_pointer != '{')
   1194      1.1     skrll     {
   1195      1.1     skrll       int reg;
   1196      1.1     skrll       int i;
   1197      1.1     skrll 
   1198      1.1     skrll       expression (&exp);
   1199      1.1     skrll 
   1200      1.1     skrll       if (exp.X_op != O_constant)
   1201      1.1     skrll 	return _("constant expression or register list expected");
   1202      1.1     skrll 
   1203      1.1     skrll       if (regs == type1_regs)
   1204      1.1     skrll 	{
   1205      1.1     skrll 	  if (exp.X_add_number & 0xFFFFF000)
   1206      1.1     skrll 	    return _("high bits set in register list expression");
   1207      1.1     skrll 
   1208      1.1     skrll 	  for (reg = 20; reg < 32; reg++)
   1209      1.1     skrll 	    if (exp.X_add_number & (1 << (reg - 20)))
   1210      1.1     skrll 	      {
   1211      1.1     skrll 		for (i = 0; i < 32; i++)
   1212      1.1     skrll 		  if (regs[i] == reg)
   1213      1.1     skrll 		    *insn |= (1 << i);
   1214      1.1     skrll 	      }
   1215      1.1     skrll 	}
   1216      1.1     skrll 
   1217      1.1     skrll       return NULL;
   1218      1.1     skrll     }
   1219      1.1     skrll 
   1220      1.1     skrll   input_line_pointer++;
   1221      1.1     skrll 
   1222      1.1     skrll   /* Parse the register list until a terminator (closing curly brace or
   1223      1.1     skrll      new-line) is found.  */
   1224  1.1.1.2  christos   for (;;)
   1225  1.1.1.2  christos     {
   1226      1.1     skrll       skip_white_space ();
   1227      1.1     skrll 
   1228      1.1     skrll       if (register_name (&exp))
   1229      1.1     skrll 	{
   1230      1.1     skrll 	  int i;
   1231      1.1     skrll 
   1232      1.1     skrll 	  /* Locate the given register in the list, and if it is there,
   1233      1.1     skrll 	     insert the corresponding bit into the instruction.  */
   1234      1.1     skrll 	  for (i = 0; i < 32; i++)
   1235      1.1     skrll 	    {
   1236      1.1     skrll 	      if (regs[i] == exp.X_add_number)
   1237      1.1     skrll 		{
   1238      1.1     skrll 		  *insn |= (1 << i);
   1239      1.1     skrll 		  break;
   1240      1.1     skrll 		}
   1241      1.1     skrll 	    }
   1242      1.1     skrll 
   1243      1.1     skrll 	  if (i == 32)
   1244  1.1.1.2  christos 	    return _("illegal register included in list");
   1245      1.1     skrll 	}
   1246      1.1     skrll       else if (system_register_name (&exp, TRUE))
   1247      1.1     skrll 	{
   1248      1.1     skrll 	  if (regs == type1_regs)
   1249      1.1     skrll 	    {
   1250      1.1     skrll 	      return _("system registers cannot be included in list");
   1251  1.1.1.2  christos 	    }
   1252  1.1.1.2  christos 	}
   1253      1.1     skrll 
   1254      1.1     skrll       if (*input_line_pointer == '}')
   1255      1.1     skrll 	{
   1256      1.1     skrll 	  input_line_pointer++;
   1257      1.1     skrll 	  break;
   1258      1.1     skrll 	}
   1259      1.1     skrll       else if (*input_line_pointer == ',')
   1260      1.1     skrll 	{
   1261      1.1     skrll 	  input_line_pointer++;
   1262      1.1     skrll 	  continue;
   1263      1.1     skrll 	}
   1264      1.1     skrll       else if (*input_line_pointer == '-')
   1265      1.1     skrll 	{
   1266      1.1     skrll 	  /* We have encountered a range of registers: rX - rY.  */
   1267      1.1     skrll 	  int j;
   1268      1.1     skrll 	  expressionS exp2;
   1269      1.1     skrll 
   1270      1.1     skrll 	  /* Skip the dash.  */
   1271      1.1     skrll 	  ++input_line_pointer;
   1272      1.1     skrll 
   1273      1.1     skrll 	  /* Get the second register in the range.  */
   1274      1.1     skrll 	  if (! register_name (&exp2))
   1275  1.1.1.2  christos 	    {
   1276  1.1.1.2  christos 	      return _("second register should follow dash in register list");
   1277  1.1.1.2  christos 	    }
   1278  1.1.1.2  christos 
   1279  1.1.1.2  christos 	  if (exp.X_add_number > exp2.X_add_number)
   1280      1.1     skrll 	    {
   1281      1.1     skrll 	      return _("second register should be greater than first register");
   1282      1.1     skrll 	    }
   1283      1.1     skrll 
   1284      1.1     skrll 	  /* Add the rest of the registers in the range.  */
   1285      1.1     skrll 	  for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
   1286      1.1     skrll 	    {
   1287      1.1     skrll 	      int i;
   1288      1.1     skrll 
   1289      1.1     skrll 	      /* Locate the given register in the list, and if it is there,
   1290      1.1     skrll 		 insert the corresponding bit into the instruction.  */
   1291      1.1     skrll 	      for (i = 0; i < 32; i++)
   1292      1.1     skrll 		{
   1293      1.1     skrll 		  if (regs[i] == j)
   1294      1.1     skrll 		    {
   1295      1.1     skrll 		      *insn |= (1 << i);
   1296      1.1     skrll 		      break;
   1297      1.1     skrll 		    }
   1298      1.1     skrll 		}
   1299      1.1     skrll 
   1300      1.1     skrll 	      if (i == 32)
   1301  1.1.1.2  christos 		return _("illegal register included in list");
   1302  1.1.1.2  christos 	    }
   1303      1.1     skrll 
   1304      1.1     skrll 	  exp = exp2;
   1305      1.1     skrll 	}
   1306      1.1     skrll       else
   1307      1.1     skrll 	break;
   1308      1.1     skrll     }
   1309      1.1     skrll 
   1310      1.1     skrll   return NULL;
   1311      1.1     skrll }
   1312      1.1     skrll 
   1313      1.1     skrll const char *md_shortopts = "m:";
   1314      1.1     skrll 
   1315  1.1.1.2  christos struct option md_longopts[] =
   1316  1.1.1.2  christos {
   1317  1.1.1.2  christos #define OPTION_DISP_SIZE_DEFAULT_22 (OPTION_MD_BASE)
   1318  1.1.1.2  christos   {"disp-size-default-22", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_22},
   1319      1.1     skrll #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 1)
   1320      1.1     skrll   {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
   1321      1.1     skrll   {NULL, no_argument, NULL, 0}
   1322      1.1     skrll };
   1323      1.1     skrll 
   1324      1.1     skrll size_t md_longopts_size = sizeof (md_longopts);
   1325      1.1     skrll 
   1326      1.1     skrll void
   1327      1.1     skrll md_show_usage (FILE *stream)
   1328      1.1     skrll {
   1329      1.1     skrll   fprintf (stream, _(" V850 options:\n"));
   1330      1.1     skrll   fprintf (stream, _("  -mwarn-signed-overflow    Warn if signed immediate values overflow\n"));
   1331      1.1     skrll   fprintf (stream, _("  -mwarn-unsigned-overflow  Warn if unsigned immediate values overflow\n"));
   1332      1.1     skrll   fprintf (stream, _("  -mv850                    The code is targeted at the v850\n"));
   1333  1.1.1.2  christos   fprintf (stream, _("  -mv850e                   The code is targeted at the v850e\n"));
   1334  1.1.1.2  christos   fprintf (stream, _("  -mv850e1                  The code is targeted at the v850e1\n"));
   1335      1.1     skrll   fprintf (stream, _("  -mv850e2                  The code is targeted at the v850e2\n"));
   1336  1.1.1.2  christos   fprintf (stream, _("  -mv850e2v3                The code is targeted at the v850e2v3\n"));
   1337  1.1.1.2  christos   fprintf (stream, _("  -mrelax                   Enable relaxation\n"));
   1338  1.1.1.2  christos   fprintf (stream, _("  --disp-size-default-22    branch displacement with unknown size is 22 bits (default)\n"));
   1339  1.1.1.2  christos   fprintf (stream, _("  --disp-size-default-32    branch displacement with unknown size is 32 bits\n"));
   1340  1.1.1.2  christos   fprintf (stream, _("  -mextension               enable extension opcode support\n"));
   1341      1.1     skrll   fprintf (stream, _("  -mno-bcond17		  disable b<cond> disp17 instruction\n"));
   1342      1.1     skrll   fprintf (stream, _("  -mno-stld23		  disable st/ld offset23 instruction\n"));
   1343      1.1     skrll }
   1344      1.1     skrll 
   1345      1.1     skrll int
   1346      1.1     skrll md_parse_option (int c, char *arg)
   1347  1.1.1.2  christos {
   1348  1.1.1.2  christos   if (c != 'm')
   1349  1.1.1.2  christos     {
   1350  1.1.1.2  christos       switch (c)
   1351  1.1.1.2  christos         {
   1352  1.1.1.2  christos         case OPTION_DISP_SIZE_DEFAULT_22:
   1353  1.1.1.2  christos           default_disp_size = 22;
   1354  1.1.1.2  christos           return 1;
   1355  1.1.1.2  christos 
   1356  1.1.1.2  christos         case OPTION_DISP_SIZE_DEFAULT_32:
   1357  1.1.1.2  christos           default_disp_size = 32;
   1358  1.1.1.2  christos           return 1;
   1359  1.1.1.2  christos         }
   1360      1.1     skrll       return 0;
   1361      1.1     skrll     }
   1362      1.1     skrll 
   1363      1.1     skrll   if (strcmp (arg, "warn-signed-overflow") == 0)
   1364      1.1     skrll     warn_signed_overflows = TRUE;
   1365      1.1     skrll 
   1366      1.1     skrll   else if (strcmp (arg, "warn-unsigned-overflow") == 0)
   1367      1.1     skrll     warn_unsigned_overflows = TRUE;
   1368      1.1     skrll 
   1369      1.1     skrll   else if (strcmp (arg, "v850") == 0)
   1370  1.1.1.2  christos     {
   1371      1.1     skrll       machine = 0;
   1372      1.1     skrll       SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850);
   1373      1.1     skrll     }
   1374      1.1     skrll   else if (strcmp (arg, "v850e") == 0)
   1375  1.1.1.2  christos     {
   1376      1.1     skrll       machine = bfd_mach_v850e;
   1377      1.1     skrll       SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);
   1378      1.1     skrll     }
   1379      1.1     skrll   else if (strcmp (arg, "v850e1") == 0)
   1380  1.1.1.2  christos     {
   1381      1.1     skrll       machine = bfd_mach_v850e1;
   1382  1.1.1.2  christos       SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E1);
   1383      1.1     skrll     }
   1384  1.1.1.2  christos   else if (strcmp (arg, "v850e2") == 0)
   1385  1.1.1.2  christos     {
   1386  1.1.1.2  christos       machine = bfd_mach_v850e2;
   1387  1.1.1.2  christos       SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2);
   1388  1.1.1.2  christos     }
   1389  1.1.1.2  christos   else if (strcmp (arg, "v850e2v3") == 0)
   1390  1.1.1.2  christos     {
   1391  1.1.1.2  christos       machine = bfd_mach_v850e2v3;
   1392  1.1.1.2  christos       SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2V3);
   1393  1.1.1.2  christos     }
   1394  1.1.1.2  christos   else if (strcmp (arg, "extension") == 0)
   1395  1.1.1.2  christos     {
   1396  1.1.1.2  christos       processor_mask |= PROCESSOR_OPTION_EXTENSION | PROCESSOR_OPTION_ALIAS;;
   1397  1.1.1.2  christos     }
   1398  1.1.1.2  christos   else if (strcmp (arg, "no-bcond17") == 0)
   1399  1.1.1.2  christos     {
   1400  1.1.1.2  christos       no_bcond17 = 1;
   1401  1.1.1.2  christos     }
   1402  1.1.1.2  christos   else if (strcmp (arg, "no-stld23") == 0)
   1403      1.1     skrll     {
   1404      1.1     skrll       no_stld23 = 1;
   1405      1.1     skrll     }
   1406      1.1     skrll   else if (strcmp (arg, "relax") == 0)
   1407      1.1     skrll     v850_relax = 1;
   1408      1.1     skrll   else
   1409      1.1     skrll     return 0;
   1410      1.1     skrll 
   1411      1.1     skrll   return 1;
   1412      1.1     skrll }
   1413      1.1     skrll 
   1414      1.1     skrll symbolS *
   1415      1.1     skrll md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   1416      1.1     skrll {
   1417      1.1     skrll   return 0;
   1418      1.1     skrll }
   1419      1.1     skrll 
   1420      1.1     skrll char *
   1421      1.1     skrll md_atof (int type, char *litp, int *sizep)
   1422      1.1     skrll {
   1423      1.1     skrll   return ieee_md_atof (type, litp, sizep, FALSE);
   1424      1.1     skrll }
   1425      1.1     skrll 
   1426      1.1     skrll /* Very gross.  */
   1427      1.1     skrll 
   1428      1.1     skrll void
   1429      1.1     skrll md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
   1430      1.1     skrll 		 asection *sec,
   1431      1.1     skrll 		 fragS *fragP)
   1432      1.1     skrll {
   1433      1.1     skrll   union u
   1434      1.1     skrll   {
   1435      1.1     skrll     bfd_reloc_code_real_type fx_r_type;
   1436      1.1     skrll     char * fr_opcode;
   1437      1.1     skrll   }
   1438      1.1     skrll   opcode_converter;
   1439      1.1     skrll   subseg_change (sec, 0);
   1440  1.1.1.2  christos 
   1441  1.1.1.2  christos   opcode_converter.fr_opcode = fragP->fr_opcode;
   1442  1.1.1.2  christos 
   1443      1.1     skrll   subseg_change (sec, 0);
   1444  1.1.1.2  christos 
   1445  1.1.1.2  christos   /* In range conditional or unconditional branch.  */
   1446  1.1.1.2  christos   if (fragP->fr_subtype == SUBYPTE_COND_9_22
   1447  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_UNCOND_9_22
   1448  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_COND_9_22_32
   1449  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_UNCOND_9_22_32
   1450  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_COND_9_17_22
   1451  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32
   1452  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_SA_9_22
   1453  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_SA_9_22_32
   1454  1.1.1.2  christos       || fragP->fr_subtype == SUBYPTE_SA_9_17_22
   1455      1.1     skrll       || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32)
   1456      1.1     skrll 
   1457      1.1     skrll     {
   1458      1.1     skrll       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
   1459      1.1     skrll 	       fragP->fr_offset, 1,
   1460      1.1     skrll 	       BFD_RELOC_UNUSED + opcode_converter.fx_r_type);
   1461  1.1.1.2  christos       fragP->fr_fix += 2;
   1462  1.1.1.2  christos     }
   1463  1.1.1.2  christos   /* V850e2r-v3 17bit conditional branch.  */
   1464  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_COND_9_17_22 + 1
   1465  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32 + 1
   1466  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_17_22 + 1
   1467  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 1)
   1468  1.1.1.2  christos     {
   1469  1.1.1.2  christos       unsigned char *buffer =
   1470  1.1.1.2  christos 	(unsigned char *) (fragP->fr_fix + fragP->fr_literal);
   1471  1.1.1.2  christos 
   1472  1.1.1.2  christos       buffer[0] &= 0x0f;	/* Use condition.  */
   1473  1.1.1.2  christos       buffer[0] |= 0xe0;
   1474  1.1.1.2  christos       buffer[1] = 0x07;
   1475  1.1.1.2  christos 
   1476  1.1.1.2  christos       /* Now create the unconditional branch + fixup to the final
   1477  1.1.1.2  christos 	 target.  */
   1478  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 2, 0x0001, 2);
   1479  1.1.1.2  christos       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
   1480  1.1.1.2  christos 	       fragP->fr_offset, 1, BFD_RELOC_V850_17_PCREL);
   1481  1.1.1.2  christos       fragP->fr_fix += 4;
   1482  1.1.1.2  christos     }
   1483  1.1.1.2  christos   /* Out of range conditional branch.  Emit a branch around a 22bit jump.  */
   1484  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_COND_9_22 + 1
   1485  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_COND_9_22_32 + 1
   1486      1.1     skrll 	   || fragP->fr_subtype == SUBYPTE_COND_9_17_22 + 2
   1487      1.1     skrll 	   || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32 + 2)
   1488      1.1     skrll     {
   1489      1.1     skrll       unsigned char *buffer =
   1490      1.1     skrll 	(unsigned char *) (fragP->fr_fix + fragP->fr_literal);
   1491      1.1     skrll 
   1492      1.1     skrll       /* Reverse the condition of the first branch.  */
   1493      1.1     skrll       buffer[0] ^= 0x08;
   1494      1.1     skrll       /* Mask off all the displacement bits.  */
   1495      1.1     skrll       buffer[0] &= 0x8f;
   1496      1.1     skrll       buffer[1] &= 0x07;
   1497      1.1     skrll       /* Now set the displacement bits so that we branch
   1498      1.1     skrll 	 around the unconditional branch.  */
   1499      1.1     skrll       buffer[0] |= 0x30;
   1500      1.1     skrll 
   1501      1.1     skrll       /* Now create the unconditional branch + fixup to the final
   1502      1.1     skrll 	 target.  */
   1503  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 2, 0x00000780, 4);
   1504      1.1     skrll       fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
   1505      1.1     skrll 	       fragP->fr_offset, 1, BFD_RELOC_V850_22_PCREL);
   1506  1.1.1.2  christos       fragP->fr_fix += 6;
   1507  1.1.1.2  christos     }
   1508  1.1.1.2  christos   /* Out of range conditional branch.  Emit a branch around a 32bit jump.  */
   1509  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_COND_9_22_32 + 2
   1510  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_COND_9_17_22_32 + 3)
   1511  1.1.1.2  christos     {
   1512  1.1.1.2  christos       unsigned char *buffer =
   1513  1.1.1.2  christos 	(unsigned char *) (fragP->fr_fix + fragP->fr_literal);
   1514  1.1.1.2  christos 
   1515  1.1.1.2  christos       /* Reverse the condition of the first branch.  */
   1516  1.1.1.2  christos       buffer[0] ^= 0x08;
   1517  1.1.1.2  christos       /* Mask off all the displacement bits.  */
   1518  1.1.1.2  christos       buffer[0] &= 0x8f;
   1519  1.1.1.2  christos       buffer[1] &= 0x07;
   1520  1.1.1.2  christos       /* Now set the displacement bits so that we branch
   1521  1.1.1.2  christos 	 around the unconditional branch.  */
   1522  1.1.1.2  christos       buffer[0] |= 0x40;
   1523  1.1.1.2  christos 
   1524  1.1.1.2  christos       /* Now create the unconditional branch + fixup to the final
   1525  1.1.1.2  christos 	 target.  */
   1526  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 2, 0x02e0, 2);
   1527  1.1.1.2  christos       fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
   1528  1.1.1.2  christos 	       fragP->fr_offset + 2, 1, BFD_RELOC_V850_32_PCREL);
   1529  1.1.1.2  christos       fragP->fr_fix += 8;
   1530  1.1.1.2  christos     }
   1531  1.1.1.2  christos   /* Out of range unconditional branch.  Emit a 22bit jump.  */
   1532      1.1     skrll   else if (fragP->fr_subtype == SUBYPTE_UNCOND_9_22 + 1
   1533      1.1     skrll 	   || fragP->fr_subtype == SUBYPTE_UNCOND_9_22_32 + 1)
   1534      1.1     skrll     {
   1535  1.1.1.2  christos       md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
   1536      1.1     skrll       fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
   1537      1.1     skrll 	       fragP->fr_offset, 1, BFD_RELOC_V850_22_PCREL);
   1538  1.1.1.2  christos       fragP->fr_fix += 4;
   1539  1.1.1.2  christos     }
   1540  1.1.1.2  christos   /* Out of range unconditional branch.  Emit a 32bit jump.  */
   1541  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_UNCOND_9_22_32 + 2)
   1542  1.1.1.2  christos     {
   1543  1.1.1.2  christos       md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x02e0, 2);
   1544  1.1.1.2  christos       fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
   1545  1.1.1.2  christos 	       fragP->fr_offset + 2, 1, BFD_RELOC_V850_32_PCREL);
   1546  1.1.1.2  christos       fragP->fr_fix += 6;
   1547  1.1.1.2  christos     }
   1548  1.1.1.2  christos   /* Out of range SA conditional branch.  Emit a branch to a 22bit jump.  */
   1549  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_SA_9_22 + 1
   1550  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_22_32 + 1
   1551  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_17_22 + 2
   1552  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 2)
   1553  1.1.1.2  christos     {
   1554  1.1.1.2  christos       unsigned char *buffer =
   1555  1.1.1.2  christos 	(unsigned char *) (fragP->fr_fix + fragP->fr_literal);
   1556  1.1.1.2  christos 
   1557  1.1.1.2  christos       /* bsa .+4 */
   1558  1.1.1.2  christos       buffer[0] &= 0x8f;
   1559  1.1.1.2  christos       buffer[0] |= 0x20;
   1560  1.1.1.2  christos       buffer[1] &= 0x07;
   1561  1.1.1.2  christos 
   1562  1.1.1.2  christos       /* br .+6 */
   1563  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 2, 0x05b5, 2);
   1564  1.1.1.2  christos 
   1565  1.1.1.2  christos       /* Now create the unconditional branch + fixup to the final
   1566  1.1.1.2  christos 	 target.  */
   1567  1.1.1.2  christos       /* jr SYM */
   1568  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 4, 0x00000780, 4);
   1569  1.1.1.2  christos       fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
   1570  1.1.1.2  christos 	       fragP->fr_offset, 1,
   1571  1.1.1.2  christos 	       BFD_RELOC_V850_22_PCREL);
   1572  1.1.1.2  christos       fragP->fr_fix += 8;
   1573  1.1.1.2  christos     }
   1574  1.1.1.2  christos   /* Out of range SA conditional branch.  Emit a branch around a 32bit jump.  */
   1575  1.1.1.2  christos   else if (fragP->fr_subtype == SUBYPTE_SA_9_22_32 + 2
   1576  1.1.1.2  christos 	   || fragP->fr_subtype == SUBYPTE_SA_9_17_22_32 + 3)
   1577  1.1.1.2  christos     {
   1578  1.1.1.2  christos       unsigned char *buffer =
   1579  1.1.1.2  christos 	(unsigned char *) (fragP->fr_fix + fragP->fr_literal);
   1580  1.1.1.2  christos 
   1581  1.1.1.2  christos       /* bsa .+2 */
   1582  1.1.1.2  christos       buffer[0] &= 0x8f;
   1583  1.1.1.2  christos       buffer[0] |= 0x20;
   1584  1.1.1.2  christos       buffer[1] &= 0x07;
   1585  1.1.1.2  christos 
   1586  1.1.1.2  christos       /* br .+8 */
   1587  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 2, 0x05c5, 2);
   1588  1.1.1.2  christos 
   1589  1.1.1.2  christos       /* Now create the unconditional branch + fixup to the final
   1590  1.1.1.2  christos 	 target.  */
   1591  1.1.1.2  christos       /* jr SYM */
   1592  1.1.1.2  christos       md_number_to_chars ((char *) buffer + 4, 0x02e0, 2);
   1593  1.1.1.2  christos       fix_new (fragP, fragP->fr_fix + 6, 4, fragP->fr_symbol,
   1594  1.1.1.2  christos 	       fragP->fr_offset + 2, 1, BFD_RELOC_V850_32_PCREL);
   1595  1.1.1.2  christos 
   1596      1.1     skrll       fragP->fr_fix += 10;
   1597      1.1     skrll     }
   1598      1.1     skrll   else
   1599      1.1     skrll     abort ();
   1600      1.1     skrll }
   1601      1.1     skrll 
   1602      1.1     skrll valueT
   1603      1.1     skrll md_section_align (asection *seg, valueT addr)
   1604      1.1     skrll {
   1605      1.1     skrll   int align = bfd_get_section_alignment (stdoutput, seg);
   1606      1.1     skrll   return ((addr + (1 << align) - 1) & (-1 << align));
   1607      1.1     skrll }
   1608      1.1     skrll 
   1609      1.1     skrll void
   1610      1.1     skrll md_begin (void)
   1611      1.1     skrll {
   1612      1.1     skrll   char *prev_name = "";
   1613  1.1.1.2  christos   const struct v850_opcode *op;
   1614  1.1.1.2  christos 
   1615  1.1.1.2  christos   if (strncmp (TARGET_CPU, "v850e2v3", 8) == 0)
   1616  1.1.1.2  christos     {
   1617  1.1.1.2  christos       if (machine == -1)
   1618  1.1.1.2  christos         machine = bfd_mach_v850e2v3;
   1619  1.1.1.2  christos 
   1620  1.1.1.2  christos       if (!processor_mask)
   1621  1.1.1.2  christos         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2V3);
   1622  1.1.1.2  christos     }
   1623  1.1.1.2  christos   else if (strncmp (TARGET_CPU, "v850e2", 6) == 0)
   1624  1.1.1.2  christos     {
   1625  1.1.1.2  christos       if (machine == -1)
   1626  1.1.1.2  christos 	machine = bfd_mach_v850e2;
   1627  1.1.1.2  christos 
   1628  1.1.1.2  christos       if (!processor_mask)
   1629  1.1.1.2  christos 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E2);
   1630      1.1     skrll     }
   1631      1.1     skrll   else if (strncmp (TARGET_CPU, "v850e1", 6) == 0)
   1632  1.1.1.2  christos     {
   1633      1.1     skrll       if (machine == -1)
   1634  1.1.1.2  christos         machine = bfd_mach_v850e1;
   1635  1.1.1.2  christos 
   1636      1.1     skrll       if (!processor_mask)
   1637      1.1     skrll         SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E1);
   1638      1.1     skrll     }
   1639      1.1     skrll   else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
   1640      1.1     skrll     {
   1641      1.1     skrll       if (machine == -1)
   1642  1.1.1.2  christos 	machine = bfd_mach_v850e;
   1643  1.1.1.2  christos 
   1644      1.1     skrll       if (!processor_mask)
   1645      1.1     skrll 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850E);
   1646      1.1     skrll     }
   1647      1.1     skrll   else if (strncmp (TARGET_CPU, "v850", 4) == 0)
   1648      1.1     skrll     {
   1649      1.1     skrll       if (machine == -1)
   1650  1.1.1.2  christos 	machine = 0;
   1651  1.1.1.2  christos 
   1652      1.1     skrll       if (!processor_mask)
   1653      1.1     skrll 	SET_PROCESSOR_MASK (processor_mask, PROCESSOR_V850);
   1654      1.1     skrll     }
   1655      1.1     skrll   else
   1656      1.1     skrll     /* xgettext:c-format  */
   1657      1.1     skrll     as_bad (_("Unable to determine default target processor from string: %s"),
   1658      1.1     skrll 	    TARGET_CPU);
   1659      1.1     skrll 
   1660      1.1     skrll   v850_hash = hash_new ();
   1661      1.1     skrll 
   1662      1.1     skrll   /* Insert unique names into hash table.  The V850 instruction set
   1663      1.1     skrll      has many identical opcode names that have different opcodes based
   1664      1.1     skrll      on the operands.  This hash table then provides a quick index to
   1665      1.1     skrll      the first opcode with a particular name in the opcode table.  */
   1666      1.1     skrll   op = v850_opcodes;
   1667      1.1     skrll   while (op->name)
   1668      1.1     skrll     {
   1669      1.1     skrll       if (strcmp (prev_name, op->name))
   1670      1.1     skrll 	{
   1671      1.1     skrll 	  prev_name = (char *) op->name;
   1672      1.1     skrll 	  hash_insert (v850_hash, op->name, (char *) op);
   1673      1.1     skrll 	}
   1674      1.1     skrll       op++;
   1675      1.1     skrll     }
   1676      1.1     skrll 
   1677      1.1     skrll   v850_seg_table[BSS_SECTION].s = bss_section;
   1678      1.1     skrll   bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
   1679  1.1.1.2  christos }
   1680      1.1     skrll 
   1681  1.1.1.2  christos 
   1682      1.1     skrll static bfd_reloc_code_real_type
   1683  1.1.1.2  christos handle_hi016 (const struct v850_operand *operand, const char **errmsg)
   1684  1.1.1.2  christos {
   1685      1.1     skrll   if (operand == NULL)
   1686  1.1.1.2  christos     return BFD_RELOC_HI16;
   1687  1.1.1.2  christos 
   1688  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_HI16)
   1689  1.1.1.2  christos     return BFD_RELOC_HI16;
   1690  1.1.1.2  christos 
   1691  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_HI16_S)
   1692  1.1.1.2  christos     return BFD_RELOC_HI16;
   1693  1.1.1.2  christos 
   1694  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_16)
   1695  1.1.1.2  christos     return BFD_RELOC_HI16;
   1696  1.1.1.2  christos 
   1697  1.1.1.2  christos   *errmsg = _("hi0() relocation used on an instruction which does "
   1698  1.1.1.2  christos 	      "not support it");
   1699  1.1.1.2  christos   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1700  1.1.1.2  christos }
   1701  1.1.1.2  christos 
   1702  1.1.1.2  christos static bfd_reloc_code_real_type
   1703  1.1.1.2  christos handle_hi16 (const struct v850_operand *operand, const char **errmsg)
   1704  1.1.1.2  christos {
   1705  1.1.1.2  christos   if (operand == NULL)
   1706  1.1.1.2  christos     return BFD_RELOC_HI16_S;
   1707  1.1.1.2  christos 
   1708  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_HI16_S)
   1709  1.1.1.2  christos     return BFD_RELOC_HI16_S;
   1710  1.1.1.2  christos 
   1711  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_HI16)
   1712  1.1.1.2  christos     return BFD_RELOC_HI16_S;
   1713  1.1.1.2  christos 
   1714  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_16)
   1715  1.1.1.2  christos     return BFD_RELOC_HI16_S;
   1716  1.1.1.2  christos 
   1717  1.1.1.2  christos   *errmsg = _("hi() relocation used on an instruction which does "
   1718  1.1.1.2  christos 	      "not support it");
   1719  1.1.1.2  christos   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1720  1.1.1.2  christos }
   1721  1.1.1.2  christos 
   1722  1.1.1.2  christos static bfd_reloc_code_real_type
   1723  1.1.1.2  christos handle_lo16 (const struct v850_operand *operand, const char **errmsg)
   1724  1.1.1.2  christos {
   1725  1.1.1.2  christos   if (operand == NULL)
   1726  1.1.1.2  christos     return BFD_RELOC_LO16;
   1727  1.1.1.2  christos 
   1728  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_LO16)
   1729  1.1.1.2  christos     return BFD_RELOC_LO16;
   1730  1.1.1.2  christos 
   1731  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_V850_16_SPLIT_OFFSET)
   1732  1.1.1.2  christos     return BFD_RELOC_V850_LO16_SPLIT_OFFSET;
   1733  1.1.1.2  christos 
   1734  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_V850_16_S1)
   1735  1.1.1.2  christos     return BFD_RELOC_V850_LO16_S1;
   1736  1.1.1.2  christos 
   1737  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_16)
   1738  1.1.1.2  christos     return BFD_RELOC_LO16;
   1739  1.1.1.2  christos 
   1740  1.1.1.2  christos   *errmsg = _("lo() relocation used on an instruction which does "
   1741      1.1     skrll 	      "not support it");
   1742      1.1     skrll   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1743      1.1     skrll }
   1744  1.1.1.2  christos 
   1745      1.1     skrll static bfd_reloc_code_real_type
   1746      1.1     skrll handle_ctoff (const struct v850_operand *operand, const char **errmsg)
   1747      1.1     skrll {
   1748      1.1     skrll   if (operand == NULL)
   1749  1.1.1.2  christos     return BFD_RELOC_V850_CALLT_16_16_OFFSET;
   1750  1.1.1.2  christos 
   1751  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_V850_CALLT_6_7_OFFSET)
   1752  1.1.1.2  christos     return operand->default_reloc;
   1753  1.1.1.2  christos 
   1754  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_V850_16_S1)
   1755  1.1.1.2  christos     return BFD_RELOC_V850_CALLT_15_16_OFFSET;
   1756  1.1.1.2  christos 
   1757      1.1     skrll   if (operand->default_reloc == BFD_RELOC_16)
   1758  1.1.1.2  christos     return BFD_RELOC_V850_CALLT_16_16_OFFSET;
   1759  1.1.1.2  christos 
   1760      1.1     skrll   *errmsg = _("ctoff() relocation used on an instruction which does not support it");
   1761      1.1     skrll   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1762      1.1     skrll }
   1763  1.1.1.2  christos 
   1764      1.1     skrll static bfd_reloc_code_real_type
   1765      1.1     skrll handle_sdaoff (const struct v850_operand *operand, const char **errmsg)
   1766      1.1     skrll {
   1767      1.1     skrll   if (operand == NULL)
   1768  1.1.1.2  christos     return BFD_RELOC_V850_SDA_16_16_OFFSET;
   1769      1.1     skrll 
   1770      1.1     skrll   if (operand->default_reloc == BFD_RELOC_V850_16_SPLIT_OFFSET)
   1771  1.1.1.2  christos     return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
   1772  1.1.1.2  christos 
   1773  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_16)
   1774  1.1.1.2  christos     return BFD_RELOC_V850_SDA_16_16_OFFSET;
   1775  1.1.1.2  christos 
   1776      1.1     skrll   if (operand->default_reloc == BFD_RELOC_V850_16_S1)
   1777  1.1.1.2  christos     return BFD_RELOC_V850_SDA_15_16_OFFSET;
   1778  1.1.1.2  christos 
   1779      1.1     skrll   *errmsg = _("sdaoff() relocation used on an instruction which does not support it");
   1780      1.1     skrll   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1781      1.1     skrll }
   1782  1.1.1.2  christos 
   1783      1.1     skrll static bfd_reloc_code_real_type
   1784      1.1     skrll handle_zdaoff (const struct v850_operand *operand, const char **errmsg)
   1785      1.1     skrll {
   1786      1.1     skrll   if (operand == NULL)
   1787  1.1.1.2  christos     return BFD_RELOC_V850_ZDA_16_16_OFFSET;
   1788      1.1     skrll 
   1789      1.1     skrll   if (operand->default_reloc == BFD_RELOC_V850_16_SPLIT_OFFSET)
   1790  1.1.1.2  christos     return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
   1791  1.1.1.2  christos 
   1792      1.1     skrll   if (operand->default_reloc == BFD_RELOC_16)
   1793  1.1.1.2  christos     return BFD_RELOC_V850_ZDA_16_16_OFFSET;
   1794  1.1.1.2  christos 
   1795  1.1.1.2  christos   if (operand->default_reloc == BFD_RELOC_V850_16_S1)
   1796  1.1.1.2  christos     return BFD_RELOC_V850_ZDA_15_16_OFFSET;
   1797  1.1.1.2  christos 
   1798      1.1     skrll   *errmsg = _("zdaoff() relocation used on an instruction which does not support it");
   1799      1.1     skrll   return BFD_RELOC_64;  /* Used to indicate an error condition.  */
   1800      1.1     skrll }
   1801  1.1.1.2  christos 
   1802      1.1     skrll static bfd_reloc_code_real_type
   1803      1.1     skrll handle_tdaoff (const struct v850_operand *operand, const char **errmsg)
   1804      1.1     skrll {
   1805  1.1.1.2  christos   if (operand == NULL)
   1806      1.1     skrll     /* Data item, not an instruction.  */
   1807  1.1.1.2  christos     return BFD_RELOC_V850_TDA_16_16_OFFSET;
   1808  1.1.1.2  christos 
   1809  1.1.1.2  christos   switch (operand->default_reloc)
   1810  1.1.1.2  christos     {
   1811  1.1.1.2  christos       /* sld.hu, operand: D5-4.  */
   1812  1.1.1.2  christos     case BFD_RELOC_V850_TDA_4_5_OFFSET:
   1813      1.1     skrll       /* sld.bu, operand: D4.  */
   1814  1.1.1.2  christos     case BFD_RELOC_V850_TDA_4_4_OFFSET:
   1815  1.1.1.2  christos     /* sld.w/sst.w, operand: D8_6.  */
   1816  1.1.1.2  christos     case BFD_RELOC_V850_TDA_6_8_OFFSET:
   1817  1.1.1.2  christos     /* sld.h/sst.h, operand: D8_7.  */
   1818  1.1.1.2  christos     case BFD_RELOC_V850_TDA_7_8_OFFSET:
   1819  1.1.1.2  christos       /* sld.b/sst.b, operand: D7.  */
   1820  1.1.1.2  christos     case BFD_RELOC_V850_TDA_7_7_OFFSET:
   1821  1.1.1.2  christos       return operand->default_reloc;
   1822  1.1.1.2  christos     default:
   1823      1.1     skrll       break;
   1824  1.1.1.2  christos     }
   1825      1.1     skrll 
   1826      1.1     skrll   if (operand->default_reloc == BFD_RELOC_16 && operand->shift == 16)
   1827      1.1     skrll     /* set1 & chums, operands: D16.  */
   1828  1.1.1.2  christos     return BFD_RELOC_V850_TDA_16_16_OFFSET;
   1829  1.1.1.2  christos 
   1830  1.1.1.2  christos   *errmsg = _("tdaoff() relocation used on an instruction which does not support it");
   1831      1.1     skrll   /* Used to indicate an error condition.  */
   1832      1.1     skrll   return BFD_RELOC_64;
   1833      1.1     skrll }
   1834      1.1     skrll 
   1835      1.1     skrll /* Warning: The code in this function relies upon the definitions
   1836      1.1     skrll    in the v850_operands[] array (defined in opcodes/v850-opc.c)
   1837      1.1     skrll    matching the hard coded values contained herein.  */
   1838  1.1.1.2  christos 
   1839      1.1     skrll static bfd_reloc_code_real_type
   1840      1.1     skrll v850_reloc_prefix (const struct v850_operand *operand, const char **errmsg)
   1841      1.1     skrll {
   1842      1.1     skrll   bfd_boolean paren_skipped = FALSE;
   1843      1.1     skrll 
   1844      1.1     skrll   /* Skip leading opening parenthesis.  */
   1845      1.1     skrll   if (*input_line_pointer == '(')
   1846      1.1     skrll     {
   1847      1.1     skrll       ++input_line_pointer;
   1848      1.1     skrll       paren_skipped = TRUE;
   1849      1.1     skrll     }
   1850      1.1     skrll 
   1851      1.1     skrll #define CHECK_(name, reloc) 						\
   1852      1.1     skrll   if (strncmp (input_line_pointer, name "(", strlen (name) + 1) == 0)	\
   1853      1.1     skrll     {									\
   1854      1.1     skrll       input_line_pointer += strlen (name);				\
   1855      1.1     skrll       return reloc;							\
   1856  1.1.1.2  christos     }
   1857  1.1.1.2  christos 
   1858  1.1.1.2  christos   CHECK_ ("hi0",    handle_hi016(operand, errmsg)  );
   1859  1.1.1.2  christos   CHECK_ ("hi",	    handle_hi16(operand, errmsg)   );
   1860  1.1.1.2  christos   CHECK_ ("lo",	    handle_lo16 (operand, errmsg)  );
   1861  1.1.1.2  christos   CHECK_ ("sdaoff", handle_sdaoff (operand, errmsg));
   1862  1.1.1.2  christos   CHECK_ ("zdaoff", handle_zdaoff (operand, errmsg));
   1863  1.1.1.2  christos   CHECK_ ("tdaoff", handle_tdaoff (operand, errmsg));
   1864  1.1.1.2  christos   CHECK_ ("hilo",   BFD_RELOC_32);
   1865      1.1     skrll   CHECK_ ("lo23",   BFD_RELOC_V850_23);
   1866      1.1     skrll   CHECK_ ("ctoff",  handle_ctoff (operand, errmsg) );
   1867      1.1     skrll 
   1868      1.1     skrll   /* Restore skipped parenthesis.  */
   1869      1.1     skrll   if (paren_skipped)
   1870      1.1     skrll     --input_line_pointer;
   1871      1.1     skrll 
   1872      1.1     skrll   return BFD_RELOC_UNUSED;
   1873      1.1     skrll }
   1874      1.1     skrll 
   1875      1.1     skrll /* Insert an operand value into an instruction.  */
   1876      1.1     skrll 
   1877      1.1     skrll static unsigned long
   1878      1.1     skrll v850_insert_operand (unsigned long insn,
   1879  1.1.1.2  christos 		     const struct v850_operand *operand,
   1880      1.1     skrll 		     offsetT val,
   1881      1.1     skrll 		     const char **errmsg)
   1882      1.1     skrll {
   1883      1.1     skrll   if (operand->insert)
   1884      1.1     skrll     {
   1885      1.1     skrll       const char *message = NULL;
   1886      1.1     skrll 
   1887      1.1     skrll       insn = operand->insert (insn, val, &message);
   1888      1.1     skrll       if (message != NULL)
   1889      1.1     skrll 	{
   1890  1.1.1.2  christos 	  if ((operand->flags & V850_OPERAND_SIGNED)
   1891      1.1     skrll 	      && ! warn_signed_overflows
   1892      1.1     skrll               && v850_msg_is_out_of_range (message))
   1893      1.1     skrll 	    {
   1894      1.1     skrll 	      /* Skip warning...  */
   1895      1.1     skrll 	    }
   1896  1.1.1.2  christos 	  else if ((operand->flags & V850_OPERAND_SIGNED) == 0
   1897      1.1     skrll 		   && ! warn_unsigned_overflows
   1898      1.1     skrll                   && v850_msg_is_out_of_range (message))
   1899      1.1     skrll 	    {
   1900      1.1     skrll 	      /* Skip warning...  */
   1901      1.1     skrll 	    }
   1902  1.1.1.2  christos 	  else
   1903  1.1.1.2  christos 	    {
   1904      1.1     skrll              if (errmsg != NULL)
   1905      1.1     skrll                *errmsg = message;
   1906      1.1     skrll 	    }
   1907  1.1.1.2  christos 	}
   1908  1.1.1.2  christos     }
   1909  1.1.1.2  christos   else if (operand->bits == -1
   1910  1.1.1.2  christos           || operand->flags & V850E_IMMEDIATE16
   1911  1.1.1.2  christos           || operand->flags & V850E_IMMEDIATE23
   1912  1.1.1.2  christos           || operand->flags & V850E_IMMEDIATE32)
   1913  1.1.1.2  christos     {
   1914      1.1     skrll       abort ();
   1915      1.1     skrll     }
   1916  1.1.1.2  christos   else
   1917      1.1     skrll     {
   1918      1.1     skrll       if (operand->bits < 32)
   1919      1.1     skrll 	{
   1920      1.1     skrll 	  long min, max;
   1921      1.1     skrll 
   1922      1.1     skrll 	  if ((operand->flags & V850_OPERAND_SIGNED) != 0)
   1923      1.1     skrll 	    {
   1924      1.1     skrll 	      if (! warn_signed_overflows)
   1925      1.1     skrll 		max = (1 << operand->bits) - 1;
   1926      1.1     skrll 	      else
   1927      1.1     skrll 		max = (1 << (operand->bits - 1)) - 1;
   1928      1.1     skrll 
   1929      1.1     skrll 	      min = -(1 << (operand->bits - 1));
   1930      1.1     skrll 	    }
   1931      1.1     skrll 	  else
   1932      1.1     skrll 	    {
   1933      1.1     skrll 	      max = (1 << operand->bits) - 1;
   1934      1.1     skrll 
   1935      1.1     skrll 	      if (! warn_unsigned_overflows)
   1936      1.1     skrll 		min = -(1 << (operand->bits - 1));
   1937      1.1     skrll 	      else
   1938      1.1     skrll 		min = 0;
   1939  1.1.1.2  christos 	    }
   1940  1.1.1.2  christos 
   1941  1.1.1.2  christos 	  /* Some people write constants with the sign extension done by
   1942  1.1.1.2  christos 	     hand but only up to 32 bits.  This shouldn't really be valid,
   1943  1.1.1.2  christos 	     but, to permit this code to assemble on a 64-bit host, we
   1944  1.1.1.2  christos 	     sign extend the 32-bit value to 64 bits if so doing makes the
   1945  1.1.1.2  christos 	     value valid.  */
   1946  1.1.1.2  christos 	  if (val > max
   1947  1.1.1.2  christos 	      && (offsetT) (val - 0x80000000 - 0x80000000) >= min
   1948  1.1.1.2  christos 	      && (offsetT) (val - 0x80000000 - 0x80000000) <= max)
   1949  1.1.1.2  christos 	    val = val - 0x80000000 - 0x80000000;
   1950  1.1.1.2  christos 
   1951  1.1.1.2  christos 	  /* Similarly, people write expressions like ~(1<<15), and expect
   1952  1.1.1.2  christos 	     this to be OK for a 32-bit unsigned value.  */
   1953  1.1.1.2  christos 	  else if (val < min
   1954  1.1.1.2  christos 		   && (offsetT) (val + 0x80000000 + 0x80000000) >= min
   1955  1.1.1.2  christos 		   && (offsetT) (val + 0x80000000 + 0x80000000) <= max)
   1956  1.1.1.2  christos 	    val = val + 0x80000000 + 0x80000000;
   1957      1.1     skrll 
   1958      1.1     skrll 	  else if (val < (offsetT) min || val > (offsetT) max)
   1959      1.1     skrll 	    {
   1960      1.1     skrll 	      char buf [128];
   1961      1.1     skrll 
   1962      1.1     skrll 	      /* Restore min and mix to expected values for decimal ranges.  */
   1963      1.1     skrll 	      if ((operand->flags & V850_OPERAND_SIGNED)
   1964      1.1     skrll 		  && ! warn_signed_overflows)
   1965      1.1     skrll 		max = (1 << (operand->bits - 1)) - 1;
   1966      1.1     skrll 
   1967      1.1     skrll 	      if (! (operand->flags & V850_OPERAND_SIGNED)
   1968      1.1     skrll 		  && ! warn_unsigned_overflows)
   1969  1.1.1.2  christos 		min = 0;
   1970  1.1.1.2  christos 
   1971  1.1.1.2  christos 	      sprintf (buf, _("operand out of range (%d is not between %d and %d)"),
   1972      1.1     skrll 		       (int) val, (int) min, (int) max);
   1973      1.1     skrll 	      *errmsg = buf;
   1974  1.1.1.2  christos 	    }
   1975  1.1.1.2  christos 
   1976  1.1.1.2  christos 	  insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
   1977  1.1.1.2  christos 	}
   1978  1.1.1.2  christos       else
   1979  1.1.1.2  christos 	{
   1980      1.1     skrll 	  insn |= (((long) val) << operand->shift);
   1981      1.1     skrll 	}
   1982      1.1     skrll     }
   1983      1.1     skrll 
   1984      1.1     skrll   return insn;
   1985      1.1     skrll }
   1986      1.1     skrll 
   1987      1.1     skrll static char copy_of_instruction[128];
   1989      1.1     skrll 
   1990      1.1     skrll void
   1991      1.1     skrll md_assemble (char *str)
   1992      1.1     skrll {
   1993      1.1     skrll   char *s;
   1994      1.1     skrll   char *start_of_operands;
   1995      1.1     skrll   struct v850_opcode *opcode;
   1996      1.1     skrll   struct v850_opcode *next_opcode;
   1997      1.1     skrll   const unsigned char *opindex_ptr;
   1998      1.1     skrll   int next_opindex;
   1999      1.1     skrll   int relaxable = 0;
   2000      1.1     skrll   unsigned long insn;
   2001      1.1     skrll   unsigned long insn_size;
   2002      1.1     skrll   char *f;
   2003      1.1     skrll   int i;
   2004      1.1     skrll   int match;
   2005      1.1     skrll   bfd_boolean extra_data_after_insn = FALSE;
   2006  1.1.1.2  christos   unsigned extra_data_len = 0;
   2007  1.1.1.2  christos   unsigned long extra_data = 0;
   2008      1.1     skrll   char *saved_input_line_pointer;
   2009      1.1     skrll   char most_match_errmsg[1024];
   2010  1.1.1.2  christos   int most_match_count = -1;
   2011      1.1     skrll 
   2012      1.1     skrll   strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
   2013      1.1     skrll   most_match_errmsg[0] = 0;
   2014      1.1     skrll 
   2015      1.1     skrll   /* Get the opcode.  */
   2016      1.1     skrll   for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
   2017      1.1     skrll     continue;
   2018      1.1     skrll 
   2019      1.1     skrll   if (*s != '\0')
   2020      1.1     skrll     *s++ = '\0';
   2021      1.1     skrll 
   2022      1.1     skrll   /* Find the first opcode with the proper name.  */
   2023      1.1     skrll   opcode = (struct v850_opcode *) hash_find (v850_hash, str);
   2024      1.1     skrll   if (opcode == NULL)
   2025      1.1     skrll     {
   2026      1.1     skrll       /* xgettext:c-format  */
   2027      1.1     skrll       as_bad (_("Unrecognized opcode: `%s'"), str);
   2028      1.1     skrll       ignore_rest_of_line ();
   2029      1.1     skrll       return;
   2030      1.1     skrll     }
   2031      1.1     skrll 
   2032      1.1     skrll   str = s;
   2033      1.1     skrll   while (ISSPACE (*str))
   2034      1.1     skrll     ++str;
   2035      1.1     skrll 
   2036      1.1     skrll   start_of_operands = str;
   2037      1.1     skrll 
   2038      1.1     skrll   saved_input_line_pointer = input_line_pointer;
   2039      1.1     skrll 
   2040  1.1.1.2  christos   for (;;)
   2041      1.1     skrll     {
   2042      1.1     skrll       const char *errmsg = NULL;
   2043  1.1.1.2  christos       const char *warningmsg = NULL;
   2044      1.1     skrll 
   2045  1.1.1.2  christos       match = 0;
   2046  1.1.1.2  christos       opindex_ptr = opcode->operands;
   2047  1.1.1.2  christos 
   2048  1.1.1.2  christos       if (no_stld23)
   2049  1.1.1.2  christos 	{
   2050  1.1.1.2  christos 	  if ((strncmp (opcode->name, "st.", 3) == 0
   2051  1.1.1.2  christos 	       && v850_operands[opcode->operands[1]].bits == 23)
   2052  1.1.1.2  christos 	      || (strncmp (opcode->name, "ld.", 3) == 0
   2053  1.1.1.2  christos 		  && v850_operands[opcode->operands[0]].bits == 23))
   2054  1.1.1.2  christos 	    {
   2055  1.1.1.2  christos 	      errmsg = _("st/ld offset 23 instruction was disabled .");
   2056  1.1.1.2  christos 	      goto error;
   2057  1.1.1.2  christos 	    }
   2058  1.1.1.2  christos 	}
   2059  1.1.1.2  christos 
   2060      1.1     skrll       if ((opcode->processors & processor_mask & PROCESSOR_MASK) == 0
   2061      1.1     skrll 	  || (((opcode->processors & ~PROCESSOR_MASK) != 0)
   2062      1.1     skrll 	      && ((opcode->processors & processor_mask & ~PROCESSOR_MASK) == 0)))
   2063      1.1     skrll 	{
   2064      1.1     skrll 	  errmsg = _("Target processor does not support this instruction.");
   2065      1.1     skrll 	  goto error;
   2066      1.1     skrll 	}
   2067      1.1     skrll 
   2068      1.1     skrll       relaxable = 0;
   2069  1.1.1.2  christos       fc = 0;
   2070      1.1     skrll       next_opindex = 0;
   2071      1.1     skrll       insn = opcode->opcode;
   2072      1.1     skrll       extra_data_len = 0;
   2073      1.1     skrll       extra_data_after_insn = FALSE;
   2074      1.1     skrll 
   2075      1.1     skrll       input_line_pointer = str = start_of_operands;
   2076      1.1     skrll 
   2077      1.1     skrll       for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
   2078      1.1     skrll 	{
   2079      1.1     skrll 	  const struct v850_operand *operand;
   2080      1.1     skrll 	  char *hold;
   2081      1.1     skrll 	  expressionS ex;
   2082      1.1     skrll 	  bfd_reloc_code_real_type reloc;
   2083      1.1     skrll 
   2084      1.1     skrll 	  if (next_opindex == 0)
   2085      1.1     skrll 	    operand = &v850_operands[*opindex_ptr];
   2086      1.1     skrll 	  else
   2087      1.1     skrll 	    {
   2088      1.1     skrll 	      operand = &v850_operands[next_opindex];
   2089      1.1     skrll 	      next_opindex = 0;
   2090      1.1     skrll 	    }
   2091  1.1.1.2  christos 
   2092  1.1.1.2  christos 	  errmsg = NULL;
   2093  1.1.1.2  christos 
   2094  1.1.1.2  christos 	  while (*str == ' ')
   2095  1.1.1.2  christos 	    ++str;
   2096  1.1.1.2  christos 
   2097  1.1.1.2  christos 	  if (operand->flags & V850_OPERAND_BANG
   2098  1.1.1.2  christos 	      && *str == '!')
   2099  1.1.1.2  christos 	    ++str;
   2100  1.1.1.2  christos 	  else if (operand->flags & V850_OPERAND_PERCENT
   2101  1.1.1.2  christos 		   && *str == '%')
   2102  1.1.1.2  christos 	    ++str;
   2103  1.1.1.2  christos 
   2104  1.1.1.2  christos 	  if (*str == ',' || *str == '[' || *str == ']')
   2105      1.1     skrll 	    ++str;
   2106      1.1     skrll 
   2107      1.1     skrll 	  while (*str == ' ')
   2108      1.1     skrll 	    ++str;
   2109      1.1     skrll 
   2110      1.1     skrll 	  if (operand->flags & V850_OPERAND_RELAX)
   2111      1.1     skrll 	    relaxable = 1;
   2112      1.1     skrll 
   2113      1.1     skrll 	  /* Gather the operand.  */
   2114      1.1     skrll 	  hold = input_line_pointer;
   2115  1.1.1.2  christos 	  input_line_pointer = str;
   2116      1.1     skrll 
   2117      1.1     skrll 	  /* lo(), hi(), hi0(), etc...  */
   2118      1.1     skrll 	  if ((reloc = v850_reloc_prefix (operand, &errmsg)) != BFD_RELOC_UNUSED)
   2119      1.1     skrll 	    {
   2120  1.1.1.2  christos 	      /* This is a fake reloc, used to indicate an error condition.  */
   2121      1.1     skrll 	      if (reloc == BFD_RELOC_64)
   2122      1.1     skrll 		{
   2123      1.1     skrll 		  /* match = 1;  */
   2124      1.1     skrll 		  goto error;
   2125      1.1     skrll 		}
   2126      1.1     skrll 
   2127      1.1     skrll 	      expression (&ex);
   2128      1.1     skrll 
   2129      1.1     skrll 	      if (ex.X_op == O_constant)
   2130      1.1     skrll 		{
   2131  1.1.1.2  christos 		  switch (reloc)
   2132  1.1.1.2  christos 		    {
   2133      1.1     skrll 		    case BFD_RELOC_V850_ZDA_16_16_OFFSET:
   2134      1.1     skrll 		    case BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET:
   2135      1.1     skrll 		    case BFD_RELOC_V850_ZDA_15_16_OFFSET:
   2136      1.1     skrll 		      /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
   2137      1.1     skrll 			 and the like.  */
   2138  1.1.1.2  christos 		      /* Fall through.  */
   2139      1.1     skrll 
   2140      1.1     skrll 		    case BFD_RELOC_LO16:
   2141      1.1     skrll 		    case BFD_RELOC_V850_LO16_S1:
   2142      1.1     skrll 		    case BFD_RELOC_V850_LO16_SPLIT_OFFSET:
   2143      1.1     skrll 		      {
   2144      1.1     skrll 			/* Truncate, then sign extend the value.  */
   2145      1.1     skrll 			ex.X_add_number = SEXT16 (ex.X_add_number);
   2146      1.1     skrll 			break;
   2147      1.1     skrll 		      }
   2148      1.1     skrll 
   2149      1.1     skrll 		    case BFD_RELOC_HI16:
   2150      1.1     skrll 		      {
   2151      1.1     skrll 			/* Truncate, then sign extend the value.  */
   2152      1.1     skrll 			ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
   2153      1.1     skrll 			break;
   2154      1.1     skrll 		      }
   2155      1.1     skrll 
   2156      1.1     skrll 		    case BFD_RELOC_HI16_S:
   2157      1.1     skrll 		      {
   2158      1.1     skrll 			/* Truncate, then sign extend the value.  */
   2159      1.1     skrll 			int temp = (ex.X_add_number >> 16) & 0xffff;
   2160      1.1     skrll 
   2161      1.1     skrll 			temp += (ex.X_add_number >> 15) & 1;
   2162      1.1     skrll 
   2163      1.1     skrll 			ex.X_add_number = SEXT16 (temp);
   2164  1.1.1.2  christos 			break;
   2165  1.1.1.2  christos 		      }
   2166  1.1.1.2  christos 
   2167  1.1.1.2  christos 		    case BFD_RELOC_V850_23:
   2168  1.1.1.2  christos 		      if ((operand->flags & V850E_IMMEDIATE23) == 0)
   2169  1.1.1.2  christos 			{
   2170  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2171  1.1.1.2  christos 			  goto error;
   2172      1.1     skrll 			}
   2173  1.1.1.2  christos 		      break;
   2174  1.1.1.2  christos 
   2175      1.1     skrll 		    case BFD_RELOC_32:
   2176      1.1     skrll 		    case BFD_RELOC_V850_32_ABS:
   2177      1.1     skrll 		    case BFD_RELOC_V850_32_PCREL:
   2178      1.1     skrll 		      if ((operand->flags & V850E_IMMEDIATE32) == 0)
   2179      1.1     skrll 			{
   2180      1.1     skrll 			  errmsg = _("immediate operand is too large");
   2181      1.1     skrll 			  goto error;
   2182      1.1     skrll 			}
   2183      1.1     skrll 
   2184      1.1     skrll 		      break;
   2185      1.1     skrll 
   2186      1.1     skrll 		    default:
   2187      1.1     skrll 		      fprintf (stderr, "reloc: %d\n", reloc);
   2188      1.1     skrll 		      as_bad (_("AAARG -> unhandled constant reloc"));
   2189  1.1.1.2  christos 		      break;
   2190  1.1.1.2  christos 		    }
   2191  1.1.1.2  christos 
   2192  1.1.1.2  christos 		  if (operand->flags & V850E_IMMEDIATE32)
   2193  1.1.1.2  christos 		    {
   2194  1.1.1.2  christos 		      extra_data_after_insn = TRUE;
   2195  1.1.1.2  christos 		      extra_data_len	    = 4;
   2196  1.1.1.2  christos 		      extra_data	    = 0;
   2197  1.1.1.2  christos 		    }
   2198  1.1.1.2  christos 		  else if (operand->flags & V850E_IMMEDIATE23)
   2199  1.1.1.2  christos 		    {
   2200  1.1.1.2  christos 		      if (reloc != BFD_RELOC_V850_23)
   2201  1.1.1.2  christos 			{
   2202  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2203  1.1.1.2  christos 			  goto error;
   2204  1.1.1.2  christos 			}
   2205  1.1.1.2  christos 		      extra_data_after_insn = TRUE;
   2206  1.1.1.2  christos 		      extra_data_len	    = 2;
   2207  1.1.1.2  christos 		      extra_data	    = 0;
   2208  1.1.1.2  christos 		    }
   2209  1.1.1.2  christos 		  else if ((operand->flags & V850E_IMMEDIATE16)
   2210  1.1.1.2  christos 			   || (operand->flags & V850E_IMMEDIATE16HI))
   2211  1.1.1.2  christos 		    {
   2212  1.1.1.2  christos 		      if (operand->flags & V850E_IMMEDIATE16HI
   2213  1.1.1.2  christos 			  && reloc != BFD_RELOC_HI16
   2214  1.1.1.2  christos 			  && reloc != BFD_RELOC_HI16_S)
   2215  1.1.1.2  christos 			{
   2216  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2217  1.1.1.2  christos 			  goto error;
   2218  1.1.1.2  christos 			}
   2219  1.1.1.2  christos 		      else if (operand->flags & V850E_IMMEDIATE16
   2220  1.1.1.2  christos 			       && reloc != BFD_RELOC_LO16)
   2221  1.1.1.2  christos 			{
   2222  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2223  1.1.1.2  christos 			  goto error;
   2224  1.1.1.2  christos 			}
   2225  1.1.1.2  christos 
   2226  1.1.1.2  christos 		      extra_data_after_insn = TRUE;
   2227  1.1.1.2  christos 		      extra_data_len	    = 2;
   2228      1.1     skrll 		      extra_data	    = 0;
   2229      1.1     skrll 		    }
   2230      1.1     skrll 
   2231      1.1     skrll 		  if (fc > MAX_INSN_FIXUPS)
   2232      1.1     skrll 		    as_fatal (_("too many fixups"));
   2233      1.1     skrll 
   2234      1.1     skrll 		  fixups[fc].exp     = ex;
   2235      1.1     skrll 		  fixups[fc].opindex = *opindex_ptr;
   2236  1.1.1.2  christos 		  fixups[fc].reloc   = reloc;
   2237      1.1     skrll 		  fc++;
   2238  1.1.1.2  christos 		}
   2239  1.1.1.2  christos 	      else	/* ex.X_op != O_constant.  */
   2240  1.1.1.2  christos 		{
   2241  1.1.1.2  christos 		  if ((reloc == BFD_RELOC_32
   2242      1.1     skrll 		       || reloc == BFD_RELOC_V850_32_ABS
   2243  1.1.1.2  christos 		       || reloc == BFD_RELOC_V850_32_PCREL)
   2244  1.1.1.2  christos 		      && operand->bits < 32)
   2245  1.1.1.2  christos 		    {
   2246  1.1.1.2  christos 		      errmsg = _("immediate operand is too large");
   2247  1.1.1.2  christos 		      goto error;
   2248  1.1.1.2  christos 		    }
   2249  1.1.1.2  christos 		  else if (reloc == BFD_RELOC_V850_23
   2250  1.1.1.2  christos 			   && (operand->flags & V850E_IMMEDIATE23) == 0)
   2251  1.1.1.2  christos 		    {
   2252  1.1.1.2  christos 		      errmsg = _("immediate operand is too large");
   2253  1.1.1.2  christos 		      goto error;
   2254  1.1.1.2  christos 		    }
   2255  1.1.1.2  christos 		  else if ((reloc == BFD_RELOC_HI16
   2256  1.1.1.2  christos 			    || reloc == BFD_RELOC_HI16_S)
   2257  1.1.1.2  christos 			   && operand->bits < 16)
   2258  1.1.1.2  christos 		    {
   2259  1.1.1.2  christos 		      errmsg = _("immediate operand is too large");
   2260  1.1.1.2  christos 		      goto error;
   2261  1.1.1.2  christos 		    }
   2262  1.1.1.2  christos 
   2263  1.1.1.2  christos 		  if (operand->flags & V850E_IMMEDIATE32)
   2264  1.1.1.2  christos 		    {
   2265  1.1.1.2  christos 		      extra_data_after_insn = TRUE;
   2266  1.1.1.2  christos 		      extra_data_len	    = 4;
   2267  1.1.1.2  christos 		      extra_data	    = 0;
   2268  1.1.1.2  christos 		    }
   2269  1.1.1.2  christos 		  else if (operand->flags & V850E_IMMEDIATE23)
   2270  1.1.1.2  christos 		    {
   2271  1.1.1.2  christos 		      if (reloc != BFD_RELOC_V850_23)
   2272  1.1.1.2  christos 			{
   2273  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2274  1.1.1.2  christos 			  goto error;
   2275  1.1.1.2  christos 			}
   2276  1.1.1.2  christos 		      extra_data_after_insn = TRUE;
   2277  1.1.1.2  christos 		      extra_data_len	    = 2;
   2278  1.1.1.2  christos 		      extra_data	    = 0;
   2279  1.1.1.2  christos 		    }
   2280  1.1.1.2  christos 		  else if ((operand->flags & V850E_IMMEDIATE16)
   2281  1.1.1.2  christos 			   || (operand->flags & V850E_IMMEDIATE16HI))
   2282  1.1.1.2  christos 		    {
   2283  1.1.1.2  christos 		      if (operand->flags & V850E_IMMEDIATE16HI
   2284  1.1.1.2  christos 			  && reloc != BFD_RELOC_HI16
   2285  1.1.1.2  christos 			  && reloc != BFD_RELOC_HI16_S)
   2286  1.1.1.2  christos 			{
   2287  1.1.1.2  christos 			  errmsg = _("immediate operand is too large");
   2288  1.1.1.2  christos 			  goto error;
   2289      1.1     skrll 			}
   2290      1.1     skrll 		      else if (operand->flags & V850E_IMMEDIATE16
   2291      1.1     skrll 			       && reloc != BFD_RELOC_LO16)
   2292      1.1     skrll 			{
   2293      1.1     skrll 			  errmsg = _("immediate operand is too large");
   2294      1.1     skrll 			  goto error;
   2295  1.1.1.2  christos 			}
   2296  1.1.1.2  christos 
   2297      1.1     skrll 		      extra_data_after_insn = TRUE;
   2298      1.1     skrll 		      extra_data_len	    = 2;
   2299      1.1     skrll 		      extra_data	    = 0;
   2300      1.1     skrll 		    }
   2301      1.1     skrll 
   2302      1.1     skrll 		  if (fc > MAX_INSN_FIXUPS)
   2303      1.1     skrll 		    as_fatal (_("too many fixups"));
   2304      1.1     skrll 
   2305      1.1     skrll 		  fixups[fc].exp     = ex;
   2306      1.1     skrll 		  fixups[fc].opindex = *opindex_ptr;
   2307      1.1     skrll 		  fixups[fc].reloc   = reloc;
   2308  1.1.1.2  christos 		  fc++;
   2309  1.1.1.2  christos 		}
   2310  1.1.1.2  christos 	    }
   2311  1.1.1.2  christos 	  else if (operand->flags & V850E_IMMEDIATE16
   2312  1.1.1.2  christos 		   || operand->flags & V850E_IMMEDIATE16HI)
   2313  1.1.1.2  christos 	    {
   2314  1.1.1.2  christos 	      expression (&ex);
   2315  1.1.1.2  christos 
   2316  1.1.1.2  christos 	      switch (ex.X_op)
   2317  1.1.1.2  christos 		{
   2318  1.1.1.2  christos 		case O_constant:
   2319  1.1.1.2  christos 		  if (operand->flags & V850E_IMMEDIATE16HI)
   2320  1.1.1.2  christos 		    {
   2321  1.1.1.2  christos 		      if (ex.X_add_number & 0xffff)
   2322  1.1.1.2  christos 			{
   2323  1.1.1.2  christos 			  errmsg = _("constant too big to fit into instruction");
   2324  1.1.1.2  christos 			  goto error;
   2325  1.1.1.2  christos 			}
   2326  1.1.1.2  christos 
   2327  1.1.1.2  christos 		      ex.X_add_number >>= 16;
   2328  1.1.1.2  christos 		    }
   2329  1.1.1.2  christos 		  if (operand->flags & V850E_IMMEDIATE16)
   2330  1.1.1.2  christos 		    {
   2331  1.1.1.2  christos 		      if (ex.X_add_number & 0xffff0000)
   2332  1.1.1.2  christos 			{
   2333  1.1.1.2  christos 			  errmsg = _("constant too big to fit into instruction");
   2334  1.1.1.2  christos 			  goto error;
   2335  1.1.1.2  christos 			}
   2336  1.1.1.2  christos 		    }
   2337  1.1.1.2  christos 		  break;
   2338  1.1.1.2  christos 
   2339  1.1.1.2  christos 		case O_illegal:
   2340  1.1.1.2  christos 		  errmsg = _("illegal operand");
   2341  1.1.1.2  christos 		  goto error;
   2342  1.1.1.2  christos 
   2343  1.1.1.2  christos 		case O_absent:
   2344  1.1.1.2  christos 		  errmsg = _("missing operand");
   2345  1.1.1.2  christos 		  goto error;
   2346  1.1.1.2  christos 
   2347  1.1.1.2  christos 		default:
   2348  1.1.1.2  christos 		  if (fc >= MAX_INSN_FIXUPS)
   2349  1.1.1.2  christos 		    as_fatal (_("too many fixups"));
   2350  1.1.1.2  christos 
   2351  1.1.1.2  christos 		  fixups[fc].exp     = ex;
   2352  1.1.1.2  christos 		  fixups[fc].opindex = *opindex_ptr;
   2353  1.1.1.2  christos 		  fixups[fc].reloc   = operand->default_reloc;
   2354  1.1.1.2  christos 		  ++fc;
   2355  1.1.1.2  christos 
   2356  1.1.1.2  christos 		  ex.X_add_number = 0;
   2357  1.1.1.2  christos 		  break;
   2358  1.1.1.2  christos 		}
   2359  1.1.1.2  christos 
   2360  1.1.1.2  christos 	      extra_data_after_insn = TRUE;
   2361  1.1.1.2  christos 	      extra_data_len        = 2;
   2362  1.1.1.2  christos 	      extra_data            = ex.X_add_number;
   2363  1.1.1.2  christos 	    }
   2364  1.1.1.2  christos 	  else if (operand->flags & V850E_IMMEDIATE23)
   2365  1.1.1.2  christos 	    {
   2366  1.1.1.2  christos 	      expression (&ex);
   2367  1.1.1.2  christos 
   2368  1.1.1.2  christos 	      switch (ex.X_op)
   2369  1.1.1.2  christos 		{
   2370  1.1.1.2  christos 		case O_constant:
   2371  1.1.1.2  christos 		  break;
   2372  1.1.1.2  christos 
   2373  1.1.1.2  christos 		case O_illegal:
   2374  1.1.1.2  christos 		  errmsg = _("illegal operand");
   2375  1.1.1.2  christos 		  goto error;
   2376  1.1.1.2  christos 
   2377  1.1.1.2  christos 		case O_absent:
   2378  1.1.1.2  christos 		  errmsg = _("missing operand");
   2379  1.1.1.2  christos 		  goto error;
   2380  1.1.1.2  christos 
   2381  1.1.1.2  christos 		default:
   2382  1.1.1.2  christos 		  break;
   2383  1.1.1.2  christos 		}
   2384  1.1.1.2  christos 
   2385  1.1.1.2  christos 	      if (fc >= MAX_INSN_FIXUPS)
   2386  1.1.1.2  christos 		as_fatal (_("too many fixups"));
   2387  1.1.1.2  christos 
   2388  1.1.1.2  christos 	      fixups[fc].exp     = ex;
   2389  1.1.1.2  christos 	      fixups[fc].opindex = *opindex_ptr;
   2390  1.1.1.2  christos 	      fixups[fc].reloc   = operand->default_reloc;
   2391  1.1.1.2  christos 	      ++fc;
   2392  1.1.1.2  christos 
   2393  1.1.1.2  christos 	      extra_data_after_insn = TRUE;
   2394  1.1.1.2  christos 	      extra_data_len        = 2;
   2395  1.1.1.2  christos 	      extra_data            = 0;
   2396  1.1.1.2  christos 	    }
   2397  1.1.1.2  christos 	  else if (operand->flags & V850E_IMMEDIATE32)
   2398  1.1.1.2  christos 	    {
   2399  1.1.1.2  christos 	      expression (&ex);
   2400  1.1.1.2  christos 
   2401  1.1.1.2  christos 	      switch (ex.X_op)
   2402  1.1.1.2  christos 		{
   2403  1.1.1.2  christos 		case O_constant:
   2404  1.1.1.2  christos 		  if ((operand->default_reloc == BFD_RELOC_V850_32_ABS
   2405  1.1.1.2  christos 		       || operand->default_reloc == BFD_RELOC_V850_32_PCREL)
   2406  1.1.1.2  christos 		      && (ex.X_add_number & 1))
   2407  1.1.1.2  christos 		    {
   2408  1.1.1.2  christos 		      errmsg = _("odd number cannot be used here");
   2409  1.1.1.2  christos 		      goto error;
   2410  1.1.1.2  christos 		    }
   2411  1.1.1.2  christos 		  break;
   2412  1.1.1.2  christos 
   2413  1.1.1.2  christos 		case O_illegal:
   2414  1.1.1.2  christos 		  errmsg = _("illegal operand");
   2415  1.1.1.2  christos 		  goto error;
   2416  1.1.1.2  christos 
   2417  1.1.1.2  christos 		case O_absent:
   2418  1.1.1.2  christos 		  errmsg = _("missing operand");
   2419  1.1.1.2  christos 		  goto error;
   2420  1.1.1.2  christos 
   2421  1.1.1.2  christos 		default:
   2422  1.1.1.2  christos 		  if (fc >= MAX_INSN_FIXUPS)
   2423  1.1.1.2  christos 		    as_fatal (_("too many fixups"));
   2424  1.1.1.2  christos 
   2425  1.1.1.2  christos 		  fixups[fc].exp     = ex;
   2426  1.1.1.2  christos 		  fixups[fc].opindex = *opindex_ptr;
   2427  1.1.1.2  christos 		  fixups[fc].reloc   = operand->default_reloc;
   2428  1.1.1.2  christos 		  ++fc;
   2429  1.1.1.2  christos 
   2430  1.1.1.2  christos 		  ex.X_add_number = 0;
   2431  1.1.1.2  christos 		  break;
   2432  1.1.1.2  christos 		}
   2433  1.1.1.2  christos 
   2434  1.1.1.2  christos 	      extra_data_after_insn = TRUE;
   2435  1.1.1.2  christos 	      extra_data_len        = 4;
   2436  1.1.1.2  christos 	      extra_data            = ex.X_add_number;
   2437  1.1.1.2  christos 	    }
   2438  1.1.1.2  christos 	  else if (operand->flags & V850E_OPERAND_REG_LIST)
   2439  1.1.1.2  christos 	    {
   2440  1.1.1.2  christos 	      errmsg = parse_register_list (&insn, operand);
   2441  1.1.1.2  christos 
   2442      1.1     skrll 	      if (errmsg)
   2443      1.1     skrll 		goto error;
   2444      1.1     skrll 	    }
   2445      1.1     skrll 	  else
   2446      1.1     skrll 	    {
   2447      1.1     skrll 	      errmsg = NULL;
   2448      1.1     skrll 
   2449  1.1.1.2  christos 	      if ((operand->flags & V850_OPERAND_REG) != 0)
   2450  1.1.1.2  christos 		{
   2451  1.1.1.2  christos 		  if (!register_name (&ex))
   2452  1.1.1.2  christos 		    {
   2453  1.1.1.2  christos 		      errmsg = _("invalid register name");
   2454      1.1     skrll 		    }
   2455      1.1     skrll 
   2456      1.1     skrll 		  if ((operand->flags & V850_NOT_R0)
   2457  1.1.1.2  christos 			   && ex.X_add_number == 0)
   2458      1.1     skrll 		    {
   2459  1.1.1.2  christos 		      errmsg = _("register r0 cannot be used here");
   2460  1.1.1.2  christos 		    }
   2461  1.1.1.2  christos 
   2462  1.1.1.2  christos 		  if (operand->flags & V850_REG_EVEN)
   2463  1.1.1.2  christos 		    {
   2464      1.1     skrll 		      if (ex.X_add_number % 2)
   2465  1.1.1.2  christos 			errmsg = _("odd register cannot be used here");
   2466      1.1     skrll 		      ex.X_add_number = ex.X_add_number / 2;
   2467      1.1     skrll 		    }
   2468      1.1     skrll 
   2469  1.1.1.2  christos 		}
   2470  1.1.1.2  christos 	      else if ((operand->flags & V850_OPERAND_SRG) != 0)
   2471  1.1.1.2  christos 		{
   2472  1.1.1.2  christos 		  if (!system_register_name (&ex, TRUE))
   2473      1.1     skrll 		    {
   2474      1.1     skrll 		      errmsg = _("invalid system register name");
   2475      1.1     skrll 		    }
   2476      1.1     skrll 		}
   2477      1.1     skrll 	      else if ((operand->flags & V850_OPERAND_EP) != 0)
   2478      1.1     skrll 		{
   2479      1.1     skrll 		  char *start = input_line_pointer;
   2480      1.1     skrll 		  char c = get_symbol_end ();
   2481      1.1     skrll 
   2482      1.1     skrll 		  if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
   2483      1.1     skrll 		    {
   2484      1.1     skrll 		      /* Put things back the way we found them.  */
   2485      1.1     skrll 		      *input_line_pointer = c;
   2486      1.1     skrll 		      input_line_pointer = start;
   2487      1.1     skrll 		      errmsg = _("expected EP register");
   2488      1.1     skrll 		      goto error;
   2489      1.1     skrll 		    }
   2490      1.1     skrll 
   2491      1.1     skrll 		  *input_line_pointer = c;
   2492      1.1     skrll 		  str = input_line_pointer;
   2493      1.1     skrll 		  input_line_pointer = hold;
   2494      1.1     skrll 
   2495      1.1     skrll 		  while (*str == ' ' || *str == ','
   2496      1.1     skrll 			 || *str == '[' || *str == ']')
   2497      1.1     skrll 		    ++str;
   2498      1.1     skrll 		  continue;
   2499  1.1.1.2  christos 		}
   2500      1.1     skrll 	      else if ((operand->flags & V850_OPERAND_CC) != 0)
   2501  1.1.1.2  christos 		{
   2502      1.1     skrll 		  if (!cc_name (&ex, TRUE))
   2503      1.1     skrll 		    {
   2504  1.1.1.2  christos 		      errmsg = _("invalid condition code name");
   2505  1.1.1.2  christos 		    }
   2506  1.1.1.2  christos 
   2507  1.1.1.2  christos 		  if ((operand->flags & V850_NOT_SA)
   2508  1.1.1.2  christos 		      && ex.X_add_number == COND_SA_NUM)
   2509      1.1     skrll 		    {
   2510  1.1.1.2  christos 		      errmsg = _("condition sa cannot be used here");
   2511      1.1     skrll 		    }
   2512  1.1.1.2  christos 		}
   2513  1.1.1.2  christos 	      else if ((operand->flags & V850_OPERAND_FLOAT_CC) != 0)
   2514  1.1.1.2  christos 		{
   2515  1.1.1.2  christos 		  if (!float_cc_name (&ex, TRUE))
   2516      1.1     skrll 		    {
   2517  1.1.1.2  christos 		      errmsg = _("invalid condition code name");
   2518  1.1.1.2  christos 		    }
   2519      1.1     skrll 		}
   2520      1.1     skrll 	      else if ((register_name (&ex)
   2521      1.1     skrll 			&& (operand->flags & V850_OPERAND_REG) == 0))
   2522      1.1     skrll 		{
   2523      1.1     skrll 		  char c;
   2524      1.1     skrll 		  int exists = 0;
   2525      1.1     skrll 
   2526      1.1     skrll 		  /* It is possible that an alias has been defined that
   2527      1.1     skrll 		     matches a register name.  For example the code may
   2528      1.1     skrll 		     include a ".set ZERO, 0" directive, which matches
   2529      1.1     skrll 		     the register name "zero".  Attempt to reparse the
   2530      1.1     skrll 		     field as an expression, and only complain if we
   2531      1.1     skrll 		     cannot generate a constant.  */
   2532      1.1     skrll 
   2533      1.1     skrll 		  input_line_pointer = str;
   2534      1.1     skrll 
   2535      1.1     skrll 		  c = get_symbol_end ();
   2536      1.1     skrll 
   2537      1.1     skrll 		  if (symbol_find (str) != NULL)
   2538      1.1     skrll 		    exists = 1;
   2539      1.1     skrll 
   2540      1.1     skrll 		  *input_line_pointer = c;
   2541      1.1     skrll 		  input_line_pointer = str;
   2542      1.1     skrll 
   2543      1.1     skrll 		  expression (&ex);
   2544      1.1     skrll 
   2545      1.1     skrll 		  if (ex.X_op != O_constant)
   2546      1.1     skrll 		    {
   2547      1.1     skrll 		      /* If this register is actually occurring too early on
   2548  1.1.1.2  christos 			 the parsing of the instruction, (because another
   2549  1.1.1.2  christos 			 field is missing) then report this.  */
   2550  1.1.1.2  christos 		      if (opindex_ptr[1] != 0
   2551  1.1.1.2  christos 			  && ((v850_operands[opindex_ptr[1]].flags
   2552      1.1     skrll 			       & V850_OPERAND_REG)
   2553      1.1     skrll 			      ||(v850_operands[opindex_ptr[1]].flags
   2554      1.1     skrll 				 & V850_OPERAND_VREG)))
   2555      1.1     skrll 			errmsg = _("syntax error: value is missing before the register name");
   2556      1.1     skrll 		      else
   2557      1.1     skrll 			errmsg = _("syntax error: register not expected");
   2558      1.1     skrll 
   2559      1.1     skrll 		      /* If we created a symbol in the process of this
   2560      1.1     skrll 			 test then delete it now, so that it will not
   2561      1.1     skrll 			 be output with the real symbols...  */
   2562      1.1     skrll 		      if (exists == 0
   2563      1.1     skrll 			  && ex.X_op == O_symbol)
   2564      1.1     skrll 			symbol_remove (ex.X_add_symbol,
   2565  1.1.1.2  christos 				       &symbol_rootP, &symbol_lastP);
   2566      1.1     skrll 		    }
   2567  1.1.1.2  christos 		}
   2568  1.1.1.2  christos 	      else if (system_register_name (&ex, FALSE)
   2569  1.1.1.2  christos 		       && (operand->flags & V850_OPERAND_SRG) == 0)
   2570  1.1.1.2  christos 		{
   2571      1.1     skrll 		  errmsg = _("syntax error: system register not expected");
   2572  1.1.1.2  christos 		}
   2573  1.1.1.2  christos 	      else if (cc_name (&ex, FALSE)
   2574  1.1.1.2  christos 		       && (operand->flags & V850_OPERAND_CC) == 0)
   2575  1.1.1.2  christos 		{
   2576  1.1.1.2  christos 		  errmsg = _("syntax error: condition code not expected");
   2577  1.1.1.2  christos 		}
   2578  1.1.1.2  christos 	      else if (float_cc_name (&ex, FALSE)
   2579  1.1.1.2  christos 		       && (operand->flags & V850_OPERAND_FLOAT_CC) == 0)
   2580      1.1     skrll 		{
   2581      1.1     skrll 		  errmsg = _("syntax error: condition code not expected");
   2582      1.1     skrll 		}
   2583  1.1.1.2  christos 	      else
   2584  1.1.1.2  christos 		{
   2585  1.1.1.2  christos 		  expression (&ex);
   2586  1.1.1.2  christos 
   2587  1.1.1.2  christos 		  if ((operand->flags & V850_NOT_IMM0)
   2588  1.1.1.2  christos 		      && ex.X_op == O_constant
   2589  1.1.1.2  christos 		      && ex.X_add_number == 0)
   2590  1.1.1.2  christos 		    {
   2591      1.1     skrll 		      errmsg = _("immediate 0 cannot be used here");
   2592  1.1.1.2  christos 		    }
   2593      1.1     skrll 
   2594  1.1.1.2  christos 		  /* Special case:
   2595      1.1     skrll 		     If we are assembling a MOV/JARL/JR instruction and the immediate
   2596      1.1     skrll 		     value does not fit into the bits available then create a
   2597  1.1.1.2  christos 		     fake error so that the next MOV/JARL/JR instruction will be
   2598  1.1.1.2  christos 		     selected.  This one has a 32 bit immediate field.  */
   2599  1.1.1.2  christos 
   2600      1.1     skrll 		  if ((strcmp (opcode->name, "mov") == 0
   2601      1.1     skrll 		       || strcmp (opcode->name, "jarl") == 0
   2602      1.1     skrll 		       || strcmp (opcode->name, "jr") == 0)
   2603  1.1.1.2  christos 		      && ex.X_op == O_constant
   2604  1.1.1.2  christos 		      && (ex.X_add_number < (-(1 << (operand->bits - 1)))
   2605  1.1.1.2  christos 			  || ex.X_add_number > ((1 << (operand->bits - 1)) - 1)))
   2606  1.1.1.2  christos 		    {
   2607  1.1.1.2  christos 		      errmsg = _("immediate operand is too large");
   2608  1.1.1.2  christos 		    }
   2609  1.1.1.2  christos 
   2610  1.1.1.2  christos 		  if ((strcmp (opcode->name, "jarl") == 0
   2611  1.1.1.2  christos 		       || strcmp (opcode->name, "jr") == 0)
   2612  1.1.1.2  christos 		      && ex.X_op != O_constant
   2613  1.1.1.2  christos 		      && operand->bits != default_disp_size)
   2614      1.1     skrll 		    {
   2615      1.1     skrll 		      errmsg = _("immediate operand is not match");
   2616      1.1     skrll 		    }
   2617      1.1     skrll 		}
   2618      1.1     skrll 
   2619      1.1     skrll 	      if (errmsg)
   2620      1.1     skrll 		goto error;
   2621      1.1     skrll 
   2622      1.1     skrll 	      switch (ex.X_op)
   2623      1.1     skrll 		{
   2624      1.1     skrll 		case O_illegal:
   2625      1.1     skrll 		  errmsg = _("illegal operand");
   2626      1.1     skrll 		  goto error;
   2627      1.1     skrll 		case O_absent:
   2628      1.1     skrll 		  errmsg = _("missing operand");
   2629  1.1.1.2  christos 		  goto error;
   2630      1.1     skrll 		case O_register:
   2631      1.1     skrll 		  if ((operand->flags
   2632      1.1     skrll 		       & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_VREG)) == 0)
   2633      1.1     skrll 		    {
   2634  1.1.1.2  christos 		      errmsg = _("invalid operand");
   2635  1.1.1.2  christos 		      goto error;
   2636  1.1.1.2  christos 		    }
   2637  1.1.1.2  christos 
   2638  1.1.1.2  christos 		  insn = v850_insert_operand (insn, operand,
   2639      1.1     skrll 					      ex.X_add_number,
   2640      1.1     skrll 					      &warningmsg);
   2641      1.1     skrll 
   2642      1.1     skrll 		  break;
   2643  1.1.1.2  christos 
   2644      1.1     skrll 		case O_constant:
   2645      1.1     skrll 		  insn = v850_insert_operand (insn, operand, ex.X_add_number,
   2646      1.1     skrll 					      &warningmsg);
   2647      1.1     skrll 		  break;
   2648      1.1     skrll 
   2649      1.1     skrll 		default:
   2650      1.1     skrll 		  /* We need to generate a fixup for this expression.  */
   2651      1.1     skrll 		  if (fc >= MAX_INSN_FIXUPS)
   2652      1.1     skrll 		    as_fatal (_("too many fixups"));
   2653      1.1     skrll 
   2654      1.1     skrll 		  fixups[fc].exp     = ex;
   2655      1.1     skrll 		  fixups[fc].opindex = *opindex_ptr;
   2656      1.1     skrll 		  fixups[fc].reloc   = BFD_RELOC_UNUSED;
   2657      1.1     skrll 		  ++fc;
   2658      1.1     skrll 		  break;
   2659      1.1     skrll 		}
   2660      1.1     skrll 	    }
   2661      1.1     skrll 
   2662      1.1     skrll 	  str = input_line_pointer;
   2663      1.1     skrll 	  input_line_pointer = hold;
   2664      1.1     skrll 
   2665      1.1     skrll 	  while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
   2666  1.1.1.2  christos 		 || *str == ')')
   2667  1.1.1.2  christos 	    ++str;
   2668  1.1.1.2  christos 	}
   2669  1.1.1.2  christos 
   2670  1.1.1.2  christos       while (ISSPACE (*str))
   2671  1.1.1.2  christos 	++str;
   2672      1.1     skrll 
   2673      1.1     skrll       if (*str == '\0')
   2674      1.1     skrll 	match = 1;
   2675      1.1     skrll 
   2676  1.1.1.2  christos     error:
   2677  1.1.1.2  christos       if (match == 0)
   2678  1.1.1.2  christos 	{
   2679  1.1.1.2  christos 	  if ((opindex_ptr - opcode->operands) >= most_match_count)
   2680  1.1.1.2  christos 	    {
   2681  1.1.1.2  christos 	      most_match_count = opindex_ptr - opcode->operands;
   2682  1.1.1.2  christos 	      if (errmsg != NULL)
   2683      1.1     skrll 		strncpy (most_match_errmsg, errmsg, sizeof (most_match_errmsg)-1);
   2684      1.1     skrll 	    }
   2685      1.1     skrll 
   2686      1.1     skrll 	  next_opcode = opcode + 1;
   2687      1.1     skrll 	  if (next_opcode->name != NULL
   2688      1.1     skrll 	      && strcmp (next_opcode->name, opcode->name) == 0)
   2689      1.1     skrll 	    {
   2690      1.1     skrll 	      opcode = next_opcode;
   2691      1.1     skrll 
   2692      1.1     skrll 	      /* Skip versions that are not supported by the target
   2693      1.1     skrll 		 processor.  */
   2694      1.1     skrll 	      if ((opcode->processors & processor_mask) == 0)
   2695      1.1     skrll 		goto error;
   2696      1.1     skrll 
   2697  1.1.1.2  christos 	      continue;
   2698  1.1.1.2  christos 	    }
   2699  1.1.1.2  christos 
   2700  1.1.1.2  christos 	  if (most_match_errmsg[0] == 0)
   2701  1.1.1.2  christos 	    /* xgettext:c-format.  */
   2702      1.1     skrll 	    as_bad (_("junk at end of line: `%s'"), str);
   2703      1.1     skrll 	  else
   2704      1.1     skrll 	    as_bad ("%s: %s", copy_of_instruction, most_match_errmsg);
   2705      1.1     skrll 
   2706      1.1     skrll 	  if (*input_line_pointer == ']')
   2707      1.1     skrll 	    ++input_line_pointer;
   2708      1.1     skrll 
   2709      1.1     skrll 	  ignore_rest_of_line ();
   2710  1.1.1.2  christos 	  input_line_pointer = saved_input_line_pointer;
   2711  1.1.1.2  christos 	  return;
   2712  1.1.1.2  christos 	}
   2713      1.1     skrll 
   2714      1.1     skrll       if (warningmsg != NULL)
   2715      1.1     skrll 	as_warn ("%s", warningmsg);
   2716      1.1     skrll       break;
   2717      1.1     skrll     }
   2718      1.1     skrll 
   2719      1.1     skrll   input_line_pointer = str;
   2720      1.1     skrll 
   2721      1.1     skrll   /* Tie dwarf2 debug info to the address at the start of the insn.
   2722      1.1     skrll      We can't do this after the insn has been output as the current
   2723      1.1     skrll      frag may have been closed off.  eg. by frag_var.  */
   2724      1.1     skrll   dwarf2_emit_insn (0);
   2725      1.1     skrll 
   2726      1.1     skrll   /* Write out the instruction.  */
   2727      1.1     skrll 
   2728      1.1     skrll   if (relaxable && fc > 0)
   2729      1.1     skrll     {
   2730  1.1.1.2  christos       insn_size = 2;
   2731  1.1.1.2  christos       fc = 0;
   2732      1.1     skrll 
   2733  1.1.1.2  christos       if (strcmp (opcode->name, "br") == 0
   2734  1.1.1.2  christos 	  || strcmp (opcode->name, "jbr") == 0)
   2735  1.1.1.2  christos 	{
   2736  1.1.1.2  christos 	  if ((processor_mask & PROCESSOR_V850E2_ALL) == 0 || default_disp_size == 22)
   2737  1.1.1.2  christos 	    {
   2738  1.1.1.2  christos 	      f = frag_var (rs_machine_dependent, 4, 2, SUBYPTE_UNCOND_9_22,
   2739  1.1.1.2  christos 			    fixups[0].exp.X_add_symbol,
   2740  1.1.1.2  christos 			    fixups[0].exp.X_add_number,
   2741  1.1.1.2  christos 			    (char *)(size_t) fixups[0].opindex);
   2742  1.1.1.2  christos 	      md_number_to_chars (f, insn, insn_size);
   2743  1.1.1.2  christos 	      md_number_to_chars (f + 2, 0, 2);
   2744  1.1.1.2  christos 	    }
   2745  1.1.1.2  christos 	  else
   2746  1.1.1.2  christos 	    {
   2747  1.1.1.2  christos 	      f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_UNCOND_9_22_32,
   2748  1.1.1.2  christos 			    fixups[0].exp.X_add_symbol,
   2749  1.1.1.2  christos 			    fixups[0].exp.X_add_number,
   2750  1.1.1.2  christos 			    (char *)(size_t) fixups[0].opindex);
   2751      1.1     skrll 	      md_number_to_chars (f, insn, insn_size);
   2752  1.1.1.2  christos 	      md_number_to_chars (f + 2, 0, 4);
   2753      1.1     skrll 	    }
   2754  1.1.1.2  christos 	}
   2755  1.1.1.2  christos       else /* b<cond>, j<cond>.  */
   2756  1.1.1.2  christos 	{
   2757  1.1.1.2  christos 	  if (default_disp_size == 22
   2758  1.1.1.2  christos 	      || (processor_mask & PROCESSOR_V850E2_ALL) == 0)
   2759  1.1.1.2  christos 	    {
   2760  1.1.1.2  christos 	      if (processor_mask & PROCESSOR_V850E2V3 && !no_bcond17)
   2761  1.1.1.2  christos 		{
   2762  1.1.1.2  christos 		  if (strcmp (opcode->name, "bsa") == 0)
   2763  1.1.1.2  christos 		    {
   2764  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_SA_9_17_22,
   2765  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2766  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2767  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2768  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2769  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 6);
   2770  1.1.1.2  christos 		    }
   2771  1.1.1.2  christos 		  else
   2772  1.1.1.2  christos 		    {
   2773  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_COND_9_17_22,
   2774  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2775  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2776  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2777  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2778  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 4);
   2779  1.1.1.2  christos 		    }
   2780  1.1.1.2  christos 		}
   2781  1.1.1.2  christos 	      else
   2782  1.1.1.2  christos 		{
   2783  1.1.1.2  christos 		  if (strcmp (opcode->name, "bsa") == 0)
   2784  1.1.1.2  christos 		    {
   2785  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_SA_9_22,
   2786  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2787  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2788  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2789  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2790  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 6);
   2791  1.1.1.2  christos 		    }
   2792  1.1.1.2  christos 		  else
   2793  1.1.1.2  christos 		    {
   2794  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 6, 4, SUBYPTE_COND_9_22,
   2795  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2796  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2797  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2798  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2799  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 4);
   2800  1.1.1.2  christos 		    }
   2801  1.1.1.2  christos 		}
   2802  1.1.1.2  christos 	    }
   2803  1.1.1.2  christos 	  else
   2804  1.1.1.2  christos 	    {
   2805  1.1.1.2  christos 	      if (processor_mask & PROCESSOR_V850E2V3 && !no_bcond17)
   2806  1.1.1.2  christos 		{
   2807  1.1.1.2  christos 		  if (strcmp (opcode->name, "bsa") == 0)
   2808  1.1.1.2  christos 		    {
   2809  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 10, 8, SUBYPTE_SA_9_17_22_32,
   2810  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2811  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2812  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2813  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2814  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 8);
   2815  1.1.1.2  christos 		    }
   2816  1.1.1.2  christos 		  else
   2817  1.1.1.2  christos 		    {
   2818  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_COND_9_17_22_32,
   2819  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2820  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2821  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2822  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2823  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 6);
   2824  1.1.1.2  christos 		    }
   2825  1.1.1.2  christos 		}
   2826  1.1.1.2  christos 	      else
   2827  1.1.1.2  christos 		{
   2828  1.1.1.2  christos 		  if (strcmp (opcode->name, "bsa") == 0)
   2829  1.1.1.2  christos 		    {
   2830  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 10, 8, SUBYPTE_SA_9_22_32,
   2831  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2832  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2833  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2834  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2835  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 8);
   2836  1.1.1.2  christos 		    }
   2837  1.1.1.2  christos 		  else
   2838  1.1.1.2  christos 		    {
   2839  1.1.1.2  christos 		      f = frag_var (rs_machine_dependent, 8, 6, SUBYPTE_COND_9_22_32,
   2840  1.1.1.2  christos 				    fixups[0].exp.X_add_symbol,
   2841  1.1.1.2  christos 				    fixups[0].exp.X_add_number,
   2842  1.1.1.2  christos 				    (char *)(size_t) fixups[0].opindex);
   2843  1.1.1.2  christos 		      md_number_to_chars (f, insn, insn_size);
   2844  1.1.1.2  christos 		      md_number_to_chars (f + 2, 0, 6);
   2845      1.1     skrll 		    }
   2846      1.1     skrll 		}
   2847      1.1     skrll 	    }
   2848      1.1     skrll 	}
   2849      1.1     skrll     }
   2850      1.1     skrll   else
   2851      1.1     skrll     {
   2852      1.1     skrll       /* Four byte insns have an opcode with the two high bits on.  */
   2853      1.1     skrll       if ((insn & 0x0600) == 0x0600)
   2854      1.1     skrll 	insn_size = 4;
   2855      1.1     skrll       else
   2856      1.1     skrll 	insn_size = 2;
   2857      1.1     skrll 
   2858      1.1     skrll       /* Special case: 32 bit MOV.  */
   2859  1.1.1.2  christos       if ((insn & 0xffe0) == 0x0620)
   2860  1.1.1.2  christos 	insn_size = 2;
   2861  1.1.1.2  christos 
   2862  1.1.1.2  christos       /* Special case: 32 bit JARL,JMP,JR.  */
   2863  1.1.1.2  christos       if ((insn & 0x1ffe0) == 0x2e0	/* JARL.  */
   2864  1.1.1.2  christos 	  || (insn & 0x1ffe0) == 0x6e0	/* JMP.  */
   2865      1.1     skrll 	  || (insn & 0x1ffff) == 0x2e0)	/* JR.  */
   2866      1.1     skrll 	insn_size = 2;
   2867      1.1     skrll 
   2868      1.1     skrll       f = frag_more (insn_size);
   2869      1.1     skrll       md_number_to_chars (f, insn, insn_size);
   2870      1.1     skrll 
   2871      1.1     skrll       if (extra_data_after_insn)
   2872      1.1     skrll 	{
   2873      1.1     skrll 	  f = frag_more (extra_data_len);
   2874      1.1     skrll 	  md_number_to_chars (f, extra_data, extra_data_len);
   2875      1.1     skrll 
   2876      1.1     skrll 	  extra_data_after_insn = FALSE;
   2877      1.1     skrll 	}
   2878      1.1     skrll     }
   2879      1.1     skrll 
   2880      1.1     skrll   /* Create any fixups.  At this point we do not use a
   2881      1.1     skrll      bfd_reloc_code_real_type, but instead just use the
   2882      1.1     skrll      BFD_RELOC_UNUSED plus the operand index.  This lets us easily
   2883      1.1     skrll      handle fixups for any operand type, although that is admittedly
   2884      1.1     skrll      not a very exciting feature.  We pick a BFD reloc type in
   2885      1.1     skrll      md_apply_fix.  */
   2886      1.1     skrll   for (i = 0; i < fc; i++)
   2887      1.1     skrll     {
   2888      1.1     skrll       const struct v850_operand *operand;
   2889      1.1     skrll       bfd_reloc_code_real_type reloc;
   2890      1.1     skrll 
   2891      1.1     skrll       operand = &v850_operands[fixups[i].opindex];
   2892      1.1     skrll 
   2893      1.1     skrll       reloc = fixups[i].reloc;
   2894      1.1     skrll 
   2895      1.1     skrll       if (reloc != BFD_RELOC_UNUSED)
   2896      1.1     skrll 	{
   2897      1.1     skrll 	  reloc_howto_type *reloc_howto =
   2898      1.1     skrll 	    bfd_reloc_type_lookup (stdoutput, reloc);
   2899      1.1     skrll 	  int size;
   2900      1.1     skrll 	  int address;
   2901      1.1     skrll 	  fixS *fixP;
   2902      1.1     skrll 
   2903      1.1     skrll 	  if (!reloc_howto)
   2904      1.1     skrll 	    abort ();
   2905      1.1     skrll 
   2906      1.1     skrll 	  size = bfd_get_reloc_size (reloc_howto);
   2907      1.1     skrll 
   2908      1.1     skrll 	  /* XXX This will abort on an R_V850_8 reloc -
   2909      1.1     skrll 	     is this reloc actually used?  */
   2910  1.1.1.2  christos 	  if (size != 2 && size != 4)
   2911  1.1.1.2  christos 	    abort ();
   2912  1.1.1.2  christos 
   2913  1.1.1.2  christos 	  if (extra_data_len == 0)
   2914  1.1.1.2  christos 	    {
   2915  1.1.1.2  christos 	      address = (f - frag_now->fr_literal) + insn_size - size;
   2916  1.1.1.2  christos 	    }
   2917  1.1.1.2  christos 	  else
   2918      1.1     skrll 	    {
   2919  1.1.1.2  christos 	      address = (f - frag_now->fr_literal) + extra_data_len - size;
   2920  1.1.1.2  christos 	    }
   2921  1.1.1.2  christos 
   2922  1.1.1.2  christos 	  if ((operand->flags & V850E_IMMEDIATE32) && (operand->flags & V850_PCREL))
   2923  1.1.1.2  christos 	    {
   2924  1.1.1.2  christos 	      fixups[i].exp.X_add_number += 2;
   2925  1.1.1.2  christos 	    }
   2926  1.1.1.2  christos 	  else if (operand->default_reloc ==  BFD_RELOC_V850_16_PCREL)
   2927  1.1.1.2  christos 	    {
   2928      1.1     skrll 	      fixups[i].exp.X_add_number += 2;
   2929  1.1.1.2  christos 	      address += 2;
   2930      1.1     skrll 	    }
   2931      1.1     skrll 
   2932      1.1     skrll 	  /* fprintf (stderr, "0x%x %d %ld\n", address, size, fixups[i].exp.X_add_number);  */
   2933      1.1     skrll 	  fixP = fix_new_exp (frag_now, address, size,
   2934      1.1     skrll 			      &fixups[i].exp,
   2935      1.1     skrll 			      reloc_howto->pc_relative,
   2936      1.1     skrll 			      reloc);
   2937      1.1     skrll 
   2938      1.1     skrll 	  fixP->tc_fix_data = (void *) operand;
   2939      1.1     skrll 
   2940  1.1.1.2  christos 	  switch (reloc)
   2941      1.1     skrll 	    {
   2942      1.1     skrll 	    case BFD_RELOC_LO16:
   2943      1.1     skrll 	    case BFD_RELOC_V850_LO16_S1:
   2944      1.1     skrll 	    case BFD_RELOC_V850_LO16_SPLIT_OFFSET:
   2945      1.1     skrll 	    case BFD_RELOC_HI16:
   2946      1.1     skrll 	    case BFD_RELOC_HI16_S:
   2947      1.1     skrll 	      fixP->fx_no_overflow = 1;
   2948      1.1     skrll 	      break;
   2949      1.1     skrll 	    default:
   2950      1.1     skrll 	      break;
   2951      1.1     skrll 	    }
   2952      1.1     skrll 	}
   2953      1.1     skrll       else
   2954      1.1     skrll 	{
   2955  1.1.1.2  christos 	  fix_new_exp (frag_now,
   2956      1.1     skrll 		       f - frag_now->fr_literal, 4,
   2957      1.1     skrll 		       & fixups[i].exp,
   2958      1.1     skrll 		       (operand->flags & V850_PCREL) != 0,
   2959      1.1     skrll 		       (bfd_reloc_code_real_type) (fixups[i].opindex
   2960      1.1     skrll 						   + (int) BFD_RELOC_UNUSED));
   2961      1.1     skrll 	}
   2962      1.1     skrll     }
   2963      1.1     skrll 
   2964      1.1     skrll   input_line_pointer = saved_input_line_pointer;
   2965      1.1     skrll }
   2966      1.1     skrll 
   2967      1.1     skrll /* If while processing a fixup, a reloc really needs to be created
   2968      1.1     skrll    then it is done here.  */
   2969      1.1     skrll 
   2970      1.1     skrll arelent *
   2971      1.1     skrll tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
   2972      1.1     skrll {
   2973      1.1     skrll   arelent *reloc;
   2974      1.1     skrll 
   2975      1.1     skrll   reloc		      = xmalloc (sizeof (arelent));
   2976      1.1     skrll   reloc->sym_ptr_ptr  = xmalloc (sizeof (asymbol *));
   2977      1.1     skrll   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   2978      1.1     skrll   reloc->address      = fixp->fx_frag->fr_address + fixp->fx_where;
   2979      1.1     skrll 
   2980      1.1     skrll   if (   fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
   2981      1.1     skrll       || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   2982      1.1     skrll       || fixp->fx_r_type == BFD_RELOC_V850_LONGCALL
   2983      1.1     skrll       || fixp->fx_r_type == BFD_RELOC_V850_LONGJUMP
   2984      1.1     skrll       || fixp->fx_r_type == BFD_RELOC_V850_ALIGN)
   2985  1.1.1.2  christos     reloc->addend = fixp->fx_offset;
   2986      1.1     skrll   else
   2987      1.1     skrll     {
   2988      1.1     skrll #if 0
   2989  1.1.1.2  christos       if (fixp->fx_r_type == BFD_RELOC_32
   2990      1.1     skrll 	  && fixp->fx_pcrel)
   2991      1.1     skrll 	fixp->fx_r_type = BFD_RELOC_32_PCREL;
   2992      1.1     skrll #endif
   2993      1.1     skrll 
   2994      1.1     skrll       reloc->addend = fixp->fx_addnumber;
   2995      1.1     skrll     }
   2996      1.1     skrll 
   2997      1.1     skrll   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
   2998      1.1     skrll 
   2999      1.1     skrll   if (reloc->howto == NULL)
   3000      1.1     skrll     {
   3001      1.1     skrll       as_bad_where (fixp->fx_file, fixp->fx_line,
   3002      1.1     skrll 		    /* xgettext:c-format  */
   3003      1.1     skrll 		    _("reloc %d not supported by object file format"),
   3004      1.1     skrll 		    (int) fixp->fx_r_type);
   3005      1.1     skrll 
   3006      1.1     skrll       xfree (reloc);
   3007      1.1     skrll 
   3008      1.1     skrll       return NULL;
   3009      1.1     skrll     }
   3010      1.1     skrll 
   3011      1.1     skrll   return reloc;
   3012      1.1     skrll }
   3013      1.1     skrll 
   3014      1.1     skrll void
   3015      1.1     skrll v850_handle_align (fragS * frag)
   3016      1.1     skrll {
   3017      1.1     skrll   if (v850_relax
   3018      1.1     skrll       && frag->fr_type == rs_align
   3019      1.1     skrll       && frag->fr_address + frag->fr_fix > 0
   3020      1.1     skrll       && frag->fr_offset > 1
   3021      1.1     skrll       && now_seg != bss_section
   3022      1.1     skrll       && now_seg != v850_seg_table[SBSS_SECTION].s
   3023      1.1     skrll       && now_seg != v850_seg_table[TBSS_SECTION].s
   3024      1.1     skrll       && now_seg != v850_seg_table[ZBSS_SECTION].s)
   3025      1.1     skrll     fix_new (frag, frag->fr_fix, 2, & abs_symbol, frag->fr_offset, 0,
   3026      1.1     skrll 	     BFD_RELOC_V850_ALIGN);
   3027      1.1     skrll }
   3028      1.1     skrll 
   3029      1.1     skrll /* Return current size of variable part of frag.  */
   3030      1.1     skrll 
   3031      1.1     skrll int
   3032      1.1     skrll md_estimate_size_before_relax (fragS *fragp, asection *seg ATTRIBUTE_UNUSED)
   3033      1.1     skrll {
   3034      1.1     skrll   if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
   3035      1.1     skrll     abort ();
   3036      1.1     skrll 
   3037      1.1     skrll   return md_relax_table[fragp->fr_subtype].rlx_length;
   3038      1.1     skrll }
   3039      1.1     skrll 
   3040      1.1     skrll long
   3041      1.1     skrll v850_pcrel_from_section (fixS *fixp, segT section)
   3042      1.1     skrll {
   3043      1.1     skrll   /* If the symbol is undefined, or in a section other than our own,
   3044      1.1     skrll      or it is weak (in which case it may well be in another section,
   3045      1.1     skrll      then let the linker figure it out.  */
   3046      1.1     skrll   if (fixp->fx_addsy != (symbolS *) NULL
   3047      1.1     skrll       && (! S_IS_DEFINED (fixp->fx_addsy)
   3048      1.1     skrll 	  || S_IS_WEAK (fixp->fx_addsy)
   3049      1.1     skrll 	  || (S_GET_SEGMENT (fixp->fx_addsy) != section)))
   3050      1.1     skrll     return 0;
   3051      1.1     skrll 
   3052      1.1     skrll   return fixp->fx_frag->fr_address + fixp->fx_where;
   3053      1.1     skrll }
   3054      1.1     skrll 
   3055      1.1     skrll void
   3056      1.1     skrll md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
   3057      1.1     skrll {
   3058      1.1     skrll   valueT value = * valueP;
   3059      1.1     skrll   char *where;
   3060      1.1     skrll 
   3061      1.1     skrll   if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   3062      1.1     skrll       || fixP->fx_r_type == BFD_RELOC_V850_LONGCALL
   3063      1.1     skrll       || fixP->fx_r_type == BFD_RELOC_V850_LONGJUMP
   3064      1.1     skrll       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
   3065      1.1     skrll     {
   3066      1.1     skrll       fixP->fx_done = 0;
   3067      1.1     skrll       return;
   3068      1.1     skrll     }
   3069      1.1     skrll 
   3070      1.1     skrll   if (fixP->fx_addsy == (symbolS *) NULL)
   3071      1.1     skrll     fixP->fx_addnumber = value,
   3072      1.1     skrll     fixP->fx_done = 1;
   3073      1.1     skrll 
   3074      1.1     skrll   else if (fixP->fx_pcrel)
   3075      1.1     skrll     fixP->fx_addnumber = fixP->fx_offset;
   3076      1.1     skrll 
   3077      1.1     skrll   else
   3078      1.1     skrll     {
   3079      1.1     skrll       value = fixP->fx_offset;
   3080      1.1     skrll       if (fixP->fx_subsy != (symbolS *) NULL)
   3081      1.1     skrll 	{
   3082      1.1     skrll 	  if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
   3083      1.1     skrll 	    value -= S_GET_VALUE (fixP->fx_subsy);
   3084      1.1     skrll 	  else
   3085      1.1     skrll 	    /* We don't actually support subtracting a symbol.  */
   3086      1.1     skrll 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3087      1.1     skrll 			  _("expression too complex"));
   3088      1.1     skrll 	}
   3089      1.1     skrll       fixP->fx_addnumber = value;
   3090      1.1     skrll     }
   3091      1.1     skrll 
   3092      1.1     skrll   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
   3093      1.1     skrll     {
   3094  1.1.1.2  christos       int opindex;
   3095      1.1     skrll       const struct v850_operand *operand;
   3096      1.1     skrll       unsigned long insn;
   3097      1.1     skrll       const char *errmsg = NULL;
   3098      1.1     skrll 
   3099      1.1     skrll       opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
   3100      1.1     skrll       operand = &v850_operands[opindex];
   3101      1.1     skrll 
   3102      1.1     skrll       /* Fetch the instruction, insert the fully resolved operand
   3103      1.1     skrll 	 value, and stuff the instruction back again.
   3104      1.1     skrll 
   3105      1.1     skrll 	 Note the instruction has been stored in little endian
   3106  1.1.1.2  christos 	 format!  */
   3107  1.1.1.2  christos       where = fixP->fx_frag->fr_literal + fixP->fx_where;
   3108  1.1.1.2  christos 
   3109  1.1.1.2  christos       if (fixP->fx_size > 2)
   3110  1.1.1.2  christos 	insn = bfd_getl32 ((unsigned char *) where);
   3111      1.1     skrll       else
   3112  1.1.1.2  christos 	insn = bfd_getl16 ((unsigned char *) where);
   3113  1.1.1.2  christos 
   3114  1.1.1.2  christos       insn = v850_insert_operand (insn, operand, (offsetT) value,
   3115  1.1.1.2  christos 				  &errmsg);
   3116  1.1.1.2  christos       if (errmsg)
   3117  1.1.1.2  christos 	as_warn_where (fixP->fx_file, fixP->fx_line, "%s", errmsg);
   3118  1.1.1.2  christos 
   3119  1.1.1.2  christos       if (fixP->fx_size > 2)
   3120      1.1     skrll 	bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
   3121      1.1     skrll       else
   3122      1.1     skrll 	bfd_putl16 ((bfd_vma) insn, (unsigned char *) where);
   3123      1.1     skrll 
   3124      1.1     skrll       if (fixP->fx_done)
   3125      1.1     skrll 	/* Nothing else to do here.  */
   3126      1.1     skrll 	return;
   3127      1.1     skrll 
   3128  1.1.1.2  christos       /* Determine a BFD reloc value based on the operand information.
   3129      1.1     skrll 	 We are only prepared to turn a few of the operands into relocs.  */
   3130      1.1     skrll 
   3131      1.1     skrll       if (operand->default_reloc == BFD_RELOC_NONE)
   3132      1.1     skrll 	{
   3133      1.1     skrll 	  as_bad_where (fixP->fx_file, fixP->fx_line,
   3134      1.1     skrll 			_("unresolved expression that must be resolved"));
   3135  1.1.1.2  christos 	  fixP->fx_done = 1;
   3136  1.1.1.2  christos 	  return;
   3137  1.1.1.2  christos 	}
   3138  1.1.1.2  christos 
   3139  1.1.1.2  christos       {
   3140  1.1.1.2  christos 	fixP->fx_r_type = operand->default_reloc;
   3141  1.1.1.2  christos 	if (operand->default_reloc ==  BFD_RELOC_V850_16_PCREL)
   3142  1.1.1.2  christos 	  {
   3143  1.1.1.2  christos 	    fixP->fx_where += 2;
   3144  1.1.1.2  christos 	    fixP->fx_size = 2;
   3145      1.1     skrll 	    fixP->fx_addnumber += 2;
   3146      1.1     skrll 	  }
   3147      1.1     skrll       }
   3148      1.1     skrll     }
   3149      1.1     skrll   else if (fixP->fx_done)
   3150      1.1     skrll     {
   3151      1.1     skrll       /* We still have to insert the value into memory!  */
   3152  1.1.1.2  christos       where = fixP->fx_frag->fr_literal + fixP->fx_where;
   3153  1.1.1.2  christos 
   3154  1.1.1.2  christos       if (fixP->tc_fix_data != NULL
   3155  1.1.1.2  christos           && ((struct v850_operand *) fixP->tc_fix_data)->insert != NULL)
   3156  1.1.1.2  christos         {
   3157  1.1.1.2  christos           const char * message = NULL;
   3158  1.1.1.2  christos           struct v850_operand * operand = (struct v850_operand *) fixP->tc_fix_data;
   3159  1.1.1.2  christos           unsigned long insn;
   3160  1.1.1.2  christos 
   3161  1.1.1.2  christos           /* The variable "where" currently points at the exact point inside
   3162  1.1.1.2  christos              the insn where we need to insert the value.  But we need to
   3163  1.1.1.2  christos              extract the entire insn so we probably need to move "where"
   3164  1.1.1.2  christos              back a few bytes.  */
   3165  1.1.1.2  christos 
   3166  1.1.1.2  christos           if (fixP->fx_size == 2)
   3167  1.1.1.2  christos             where -= 2;
   3168  1.1.1.2  christos           else if (fixP->fx_size == 1)
   3169  1.1.1.2  christos             where -= 3;
   3170  1.1.1.2  christos 
   3171  1.1.1.2  christos           insn = bfd_getl32 ((unsigned char *) where);
   3172  1.1.1.2  christos 
   3173  1.1.1.2  christos           /* Use the operand's insertion procedure, if present, in order to
   3174      1.1     skrll              make sure that the value is correctly stored in the insn.  */
   3175  1.1.1.2  christos           insn = operand->insert (insn, (offsetT) value, & message);
   3176  1.1.1.2  christos           /* Ignore message even if it is set.  */
   3177      1.1     skrll 
   3178  1.1.1.2  christos           bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
   3179  1.1.1.2  christos         }
   3180  1.1.1.2  christos       else
   3181  1.1.1.2  christos         {
   3182  1.1.1.2  christos 	  switch (fixP->fx_r_type)
   3183  1.1.1.2  christos 	    {
   3184  1.1.1.2  christos 	    case BFD_RELOC_V850_32_ABS:
   3185  1.1.1.2  christos 	    case BFD_RELOC_V850_32_PCREL:
   3186  1.1.1.2  christos 	      bfd_putl32 (value & 0xfffffffe, (unsigned char *) where);
   3187  1.1.1.2  christos 	      break;
   3188  1.1.1.2  christos 
   3189  1.1.1.2  christos 	    case BFD_RELOC_32:
   3190  1.1.1.2  christos 	      bfd_putl32 (value, (unsigned char *) where);
   3191  1.1.1.2  christos 	      break;
   3192  1.1.1.2  christos 
   3193  1.1.1.2  christos 	    case BFD_RELOC_V850_23:
   3194  1.1.1.2  christos 	      bfd_putl32 (((value & 0x7f) << 4) | ((value & 0x7fff80) << (16-7))
   3195  1.1.1.2  christos 			  | (bfd_getl32 (where) & ~((0x7f << 4) | (0xffff << 16))),
   3196  1.1.1.2  christos 			  (unsigned char *) where);
   3197  1.1.1.2  christos 	    break;
   3198  1.1.1.2  christos 
   3199  1.1.1.2  christos 	    case BFD_RELOC_16:
   3200  1.1.1.2  christos 	    case BFD_RELOC_HI16:
   3201  1.1.1.2  christos 	    case BFD_RELOC_HI16_S:
   3202  1.1.1.2  christos 	    case BFD_RELOC_LO16:
   3203  1.1.1.2  christos 	    case BFD_RELOC_V850_ZDA_16_16_OFFSET:
   3204  1.1.1.2  christos 	    case BFD_RELOC_V850_SDA_16_16_OFFSET:
   3205  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_16_16_OFFSET:
   3206  1.1.1.2  christos 	    case BFD_RELOC_V850_CALLT_16_16_OFFSET:
   3207  1.1.1.2  christos 	      bfd_putl16 (value & 0xffff, (unsigned char *) where);
   3208  1.1.1.2  christos 	      break;
   3209  1.1.1.2  christos 
   3210  1.1.1.2  christos 	    case BFD_RELOC_8:
   3211  1.1.1.2  christos 	      *where = value & 0xff;
   3212  1.1.1.2  christos 	      break;
   3213  1.1.1.2  christos 
   3214  1.1.1.2  christos 	    case BFD_RELOC_V850_9_PCREL:
   3215  1.1.1.2  christos 	      bfd_putl16 (((value & 0x1f0) << 7) | ((value & 0x0e) << 3)
   3216  1.1.1.2  christos 			  | (bfd_getl16 (where) & ~((0x1f0 << 7) | (0x0e << 3))), where);
   3217  1.1.1.2  christos 	      break;
   3218  1.1.1.2  christos 
   3219  1.1.1.2  christos 	    case BFD_RELOC_V850_17_PCREL:
   3220  1.1.1.2  christos 	      bfd_putl32 (((value & 0x10000) >> (16 - 4)) | ((value & 0xfffe) << 16)
   3221  1.1.1.2  christos 			  | (bfd_getl32 (where) & ~((0x10000 >> (16 - 4)) | (0xfffe << 16))), where);
   3222  1.1.1.2  christos 	      break;
   3223  1.1.1.2  christos 
   3224  1.1.1.2  christos 	    case BFD_RELOC_V850_16_PCREL:
   3225  1.1.1.2  christos 	      bfd_putl16 (-value & 0xfffe, (unsigned char *) where);
   3226  1.1.1.2  christos 	      break;
   3227  1.1.1.2  christos 
   3228  1.1.1.2  christos 	    case BFD_RELOC_V850_22_PCREL:
   3229  1.1.1.2  christos 	      bfd_putl32 (((value & 0xfffe) << 16) | ((value & 0x3f0000) >> 16)
   3230  1.1.1.2  christos 			  | (bfd_getl32 (where) & ~((0xfffe << 16) | (0x3f0000 >> 16))), where);
   3231  1.1.1.2  christos 	      break;
   3232  1.1.1.2  christos 
   3233  1.1.1.2  christos 	    case BFD_RELOC_V850_16_S1:
   3234  1.1.1.2  christos 	    case BFD_RELOC_V850_LO16_S1:
   3235  1.1.1.2  christos 	    case BFD_RELOC_V850_ZDA_15_16_OFFSET:
   3236  1.1.1.2  christos 	    case BFD_RELOC_V850_SDA_15_16_OFFSET:
   3237  1.1.1.2  christos 	      bfd_putl16 (value & 0xfffe, (unsigned char *) where);
   3238  1.1.1.2  christos 	      break;
   3239  1.1.1.2  christos 
   3240  1.1.1.2  christos 	    case BFD_RELOC_V850_16_SPLIT_OFFSET:
   3241  1.1.1.2  christos 	    case BFD_RELOC_V850_LO16_SPLIT_OFFSET:
   3242  1.1.1.2  christos 	    case BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET:
   3243  1.1.1.2  christos 	    case BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET:
   3244  1.1.1.2  christos 	      bfd_putl32 (((value << 16) & 0xfffe0000)
   3245  1.1.1.2  christos 			  | ((value << 5) & 0x20)
   3246  1.1.1.2  christos 			  | (bfd_getl32 (where) & ~0xfffe0020), where);
   3247  1.1.1.2  christos 	      break;
   3248  1.1.1.2  christos 
   3249  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_6_8_OFFSET:
   3250  1.1.1.2  christos 	      *where = (*where & ~0x7e) | ((value >> 1) & 0x7e);
   3251  1.1.1.2  christos 	      break;
   3252  1.1.1.2  christos 
   3253  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_7_8_OFFSET:
   3254  1.1.1.2  christos 	      *where = (*where & ~0x7f) | ((value >> 1) & 0x7f);
   3255  1.1.1.2  christos 	      break;
   3256  1.1.1.2  christos 
   3257  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_7_7_OFFSET:
   3258  1.1.1.2  christos 	      *where = (*where & ~0x7f) | (value & 0x7f);
   3259  1.1.1.2  christos 	      break;
   3260  1.1.1.2  christos 
   3261  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_4_5_OFFSET:
   3262  1.1.1.2  christos 	      *where = (*where & ~0xf) | ((value >> 1) & 0xf);
   3263  1.1.1.2  christos 	      break;
   3264  1.1.1.2  christos 
   3265  1.1.1.2  christos 	    case BFD_RELOC_V850_TDA_4_4_OFFSET:
   3266  1.1.1.2  christos 	      *where = (*where & ~0xf) | (value & 0xf);
   3267  1.1.1.2  christos 	      break;
   3268  1.1.1.2  christos 
   3269  1.1.1.2  christos 	    case BFD_RELOC_V850_CALLT_6_7_OFFSET:
   3270  1.1.1.2  christos 	      *where = (*where & ~0x3f) | (value & 0x3f);
   3271  1.1.1.2  christos 	      break;
   3272  1.1.1.2  christos 
   3273  1.1.1.2  christos 	    default:
   3274      1.1     skrll 	      abort ();
   3275      1.1     skrll 	    }
   3276  1.1.1.2  christos         }
   3277      1.1     skrll     }
   3278      1.1     skrll }
   3279      1.1     skrll 
   3280      1.1     skrll /* Parse a cons expression.  We have to handle hi(), lo(), etc
   3281      1.1     skrll    on the v850.  */
   3282      1.1     skrll 
   3283  1.1.1.2  christos void
   3284      1.1     skrll parse_cons_expression_v850 (expressionS *exp)
   3285  1.1.1.2  christos {
   3286      1.1     skrll   const char *errmsg;
   3287      1.1     skrll   /* See if there's a reloc prefix like hi() we have to handle.  */
   3288      1.1     skrll   hold_cons_reloc = v850_reloc_prefix (NULL, &errmsg);
   3289      1.1     skrll 
   3290      1.1     skrll   /* Do normal expression parsing.  */
   3291      1.1     skrll   expression (exp);
   3292      1.1     skrll }
   3293      1.1     skrll 
   3294      1.1     skrll /* Create a fixup for a cons expression.  If parse_cons_expression_v850
   3295      1.1     skrll    found a reloc prefix, then we use that reloc, else we choose an
   3296      1.1     skrll    appropriate one based on the size of the expression.  */
   3297      1.1     skrll 
   3298      1.1     skrll void
   3299      1.1     skrll cons_fix_new_v850 (fragS *frag,
   3300      1.1     skrll 		   int where,
   3301      1.1     skrll 		   int size,
   3302      1.1     skrll 		   expressionS *exp)
   3303      1.1     skrll {
   3304      1.1     skrll   if (hold_cons_reloc == BFD_RELOC_UNUSED)
   3305      1.1     skrll     {
   3306      1.1     skrll       if (size == 4)
   3307      1.1     skrll 	hold_cons_reloc = BFD_RELOC_32;
   3308      1.1     skrll       if (size == 2)
   3309      1.1     skrll 	hold_cons_reloc = BFD_RELOC_16;
   3310      1.1     skrll       if (size == 1)
   3311      1.1     skrll 	hold_cons_reloc = BFD_RELOC_8;
   3312      1.1     skrll     }
   3313      1.1     skrll 
   3314      1.1     skrll   if (exp != NULL)
   3315      1.1     skrll     fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
   3316      1.1     skrll   else
   3317      1.1     skrll     fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);
   3318      1.1     skrll 
   3319      1.1     skrll   hold_cons_reloc = BFD_RELOC_UNUSED;
   3320      1.1     skrll }
   3321      1.1     skrll 
   3322      1.1     skrll bfd_boolean
   3323      1.1     skrll v850_fix_adjustable (fixS *fixP)
   3324      1.1     skrll {
   3325      1.1     skrll   if (fixP->fx_addsy == NULL)
   3326      1.1     skrll     return 1;
   3327      1.1     skrll 
   3328      1.1     skrll   /* Don't adjust function names.  */
   3329      1.1     skrll   if (S_IS_FUNCTION (fixP->fx_addsy))
   3330      1.1     skrll     return 0;
   3331      1.1     skrll 
   3332      1.1     skrll   /* We need the symbol name for the VTABLE entries.  */
   3333      1.1     skrll   if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   3334      1.1     skrll       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
   3335      1.1     skrll     return 0;
   3336      1.1     skrll 
   3337      1.1     skrll   return 1;
   3338      1.1     skrll }
   3339      1.1     skrll 
   3340      1.1     skrll int
   3341      1.1     skrll v850_force_relocation (struct fix *fixP)
   3342      1.1     skrll {
   3343      1.1     skrll   if (fixP->fx_r_type == BFD_RELOC_V850_LONGCALL
   3344      1.1     skrll       || fixP->fx_r_type == BFD_RELOC_V850_LONGJUMP)
   3345      1.1     skrll     return 1;
   3346      1.1     skrll 
   3347      1.1     skrll   if (v850_relax
   3348  1.1.1.2  christos       && (fixP->fx_pcrel
   3349  1.1.1.2  christos 	  || fixP->fx_r_type == BFD_RELOC_V850_ALIGN
   3350  1.1.1.2  christos 	  || fixP->fx_r_type == BFD_RELOC_V850_9_PCREL
   3351  1.1.1.2  christos 	  || fixP->fx_r_type == BFD_RELOC_V850_16_PCREL
   3352      1.1     skrll 	  || fixP->fx_r_type == BFD_RELOC_V850_17_PCREL
   3353      1.1     skrll 	  || fixP->fx_r_type == BFD_RELOC_V850_22_PCREL
   3354      1.1     skrll 	  || fixP->fx_r_type == BFD_RELOC_V850_32_PCREL
   3355      1.1     skrll 	  || fixP->fx_r_type >= BFD_RELOC_UNUSED))
   3356      1.1     skrll     return 1;
   3357                    
   3358                      return generic_force_reloc (fixP);
   3359                    }
   3360