从 C、GCC(裸机)调用 ARM 程序集 [英] Calling ARM assembly from C, GCC (bare metal)

查看:33
本文介绍了从 C、GCC(裸机)调用 ARM 程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 GCC 在 ARM 中进行一些裸机编程并在 QEMU 上进行测试.每当我从 C 调用 ARM 标签时,我的程序就会挂起.我有一个简单的代码示例,显示了 https://gist.github.com/1654392-- 当我在该代码中调用 activate() 时,它挂起.

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 that shows the problem at https://gist.github.com/1654392 -- when I call activate() in that code, it hangs.

我用 objdump 观察到,当我从汇编代码到 C 代码(从 _start 开始)执行 bl 时,它会生成一个切换到拇指指令的小包装器.似乎 C 代码都是在拇指指令中生成的,但我所有的程序集都是在 ARM(32 位)指令中生成的.我不知道为什么会这样或如何解决它.

I have observed with objdump that when I do a bl from assembly to C code (as from _start) it is generating a small wrapper that switches to thumb instructions. It seems that the C code is all being generated in thumb instructions, but all my assembly is being generated in ARM (32-bit) instructions. I cannot figure out why this is or how to fix it.

推荐答案

为了从 C 中定义的 THUMB 模式函数调用汇编中定义的 ARM 模式函数,需要在汇编中将符号定义为函数,并且工具 (Linaro gcc) 将生成 blx 指令而不是 bl.

In order to call an ARM mode function defined in assembly from a THUMB mode function defined in C, you need to define a symbol in assembly as a function, and the tools (Linaro gcc) will produce a blx instruction instead of bl.

示例:

@ Here, we suppose that this part of code is inside of .code 32

.type fn, %function

fn:
   mov  pc, lr

这篇关于从 C、GCC(裸机)调用 ARM 程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆