Skip to content

Conversation

moste00
Copy link

@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

...

…son, and riscv.h comments for generated content added
SStream_concat0(markup(O, Markup_Register), "x18");
}
break;
case RISCVZC_RLISTENCODE::RA_S0_S3:
Copy link
Collaborator

Choose a reason for hiding this comment

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

These namespace specifiers should have been replaced by AS. This might be a bug.


if (PrintBranchImmAsAddress) {
uint64_t Target = Address + MCOperand_getImm(MO);
if (!STI.hasFeature(RISCV_Feature64Bit))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The STI.hasFeature should probably be automated away as well.
You can check the STIFeatureBits patch and just copy and adapt it if you have some time.

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.

// which will not print trailing zeros and will use scientific notation
// if it is shorter than printing as a decimal. The smallest value requires
// 12 digits of precision including the decimal.
if (FPVal == (int)(FPVal))
Copy link
Collaborator

@Rot127 Rot127 Jul 25, 2025

Choose a reason for hiding this comment

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

I'd need to check the standard, but casting an float to an integer just rounds it up/down.
Please just use the SStream function for printing it.

@github-actions github-actions bot added the CS-core-files auto-sync label Jul 26, 2025
@github-actions github-actions bot added the LLVM-core-files auto-sync label Aug 1, 2025
@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?

…ated, it doesn't compile yet but is mostly valid C except for a few problems
input:
bytes: [ 0xdb, 0x52, 0x03, 0xa0 ]
arch: "CS_ARCH_RISCV"
options: [ "riscv32", "xcvmac" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
options: [ "riscv32", "xcvmac" ]
options: [ "riscv32", "xcvmac" ]

These riscv32 should be mapped to CS_MODE_32

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?

Comment on lines +202 to +205
CS_MODE_RISCVFD = 1 << 3,
CS_MODE_RISCVV = 1 << 4,
CS_MODE_RISCVZFINX = 1 << 5,
CS_MODE_RISCVZCMP_ZCMT_ZCE = 1 << 6,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest to add a _ after RISCV for better readability.
CS_MODE_RISCV_FD

{ .str = "riscv64", .val = CS_MODE_RISCV64 },
{ .str = "v" , .val = CS_MODE_RISCVV },
{ .str = "zce" , .val = CS_MODE_RISCVZCMP_ZCMT_ZCE},
{ .str = "zcmp" , .val = CS_MODE_RISCVZCMP_ZCMT_ZCE},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use CS_MODE_RISCV_ZCMP, CS_MODE_RISCV_F etc.

You can map the feature names passed to llvm-mc via -mattr with the "replace_option_map" object in mcupdater.json.
This way it is replaced automatically when generating.

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

Successfully merging this pull request may close these issues.

3 participants