Skip to content

Conversation

@moste00
Copy link
Contributor

@moste00 moste00 commented Jul 16, 2025

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

This PR is attempting to refactor the RISCV architecture to be updatable from the Auto-Sync tool, such that it automatically follows RISCV-in-LLVM additions and fixes. Following the refactoring guide

depends-on: capstone-engine/llvm-capstone#83

Test plan

...

Closing issues

...

if (SysReg && SysReg->haveRequiredFeatures(STI.getFeatureBits()))
SStream_concat0(markup(O, Markup_Register), SysReg->Name);
else
SStream_concat0(markup(O, Markup_Register), formatImm(Imm));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, better get rid of these formatImm calls. Otherwise we have two places to take care of formatting and everything gets less consistent.

@Rot127
Copy link
Collaborator

Rot127 commented Aug 14, 2025

cc @hainest You are probably aware of this PR, just wanted to ping you as well. Because you mentioned in the Zydis discussion you use Capstone for RISCV as well.

@hainest
Copy link
Contributor

hainest commented Aug 14, 2025

cc @hainest You are probably aware of this PR, just wanted to ping you as well. Because you mentioned in the Zydis discussion you use Capstone for RISCV as well.

I had not seen this. @wxrdnx have you looked at this?

Comment on lines 188 to 189
{ .str = "riscv32", .val = CS_MODE_RISCV32 },
{ .str = "riscv64", .val = CS_MODE_RISCV64 },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In response to above. Please stick with the Capstone flag naming convention.
Is RSICV32 is anything else than just 32bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a point, but I don't know, RISCV[32|64] and RISCVC were legacy flags that were already in the old plugin, so I kept them.

Removing them would probably not affect anything but just be a hassle, it could also be the case that the generated code references them from lots of places and changing the generated code is always a hassle.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generated code references them

Which one? The test files from the MCUpdater? Those ones can be replaced as described here #2756 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rot127 sorry for the late reply, yes, only the yaml MC tests reference those values, plus a few references in handwritten code in the cstool.c and so on, so it's doable to replace them, will do.

Although this might break APIs, because I see some Python usage from my editor search, until now I have avoided deleting enum members from includes/riscv.h, that's why we still have CS_MODE_RISCV_C and CS_MODE_RISCVC.

@Rot127 Rot127 added this to the v6 - Beta milestone Sep 1, 2025
@Rot127 Rot127 added the blocker Must be finished with the assigned milestone. label Sep 1, 2025
Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check out the helper functions in Mapping.h. They should always be used for these tasks. Because they do bounds checking and such. Accessing the struct members directly (e.g. like details->groups[details->groups_count]) should be the absolute exception, not the rule.

You can also see how the helpers are used in other architectures and just do it the same way. LoongArch is a good example, because it is relatively simple.
AArch64 has many very complex operands. You can check its code if you need examples for these cases.

@Rot127
Copy link
Collaborator

Rot127 commented Sep 17, 2025

The conflicts are coming from the clang-format formatting we did recently btw. So nothing to preserve there.
You can just accept all your changes.

@moste00 moste00 force-pushed the refactor_riscv_autosync branch from 12882dc to 1d59145 Compare October 17, 2025 01:16
@moste00 moste00 marked this pull request as ready for review October 17, 2025 01:19
@github-actions github-actions bot added the Python Bindings label Nov 14, 2025
@moste00 moste00 force-pushed the refactor_riscv_autosync branch 2 times, most recently from 0e5a2a8 to f99aa52 Compare November 15, 2025 22:28
@moste00 moste00 force-pushed the refactor_riscv_autosync branch from 96b38b1 to 6b3d2f0 Compare December 23, 2025 21:58
Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moste00 One exceptionally important thing still missing is the documentation in the v6 release guide. It is the first thing we will send people to for questions.

…t broke due to fixing it, add command line switches to turn on and off ZB* and ZBK* extensions
@moste00 moste00 mentioned this pull request Jan 10, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Sync-files Auto-Sync blocker Must be finished with the assigned milestone. CS-core-files auto-sync LLVM-core-files auto-sync LLVM-generated-files Python Bindings RISCV Arch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants