-
Notifications
You must be signed in to change notification settings - Fork 330
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: Replace [sg]et_field macros with functions. #958
Conversation
src/target/riscv/riscv-013.c
Outdated
LOG_TARGET_DEBUG(target, "dtmcontrol=0x%x", dtmcontrol); | ||
LOG_TARGET_DEBUG(target, " dmireset=%d", get_field(dtmcontrol, DTM_DTMCS_DMIRESET)); | ||
LOG_TARGET_DEBUG(target, " idle=%d", get_field(dtmcontrol, DTM_DTMCS_IDLE)); | ||
LOG_TARGET_DEBUG(target, " dmistat=%d", get_field(dtmcontrol, DTM_DTMCS_DMISTAT)); | ||
LOG_TARGET_DEBUG(target, " abits=%d", get_field(dtmcontrol, DTM_DTMCS_ABITS)); | ||
LOG_TARGET_DEBUG(target, " version=%d", get_field(dtmcontrol, DTM_DTMCS_VERSION)); | ||
LOG_TARGET_DEBUG(target, " dmireset=%d", get_field32(dtmcontrol, DTM_DTMCS_DMIRESET)); | ||
LOG_TARGET_DEBUG(target, " idle=%d", get_field32(dtmcontrol, DTM_DTMCS_IDLE)); | ||
LOG_TARGET_DEBUG(target, " dmistat=%d", get_field32(dtmcontrol, DTM_DTMCS_DMISTAT)); | ||
LOG_TARGET_DEBUG(target, " abits=%d", get_field32(dtmcontrol, DTM_DTMCS_ABITS)); | ||
LOG_TARGET_DEBUG(target, " version=%d", get_field32(dtmcontrol, DTM_DTMCS_VERSION)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using log_debug_reg(target, DTM_DTMCS_ORDINAL, dtmcontrol)
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/target/riscv/riscv-013.c
Outdated
LOG_TARGET_DEBUG(target, " idle=%d", get_field32(dtmcontrol, DTM_DTMCS_IDLE)); | ||
LOG_TARGET_DEBUG(target, " dmistat=%d", get_field32(dtmcontrol, DTM_DTMCS_DMISTAT)); | ||
LOG_TARGET_DEBUG(target, " abits=%d", get_field32(dtmcontrol, DTM_DTMCS_ABITS)); | ||
LOG_TARGET_DEBUG(target, " version=%d", get_field32(dtmcontrol, DTM_DTMCS_VERSION)); | ||
|
||
if (get_field(dtmcontrol, DTM_DTMCS_VERSION) != 1) { | ||
LOG_TARGET_ERROR(target, "Unsupported DTM version %d. (dtmcontrol=0x%x)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG_TARGET_ERROR(target, "Unsupported DTM version %d. (dtmcontrol=0x%x)", | |
LOG_TARGET_ERROR(target, "Unsupported DTM version %" PRIu32 ". (dtmcontrol=0x%" PRIx32 ")", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpicking] we still have "%d" / "%x" as part of this commit, while the return type is uint32_t. Probably would not hurt to replace with PRIu32 / PRIx32. This is the price we have to pay to use fixed-width types :(.
src/target/riscv/riscv-013.c
Outdated
@@ -781,7 +779,7 @@ static int dmstatus_read_timeout(struct target *target, uint32_t *dmstatus, | |||
LOG_ERROR("OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not " | |||
"%d (dmstatus=0x%x). This error might be caused by a JTAG " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"%d (dmstatus=0x%x). This error might be caused by a JTAG " | |
"%" PRIu32 " (dmstatus=0x%" PRIx32 "). This error might be caused by a JTAG " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/* Clear current value from field. */ | ||
reg &= ~mask; | ||
uint64_t low_field_bit = mask & ~(mask << 1); | ||
reg |= (val * low_field_bit) & mask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reg |= (val * low_field_bit) & mask; | |
assert(!((val * low_field_bit) & ~mask)); | |
reg |= (val * low_field_bit) & mask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you want to check that the value fits in the mask. Is that right?
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you want to check that the value fits in the mask. Is that right?
Yes. Thanks!
1643d1b
to
3c21c59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked this visually and it looks fine to me. I only have one last minor suggestion.
Compilers are good at optimizing, and with functions it's abundantly clear what all the types involved are. This change means we don't have to be super careful about the type of values because of what the macro might do to them that might cause overflow. The only place where the return type matters is in printf-style functions, and I made get_value32() for those cases where a change was needed. This should set the stage for simply copying the latest debug_defines.h from the debug spec build again. Change-Id: I5fb19d0cfc1e20137832a7b344b05db215ce00e1 Signed-off-by: Tim Newsome <[email protected]>
3c21c59
to
86b430b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I agree that the occurrences of %d
(and similar) should be replaced by PRId32
(and similar). I don't have preference whether to do it in this merge request or in a following one.
Let's do it separate. More, smaller PRs are almost always preferable. Especially if the changes are individually helpful. Unless the build as-is causes warnings on some compiler that I'm not using? |
No, at least not in the environment we have. The comment was mostly a nitpick - it can surely be addressed later |
Compilers are good at optimizing, and with functions it's abundantly clear what all the types involved are. This change means we don't have to be super careful about the type of values because of what the macro might do to them that might cause overflow.
The only place where the return type matters is in printf-style functions, and I made get_value32() for those cases where a change was needed.
This should set the stage for simply copying the latest debug_defines.h from the debug spec build again.
See discussion at end of riscv/riscv-debug-spec#902
Change-Id: I5fb19d0cfc1e20137832a7b344b05db215ce00e1