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

mos65xx: use address on mem operands for relative addressing #1702

Merged
merged 3 commits into from
Mar 10, 2021

Conversation

zydeco
Copy link
Contributor

@zydeco zydeco commented Nov 15, 2020

This changes how the mem field is used in relative addressing:

Previously, the last operand would show the offset as it's encoded in the instruction, instead of the address, which doesn't match what is printed:

0x1010:	bpl	$1010
	address mode: relative
	modifies flags: false
	op_count: 1
		operands[0].type: MEM = 0xfe

0x1012:	bbr0	$12, $1012
	address mode: relative bit branch
	modifies flags: false
	op_count: 2
		operands[0].type: MEM = 0x12
		operands[1].type: MEM = 0xfd

Now, it shows the matching address for all operands:

0x1010:	bpl	$1010
	address mode: relative
	modifies flags: false
	op_count: 1
		operands[0].type: MEM = 0x1010

0x1012:	bbr0	$12, $1012
	address mode: relative bit branch
	modifies flags: false
	op_count: 2
		operands[0].type: MEM = 0x12
		operands[1].type: MEM = 0x1012

An alternative to this solution would be using a different operand type (not MEM) for relative addressing, or using a structure to indicate if the address is absolute or relative.

Also, a small fix of setting imm instead of mem, which would return wrong values when running on big endian hosts.

using the wrong field works on little-endian hosts, but on big-endian the wrong value would be read
previously the last operand would have an offset, which doesn't match the printed operand
this demonstrates an address operand with relative addressing
@zydeco
Copy link
Contributor Author

zydeco commented Nov 15, 2020

Looks like the fuzz test is failing due to the fancy quotes in long_desc in bindings/python/setup.py on the v4 branch:
https://github.com/aquynh/capstone/blob/b183f152acd265a5728cfd587e3fd5108ac0f9f8/bindings/python/setup.py#L222

@pranith
Copy link
Contributor

pranith commented Mar 4, 2021

Can you please create a new PR on libcapstone?

@aquynh
Copy link
Collaborator

aquynh commented Mar 7, 2021

@s-macke please can you ack?

@s-macke
Copy link
Contributor

s-macke commented Mar 9, 2021

The first commit fixes one obvious bug.

For the second commit I compared the current output with other architectures. They all use absolute addresses for relative branches. So the commit if fine for me.

Acknowledged

@aquynh aquynh merged commit baa1f94 into capstone-engine:next Mar 10, 2021
@aquynh
Copy link
Collaborator

aquynh commented Mar 10, 2021

merged, thanks!

@riptl riptl mentioned this pull request Jul 22, 2022
6 tasks
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

Successfully merging this pull request may close these issues.

None yet

4 participants