Use FP in vdsp to obtain the function call stack

Source: Internet
Author: User

Development Environment: Vdsp 5.0, bf561There is a built-in function in GCC _ Builtin_return_address (level)To obtain the return address of the function. This function is not available in vdsp, but FP pointers can be used for the same purpose. In the C function of vdsp, the first assembly command is usually link 0x0; // here the variable number command does the following: [-- Sp] = rets; [-- Sp] = FP; FP = sp; SP + =-N; that is, the return address of this function is saved at the beginning of each function, the FP pointer of the previous function is also saved. In fact, it is equivalent to linking the return address of the function with a single-chain table. As long as you follow the chain table up, you can naturally find the return address for calling the function. Example: # define Level 3 void S3 (void) {unsigned int FP, RTS; int I; ASM ("% 0 = FP;": "= D" (FP )); for (I = 0; I <level; I ++) {RTS = * (unsigned int *) (FP + 4); FP = * (unsigned int *) FP ;} printf ("RTS: 0x % x", RTS);} void S2 (void) {S3 ();} void S1 (void) {S2 ();} int main (INT argc, char * argv []) {S1 (); Return 0;} the output result is: RTS: 0xffa014ba, that is, pointing to S1 () in the main function () the next statement called.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.