/* s390-dis.c -- Disassemble S390 instructions
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2020 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
This file is part of the GNU opcodes library.
#include "sysdep.h"
#include <stdio.h>
#include "ansidecl.h"
-#include "dis-asm.h"
+#include "disassemble.h"
#include "opintl.h"
#include "opcode/s390.h"
+#include "libiberty.h"
-static int init_flag = 0;
static int opc_index[256];
static int current_arch_mask = 0;
static int option_use_insn_len_bits_p = 0;
+typedef struct
+{
+ const char *name;
+ const char *description;
+} s390_options_t;
+
+static const s390_options_t options[] =
+{
+ { "esa" , N_("Disassemble in ESA architecture mode") },
+ { "zarch", N_("Disassemble in z/Architecture mode") },
+ { "insnlength", N_("Print unknown instructions according to "
+ "length from first two bits") }
+};
+
/* Set up index table for first opcode byte. */
-static void
-init_disasm (struct disassemble_info *info)
+void
+disassemble_init_s390 (struct disassemble_info *info)
{
int i;
const char *p;
for (i = s390_num_opcodes; i--; )
opc_index[s390_opcodes[i].opcode[0]] = i;
+ current_arch_mask = 1 << S390_OPCODE_ZARCH;
+ option_use_insn_len_bits_p = 0;
+
for (p = info->disassembler_options; p != NULL; )
{
if (CONST_STRNEQ (p, "esa"))
else if (CONST_STRNEQ (p, "insnlength"))
option_use_insn_len_bits_p = 1;
else
- fprintf (stderr, "Unknown S/390 disassembler option: %s\n", p);
+ /* xgettext:c-format */
+ opcodes_error_handler (_("unknown S/390 disassembler option: %s"), p);
p = strchr (p, ',');
if (p != NULL)
p++;
}
-
- if (!current_arch_mask)
- current_arch_mask = 1 << S390_OPCODE_ZARCH;
-
- init_flag = 1;
}
/* Derive the length of an instruction from its first byte. */
/* For instructions with a last optional operand don't print it
if zero. */
- if ((opcode->flags & S390_INSTR_FLAG_OPTPARM)
+ if ((opcode->flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2))
&& val.u == 0
&& opindex[1] == 0)
break;
+ if ((opcode->flags & S390_INSTR_FLAG_OPTPARM2)
+ && val.u == 0 && opindex[1] != 0 && opindex[2] == 0)
+ {
+ union operand_value next_op_val =
+ s390_extract_operand (buffer, s390_operands + opindex[1]);
+ if (next_op_val.u == 0)
+ break;
+ }
+
if (flags & S390_OPERAND_GPR)
info->fprintf_func (info->stream, "%c%%r%u", separator, val.u);
else if (flags & S390_OPERAND_FPR)
unsigned int value;
int status, opsize, bufsize, bytes_to_dump, i;
- if (init_flag == 0)
- init_disasm (info);
-
/* The output looks better if we put 6 bytes on a line. */
info->bytes_per_line = 6;
return 0;
}
+const disasm_options_and_args_t *
+disassembler_options_s390 (void)
+{
+ static disasm_options_and_args_t *opts_and_args;
+
+ if (opts_and_args == NULL)
+ {
+ size_t i, num_options = ARRAY_SIZE (options);
+ disasm_options_t *opts;
+
+ opts_and_args = XNEW (disasm_options_and_args_t);
+ opts_and_args->args = NULL;
+
+ opts = &opts_and_args->options;
+ opts->name = XNEWVEC (const char *, num_options + 1);
+ opts->description = XNEWVEC (const char *, num_options + 1);
+ opts->arg = NULL;
+ for (i = 0; i < num_options; i++)
+ {
+ opts->name[i] = options[i].name;
+ opts->description[i] = _(options[i].description);
+ }
+ /* The array we return must be NULL terminated. */
+ opts->name[i] = NULL;
+ opts->description[i] = NULL;
+ }
+
+ return opts_and_args;
+}
+
void
print_s390_disassembler_options (FILE *stream)
{
+ unsigned int i, max_len = 0;
fprintf (stream, _("\n\
The following S/390 specific disassembler options are supported for use\n\
with the -M switch (multiple options should be separated by commas):\n"));
- fprintf (stream, _(" esa Disassemble in ESA architecture mode\n"));
- fprintf (stream, _(" zarch Disassemble in z/Architecture mode\n"));
- fprintf (stream, _(" insnlength Print unknown instructions according "
- "to length from first two bits\n"));
+ for (i = 0; i < ARRAY_SIZE (options); i++)
+ {
+ unsigned int len = strlen (options[i].name);
+ if (max_len < len)
+ max_len = len;
+ }
+
+ for (i = 0, max_len++; i < ARRAY_SIZE (options); i++)
+ fprintf (stream, " %s%*c %s\n",
+ options[i].name,
+ (int)(max_len - strlen (options[i].name)), ' ',
+ _(options[i].description));
}