-
Notifications
You must be signed in to change notification settings - Fork 95
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
Fix macro generation #902
Fix macro generation #902
Conversation
88cef97
to
20104f3
Compare
Does this still let OpenOCD build using mingw32? ISTR that was the reason to add the extension. |
20104f3
to
1664d36
Compare
Yes, I successfully build OpenOCD with mingw32. |
Just a double-check: what is extension are you talking about? And what does |
Upd: I have a problems with testing OpenOCD on |
By "extension" I meant "ULL". ISTR=I Seem To Recall |
e3c8b29
to
527662c
Compare
Previous version of this patch leads to failure on some (look above) riscv-tests. After I replace Short reproduction of occured problem you can see here: https://godbolt.org/z/z6n7xd71s (change MASK from |
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 overall.
registers.py
Outdated
return "-0x%x" % -expression | ||
elif (expression > -2**32): | ||
return "-0x%xU" % -expression | ||
sufffix = "ULL" if unsigned else "" |
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.
sufffix = "ULL" if unsigned else "" | |
suffix = "ULL" if unsigned else "" |
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.
Addressed
1) We need to add ULL modifier to all values to fix some issues with `set_field` and `get_field` OpenOCD macros (for example, when `mask` = 1 << 31, it leads to UB becuase of signed overflow)
527662c
to
44b8d86
Compare
I just tried to use the output of this with OpenOCD, and it fails to build because of a bunch of printf() using %d for what are now ULL values. How did you resolve that? Looking at your godbolt example again, doesn't it make more sense to change the shift macro? |
I just replace %d with correct specifier in all such places.
We thoughr about it at internal discussion (with @aap-sc and @en-sc ) and came to conclusion that we need both changes: fix macro and update suffixes. I work on patch for shift macro now. |
That seems like a lot of unnecessary churn. Here's an example of an OpenOCD build error if we use the latest version:
Because the new definition of CSR_DCSR_CAUSE is:
There is no reason for that constant to have any suffix at all. The original code only applied the suffix for large constants, which seems cleaner. What specific bug did you originally encounter? Which fields were involved? |
I catch UB on OpenOCD with Sanitizer on riscv-013.c:5064
|
As I write above, we decided to apply |
The original issue was with undefined behavior due to integer overflow in operations like so:
To mitigate this, such constants were made unsigned. As for
If An alternative approach is to use a direct cast to a fixed-length integer types for masks (depending on the size of the register):
|
There are 3 types of values in debug_defines.h:
So I agree that every number should be unsigned. But masks of 32-bit registers (such as dmcontrol) shouldn't be 64-bit. Field offsets and lengths shouldn't be 64-bit either. It just feels off. What if we use this function instead of the macro? Seems to work. Less messy than macros in any case, and the types are very explicit.
|
Change-Id: Ie969866d1de83360a5f45e96e22108b58b8aa02f Signed-off-by: Kirill Radkin <kirill.radkin@syntacore.com>
Change-Id: Ie969866d1de83360a5f45e96e22108b58b8aa02f Signed-off-by: Kirill Radkin <kirill.radkin@syntacore.com>
Change-Id: Ie969866d1de83360a5f45e96e22108b58b8aa02f Signed-off-by: Kirill Radkin <kirill.radkin@syntacore.com>
set_field
andget_field
OpenOCD macros (for example, whenmask
= 2 << 31, it leads to UB)