Hi
I need to implement a stack overflow handler which will disable all interrupts and then execute some instruction such as bkpt #0 in case of ARM Cortex and then enter infinite loop
void StackOverflow( ) { // disable all interrupts //todo: Indicate Overflow by write to GPIO port or an LED __asm volatile("bkpt #0"); // breakpoint here for(;;) { }}
Is there similar instruction in RH850 to do this similar to bkpt #0 in case of ARM Cortex?
Thanks,
The equivalent RH850 assembly instruction that you are looking for is the DBTRAP insn, but I'm not sure that is the appropriate action to take based on a stack overflow detection.
asm( "dbtrap" ); // GHS in-line assembly
As this insn is used to implement software breakpoints, using this to throw a run-time exception would seem ill-advised.
It might be better to use something like SYSCALL, TRAP, or FETRAP to handle this condition.
ok noted, thanks very much for point it out . I will try out the TRAP or SYSCALL or perhaps HALT and see how it works
ok in that case when stack overflow occurs in an application thread , will we still be able to access the data flash (r/w) or suspend the data flash
, what is the suggested behaviour ?
Hello pras,
if any exception is called, the CPU enter the exception mode and no other (maskable) interrupt can be called. Depending on the exception level also other exceptions might be prevented, before the exception returns to normal operation mode. Leaving the exception can only be done by a EIRET/FERET instruction, which places the Compiler at the end of an exception routine. This just explain the CPU modes, which you should take in mind when trying to execude code from the exception routine. Some software drivers might needed interrupt processing in the background and may not work as expected.
The flash handling (regardless of code/data flash) is handled by an internal Flash Access Controller Interface (FACI), which do not care for the CPU mode. You could control the flash as usual. Please take in mind that you may have currently a data flash operation. So, it depends on the current status, which kind of access is possible.
Attention: If you have a stack overflow, you have to think about the consequences. Calling data flash libraries could work , but without having a valid stack, this should be handled with care (e.g. restoring stack to valid area).
The flash librarues are usual not designed for re-entrance!
Best regards