如何确定处理器在运行端模式? [英] How to determine the endian mode the processor is running in?

查看:152
本文介绍了如何确定处理器在运行端模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定的ARM处理器在仅使用汇编语言运行端模式。

How do I determine the endian mode the ARM processor is running in using only assembly language.

我可以很容易地看到的Thumb / ARM状态下读取CPSR的第5位,但我不知道是否有在CPSR或相应的位别处字节顺序。

I can easily see the Thumb/ARM state reading bit 5 of the CPSR, but I don't know if there a corresponding bit in the CPSR or elsewhere for endianness.

;silly example trying to execute ARM code when I may be in Thumb mode....
MRS R0,CPSR    
ANDS R0,#0x20
BNE ThumbModeIsActive
B   ARMModeIsActive

我有访问数据ARM7TDMI表,但这份文件并没有告诉我如何看当前的状态。结果
什么总成code做我用它来确定字节顺序?

让我们假设我使用的是ARM9处理器。

Let's assume I'm using an ARM9 processor.

推荐答案

有是ARM版本(ARM7TDMI)或ARMv5的(ARM9)字节序没有CPSR位,所以你需要使用其他手段。

There is no CPSR bit for endianness in ARMv4 (ARM7TDMI) or ARMv5 (ARM9), so you need to use other means.

如果您的核心实现系统协处理器15,那么你可以检查的7位寄存器1:

If your core implements system coprocessor 15, then you can check the bit 7 of the register 1:

MRC p15, 0, r0, c1, c0 ; CP15 register 1
TST r0, #0x80          ; check bit 7 (B)
BNE big_endian
B   little_endian

不过,DOC(ARM DDI 0100E)似乎暗示该位仅适用于那里的字节顺序在运行时可配置的系统。如果它是由引脚设置,该位可能是错误的。而且,当然,在大多数(所有?)ARM7核心,CP15是不是present。

However, the doc (ARM DDI 0100E) seems to hint that this bit is only valid for systems where the endianness is configurable at runtime. If it's set by the pin, the bit may be wrong. And, of course, on most(all?) ARM7 cores, the CP15 is not present.

有是检查它不需要任何硬件位字节序的平台无关的方式。它是这样的:

There is a platform-independent way of checking the endianness which does not require any hardware bits. It goes something like this:

   LDR R0, checkbytes
   CMP R0, 0x12345678
   BE  big_endian
   BNE little_endian
checkbytes
   DB 0x12, 0x34, 0x56, 0x78

根据当前的字节顺序,负载会产生要么为0x12345678或0x78563412。

Depending on the current endianness, the load will produce either 0x12345678 or 0x78563412.

这篇关于如何确定处理器在运行端模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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