Chinaunix首页 | 论坛 | 博客
  • 博客访问: 974238
  • 博文数量: 109
  • 博客积分: 1751
  • 博客等级: 上尉
  • 技术积分: 1817
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-31 22:37
文章分类

全部博文(109)

文章存档

2014年(9)

2013年(21)

2012年(48)

2011年(31)

TMP

分类: LINUX

2011-09-30 19:07:13

The following illustration shows the stack frame layout.

The following list gives more information about the stack frame layout.

  • The Register Save Area holds the preserved values of any permanent registers used by the function. It also contains the function return address.
  • The Locals and Temporaries area represents the stack space allocated for local variables and compiler-generated temporaries.
  • The first four words at the top of the stack may contain the values passed in R0-R3. Any of these values could be missing. The values should be stored in the R0-R3 if registers cannot hold the arguments for the entire function, or if the addresses for the arguments are already in use.
  • If a routine needs storage space for the first four words of arguments, it creates and initializes the storage at the very top of the called function stack. The following list shows reasons for which a routine can allocate space:
    • An argument word address is taken
    • An argument word has a value altered by the called function
    • An argument register must be spilled.

    If a register keeps an argument for the argument live range, the argument has no associated storage in the stack frame.

  • If a routine has alloca() locals, the ARM Specification requires a separate frame pointer register to access incoming arguments and locals. R11 is the assigned frame pointer for ARM, and R7 is the assigned frame pointer for THUMB. A leaf routine may use any free integer register as the frame pointer. A non-leaf routine must use a permanent register. The routine must not modify the frame pointer register between the prolog and epilog.
  • In a routine that uses alloca(), everything in the frame at a lower address than the alloca() area is referenced relative to R13 and never contains a defined value at the time of an alloca() call. Thus, the alloca() operation never has to copy this part of the stack frame, and no data relocation problems arise. Everything in the frame at an address higher than the alloca() area is referenced relative to the frame pointer, R11 for ARM or R7 for THUMB.
  • To more efficiently access data in large stack frames, a routine may establish another frame pointer. A frame pointer helps mitigate problems with the limited size of the bit-field that specifies register-displacement-addressing offset. The frame pointer typically points to a fixed frame offset in the RSA or Local and Temporaries areas of the stack frame, but may point to other offsets within the frame.
  • A routine need not set up a stack frame for itself unless it needs to save permanent registers, or to allocate space for locals or outgoing argument areas that are bigger than four words.
  • The stack pointer and frame pointer addresses align on 4-byte boundaries.












Frame pointer is a convenience for referencing local variables in a
subrouting, usually all the args are pushed onto the stack then BP
(the frame, or Base pointer) is pushed , then SP
(the stack pointer) is copied to BP, so all variables can easily be
referenced via BP+x, BP+y, etc. It is especially useful if you are
debugging since BP will give you an idea of where the parameters to
the current subroutine are located. It is also useful if you are doing
a stack traceback since the values of BP have been pushed onto the stack
for each stack frame.

On the otherhand, there are otherways of accessing those variables by
referencing off of "SP" and using BP as a general purpose register
to do other things -- this can result in faster code that is less
easy to debug.

If you aren't doing kernel debugging and/or are not expecting to be
generating stack traces, allowing the compiler to use BP (Base/Frame
Pointer) is usually a good thing for optimizing memory and CPU
execution time.
阅读(1422) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~