This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to caculate the total reentrant stack size in KeilC?

Hi,all

I have succeeded in runing ucos (v2.52) in the keil simulator environment, and still confused about the reentrant functions though I searched it here. reentrant stack is also called simulator stack,right? My OS is xp sp2. Keil is C51.EXE V8.06 My project is complied in large mode.

And the quetions are:

1, Does every reentrant function have Its own reentrant stack? Are there the same number of ?C_XBP as the reentrant functions.

2, For all the reentrant functions, Arguments and local variable are stored in the simulator stack,right? If all the functions in my project are reentrant. is
there no hardware stack wanted? if not what is it for?

3,How can I know each or the total simulator stack size ?Can I get it from the map file? or other ways.

Thanks

Parents
  • 1. There is only one stack and one ?C_XBP shared by all the reentrant functions.

    2a. If the reentrant functions need to spill parameters, temporaries, and/or locals into the stack, they will use the software stack. It is possible to have a reentrant function that happens not to need stack (that is, all the parameters fit into registers).

    2b. The hardware stack (core SP register pointing into idata) is always used for return addresses, and for very little else. (I've seen a few bits of code that will push a temporary value.) Parameters/locals/temps are either assigned fixed memory addresses by the call tree overlay analysis for non-reentrant, or else copied to the stack dynamically for reentrant functions.

    3. The linker outputs an HTML document that shows the stack depth. For reentrant functions, you'll have to know how many times the function could potentially be called. (Potentially this is once per context, unless the reentrant function is also recursive, in which case only you, the programmer, can really know the maximum depth of recursion at run time.)

    The traditional way to measure stack usage is to fill the stack area with a known pattern, run your system through its test suite, and then examine the stack to see where the pattern remains. That is, you can see the part of the stack that was overwritten in use. If your test suite actually forces the code down its maximum depth path, this will give you the right answer.

Reply
  • 1. There is only one stack and one ?C_XBP shared by all the reentrant functions.

    2a. If the reentrant functions need to spill parameters, temporaries, and/or locals into the stack, they will use the software stack. It is possible to have a reentrant function that happens not to need stack (that is, all the parameters fit into registers).

    2b. The hardware stack (core SP register pointing into idata) is always used for return addresses, and for very little else. (I've seen a few bits of code that will push a temporary value.) Parameters/locals/temps are either assigned fixed memory addresses by the call tree overlay analysis for non-reentrant, or else copied to the stack dynamically for reentrant functions.

    3. The linker outputs an HTML document that shows the stack depth. For reentrant functions, you'll have to know how many times the function could potentially be called. (Potentially this is once per context, unless the reentrant function is also recursive, in which case only you, the programmer, can really know the maximum depth of recursion at run time.)

    The traditional way to measure stack usage is to fill the stack area with a known pattern, run your system through its test suite, and then examine the stack to see where the pattern remains. That is, you can see the part of the stack that was overwritten in use. If your test suite actually forces the code down its maximum depth path, this will give you the right answer.

Children