2001-01-14 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / gas / config / tc-alpha.c
index 44aedcd1cd086d18b0362a917aae4ab73084e5c8..ee9e220e5c5a1b085c1cd5138419ad2e918fdc4b 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-alpha.c - Processor-specific code for the DEC Alpha AXP CPU.
-   Copyright (C) 1989, 93-98, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1989, 93-98, 1999, 2000, 2001 Free Software Foundation, Inc.
    Contributed by Carnegie Mellon University, 1993.
    Written by Alessandro Forin, based on earlier gas-1.38 target CPU files.
    Modified by Ken Raeburn for gas-2.x and ECOFF support.
@@ -58,6 +58,7 @@
 
 #ifdef OBJ_ELF
 #include "elf/alpha.h"
+#include "dwarf2dbg.h"
 #endif
 
 #include <ctype.h>
@@ -144,14 +145,14 @@ struct alpha_macro
 
 #if 1
 #define range_signed_16(x) \
-       (((offsetT)(x) >> 15) == 0 || ((offsetT)(x) >> 15) == -1)
+       (((offsetT) (x) >> 15) == 0 || ((offsetT) (x) >> 15) == -1)
 #define range_signed_32(x) \
-       (((offsetT)(x) >> 31) == 0 || ((offsetT)(x) >> 31) == -1)
+       (((offsetT) (x) >> 31) == 0 || ((offsetT) (x) >> 31) == -1)
 #else
-#define range_signed_16(x)     ((offsetT)(x) >= -(offsetT)0x8000 &&    \
-                                (offsetT)(x) <=  (offsetT)0x7FFF)
-#define range_signed_32(x)     ((offsetT)(x) >= -(offsetT)0x80000000 && \
-                                (offsetT)(x) <=  (offsetT)0x7FFFFFFF)
+#define range_signed_16(x)     ((offsetT) (x) >= -(offsetT)0x8000 &&   \
+                                (offsetT) (x) <=  (offsetT)0x7FFF)
+#define range_signed_32(x)     ((offsetT) (x) >= -(offsetT)0x80000000 && \
+                                (offsetT) (x) <=  (offsetT)0x7FFFFFFF)
 #endif
 
 /* Macros for sign extending from 16- and 32-bits.  */
@@ -159,33 +160,33 @@ struct alpha_macro
    but really a predicate should be found to use the non-cast forms.  */
 
 #if 1
-#define sign_extend_16(x)      ((short)(x))
-#define sign_extend_32(x)      ((int)(x))
+#define sign_extend_16(x)      ((short) (x))
+#define sign_extend_32(x)      ((int) (x))
 #else
-#define sign_extend_16(x)      ((offsetT)(((x) & 0xFFFF) ^ 0x8000) - 0x8000)
-#define sign_extend_32(x)      ((offsetT)(((x) & 0xFFFFFFFF) \
+#define sign_extend_16(x)      ((offsetT) (((x) & 0xFFFF) ^ 0x8000) - 0x8000)
+#define sign_extend_32(x)      ((offsetT) (((x) & 0xFFFFFFFF) \
                                           ^ 0x80000000) - 0x80000000)
 #endif
 
 /* Macros to build tokens */
 
-#define set_tok_reg(t, r)      (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_reg(t, r)      (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_register,                 \
                                 (t).X_add_number = (r))
-#define set_tok_preg(t, r)     (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_preg(t, r)     (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_pregister,                \
                                 (t).X_add_number = (r))
-#define set_tok_cpreg(t, r)    (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_cpreg(t, r)    (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_cpregister,               \
                                 (t).X_add_number = (r))
-#define set_tok_freg(t, r)     (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_freg(t, r)     (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_register,                 \
                                 (t).X_add_number = (r)+32)
-#define set_tok_sym(t, s, a)   (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_sym(t, s, a)   (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_symbol,                   \
                                 (t).X_add_symbol = (s),                \
                                 (t).X_add_number = (a))
-#define set_tok_const(t, n)    (memset(&(t), 0, sizeof(t)),            \
+#define set_tok_const(t, n)    (memset(&(t), 0, sizeof (t)),           \
                                 (t).X_op = O_constant,                 \
                                 (t).X_add_number = (n))
 
@@ -245,6 +246,9 @@ static void s_alpha_end PARAMS ((int));
 static void s_alpha_mask PARAMS ((int));
 static void s_alpha_frame PARAMS ((int));
 static void s_alpha_prologue PARAMS ((int));
+static void s_alpha_file PARAMS ((int));
+static void s_alpha_loc PARAMS ((int));
+static void s_alpha_stab PARAMS ((int));
 static void s_alpha_coff_wrapper PARAMS ((int));
 #endif
 #ifdef OBJ_EVAX
@@ -316,7 +320,7 @@ struct option md_longopts[] = {
   { NULL, no_argument, NULL, 0 }
 };
 
-size_t md_longopts_size = sizeof(md_longopts);
+size_t md_longopts_size = sizeof (md_longopts);
 
 \f
 #ifdef OBJ_EVAX
@@ -393,8 +397,8 @@ static offsetT alpha_lit4_literal;
 static offsetT alpha_lit8_literal;
 #endif
 
-/* The active .ent symbol.  */
 #ifdef OBJ_ELF
+/* The active .ent symbol.  */
 static symbolS *alpha_cur_ent_sym;
 #endif
 
@@ -432,7 +436,7 @@ static int alpha_debug;
 
 #ifdef OBJ_ELF
 /* Whether we are emitting an mdebug section.  */
-int alpha_flag_mdebug = 1;
+int alpha_flag_mdebug = -1;
 #endif
 
 /* Don't fully resolve relocations, allowing code movement in the linker.  */
@@ -474,7 +478,7 @@ static int alpha_flag_show_after_trunc = 0;         /* -H */
 #define ALPHA_RELOC_TABLE(op)                                          \
 &alpha_reloc_op[ ((!USER_RELOC_P (op))                                 \
                  ? (abort (), 0)                                       \
-                 : (int)(op) - (int)O_literal) ]
+                 : (int) (op) - (int)O_literal) ]
 
 #define LITUSE_BASE    1
 #define LITUSE_BYTOFF  2
@@ -546,13 +550,13 @@ static const struct alpha_reloc_op_tag {
 };
 
 static const int alpha_num_reloc_op
-  = sizeof(alpha_reloc_op) / sizeof(*alpha_reloc_op);
+  = sizeof (alpha_reloc_op) / sizeof (*alpha_reloc_op);
 
 /* Maximum # digits needed to hold the largest sequence # */
 #define ALPHA_RELOC_DIGITS 25
 
 /* Whether a sequence number is valid.  */
-#define ALPHA_RELOC_SEQUENCE_OK(X) ((X) > 0 && ((unsigned)(X)) == (X))
+#define ALPHA_RELOC_SEQUENCE_OK(X) ((X) > 0 && ((unsigned) (X)) == (X))
 
 /* Structure to hold explict sequence information.  */
 struct alpha_literal_tag
@@ -800,7 +804,7 @@ static const struct alpha_macro alpha_macros[] = {
 };
 
 static const unsigned int alpha_num_macros
-  = sizeof(alpha_macros) / sizeof(*alpha_macros);
+  = sizeof (alpha_macros) / sizeof (*alpha_macros);
 \f
 /* Public interface functions */
 
@@ -877,14 +881,14 @@ md_begin ()
   for (i = 0; i < 32; ++i)
     {
       char name[4];
-      sprintf(name, "$%d", i);
+      sprintf (name, "$%d", i);
       alpha_register_table[i] = symbol_create(name, reg_section, i,
                                              &zero_address_frag);
     }
   for (; i < 64; ++i)
     {
       char name[5];
-      sprintf(name, "$f%d", i-32);
+      sprintf (name, "$f%d", i-32);
       alpha_register_table[i] = symbol_create(name, reg_section, i,
                                              &zero_address_frag);
     }
@@ -1289,6 +1293,10 @@ md_apply_fix (fixP, valueP)
       abort ();
 #endif
 
+    case BFD_RELOC_VTABLE_INHERIT:
+    case BFD_RELOC_VTABLE_ENTRY:
+      return 1;
+
     default:
       {
        const struct alpha_operand *operand;
@@ -1458,6 +1466,8 @@ alpha_force_relocation (f)
     case BFD_RELOC_ALPHA_USER_GPRELHIGH:
     case BFD_RELOC_ALPHA_USER_GPRELLOW:
 #endif
+    case BFD_RELOC_VTABLE_INHERIT:
+    case BFD_RELOC_VTABLE_ENTRY:
       return 1;
 
     case BFD_RELOC_23_PCREL_S2:
@@ -1517,6 +1527,8 @@ alpha_fix_adjustable (f)
     case BFD_RELOC_ALPHA_USER_GPRELHIGH:
     case BFD_RELOC_ALPHA_USER_GPRELLOW:
 #endif
+    case BFD_RELOC_VTABLE_ENTRY:
+    case BFD_RELOC_VTABLE_INHERIT:
       return 0;
 
     case BFD_RELOC_GPREL32:
@@ -1671,9 +1683,9 @@ alpha_adjust_symtab ()
 
 static void
 alpha_adjust_symtab_relocs (abfd, sec, ptr)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      asection *sec;
-     PTR ptr;
+     PTR ptr ATTRIBUTE_UNUSED;
 {
   segment_info_type *seginfo = seg_info (sec);
   fixS **prevP;
@@ -2138,7 +2150,7 @@ find_opcode_match(first_opcode, tok, pntok, pcpumatch)
 
            default:
              /* everything else should have been fake */
-             abort();
+             abort ();
            }
          ++tokidx;
        }
@@ -2406,7 +2418,7 @@ assemble_insn(opcode, tok, ntok, insn)
              }
              break;
            default:
-             abort();
+             abort ();
            }
        }
       else
@@ -2466,6 +2478,10 @@ emit_insn (insn)
   f = frag_more (4);
   md_number_to_chars (f, insn->insn, 4);
 
+#ifdef OBJ_ELF
+  dwarf2_emit_insn (4);
+#endif
+
   /* Apply the fixups in order */
   for (i = 0; i < insn->nfixups; ++i)
     {
@@ -3161,7 +3177,7 @@ load_expression (targreg, exp, pbasereg, poffset, explicit_reloc)
       if (insn.nfixups > 0)
        {
          memmove (&insn.fixups[1], &insn.fixups[0],
-                  sizeof(struct alpha_fixup) * insn.nfixups);
+                  sizeof (struct alpha_fixup) * insn.nfixups);
        }
       insn.nfixups++;
       insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
@@ -3287,8 +3303,8 @@ emit_lda (tok, ntok, opname)
              || tok[2].X_op != O_pregister
              || !is_ir_num(tok[2].X_add_number))
            {
-             as_bad (_("bad instruction format for lda !%s!%d"), r->name,
-                     reloc->X_add_number);
+             as_bad (_("bad instruction format for lda !%s!%ld"), r->name,
+                     (long) reloc->X_add_number);
 
              reloc = (const expressionS *)0;
              ntok--;
@@ -3418,7 +3434,7 @@ emit_ir_load (tok, ntok, opname)
       if (insn.nfixups > 0)
        {
          memmove (&insn.fixups[1], &insn.fixups[0],
-                  sizeof(struct alpha_fixup) * insn.nfixups);
+                  sizeof (struct alpha_fixup) * insn.nfixups);
        }
       insn.nfixups++;
       insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
@@ -3504,7 +3520,7 @@ emit_loadstore (tok, ntok, opname)
       if (insn.nfixups > 0)
        {
          memmove (&insn.fixups[1], &insn.fixups[0],
-                  sizeof(struct alpha_fixup) * insn.nfixups);
+                  sizeof (struct alpha_fixup) * insn.nfixups);
        }
       insn.nfixups++;
       insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
@@ -3669,7 +3685,7 @@ emit_ldil (tok, ntok, unused)
     }
 #endif
 
-  memcpy (newtok, tok, sizeof(newtok));
+  memcpy (newtok, tok, sizeof (newtok));
   newtok[1].X_add_number = sign_extend_32 (tok[1].X_add_number);
 
   assemble_tokens ("lda", newtok, ntok, 1);
@@ -3683,7 +3699,7 @@ emit_stX (tok, ntok, vlgsize)
      int ntok;
      const PTR vlgsize;
 {
-  int lgsize = (int)(long)vlgsize;
+  int lgsize = (int) (long)vlgsize;
 
   if (alpha_target & AXP_OPCODE_BWX)
     emit_loadstore (tok, ntok, stX_op[lgsize]);
@@ -3741,7 +3757,7 @@ emit_ustX (tok, ntok, vlgsize)
      int ntok;
      const PTR vlgsize;
 {
-  int lgsize = (int)(long)vlgsize;
+  int lgsize = (int) (long)vlgsize;
   expressionS newtok[3];
 
   /* emit "lda $at, exp" */
@@ -4161,7 +4177,7 @@ emit_jsrjmp (tok, ntok, vopname)
       if (insn.nfixups > 0)
        {
          memmove (&insn.fixups[1], &insn.fixups[0],
-                  sizeof(struct alpha_fixup) * insn.nfixups);
+                  sizeof (struct alpha_fixup) * insn.nfixups);
        }
       insn.nfixups++;
       insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
@@ -4571,6 +4587,72 @@ s_alpha_prologue (ignore)
     }
 }
 
+static char * first_file_directive;
+
+static void
+s_alpha_file (ignore)
+     int ignore ATTRIBUTE_UNUSED;
+{
+  /* Save the first .file directive we see, so that we can change our
+     minds about whether ecoff debugging should or shouldn't be enabled.  */
+  if (alpha_flag_mdebug < 0 && ! first_file_directive)
+    {
+      char *start = input_line_pointer;
+      size_t len;
+
+      discard_rest_of_line ();
+
+      len = input_line_pointer - start;
+      first_file_directive = xmalloc (len + 1);
+      memcpy (first_file_directive, start, len);
+      first_file_directive[len] = '\0';
+
+      input_line_pointer = start;
+    }
+
+  if (ECOFF_DEBUGGING)
+    ecoff_directive_file (0);
+  else
+    dwarf2_directive_file (0);
+}
+
+static void
+s_alpha_loc (ignore)
+     int ignore ATTRIBUTE_UNUSED;
+{
+  if (ECOFF_DEBUGGING)
+    ecoff_directive_loc (0);
+  else
+    dwarf2_directive_loc (0);
+}
+
+static void
+s_alpha_stab (n)
+     int n;
+{
+  /* If we've been undecided about mdebug, make up our minds in favour.  */
+  if (alpha_flag_mdebug < 0)
+    {
+      segT sec = subseg_new(".mdebug", 0);
+      bfd_set_section_flags(stdoutput, sec, SEC_HAS_CONTENTS|SEC_READONLY);
+      bfd_set_section_alignment(stdoutput, sec, 3);
+
+      ecoff_read_begin_hook ();
+
+      if (first_file_directive)
+       {
+         char *save_ilp = input_line_pointer;
+          input_line_pointer = first_file_directive;
+         ecoff_directive_file (0);
+         input_line_pointer = save_ilp;
+         free (first_file_directive);
+       }
+
+      alpha_flag_mdebug = 1;
+    }
+  s_stab (n);
+}
+
 static void
 s_alpha_coff_wrapper (which)
      int which;
@@ -4581,17 +4663,15 @@ s_alpha_coff_wrapper (which)
     ecoff_directive_def,
     ecoff_directive_dim,
     ecoff_directive_endef,
-    ecoff_directive_file,
     ecoff_directive_scl,
     ecoff_directive_tag,
     ecoff_directive_val,
-    ecoff_directive_loc,
   };
 
-  assert (which >= 0 && which < (int)(sizeof(fns)/sizeof(*fns)));
+  assert (which >= 0 && which < (int) (sizeof (fns)/sizeof (*fns)));
 
   if (ECOFF_DEBUGGING)
-    (*fns[which])(0);
+    (*fns[which]) (0);
   else
     {
       as_bad (_("ECOFF debugging is disabled."));
@@ -5062,7 +5142,7 @@ s_alpha_gprel32 (ignore)
     case O_symbol:
       break;
     default:
-      abort();
+      abort ();
     }
 #else
 #ifdef OBJ_ECOFF
@@ -5447,17 +5527,19 @@ const pseudo_typeS md_pseudo_table[] =
   {"fmask", s_alpha_mask, 1},
   {"frame", s_alpha_frame, 0},
   {"prologue", s_alpha_prologue, 0},
+  {"file", s_alpha_file, 5},
+  {"loc", s_alpha_loc, 9},
+  {"stabs", s_alpha_stab, 's'},
+  {"stabn", s_alpha_stab, 'n'},
   /* COFF debugging related pseudos.  */
   {"begin", s_alpha_coff_wrapper, 0},
   {"bend", s_alpha_coff_wrapper, 1},
   {"def", s_alpha_coff_wrapper, 2},
   {"dim", s_alpha_coff_wrapper, 3},
   {"endef", s_alpha_coff_wrapper, 4},
-  {"file", s_alpha_coff_wrapper, 5},
-  {"scl", s_alpha_coff_wrapper, 6},
-  {"tag", s_alpha_coff_wrapper, 7},
-  {"val", s_alpha_coff_wrapper, 8},
-  {"loc", s_alpha_coff_wrapper, 9},
+  {"scl", s_alpha_coff_wrapper, 5},
+  {"tag", s_alpha_coff_wrapper, 6},
+  {"val", s_alpha_coff_wrapper, 7},
 #else
   {"prologue", s_ignore, 0},
 #endif
@@ -5599,27 +5681,8 @@ alpha_align (n, pfill, label, force)
 
   if (pfill == NULL)
     {
-      if (n > 2
-         && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
-       {
-         static char const unop[4] = { 0x00, 0x00, 0xe0, 0x2f };
-         static char const nopunop[8] = {
-               0x1f, 0x04, 0xff, 0x47,
-               0x00, 0x00, 0xe0, 0x2f
-         };
-
-         /* First, make sure we're on a four-byte boundary, in case
-            someone has been putting .byte values into the text
-            section.  The DEC assembler silently fills with unaligned
-            no-op instructions.  This will zero-fill, then nop-fill
-            with proper alignment.  */
-         if (alpha_current_align < 2)
-           frag_align (2, 0, 0);
-         if (alpha_current_align < 3)
-           frag_align_pattern (3, unop, sizeof unop, 0);
-         if (n > 3)
-           frag_align_pattern (n, nopunop, sizeof nopunop, 0);
-       }
+      if (subseg_text_p (now_seg))
+       frag_align_code (n, 0);
       else
        frag_align (n, 0, 0);
     }
@@ -5636,10 +5699,55 @@ alpha_align (n, pfill, label, force)
 
   record_alignment (now_seg, n);
 
-  /* ??? if alpha_flag_relax && force && elf, record the requested alignment
+  /* ??? If alpha_flag_relax && force && elf, record the requested alignment
      in a reloc for the linker to see.  */
 }
 
+/* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
+   of an rs_align_code fragment.  */
+
+void
+alpha_handle_align (fragp)
+     fragS *fragp;
+{
+  static char const unop[4] = { 0x00, 0x00, 0xe0, 0x2f };
+  static char const nopunop[8] = {
+       0x1f, 0x04, 0xff, 0x47,
+       0x00, 0x00, 0xe0, 0x2f
+  };
+
+  int bytes, fix;
+  char *p;
+
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+  p = fragp->fr_literal + fragp->fr_fix;
+  fix = 0;
+
+  if (bytes & 3)
+    {
+      fix = bytes & 3;
+      memset (p, 0, fix);
+      p += fix;
+      bytes -= fix;
+    }
+
+  if (bytes & 4)
+    {
+      memcpy (p, unop, 4);
+      p += 4;
+      bytes -= 4;
+      fix += 4;
+    }
+
+  memcpy (p, nopunop, 8);
+
+  fragp->fr_fix += fix;
+  fragp->fr_var = 8;
+}
+
 /* The Alpha has support for some VAX floating point types, as well as for
    IEEE floating point.  We consider IEEE to be the primary floating point
    format, and sneak in the VAX floating point support here.  */
This page took 0.031385 seconds and 4 git commands to generate.