Author Topic: Stack size / pointer setting recommendations  (Read 14368 times)

Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Stack size / pointer setting recommendations
« on: August 22, 2008, 09:06:03 AM »
I think i need some advice for how i should be setting up the stack in the NE64.

I guess there's three settings im wondering about really.

Everything is working ok but i wonder if its just been luck so far.
I havn't yet used any of the stack/heap checking functions.

1. At what address should i be setting the stack pointer at initialisation?
2. In the PRM file should i leave room at the stack end of RAM indicating that the compiler should not try to allocate variables in a space set aside for the stack?
3. In the PRM file what size should STACKSIZE be?

 If i run the project on the debugger for a while and then stop it, can i look for some "untouched" memory pattern to make sure the stack and the heap didnt get too close to each other?

some of the settings in my prm file

      RAM = READ_WRITE 0x2602 TO 0x3D00;

      STACKSIZE 0x160

I'm using some of the buffer space normally used for ethernet buffers as ram at the bottom there. DHCP has been disabled. my name of "STACKSPACE" is only used in the above line and not referenced anywhere.

 i note in the demo program that STACKSIZE is 1 and RAM is allocated all the way:
RAM = READ_WRITE 0x2c00 TO 0x3FFF;


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: Stack size / pointer setting recommendations
« Reply #1 on: August 22, 2008, 01:51:08 PM »

The stack pointer should be initialised to the top of RAM 0x2000.
There is no need to declare space for stack in the memory configuration files. The stack can grow until it hits variables, so is defined by the remaining space.

If you call fnStackFree() is returns the gap between the top of variables (actually the top of heap) to the lowest point that the stack pointer reached during operation. This space is filled with the pattern UNUSED_STACK_PATTERN (as defined in config.h) so uses the method which you are referring to.

Also take a look at the following:

This is basically valid for all projects/processors. Note that it is best to monitor fnHeapFree() to see how much of the defined OUR_HEAP_SIZE (fnHeapAvailable()) is really being used. When the project is stable and the exact maximum heap use is known reduce OUR_HEAP_SIZE so that fnHeapAvailable() [the remaining space] is almost zero. This will ensure that the stack space is maximised.