diff options
-rw-r--r-- | opcodes/ChangeLog | 5 | ||||
-rw-r--r-- | opcodes/v850-dis.c | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 3ba885c..2ad26cb 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,5 +1,10 @@ 2019-12-11 Alan Modra <amodra@gmail.com> + * v850-dis.c (get_operand_value): Use unsigned arithmetic. Don't + sign extend using shifts. + +2019-12-11 Alan Modra <amodra@gmail.com> + * tic6x-dis.c (tic6x_extract_32): Avoid signed overflow. 2019-12-11 Alan Modra <amodra@gmail.com> diff --git a/opcodes/v850-dis.c b/opcodes/v850-dis.c index f8b5d1c..45e6c65 100644 --- a/opcodes/v850-dis.c +++ b/opcodes/v850-dis.c @@ -88,7 +88,7 @@ get_operand_value (const struct v850_operand *operand, bfd_boolean noerror, int *invalid) { - long value; + unsigned long value; bfd_byte buffer[4]; if ((operand->flags & V850E_IMMEDIATE16) @@ -158,11 +158,13 @@ get_operand_value (const struct v850_operand *operand, if (operand->bits == -1) value = (insn & operand->shift); else - value = (insn >> operand->shift) & ((1 << operand->bits) - 1); + value = (insn >> operand->shift) & ((1ul << operand->bits) - 1); if (operand->flags & V850_OPERAND_SIGNED) - value = ((long)(value << (sizeof (long)*8 - operand->bits)) - >> (sizeof (long)*8 - operand->bits)); + { + unsigned long sign = 1ul << (operand->bits - 1); + value = (value ^ sign) - sign; + } } return value; |