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
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-11 06:10 IST by Andrew Church
Modified: 2018-01-25 16:41 IST (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

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 IST
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 IST
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 ?