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

Incorrect instruction encoding on AArch64 when using xzr as the destination register #49

Closed
losfair opened this issue Nov 15, 2020 · 4 comments
Labels

Comments

@losfair
Copy link

losfair commented Nov 15, 2020

Hi,

I'm trying to generate some code like:

        dynasm!(self.a
            ; .arch aarch64
            ; add X(31), X(1), 1
        );

Dynasm successfully assembles this without reporting an error. However, the assembled code is:

add     sp, x1, #0x1

Which is incorrect according to the documentation that specifies only the dynamic encoding prefix XSP should encode a sp operand.

Is something like add xzr, x1, #0x1 unencodable? If that's the case, maybe dynasm should return an error instead of generating sp silently.

@CensoredUsername
Copy link
Owner

add xzr, x1, #0x1 is indeed unencodable, as can be seen in the instruction reference where the relevant format (two regs and an immediate) specifies:

add Xn|SP, Xm|SP, #uimm {, LSL #uimm1 }                         (#uimm < 4096, #uimm1 = [0, 12])

You're right that using an X dynamic register instead of an XSP dynamic register shouldn't allow this instruction to match at all, so something is going wrong here. I'll investigate.

@CensoredUsername
Copy link
Owner

Found the bug, that part of the code also allows non-XSP family registers through so normal registers that aren't the zero reg can be used. This exemption is needed for static registers (what family is X1, X or XSP), but it doesn't actually check that they're static so dynamic regs get a pass as well.

Easy fix, but will break working user code so probably have to cut a new release for this.

@CensoredUsername
Copy link
Owner

In the meantime you can try this fix at 83743bf.

@CensoredUsername
Copy link
Owner

This has been merged into master with v2.0.0.

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

No branches or pull requests

2 participants