Don't assume a valueT is 4 bytes.
[binutils-gdb.git] / gas / config / tc-vax.c
index 1e1c1282aa0c9cb58accfd27685182f7a4cb8082..7934aea9289cde457189db2599465ca8ad85047c 100644 (file)
@@ -1,5 +1,6 @@
 /* tc-vax.c - vax-specific -
-   Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1998, 2000, 2001, 2002, 2003
+   Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1998, 2000, 2001, 2002,
+   2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -16,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with GAS; see the file COPYING.  If not, write to the Free
-   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 #include "as.h"
 
 #include "elf/vax.h"
 #endif
 
+#if defined (OBJ_AOUT) && !defined (BFD_ASSEMBLER) && defined (TE_NetBSD)
+#include <netinet/in.h>
+#endif
+
 /* These chars start a comment anywhere in a source file (except inside
    another comment */
 const char comment_chars[] = "#";
@@ -246,6 +251,10 @@ const pseudo_typeS md_pseudo_table[] =
   {"ffloat", float_cons, 'f'},
   {"gfloat", float_cons, 'g'},
   {"hfloat", float_cons, 'h'},
+  {"d_floating", float_cons, 'd'},
+  {"f_floating", float_cons, 'f'},
+  {"g_floating", float_cons, 'g'},
+  {"h_floating", float_cons, 'h'},
   {NULL, NULL, 0},
 };
 
@@ -339,6 +348,60 @@ md_chars_to_number (con, nbytes)
     }
   return retval;
 }
+
+/*
+ * Copy a bignum from in to out.
+ * If the output is shorter than the input, copy lower-order
+ * littlenums.  Return 0 or the number of significant littlenums
+ * dropped.  Assumes littlenum arrays are densely packed: no unused
+ * chars between the littlenums. Uses memcpy() to move littlenums, and
+ * wants to know length (in chars) of the input bignum.
+ */
+
+static int
+bignum_copy (register LITTLENUM_TYPE *in,
+            register int in_length,    /* in sizeof(littlenum)s */
+            register LITTLENUM_TYPE *out,
+            register int out_length    /* in sizeof(littlenum)s */)
+{
+  int significant_littlenums_dropped;
+
+  if (out_length < in_length)
+    {
+      LITTLENUM_TYPE *p;       /* -> most significant (non-zero) input
+                                     littlenum.  */
+
+      memcpy ((void *) out, (void *) in,
+             (unsigned int) out_length << LITTLENUM_SHIFT);
+      for (p = in + in_length - 1; p >= in; --p)
+       {
+         if (*p)
+           break;
+       }
+      significant_littlenums_dropped = p - in - in_length + 1;
+
+      if (significant_littlenums_dropped < 0)
+       {
+         significant_littlenums_dropped = 0;
+       }
+    }
+  else
+    {
+      memcpy ((char *) out, (char *) in,
+             (unsigned int) in_length << LITTLENUM_SHIFT);
+
+      if (out_length > in_length)
+       {
+         memset ((char *) (out + in_length),
+                 '\0',
+                 (unsigned int) (out_length - in_length) << LITTLENUM_SHIFT);
+       }
+
+      significant_littlenums_dropped = 0;
+    }
+
+  return (significant_littlenums_dropped);
+}
 \f
 /* vax:md_assemble() emit frags for 1 instruction */
 
@@ -662,7 +725,8 @@ md_assemble (instruction_string)
   /* Remember where it is, in case we want to modify the op-code later.  */
   opcode_low_byteP = frag_more (v.vit_opcode_nbytes);
   memcpy (opcode_low_byteP, v.vit_opcode, v.vit_opcode_nbytes);
-  opcode_as_number = md_chars_to_number (opcode_as_chars = v.vit_opcode, 4);
+  opcode_as_chars = v.vit_opcode;
+  opcode_as_number = md_chars_to_number ((unsigned char *) opcode_as_chars, 4);
   for (operandP = v.vit_operand,
        expP = exp_of_operand,
        segP = seg_of_operand,
@@ -1126,18 +1190,17 @@ md_assemble (instruction_string)
                          p[0] = (operandP->vop_mode << 4) | 0xF;
                          if ((is_absolute) && (expP->X_op != O_big))
                            {
-                             /*
-                              * If nbytes > 4, then we are scrod. We
-                              * don't know if the high order bytes
-                              * are to be 0xFF or 0x00.  BSD4.2 & RMS
-                              * say use 0x00. OK --- but this
-                              * assembler needs ANOTHER rewrite to
-                              * cope properly with this bug.  */
-                             md_number_to_chars (p + 1, this_add_number, min (4, nbytes));
-                             if (nbytes > 4)
-                               {
-                                 memset (p + 5, '\0', nbytes - 4);
-                               }
+                             /* If nbytes > 4, then we are scrod. We
+                                don't know if the high order bytes
+                                are to be 0xFF or 0x00.  BSD4.2 & RMS
+                                say use 0x00. OK --- but this
+                                assembler needs ANOTHER rewrite to
+                                cope properly with this bug.  */
+                             md_number_to_chars (p + 1, this_add_number,
+                                                 min (sizeof (valueT),
+                                                      (size_t) nbytes));
+                             if ((size_t) nbytes > sizeof (valueT))
+                               memset (p + 5, '\0', nbytes - sizeof (valueT));
                            }
                          else
                            {
@@ -3214,8 +3277,8 @@ mumble (text, value)
 
 /* end: vip_op.c */
 
-const int md_short_jump_size = 3;
-const int md_long_jump_size = 6;
+int md_short_jump_size = 3;
+int md_long_jump_size = 6;
 const int md_reloc_size = 8;   /* Size of relocation record */
 
 void
@@ -3407,7 +3470,7 @@ tc_headers_hook(headers)
 {
 #ifdef TE_NetBSD
   N_SET_INFO(headers->header, OMAGIC, M_VAX4K_NETBSD, 0);
-  headers->header.a_info = htonl(headers->header.a_info);
+  headers->header.a_info = htonl (headers->header.a_info);
 #endif
 }
 #endif /* !BFD_ASSEMBLER */