Altera_Forum
Honored Contributor
21 years agoHow to validate ram and stack size
I have been fighting to get a NIOS II system going. One of the problems I have faced I suspect to be stack overflows. This makes me ask if you have some good ideas on how to
a) detect that stack overflow has indeed occoured.c) predict or measure how large stack will be needed in a running system. The same could be asked about the heap requirements. I have thought about the following for the stack problem but possibly also useful to check heap size: fill the ram with a known pattern, and after the system has run or is running, read the ram and find how far down (for a stack growing towards 0) the ram has been changed. A function which goes through the ram looking for the fill pattern could map out any unused ram, giving an indication of heap usage as well. Filling of the ram could be tricky as one would not want to overwrite anything of value. Are there a trick with the linker which could be used? hardware peak stack value register Given the unique feature of a "semi-soft" processor core it would be useful to build a hardware stack pointer monitor into the core. A kind of peak-finding register, which always tracks the minimal value of the stack (again for a downgrowing stack). Initialize it at startup to point to the top, and read it later to see how far down it went! Easy in principle, but requires access to nios code. I dont think it would fit as a custom instruction thing. When having an operating system, one would have to deal with the task switching, which relocates the stack to the memory block for the running task. The peak stack value register would in that case have to be managed by the OS as one would have a peak stack value per task. I have not tried any of these ideas. I am sure there are other solutions! Aren't there?