-
Notifications
You must be signed in to change notification settings - Fork 120
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
naked interrupt will break when s registers get used #90
Comments
Those are really long discussions, can you explain it with more detail here? Is there a work around? Does this fix it? (If so, I don't understand quite why.) __attribute__((noinline))
void my_handler_inner() {
... all your stuff here
}
__attribute__((naked))
void my_handler() {
my_handler_inner();
asm volatile ("mret");
__builtin_unreachable(); // suppress the usual ret
} Or is the argument that we just would be better off without that feature? Because I would be A OK with that conclusion!! |
Ok, let me see if I have this right:
|
wait |
Well this is flaming nightmare. |
Wait, you can get around it with GCC. https://godbolt.org/z/aEffcsvfv |
Manually pushing s0, s1 will add 6 instructions, that in typical use case will be useless. Apart from the The best scenario is to get standardized something like "prestacked" annotations for compilers, otherwise we end up with more and more proprietary attributes and related mess. |
In BH solution it's the job of the inner function to handle the stack and saved registers. hence it must be ED:
This one does actually underflow the stack |
That's wrong I must have gotten the custom xpack-gcc build from somewhere else |
Nope. If |
Allow me to quote from https://www.eevblog.com/forum/microcontrollers/bizarre-problem-on-ch32v003-with-systick-isr-corrupting-uart-tx-data/msg4785773/#msg4785773
|
I think I understand a bit more now. This really does feel sticky. I think the best answer is to, for now, not encourage people to use the fast interrupts. Maybe someday. I was just hoping to find something where you could have some |
Here's how it's handled in tinyusb: void USBHS_IRQHandler (void) __attribute__((naked));
void USBHS_IRQHandler (void)
{
__asm volatile ("call USBHS_IRQHandler_impl; mret");
}
__attribute__ ((used)) void USBHS_IRQHandler_impl (void)
{
tud_int_handler(0);
} https://github.com/hathach/tinyusb/blob/master/hw/bsp/ch32v307/family.c#L38-L47 Not sure if it has the same issues but it is worth looking at |
Is this sufficient to explain to users? maybe? https://github.com/cnlohr/ch32v003fun/blob/master/examples/exti_pin_change_isr/exti_pin_change_isr.c |
I will close this ticket now. At some point I may show the example of the asm called interrupt. |
It turns out that even the workaround is broken when FPU is present (e.g. ch32v307) hydrausb3/riscv-none-elf-gcc-xpack#5 I've already sent prestacked annotation RFC to llvm list. That could finally solve this mess... |
Only when FP is actually used in the handler, Shirley? Which is pretty questionable in an interrupt handler small enough that you care about register stacking overhead. The Linux kernel is a pretty big interrupt handler and it doesn't use FP! Remember the tech media fuss when René Rebe patched Linux to enable RDNA2-based Radeon RX 6700XT cards to be used on the Unmatched? Do you know what the patch was? Saving and restoring FP state so the kernel (and kernel modules) could use FP. The "prestacked" attribute is a good idea, but people can easily make errors while using it. There should probably be some predefined constants e.g. WCH_HPE. Which will need to be defined differently for RV32E and RV32I (or maybe it's ok to just expand to the RV32I values always, as the compiler won't use the other registers anyway) |
that's right
Things like 3p3z compensators etc. are using a few FP registers, and those do care about latency.
Vendors could provide those in the device headers. e.g.
|
As introduced in exti example. Be it function call, register pressure or pure size optimization.
see:
https://www.eevblog.com/forum/microcontrollers/bizarre-problem-on-ch32v003-with-systick-isr-corrupting-uart-tx-data
https://www.reddit.com/r/RISCV/comments/126262j/notes_on_wch_fast_interrupts/
The text was updated successfully, but these errors were encountered: