Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPC - Branch absolute target restricted to 26/16 bits #423

Closed
EdwardLarson opened this issue Jul 15, 2019 · 1 comment
Closed

PPC - Branch absolute target restricted to 26/16 bits #423

EdwardLarson opened this issue Jul 15, 2019 · 1 comment

Comments

@EdwardLarson
Copy link
Contributor

For all branch instructions, the target address is passed in as the absolute address (see issue #108). Any address higher than 0x1fffffc throws an "Invalid Operand" error:

/# kstool ppc32be "b 0x1fffffc"
b 0x1fffffc = [ 49 ff ff fc ]
/# kstool ppc32be "b 0x2000000"
ERROR: failed on ks_asm() with count = 0, error = 'Invalid operand (KS_ERR_ASM_INVALIDOPERAND)' (code = 512)

This issue is present on ppc64, ppc64be, and ppc32be.

This behavior appears to be caused by a check that the target address fits the 26-bit limit for unconditional branch targets (16 bits for conditional). However for relative-offset branch instructions it is the offset which is restricted to 26/16 bits, not the target address. For example, the below is a valid branch to an instruction only 8 bytes ahead. The offset which will be encoded, 0x8, is well within the 26-bit limit, however since the target address is more than 26 bits wide, keystone fails:

/# kstool ppc32be "b 0x2000008" 0x2000000
ERROR: failed on ks_asm() with count = 0, error = 'Invalid operand (KS_ERR_ASM_INVALIDOPERAND)' (code = 512)

The expected behavior is that, like other architectures' implementations, keystone does not try to enforce range bounds at all. For example, in ARM64 the max branch range is 2**27 - 4 (0x7fffffc), but keystone will not enforce this limit:

/# kstool arm64 "b 0x1ffffffffffffffc" 0
b 0x1ffffffffffffffc = [ ff ff ff 17 ]
@EdwardLarson
Copy link
Contributor Author

Long-resolved with #428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant