Bug 22699 - sh*: Immediate signedness is incorrect in and/or/tst/xor #imm
Summary: sh*: Immediate signedness is incorrect in and/or/tst/xor #imm
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2018-01-11 06:10 UTC by Andrew Church
Modified: 2018-01-25 16:41 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Church 2018-01-11 06:10:53 UTC
When objdump disassembles SuperH (sh2, sh4, etc.) instructions of the form "AND/OR/TST/XOR #imm,R0", it treats the immediate as a signed 8-bit value, but in fact the value is unsigned.

To reproduce: echo 'tst #128,r0' |sh4-as -o foo.o; sh4-objdump -d foo.o

Expected output:
   0:   80 c8           tst     #128,r0

Actual output:
   0:   80 c8           tst     #-128,r0
Comment 1 fenugrec 2018-01-25 16:41:21 UTC
Correct. To recap:

1) some opcodes need the sign-extended 8-bit immediate value:
- add #imm, Rn (OK)
- cmp/eq #imm, R0 (OK)
- mov #imm, Rn (OK)

2) others take the zero-extended imm8 :
- bitwise logic operators {and, and.b,...} : broken
- trapa : broken

3) some I haven't personally checked :
- ldrc / setrc
- other DSP , SH2A, SH4A opcodes

I would suggest reworking the relevant entries in opcodes/sh-opc.h (maybe replace IMM0_8 by IMM0_8S and IMM0_8U to ensure every occurence is verified manually; and add the proper handling in opcodes/sh-dis.c

Is there a regression test for this already ?