显式访问 ARM 上的存储寄存器
根据 ARM 手册,应该可以访问特定 CPU 模式的分组寄存器,例如“r13_svc”。当我尝试执行此操作时,gcc 对我大喊以下错误:
立即表达式需要 # 前缀 -- `mov r2,sp_svc'
出了什么问题?
更新。 ARMv5 和 ARMv6 的 ARM 架构参考手册中的以下文本让我相信这是可能的,第 A2.4.2 节:
寄存器 R13 和 R14 有 6 个存储区 每个物理寄存器。已使用1个 在用户和系统模式下,以及每个 其余五个用于其中之一 五种异常模式。它在哪里 有必要具体说明哪些 正在引用版本,您使用 形式名称:R13_mode R14_mode 其中模式是 usr、svc 中适当的一项(对于 管理模式)、abt、und、irq 和 FIQ。
According to the ARM manual, it should be possible to access the banked registers for a specific CPU mode as, for instance, "r13_svc". When I try to do this gcc yells at me with the following error:
immediate expression requires a # prefix -- `mov r2,sp_svc'
What's wrong?
Update. The following text from the ARM Architecture Reference Manual for ARMv5 and ARMv6 led me to believe that it is possible, section A2.4.2:
Registers R13 and R14 have six banked
physical registers each. One is used
in User and System modes, and each of
the remaining five is used in one of
the five exception modes. Where it is
necessary to be specific about which
version is being referred to, you use
names of the form: R13_mode
R14_mode where mode is the
appropriate one of usr, svc (for
Supervisor mode), abt, und, irq and
fiq.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确的语法是
mrs r2,sp_svc
或mrs r3, sp_usr
。这是一个新的 armv7 扩展。代码可以在ARM Linux KVM源文件中看到 interrupt_head.S。此指令支持的gas binutils 补丁 作者:马修·格雷顿-丹恩。据我所知,它需要虚拟化扩展。据我了解,LPAE(大型物理地址扩展)意味着虚拟化扩展。因此 Cortex-A7、Cortex-A12、Cortex-A15 和 Cortex-A17 可能能够使用此扩展。但是,Cortex-A5、Cortex-A8 和 Cortex-A9 则不能。
有关该指令的文档可以在 ARMv7a TRM revC 的 B9.3.9 MRS(分组寄存器) 部分找到。
对于其他 Cortex-A(和 ARMv6)CPU,您可以使用 cps 指令切换模式并将存储寄存器传输到非存储寄存器 (R0-R7),然后再切换回来。明显的困难在于用户模式。处理这个问题的正确方法是使用
ldm rN, {sp,lr}^
;用户模式没有返回特权模式的简单方法。对于所有较旧的 CPU,old_timer 提供的信息都适用。主要是使用
mrs/msr
来改变模式。 mrs/msr 适用于全类 ARM cpu,但需要多条指令,因此可能存在竞争问题,需要根据上下文进行中断和异常屏蔽。这是上下文切换(VM 经常执行此操作)的重要指令(序列)。
The correct syntax for this is
mrs r2,sp_svc
ormrs r3, sp_usr
. This is a new armv7 extension. The code can be seen in the ARM Linux KVM source file interrupt_head.S. The gas binutils patch for this instruction support by Matthew Gretton-Dann. It requires the virtualization extensions are far as I understand.According to what I understand, the LPAE (large physical address extension) implies the virtualization extensions. So Cortex-A7, Cortex-A12, Cortex-A15, and Cortex-A17 may be able to use this extension. However, the Cortex-A5, Cortex-A8, and Cortex-A9 can not.
Documentation on the instruction can be found in the ARMv7a TRM revC, under section B9.3.9 MRS (Banked register).
For other Cortex-A (and ARMv6) CPU's you can use the
cps
instruction to switch modes and transfer the banked register to an un-banked register (R0-R7) and then switch back. The obvious difficulty is with user mode. The correct way to handle this is withldm rN, {sp,lr}^
; user mode has no simple way back to the privileged modes.For all older CPUs, the information given by old_timer will work. Mainly, use
mrs/msr
to change modes.mrs/msr
works over the full class of ARM cpus but requires multiple instructions and hence may have race issues which require interrupt and exception masking depending on context.This is an important instruction (sequences) for context switching (which VMs do a lot of).
我认为使用
mov
指令不可能做到这一点;至少根据我正在阅读的 ARM 架构参考手册。你有什么文件?有一个ldm
变体,可以从特权模式加载用户模式寄存器(使用^
)。您唯一的其他选择是切换到 SVC 模式,执行mov r2, sp
,然后切换回您正在使用的任何其他模式。您收到的错误是因为它不理解
sp_svc
,因此它认为您正在尝试立即执行mov
,这看起来像:这就是为什么它说“需要 # 前缀”。
I don't think that's possible with the
mov
instruction; at least according to the ARM Architecture Reference Manual I'm reading. What document do you have? There are is a variant ofldm
that can load user mode registers from a privileged mode (using^
). Your only other option is to switch to SVC mode, domov r2, sp
, and then switch back to whatever other mode you were using.The error you're getting is because it doesn't understand
sp_svc
, so it thinks you're trying to do an immediatemov
, which would look like:So that's why it says "requires a # prefix".
您可以使用 mrs 和 msr 通过更改 cpsr 中的位来更改模式,然后通常使用 r13。
从手臂开始
然后,
,或者如果您立即需要更多位,
或者如果您不希望汇编器放置您的数据,您可以自己放置。
您将看到典型的arm启动代码,其中应用程序将支持中断、中止和其他异常,以设置您将需要的所有堆栈指针、更改模式、设置sp、更改模式、设置sp、更改模式...
You use mrs and msr to change modes by changing bits in the cpsr then use r13 normally.
From the arm arm
then
or if you need more bits in the immediate
or if you dont want the assembler placing your data, you can place it yourself.
You will see typical arm startup code, where the application is going to support interrupts, aborts and other exceptions, to set all of your stack pointers that you are going to need, change mode, set sp, change mode, set sp, change mode ...