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

Open
wants to merge 1 commit into
base: riscv
Choose a base branch
from

Conversation

aap-sc
Copy link
Collaborator

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

No description provided.

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

++reg_address_str;
}
// try to detect if string starts with 0x
bool is_hex_address = strncmp(reg_address_str, "0x", 2) == 0 ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not simply a case sensitive comparison: strnicmp(reg_address_str, "0x", 2)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could. I just forgot that this function existed. Will address

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually no! This function does not exist in C language. This is Microsoft-specific extension.

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually no! This function does not exist in C language. This is Microsoft-specific extension.

What about strncasecmp()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

strcasecmp is not in the C or C++ standard. It's defined by POSIX.1-2001 and 4.4BSD. I would prefer not to use it.

bool is_hex_address = strncmp(reg_address_str, "0x", 2) == 0 ||
strncmp(reg_address_str, "0X", 2) == 0;

unsigned chars_scanned;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could use unsigned char instead of unsigned here but maybe coding style doesn't like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should be an unsigned int , actually. Writing unsigned is just an old habit of mine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@TommyMurphyTM1234 , given that there is a reaction from you under this thread, can I assume that this one is addressed from your point of view?

(Typically I would expect reviewer to resolve his threads, so I want to double-check that our expectations are aligned).

@aap-sc aap-sc force-pushed the aap-sc/csr_as_hex branch 4 times, most recently from 4699b8e to 6f88874 Compare November 11, 2024 11:10
hexadecimal values are often used in the documentation. Forcing user to
convert CSRs addresses to decimal is unnecessary.
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.

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.

/* For backward compatibility, allow multiple parameters within one TCL argument, separated by ',' */
char *arg = strtok(args, ",");
while (arg) {
static bool parse_csr_address(const char *reg_address_str, unsigned int *reg_addr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this function be replaced by existing parse_uint() from command.c?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If i the description of those commands right - they still accept octal numbers. Given the nature of what we are dealing with here - I would forbid usage of octals to reduce risk of errors...

Though, now that I've said it - I think it would not hurt to add an actual check that the number does not start with zero.

Copy link
Collaborator

@JanMatCodasip JanMatCodasip Nov 15, 2024

Choose a reason for hiding this comment

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

Good point about the octals. Better to leave these unsupported to avoid user mistakes.

I think it would not hurt to add an actual check that the number does not start with zero.

Sounds good.

Comment on lines +4039 to +4041
/* For backward compatibility, allow multiple parameters within one TCL
* argument, separated by ',' */
for (char *arg = strtok(args, ","); arg; arg = strtok(NULL, ",")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Just a comment, no change requested)

In future, it would be my preference to simplify the syntax of expose_csrs and expose_custom. I'd deprecate (and eventually remove) the syntax with comma-separated list of registers.

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.

4 participants