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

target/riscv: allow hexadecimal values to expose_csr-like commands #1162

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

aap-sc
Copy link
Collaborator

@aap-sc aap-sc commented Nov 9, 2024

No description provided.

@aap-sc aap-sc requested review from JanMatCodasip and en-sc November 9, 2024 21:05
Copy link
Collaborator

@TommyMurphyTM1234 TommyMurphyTM1234 left a comment

Choose a reason for hiding this comment

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

Small comments

src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@aap-sc aap-sc force-pushed the aap-sc/csr_as_hex branch 5 times, most recently from 6f88874 to 92532db Compare November 11, 2024 11:12
en-sc
en-sc previously approved these changes Nov 11, 2024
Copy link
Collaborator

@en-sc en-sc left a comment

Choose a reason for hiding this comment

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

LGTM (reviewed internally).

@JanMatCodasip
Copy link
Collaborator

I will be able to review this change by the end of the week.

JanMatCodasip
JanMatCodasip previously approved these changes Nov 15, 2024
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

I am sending one optional suggestion and one general comment.

src/target/riscv/riscv.c Show resolved Hide resolved
src/target/riscv/riscv.c Show resolved Hide resolved
@zqb-all
Copy link
Contributor

zqb-all commented Nov 18, 2024

LGTM, I wanted this feature too but haven't really put in the time to implement it yet, thank you for implementing it

@aap-sc aap-sc dismissed stale reviews from JanMatCodasip and en-sc via 13bc1fa November 19, 2024 02:18
@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 19, 2024

Note to reviewers:

the following checks were added in most recent update:

...
		/* If we are here and register address string starts with zero, this is
		 * an indication that most likely user has an incorrect input because:
		 * - decimal numbers typically do not start with "0"
		 * - octals are not supported by our interface
		 * - hexadecimal numbers should have "0x" prefix
		 * Thus such input is rejected. */
		if (strncmp(reg_address_str, "0", 1) == 0 && strlen(reg_address_str) > 1)
			return false;
...

Would you kindly take a look?

@TommyMurphyTM1234
Copy link
Collaborator

Note to reviewers:

the following checks were added in most recent update:

...
		/* If we are here and register address string starts with zero, this is
		 * an indication that most likely user has an incorrect input because:

This comment seems a bit misleading because in the code there is a prior explicit check for 0x prefix, so a register number starting with 0 IS valid, if the next character is x/X.

On a more general point, why not just allow decimal numbers that start with 0(s)? Might not somebody legitimately use a Tcl script that generates register numbers of a similar form as generated by C's printf("04%u", x); padded with leading 0s? Why go to the bother of explicitly excluding such number representation? Do many people actually try to use octal representation in such circumstances?

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 19, 2024

This comment seems a bit misleading because in the code there is a prior explicit check for 0x prefix, so a register number starting with 0 IS valid, if the next character is x/X.

But there is a precondition: "If we are here". Meaning we've already checked for hexadecimal numbers a few lines above.

On a more general point, why not just allow decimal numbers that start with 0(s)?

Because it suspiciously looks like someone copy-pasted a hexadecimal number from some documentation and forgot to add a leading "0x".

Might not somebody legitimately use a Tcl script that generates register numbers of a similar form as generated by C's printf("04%u", x); padded with leading 0s?

Same point as above.

Do many people actually try to use octal representation in such circumstances?

People may copy-paste a hexadecimal number.

Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

I have submitted few last minor comments and I do not expect to have any more. Other than that the change looks fine.

src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@aap-sc aap-sc force-pushed the aap-sc/csr_as_hex branch 2 times, most recently from af1fb32 to b72d80d Compare November 19, 2024 19:24
hexadecimal values are often used in the documentation. Forcing user to
convert CSRs addresses to decimal is unnecessary.
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 20, 2024

This comment seems a bit misleading because in the code there is a prior explicit check for 0x prefix, so a register number starting with 0 IS valid, if the next character is x/X.

But there is a precondition: "If we are here". Meaning we've already checked for hexadecimal numbers a few lines above.

On a more general point, why not just allow decimal numbers that start with 0(s)?

Because it suspiciously looks like someone copy-pasted a hexadecimal number from some documentation and forgot to add a leading "0x".

Might not somebody legitimately use a Tcl script that generates register numbers of a similar form as generated by C's printf("04%u", x); padded with leading 0s?

Same point as above.

Do many people actually try to use octal representation in such circumstances?

People may copy-paste a hexadecimal number.

@TommyMurphyTM1234 could you please clarify is my reasoning is fine with you? Or do you still have objections or concerns?

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 22, 2024

@TommyMurphyTM1234 could you please clarify is my reasoning is fine with you? Or do you still have objections or concerns?

@TommyMurphyTM1234 ping)

@aap-sc
Copy link
Collaborator Author

aap-sc commented Nov 25, 2024

Well, if no additional objections follow, I'm going to merge this by the end of week (around Friday).

@TommyMurphyTM1234
Copy link
Collaborator

@TommyMurphyTM1234 could you please clarify is my reasoning is fine with you? Or do you still have objections or concerns?

@TommyMurphyTM1234 ping)

Apologies for the delay - I have no strong objections - definitely none that should hold this up further.

@aap-sc aap-sc merged commit 6587668 into riscv-collab:riscv Nov 25, 2024
4 checks passed
Comment on lines -4071 to -4073
/* Register prefix: "csr_" or "custom_" */
strcpy(name, reg_type);
name[strlen(reg_type)] = '_';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JanMatCodasip , @en-sc

This MR introduced a regression since these lines were deleted. It seems that I've made a mistake while my changes were rebased (our internal change reviewed by @en-sc had this code). The regression was detected by our internal testsuite.

I'll post a patch shortly and will try to extend riscv-tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MR with the fix: #1176

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

Successfully merging this pull request may close these issues.

5 participants