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