About the stack configuration in MPC574xP

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

About the stack configuration in MPC574xP

1,101件の閲覧回数
jerrytomlee
Contributor II

I have read the example in S32DS including  57xx_flash.ld & startup.S.

At the beginning of  '57xx_flash.ld":

/* define heap and stack size */
__HEAP_SIZE = 0 ;
__STACK_SIZE = 4096 ;

At the end of "startup.S" is the "Configure Stack":

;#****************************** Configure Stack ******************************/
e_lis r1, __SP_INIT@h ;# Initialize stack pointer r1 to
e_or2i r1, __SP_INIT@l ;# value in linker command file.

e_lis r13, _SDA_BASE_@h ;# Initialize r13 to sdata base
e_or2i r13, _SDA_BASE_@l ;# (provided by linker).

e_lis r2, _SDA2_BASE_@h ;# Initialize r2 to sdata2 base
e_or2i r2, _SDA2_BASE_@l ;# (provided by linker).

e_stwu r0,-64(r1) ;# Terminate stack.

And my questions are:

1)  what is the stack use for? what is the heap use for?  And why the HEAP SIZE is defined to zero?

2) I have seen __SP_INIT defined in the link file, but I have not seen any _SDA_BASE_ or _SDA2_BASE_ definition, other than the extern define in "startup.S", and I search the project , there is no definition for _SDA_BASE_ or _SDA2_BASE_.

 So why the compiler or linker  tell any error when I build the project? And the program works well.

3) what is the meaning of the "Configure Stack" in "startup.S"?  Is r1 used for stack pointer when the program running?

    And what r2 & r13 use for ?  and what about r0?

Thanks a lot

ラベル(1)
2 返答(返信)

798件の閲覧回数
martin_kovar
NXP Employee
NXP Employee

Hello Jerry,

1) here is simple comparison of STACK and HEAP

Stack:

  • Stored in computer RAM just like the heap.
  • Variables created on the stack will go out of scope and are automatically deallocated.
  • Much faster to allocate in comparison to variables on the heap.
  • Implemented with an actual stack data structure.
  • Stores local data, return addresses, used for parameter passing.
  • Can have a stack overflow when too much of the stack is used (mostly from infinite or too deep recursion, very large allocations).
  • Data created on the stack can be used without pointers.
  • You would use the stack if you know exactly how much data you need to allocate before compile time and it is not too big.
  • Usually has a maximum size already determined when your program starts.

Heap:

  • Stored in computer RAM just like the stack.
  • In C++, variables on the heap must be destroyed manually and never fall out of scope. The data is freed with delete, delete[], or free.
  • Slower to allocate in comparison to variables on the stack.
  • Used on demand to allocate a block of data for use by the program.
  • Can have fragmentation when there are a lot of allocations and deallocations.
  • In C++ or C, data created on the heap will be pointed to by pointers and allocated with new or malloc respectively.
  • Can have allocation failures if too big of a buffer is requested to be allocated.
  • You would use the heap if you don't know exactly how much data you will need at run time or if you need to allocate a lot of data.
  • Responsible for memory leaks.

In embedded systems it is not common to use dynamic memory allocation, so HEAP is by default set to 0, but you have the possibility to increase it and use the dynamic allocation.

2) These are the symbols automatically generated by linker file.

3) Please read the EABI document I am attaching you to this post.

Regards,

Martin

798件の閲覧回数
jerrytomlee
Contributor II

Thanks for your reply, now I see.

0 件の賞賛