-
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: Reject size 2 soft breakpoints when C extension not supported #908
target/riscv: Reject size 2 soft breakpoints when C extension not supported #908
Conversation
159a49d
to
58fd2a3
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.
Thanks.
58fd2a3
to
257c30c
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 overall. Just have an OpenOCD style comment.
257c30c
to
1faadde
Compare
…ported This patch disables software breakpoints of size 2 for targets which don't support compressed instructions. Change-Id: I8200b22a51c97ba2aa89e6328beadde8dd35cdd5 Signed-off-by: Marek Vrbka <[email protected]>
1faadde
to
8ad4176
Compare
/** @todo check RVC for size/alignment */ | ||
if (!(breakpoint->length == 4 || breakpoint->length == 2)) { | ||
LOG_TARGET_ERROR(target, "Invalid breakpoint length %d", breakpoint->length); | ||
const bool c_extension_supported = riscv_supports_extension(target, 'C'); |
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.
There is a code size reduction isa called Zc*(ratified), see https://github.com/riscv/riscv-code-size-reduction
If Zc extension is used, the instruction can be also 16 bit, so this check by just riscv_supports_extension(target, 'C')
maybe not correct, since as described here riscvarchive/riscv-code-size-reduction#144 (comment), this misa.c only set when all normal compress instruction are implemented, but in some case, for example, rv32imaf_zca
, it will not set misa.c bit, but it still contains 16 bit instruction, so I think sw breakpoint can still set here, so the check by misa.c bit is not enough.
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.
also here riscv-software-src/riscv-isa-sim#1172
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.
Hi @MarekVCodasip @timsifive @tariqkurd-repo , is there any feedback on my comments regarding the new added Zc* extensions will affect this compress instructions existing checking.
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.
Implementing Zca and not C will not set misa.C
I think you actually need to specify C to set it
Is that your understanding @aswaterman ?
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.
Implementing Zca and not C will not set misa.C I think you actually need to specify C to set it Is that your understanding @aswaterman ?
If I implement rv32imaf_zca_zcb_zcf_zcmp_zcmt it contains all C required zca_zcf will the misa.C bit be set? This riscv_supports_extension
function only use the misa.C bit to check whether compressed instructions are supported.
Are there specific reasons not to simply always use the "lowest common denominator" of 32-bit software breakpoints regardless of the target's 16-bit instruction capabilities? Off the top of my head the only one that I can think of is the inability to write one at the instruction address 2 bytes from the "top" of a memory region. Are there other reasons not to just take the simpler approach? |
By placing a SW breakpoint ( Using always the 32-bit SW breaks is therefore not an option. |
Thanks for that explanation @JanMatCodasip 👍 |
Hi @MarekVCodasip @timsifive @JanMatCodasip , using this commit, I am not able to set breakpoint at 2 bytes aligned address, with Zc* extension enabled which also provided compressed instructions. |
Is there a reliable way how OpenOCD can detect the
|
Hi @JanMatCodasip , I didn't know whether there is a way to check whether |
Earlier: it was stated that:
But, as far as I can see, support for
The That being the case shouldn't a check of |
Perhaps this is another option?
|
The simple option is to revert this change. gdb already has good logic to decide what breakpoint size to use, because it knows what size instruction is being replaced. What was the original reason for this change? I don't see a rationale in the description. |
From what I can tell, c.ebreak is defined in the unprivileged spec, where it is part of the "C" Standard Extension chapter. That means to me that if c.ebreak is implemented then misa.C must be set. That feels like a spec bug, though. If you are allowed to implement 16-bit instructions without setting misa.C, which the Zc* extensions clearly do, then obviously you want c.ebreak as well, without being required to implement all the other C extension instructions. I filed riscvarchive/riscv-code-size-reduction#228 for this. I would expect the outcome to be something that allows c.ebreak even without C, and the result for OpenOCD is that we should revert this change. |
|
@@ -1198,15 +1198,17 @@ static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakp | |||
LOG_TARGET_DEBUG(target, "@0x%" TARGET_PRIxADDR, breakpoint->address); | |||
assert(breakpoint); | |||
if (breakpoint->type == BKPT_SOFT) { | |||
/** @todo check RVC for size/alignment */ |
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.
@timsifive I think this patch is added due to there is a todo here, is it possible to check whether 16bit instruction execute ok without any exception, such as test c.nop
, if no exception, compress instruction is supported, otherwise no.
I am in agreement.
The reason was to prevent user mistakes and improve robustness (an attempt that in the end has the opposite effect: additional issues). |
Did you mean |
Hi @TommyMurphyTM1234 , please check it here riscvarchive/riscv-code-size-reduction@4abffe7 |
The ratified The ratified specification does not mention Are you referring to some proposed draft update? |
@TommyMurphyTM1234, see riscvarchive/riscv-code-size-reduction#228. TLDR: Every Zc* requires Zca, and Zca is all of the existing C extension, except some 16-bit floating point ops. |
This patch disables software breakpoints of size 2 for targets which don't support compressed instructions.
Change-Id: I8200b22a51c97ba2aa89e6328beadde8dd35cdd5