Arm Community
Site
Search
User
Site
Search
User
Support forums
Arm Development Studio forum
What is different of the function call and return manner between ARM Linux kernel and ARM applications?
Jump...
Cancel
Locked
Locked
Replies
4 replies
Subscribers
119 subscribers
Views
3416 views
Users
0 members are here
Options
Share
More actions
Cancel
Related
How was your experience today?
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
What is different of the function call and return manner between ARM Linux kernel and ARM applications?
Heron Zhang
over 12 years ago
Note: This was originally posted on 29th August 2012 at
http://forums.arm.com
Hi,
When I disassamble the ARM Linux kernel for ARMv7(tegra 2),I found that a lot of function return using ldm command,just like ldm sp, {fp, sp, pc},but in the applications ( SPECCPU2006 for arm),the function return mostly using bx or b.Why that happened? Is the kernel Makefile used some gcc arguments that can lead the compiler to optimize the kernel?
Parents
Gilead Kutnick
over 12 years ago
Note: This was originally posted on 29th August 2012 at
http://forums.arm.com
The reason why the compiler would use ldm instead of an instruction like bx lr or mov pc, lr is because lr was stored on the stack and needs to be restored from the stack. This will happen any time the function has to modify lr after it's called, which will occur if the function calls another function or if lr is allocated to a variable. The compiler is easily intelligent enough to distinguish between these cases.
The difference between bx lr and mov pc, lr is that bx will switch you from ARM to Thumb mode or vice-versa depending on what the mode was when the function was called. mov can be used if it's known that the call didn't cause a mode switch, for instance if the entire program is ARM or Thumb. This might be preferable because it means the program could work on old ARM processors that don't support Thumb and therefore don't have the bx instruction.
Cancel
Vote up
0
Vote down
Cancel
Reply
Gilead Kutnick
over 12 years ago
Note: This was originally posted on 29th August 2012 at
http://forums.arm.com
The reason why the compiler would use ldm instead of an instruction like bx lr or mov pc, lr is because lr was stored on the stack and needs to be restored from the stack. This will happen any time the function has to modify lr after it's called, which will occur if the function calls another function or if lr is allocated to a variable. The compiler is easily intelligent enough to distinguish between these cases.
The difference between bx lr and mov pc, lr is that bx will switch you from ARM to Thumb mode or vice-versa depending on what the mode was when the function was called. mov can be used if it's known that the call didn't cause a mode switch, for instance if the entire program is ARM or Thumb. This might be preferable because it means the program could work on old ARM processors that don't support Thumb and therefore don't have the bx instruction.
Cancel
Vote up
0
Vote down
Cancel
Children
No data