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

[ARM-semantic] Implement carry flag for basic shifters #1456

Open
W0ni opened this issue Sep 5, 2023 · 2 comments
Open

[ARM-semantic] Implement carry flag for basic shifters #1456

W0ni opened this issue Sep 5, 2023 · 2 comments

Comments

@W0ni
Copy link
Contributor

W0ni commented Sep 5, 2023

Modified instructions:

  • ASRS, LSLS, LSRS, RORS, RRXS
  • MOVS, MVNS with shifter

For the shift and rotate instructions, the carry flag could be implemented similarly to x86, using another block to handle the zero shift case.

See: https://developer.arm.com/documentation/ddi0597/2023-06/Base-Instructions/MOV--MOVS--register---Move--register--?lang=en

@W0ni W0ni changed the title Implement carry flag for basic shifters [ARM-semantic] Implement carry flag for basic shifters Sep 5, 2023
@serpilliere
Copy link
Contributor

Hi @W0ni
Maybe I have missed something, but it seems the flags are present and modified for those instructions:
in miasm/arch/arm/sem.py:

def rors(ir, instr, a, b):
    e = []
    r = ExprOp(">>>", a, b)
    e.append(ExprAssign(a, r))

    e += [ExprAssign(zf, ExprOp('FLAG_EQ', r))]
    e += update_flag_nf(r)

    dst = get_dst(a)
    if dst is not None:
        e.append(ExprAssign(ir.IRDst, r))
    return e, []
...

def asrs(ir, instr, a, b, c=None):
    e = []
    if c is None:
        b, c = a, b
    r = ExprOp("a>>", b, c)
    e.append(ExprAssign(a, r))

    e += [ExprAssign(zf, ExprOp('FLAG_EQ', r))]
    e += update_flag_nf(r)

    dst = get_dst(a)
    if dst is not None:
        e.append(ExprAssign(ir.IRDst, r))
    return e, []
...

@W0ni
Copy link
Contributor Author

W0ni commented Sep 5, 2023

Hey @serpilliere !

Indeed, the N and Z flags are correctly modified by this code. However, these instructions should also modify the C flag according to this documentation: https://developer.arm.com/documentation/ddi0597/2023-06/Base-Instructions/MOV--MOVS--register---Move--register--?lang=en

If the shift is 0, the carry flag is not affected. If it's not 0, a new block is required to compute the carry flag.

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

2 participants