Calling ARM assembly from C, GCC (bare metal)

前端 未结 4 523
广开言路
广开言路 2021-02-06 06:07

I am trying to do some bare-metal programming in ARM with GCC and testing on QEMU. Whenever I call into an ARM label from C, my program hangs. I have a simple example of code

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 07:05

    If you assemble your asm code as Thumb, you need to mark the function as a Thumb function, so that the linker uses correct instruction when branching to it (e.g. BLX or BX to an address with the low bit set). This is done with the .thumb_func directive:

    .global activate
    .thumb_func
    activate:
        b test
    

    Another option is to explicitly ask the assembler to generate ARM code:

    .code 32
    .global activate
    activate:
        b test
    

    Check this article too, although remember that current processors don't need many workarounds that were necessary in ARMv4, so you probably shouldn't follow it blindly.

提交回复
热议问题