* elf32-m32c.c (ELF_MAXPAGESIZE): Change page size to 256 bytes.
[deliverable/binutils-gdb.git] / gas / config / tc-hppa.c
index da84526fa9513ccf01aa9d27dc8c62f249b7b583..e55b2b45c145b6bc90d42ddb59090e06ca5a950a 100644 (file)
@@ -1,6 +1,7 @@
 /* tc-hppa.c -- Assemble for the PA
-   Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -995,6 +996,19 @@ static struct default_space_dict pa_def_spaces[] =
 #define IS_R_SELECT(S)   (*(S) == 'R' || *(S) == 'r')
 #define IS_L_SELECT(S)   (*(S) == 'L' || *(S) == 'l')
 
+/* Store immediate values of shift/deposit/extract functions.  */
+
+#define SAVE_IMMEDIATE(VALUE) \
+  { \
+    if (immediate_check) \
+      { \
+       if (pos == -1) \
+         pos = (VALUE); \
+       else if (len == -1) \
+         len = (VALUE); \
+      } \
+  }
+
 /* Insert FIELD into OPCODE starting at bit START.  Continue pa_ip
    main loop after insertion.  */
 
@@ -1375,8 +1389,8 @@ tc_gen_reloc (asection *section, fixS *fixp)
   if (fixp->fx_addsy == 0)
     return &no_relocs;
 
-  assert (hppa_fixp != 0);
-  assert (section != 0);
+  gas_assert (hppa_fixp != 0);
+  gas_assert (section != 0);
 
   reloc = xmalloc (sizeof (arelent));
 
@@ -1388,7 +1402,8 @@ tc_gen_reloc (asection *section, fixS *fixp)
   /* ??? It might be better to hide this +8 stuff in tc_cfi_emit_pcrel_expr,
      undefine DIFF_EXPR_OK, and let these sorts of complex expressions fail
      when R_HPPA_COMPLEX == R_PARISC_UNIMPLEMENTED.  */
-  if (fixp->fx_r_type == R_HPPA_COMPLEX && fixp->fx_pcrel)
+  if (fixp->fx_r_type == (bfd_reloc_code_real_type) R_HPPA_COMPLEX
+      && fixp->fx_pcrel)
     {
       fixp->fx_r_type = R_HPPA_PCREL_CALL;
       fixp->fx_offset += 8;
@@ -1421,7 +1436,7 @@ tc_gen_reloc (asection *section, fixS *fixp)
   switch (fixp->fx_r_type)
     {
     default:
-      assert (n_relocs == 1);
+      gas_assert (n_relocs == 1);
 
       code = *codes[0];
 
@@ -1475,7 +1490,7 @@ tc_gen_reloc (asection *section, fixS *fixp)
                                            (bfd_reloc_code_real_type) code);
       reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
 
-      assert (reloc->howto && (unsigned int) code == reloc->howto->type);
+      gas_assert (reloc->howto && (unsigned int) code == reloc->howto->type);
       break;
     }
 #else /* OBJ_SOM */
@@ -1498,7 +1513,7 @@ tc_gen_reloc (asection *section, fixS *fixp)
          /* The only time we ever use a R_COMP2 fixup is for the difference
             of two symbols.  With that in mind we fill in all four
             relocs now and break out of the loop.  */
-         assert (i == 1);
+         gas_assert (i == 1);
          relocs[0]->sym_ptr_ptr
            = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
          relocs[0]->howto
@@ -2548,7 +2563,6 @@ pa_get_absolute_expression (struct pa_it *insn, char **strp)
   if (insn->exp.X_op == O_modulus)
     {
       char *s, c;
-      int retval;
 
       input_line_pointer = *strp;
       s = *strp;
@@ -2558,7 +2572,7 @@ pa_get_absolute_expression (struct pa_it *insn, char **strp)
       c = *s;
       *s = 0;
 
-      retval = pa_get_absolute_expression (insn, strp);
+      pa_get_absolute_expression (insn, strp);
 
       input_line_pointer = save_in;
       *s = c;
@@ -3191,6 +3205,7 @@ pa_ip (char *str)
   int match = FALSE;
   int comma = 0;
   int cmpltr, nullif, flag, cond, num;
+  int immediate_check = 0, pos = -1, len = -1;
   unsigned long opcode;
   struct pa_opcode *insn;
 
@@ -3233,7 +3248,7 @@ pa_ip (char *str)
   /* Look up the opcode in the hash table.  */
   if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
     {
-      as_bad ("Unknown opcode: `%s'", str);
+      as_bad (_("Unknown opcode: `%s'"), str);
       return;
     }
 
@@ -3351,6 +3366,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 32, 1, 0);
+             SAVE_IMMEDIATE(num);
              INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
 
            /* Handle a 5 bit immediate at 15.  */
@@ -3953,6 +3969,12 @@ pa_ip (char *str)
 
                  /* Handle an add condition.  */
                  case 'A':
+                   /* PR gas/11395
+                      If we are looking for 64-bit add conditions and we
+                      do not have the ",*" prefix, then we have no match.  */
+                   if (*s != ',')
+                     break;
+                   /* Fall through.  */
                  case 'a':
                    cmpltr = 0;
                    flag = 0;
@@ -4333,6 +4355,9 @@ pa_ip (char *str)
                  case 'x':
                  case 'y':
                    cmpltr = 0;
+                   /* Check immediate values in shift/extract/deposit
+                    * instructions if they will give undefined behaviour.  */
+                   immediate_check = 1;
                    if (*s == ',')
                      {
                        save_s = s++;
@@ -5125,6 +5150,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 31, 0, strict);
+             SAVE_IMMEDIATE(num);
              INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
 
            /* Handle a 6 bit shift count at 20,22:26.  */
@@ -5134,6 +5160,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 63, 0, strict);
+             SAVE_IMMEDIATE(num);
              num = 63 - num;
              opcode |= (num & 0x20) << 6;
              INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
@@ -5146,6 +5173,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 64, 1, strict);
+             SAVE_IMMEDIATE(num);
              num--;
              opcode |= (num & 0x20) << 3;
              num = 31 - (num & 0x1f);
@@ -5158,6 +5186,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 64, 1, strict);
+             SAVE_IMMEDIATE(num);
              num--;
              opcode |= (num & 0x20) << 7;
              num = 31 - (num & 0x1f);
@@ -5170,6 +5199,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 31, 0, strict);
+             SAVE_IMMEDIATE(num);
              INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
 
            /* Handle a 6 bit bit position at 20,22:26.  */
@@ -5179,6 +5209,7 @@ pa_ip (char *str)
                break;
              s = expr_end;
              CHECK_FIELD (num, 63, 0, strict);
+             SAVE_IMMEDIATE(num);
              opcode |= (num & 0x20) << 6;
              INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
 
@@ -5686,6 +5717,13 @@ pa_ip (char *str)
       break;
     }
 
+  if (immediate_check)
+    {
+      if (pos != -1 && len != -1 && pos < len - 1)
+        as_warn (_("Immediates %d and %d will give undefined behavior."),
+                       pos, len);
+    }
+
   the_insn.opcode = opcode;
 }
 
@@ -5697,7 +5735,7 @@ md_assemble (char *str)
   char *to;
 
   /* The had better be something to assemble.  */
-  assert (str);
+  gas_assert (str);
 
   /* If we are within a procedure definition, make sure we've
      defined a label for the procedure; handle case where the
@@ -5930,13 +5968,45 @@ pa_build_unwind_subspace (struct call_info *call_info)
   subsegT save_subseg;
   unsigned int unwind;
   int reloc;
-  char *p;
+  char *name, *p;
+  symbolS *symbolP;
 
   if ((bfd_get_section_flags (stdoutput, now_seg)
        & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
       != (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
     return;
 
+  if (call_info->start_symbol == NULL)
+    /* This can happen if there were errors earlier on in the assembly.  */
+    return;
+
+  /* Replace the start symbol with a local symbol that will be reduced
+     to a section offset.  This avoids problems with weak functions with
+     multiple definitions, etc.  */
+  name = xmalloc (strlen ("L$\001start_")
+                 + strlen (S_GET_NAME (call_info->start_symbol))
+                 + 1);
+  strcpy (name, "L$\001start_");
+  strcat (name, S_GET_NAME (call_info->start_symbol));
+
+  /* If we have a .procend preceded by a .exit, then the symbol will have
+     already been defined.  In that case, we don't want another unwind
+     entry.  */
+  symbolP = symbol_find (name);
+  if (symbolP)
+    {
+      xfree (name);
+      return;
+    }
+  else
+    {
+      symbolP = symbol_new (name, now_seg,
+                           S_GET_VALUE (call_info->start_symbol), frag_now);
+      gas_assert (symbolP);
+      S_CLEAR_EXTERNAL (symbolP);
+      symbol_table_insert (symbolP);
+    }
+
   reloc = R_PARISC_SEGREL32;
   save_seg = now_seg;
   save_subseg = now_subseg;
@@ -5962,7 +6032,7 @@ pa_build_unwind_subspace (struct call_info *call_info)
   /* Relocation info. for start offset of the function.  */
   md_number_to_chars (p, 0, 4);
   fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
-               call_info->start_symbol, (offsetT) 0,
+               symbolP, (offsetT) 0,
                (expressionS *) NULL, 0, reloc,
                e_fsel, 32, 0, 0);
 
@@ -6402,7 +6472,7 @@ hppa_elf_mark_end_of_function (void)
          symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
                                frag_now);
 
-         assert (symbolP);
+         gas_assert (symbolP);
          S_CLEAR_EXTERNAL (symbolP);
          symbol_table_insert (symbolP);
        }
@@ -6433,6 +6503,7 @@ process_exit (void)
   /* Mark the end of the function, stuff away the location of the frag
      for the end of the function, and finally call pa_build_unwind_subspace
      to add an entry in the unwind table.  */
+  (void) where;
   hppa_elf_mark_end_of_function ();
   pa_build_unwind_subspace (last_call_info);
 #else
@@ -6574,6 +6645,8 @@ pa_type_args (symbolS *symbolP, int is_export)
      to the SOM BFD backend.  */
 #ifdef obj_set_symbol_type
   obj_set_symbol_type (bfdsym, (int) type);
+#else
+  (void) type;
 #endif
 
   /* Now that the type of the exported symbol has been handled,
@@ -6596,6 +6669,8 @@ pa_type_args (symbolS *symbolP, int is_export)
          arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
 #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
          symbol_arg_reloc_info (symbolP) |= arg_reloc;
+#else
+         (void) arg_reloc;
 #endif
          *input_line_pointer = c;
        }
@@ -6610,6 +6685,8 @@ pa_type_args (symbolS *symbolP, int is_export)
          arg_reloc = pa_build_arg_reloc (name);
 #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
          symbol_arg_reloc_info (symbolP) |= arg_reloc;
+#else
+         (void) arg_reloc;
 #endif
          *input_line_pointer = c;
        }
@@ -7310,7 +7387,7 @@ pa_subspace (int create_new)
 {
   char *name, *ss_name, c;
   char loadable, code_only, comdat, common, dup_common, zero, sort;
-  int i, access, space_index, alignment, quadrant, applicable, flags;
+  int i, access_ctr, space_index, alignment, quadrant, applicable, flags;
   sd_chain_struct *space;
   ssd_chain_struct *ssd;
   asection *section;
@@ -7333,7 +7410,7 @@ pa_subspace (int create_new)
 
       /* Load default values.  */
       sort = 0;
-      access = 0x7f;
+      access_ctr = 0x7f;
       loadable = 1;
       comdat = 0;
       common = 0;
@@ -7378,7 +7455,7 @@ pa_subspace (int create_new)
                  space_index = pa_def_subspaces[i].space_index;
                  alignment = pa_def_subspaces[i].alignment;
                  quadrant = pa_def_subspaces[i].quadrant;
-                 access = pa_def_subspaces[i].access;
+                 access_ctr = pa_def_subspaces[i].access;
                  sort = pa_def_subspaces[i].sort;
                  break;
                }
@@ -7416,7 +7493,7 @@ pa_subspace (int create_new)
                {
                  *input_line_pointer = c;
                  input_line_pointer++;
-                 access = get_absolute_expression ();
+                 access_ctr = get_absolute_expression ();
                }
              else if ((strncasecmp (name, "sort", 4) == 0))
                {
@@ -7524,14 +7601,14 @@ pa_subspace (int create_new)
 
        current_subspace = update_subspace (space, ss_name, loadable,
                                            code_only, comdat, common,
-                                           dup_common, sort, zero, access,
+                                           dup_common, sort, zero, access_ctr,
                                            space_index, alignment, quadrant,
                                            section);
       else
        current_subspace = create_new_subspace (space, ss_name, loadable,
                                                code_only, comdat, common,
                                                dup_common, zero, sort,
-                                               access, space_index,
+                                               access_ctr, space_index,
                                                alignment, quadrant, section);
 
       demand_empty_rest_of_line ();
@@ -7762,7 +7839,7 @@ create_new_subspace (sd_chain_struct *space,
                     int dup_common,
                     int is_zero ATTRIBUTE_UNUSED,
                     int sort,
-                    int access,
+                    int access_ctr,
                     int space_index ATTRIBUTE_UNUSED,
                     int alignment ATTRIBUTE_UNUSED,
                     int quadrant,
@@ -7817,7 +7894,7 @@ create_new_subspace (sd_chain_struct *space,
     }
 
 #ifdef obj_set_subsection_attributes
-  obj_set_subsection_attributes (seg, space->sd_seg, access, sort,
+  obj_set_subsection_attributes (seg, space->sd_seg, access_ctr, sort,
                                 quadrant, comdat, common, dup_common);
 #endif
 
@@ -7837,7 +7914,7 @@ update_subspace (sd_chain_struct *space,
                 int dup_common,
                 int sort,
                 int zero ATTRIBUTE_UNUSED,
-                int access,
+                int access_ctr,
                 int space_index ATTRIBUTE_UNUSED,
                 int alignment ATTRIBUTE_UNUSED,
                 int quadrant,
@@ -7848,7 +7925,7 @@ update_subspace (sd_chain_struct *space,
   chain_entry = is_defined_subspace (name);
 
 #ifdef obj_set_subsection_attributes
-  obj_set_subsection_attributes (section, space->sd_seg, access, sort,
+  obj_set_subsection_attributes (section, space->sd_seg, access_ctr, sort,
                                 quadrant, comdat, common, dup_common);
 #endif
 
@@ -8434,7 +8511,7 @@ hppa_force_relocation (struct fix *fixp)
     return 1;
 #endif
 
-  assert (fixp->fx_addsy != NULL);
+  gas_assert (fixp->fx_addsy != NULL);
 
   /* Ensure we emit a relocation for global symbols so that dynamic
      linking works.  */
@@ -8676,9 +8753,19 @@ hppa_regname_to_dw2regnum (char *regname)
     {
       p = regname + 2;
       regnum = strtoul (p, &q, 10);
+#if TARGET_ARCH_SIZE == 64
       if (p == q || *q || regnum <= 4 || regnum >= 32)
        return -1;
       regnum += 32 - 4;
+#else
+      if (p == q
+         || (*q  && ((*q != 'L' && *q != 'R') || *(q + 1)))
+         || regnum <= 4 || regnum >= 32)
+       return -1;
+      regnum = (regnum - 4) * 2 + 32;
+      if (*q == 'R')
+       regnum++;
+#endif
     }
   return regnum;
 }
This page took 0.032473 seconds and 4 git commands to generate.