File s390-fix-disassembly-of-optional-addressing-operands.patch of Package gdb
From 708495beae38a6b5c265a3865f38d2be79414a63 Mon Sep 17 00:00:00 2001
From: Jens Remus <jremus@linux.ibm.com>
Date: Fri, 7 Mar 2025 13:06:53 +0100
Subject: [PATCH 08/10] s390: Fix disassembly of optional addressing operands
"nop D1(B1)" erroneously disassembled into "nop D1(B1" (missing
closing parenthesis). "nop D1(X1,0)" and "nop D1(X1,)" erroneously
disassembled into "nop D1(X1)" (missing zero base register) instead
of "nop D1(X1,0)".
Do not skip disassembly of optional operands if they are index (X)
or base (B) registers or length (L) in an addressing operand sequence
"D(X,B)", "D(B)", or "D(L,B). Index and base register operand values
of zero are being handled separately, as they may not be omitted
unconditionally. For instance a base register value of zero must be
printed in above mentioned case, to distinguish the index from the
base register. This also ensures proper formatting of addressing
operand sequences.
While at it add further test cases for instructions with optional
operands.
opcodes/
* s390-dis.c (s390_print_insn_with_opcode): Do not
unconditionally skip disassembly of optional operands with a
value of zero, if within an addressing operand sequence.
gas/testsuite/
* gas/s390/zarch-optargs.d: Add further test cases for
instructions with optional operands.
* gas/s390/zarch-optargs.s: Likewise.
Reported-by: Florian Krohm <flo2030@eich-krohm.de>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
(cherry picked from commit 7507fe37980)
(cherry pick dropped: gas/testsuite/gas/s390/zarch-optargs.d)
(cherry pick dropped: gas/testsuite/gas/s390/zarch-optargs.s)
---
opcodes/s390-dis.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 852d2f6ebb9..1a23afc8f40 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -214,20 +214,29 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
continue;
}
- /* For instructions with a last optional operand don't print it
- if zero. */
- 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)
+ /* Omit optional last operands with a value of zero, except if
+ within an addressing operand sequence D(X,B), D(B), and D(L,B).
+ Index and base register operands with a value of zero are
+ handled separately, as they may not be omitted unconditionally. */
+ if (!(operand->flags & (S390_OPERAND_BASE
+ | S390_OPERAND_INDEX
+ | S390_OPERAND_LENGTH)))
{
- union operand_value next_op_val =
- s390_extract_operand (buffer, s390_operands + opindex[1]);
- if (next_op_val.u == 0)
+ 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)
@@ -312,6 +321,7 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
&& val.u == 0
&& opindex[1] == 0)
break;
+
info->fprintf_styled_func (info->stream, dis_style_text,
"%c", separator);
style = ((flags & S390_OPERAND_DISP)
--
2.43.0