How to determine the final mode in which the processor works?

How to determine the final mode in which the ARM processor operates using only assembly language.

I easily see bit 5 of reading the Thumb / ARM state in CPSR, but I don't know if there is a corresponding bit in 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

I have access to the ARM7TDMI data sheet, but this document does not tell me how to read the current state.
What assembly code do I use to define the entity?

Suppose I use an ARM9 processor.

+4
source share
2 answers

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

​​ 15, 7 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 .

, - . :

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

, 0x12345678, 0x78563412.

+5

ARMv6 CPSR E (9) .

AR- ARMv6 c1, 7 , ​​ .

1 big-endian, 0 .

+4

Source: https://habr.com/ru/post/1531353/


All Articles