Page MenuHomeFreeBSD

arm64/disassem.c: Add support insts of shifted register with rsv option
ClosedPublic

Authored by koliagogsadze_gmail.com on May 8 2023, 7:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 9 2024, 7:28 PM
Unknown Object (File)
Feb 9 2024, 7:28 PM
Unknown Object (File)
Jan 5 2024, 10:28 PM
Unknown Object (File)
Dec 25 2023, 5:14 PM
Unknown Object (File)
Dec 22 2023, 9:42 PM
Unknown Object (File)
Dec 12 2023, 10:02 AM
Unknown Object (File)
Nov 28 2023, 6:49 AM
Unknown Object (File)
Nov 26 2023, 8:59 AM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

The wording used by the docs is confusing, but it is actually saying that disassemblers should output the aliases when possible.

For example, we should print cmn x2, #1 rather than adds xzr, x2, #1.

This is the behaviour of GNU and LLVM objdump utilities.

sys/arm64/arm64/disassem.c
156–158

I believe it will be sufficient to add the alias like this, since we walk the list front-to-back, it will be matched first.

The wording used by the docs is confusing, but it is actually saying that disassemblers should output the aliases when possible.

For example, we should print cmn x2, #1 rather than adds xzr, x2, #1.

This is the behaviour of GNU and LLVM objdump utilities.

understood, thanks!

sys/arm64/arm64/disassem.c
156–158

Unfortunatelly, we can't do like this, because in case of TYPE_01 we read RD and RN registers as "Mandatory tokens" via arm64_disasm_read_token function:

ret = arm64_disasm_read_token(i_ptr, insn, "RD", &rd);
ret |= arm64_disasm_read_token(i_ptr, insn, "RN", &rn);

if we just use constant (e.g. 11111) instead of RD(5) or RN(5) we will get error message:

printf("ERROR: "
    "Missing mandatory token for op %s type %d\n",
    i_ptr->name, i_ptr->type);

I was considering introducing OP_ flags, I think it's possible to do it in this type, but we have to properly handle conditions with current logic, cases like:
we have to take into account OP_ flags that indicates RD or RN is 11111.

Distinguish when we only have RD or only RN with RM, and remember that RM can be missing like this

OP <RD>, <RN>, #<imm>{, <shift [0, 12]>} SF32/64

I think adding new patterns will complicate the TYPE_1 logic and make it harder to read/maintain, so the second approach is to introduce a new type TYPE_04

What do you think?

sys/arm64/arm64/disassem.c
156–158

second approach patch:

sys/arm64/arm64/disassem.c
156–158

Okay, that is indeed a problem. I like your second solution, it is clean enough.

I do not think that the "mandatory token" checks are very important, because the only way they can be triggered is when a disassembly mask is incorrectly defined. In other words, once the author (you) has correctly defined the entry in arm64_i[], these error messages will never be emitted.

So, it might be possible to remove these checks, and make all of rd, rm, and rn optional for TYPE_01. If it works and is not too messy I would prefer that to adding a whole new TYPE, but maybe there is something I am overlooking.

sys/arm64/arm64/disassem.c
156–158

I removed these checks in TYPE_01. We should check that we have rd and rn, if they are present, then we will use these patterns:

OP <RD>, <RN>, <RM>{, <shift [LSL, LSR, ASR]> #<imm>} SF32/64
OP <RD>, <RN>, #<imm>{, <shift [0, 12]>} SF32/64

if we have either only RD or only RN, we will use:

OP <RD>, <RM> {, <shift> #<imm> }
OP <RN>, <RM> {, <shift> #<imm> }

We do not change the RM logic, because it is the same and it is last register in the patterns:

OP <RD>, <RN>, <RM>{, <shift [LSL, LSR, ASR]> #<imm>} SF32/64
OP <RD>, <RM> {, <shift> #<imm> }
OP <RN>, <RM> {, <shift> #<imm> }

patch:

in this case we added few checks and removed validation on "mandatory token", so this looks like a minimal change to me and does not complicate the logic too much, now I think that it's better suited than adding a new type, what do you think?

sys/arm64/arm64/disassem.c
156–158

Yes, the result is excellent! Please go ahead and update this review with the new approach.

Looks good, one thing to fix.

sys/arm64/arm64/disassem.c
416

Consider changing these to bool type. Maybe it needs to be a separate change to handle arm64_disasm_read_token() return value. Either way it is not critical.

494

Since these are effectively boolean values, we should check this way.

497

Updated type of rm_absent, rd_absent, rn_absent to bool.

Thanks. I will commit this and D39820 today or tomorrow.

This revision is now accepted and ready to land.May 22 2023, 1:14 PM