在C中调用,海湾合作委员会(裸机)ARM汇编 [英] Calling ARM assembly from C, GCC (bare metal)

查看:234
本文介绍了在C中调用,海湾合作委员会(裸机)ARM汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些ARM裸机编程GCC和测试的QEMU。每当我调入从C一个ARM的标签,我的程序挂起。我有code的一个简单的例子,显示在 https://gist.github.com/1654392 <问题/ A> - 当我打电话在code激活(),它挂起

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的观察到,当我做了BL从组装到C code(从_start)它产生较小的包装器,切换到Thumb指令。看来,C code是所有Thumb指令正在生成,但在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 ARM mode function defined in assembler from THUMB mode function defined in C, it is need to define symbol in assembler as function, and tools (Linaro gcc) will produce blx instruction instead of bl.

例如:

@在这里,我们假设code,这部分里面,code 32

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

.TYPE FN,功能%

.type fn, %function

FN:

MOV PC,LR

mov pc, lr

这篇关于在C中调用,海湾合作委员会(裸机)ARM汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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