ARM: generating a call stack without a frame pointer

I am trying to build a call stack on a Cortex-M3 processor (ARMv7-M architecture), without an OS (bare metal). However, there is no frame pointer for this ABI. So I'm trying to create a call stack when I don't have a frame pointer.

Regardless of the use of options -mapcs-frame, -fno-omit-frame-pointerand -O0with GCC, the frame pointer is not saved. I am wondering if there is another ABI that I can force GCC to use, so I have a pointer frame / stack of frames? If not, is there another reliable way to create a call stack?

Thanks in advance.

+4
source share
1 answer

, , ARM , Thumb, . (AAPCS Arm call standard). .

, . ...

, - ? - "no frame pointer register" - r13 - . , , .

, , ,

arm-none-eabi-gcc - -nostdlib -ggdb -mthumb -mcpu = cortex-m3 -mtpcs-frame -mtpcs-leaf-frame myfile.c

gcc-arm-none, linaro. gdb backtrace Atmel SAM3X. Thumb ABI , ARM EABI, , , , objdump -D.

r7, -fno-omit-frame- ( )

void test2(int i) {}
void main() { test(0); 

-fomit-frame-pointer

00008000 <test2>:
    8000:   b082        sub   sp, #8
    8002:   9001        str   r0, [sp, #4]
    8004:   b002        add   sp, #8
    8006:   4770        bx lr

00008008 <main>:
    8008:   b508        push  {r3, lr}
    800a:   f04f 0000   mov.w r0, #0
    800e:   f7ff fff7   bl 8000 <test2>
    8012:   bd08        pop   {r3, pc}

-fno-omit-frame-pointer

00008000 <test2>:
    8000:   b480        push  {r7}
    8002:   b083        sub   sp, #12
    8004:   af00        add   r7, sp, #0
    8006:   6078        str   r0, [r7, #4]
    8008:   f107 070c   add.w r7, r7, #12
    800c:   46bd        mov   sp, r7
    800e:   bc80        pop   {r7}
    8010:   4770        bx lr
    8012:   bf00        nop

00008014 <main>:
    8014:   b580        push  {r7, lr}
    8016:   af00        add   r7, sp, #0
    8018:   f04f 0000   mov.w r0, #0
    801c:   f7ff fff0   bl 8000 <test2>
    8020:   bd80        pop   {r7, pc}
    8022:   bf00        nop

, r7 , r7 ..

+2

All Articles