* read.c (potable): Add string8, string16, string32 and string64. Add bit size for...
authorNick Clifton <nickc@redhat.com>
Thu, 4 Oct 2007 17:05:37 +0000 (17:05 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 4 Oct 2007 17:05:37 +0000 (17:05 +0000)
 (stringer_append_char): New.
 (stringer): Use stringer_append_char().
* config/obj-coff.c (obj_coff_ident): Add bit size for stringer function.
* config/obj-elf.c (obj_elf_ident): Likewise.
* config/tc-alpha.c (s_alpha_stringer): Likewise.
* config/tc-dlx.c (dlx_pseudo_table): Likewise.
* config/tc-hppa.c (pa_stringer): Likewise.
* config/tc-ia64.c (md_pseudo_table, pseudo_opcode): Likewise.
* config/tc-m68hc11.c (md_pseudo_table): Likewise.
* config/tc-mcore.c (md_pseudo_table): Likewise.
* config/tc-mips.c (mips_pseudo_table): Likewise.
* config/tc-spu.c (md_pseudo_table): Likewise.
* config/tc-s390.c (md_pseudo_table): Likewise. Replace '2' by '1'.
* doc/as.texinfo (ABORT): Fix identing.
  (String): Document new string8, string16, string32, string64 functions.
* NEWS: Mention the new feature.

* testsuite/gas/all/gas.exp: Include new test "strings".
* testsuite/gas/all/string.s: New
* testsuite/gas/all/string.d: New.

19 files changed:
gas/ChangeLog
gas/NEWS
gas/config/obj-coff.c
gas/config/obj-elf.c
gas/config/tc-alpha.c
gas/config/tc-dlx.c
gas/config/tc-hppa.c
gas/config/tc-ia64.c
gas/config/tc-m68hc11.c
gas/config/tc-mcore.c
gas/config/tc-mips.c
gas/config/tc-s390.c
gas/config/tc-spu.c
gas/doc/as.texinfo
gas/read.c
gas/testsuite/ChangeLog
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/string.d [new file with mode: 0644]
gas/testsuite/gas/all/string.s [new file with mode: 0644]

index ef12adbdf5a8da37af58e66969db0538b9f23179..6694d9896a584315df1d9fe551fda1e544c02b6b 100644 (file)
@@ -1,3 +1,25 @@
+2007-10-04  Helge Deller  <deller@gmx.de>
+
+       * read.c (potable): Add string8, string16, string32 and string64.
+       Add bit size for stringer function.
+       (stringer_append_char): New.
+       (stringer): Use stringer_append_char().
+       * config/obj-coff.c (obj_coff_ident): Add bit size for stringer function.
+       * config/obj-elf.c (obj_elf_ident): Likewise.
+       * config/tc-alpha.c (s_alpha_stringer): Likewise.
+       * config/tc-dlx.c (dlx_pseudo_table): Likewise.
+       * config/tc-hppa.c (pa_stringer): Likewise.
+       * config/tc-ia64.c (md_pseudo_table, pseudo_opcode): Likewise.
+       * config/tc-m68hc11.c (md_pseudo_table): Likewise.
+       * config/tc-mcore.c (md_pseudo_table): Likewise.
+       * config/tc-mips.c (mips_pseudo_table): Likewise.
+       * config/tc-spu.c (md_pseudo_table): Likewise.
+       * config/tc-s390.c (md_pseudo_table): Likewise. Replace '2' by '1'.
+       * doc/as.texinfo (ABORT): Fix identing.
+       (String): Document new string8, string16, string32, string64
+       functions.
+       * NEWS: Mention the new feature.
+
 2007-10-03  Nick Clifton  <nickc@redhat.com>
 
        PR gas/5078
index 8f6f3709efbb32cc7a2d3955fe5d2ec1a8088a3f..d9c55796b6331d558794c3a6e5827355259e6985 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -1,4 +1,7 @@
 -*- text -*-
+* Support for generating wide character strings has been added via the new
+  pseudo ops: .string16, .string32 and .string64.
+
 * Support for SSE5 has been added to the i386 port.
 
 Changes in 2.18:
index 9bbeca485397f90b387ae808d278baaeb036f9dd..4bcede6ee2a577083a94831f3fcbf405fc1c967c 100644 (file)
@@ -497,7 +497,7 @@ obj_coff_ident (int ignore ATTRIBUTE_UNUSED)
   subseg_new (".comment", 0);
 #endif
 
-  stringer (1);
+  stringer (8 + 1);
   subseg_set (current_seg, current_subseg);
 }
 
index 014117a69591c951a9cab7027c5ec8b6a3c1c475..8f696d77202325d7af4c3efc188cc4bad448d5e9 100644 (file)
@@ -1618,7 +1618,7 @@ obj_elf_ident (int ignore ATTRIBUTE_UNUSED)
     }
   else
     subseg_set (comment_section, 0);
-  stringer (1);
+  stringer (8 + 1);
   subseg_set (old_section, old_subsection);
 }
 
index 69bd57599e0f998dcc11910ab12e3f5ca296291b..2b3cb6deeb819c5e06166f6d12fefe8e1715ad50 100644 (file)
@@ -4527,7 +4527,7 @@ s_alpha_stringer (int terminate)
 {
   alpha_current_align = 0;
   alpha_insn_label = NULL;
-  stringer (terminate);
+  stringer (8 + terminate);
 }
 
 /* Hook the normal space processing to reset known alignment.  */
index 1c751dbc8323b1425611b5039854122651b2b557..e4291667d67a93b62d0d4eb68d5e1f743a156816 100644 (file)
@@ -1276,7 +1276,7 @@ const pseudo_typeS
 dlx_pseudo_table[] =
 {
   /* Some additional ops that are used by gcc-dlx.  */
-  {"asciiz", stringer, 1},
+  {"asciiz", stringer, 8 + 1},
   {"half", cons, 2},
   {"dword", cons, 8},
   {"word", cons, 4},
index 05c7f12375a5d8a29ba79b7ea36854e190b89ff2..996c0027cf5eabb926171f2d6e2d47ab6745f17e 100644 (file)
@@ -8150,7 +8150,7 @@ pa_stringer (int append_zero)
            }
        }
     }
-  stringer (append_zero);
+  stringer (8 + append_zero);
   pa_undefine_label ();
 }
 
index 04995cc86d68ea3310862b128c20fff0f45c02a8..55f05a4b5a1217c1f7cf16778ce66fc8a6162a84 100644 (file)
@@ -5089,8 +5089,7 @@ dot_xfloat_cons (kind)
 }
 
 static void
-dot_xstringer (zero)
-     int zero;
+dot_xstringer (int zero)
 {
   cross_section (zero, stringer, 0);
 }
@@ -5527,8 +5526,8 @@ const pseudo_typeS md_pseudo_table[] =
     { "xreal8", dot_xfloat_cons, 'd' },
     { "xreal10", dot_xfloat_cons, 'x' },
     { "xreal16", dot_xfloat_cons, 'X' },
-    { "xstring", dot_xstringer, 0 },
-    { "xstringz", dot_xstringer, 1 },
+    { "xstring", dot_xstringer, 8 + 0 },
+    { "xstringz", dot_xstringer, 8 + 1 },
 
     /* unaligned versions:  */
     { "xdata2.ua", dot_xdata_ua, 2 },
@@ -5585,8 +5584,8 @@ pseudo_opcode[] =
     { "real8", stmt_float_cons, 'd' },
     { "real10", stmt_float_cons, 'x' },
     { "real16", stmt_float_cons, 'X' },
-    { "string", stringer, 0 },
-    { "stringz", stringer, 1 },
+    { "string", stringer, 8 + 0 },
+    { "stringz", stringer, 8 + 1 },
 
     /* unaligned versions:  */
     { "data2.ua", stmt_cons_ua, 2 },
index dcd1ce67426114d7fe4d6bfb8a26ad18658c2a9f..b228ea569d4c77687431fd9b3e93015b1e366484 100644 (file)
@@ -263,7 +263,7 @@ const pseudo_typeS md_pseudo_table[] = {
   /* The following pseudo-ops are supported for MRI compatibility.  */
   {"fcb", cons, 1},
   {"fdb", cons, 2},
-  {"fcc", stringer, 1},
+  {"fcc", stringer, 8 + 1},
   {"rmb", s_space, 0},
 
   /* Motorola ALIS.  */
index fa7c911e6851b7184593d92c3dd1658cfd81bd6a..0604ad9042453c6e5445e61a73dff299f217951c 100644 (file)
@@ -411,8 +411,8 @@ const pseudo_typeS md_pseudo_table[] =
      occupy can be taken into account when deciding whether or not to
      dump the current literal pool.
      XXX - currently we do not cope with the .space and .dcb.d directives.  */
-  { "ascii",    mcore_stringer,       0 },
-  { "asciz",    mcore_stringer,       1 },
+  { "ascii",    mcore_stringer,       8 + 0 },
+  { "asciz",    mcore_stringer,       8 + 1 },
   { "byte",     mcore_cons,           1 },
   { "dc",       mcore_cons,           2 },
   { "dc.b",     mcore_cons,           1 },
@@ -430,7 +430,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "quad",     mcore_cons,           8 },
   { "short",    mcore_cons,           2 },
   { "single",   mcore_float_cons,    'f'},
-  { "string",   mcore_stringer,       1 },
+  { "string",   mcore_stringer,       8 + 1 },
   { "word",     mcore_cons,           2 },
   { "fill",     mcore_fill,           0 },
 
index be50025ab128fc4cc9f470d7efd33196cfc97e77..6c6baf0ba3abef1f9307924143433f0f073bd589 100644 (file)
@@ -1109,7 +1109,7 @@ static const pseudo_typeS mips_pseudo_table[] =
 
   /* Relatively generic pseudo-ops that happen to be used on MIPS
      chips.  */
-  {"asciiz", stringer, 1},
+  {"asciiz", stringer, 8 + 1},
   {"bss", s_change_sec, 'b'},
   {"err", s_err, 0},
   {"half", s_cons, 1},
index dc5ca2649dd21d5d387b923d4cfe21e5dba74314..deb7307dbe47d97ec50df68c22466d72f12e5fe8 100644 (file)
@@ -95,7 +95,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "long",    s390_elf_cons,  4 },
   { "quad",     s390_elf_cons,  8 },
   { "ltorg",    s390_literals,  0 },
-  { "string",   stringer,       2 },
+  { "string",   stringer,       8 + 1 },
   { NULL,      NULL,           0 }
 };
 
index f50f716d32c2bcdfd45efa1d6ebf4face8ba8e52..924c6fc20f44f55716d2c63be08fd32a128e8730 100644 (file)
@@ -91,7 +91,7 @@ const pseudo_typeS md_pseudo_table[] =
   {"int", spu_cons, 4},
   {"long", spu_cons, 4},
   {"quad", spu_cons, 8},
-  {"string", stringer, 1},
+  {"string", stringer, 8 + 1},
   {"word", spu_cons, 4},
   /* Force set to be treated as an instruction.  */
   {"set", NULL, 0},
index bf8bab723575de1db6880a56c646391b8c7532c1..a59b272f6038556790fe8808f3ef126f8a50ef8d 100644 (file)
@@ -3776,7 +3776,7 @@ Some machine configurations provide additional directives.
 @menu
 * Abort::                       @code{.abort}
 @ifset COFF
-* ABORT (COFF)::                       @code{.ABORT}
+* ABORT (COFF)::                @code{.ABORT}
 @end ifset
 
 * Align::                       @code{.align @var{abs-expr} , @var{abs-expr}}
@@ -3908,7 +3908,7 @@ Some machine configurations provide additional directives.
 * Stab::                        @code{.stabd, .stabn, .stabs}
 @end ifset
 
-* String::                      @code{.string "@var{str}"}
+* String::                      @code{.string "@var{str}"}, @code{.string8 "@var{str}"}, @code{.string16 "@var{str}"}, @code{.string32 "@var{str}"}, @code{.string64 "@var{str}"}
 * Struct::                     @code{.struct @var{expression}}
 @ifset ELF
 * SubSection::                  @code{.subsection}
@@ -5932,16 +5932,39 @@ All five fields are specified.
 @c end     have-stabs
 
 @node String
-@section @code{.string} "@var{str}"
+@section @code{.string} "@var{str}", @code{.string8} "@var{str}", @code{.string16}
+"@var{str}", @code{.string32} "@var{str}", @code{.string64} "@var{str}" 
 
 @cindex string, copying to object file
+@cindex string8, copying to object file
+@cindex string16, copying to object file
+@cindex string32, copying to object file
+@cindex string64, copying to object file
 @cindex @code{string} directive
+@cindex @code{string8} directive
+@cindex @code{string16} directive
+@cindex @code{string32} directive
+@cindex @code{string64} directive
 
 Copy the characters in @var{str} to the object file.  You may specify more than
 one string to copy, separated by commas.  Unless otherwise specified for a
 particular machine, the assembler marks the end of each string with a 0 byte.
 You can use any of the escape sequences described in @ref{Strings,,Strings}.
 
+The variants @code{string16}, @code{string32} and @code{string64} differ from 
+the @code{string} pseudo opcode in that each 8-bit character from @var{str} is
+copied and expanded to 16, 32 or 64 bits respectively.  The expanded characters
+are stored in target endianness byte order.
+
+Example:
+@smallexample
+       .string32 "BYE"
+expands to:
+       .string   "B\0\0\0Y\0\0\0E\0\0\0"  /* On little endian targets.  */
+       .string   "\0\0\0B\0\0\0Y\0\0\0E"  /* On big endian targets.  */
+@end smallexample
+
+
 @node Struct
 @section @code{.struct @var{expression}}
 
index 4c13d874ede08d42d85b6fa62298645c8d6ab5d5..baf85be39b13fd8b4d22706525e5f1ab110cafb4 100644 (file)
@@ -270,8 +270,8 @@ static const pseudo_typeS potable[] = {
   {"abort", s_abort, 0},
   {"align", s_align_ptwo, 0},
   {"altmacro", s_altmacro, 1},
-  {"ascii", stringer, 0},
-  {"asciz", stringer, 1},
+  {"ascii", stringer, 8+0},
+  {"asciz", stringer, 8+1},
   {"balign", s_align_bytes, 0},
   {"balignw", s_align_bytes, -2},
   {"balignl", s_align_bytes, -4},
@@ -416,7 +416,11 @@ static const pseudo_typeS potable[] = {
   {"stabd", s_stab, 'd'},
   {"stabn", s_stab, 'n'},
   {"stabs", s_stab, 's'},
-  {"string", stringer, 1},
+  {"string", stringer, 8+1},
+  {"string8", stringer, 8+1},
+  {"string16", stringer, 16+1},
+  {"string32", stringer, 32+1},
+  {"string64", stringer, 64+1},
   {"struct", s_struct, 0},
 /* tag  */
   {"text", s_text, 0},
@@ -4961,16 +4965,52 @@ s_leb128 (int sign)
   demand_empty_rest_of_line ();
 }
 \f
-/* We read 0 or more ',' separated, double-quoted strings.
+static void
+stringer_append_char (int c, int bitsize)
+{
+  if (!target_big_endian)
+    FRAG_APPEND_1_CHAR (c);
+
+  switch (bitsize)
+    {
+    case 64:
+      FRAG_APPEND_1_CHAR (0);
+      FRAG_APPEND_1_CHAR (0);
+      FRAG_APPEND_1_CHAR (0);
+      FRAG_APPEND_1_CHAR (0);
+      /* Fall through.  */
+    case 32:
+      FRAG_APPEND_1_CHAR (0);
+      FRAG_APPEND_1_CHAR (0);
+      /* Fall through.  */
+    case 16:
+      FRAG_APPEND_1_CHAR (0);
+      /* Fall through.  */
+    case 8:
+      break;
+    default:
+      /* Called with invalid bitsize argument.  */
+      abort ();
+      break;
+    }
+  if (target_big_endian)
+    FRAG_APPEND_1_CHAR (c);
+}
+
+/* Worker to do .ascii etc statements.
+   Reads 0 or more ',' separated, double-quoted strings.
    Caller should have checked need_pass_2 is FALSE because we don't
-   check it.  */
+   check it.
+   Checks for end-of-line.
+   BITS_APPENDZERO says how many bits are in a target char.
+   The bottom bit is set if a NUL char should be appended to the strings.  */
 
 void
-stringer (/* Worker to do .ascii etc statements.  */
-         /* Checks end-of-line.  */
-         register int append_zero      /* 0: don't append '\0', else 1.  */)
+stringer (int bits_appendzero)
 {
-  register unsigned int c;
+  const int bitsize = bits_appendzero & ~7;
+  const int append_zero = bits_appendzero & 1;
+  unsigned int c;
   char *start;
 
 #ifdef md_flush_pending_output
@@ -5008,14 +5048,13 @@ stringer (/* Worker to do .ascii etc statements.  */
        case '\"':
          ++input_line_pointer; /*->1st char of string.  */
          start = input_line_pointer;
+
          while (is_a_char (c = next_char_of_string ()))
-           {
-             FRAG_APPEND_1_CHAR (c);
-           }
+           stringer_append_char (c, bitsize);
+
          if (append_zero)
-           {
-             FRAG_APPEND_1_CHAR (0);
-           }
+           stringer_append_char (0, bitsize);
+
          know (input_line_pointer[-1] == '\"');
 
 #ifndef NO_LISTING
@@ -5042,11 +5081,10 @@ stringer (/* Worker to do .ascii etc statements.  */
        case '<':
          input_line_pointer++;
          c = get_single_number ();
-         FRAG_APPEND_1_CHAR (c);
+         stringer_append_char (c, bitsize);
          if (*input_line_pointer != '>')
-           {
-             as_bad (_("expected <nn>"));
-           }
+           as_bad (_("expected <nn>"));
+
          input_line_pointer++;
          break;
        case ',':
@@ -5058,7 +5096,7 @@ stringer (/* Worker to do .ascii etc statements.  */
     }
 
   demand_empty_rest_of_line ();
-}                              /* stringer() */
+}
 \f
 /* FIXME-SOMEDAY: I had trouble here on characters with the
     high bits set.  We'll probably also have trouble with
index 7967a1a48a6462bacc7b406cc277384ac21bf694..f2cb037f2393b40bfbb6637b09402601077f7b33 100644 (file)
@@ -1,3 +1,9 @@
+2007-10-04  Helge Deller  <deller@gmx.de>
+
+       * gas/all/gas.exp: Include new test "strings".
+       * gas/all/string.s: New
+       * gas/all/string.d: New.
+
 2007-10-01  Tristan Gingold  <gingold@adacore.com>
 
        * gas/ppc/altivec_xcoff.s: Do not use .machine pseudo-ops as it
index 081c4183bedfc8979773028110186ce6236c6edc..119eeb0b840215417a17be5f77618ab1fbfae8e2 100644 (file)
@@ -297,6 +297,8 @@ gas_test_error "weakref2.s" "" "e: would close weakref loop: e => a => b => c =>
 gas_test_error "weakref3.s" "" "a: would close weakref loop: a => b => c => d => e => a"
 gas_test_error "weakref4.s" "" "is already defined"
 
+run_dump_test string
+
 load_lib gas-dg.exp
 dg-init
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s $srcdir/$subdir/warn-*.s]] "" ""
diff --git a/gas/testsuite/gas/all/string.d b/gas/testsuite/gas/all/string.d
new file mode 100644 (file)
index 0000000..da6177d
--- /dev/null
@@ -0,0 +1,12 @@
+#objdump : -s -j .data -j "\$DATA\$"
+#name : .strings tests
+
+.*: .*
+
+Contents of section (\.data|\$DATA\$):
+ 0000 73747238 00000000 00000000 00000000  str8.*
+ 0010 7374726e 65773800 00000000 00000000  strnew8.*
+ 0020 (73007400 72003100 36000000 00000000|00730074 00720031 00360000 00000000).*
+ 0030 (33000000 32000000 00000000 00000000|00000033 00000032 00000000 00000000).*
+ 0040 (36000000 00000000 34000000 00000000|00000000 00000036 00000000 00000034).*
+#pass
diff --git a/gas/testsuite/gas/all/string.s b/gas/testsuite/gas/all/string.s
new file mode 100644 (file)
index 0000000..80743bb
--- /dev/null
@@ -0,0 +1,14 @@
+       .data
+       .string         "str8"
+
+       .balign 16
+       .string8        "strnew8"
+
+       .balign 16
+       .string16       "str16"
+
+       .balign 16
+       .string32       "32"
+
+       .balign 16
+       .string64       "64"