Hello Guys,
Does anyone know if the SDK C compiler for FX-9860G has a compiler switch or command line option to force a stack overflow check?
I do not know if that was the problem but I had many local variables declared inside a function and I was experiencing weird memory problems (with the subsequent headache... ) such as global variables being overwriten. So I think it could be because I was going outside of the compiler limits. Do we have a limit for the size of the local variable data area declared inside a function? Can we check somehow that we are going outside this area?
Thanks for your help.
Diego.
Stack Overflow Check In Sdk C Compiler - Fx-9860g
Started by
neptune45
, Dec 21 2008 11:42 AM
4 replies to this topic
#1
Posted 21 December 2008 - 11:42 AM
#2
Posted 21 December 2008 - 03:57 PM
The FX9860G's total stack size is 16 kByte (address range 0x88020000 - 0x88024000).
If the stack pointer reaches 0x88020000, the stack is exhausted.
If you want to check the current stack pointer,
you could use a function like GetStackPtr below:
000B 33 RTS
60F3 34 MOV R15, R0
*/
If the stack pointer reaches 0x88020000, the stack is exhausted.
If you want to check the current stack pointer,
you could use a function like GetStackPtr below:
const int GetStackPtrCode = 0x000B60F3; const int (*internalGetStackPtr)(void) = (void*)&GetStackPtrCode; int GetStackPtr( void ){ return (*internalGetStackPtr)(); }/* for reference
000B 33 RTS
60F3 34 MOV R15, R0
*/
#3
Posted 21 December 2008 - 05:03 PM
Thank you, SimLo
Do you know if local variables of a C function are stored in the stack? Just to be sure what was my problem.
I decreased the size of local variable data and my problem was gone (I had big array), so it seems that I have the problem under control.
However I want to know if the problem was most likely due to the available stack size.
Do you know if local variables of a C function are stored in the stack? Just to be sure what was my problem.
I decreased the size of local variable data and my problem was gone (I had big array), so it seems that I have the problem under control.
However I want to know if the problem was most likely due to the available stack size.
Edited by neptune45, 21 December 2008 - 05:07 PM.
#4
Posted 21 December 2008 - 05:44 PM
It partly depends on the size of required local variable space.
If possible, the compiler uses registers, else it uses stack.
Arrays generally need stack.
Though, if you instruct the compiler to use non-stack-RAM (f. i. with "static"), it uses non-stack-RAM, even if you declare a variable inside a function body.
If possible, the compiler uses registers, else it uses stack.
Arrays generally need stack.
Though, if you instruct the compiler to use non-stack-RAM (f. i. with "static"), it uses non-stack-RAM, even if you declare a variable inside a function body.
#5
Posted 21 December 2008 - 08:06 PM
Thank you, that helps me a lot.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users