Ghidra: SH2-A decompile issue with exts.b instruction

Created on 25 Sep 2019  路  4Comments  路  Source: NationalSecurityAgency/ghidra

Describe the bug
I have some code using the the exts.b instruction (extend sign byte):

        06006706 b0 4d           bsr        loadOverlay                                                  int loadOverlay(void)
        06006708 64 e3           _mov       r14,r4
        0600670a 60 0e           exts.b     r0,r0
        0600670c 20 08           tst        r0,r0
        0600670e 8b 15           bf         LAB_0600673c
        06006710 e3 01           mov        0x1,r3
        06006712 a0 13           bra        LAB_0600673c
        06006714 2e 31           _mov.w     r3,@r14

The decompilation generated is:

  iVar1 = loadOverlay();
  iVar1 = (int)(char)((uint)iVar1 >> 8);
  if (iVar1 != 0) {
    return iVar1;
  }
  *psParm1 = 1;

Now what is very unclear to me is where the >> 8 come from. loadOverlay is setup to return an int.

ProcessoSuperH Bug

Most helpful comment

@yaz0r good eye. Looks like the exts.b and exts.w had a syntax issue and were accidentally masking off the low byte(s) instead of sign extending them. This PR should fix

All 4 comments

@VGKintsugi might be interesting to you?

@yaz0r good eye. Looks like the exts.b and exts.w had a syntax issue and were accidentally masking off the low byte(s) instead of sign extending them. This PR should fix

Gave the PR a shot, worked great. Thanks!

Thanks @mumbel

Was this page helpful?
0 / 5 - 0 ratings

Related issues

astrelsky picture astrelsky  路  3Comments

rrivera1849 picture rrivera1849  路  3Comments

0x6d696368 picture 0x6d696368  路  3Comments

ghost picture ghost  路  3Comments

astrelsky picture astrelsky  路  3Comments