+ /* Check for special long displacement case. */
+ if (operand->bits == 20 && operand->shift == 20)
+ val = (val & 0xff) << 12 | (val & 0xfff00) >> 8;
+
+ /* Sign extend value if the operand is signed or pc relative. Avoid
+ integer overflows. */
+ if (operand->flags & (S390_OPERAND_SIGNED | S390_OPERAND_PCREL))
+ {
+ unsigned int m = 1U << (operand->bits - 1);
+
+ if (val >= m)
+ ret.i = (int) (val - m) - 1 - (int) (m - 1U);
+ else
+ ret.i = (int) val;
+ }
+ else if (operand->flags & S390_OPERAND_LENGTH)
+ /* Length x in an instruction has real length x + 1. */
+ ret.u = val + 1;
+ else
+ ret.u = val;
+
+ return ret;
+}
+
+/* Print the S390 instruction in BUFFER, assuming that it matches the
+ given OPCODE. */
+
+static void
+s390_print_insn_with_opcode (bfd_vma memaddr,
+ struct disassemble_info *info,
+ const bfd_byte *buffer,
+ const struct s390_opcode *opcode)
+{
+ const unsigned char *opindex;
+ char separator;
+
+ /* Mnemonic. */
+ info->fprintf_func (info->stream, "%s", opcode->name);
+
+ /* Operands. */
+ separator = '\t';
+ for (opindex = opcode->operands; *opindex != 0; opindex++)
+ {
+ const struct s390_operand *operand = s390_operands + *opindex;
+ union operand_value val = s390_extract_operand (buffer, operand);
+ unsigned long flags = operand->flags;
+
+ if ((flags & S390_OPERAND_INDEX) && val.u == 0)
+ continue;
+ if ((flags & S390_OPERAND_BASE) &&
+ val.u == 0 && separator == '(')
+ {
+ separator = ',';
+ continue;
+ }
+
+ info->fprintf_func (info->stream, "%c", separator);
+
+ if (flags & S390_OPERAND_GPR)
+ info->fprintf_func (info->stream, "%%r%u", val.u);
+ else if (flags & S390_OPERAND_FPR)
+ info->fprintf_func (info->stream, "%%f%u", val.u);
+ else if (flags & S390_OPERAND_AR)
+ info->fprintf_func (info->stream, "%%a%u", val.u);
+ else if (flags & S390_OPERAND_CR)
+ info->fprintf_func (info->stream, "%%c%u", val.u);
+ else if (flags & S390_OPERAND_PCREL)
+ info->print_address_func (memaddr + val.i + val.i, info);
+ else if (flags & S390_OPERAND_SIGNED)
+ info->fprintf_func (info->stream, "%i", val.i);
+ else
+ info->fprintf_func (info->stream, "%u", val.u);
+
+ if (flags & S390_OPERAND_DISP)
+ separator = '(';
+ else if (flags & S390_OPERAND_BASE)
+ {
+ info->fprintf_func (info->stream, ")");
+ separator = ',';
+ }
+ else
+ separator = ',';
+ }
+}